[xiph-commits] r7448 - trunk/vorbisfile-python

jack at motherfish-iii.xiph.org jack
Thu Aug 5 19:06:40 PDT 2004


Author: jack
Date: Thu Aug  5 19:06:40 2004
New Revision: 7448

Added:
trunk/vorbisfile-python/test_float.py
Modified:
trunk/vorbisfile-python/vorbisfile.c
Log:
All functions implemented and working.


Added: trunk/vorbisfile-python/test_float.py
===================================================================
--- trunk/vorbisfile-python/test_float.py	2004-08-01 13:36:35 UTC (rev 7447)
+++ trunk/vorbisfile-python/test_float.py	2004-08-01 16:46:41 UTC (rev 7448)
@@ -0,0 +1,25 @@
+import struct
+import ossaudiodev
+import _vorbisfile
+
+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:
+    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)
+
+    adev.write(buffer)
+
+    num, data, cs = _vorbisfile.ov_read_float(vf, 4096)

Modified: trunk/vorbisfile-python/vorbisfile.c
===================================================================
--- trunk/vorbisfile-python/vorbisfile.c	2004-08-01 13:36:35 UTC (rev 7447)
+++ trunk/vorbisfile-python/vorbisfile.c	2004-08-01 16:46:41 UTC (rev 7448)
@@ -788,6 +788,45 @@
return result;
}

+static PyObject *ov_read_float_py(PyObject *self, PyObject *args)
+{
+    PyObject *cobj, *result, **channel, *list;
+    long ret;
+    int current_section, samples, channels, i, j;
+    float **pcm_channels;
+    OggVorbis_File *vf;
+
+    if (!PyArg_ParseTuple(args, "Oi", &cobj, &samples)) {
+	PyErr_SetString(PyExc_StandardError, "Couldn't parse arguments");
+	return NULL;
+    }
+
+    if (!PyCObject_Check(cobj)) {
+	PyErr_SetString(PyExc_StandardError, "Expected vorbisfile object");
+	return NULL;
+    }
+
+    vf = (OggVorbis_File *)PyCObject_AsVoidPtr(cobj);
+    channels = vf->vi->channels;
+
+    ret = ov_read_float(vf, &pcm_channels, samples, &current_section);
+    if (ret > 0) {
+	list = PyList_New(channels);
+	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]));
+	    }
+	}
+    }
+
+    result = Py_BuildValue("(lOi)", ret, list, current_section);
+    return result;
+}
+
static PyObject *ov_read_py(PyObject *self, PyObject *args)
{
PyObject *cobj, *result;
@@ -947,8 +986,8 @@
"return something"},
{"ov_comment", ov_comment_py, METH_VARARGS,
"return something"},
-    //{"ov_read_float", ov_read_float_py, METH_VARARGS,
-    // "return something"},
+    {"ov_read_float", ov_read_float_py, METH_VARARGS,
+     "return something"},
{"ov_read", ov_read_py, METH_VARARGS,
"return something"},
{"ov_crosslap", ov_crosslap_py, METH_VARARGS,



More information about the commits mailing list