[xiph-commits] r8261 - in experimental/dholth/oggpy: . tests

dholth at motherfish-iii.xiph.org dholth at motherfish-iii.xiph.org
Mon Nov 22 18:33:04 PST 2004


Author: dholth
Date: 2004-11-22 18:33:04 -0800 (Mon, 22 Nov 2004)
New Revision: 8261

Added:
   experimental/dholth/oggpy/Jamfile
   experimental/dholth/oggpy/Jamfile.v2
   experimental/dholth/oggpy/Jamrules
   experimental/dholth/oggpy/flacpy.cpp
   experimental/dholth/oggpy/oggpy.cpp
   experimental/dholth/oggpy/panogg.cc
   experimental/dholth/oggpy/tests/bigogg.py
   experimental/dholth/oggpy/tests/bridgetest.py
   experimental/dholth/oggpy/tests/encode.py
   experimental/dholth/oggpy/tests/flacframing.py
   experimental/dholth/oggpy/tests/reencode.py
   experimental/dholth/oggpy/tests/video.py
   experimental/dholth/oggpy/theorapy.cpp
   experimental/dholth/oggpy/vorbiscc.h
   experimental/dholth/oggpy/vorbispy.cpp
Modified:
   experimental/dholth/oggpy/MANIFEST.in
   experimental/dholth/oggpy/README
   experimental/dholth/oggpy/pygame_bridge.cc
   experimental/dholth/oggpy/setup.py
   experimental/dholth/oggpy/tests/theoratest.py
   experimental/dholth/oggpy/theoracc.h
   experimental/dholth/oggpy/vorbispy_wrappers.cc
Log:
more files and latest modifications


Added: experimental/dholth/oggpy/Jamfile
===================================================================
--- experimental/dholth/oggpy/Jamfile	2004-11-23 02:15:58 UTC (rev 8260)
+++ experimental/dholth/oggpy/Jamfile	2004-11-23 02:33:04 UTC (rev 8261)
@@ -0,0 +1,58 @@
+# Daniel Holth <dholth at fastmail.fm>, 2004
+# based on David Abraham's example from Boost.Python
+
+# This is the top of our own project tree
+project-root ;
+
+# Include definitions needed for Python modules
+SEARCH on python.jam = $(BOOST_BUILD_PATH) ;
+import python ;
+
+# Declare a Python extension called oggpy
+extension oggpy
+: # sources
+  oggcc.cc
+  oggpy.cpp
+  oggpy_wrappers.cc
+: # requirements
+
+  # <release><find-library>boost_python
+  # <debug><find-library>boost_python
+  # <debug-python><find-library>boost_python
+  # <release><find-library>ogg
+  # <debug><find-library>ogg
+  # <debug-python><find-library>ogg
+  
+  <find-library>ogg
+  <find-library>boost_python
+  
+  <library-path>/usr/lib
+  ;
+
+extension vorbispy
+: # sources
+	oggcc.cc 
+	vorbispy.cpp 
+	vorbispy_wrappers.cc
+: # depends	
+  <find-library>ogg
+  <find-library>vorbis
+  <find-library>boost_python
+  
+  <library-path>/usr/lib
+  ;
+
+
+
+#extension flacpy
+#: # sources
+#  flacpy.cpp
+
+  # requirements and dependencies for Boost.Python extensions
+  # <template>@boost/libs/python/build/extension
+#: # requirements
+#  <dll>FLAC
+#  <dll>FLAC++
+
+#  ;
+

Added: experimental/dholth/oggpy/Jamfile.v2
===================================================================
--- experimental/dholth/oggpy/Jamfile.v2	2004-11-23 02:15:58 UTC (rev 8260)
+++ experimental/dholth/oggpy/Jamfile.v2	2004-11-23 02:33:04 UTC (rev 8261)
@@ -0,0 +1,10 @@
+
+use-project /boost/python : ../build ;
+
+project
+    : requirements <library>/boost/python//boost_python
+    ;
+
+python-extension getting_started1 : getting_started1.cpp : <link>shared ;
+python-extension getting_started2 : getting_started2.cpp : <link>shared ;
+

Added: experimental/dholth/oggpy/Jamrules
===================================================================
--- experimental/dholth/oggpy/Jamrules	2004-11-23 02:15:58 UTC (rev 8260)
+++ experimental/dholth/oggpy/Jamrules	2004-11-23 02:33:04 UTC (rev 8261)
@@ -0,0 +1,7 @@
+# Copyright David Abrahams 2003. See accompanying LICENSE for terms
+# and conditions of use.
+
+# Edit this path to point at the root directory of your Boost
+# installation.  Absolute paths work, too.
+path-global BOOST_ROOT : $(HOME)/src/boost ;
+project boost : $(BOOST_ROOT) ;


Property changes on: experimental/dholth/oggpy/Jamrules
___________________________________________________________________
Name: svn:executable
   + *

Modified: experimental/dholth/oggpy/MANIFEST.in
===================================================================
--- experimental/dholth/oggpy/MANIFEST.in	2004-11-23 02:15:58 UTC (rev 8260)
+++ experimental/dholth/oggpy/MANIFEST.in	2004-11-23 02:33:04 UTC (rev 8261)
@@ -5,3 +5,6 @@
 include tests/oggtext.py
 include tests/test.py
 include config.py
+include Jamfile Jamrules boost-build.jam
+recursive-include debian *
+recursive-include gentoo *.ebuild

Modified: experimental/dholth/oggpy/README
===================================================================
--- experimental/dholth/oggpy/README	2004-11-23 02:15:58 UTC (rev 8260)
+++ experimental/dholth/oggpy/README	2004-11-23 02:33:04 UTC (rev 8261)
@@ -21,10 +21,6 @@
 
 Incidentally there's a separately usable C++ wrapper here too.
 
-This is still an early release.  By downloading this software, you're
-participating in the receiving end of the 'release early, release often'
-open source philosophy, so I'd very much appreciate your feedback.
-
 Send feedback to dholth at fastmail.fm.
 
 Thanks, I hope you enjoy this wrapper.
@@ -42,10 +38,6 @@
 
 	I've also submitted an ebuild.
 
-Then use setup.py build as normal.
-
-Hopefully I'll figure out an ebuild for this.
-
 To compile this software, use setup.py.
 	
 Edit the setup:
@@ -62,3 +54,6 @@
 
 Boost.Python 1.31 or CVS is necessary; 1.30 won't work because it lacks
 a str:: constructor used in vorbispy_wrappers.cc
+
+If you have boost.build and a copy of the boost source installed, you
+might be interested in using boost-jam (bjam) to build this software.

