[xiph-commits] r8254 - in experimental/dholth/oggpy: . tests
dholth at motherfish-iii.xiph.org
dholth at motherfish-iii.xiph.org
Mon Nov 22 18:01:03 PST 2004
Author: dholth
Date: 2004-11-22 18:01:03 -0800 (Mon, 22 Nov 2004)
New Revision: 8254
Modified:
experimental/dholth/oggpy/oggcc.h
experimental/dholth/oggpy/oggpy.pyste
experimental/dholth/oggpy/tests/decode.py
experimental/dholth/oggpy/vorbispy.pyste
Log:
patch-21
Modified: experimental/dholth/oggpy/oggcc.h
===================================================================
--- experimental/dholth/oggpy/oggcc.h 2004-11-23 01:58:20 UTC (rev 8253)
+++ experimental/dholth/oggpy/oggcc.h 2004-11-23 02:01:03 UTC (rev 8254)
@@ -5,6 +5,8 @@
* @author Daniel Holth <dholth at fastmail.fm>
*/
+// #include "oggpy_wrappers.h"
+
#ifndef OGGCC_H
#define OGGCC_H
@@ -50,7 +52,7 @@
userpacket(std::string bytes, ogg_int64_t granulepos, bool bos = false, bool eos = false)
{
this->bytes = bytes;
- (const char*)(this->get_data()->packet) = bytes.c_str();
+ (const char*)(this->get_data()->packet) = bytes.c_str();
this->get_data()->granulepos = granulepos;
this->get_data()->bytes = bytes.size();
this->get_data()->b_o_s = bos;
@@ -90,12 +92,19 @@
}
void writeinit ( ) { oggpack_writeinit ( this->get_data() ); }
+
+ /// Probably inefficient at the moment, but it's for a Python wraper.
+ ogg::packet packetout(ogg_int64_t granulepos, bool bos=false, bool eos=false) {
+ oggpack_buffer *opb = this->get_data();
+ return ogg::userpacket(std::string((const char*)opb->buffer,
+ oggpack_bytes(opb)), granulepos, bos, eos);
+ }
};
/// Little-endian bitpacker.
class oggpack : public oggpack_base {
-
+ public:
long bits ( ) { return oggpack_bits ( this->get_data() ); }
long bytes ( ) { return oggpack_bytes ( this->get_data() ); }
long look ( int bits ) { return oggpack_look ( this->get_data(), bits ); }
@@ -118,7 +127,7 @@
/// Big-endian bitpacker
class oggpackB : public oggpack_base {
-
+ public:
long bits ( ) { return oggpackB_bits ( this->get_data() ); }
long bytes ( ) { return oggpackB_bytes ( this->get_data() ); }
long look ( int bits ) { return oggpackB_look ( this->get_data(), bits ); }
Modified: experimental/dholth/oggpy/oggpy.pyste
===================================================================
--- experimental/dholth/oggpy/oggpy.pyste 2004-11-23 01:58:20 UTC (rev 8253)
+++ experimental/dholth/oggpy/oggpy.pyste 2004-11-23 02:01:03 UTC (rev 8254)
@@ -3,30 +3,63 @@
element._Attribute('doc', blurb)
Include("oggpy_wrappers.h")
+Include("oggcc.h")
-oggpy = AllFromHeader("oggcc.h")
+# oggpy = AllFromHeader("oggcc.h")
# exclude(oggpy.oggpack_base)
-exclude(oggpy.oggpack_base.get_data)
-exclude(oggpy.oggpack_base.get_buffer)
-exclude(oggpy.oggpack.get_buffer)
-exclude(oggpy.oggpack.get_data)
-exclude(oggpy.oggpackB.get_buffer)
-exclude(oggpy.oggpackB.get_data)
-exclude(oggpy.packet.data)
-exclude(oggpy.packet.get_data)
-exclude(oggpy.page.data)
-exclude(oggpy.page.get_data)
-exclude(oggpy.stream.data)
-exclude(oggpy.sync.buffer)
-exclude(oggpy.sync.data)
-exclude(oggpy.sync.wrote)
-exclude(oggpy.userpacket.get_data)
+# exclude(oggpy.oggpack_base.get_data)
+# exclude(oggpy.oggpack_base.get_buffer)
+# exclude(oggpy.oggpack.get_buffer)
+# exclude(oggpy.oggpack.get_data)
+# exclude(oggpy.oggpackB.get_buffer)
+# exclude(oggpy.oggpackB.get_data)
+# exclude(oggpy.packet.data)
+# exclude(oggpy.packet.get_data)
+# exclude(oggpy.page.data)
+# exclude(oggpy.page.get_data)
+# exclude(oggpy.stream.data)
+# exclude(oggpy.sync.buffer)
+# exclude(oggpy.sync.data)
+# exclude(oggpy.sync.wrote)
+# exclude(oggpy.userpacket.get_data)
+#
+# syncwrite = Function("ogg::sync_write", "oggpy_wrappers.h")
+# oggpy.syncwrite = syncwrite
+#
+# document(oggpy.sync, "Separate streams into ogg pages")
+# document(oggpy.sync.pageout, "Produce a page.")
+#
+# add_method(oggpy.sync, "sync_write")
-syncwrite = Function("ogg::sync_write", "oggpy_wrappers.h")
-oggpy.syncwrite = syncwrite
+# New AllFromHeader-free version:
+
+packet = Class("ogg::packet", "oggcc.h")
+userpacket = Class("ogg::userpacket", "oggcc.h")
+oggpack_base = Class("ogg::oggpack_base", "oggcc.h")
+oggpack = Class("ogg::oggpack", "oggcc.h")
+oggpackB = Class("ogg::oggpackB", "oggcc.h")
+page = Class("ogg::page", "oggcc.h")
+sync = Class("ogg::sync", "oggpy_wrappers.h")
+stream = Class("ogg::stream", "oggcc.h")
-document(oggpy.sync, "Separate streams into ogg pages")
-document(oggpy.sync.pageout, "Produce a page.")
+exclude(oggpack_base.get_data)
+exclude(oggpack_base.get_buffer)
+exclude(oggpack.get_buffer)
+exclude(oggpack.get_data)
+exclude(oggpackB.get_buffer)
+exclude(oggpackB.get_data)
+exclude(packet.data)
+exclude(packet.get_data)
+exclude(page.data)
+exclude(page.get_data)
+exclude(stream.data)
+exclude(sync.buffer)
+exclude(sync.data)
+exclude(sync.wrote)
+exclude(userpacket.get_data)
-# add_method(oggpy.sync, "sync_write")
+syncwrite = Function("ogg::sync_write", "oggpy_wrappers.h")
+add_method(sync, "ogg::sync_write")
+rename(sync.sync_write, "write")
+exclude(syncwrite)
Modified: experimental/dholth/oggpy/tests/decode.py
===================================================================
--- experimental/dholth/oggpy/tests/decode.py 2004-11-23 01:58:20 UTC (rev 8253)
+++ experimental/dholth/oggpy/tests/decode.py 2004-11-23 02:01:03 UTC (rev 8254)
@@ -5,8 +5,10 @@
#
# Daniel Holth <dholth at fastmail.fm>, 2004
+import oss
+import sys
import oggpy
-import sys
+import vorbispy
import numarray
BUFSIZE=8192
@@ -17,14 +19,20 @@
oy = oggpy.sync()
og = oggpy.page()
op = oggpy.packet()
- vi = oggpy.info()
- vd = oggpy.dsp()
- vb = oggpy.block()
- vc = oggpy.comment()
+
+ vi = vorbispy.info()
+ vd = vorbispy.dsp()
+ vb = vorbispy.block()
+ vc = vorbispy.comment()
+ audio = oss.open_audio()
+ audio.stereo(1)
+ audio.format(oss.AFMT_S16_LE)
+ audio.speed(44100)
+
while 1:
buffer = ogg.read(BUFSIZE)
- oggpy.sync_write(oy, buffer)
+ oy.write(buffer)
if oy.pageout(og) != 1:
if len(buffer) < BUFSIZE: break
@@ -66,9 +74,9 @@
print >> sys.stderr, "EOF before finding all vorbis headers!"
sys.exit(1)
- oggpy.sync_write(oy, buffer)
+ oy.write(buffer)
- print >> sys.stderr, oggpy.get_comments(vc)
+ print >> sys.stderr, vorbispy.get_comments(vc)
vd.synthesis_init(vi)
vd.block_init(vb)
@@ -91,25 +99,33 @@
if vb.synthesis(op) == 0:
vd.synthesis_blockin(vb)
- samples = oggpy.oggpy_synthesis_pcmout(vd)
+ samples = vorbispy.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)
+
+ # interleaved.tofile(outfile)
+ audio.write(interleaved.tostring())
- samples = oggpy.oggpy_synthesis_pcmout(vd)
+ samples = vorbispy.oggpy_synthesis_pcmout(vd)
if og.eos(): eos = True
if not eos:
buffer = ogg.read(BUFSIZE)
- oggpy.sync_write(oy, buffer)
+ oy.write(buffer)
if len(buffer) == 0: eos = True
if __name__ == "__main__":
- # test(sys.stdin)
- test(file("music.ogg", "r"))
+ if len(sys.argv) == 2:
+ if sys.argv[1] == "-":
+ test(sys.stdin)
+ else:
+ test(file(sys.argv[1], "rb"))
+ else:
+ test(file("music.ogg", "rb"))
Modified: experimental/dholth/oggpy/vorbispy.pyste
===================================================================
--- experimental/dholth/oggpy/vorbispy.pyste 2004-11-23 01:58:20 UTC (rev 8253)
+++ experimental/dholth/oggpy/vorbispy.pyste 2004-11-23 02:01:03 UTC (rev 8254)
@@ -6,6 +6,7 @@
exclude(vorbispy.dsp.analysis_buffer)
exclude(vorbispy.dsp.get_data)
exclude(vorbispy.comment.get_data)
+exclude(vorbispy.info.get_data)
# vorbispy.block.synthesis.infos.doc = "Synthesize things."
# #Function("oggpy_synthesis_pcmout", "oggpy_wrappers.h")
@@ -23,4 +24,4 @@
# #add_method(oggpy.sync, "ogg::sync_write")
# #rename(oggpy.sync.sync_write, "write")
-# module_code("oggpy_wrappers_init();\n")
+module_code("oggpy_wrappers_init();\n")
More information about the commits
mailing list