[xiph-commits] r7456 - trunk/vorbisfile-python
jack at motherfish-iii.xiph.org
jack
Thu Aug 5 19:07:24 PDT 2004
Author: jack
Date: Thu Aug 5 19:07:24 2004
New Revision: 7456
Modified:
trunk/vorbisfile-python/test.py
trunk/vorbisfile-python/test_float.py
trunk/vorbisfile-python/vorbisfile.c
trunk/vorbisfile-python/vorbisfile.py
Log:
First pass of vorbisfile wrapper around _vorbisfile.
Modified: trunk/vorbisfile-python/test.py
===================================================================
--- trunk/vorbisfile-python/test.py 2004-08-03 00:42:04 UTC (rev 7455)
+++ trunk/vorbisfile-python/test.py 2004-08-03 02:57:43 UTC (rev 7456)
@@ -1,13 +1,14 @@
import ossaudiodev
-import _vorbisfile
+from vorbisfile import *
adev = ossaudiodev.open('w')
adev.setfmt(ossaudiodev.AFMT_S16_BE)
adev.channels(2)
adev.speed(44100)
-vf = _vorbisfile.ov_open(open('/home/jack/test.ogg'))
+vf = VorbisFile()
+vf.open('/home/jack/test.ogg')
-len, data, cs = _vorbisfile.ov_read(vf, 4096, 1, 2, 1)
+data, cs = vf.read(4096, bendian=1)
while len > 0:
adev.write(data)
- len, data, cs = _vorbisfile.ov_read(vf, 4096, 1, 2, 1)
+ data, cs = vf.read(4096, bendian=1)
Modified: trunk/vorbisfile-python/test_float.py
===================================================================
--- trunk/vorbisfile-python/test_float.py 2004-08-03 00:42:04 UTC (rev 7455)
+++ trunk/vorbisfile-python/test_float.py 2004-08-03 02:57:43 UTC (rev 7456)
@@ -1,25 +1,27 @@
import struct
import ossaudiodev
-import _vorbisfile
+from vorbisfile import *
adev = ossaudiodev.open('w')
adev.setfmt(ossaudiodev.AFMT_S16_BE)
adev.channels(2)
adev.speed(44100)
-vf = _vorbisfile.ov_open(open('/home/jack/test.ogg'))
-num, data, cs = _vorbisfile.ov_read_float(vf, 4096)
-while num > 0:
+vf = VorbisFile()
+vf.open('/home/jack/test.ogg')
+
+
+data, cs = vf.read(8192, format=FORMAT_FLOAT)
+while len(data) > 0:
buffer = ''
- for j in range(num):
- l = int(data[0][j]*32768)
- r = int(data[1][j]*32768)
- if l > 32767: l = 32767
- if r > 32767: r = 32767
- if l < -32768: l = -32768
- if r < -32768: r = -32768
- buffer += struct.pack("hh", l, r)
+ for j in range(len(data[0])):
+ l = int(data[0][j]*32768)
+ r = int(data[1][j]*32768)
+ if l > 32767: l = 32767
+ if r > 32767: r = 32767
+ if l < -32768: l = -32768
+ if r < -32768: r = -32768
+ buffer += struct.pack("hh", l, r)
adev.write(buffer)
-
- num, data, cs = _vorbisfile.ov_read_float(vf, 4096)
+ data, cs = vf.read(8192, format=FORMAT_FLOAT)
Modified: trunk/vorbisfile-python/vorbisfile.c
===================================================================
--- trunk/vorbisfile-python/vorbisfile.c 2004-08-03 00:42:04 UTC (rev 7455)
+++ trunk/vorbisfile-python/vorbisfile.c 2004-08-03 02:57:43 UTC (rev 7456)
@@ -790,7 +790,7 @@
static PyObject *ov_read_float_py(PyObject *self, PyObject *args)
{
- PyObject *cobj, *result, **channel, *list;
+ PyObject *cobj, *result, *channel[255], *list;
long ret;
int current_section, samples, channels, i, j;
float **pcm_channels;
@@ -815,7 +815,6 @@
for (i=0; i<channels; i++) {
channel[i] = PyList_New(ret);
PyList_SetItem(list, i, channel[i]);
-
for (j=0; j<ret; j++) {
PyList_SetItem(channel[i], j,
PyFloat_FromDouble(pcm_channels[i][j]));
Modified: trunk/vorbisfile-python/vorbisfile.py
===================================================================
--- trunk/vorbisfile-python/vorbisfile.py 2004-08-03 00:42:04 UTC (rev 7455)
+++ trunk/vorbisfile-python/vorbisfile.py 2004-08-03 02:57:43 UTC (rev 7456)
@@ -1,6 +1,15 @@
import types
from _vorbisfile import *
+MODE_RAW = 0
+MODE_PCM = 1
+MODE_TIME = 2
+MODE_PAGE = 4
+MODE_LAP = 8
+
+FORMAT_INT = 0
+FORMAT_FLOAT = 1
+
class VorbisFile(object):
def __init__(self):
self.vf = None
@@ -34,12 +43,12 @@
def clear(self):
return ov_clear(self.vf)
- def bitrate(self, link=-1):
- return ov_bitrate(self.vf, link)
+ def bitrate(self, link=-1, instant=0):
+ if instant:
+ return ov_bitrate_instant(self.vf)
+ else:
+ return ov_bitrate(self.vf, link)
- def bitrate_instant(self):
- return ov_bitrate_instant(self.vf)
-
def links(self):
return ov_streams(self.vf)
@@ -49,5 +58,70 @@
def serialnumber(self, link=-1):
return ov_serialnumber(self.vf, link)
- def raw_length(self, link=-1):
- return ov_raw_total(self.vf, link)
+ def length(self, link=-1, mode=MODE_TIME):
+ if mode == MODE_RAW:
+ return ov_raw_total(self.vf, link)
+ elif mode == MODE_PCM:
+ return ov_pcm_total(self.vf, link)
+ elif mode == MODE_TIME:
+ return ov_time_total(self.vf, link)
+ else:
+ raise StandardError, "Unknown mode requested"
+
+ def seek(self, pos, mode=MODE_TIME):
+ if mode == MODE_RAW:
+ return ov_raw_seek(self.vf, pos)
+ elif mode == MODE_RAW | MODE_LAP:
+ return ov_raw_seek_lap(self.vf, pos)
+ elif mode == MODE_PCM:
+ return ov_pcm_seek(self.vf, pos)
+ elif mode == MODE_PCM | MODE_LAP:
+ return ov_pcm_seek_lap(self.vf, pos)
+ elif mode == MODE_PCM | MODE_PAGE:
+ return ov_pcm_seek_page(self.vf, pos)
+ elif mode == MODE_PCM | MODE_PAGE | MODE_LAP:
+ return ov_pcm_seek_page_lap(self.vf, pos)
+ elif mode == MODE_TIME:
+ return ov_time_seek(self.vf, pos)
+ elif mode == MODE_TIME | MODE_LAP:
+ return ov_time_seek_lap(self.vf, pos)
+ elif mode == MODE_TIME | MODE_PAGE:
+ return ov_time_seek_page(self.vf, pos)
+ elif mode == MODE_TIME | MODE_PAGE | MODE_LAP:
+ return ov_time_seek_page_lap(self.vf, pos)
+ else:
+ raise StandardError, "Unknown mode requested"
+
+ def tell(self, mode=MODE_TIME):
+ if mode == MODE_RAW:
+ return ov_raw_tell(self.vf)
+ elif mode == MODE_PCM:
+ return ov_pcm_tell(self.vf)
+ elif mode == MODE_TIME:
+ return ov_time_tell(self.vf)
+ else:
+ raise StandardError, "Unknown mode requested"
+
+ def info(self):
+ return ov_info(self.vf)
+
+ def comments(self):
+ return ov_comment(self.vf)
+
+ def read(self, num, format=FORMAT_INT, wordsize=2, signed=1, bendian=0):
+ if format == FORMAT_FLOAT:
+ samps, data, cs = ov_read_float(self.vf, num)
+ return data, cs
+ elif format == FORMAT_INT:
+ real_num = num * wordsize * 2 # FIXME: get number channels
+ samps, data, cs = ov_read(self.vf, real_num, bendian,
+ wordsize, signed)
+ return data, cs
+ else:
+ raise StandardError, "Unknown format requested"
+
+ def halfrate(self, flag):
+ return ov_halfrate(self.vf, flag)
+
+ def halfratable(self):
+ return ov_halfrate(self.vf)
More information about the commits
mailing list