Added: experimental/dholth/oggpy/flacpy.cpp
===================================================================
--- experimental/dholth/oggpy/flacpy.cpp	2004-11-23 02:15:58 UTC (rev 8260)
+++ experimental/dholth/oggpy/flacpy.cpp	2004-11-23 02:33:04 UTC (rev 8261)
@@ -0,0 +1,82 @@
+
+// Boost Includes ==============================================================
+#include <boost/python.hpp>
+#include <boost/cstdint.hpp>
+
+// Includes ====================================================================
+#include <FLAC++/decoder.h>
+
+// Using =======================================================================
+using namespace boost::python;
+
+// Declarations ================================================================
+namespace  {
+
+struct FLAC_Decoder_Stream_Wrapper: FLAC::Decoder::Stream
+{
+    FLAC_Decoder_Stream_Wrapper(PyObject* self_):
+        FLAC::Decoder::Stream(), self(self_) {}
+
+    FLAC__StreamDecoderReadStatus read_callback(FLAC__byte* p0, unsigned int* p1) {
+        return call_method< FLAC__StreamDecoderReadStatus >(self, "read_callback", p0, p1);
+    }
+
+    FLAC__StreamDecoderWriteStatus write_callback(const FLAC__Frame* p0, const FLAC__int32** p1) {
+        return call_method< FLAC__StreamDecoderWriteStatus >(self, "write_callback", p0, p1);
+    }
+
+    void metadata_callback(const ::FLAC__StreamMetadata* p0) {
+        call_method< void >(self, "metadata_callback", p0);
+    }
+
+    void error_callback(::FLAC__StreamDecoderErrorStatus p0) {
+        call_method< void >(self, "error_callback", p0);
+    }
+
+    PyObject* self;
+};
+
+
+}// namespace 
+
+
+// Module ======================================================================
+BOOST_PYTHON_MODULE(flacpy)
+{
+    scope* FLAC_Decoder_Stream_scope = new scope(
+    class_< FLAC_Decoder_Stream_Wrapper >("Stream")
+        .def("is_valid", &FLAC::Decoder::Stream::is_valid)
+        .def("set_metadata_respond", &FLAC::Decoder::Stream::set_metadata_respond)
+        .def("set_metadata_respond_application", &FLAC::Decoder::Stream::set_metadata_respond_application)
+        .def("set_metadata_respond_all", &FLAC::Decoder::Stream::set_metadata_respond_all)
+        .def("set_metadata_ignore", &FLAC::Decoder::Stream::set_metadata_ignore)
+        .def("set_metadata_ignore_application", &FLAC::Decoder::Stream::set_metadata_ignore_application)
+        .def("set_metadata_ignore_all", &FLAC::Decoder::Stream::set_metadata_ignore_all)
+        .def("get_state", &FLAC::Decoder::Stream::get_state)
+        .def("get_channels", &FLAC::Decoder::Stream::get_channels)
+        .def("get_channel_assignment", &FLAC::Decoder::Stream::get_channel_assignment)
+        .def("get_bits_per_sample", &FLAC::Decoder::Stream::get_bits_per_sample)
+        .def("get_sample_rate", &FLAC::Decoder::Stream::get_sample_rate)
+        .def("get_blocksize", &FLAC::Decoder::Stream::get_blocksize)
+        .def("init", &FLAC::Decoder::Stream::init)
+        .def("finish", &FLAC::Decoder::Stream::finish)
+        .def("flush", &FLAC::Decoder::Stream::flush)
+        .def("reset", &FLAC::Decoder::Stream::reset)
+        .def("process_single", &FLAC::Decoder::Stream::process_single)
+        .def("process_until_end_of_metadata", &FLAC::Decoder::Stream::process_until_end_of_metadata)
+        .def("process_until_end_of_stream", &FLAC::Decoder::Stream::process_until_end_of_stream)
+        .def("to_bool", &FLAC::Decoder::Stream::operator bool)
+    );
+
+    class_< FLAC::Decoder::Stream::State >("State", init< const FLAC::Decoder::Stream::State& >())
+        .def(init< FLAC__StreamDecoderState >())
+        .def("as_cstring", &FLAC::Decoder::Stream::State::as_cstring)
+        .def("resolved_as_cstring", &FLAC::Decoder::Stream::State::resolved_as_cstring)
+        .def("to_FLAC_StreamDecoderState", &FLAC::Decoder::Stream::State::operator FLAC__StreamDecoderState)
+    ;
+
+    delete FLAC_Decoder_Stream_scope;
+
+}
+
+

Added: experimental/dholth/oggpy/oggpy.cpp
===================================================================
--- experimental/dholth/oggpy/oggpy.cpp	2004-11-23 02:15:58 UTC (rev 8260)
+++ experimental/dholth/oggpy/oggpy.cpp	2004-11-23 02:33:04 UTC (rev 8261)
@@ -0,0 +1,116 @@
+
+// Boost Includes ==============================================================
+#include <boost/python.hpp>
+#include <boost/cstdint.hpp>
+
+// Includes ====================================================================
+#include "oggcc.h"
+#include "oggpy_wrappers.h"
+
+// Using =======================================================================
+using namespace boost::python;
+
+// Declarations ================================================================
+namespace  {
+
+BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(ogg_oggpack_base_packetout_overloads_1_3, packetout, 1, 3)
+
+
+}// namespace 
+
+
+// Module ======================================================================
+BOOST_PYTHON_MODULE(oggpy)
+{
+    class_< ogg::packet >("packet", init<  >())
+        .def(init< const ogg::packet& >())
+        .def("packetno", &ogg::packet::packetno)
+        .def("granulepos", &ogg::packet::granulepos)
+    ;
+
+    class_< ogg::userpacket, bases< ogg::packet >  >("userpacket", init< const ogg::userpacket& >())
+        .def(init< std::string, ogg_int64_t, optional< bool, bool > >())
+    ;
+
+    class_< ogg::oggpack_base >("oggpack_base", init<  >())
+        .def(init< const ogg::oggpack_base& >())
+        .def("readinit", (void (ogg::oggpack_base::*)(unsigned char*, int) )&ogg::oggpack_base::readinit)
+        .def("readinit", (void (ogg::oggpack_base::*)(ogg::packet*) )&ogg::oggpack_base::readinit)
+        .def("writeinit", &ogg::oggpack_base::writeinit)
+        .def("packetout", &ogg::oggpack_base::packetout, ogg_oggpack_base_packetout_overloads_1_3())
+    ;
+
+    class_< ogg::oggpack, bases< ogg::oggpack_base >  >("oggpack", init<  >())
+        .def(init< const ogg::oggpack& >())
+        .def("bits", &ogg::oggpack::bits)
+        .def("bytes", &ogg::oggpack::bytes)
+        .def("look", &ogg::oggpack::look)
+        .def("look1", &ogg::oggpack::look1)
+        .def("read", &ogg::oggpack::read)
+        .def("read1", &ogg::oggpack::read1)
+        .def("adv", &ogg::oggpack::adv)
+        .def("adv1", &ogg::oggpack::adv1)
+        .def("reset", &ogg::oggpack::reset)
+        .def("write", &ogg::oggpack::write)
+        .def("writealign", &ogg::oggpack::writealign)
+        .def("writeclear", &ogg::oggpack::writeclear)
+        .def("writecopy", &ogg::oggpack::writecopy)
+        .def("writetrunc", &ogg::oggpack::writetrunc)
+    ;
+
+    class_< ogg::oggpackB, bases< ogg::oggpack_base >  >("oggpackB", init<  >())
+        .def(init< const ogg::oggpackB& >())
+        .def("bits", &ogg::oggpackB::bits)
+        .def("bytes", &ogg::oggpackB::bytes)
+        .def("look", &ogg::oggpackB::look)
+        .def("look1", &ogg::oggpackB::look1)
+        .def("read", &ogg::oggpackB::read)
+        .def("read1", &ogg::oggpackB::read1)
+        .def("adv", &ogg::oggpackB::adv)
+        .def("adv1", &ogg::oggpackB::adv1)
+        .def("reset", &ogg::oggpackB::reset)
+        .def("write", &ogg::oggpackB::write)
+        .def("writealign", &ogg::oggpackB::writealign)
+        .def("writeclear", &ogg::oggpackB::writeclear)
+        .def("writecopy", &ogg::oggpackB::writecopy)
+        .def("writetrunc", &ogg::oggpackB::writetrunc)
+    ;
+
+    class_< ogg::page >("page", init<  >())
+        .def(init< const ogg::page& >())
+        .def("bos", &ogg::page::bos)
+        .def("continued", &ogg::page::continued)
+        .def("eos", &ogg::page::eos)
+        .def("packets", &ogg::page::packets)
+        .def("serialno", &ogg::page::serialno)
+        .def("version", &ogg::page::version)
+        .def("pageno", &ogg::page::pageno)
+        .def("granulepos", &ogg::page::granulepos)
+        .def("checksum_set", &ogg::page::checksum_set)
+        .def("header", &ogg::page::header)
+        .def("body", &ogg::page::body)
+    ;
+
+    class_< ogg::sync >("sync", init<  >())
+        .def(init< const ogg::sync& >())
+        .def("pageout", (int (ogg::sync::*)(ogg::page*) )&ogg::sync::pageout)
+        .def("pageseek", (long int (ogg::sync::*)(ogg::page*) )&ogg::sync::pageseek)
+        .def("reset", &ogg::sync::reset)
+        .def("write", &ogg::sync_write)
+    ;
+
+    class_< ogg::stream >("stream", init< const ogg::stream& >())
+        .def(init< int >())
+        .def("eos", &ogg::stream::eos)
+        .def("flush", (int (ogg::stream::*)(ogg::page*) )&ogg::stream::flush)
+        .def("pagein", (int (ogg::stream::*)(ogg::page*) )&ogg::stream::pagein)
+        .def("packetout", (int (ogg::stream::*)(ogg::packet*) )&ogg::stream::packetout)
+        .def("packetpeek", (int (ogg::stream::*)(ogg::packet*) )&ogg::stream::packetpeek)
+        .def("packetin", (int (ogg::stream::*)(ogg::packet*) )&ogg::stream::packetin)
+        .def("pageout", (int (ogg::stream::*)(ogg::page*) )&ogg::stream::pageout)
+        .def("reset", &ogg::stream::reset)
+        .def("reset_serialno", &ogg::stream::reset_serialno)
+    ;
+
+}
+

