2 #include <vorbis/vorbisfile.h>
4 static size_t read_func(void *ptr
, size_t size
, size_t nmemb
, void *datasource
)
7 PyObject
*arglist
, *result
;
11 file
= (PyObject
*)datasource
;
12 read
= PyObject_GetAttrString(file
, "read");
14 arglist
= Py_BuildValue("(i)", size
*nmemb
);
15 result
= PyEval_CallObject(read
, arglist
);
19 printf("DEBUG: got null result from read()\n");
24 if (!PyString_Check(result
)) {
25 printf("DEBUG: result is not a string!\n");
26 PyErr_SetString(PyExc_StandardError
, "Result of read callback not a string");
31 strsize
= PyString_Size(result
);
32 str
= PyString_AsString(result
);
33 memcpy(ptr
, (void *)str
, strsize
);
40 static int seek_func(void *datasource
, ogg_int64_t offset
, int whence
)
42 PyObject
*file
, *seek
, *result
;
46 file
= (PyObject
*)datasource
;
47 seek
= PyObject_GetAttrString(file
, "seek");
50 arglist
= Py_BuildValue("(li)", (long)offset
, whence
);
51 result
= PyEval_CallObject(seek
, arglist
);
55 printf("DEBUG: got null result from seek\n");
60 ret
= PyInt_AsLong(result
);
66 static int close_func(void *datasource
)
68 PyObject
*file
, *close
;
71 file
= (PyObject
*)datasource
;
72 close
= PyObject_GetAttrString(file
, "close");
74 result
= PyEval_CallObject(close
, NULL
);
75 if (result
!= NULL
) Py_DECREF(result
);
82 static long tell_func(void *datasource
)
84 PyObject
*file
, *tell
;
88 file
= (PyObject
*)datasource
;
89 tell
= PyObject_GetAttrString(file
, "tell");
91 result
= PyEval_CallObject(tell
, NULL
);
94 printf("DEBUG: got null result from tell\n");
99 if (PyLong_Check(result
)) {
100 ret
= PyLong_AsLong(result
);
101 } else if (PyInt_Check(result
)) {
102 ret
= PyInt_AsLong(result
);
104 printf("DEBUG: got non-long/non-int from tell\n");
111 static void vf_destroy(void *data
)
113 ov_clear((OggVorbis_File
*)data
);
117 ** returns a vorbisfile object
119 static PyObject
*ov_open_py(PyObject
*self
, PyObject
*args
)
121 PyObject
*file
, *read
, *seek
, *close
, *tell
;
123 ov_callbacks callbacks
;
127 if (!PyArg_ParseTuple(args
, "O", &file
)) {
128 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
132 if (!PyFile_Check(file
)) {
133 PyErr_SetString(PyExc_TypeError
, "Expected a file object");
137 /* setup callback functions */
138 callbacks
.read_func
= read_func
;
139 callbacks
.seek_func
= seek_func
;
140 callbacks
.tell_func
= tell_func
;
141 callbacks
.close_func
= close_func
;
144 vf
= (OggVorbis_File
*)PyMem_Malloc(sizeof(OggVorbis_File
));
146 ret
= ov_open_callbacks((void *)file
, vf
, NULL
, 0, callbacks
);
148 /* FIXME: handle open failures more gracefully */
149 PyErr_SetString(PyExc_StandardError
, "ov_open failed");
150 PyMem_Free((void *)vf
);
154 result
= PyCObject_FromVoidPtr((void *)vf
, vf_destroy
);
159 static PyObject
*ov_test_py(PyObject
*self
, PyObject
*args
)
161 PyObject
*file
, *read
, *seek
, *close
, *tell
;
163 ov_callbacks callbacks
;
167 if (!PyArg_ParseTuple(args
, "O", &file
)) {
168 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
172 if (!PyFile_Check(file
)) {
173 PyErr_SetString(PyExc_TypeError
, "Expected a file object");
177 /* setup callback functions */
178 callbacks
.read_func
= read_func
;
179 callbacks
.seek_func
= seek_func
;
180 callbacks
.tell_func
= tell_func
;
181 callbacks
.close_func
= close_func
;
184 vf
= (OggVorbis_File
*)PyMem_Malloc(sizeof(OggVorbis_File
));
186 ret
= ov_test_callbacks((void *)file
, vf
, NULL
, 0, callbacks
);
188 /* FIXME: implement error handling */
189 PyErr_SetString(PyExc_StandardError
, "ov_test failed");
190 PyMem_Free((void *)vf
);
194 result
= PyCObject_FromVoidPtr((void *)vf
, vf_destroy
);
199 static PyObject
*ov_test_open_py(PyObject
*self
, PyObject
*args
)
201 PyObject
*cobj
, *result
;
205 if (!PyArg_ParseTuple(args
, "O", &cobj
)) {
206 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
210 if (!PyCObject_Check(cobj
)) {
211 PyErr_SetString(PyExc_TypeError
, "Expected a vorbisfile object");
215 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
216 ret
= ov_test_open(vf
);
218 result
= Py_BuildValue("i", ret
);
222 static PyObject
*ov_clear_py(PyObject
*self
, PyObject
*args
)
229 if (!PyArg_ParseTuple(args
, "O", &cobj
)) {
230 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
234 if (!PyCObject_Check(cobj
)) {
235 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
239 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
242 result
= Py_BuildValue("i", ret
);
246 static PyObject
*ov_bitrate_py(PyObject
*self
, PyObject
*args
)
248 PyObject
*cobj
, *result
;
253 if (!PyArg_ParseTuple(args
, "Oi", &cobj
, &link
)) {
254 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
258 if (!PyCObject_Check(cobj
)) {
259 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
263 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
265 ret
= ov_bitrate(vf
, link
);
267 result
= Py_BuildValue("i", ret
);
271 static PyObject
*ov_bitrate_instant_py(PyObject
*self
, PyObject
*args
)
273 PyObject
*cobj
, *result
;
277 if (!PyArg_ParseTuple(args
, "O", &cobj
)) {
278 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
282 if (!PyCObject_Check(cobj
)) {
283 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
287 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
288 ret
= ov_bitrate_instant(vf
);
290 result
= Py_BuildValue("i", ret
);
294 static PyObject
*ov_streams_py(PyObject
*self
, PyObject
*args
)
296 PyObject
*cobj
, *result
;
300 if (!PyArg_ParseTuple(args
, "O", &cobj
)) {
301 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
305 if (!PyCObject_Check(cobj
)) {
306 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
310 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
311 ret
= ov_streams(vf
);
313 result
= Py_BuildValue("i", ret
);
317 static PyObject
*ov_seekable_py(PyObject
*self
, PyObject
*args
)
319 PyObject
*cobj
, *result
;
323 if (!PyArg_ParseTuple(args
, "O", &cobj
)) {
324 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
328 if (!PyCObject_Check(cobj
)) {
329 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
333 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
334 ret
= ov_seekable(vf
);
336 result
= Py_BuildValue("i", ret
);
340 static PyObject
*ov_serialnumber_py(PyObject
*self
, PyObject
*args
)
342 PyObject
*cobj
, *result
;
347 if (!PyArg_ParseTuple(args
, "Oi", &cobj
, &link
)) {
348 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
352 if (!PyCObject_Check(cobj
)) {
353 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
357 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
358 ret
= ov_serialnumber(vf
, link
);
360 result
= Py_BuildValue("i", ret
);
364 static PyObject
*ov_raw_total_py(PyObject
*self
, PyObject
*args
)
366 PyObject
*cobj
, *result
;
371 if (!PyArg_ParseTuple(args
, "Oi", &cobj
, &link
)) {
372 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
376 if (!PyCObject_Check(cobj
)) {
377 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
381 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
382 ret
= ov_raw_total(vf
, link
);
384 result
= PyLong_FromLongLong(ret
);
388 static PyObject
*ov_pcm_total_py(PyObject
*self
, PyObject
*args
)
390 PyObject
*cobj
, *result
;
395 if (!PyArg_ParseTuple(args
, "Oi", &cobj
, &link
)) {
396 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
400 if (!PyCObject_Check(cobj
)) {
401 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
405 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
406 ret
= ov_pcm_total(vf
, link
);
408 result
= PyLong_FromLongLong(ret
);
412 static PyObject
*ov_time_total_py(PyObject
*self
, PyObject
*args
)
414 PyObject
*cobj
, *result
;
419 if (!PyArg_ParseTuple(args
, "Oi", &cobj
, &link
)) {
420 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
424 if (!PyCObject_Check(cobj
)) {
425 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
429 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
430 ret
= ov_time_total(vf
, link
);
432 result
= Py_BuildValue("d", ret
);
436 static PyObject
*ov_raw_seek_py(PyObject
*self
, PyObject
*args
)
438 PyObject
*cobj
, *result
;
443 if (!PyArg_ParseTuple(args
, "OL", &cobj
, &pos
)) {
444 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
448 if (!PyCObject_Check(cobj
)) {
449 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
453 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
454 ret
= ov_raw_seek(vf
, pos
);
456 result
= Py_BuildValue("i", ret
);
460 static PyObject
*ov_pcm_seek_py(PyObject
*self
, PyObject
*args
)
462 PyObject
*cobj
, *result
;
467 if (!PyArg_ParseTuple(args
, "OL", &cobj
, &pos
)) {
468 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
472 if (!PyCObject_Check(cobj
)) {
473 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
477 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
478 ret
= ov_pcm_seek(vf
, pos
);
480 result
= Py_BuildValue("i", ret
);
484 static PyObject
*ov_pcm_seek_page_py(PyObject
*self
, PyObject
*args
)
486 PyObject
*cobj
, *result
;
491 if (!PyArg_ParseTuple(args
, "OL", &cobj
, &pos
)) {
492 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
496 if (!PyCObject_Check(cobj
)) {
497 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
501 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
502 ret
= ov_pcm_seek_page(vf
, pos
);
504 result
= Py_BuildValue("i", ret
);
508 static PyObject
*ov_time_seek_py(PyObject
*self
, PyObject
*args
)
510 PyObject
*cobj
, *result
;
515 if (!PyArg_ParseTuple(args
, "Od", &cobj
, &pos
)) {
516 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
520 if (!PyCObject_Check(cobj
)) {
521 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
525 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
526 ret
= ov_time_seek(vf
, pos
);
528 result
= Py_BuildValue("i", ret
);
532 static PyObject
*ov_time_seek_page_py(PyObject
*self
, PyObject
*args
)
534 PyObject
*cobj
, *result
;
539 if (!PyArg_ParseTuple(args
, "Od", &cobj
, &pos
)) {
540 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
544 if (!PyCObject_Check(cobj
)) {
545 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
549 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
550 ret
= ov_time_seek_page(vf
, pos
);
552 result
= Py_BuildValue("i", ret
);
556 static PyObject
*ov_raw_seek_lap_py(PyObject
*self
, PyObject
*args
)
558 PyObject
*cobj
, *result
;
563 if (!PyArg_ParseTuple(args
, "OL", &cobj
, &pos
)) {
564 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
568 if (!PyCObject_Check(cobj
)) {
569 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
573 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
574 ret
= ov_raw_seek_lap(vf
, pos
);
576 result
= Py_BuildValue("i", ret
);
580 static PyObject
*ov_pcm_seek_lap_py(PyObject
*self
, PyObject
*args
)
582 PyObject
*cobj
, *result
;
587 if (!PyArg_ParseTuple(args
, "OL", &cobj
, &pos
)) {
588 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
592 if (!PyCObject_Check(cobj
)) {
593 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
597 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
598 ret
= ov_pcm_seek_lap(vf
, pos
);
600 result
= Py_BuildValue("i", ret
);
604 static PyObject
*ov_pcm_seek_page_lap_py(PyObject
*self
, PyObject
*args
)
606 PyObject
*cobj
, *result
;
611 if (!PyArg_ParseTuple(args
, "OL", &cobj
, &pos
)) {
612 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
616 if (!PyCObject_Check(cobj
)) {
617 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
621 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
622 ret
= ov_pcm_seek_page_lap(vf
, pos
);
624 result
= Py_BuildValue("i", ret
);
628 static PyObject
*ov_time_seek_lap_py(PyObject
*self
, PyObject
*args
)
630 PyObject
*cobj
, *result
;
635 if (!PyArg_ParseTuple(args
, "Od", &cobj
, &pos
)) {
636 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
640 if (!PyCObject_Check(cobj
)) {
641 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
645 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
646 ret
= ov_time_seek_lap(vf
, pos
);
648 result
= Py_BuildValue("i", ret
);
652 static PyObject
*ov_time_seek_page_lap_py(PyObject
*self
, PyObject
*args
)
654 PyObject
*cobj
, *result
;
659 if (!PyArg_ParseTuple(args
, "Od", &cobj
, &pos
)) {
660 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
664 if (!PyCObject_Check(cobj
)) {
665 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
669 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
670 ret
= ov_time_seek_page_lap(vf
, pos
);
672 result
= Py_BuildValue("i", ret
);
676 static PyObject
*ov_raw_tell_py(PyObject
*self
, PyObject
*args
)
678 PyObject
*cobj
, *result
;
682 if (!PyArg_ParseTuple(args
, "O", &cobj
)) {
683 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
687 if (!PyCObject_Check(cobj
)) {
688 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
692 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
693 ret
= ov_raw_tell(vf
);
695 result
= PyLong_FromLongLong(ret
);
699 static PyObject
*ov_pcm_tell_py(PyObject
*self
, PyObject
*args
)
701 PyObject
*cobj
, *result
;
705 if (!PyArg_ParseTuple(args
, "O", &cobj
)) {
706 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
710 if (!PyCObject_Check(cobj
)) {
711 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
715 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
716 ret
= ov_pcm_tell(vf
);
718 result
= PyLong_FromLongLong(ret
);
722 static PyObject
*ov_time_tell_py(PyObject
*self
, PyObject
*args
)
724 PyObject
*cobj
, *result
;
728 if (!PyArg_ParseTuple(args
, "O", &cobj
)) {
729 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
733 if (!PyCObject_Check(cobj
)) {
734 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
738 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
739 ret
= ov_time_tell(vf
);
741 result
= Py_BuildValue("d", ret
);
745 static PyObject
*ov_info_py(PyObject
*self
, PyObject
*args
)
747 PyObject
*cobj
, *result
;
752 if (!PyArg_ParseTuple(args
, "Oi", &cobj
, &link
)) {
753 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
757 if (!PyCObject_Check(cobj
)) {
758 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
762 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
763 ret
= ov_info(vf
, link
);
765 result
= PyCObject_FromVoidPtr((void *)ret
, NULL
);
769 static PyObject
*ov_comment_py(PyObject
*self
, PyObject
*args
)
771 PyObject
*cobj
, *result
;
776 if (!PyArg_ParseTuple(args
, "Oi", &cobj
, &link
)) {
777 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
781 if (!PyCObject_Check(cobj
)) {
782 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
786 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
787 ret
= ov_comment(vf
, link
);
789 result
= PyCObject_FromVoidPtr((void *)ret
, NULL
);
793 static PyObject
*ov_read_float_py(PyObject
*self
, PyObject
*args
)
795 PyObject
*cobj
, *result
, *channel
[255], *list
;
797 int current_section
, samples
, channels
, i
, j
;
798 float **pcm_channels
;
801 if (!PyArg_ParseTuple(args
, "Oi", &cobj
, &samples
)) {
802 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
806 if (!PyCObject_Check(cobj
)) {
807 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
811 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
812 channels
= vf
->vi
->channels
;
814 ret
= ov_read_float(vf
, &pcm_channels
, samples
, ¤t_section
);
816 list
= PyList_New(channels
);
817 for (i
=0; i
<channels
; i
++) {
818 channel
[i
] = PyList_New(ret
);
819 PyList_SetItem(list
, i
, channel
[i
]);
820 for (j
=0; j
<ret
; j
++) {
821 PyList_SetItem(channel
[i
], j
,
822 PyFloat_FromDouble(pcm_channels
[i
][j
]));
827 result
= Py_BuildValue("(lOi)", ret
, list
, current_section
);
831 static PyObject
*ov_read_py(PyObject
*self
, PyObject
*args
)
833 PyObject
*cobj
, *result
;
835 int current_section
, len
, bigendianp
, word
, sgned
;
839 if (!PyArg_ParseTuple(args
, "Oiiii", &cobj
, &len
, &bigendianp
, &word
,
841 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
845 if (!PyCObject_Check(cobj
)) {
846 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
850 buffer
= (char *)PyMem_Malloc(len
);
851 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
852 ret
= ov_read(vf
, buffer
, len
, bigendianp
, word
, sgned
, ¤t_section
);
854 result
= Py_BuildValue("(ls#i)", ret
, buffer
, ret
, current_section
);
856 result
= Py_BuildValue("(ls#i)", ret
, buffer
, 0, current_section
);
862 static PyObject
*ov_crosslap_py(PyObject
*self
, PyObject
*args
)
864 PyObject
*cobj1
, *cobj2
, *result
;
866 OggVorbis_File
*vf1
, *vf2
;
868 if (!PyArg_ParseTuple(args
, "OO", &cobj1
, &cobj2
)) {
869 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
873 if (!PyCObject_Check(cobj1
)) {
874 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
878 if (!PyCObject_Check(cobj2
)) {
879 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
883 vf1
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj1
);
884 vf2
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj2
);
885 ret
= ov_crosslap(vf1
, vf2
);
887 result
= Py_BuildValue("i", ret
);
891 static PyObject
*ov_halfrate_py(PyObject
*self
, PyObject
*args
)
893 PyObject
*cobj
, *result
;
897 if (!PyArg_ParseTuple(args
, "Oi", &cobj
, &flag
)) {
898 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
902 if (!PyCObject_Check(cobj
)) {
903 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
907 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
908 ret
= ov_halfrate(vf
, flag
);
910 result
= Py_BuildValue("i", ret
);
914 static PyObject
*ov_halfrate_p_py(PyObject
*self
, PyObject
*args
)
916 PyObject
*cobj
, *result
;
920 if (!PyArg_ParseTuple(args
, "O", &cobj
)) {
921 PyErr_SetString(PyExc_StandardError
, "Couldn't parse arguments");
925 if (!PyCObject_Check(cobj
)) {
926 PyErr_SetString(PyExc_StandardError
, "Expected vorbisfile object");
930 vf
= (OggVorbis_File
*)PyCObject_AsVoidPtr(cobj
);
931 ret
= ov_halfrate_p(vf
);
933 result
= Py_BuildValue("i", ret
);
937 static PyMethodDef vorbisfileMethods
[] = {
938 {"ov_open", ov_open_py
, METH_VARARGS
,
939 "Opens a Vorbis file"},
940 {"ov_test", ov_test_py
, METH_VARARGS
,
941 "Tests if a file is a Vorbis file"},
942 {"ov_test_open", ov_test_open_py
, METH_VARARGS
,
943 "Opens a Vorbis file after testing"},
944 {"ov_clear", ov_clear_py
, METH_VARARGS
,
945 "Clears a vorbisfile object"},
946 {"ov_bitrate", ov_bitrate_py
, METH_VARARGS
,
947 "Returns bitrate of chain(s)"},
948 {"ov_bitrate_instant", ov_bitrate_instant_py
, METH_VARARGS
,
949 "Returns instantaneous bitrate"},
950 {"ov_streams", ov_streams_py
, METH_VARARGS
,
951 "Returns number of chains"},
952 {"ov_seekable", ov_seekable_py
, METH_VARARGS
,
953 "Returns whether stream is seekable"},
954 {"ov_serialnumber", ov_serialnumber_py
, METH_VARARGS
,
955 "Returns a link's serial number"},
956 {"ov_raw_total", ov_raw_total_py
, METH_VARARGS
,
957 "Returns total raw compressed length of bitstream"},
958 {"ov_pcm_total", ov_pcm_total_py
, METH_VARARGS
,
959 "Returns total number of PCM samples"},
960 {"ov_time_total", ov_time_total_py
, METH_VARARGS
,
961 "Returns total length of bitstream in seconds"},
962 {"ov_raw_seek", ov_raw_seek_py
, METH_VARARGS
,
963 "Seeks to an offset relative to compressed data"},
964 {"ov_pcm_seek", ov_pcm_seek_py
, METH_VARARGS
,
965 "Seeks to a sample offset of the PCM data"},
966 {"ov_pcm_seek_page", ov_pcm_seek_page_py
, METH_VARARGS
,
967 "Seeks to page near sample offset"},
968 {"ov_time_seek", ov_time_seek_py
, METH_VARARGS
,
969 "Seeks to sample at time"},
970 {"ov_time_seek_page", ov_time_seek_page_py
, METH_VARARGS
,
971 "Seeks to page near sample at time"},
972 {"ov_raw_seek_lap", ov_raw_seek_lap_py
, METH_VARARGS
,
973 "Seeks something (FIXME)"},
974 {"ov_pcm_seek_lap", ov_pcm_seek_lap_py
, METH_VARARGS
,
975 "Seeks something (FIXME)"},
976 {"ov_pcm_seek_page_lap", ov_pcm_seek_page_lap_py
, METH_VARARGS
,
977 "Seeks something (FIXME)"},
978 {"ov_time_seek_lap", ov_time_seek_lap_py
, METH_VARARGS
,
979 "Seeks something (FIXME)"},
980 {"ov_time_seek_page_lap", ov_time_seek_page_lap_py
, METH_VARARGS
,
981 "Seeks something (FIXME)"},
982 {"ov_raw_tell", ov_raw_tell_py
, METH_VARARGS
,
983 "Returns the current stream offset"},
984 {"ov_pcm_tell", ov_pcm_tell_py
, METH_VARARGS
,
985 "Returns PCM offset of next sample to be read"},
986 {"ov_time_tell", ov_time_tell_py
, METH_VARARGS
,
987 "Returns time offset of next sample to be read"},
988 {"ov_info", ov_info_py
, METH_VARARGS
,
989 "Returns the vorbis_info object for the current chain"},
990 {"ov_comment", ov_comment_py
, METH_VARARGS
,
991 "Returns the vorbis_comment object for the current chain"},
992 {"ov_read_float", ov_read_float_py
, METH_VARARGS
,
993 "Returns array of decoded float data"},
994 {"ov_read", ov_read_py
, METH_VARARGS
,
995 "Returns array of decoded sample data"},
996 {"ov_crosslap", ov_crosslap_py
, METH_VARARGS
,
997 "Crosses something (FIXME)"},
998 {"ov_halfrate", ov_halfrate_py
, METH_VARARGS
,
999 "Does something (FIXME)"},
1000 {"ov_halfrate_p", ov_halfrate_p_py
, METH_VARARGS
,
1001 "Does something (FIXME)"},
1002 {NULL
, NULL
, 0, NULL
}
1005 PyMODINIT_FUNC
init_vorbisfile(void)
1007 Py_InitModule("_vorbisfile", vorbisfileMethods
);