1 #include <Python.h> 2 #include <stdint.h> 3 #include <vorbis/vorbisfile.h> 4 #include "../array.h" 5 6 /******************************************************** 7 Audio Tools, a module and set of tools for manipulating audio data 8 Copyright (C) 2007-2014 Brian Langenberger 9 10 This program is free software; you can redistribute it and/or modify 11 it under the terms of the GNU General Public License as published by 12 the Free Software Foundation; either version 2 of the License, or 13 (at your option) any later version. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with this program; if not, write to the Free Software 22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 *******************************************************/ 24 25 typedef struct { 26 PyObject_HEAD 27 28 OggVorbis_File vorbisfile; 29 int open_ok; /*used to determine if vorbis_file is opened successfully*/ 30 31 int channel_count; 32 long rate; 33 int closed; 34 35 aa_int* channels; 36 PyObject* audiotools_pcm; 37 } decoders_VorbisDecoder; 38 39 static PyObject* 40 VorbisDecoder_sample_rate(decoders_VorbisDecoder *self, void *closure); 41 42 static PyObject* 43 VorbisDecoder_bits_per_sample(decoders_VorbisDecoder *self, void *closure); 44 45 static PyObject* 46 VorbisDecoder_channels(decoders_VorbisDecoder *self, void *closure); 47 48 static PyObject* 49 VorbisDecoder_channel_mask(decoders_VorbisDecoder *self, void *closure); 50 51 static PyObject* 52 VorbisDecoder_read(decoders_VorbisDecoder *self, PyObject *args); 53 54 static PyObject* 55 VorbisDecoder_close(decoders_VorbisDecoder *self, PyObject *args); 56 57 static PyObject* 58 VorbisDecoder_new(PyTypeObject *type, PyObject *args, PyObject *kwds); 59 60 void 61 VorbisDecoder_dealloc(decoders_VorbisDecoder *self); 62 63 int 64 VorbisDecoder_init(decoders_VorbisDecoder *self, PyObject *args, PyObject *kwds); 65 66 static PyObject* 67 VorbisDecoder_enter(decoders_VorbisDecoder* self, PyObject *args); 68 69 static PyObject* 70 VorbisDecoder_exit(decoders_VorbisDecoder* self, PyObject *args); 71 72 PyGetSetDef VorbisDecoder_getseters[] = { 73 {"sample_rate", (getter)VorbisDecoder_sample_rate, 74 NULL, "sample rate", NULL}, 75 {"bits_per_sample", (getter)VorbisDecoder_bits_per_sample, 76 NULL, "bits-per-sample", NULL}, 77 {"channels", (getter)VorbisDecoder_channels, NULL, 78 "channels", NULL}, 79 {"channel_mask", (getter)VorbisDecoder_channel_mask, 80 NULL, "channel mask", NULL}, 81 {NULL} 82 }; 83 84 PyMethodDef VorbisDecoder_methods[] = { 85 {"read", (PyCFunction)VorbisDecoder_read, METH_VARARGS, 86 "read(pcm_frame_count) -> FrameList"}, 87 {"close", (PyCFunction)VorbisDecoder_close, METH_NOARGS, 88 "close() -> None"}, 89 {"__enter__", (PyCFunction)VorbisDecoder_enter, 90 METH_NOARGS, "enter() -> self"}, 91 {"__exit__", (PyCFunction)VorbisDecoder_exit, 92 METH_VARARGS, "exit(exc_type, exc_value, traceback) -> None"}, 93 {NULL} 94 }; 95 96 PyTypeObject decoders_VorbisDecoderType = { 97 PyVarObject_HEAD_INIT(NULL, 0) 98 "decoders.VorbisDecoder", /*tp_name*/ 99 sizeof(decoders_VorbisDecoder), /*tp_basicsize*/ 100 0, /*tp_itemsize*/ 101 (destructor)VorbisDecoder_dealloc, /*tp_dealloc*/ 102 0, /*tp_print*/ 103 0, /*tp_getattr*/ 104 0, /*tp_setattr*/ 105 0, /*tp_compare*/ 106 0, /*tp_repr*/ 107 0, /*tp_as_number*/ 108 0, /*tp_as_sequence*/ 109 0, /*tp_as_mapping*/ 110 0, /*tp_hash */ 111 0, /*tp_call*/ 112 0, /*tp_str*/ 113 0, /*tp_getattro*/ 114 0, /*tp_setattro*/ 115 0, /*tp_as_buffer*/ 116 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ 117 "VorbisDecoder objects", /* tp_doc */ 118 0, /* tp_traverse */ 119 0, /* tp_clear */ 120 0, /* tp_richcompare */ 121 0, /* tp_weaklistoffset */ 122 0, /* tp_iter */ 123 0, /* tp_iternext */ 124 VorbisDecoder_methods, /* tp_methods */ 125 0, /* tp_members */ 126 VorbisDecoder_getseters, /* tp_getset */ 127 0, /* tp_base */ 128 0, /* tp_dict */ 129 0, /* tp_descr_get */ 130 0, /* tp_descr_set */ 131 0, /* tp_dictoffset */ 132 (initproc)VorbisDecoder_init, /* tp_init */ 133 0, /* tp_alloc */ 134 VorbisDecoder_new, /* tp_new */ 135 }; 136