Added: experimental/dholth/oggpy/panogg.cc
===================================================================
--- experimental/dholth/oggpy/panogg.cc	2004-11-23 02:15:58 UTC (rev 8260)
+++ experimental/dholth/oggpy/panogg.cc	2004-11-23 02:33:04 UTC (rev 8261)
@@ -0,0 +1,43 @@
+/* Boost.Python wrapper for ogg, vorbis and theora.                          */
+/*                                                                           */
+/* This library is free software; you can redistribute it and/or             */
+/* modify it under the terms of the GNU Lesser General Public                */
+/* License as published by the Free Software Foundation; either              */
+/* version 2.1 of the License, or (at your option) any later version.        */
+/*                                                                           */
+/* This library is distributed in the hope that it will be useful,           */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of            */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         */
+/* Lesser General Public License for more details.                           */
+/*                                                                           */
+/* You should have received a copy of the GNU Lesser General Public          */
+/* License along with this library; if not, write to the Free Software       */
+/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+/*                                                                           */
+/* For questions regarding this program contact                              */
+/* Daniel Holth <dholth at fastmail.fm>                                         */
+
+/**
+ * Control xiph codecs through a Boost.Python wrapper.
+ * 
+ * @author Daniel Holth
+ */
+
+#include <boost/python.hpp>
+#include <boost/python/def.hpp>
+#include <boost/python/module.hpp>
+#include <boost/python/tuple.hpp>
+#include <boost/python/exception_translator.hpp>
+
+using namespace boost::python;
+
+void Export_oggpy();
+void Export_vorbispy();
+void Export_theorapy();
+
+BOOST_PYTHON_MODULE_INIT(panogg)
+{
+    Export_oggpy();
+    Export_vorbispy();
+    Export_theorapy();
+}

Modified: experimental/dholth/oggpy/pygame_bridge.cc
===================================================================
--- experimental/dholth/oggpy/pygame_bridge.cc	2004-11-23 02:15:58 UTC (rev 8260)
+++ experimental/dholth/oggpy/pygame_bridge.cc	2004-11-23 02:33:04 UTC (rev 8261)
@@ -95,11 +95,16 @@
     /* and crop input properly, respecting the encoded frame rect */
     crop_offset=ti.offset_x+yuv.y_stride*ti.offset_y;
     for(i=0;i<yuv_overlay->h;i++)
+    {
         memcpy(yuv_overlay->pixels[0]+yuv_overlay->pitches[0]*i,
                yuv.y+crop_offset+yuv.y_stride*i,
                yuv_overlay->w);
+    }
+
     crop_offset=(ti.offset_x/2)+(yuv.uv_stride)*(ti.offset_y/2);
-    for(i=0;i<yuv_overlay->h/2;i++){
+    
+    for(i=0;i<yuv_overlay->h/2;i++)
+    {
         memcpy(yuv_overlay->pixels[1]+yuv_overlay->pitches[1]*i,
                yuv.v+crop_offset+yuv.uv_stride*i,
                yuv_overlay->w/2);

Modified: experimental/dholth/oggpy/setup.py
===================================================================
--- experimental/dholth/oggpy/setup.py	2004-11-23 02:15:58 UTC (rev 8260)
+++ experimental/dholth/oggpy/setup.py	2004-11-23 02:33:04 UTC (rev 8261)
@@ -22,7 +22,7 @@
 Topic :: Multimedia :: Video
 """
 
-version = "0.5"
+version = "0.5.2"
 url = "http://dingoskidneys.com/oggpy/"
 
 setup(name="oggpy",
@@ -53,12 +53,12 @@
                               include_dirs=config.theorapy_include_dirs,
                               depends=["oggcc.h", "theoracc.h"]),
                     
-                    Extension("flacpy", ["flacpy.cpp"],
-                              libraries=config.flacpy_libraries,
-                              include_dirs=config.flacpy_include_dirs)
+#                    Extension("flacpy", ["flacpy.cpp"],
+#                              libraries=config.flacpy_libraries,
+#                              include_dirs=config.flacpy_include_dirs)
 
                     # It works!
-                    , Extension("pygame_bridge", ["pygame_bridge.cc"],
+                    Extension("pygame_bridge", ["pygame_bridge.cc"],
                                 libraries=config.bridge_libraries,
                                 include_dirs=config.bridge_include_dirs)
 

Added: experimental/dholth/oggpy/tests/bigogg.py
===================================================================
--- experimental/dholth/oggpy/tests/bigogg.py	2004-11-23 02:15:58 UTC (rev 8260)
+++ experimental/dholth/oggpy/tests/bigogg.py	2004-11-23 02:33:04 UTC (rev 8261)
@@ -0,0 +1,46 @@
+#!/usr/bin/python
+#
+# Find out what happens when big ogg packets are used.
+# Hint: they are spread across several ogg pages.
+#
+# Daniel Holth <dholth at fastmail.fm>, 2004
+
+import oggpy
+import sys
+
+granule  = 0
+
+os = oggpy.stream(0x00FF00FF)
+page = oggpy.page()
+
+pack = oggpy.userpacket("OGGText", granule, True, False)
+os.packetin(pack)
+
+os.flush(page)
+sys.stdout.write(page.header())
+sys.stdout.write(page.body())
+
+
+bigdata = " Ogg Data " * 1024
+
+pack = oggpy.userpacket(bigdata, granule, False, False)
+os.packetin(pack)
+
+while os.pageout(page):
+    sys.stdout.write(page.header())
+    sys.stdout.write(page.body())
+
+for data in sys.stdin.readlines():
+    if data[0] == chr(12):
+        while(os.flush(page) != 0):
+            sys.stdout.write(page.header())
+            sys.stdout.write(page.body())
+    granule += 1
+    pack = oggpy.userpacket(data, granule, False, False)
+    os.packetin(pack)
+
+pack = oggpy.userpacket("", granule, False, True)
+os.packetin(pack)
+os.pageout(page)
+sys.stdout.write(page.header())
+sys.stdout.write(page.body())


Property changes on: experimental/dholth/oggpy/tests/bigogg.py
___________________________________________________________________
Name: svn:executable
   + *

Added: experimental/dholth/oggpy/tests/bridgetest.py
===================================================================
--- experimental/dholth/oggpy/tests/bridgetest.py	2004-11-23 02:15:58 UTC (rev 8260)
+++ experimental/dholth/oggpy/tests/bridgetest.py	2004-11-23 02:33:04 UTC (rev 8261)
@@ -0,0 +1,14 @@
+#!/usr/bin/python
+
+import pygame
+import pygame_bridge
+
+pygame.init()
+pygame.display.set_mode((320,320))
+pygame.display.init()
+
+b = pygame_bridge.bridge()
+
+print "is a string a surface?", b.is_surface("foo")
+s = b.make_surface()
+print "is", s, "a surface?", b.is_surface(s)


Property changes on: experimental/dholth/oggpy/tests/bridgetest.py
___________________________________________________________________
Name: svn:executable
   + *

Added: experimental/dholth/oggpy/tests/encode.py
===================================================================
--- experimental/dholth/oggpy/tests/encode.py	2004-11-23 02:15:58 UTC (rev 8260)
+++ experimental/dholth/oggpy/tests/encode.py	2004-11-23 02:33:04 UTC (rev 8261)
@@ -0,0 +1,86 @@
+#!/usr/bin/python
+#
+# Encoding example.
+# This is approximately a port of libvorbis's encoder_example.c
+# It expects 44kHz 16-bit stereo input.
+#
+# With numarray version 0.9, this is only 6.4-15% slower than oggenc.c -
+# only a second's difference on most songs.
+#
+# Daniel Holth <dholth at fastmail.fm>, 2004
+
+import oggpy
+import vorbispy
+import sys
+import numarray
+import random
+from numarray import array
+
+# samples to read at one time, halving or quartering doesn't slow things down
+READ = 8192
+
+def test(indata):
+    outfile = file("encodepy.ogg", "wb")
+    
+    og = oggpy.page()
+    op = oggpy.packet()
+    vi = vorbispy.info()
+    vc = vorbispy.comment()
+    vd = vorbispy.dsp()
+    vb = vorbispy.block()
+
+    vi.encode_init_vbr(2, 44100, -0.1)
+    # vc.add_tag("ENCODER", "encode.py")
+    vd.analysis_init(vi)
+    vd.block_init(vb)
+    
+    randomnumber = random.randrange(0,2**30)
+    os = oggpy.stream(randomnumber)
+
+    header      = oggpy.packet()
+    header_comm = oggpy.packet()
+    header_code = oggpy.packet()
+
+    vd.analysis_headerout(vc, header, header_comm, header_code)
+
+    os.packetin(header)
+    os.packetin(header_comm)
+    os.packetin(header_code)
+
+    # ensure the actual audio data will start on a new page
+    eos = False
+    while not eos:
+        result = os.flush(og)
+        if result == 0: break
+        outfile.write(og.header())
+        outfile.write(og.body())
+
+    while not eos:
+        data  = indata.read(READ*4)
+        if not data:
+            vd.analysis_write(None)
+        else:
+            interleaved = numarray.fromstring(data, numarray.Int16)
+            # better convert to float, from -1.0 to 1.0
+            deinterleaved = numarray.array((interleaved[0::2], interleaved[1::2]), numarray.Float32)
+            deinterleaved *= 1.0/32768.0
+            vd.analysis_write(deinterleaved)
+ 
+        while(vd.analysis_blockout(vb)==1):
+            # will have to be able to take null/None to use bitrate management:
+            vb.analysis(op)
+            os.packetin(op)
+            
+            while not eos:
+                result = os.pageout(og)
+                if result == 0: break
+                outfile.write(og.header())
+                outfile.write(og.body())
+
+                if og.eos(): eos = 1
+    
+    del og
+
+
+if __name__ == "__main__":
+    test(file("./decode.raw", 'rb'))


Property changes on: experimental/dholth/oggpy/tests/encode.py
___________________________________________________________________
Name: svn:executable
   + *

Added: experimental/dholth/oggpy/tests/flacframing.py
===================================================================
--- experimental/dholth/oggpy/tests/flacframing.py	2004-11-23 02:15:58 UTC (rev 8260)
+++ experimental/dholth/oggpy/tests/flacframing.py	2004-11-23 02:33:04 UTC (rev 8261)
@@ -0,0 +1,120 @@
+#!/usr/bin/python
+#
+# Partial port of decoder_example.c from the vorbis library.
+# Decodes an ogg/vorbis file from stdin, writing the first channel to disk.
+#
+# Daniel Holth <dholth at fastmail.fm>, 2004
+
+# NOTICE
+# this file does
+# NOT do anything fLaC
+# at the moment -dwh
+
+import oggpy
+import sys
+import numarray
+
+BUFSIZE=8192
+
+def test(ogg, outfile=file("decode.raw", "w")):
+    numarray.Error.setMode(all="ignore")
+    
+    oy = oggpy.sync()
+    og = oggpy.page()
+    op = oggpy.packet()
+    vi = oggpy.info()
+    vd = oggpy.dsp()
+    vb = oggpy.block()
+    vc = oggpy.comment()
+
+    while 1:
+        buffer = ogg.read(BUFSIZE)
+        oggpy.sync_write(oy, buffer)
+
+        if oy.pageout(og) != 1:
+            if len(buffer) < BUFSIZE: break
+            print >> sys.stderr, "Input does not appear to be an Ogg bitstream."
+            sys.exit(1)
+
+        os = oggpy.stream(og.serialno())
+
+        if os.pagein(og) < 0:
+            print >> sys.stderr, "Error reading first Ogg bitstream page"
+            sys.exit(1)
+
+        if os.packetout(op) != 1:
+            print >> sys.stderr, "Error reading initial header packet"
+            sys.exit(1)
+
+        if vi.synthesis_headerin(vc, op) < 0:
+            print >> sys.stderr, "Not an ogg/vorbis bitstream."
+            sys.exit(1)
+
+        i = 0
+        while i < 2:
+            while i < 2:
+                result = oy.pageout(og)
+                if result == 0: break
+                if result == 1:
+                    os.pagein(og)
+                    while i < 2:
+                        result = os.packetout(op)
+                        if result == 0: break
+                        if result < 0:
+                            print >> sys.stderr, "corrupt second header."
+                            sys.exit(1)
+                        vi.synthesis_headerin(vc, op)
+                        i += 1
+        
+            buffer = ogg.read(BUFSIZE)
+            if len(buffer) == 0 and i < 2:
+                print >> sys.stderr, "EOF before finding all vorbis headers!"
+                sys.exit(1)
+
+            oggpy.sync_write(oy, buffer)
+
+        print >> sys.stderr, oggpy.get_comments(vc)
+
+        vd.synthesis_init(vi)
+        vd.block_init(vb)
+
+        eos = False
+        while not eos:
+            while not eos:
+                result = oy.pageout(og)
+                if result == 0: break           # need more data
+                if result < 0:
+                    print >> sys.stderr, "Yikes, corruption! continue..."
+                else:
+                    os.pagein(og)
+                    p = 0
+                    while 1:
+                        result = os.packetout(op)
+                        if result == 0: break   # need more data
+                        if result > 0:          # we have a packet. decode it.
+                            p += 1
+                            if vb.synthesis(op) == 0:
+                                vd.synthesis_blockin(vb)
+                                                        
+                            samples = oggpy.oggpy_synthesis_pcmout(vd)
+                            while samples != None:
+                                samples *= 32767;
+                                wav = samples.astype('Int16')
+                                
+                                interleaved = numarray.zeros(samples.shape[1]*2, numarray.Int16)
+                                interleaved[0::2] = wav[0]
+                                interleaved[1::2] = wav[1]
+                                interleaved.tofile(outfile)
+                                        
+                                samples = oggpy.oggpy_synthesis_pcmout(vd)
+                                
+                if og.eos(): eos = True
+            if not eos:
+                buffer = ogg.read(BUFSIZE)
+                oggpy.sync_write(oy, buffer)
+                if len(buffer) == 0: eos = True
+        
+
+if __name__ == "__main__":
+    # test(sys.stdin)
+    test(file("music.ogg", "r"))


Property changes on: experimental/dholth/oggpy/tests/flacframing.py
___________________________________________________________________
Name: svn:executable
   + *

Added: experimental/dholth/oggpy/tests/reencode.py
===================================================================
--- experimental/dholth/oggpy/tests/reencode.py	2004-11-23 02:15:58 UTC (rev 8260)
+++ experimental/dholth/oggpy/tests/reencode.py	2004-11-23 02:33:04 UTC (rev 8261)
@@ -0,0 +1,95 @@
+#!/usr/bin/python
+#
+# Encoding+streaming example.
+# This is approximately a port of libvorbis's encoder_example.c
+# It expects 44kHz 16-bit stereo input.
+#
+# Daniel Holth <dholth at fastmail.fm>, 2004
+
+import numarray
+import oggpy
+import random
+import shoutpy
+import sys
+import vorbispy
+from numarray import array
+
+# samples to read at one time, halving or quartering doesn't slow things down
+READ = 8192
+
+def test(indata):
+    numarray.Error.setMode(all="ignore")
+
+    s = shoutpy.Shout()
+    s.user      = "source"
+    s.password  = "hackme"
+    s.mount     = "/shoutpy.ogg"
+    s.port      = 8001
+    s.format    = shoutpy.FORMAT_VORBIS
+    s.open()
+    
+    og = oggpy.page()
+    op = oggpy.packet()
+    vi = vorbispy.info()
+    vc = vorbispy.comment()
+    vd = vorbispy.dsp()
+    vb = vorbispy.block()
+
+    vi.encode_init_vbr(2, 44100, 0.0)
+    vc.add_tag("ENCODER", "stream.py")
+    vc.add_tag("ARTIST", "unknown")
+    vd.analysis_init(vi)
+    vd.block_init(vb)
+    
+    randomnumber = random.randrange(0,2**30)
+    os = oggpy.stream(randomnumber)
+
+    header      = oggpy.packet()
+    header_comm = oggpy.packet()
+    header_code = oggpy.packet()
+
+    vd.analysis_headerout(vc, header, header_comm, header_code)
+
+    os.packetin(header)
+    os.packetin(header_comm)
+    os.packetin(header_code)
+
+    # ensure the actual audio data will start on a new page
+    eos = False
+    while not eos:
+        result = os.flush(og)
+        if result == 0: break
+        s.send(og.header())
+        s.send(og.body())
+
+    while not eos:
+        data  = indata.read(READ*4)
+        if not data:
+            vd.analysis_write(None)
+        else:
+            interleaved = numarray.fromstring(data, numarray.Int16)
+            # better convert to float, from -1.0 to 1.0
+            deinterleaved = numarray.array((interleaved[0::2], interleaved[1::2]), numarray.Float32)
+            deinterleaved *= 1.0/32768.0
+            vd.analysis_write(deinterleaved)
+ 
+        while(vd.analysis_blockout(vb)==1):
+            # will have to be able to take null/None to use bitrate management:
+            vb.analysis(op)
+            os.packetin(op)
+            
+            while not eos:
+                result = os.pageout(og)
+                if result == 0: break
+
+                s.send(og.header())
+                s.send(og.body())
+                s.sync()
+
+                if og.eos(): eos = 1
+    
+    del og
+
+
+if __name__ == "__main__":
+    test(file("./decode.raw", 'rb'))


Property changes on: experimental/dholth/oggpy/tests/reencode.py
___________________________________________________________________
Name: svn:executable
   + *

Modified: experimental/dholth/oggpy/tests/theoratest.py
===================================================================
--- experimental/dholth/oggpy/tests/theoratest.py	2004-11-23 02:15:58 UTC (rev 8260)
+++ experimental/dholth/oggpy/tests/theoratest.py	2004-11-23 02:33:04 UTC (rev 8261)
@@ -71,8 +71,8 @@
             td.decode_init(ti)
             yield (ti, tc, td)
             
-            # print "This theora encoded by: ", tc.get_vendor()
-            # print "Trying to decode with: ", theorapy.version_string(), theorapy.version_number()
+            print "This theora encoded by: ", tc.get_vendor()
+            print "Trying to decode with: ", theorapy.version_string(), theorapy.version_number()
             # for i in dir(ti):
             #     if i[0:2] != "__":
             #         try:

Added: experimental/dholth/oggpy/tests/video.py
===================================================================
--- experimental/dholth/oggpy/tests/video.py	2004-11-23 02:15:58 UTC (rev 8260)
+++ experimental/dholth/oggpy/tests/video.py	2004-11-23 02:33:04 UTC (rev 8261)
@@ -0,0 +1,55 @@
+#!/usr/bin/python
+#
+# Display theora video, silently, via pygame.
+#
+# Daniel Holth <dholth at fastmail.fm>, 2004
+
+import pygame, os
+import pygame.draw
+from pygame.locals import *
+
+import theorapy
+import oggpy
+import time
+import pygame_bridge
+import theoratest
+import sys
+
+def play():
+    pygame.init()
+
+    vidsrc = theoratest.test(file(sys.argv[1], "rb"))
+
+    info, comment, state = vidsrc.next()
+    print "info", info, "comment", comment, "state", state
+
+    frame_duration = float(info.fps_denominator) / float(info.fps_numerator)
+    print "frames per second:", 1/frame_duration
+    
+    width  = info.width
+    height = info.height
+
+    screen      = pygame.display.set_mode((width, height), HWSURFACE|DOUBLEBUF)
+    surf        = pygame.display.get_surface()
+    surfshot    = pygame.Surface((width, height))
+    
+    surf.fill((0,0,0))
+    pygame.display.flip()
+
+    bridge = pygame_bridge.bridge()
+
+#    bridge.set_surface(surfshot)
+    bridge.set_surface(surf)
+    bridge.set_info(info)
+
+    frames = 0
+    basetime = time.time()
+
+    for frame in vidsrc:
+        t = time.time()
+        bridge.render(frame)
+        frames += 1
+        time.sleep(max(0,frame_duration-(time.time()-t)))
+
+if __name__ == "__main__":
+    play()


Property changes on: experimental/dholth/oggpy/tests/video.py
___________________________________________________________________
Name: svn:executable
   + *

Modified: experimental/dholth/oggpy/theoracc.h
===================================================================
--- experimental/dholth/oggpy/theoracc.h	2004-11-23 02:15:58 UTC (rev 8260)
+++ experimental/dholth/oggpy/theoracc.h	2004-11-23 02:33:04 UTC (rev 8261)
@@ -146,7 +146,74 @@
         {
             public:
                 yuv_buffer *get_data()  { return (yuv_buffer*)this; }
+                
+                PyObject* tostring () { 
+                    int crop_offset=0;
+                    int i,j;
+                    char  y[this->y_width*this->y_height];
+                    char  u[this->y_width*this->y_height];
+                    char  v[this->y_width*this->y_height];
+                    char  data[this->y_width*this->y_height*3];
+
+                    //crop_offset=ti.offset_x+yuv.y_stride*ti.offset_y;
+                    for(i=0;i<this->y_height;i++){
+                        std::memcpy(y+i*this->y_width,
+                                this->y+crop_offset+this->y_stride*i,this->y_width);
+                    }
+                    //  crop_offset=(ti.offset_x/2)+(yuv.uv_stride)*(ti.offset_y/2);
+                    for(i=0;i<this->uv_height;i++) {
+                        std::memcpy(u+i*this->uv_width,
+                                this->v+crop_offset+this->uv_stride*i,this->uv_width);
+                        std::memcpy(v+i*this->uv_width,
+                                this->v+crop_offset+this->uv_stride*i,this->uv_width);
+                    }
+
+                    for(i=0;i<this->uv_height;i++) {
+                        for(j=0;j<this->uv_width;j++) {
+                            int uv_count=(i/2)*(j/2);
+                            data[i*j*3]=y[i*j];
+                            data[i*j*3+1]=u[uv_count];
+                            data[i*j*3+2]=v[uv_count];
+                        }
+                    }
+                    return PyString_FromStringAndSize(data,this->y_width*this->y_height*3); 
+                }
+                
+                PyObject* tostrings () { 
+                    int crop_offset=0;
+                    int i;
+                    char  y[this->y_width*this->y_height];
+                    char  u[this->uv_width*this->uv_height];
+                    char  v[this->uv_width*this->uv_height];
+
+                    //crop_offset=theora_info::offset_x+this->y_stride*theora_info::offset_y;
+                    for(i=0;i<this->y_height;i++) {
+                        std::memcpy(y+i*this->y_width,
+                                this->y+crop_offset+this->y_stride*i,this->y_width);
+                    }
+                    
+                    //crop_offset=theora_info::offset_x/2+this->y_stride*theora_info::offset_y/2;
+                    for(i=0; i < this->uv_height; i++) {
+                        std::memcpy(u+i*this->uv_width, this->u+crop_offset+this->uv_stride*i,this->uv_width);
+                        std::memcpy(v+i*this->uv_width, this->v+crop_offset+this->uv_stride*i,this->uv_width);
+                    }
+
+                    PyObject *tuple, *string;
+                    tuple = PyTuple_New(3);
+                    if (tuple == NULL) {
+                        return NULL;
+                    }
+                    
+                    string = PyString_FromStringAndSize(y,this->y_width*this->y_height);
+                    PyTuple_SET_ITEM(tuple, 0, string);
+                    string = PyString_FromStringAndSize(u,this->uv_width*this->uv_height);
+                    PyTuple_SET_ITEM(tuple, 1, string);
+                    string = PyString_FromStringAndSize(v,this->uv_width*this->uv_height);
+                    PyTuple_SET_ITEM(tuple, 2, string);
+                    return tuple;
+                }
         };
+	
 
 
         /// Codec state.

Added: experimental/dholth/oggpy/theorapy.cpp
===================================================================
--- experimental/dholth/oggpy/theorapy.cpp	2004-11-23 02:15:58 UTC (rev 8260)
+++ experimental/dholth/oggpy/theorapy.cpp	2004-11-23 02:33:04 UTC (rev 8261)
@@ -0,0 +1,107 @@
+
+// Boost Includes ==============================================================
+#include <boost/python.hpp>
+#include <boost/cstdint.hpp>
+
+// Includes ====================================================================
+#include <theora/theora.h>
+#include <theoracc.h>
+
+// Using =======================================================================
+using namespace boost::python;
+
+// Module ======================================================================
+BOOST_PYTHON_MODULE(theorapy)
+{
+    class_< ogg::theora::state >("state", init<  >())
+        .def(init< const ogg::theora::state& >())
+        .def("granule_time", &ogg::theora::state::granule_time)
+        .def("decode_init", &ogg::theora::state::decode_init)
+        .def("decode_packetin", &ogg::theora::state::decode_packetin)
+        .def("decode_YUVout", &ogg::theora::state::decode_YUVout)
+        .def("encode_init", &ogg::theora::state::encode_init)
+        .def("encode_header", &ogg::theora::state::encode_header)
+        .def("encode_tables", &ogg::theora::state::encode_tables)
+        .def("encode_YUVin", &ogg::theora::state::encode_YUVin)
+        .def("encode_packetout", &ogg::theora::state::encode_packetout)
+    ;
+
+    class_< ogg::theora::info >("info", init<  >())
+        .def(init< const ogg::theora::info& >())
+        .def_readwrite("width", &theora_info::width)
+        .def_readwrite("height", &theora_info::height)
+        .def_readwrite("frame_width", &theora_info::frame_width)
+        .def_readwrite("frame_height", &theora_info::frame_height)
+        .def_readwrite("offset_x", &theora_info::offset_x)
+        .def_readwrite("offset_y", &theora_info::offset_y)
+        .def_readwrite("fps_numerator", &theora_info::fps_numerator)
+        .def_readwrite("fps_denominator", &theora_info::fps_denominator)
+        .def_readwrite("aspect_numerator", &theora_info::aspect_numerator)
+        .def_readwrite("aspect_denominator", &theora_info::aspect_denominator)
+        .def_readwrite("colorspace", &theora_info::colorspace)
+        .def_readwrite("target_bitrate", &theora_info::target_bitrate)
+        .def_readwrite("quality", &theora_info::quality)
+        .def_readwrite("quick_p", &theora_info::quick_p)
+        .def_readwrite("version_major", &theora_info::version_major)
+        .def_readwrite("version_minor", &theora_info::version_minor)
+        .def_readwrite("version_subminor", &theora_info::version_subminor)
+        .def_readwrite("codec_setup", &theora_info::codec_setup)
+        .def_readwrite("dropframes_p", &theora_info::dropframes_p)
+        .def_readwrite("keyframe_auto_p", &theora_info::keyframe_auto_p)
+        .def_readwrite("keyframe_frequency", &theora_info::keyframe_frequency)
+        .def_readwrite("keyframe_frequency_force", &theora_info::keyframe_frequency_force)
+        .def_readwrite("keyframe_data_target_bitrate", &theora_info::keyframe_data_target_bitrate)
+        .def_readwrite("keyframe_auto_threshold", &theora_info::keyframe_auto_threshold)
+        .def_readwrite("keyframe_mindistance", &theora_info::keyframe_mindistance)
+        .def_readwrite("noise_sensitivity", &theora_info::noise_sensitivity)
+        .def_readwrite("sharpness", &theora_info::sharpness)
+        .def("decode_header", &ogg::theora::info::decode_header)
+    ;
+
+    class_< ogg::theora::comment >("comment", init<  >())
+        .def(init< const ogg::theora::comment& >())
+        .def("query", &ogg::theora::comment::query)
+        .def("query_index", &ogg::theora::comment::query_index)
+        .def("query_count", &ogg::theora::comment::query_count)
+        .def("encode", &ogg::theora::comment::encode)
+        .def("add", &ogg::theora::comment::add)
+        .def("add_tag", &ogg::theora::comment::add_tag)
+        .def("get_vendor", &ogg::theora::comment::get_vendor)
+        .def("size", &ogg::theora::comment::size)
+    ;
+
+    class_< ogg::theora::yuv_image >("yuv_image", init<  >())
+        .def(init< const ogg::theora::yuv_image& >())
+        .def_readwrite("y_width", &yuv_buffer::y_width)
+        .def_readwrite("y_height", &yuv_buffer::y_height)
+        .def_readwrite("y_stride", &yuv_buffer::y_stride)
+        .def_readwrite("uv_width", &yuv_buffer::uv_width)
+        .def_readwrite("uv_height", &yuv_buffer::uv_height)
+        .def_readwrite("uv_stride", &yuv_buffer::uv_stride)
+        .def_readwrite("y", &yuv_buffer::y)
+        .def_readwrite("u", &yuv_buffer::u)
+        .def_readwrite("v", &yuv_buffer::v)
+        .def("tostring", &ogg::theora::yuv_image::tostring)
+        .def("tostrings", &ogg::theora::yuv_image::tostrings)
+    ;
+
+    def("version_number", &ogg::theora::version_number);
+    def("version_string", &ogg::theora::version_string);
+    enum_< ogg::theora::theora_errors >("theora_errors")
+        .value("ocBadPacket", ogg::theora::ocBadPacket)
+        .value("ocNotFormat", ogg::theora::ocNotFormat)
+        .value("ocBadHeader", ogg::theora::ocBadHeader)
+        .value("ocFault", ogg::theora::ocFault)
+        .value("ocEinval", ogg::theora::ocEinval)
+        .value("ocImpl", ogg::theora::ocImpl)
+        .value("ocNewPacket", ogg::theora::ocNewPacket)
+    ;
+
+    enum_< theora_colorspace >("theora_colorspace")
+        .value("OC_CS_UNSPECIFIED", OC_CS_UNSPECIFIED)
+        .value("OC_CS_ITU_REC_470M", OC_CS_ITU_REC_470M)
+        .value("OC_CS_ITU_REC_470BG", OC_CS_ITU_REC_470BG)
+    ;
+
+}
+

Added: experimental/dholth/oggpy/vorbiscc.h
===================================================================
--- experimental/dholth/oggpy/vorbiscc.h	2004-11-23 02:15:58 UTC (rev 8260)
+++ experimental/dholth/oggpy/vorbiscc.h	2004-11-23 02:33:04 UTC (rev 8261)
@@ -0,0 +1,293 @@
+/** vorbiscc.h
+ *
+ * A straightforward C++ wrapper for libvorbis.
+ *
+ * @author Daniel Holth <dholth at fastmail.fm>
+ */
+
+#ifndef VORBISCC_H
+#define VORBISCC_H
+
+#include "oggcc.h"
+#include <string>
+#include <vorbis/codec.h>
+#include <vorbis/vorbisenc.h>
+
+namespace ogg {
+    /// libvorbis
+    namespace vorbis {
+        /// interestingly, the vorbis spec in theory supports 8-bit clean comments, but the comment
+        /// manipulators only accept null-terminated strings.  however, if you did somehow put a null 
+        /// in the middle of a vorbis comment you risk being compatible with only yourself.
+        class comment {
+            protected:
+                void init ( )   { vorbis_comment_init ( &this->data ); }
+                void clear ( )  { vorbis_comment_clear ( &this->data ); }
+
+                int header_out ( ogg_packet *op )  {
+                    return vorbis_commentheader_out ( &this->data, op ); }
+
+            public:
+                vorbis_comment data;
+                vorbis_comment *get_data()  { return &this->data; }
+
+                comment()   { this->init(); }
+                ~comment()  { this->clear(); }
+
+                const char *query ( char *tag , int count )  {
+                    return vorbis_comment_query ( &this->data, tag, count ); }
+
+                int query_count ( char *tag )  {
+                    return vorbis_comment_query_count ( &this->data, tag ); }
+
+                void add ( char *comment )  {
+                    vorbis_comment_add ( &this->data, comment ); }
+
+                void add_tag ( char *tag , char *contents )  {
+                    vorbis_comment_add_tag ( &this->data, tag, contents ); }
+
+                int header_out ( packet *op )  {
+                    return this->header_out ( op->get_data() ); }
+
+                /// Return the nth comment.
+                std::string query_index(unsigned int index) { 
+                    vorbis_comment *data = this->get_data();
+                    return (index < (unsigned)(data->comments) ? 
+                            std::string(data->user_comments[index], data->comment_lengths[index]) : ""); };
+                
+                int size()  { return this->get_data()->comments; }
+        };
+
+
+        /// Center of vorbis decoding.  Stores lots of bitstream metadata.
+        class info {
+            protected:
+                int synthesis_headerin ( vorbis_comment *vc, ogg_packet *op )  {
+                    return vorbis_synthesis_headerin ( &this->data, vc, op );  }
+
+                long packet_blocksize ( ogg_packet *op )  {
+                    return vorbis_packet_blocksize ( &this->data, op );  }
+
+                void info_init ( )  { return vorbis_info_init ( &this->data );  }
+                void info_clear ( )  { return vorbis_info_clear ( &this->data );  }
+
+            public:
+                vorbis_info data;
+                vorbis_info *get_data() { return &this->data; }
+
+                info()    { this->info_init(); }
+                ~info()   { this->info_clear(); }
+
+                int encode_init(long channels,
+                                long rate, 
+                                long max_bitrate, 
+                                long nominal_bitrate, 
+                                long min_bitrate)
+
+                { return vorbis_encode_init(&this->data,
+                                            channels, 
+                                            rate, 
+                                            max_bitrate, 
+                                            nominal_bitrate, 
+                                            min_bitrate); } 
+
+
+                int encode_setup_managed(long channels, 
+                                         long rate, 
+                                         long max_bitrate, 
+                                         long nominal_bitrate, 
+                                         long min_bitrate) { 
+
+                    return vorbis_encode_setup_managed(&this->data, 
+                                                       channels, 
+                                                       rate, 
+                                                       max_bitrate,
+                                                       nominal_bitrate, 
+                                                       min_bitrate); }
+
+                /// quality from 0. (lo) to 1. (hi)
+                int encode_setup_vbr(long channels, 
+                                     long rate, 
+                                     float base_quality) {
+
+                    return vorbis_encode_setup_vbr(&this->data, 
+                                                   channels, 
+                                                   rate,           
+                                                   base_quality); }
+
+
+                int encode_init_vbr(long channels, 
+                                    long rate, 
+                                    float base_quality) {
+
+                    return vorbis_encode_init_vbr(&this->data, 
+                                                  channels, 
+                                                  rate, 
+                                                  base_quality); }
+
+
+                int encode_ctl(vorbis_info *vi, int number, void *arg) {
+                    return vorbis_encode_ctl( &this->data, number, arg ); }
+
+
+                int encode_setup_init() {
+                    return vorbis_encode_setup_init( &this->data ); }
+
+
+                int info_blocksize ( int zo )  {
+                    return vorbis_info_blocksize ( &this->data, zo );  }
+
+                int synthesis_halfrate ( int flag )  {
+                    return vorbis_synthesis_halfrate ( &this->data, flag );  }
+
+                int synthesis_halfrate_p ( )  {
+                    return vorbis_synthesis_halfrate_p ( &this->data );  }
+
+                // packet in, comment out.
+                int synthesis_headerin ( comment *vc, packet *op ) {
+                    return this->synthesis_headerin ( &vc->data, op->get_data() ); }
+
+                long packet_blocksize ( packet *op )  {
+                    return this->packet_blocksize ( op->get_data() );  }
+
+                int  get_version()  { return this->get_data()->version; }
+                int  get_channels() { return this->get_data()->channels; }
+                long get_rate()     { return this->get_data()->rate; }
+        };
+
+
+        /// Local state for a chunk of vorbis.  Multiple block decodes may proceed in parallel.
+        class block {
+            protected:
+                int analysis ( ogg_packet *op )  {
+                    return vorbis_analysis ( &this->data, op );  }
+
+                int synthesis ( ogg_packet *op )  {
+                    return vorbis_synthesis ( &this->data, op ); }
+
+                int synthesis_trackonly ( ogg_packet *op )  {
+                    return vorbis_synthesis_trackonly ( &this->data, op ); }
+
+            public:
+                vorbis_block data;
+
+                int analysis ( packet *op )   { return this->analysis(op->get_data()); }
+                int bitrate_addblock ( )      { return vorbis_bitrate_addblock ( &this->data ); }
+                int block_clear ( )           { return vorbis_block_clear ( &this->data ); }
+                int synthesis ( packet *op )  { return this->synthesis(op->get_data()); }
+                int synthesis_trackonly ( packet *op )  { return this->synthesis_trackonly(op->get_data()); }
+        };
+
+
+        /// PCM processing.
+        // may separate into separate synthesis and analysis objects.
+        class dsp {
+            protected:
+                int bitrate_flushpacket ( ogg_packet *op )  {
+                    return vorbis_bitrate_flushpacket ( &this->data, op ); }
+
+                int analysis_init ( vorbis_info *vi )  {
+                    return vorbis_analysis_init ( &this->data, vi ); }
+
+                int analysis_blockout ( vorbis_block *vb )  {
+                    return vorbis_analysis_blockout ( &this->data, vb ); }
+
+                int analysis_headerout ( vorbis_comment *vc, ogg_packet *op, ogg_packet *op_comm, ogg_packet *op_code )  {
+                    return vorbis_analysis_headerout ( &this->data, vc , op , op_comm , op_code ); }
+
+                int synthesis_init ( vorbis_info *vi )  {
+                    return vorbis_synthesis_init ( &this->data, vi ); }
+
+                int synthesis_blockin ( vorbis_block *vb )  {
+                    return vorbis_synthesis_blockin ( &this->data, vb ); }
+
+                int block_init ( vorbis_block *vb )  {
+                    return vorbis_block_init ( &this->data, vb ); }
+
+            public:
+                /// this struct holds a reference to vorbis_info
+                vorbis_dsp_state data;
+                vorbis_dsp_state *get_data()  { return &this->data; }
+
+                int block_init ( block *vb )  {
+                    return this->block_init ( &vb->data ); }
+
+                double granule_time ( ogg_int64_t granulepos )  {
+                    return vorbis_granule_time ( &this->data, granulepos ); }
+
+                int bitrate_flushpacket ( packet *op )  {
+                    return this->bitrate_flushpacket ( op->get_data() ); }
+
+                ////////////// ANALYSIS //////////////////
+
+                int analysis_init ( info *vi )  {
+                    return this->analysis_init ( &vi->data ); }
+
+                float **analysis_buffer ( int vals )  {
+                    return vorbis_analysis_buffer ( &this->data, vals ); }
+
+                int analysis_wrote ( int vals )  {
+                    return vorbis_analysis_wrote ( &this->data, vals ); }
+
+                int analysis_blockout ( block *vb )  {
+                    return this->analysis_blockout ( &vb->data ); }        
+
+                // spits out three headers.
+                int analysis_headerout ( comment *vc, 
+                                         packet *op, 
+                                         packet *op_comm, 
+                                         packet *op_code )  {
+                    return this->analysis_headerout ( &vc->data , 
+                                                      op->get_data() , 
+                                                      op_comm->get_data() , 
+                                                      op_code->get_data() ); }
+
+
+                ////////////// SYNTHESIS //////////////////
+
+                int synthesis_init ( info *vi )  {
+                    return this->synthesis_init ( &vi->data ); }
+
+                int synthesis_blockin ( block *vb )  {
+                    return this->synthesis_blockin ( &vb->data ); }
+
+                int synthesis_lapout ( float ***pcm )  {
+                    return vorbis_synthesis_lapout ( &this->data, pcm ); }
+
+                int synthesis_pcmout ( float ***pcm )  {
+                    return vorbis_synthesis_pcmout ( &this->data, pcm ); }
+
+                int synthesis_read ( int samples )  {
+                    return vorbis_synthesis_read ( &this->data, samples ); }
+
+                int synthesis_restart ( )  {
+                    return vorbis_synthesis_restart ( &this->data ); }
+
+
+                void dsp_clear ( )  {
+                    vorbis_dsp_clear ( &this->data ); }
+        };
+    };
+};
+
+#endif
+
+/* Vorbis ERRORS and return codes **
+
+#define OV_FALSE      -1  
+#define OV_EOF        -2
+#define OV_HOLE       -3
+
+#define OV_EREAD      -128
+#define OV_EFAULT     -129
+#define OV_EIMPL      -130
+#define OV_EINVAL     -131
+#define OV_ENOTVORBIS -132
+#define OV_EBADHEADER -133
+#define OV_EVERSION   -134
+#define OV_ENOTAUDIO  -135
+#define OV_EBADPACKET -136
+#define OV_EBADLINK   -137
+#define OV_ENOSEEK    -138
+
+ *************************************/

Added: experimental/dholth/oggpy/vorbispy.cpp
===================================================================
--- experimental/dholth/oggpy/vorbispy.cpp	2004-11-23 02:15:58 UTC (rev 8260)
+++ experimental/dholth/oggpy/vorbispy.cpp	2004-11-23 02:33:04 UTC (rev 8261)
@@ -0,0 +1,80 @@
+
+// Boost Includes ==============================================================
+#include <boost/python.hpp>
+#include <boost/cstdint.hpp>
+
+// Includes ====================================================================
+#include <vorbispy_wrappers.h>
+
+// Using =======================================================================
+using namespace boost::python;
+
+// Module ======================================================================
+BOOST_PYTHON_MODULE(vorbispy)
+{
+    class_< ogg::vorbis::comment >("comment", init<  >())
+        .def(init< const ogg::vorbis::comment& >())
+        .def_readwrite("data", &ogg::vorbis::comment::data)
+        .def("query", &ogg::vorbis::comment::query)
+        .def("query_count", &ogg::vorbis::comment::query_count)
+        .def("add", &ogg::vorbis::comment::add)
+        .def("add_tag", &ogg::vorbis::comment::add_tag)
+        .def("header_out", (int (ogg::vorbis::comment::*)(ogg::packet*) )&ogg::vorbis::comment::header_out)
+        .def("query_index", &ogg::vorbis::comment::query_index)
+        .def("size", &ogg::vorbis::comment::size)
+        .def("get_comments", &get_comments)
+    ;
+
+    class_< ogg::vorbis::info >("info", init<  >())
+        .def(init< const ogg::vorbis::info& >())
+        .def_readwrite("data", &ogg::vorbis::info::data)
+        .def("encode_init", &ogg::vorbis::info::encode_init)
+        .def("encode_setup_managed", &ogg::vorbis::info::encode_setup_managed)
+        .def("encode_setup_vbr", &ogg::vorbis::info::encode_setup_vbr)
+        .def("encode_init_vbr", &ogg::vorbis::info::encode_init_vbr)
+        .def("encode_ctl", &ogg::vorbis::info::encode_ctl)
+        .def("encode_setup_init", &ogg::vorbis::info::encode_setup_init)
+        .def("info_blocksize", &ogg::vorbis::info::info_blocksize)
+        .def("synthesis_halfrate", &ogg::vorbis::info::synthesis_halfrate)
+        .def("synthesis_halfrate_p", &ogg::vorbis::info::synthesis_halfrate_p)
+        .def("synthesis_headerin", (int (ogg::vorbis::info::*)(ogg::vorbis::comment*, ogg::packet*) )&ogg::vorbis::info::synthesis_headerin)
+        .def("packet_blocksize", (long int (ogg::vorbis::info::*)(ogg::packet*) )&ogg::vorbis::info::packet_blocksize)
+        .def("get_version", &ogg::vorbis::info::get_version)
+        .def("get_channels", &ogg::vorbis::info::get_channels)
+        .def("get_rate", &ogg::vorbis::info::get_rate)
+    ;
+
+    class_< ogg::vorbis::block >("block", init<  >())
+        .def(init< const ogg::vorbis::block& >())
+        .def_readwrite("data", &ogg::vorbis::block::data)
+        .def("analysis", (int (ogg::vorbis::block::*)(ogg::packet*) )&ogg::vorbis::block::analysis)
+        .def("bitrate_addblock", &ogg::vorbis::block::bitrate_addblock)
+        .def("block_clear", &ogg::vorbis::block::block_clear)
+        .def("synthesis", (int (ogg::vorbis::block::*)(ogg::packet*) )&ogg::vorbis::block::synthesis)
+        .def("synthesis_trackonly", (int (ogg::vorbis::block::*)(ogg::packet*) )&ogg::vorbis::block::synthesis_trackonly)
+    ;
+
+    class_< ogg::vorbis::dsp >("dsp", init<  >())
+        .def(init< const ogg::vorbis::dsp& >())
+        .def_readwrite("data", &ogg::vorbis::dsp::data)
+        .def("block_init", (int (ogg::vorbis::dsp::*)(ogg::vorbis::block*) )&ogg::vorbis::dsp::block_init)
+        .def("granule_time", &ogg::vorbis::dsp::granule_time)
+        .def("bitrate_flushpacket", (int (ogg::vorbis::dsp::*)(ogg::packet*) )&ogg::vorbis::dsp::bitrate_flushpacket)
+        .def("analysis_init", (int (ogg::vorbis::dsp::*)(ogg::vorbis::info*) )&ogg::vorbis::dsp::analysis_init)
+        .def("analysis_wrote", &ogg::vorbis::dsp::analysis_wrote)
+        .def("analysis_blockout", (int (ogg::vorbis::dsp::*)(ogg::vorbis::block*) )&ogg::vorbis::dsp::analysis_blockout)
+        .def("analysis_headerout", (int (ogg::vorbis::dsp::*)(ogg::vorbis::comment*, ogg::packet*, ogg::packet*, ogg::packet*) )&ogg::vorbis::dsp::analysis_headerout)
+        .def("synthesis_init", (int (ogg::vorbis::dsp::*)(ogg::vorbis::info*) )&ogg::vorbis::dsp::synthesis_init)
+        .def("synthesis_blockin", (int (ogg::vorbis::dsp::*)(ogg::vorbis::block*) )&ogg::vorbis::dsp::synthesis_blockin)
+        .def("synthesis_lapout", &ogg::vorbis::dsp::synthesis_lapout)
+        .def("synthesis_pcmout", &ogg::vorbis::dsp::synthesis_pcmout)
+        .def("synthesis_read", &ogg::vorbis::dsp::synthesis_read)
+        .def("synthesis_restart", &ogg::vorbis::dsp::synthesis_restart)
+        .def("dsp_clear", &ogg::vorbis::dsp::dsp_clear)
+        .def("analysis_write", &oggpy_analysis_write)
+        .def("synthesis_pcmout", &oggpy_synthesis_pcmout)
+    ;
+
+    oggpy_wrappers_init();
+}
+

Modified: experimental/dholth/oggpy/vorbispy_wrappers.cc
===================================================================
--- experimental/dholth/oggpy/vorbispy_wrappers.cc	2004-11-23 02:15:58 UTC (rev 8260)
+++ experimental/dholth/oggpy/vorbispy_wrappers.cc	2004-11-23 02:33:04 UTC (rev 8261)
@@ -8,6 +8,7 @@
 #include <string.h>
 #include <vorbis/codec.h>
 #include <numarray/libnumarray.h>
+#include <fenv.h>
 
 using namespace ogg;
 using namespace boost::python;
@@ -24,11 +25,14 @@
 PyObject *oggpy_synthesis_pcmout(ogg::vorbis::dsp *dsp)
 {
   PyArrayObject *pcmarray = NULL;
+  PyObject *retval;
   float **pcm;
   float *mono;
   int samples;
   int channels;
+  fenv_t env;
 
+  feholdexcept(&env);
   samples = dsp->synthesis_pcmout(&pcm);
   
   if(samples > 0)
@@ -41,11 +45,15 @@
       memcpy((void*)mono, (void*)*(pcm+i), samples*sizeof(float));
     }
     vorbis_synthesis_read(&dsp->data, samples);
-    return NA_ReturnOutput(NULL, pcmarray);
+    retval = NA_ReturnOutput(NULL, pcmarray);  
+  } else {
+    Py_INCREF(Py_None);
+    retval = Py_None;
   }
+  
+  feupdateenv(&env);
 
-  Py_INCREF(Py_None);
-  return Py_None;
+  return retval;
 }
 
 



More information about the commits mailing list