From 16782bb6c2ed5594cab4f70674c791fdaaa2dcdb Mon Sep 17 00:00:00 2001 From: Joerg Mueller Date: Tue, 3 Aug 2010 08:30:49 +0000 Subject: Audaspace Py API: Getting rid of unnecessary forward declarations. --- intern/audaspace/Python/AUD_PyAPI.cpp | 639 ++++++++++++++++------------------ 1 file changed, 302 insertions(+), 337 deletions(-) (limited to 'intern/audaspace') diff --git a/intern/audaspace/Python/AUD_PyAPI.cpp b/intern/audaspace/Python/AUD_PyAPI.cpp index adbaaa2bec4..c3f2efa9c3c 100644 --- a/intern/audaspace/Python/AUD_PyAPI.cpp +++ b/intern/audaspace/Python/AUD_PyAPI.cpp @@ -136,322 +136,7 @@ PyDoc_STRVAR(M_aud_Sound_sine_doc, ":rtype: aud.Sound"); static PyObject * -Sound_sine(PyObject* nothing, PyObject* args); - -PyDoc_STRVAR(M_aud_Sound_file_doc, - "file(filename)\n\n" - "Creates a sound object of a sound file.\n\n" - ":arg filename: Path of the file.\n" - ":type filename: string\n" - ":return: The created aud.Sound object.\n" - ":rtype: aud.Sound"); - -static PyObject * -Sound_file(PyObject* nothing, PyObject* args); - -PyDoc_STRVAR(M_aud_Sound_lowpass_doc, - "lowpass(frequency[, Q])\n\n" - "Creates a second order lowpass filter.\n\n" - ":arg frequency: The cut off trequency of the lowpass.\n" - ":type frequency: float\n" - ":arg Q: Q factor of the lowpass.\n" - ":type Q: float\n" - ":return: The created aud.Sound object.\n" - ":rtype: aud.Sound"); - -static PyObject * -Sound_lowpass(Sound* self, PyObject* args); - -PyDoc_STRVAR(M_aud_Sound_delay_doc, - "delay(time)\n\n" - "Delays a sound by playing silence before the sound starts.\n\n" - ":arg time: How many seconds of silence should be added before the sound.\n" - ":type time: float\n" - ":return: The created aud.Sound object.\n" - ":rtype: aud.Sound"); - -static PyObject * -Sound_delay(Sound* self, PyObject* args); - -PyDoc_STRVAR(M_aud_Sound_join_doc, - "join(sound)\n\n" - "Plays two sounds in sequence.\n\n" - ":arg sound: The sound to play second.\n" - ":type sound: aud.Sound\n" - ":return: The created aud.Sound object.\n" - ":rtype: aud.Sound\n\n" - ".. note:: The two sounds have to have the same specifications " - "(channels and samplerate)."); - -static PyObject * -Sound_join(Sound* self, PyObject* object); - -PyDoc_STRVAR(M_aud_Sound_highpass_doc, - "highpass(frequency[, Q])\n\n" - "Creates a second order highpass filter.\n\n" - ":arg frequency: The cut off trequency of the highpass.\n" - ":type frequency: float\n" - ":arg Q: Q factor of the lowpass.\n" - ":type Q: float\n" - ":return: The created aud.Sound object.\n" - ":rtype: aud.Sound"); - -static PyObject * -Sound_highpass(Sound* self, PyObject* args); - -PyDoc_STRVAR(M_aud_Sound_limit_doc, - "limit(start, end)\n\n" - "Limits a sound within a specific start and end time.\n\n" - ":arg start: Start time in seconds.\n" - ":type start: float\n" - ":arg end: End time in seconds.\n" - ":type end: float\n" - ":return: The created aud.Sound object.\n" - ":rtype: aud.Sound"); - -static PyObject * -Sound_limit(Sound* self, PyObject* args); - -PyDoc_STRVAR(M_aud_Sound_pitch_doc, - "pitch(factor)\n\n" - "Changes the pitch of a sound with a specific factor.\n\n" - ":arg factor: The factor to change the pitch with.\n" - ":type factor: float\n" - ":return: The created aud.Sound object.\n" - ":rtype: aud.Sound\n\n" - ".. note:: This is done by changing the sample rate of the " - "underlying sound, which has to be an integer, so the factor " - "value rounded and the factor may not be 100 % accurate."); - -static PyObject * -Sound_pitch(Sound* self, PyObject* args); - -PyDoc_STRVAR(M_aud_Sound_volume_doc, - "volume(volume)\n\n" - "Changes the volume of a sound.\n\n" - ":arg volume: The new volume..\n" - ":type volume: float\n" - ":return: The created aud.Sound object.\n" - ":rtype: aud.Sound\n\n" - ".. note:: Should be in the range [0, 1] to avoid clipping.\n\n" - ".. note:: This is a filter function, you might consider using " - "aud.Handle.pitch instead."); - -static PyObject * -Sound_volume(Sound* self, PyObject* args); - -PyDoc_STRVAR(M_aud_Sound_fadein_doc, - "fadein(start, length)\n\n" - "Fades a sound in.\n\n" - ":arg start: Time in seconds when the fading should start.\n" - ":type start: float\n" - ":arg length: Time in seconds how long the fading should last.\n" - ":type length: float\n" - ":return: The created aud.Sound object.\n" - ":rtype: aud.Sound\n\n" - ".. note:: This is a filter function, you might consider using " - "aud.Handle.volume instead."); - -static PyObject * -Sound_fadein(Sound* self, PyObject* args); - -PyDoc_STRVAR(M_aud_Sound_fadeout_doc, - "fadeout(start, length)\n\n" - "Fades a sound out.\n\n" - ":arg start: Time in seconds when the fading should start.\n" - ":type start: float\n" - ":arg length: Time in seconds how long the fading should last.\n" - ":type length: float\n" - ":return: The created aud.Sound object.\n" - ":rtype: aud.Sound"); - -static PyObject * -Sound_fadeout(Sound* self, PyObject* args); - -PyDoc_STRVAR(M_aud_Sound_loop_doc, - "loop(count)\n\n" - "Loops a sound.\n\n" - ":arg count: How often the sound should be looped. " - "Negative values mean endlessly.\n" - ":type count: integer\n" - ":return: The created aud.Sound object.\n" - ":rtype: aud.Sound"); - -static PyObject * -Sound_loop(Sound* self, PyObject* args); - -PyDoc_STRVAR(M_aud_Sound_mix_doc, - "mix(sound)\n\n" - "Mixes two sounds.\n\n" - ":arg sound: The sound to mix over the other.\n" - ":type sound: aud.Sound\n" - ":return: The created aud.Sound object.\n" - ":rtype: aud.Sound\n\n" - ".. note:: The two sounds have to have the same specifications " - "(channels and samplerate)."); - -static PyObject * -Sound_mix(Sound* self, PyObject* object); - -PyDoc_STRVAR(M_aud_Sound_pingpong_doc, - "pingpong()\n\n" - "Plays a sound forward and then backward.\n\n" - ":return: The created aud.Sound object.\n" - ":rtype: aud.Sound\n\n" - ".. note:: The sound has to be buffered to be played reverse."); - -static PyObject * -Sound_pingpong(Sound* self); - -PyDoc_STRVAR(M_aud_Sound_reverse_doc, - "reverse()\n\n" - "Plays a sound reversed.\n\n" - ":return: The created aud.Sound object.\n" - ":rtype: aud.Sound\n\n" - ".. note:: The sound has to be buffered to be played reverse."); - -static PyObject * -Sound_reverse(Sound* self); - -PyDoc_STRVAR(M_aud_Sound_buffer_doc, - "buffer()\n\n" - "Buffers a sound into RAM.\n\n" - ":return: The created aud.Sound object.\n" - ":rtype: aud.Sound\n\n" - ".. note:: Raw PCM data needs a lot of space, only buffer short sounds."); - -static PyObject * -Sound_buffer(Sound* self); - -PyDoc_STRVAR(M_aud_Sound_square_doc, - "squre([threshold = 0])\n\n" - "Makes a square wave out of an audio wave.\n\n" - ":arg threshold: Threshold value over which an amplitude counts non-zero.\n" - ":type threshold: float\n" - ":return: The created aud.Sound object.\n" - ":rtype: aud.Sound"); - -static PyObject * -Sound_square(Sound* self, PyObject* args); - -PyDoc_STRVAR(M_aud_Sound_filter_doc, - "filter(b[, a = (1)])\n\n" - "Filters a sound with the supplied IIR filter coefficients.\n\n" - ":arg b: The nominator filter coefficients.\n" - ":type b: sequence of float\n" - ":arg a: The denominator filter coefficients.\n" - ":type a: sequence of float\n" - ":return: The created aud.Sound object.\n" - ":rtype: aud.Sound"); - -static PyObject * -Sound_filter(Sound* self, PyObject* args); - -static PyMethodDef Sound_methods[] = { - {"sine", (PyCFunction)Sound_sine, METH_VARARGS | METH_STATIC, - M_aud_Sound_sine_doc - }, - {"file", (PyCFunction)Sound_file, METH_VARARGS | METH_STATIC, - M_aud_Sound_file_doc - }, - {"lowpass", (PyCFunction)Sound_lowpass, METH_VARARGS, - M_aud_Sound_lowpass_doc - }, - {"delay", (PyCFunction)Sound_delay, METH_VARARGS, - M_aud_Sound_delay_doc - }, - {"join", (PyCFunction)Sound_join, METH_O, - M_aud_Sound_join_doc - }, - {"highpass", (PyCFunction)Sound_highpass, METH_VARARGS, - M_aud_Sound_highpass_doc - }, - {"limit", (PyCFunction)Sound_limit, METH_VARARGS, - M_aud_Sound_limit_doc - }, - {"pitch", (PyCFunction)Sound_pitch, METH_VARARGS, - M_aud_Sound_pitch_doc - }, - {"volume", (PyCFunction)Sound_volume, METH_VARARGS, - M_aud_Sound_volume_doc - }, - {"fadein", (PyCFunction)Sound_fadein, METH_VARARGS, - M_aud_Sound_fadein_doc - }, - {"fadeout", (PyCFunction)Sound_fadeout, METH_VARARGS, - M_aud_Sound_fadeout_doc - }, - {"loop", (PyCFunction)Sound_loop, METH_VARARGS, - M_aud_Sound_loop_doc - }, - {"mix", (PyCFunction)Sound_mix, METH_O, - M_aud_Sound_mix_doc - }, - {"pingpong", (PyCFunction)Sound_pingpong, METH_NOARGS, - M_aud_Sound_pingpong_doc - }, - {"reverse", (PyCFunction)Sound_reverse, METH_NOARGS, - M_aud_Sound_reverse_doc - }, - {"buffer", (PyCFunction)Sound_buffer, METH_NOARGS, - M_aud_Sound_buffer_doc - }, - {"square", (PyCFunction)Sound_square, METH_VARARGS, - M_aud_Sound_square_doc - }, - {"filter", (PyCFunction)Sound_filter, METH_VARARGS, - M_aud_Sound_filter_doc - }, - {NULL} /* Sentinel */ -}; - -PyDoc_STRVAR(M_aud_Sound_doc, - "Sound objects are immutable and represent a sound that can be " - "played simultaneously multiple times."); - -static PyTypeObject SoundType = { - PyVarObject_HEAD_INIT(NULL, 0) - "aud.Sound", /* tp_name */ - sizeof(Sound), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)Sound_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - M_aud_Sound_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - Sound_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - Sound_new, /* tp_new */ -}; - -static PyObject * -Sound_sine(PyObject* nothing, PyObject* args) +Sound_sine(PyTypeObject* type, PyObject* args) { float frequency; int rate = 44100; @@ -461,7 +146,7 @@ Sound_sine(PyObject* nothing, PyObject* args) Sound *self; - self = (Sound*)SoundType.tp_alloc(&SoundType, 0); + self = (Sound*)type->tp_alloc(type, 0); if(self != NULL) { try @@ -479,8 +164,16 @@ Sound_sine(PyObject* nothing, PyObject* args) return (PyObject *)self; } +PyDoc_STRVAR(M_aud_Sound_file_doc, + "file(filename)\n\n" + "Creates a sound object of a sound file.\n\n" + ":arg filename: Path of the file.\n" + ":type filename: string\n" + ":return: The created aud.Sound object.\n" + ":rtype: aud.Sound"); + static PyObject * -Sound_file(PyObject* nothing, PyObject* args) +Sound_file(PyTypeObject* type, PyObject* args) { const char* filename = NULL; @@ -489,7 +182,7 @@ Sound_file(PyObject* nothing, PyObject* args) Sound *self; - self = (Sound*)SoundType.tp_alloc(&SoundType, 0); + self = (Sound*)type->tp_alloc(type, 0); if(self != NULL) { try @@ -507,6 +200,16 @@ Sound_file(PyObject* nothing, PyObject* args) return (PyObject *)self; } +PyDoc_STRVAR(M_aud_Sound_lowpass_doc, + "lowpass(frequency[, Q])\n\n" + "Creates a second order lowpass filter.\n\n" + ":arg frequency: The cut off trequency of the lowpass.\n" + ":type frequency: float\n" + ":arg Q: Q factor of the lowpass.\n" + ":type Q: float\n" + ":return: The created aud.Sound object.\n" + ":rtype: aud.Sound"); + static PyObject * Sound_lowpass(Sound* self, PyObject* args) { @@ -516,7 +219,8 @@ Sound_lowpass(Sound* self, PyObject* args) if(!PyArg_ParseTuple(args, "f|f:lowpass", &frequency, &Q)) return NULL; - Sound *parent = (Sound*)SoundType.tp_alloc(&SoundType, 0); + PyTypeObject* type = ((PyObject*)self)->ob_type; + Sound *parent = (Sound*)type->tp_alloc(type, 0); if(parent != NULL) { @@ -538,6 +242,14 @@ Sound_lowpass(Sound* self, PyObject* args) return (PyObject *)parent; } +PyDoc_STRVAR(M_aud_Sound_delay_doc, + "delay(time)\n\n" + "Delays a sound by playing silence before the sound starts.\n\n" + ":arg time: How many seconds of silence should be added before the sound.\n" + ":type time: float\n" + ":return: The created aud.Sound object.\n" + ":rtype: aud.Sound"); + static PyObject * Sound_delay(Sound* self, PyObject* args) { @@ -546,7 +258,9 @@ Sound_delay(Sound* self, PyObject* args) if(!PyArg_ParseTuple(args, "f:delay", &delay)) return NULL; - Sound *parent = (Sound*)SoundType.tp_alloc(&SoundType, 0); + PyTypeObject* type = ((PyObject*)self)->ob_type; + Sound *parent = (Sound*)type->tp_alloc(type, 0); + if(parent != NULL) { Py_INCREF(self); @@ -567,10 +281,22 @@ Sound_delay(Sound* self, PyObject* args) return (PyObject *)parent; } +PyDoc_STRVAR(M_aud_Sound_join_doc, + "join(sound)\n\n" + "Plays two sounds in sequence.\n\n" + ":arg sound: The sound to play second.\n" + ":type sound: aud.Sound\n" + ":return: The created aud.Sound object.\n" + ":rtype: aud.Sound\n\n" + ".. note:: The two sounds have to have the same specifications " + "(channels and samplerate)."); + static PyObject * Sound_join(Sound* self, PyObject* object) { - if(!PyObject_TypeCheck(object, &SoundType)) + PyTypeObject* type = ((PyObject*)self)->ob_type; + + if(!PyObject_TypeCheck(object, type)) { PyErr_SetString(PyExc_TypeError, "Object has to be of type aud.Sound!"); return NULL; @@ -579,7 +305,7 @@ Sound_join(Sound* self, PyObject* object) Sound *parent; Sound *child = (Sound*)object; - parent = (Sound*)SoundType.tp_alloc(&SoundType, 0); + parent = (Sound*)type->tp_alloc(type, 0); if(parent != NULL) { parent->child_list = Py_BuildValue("(OO)", self, object); @@ -599,6 +325,16 @@ Sound_join(Sound* self, PyObject* object) return (PyObject *)parent; } +PyDoc_STRVAR(M_aud_Sound_highpass_doc, + "highpass(frequency[, Q])\n\n" + "Creates a second order highpass filter.\n\n" + ":arg frequency: The cut off trequency of the highpass.\n" + ":type frequency: float\n" + ":arg Q: Q factor of the lowpass.\n" + ":type Q: float\n" + ":return: The created aud.Sound object.\n" + ":rtype: aud.Sound"); + static PyObject * Sound_highpass(Sound* self, PyObject* args) { @@ -608,7 +344,8 @@ Sound_highpass(Sound* self, PyObject* args) if(!PyArg_ParseTuple(args, "f|f:highpass", &frequency, &Q)) return NULL; - Sound *parent = (Sound*)SoundType.tp_alloc(&SoundType, 0); + PyTypeObject* type = ((PyObject*)self)->ob_type; + Sound *parent = (Sound*)type->tp_alloc(type, 0); if(parent != NULL) { @@ -630,6 +367,16 @@ Sound_highpass(Sound* self, PyObject* args) return (PyObject *)parent; } +PyDoc_STRVAR(M_aud_Sound_limit_doc, + "limit(start, end)\n\n" + "Limits a sound within a specific start and end time.\n\n" + ":arg start: Start time in seconds.\n" + ":type start: float\n" + ":arg end: End time in seconds.\n" + ":type end: float\n" + ":return: The created aud.Sound object.\n" + ":rtype: aud.Sound"); + static PyObject * Sound_limit(Sound* self, PyObject* args) { @@ -638,7 +385,8 @@ Sound_limit(Sound* self, PyObject* args) if(!PyArg_ParseTuple(args, "ff:limit", &start, &end)) return NULL; - Sound *parent = (Sound*)SoundType.tp_alloc(&SoundType, 0); + PyTypeObject* type = ((PyObject*)self)->ob_type; + Sound *parent = (Sound*)type->tp_alloc(type, 0); if(parent != NULL) { @@ -660,6 +408,17 @@ Sound_limit(Sound* self, PyObject* args) return (PyObject *)parent; } +PyDoc_STRVAR(M_aud_Sound_pitch_doc, + "pitch(factor)\n\n" + "Changes the pitch of a sound with a specific factor.\n\n" + ":arg factor: The factor to change the pitch with.\n" + ":type factor: float\n" + ":return: The created aud.Sound object.\n" + ":rtype: aud.Sound\n\n" + ".. note:: This is done by changing the sample rate of the " + "underlying sound, which has to be an integer, so the factor " + "value rounded and the factor may not be 100 % accurate."); + static PyObject * Sound_pitch(Sound* self, PyObject* args) { @@ -668,7 +427,8 @@ Sound_pitch(Sound* self, PyObject* args) if(!PyArg_ParseTuple(args, "f:pitch", &factor)) return NULL; - Sound *parent = (Sound*)SoundType.tp_alloc(&SoundType, 0); + PyTypeObject* type = ((PyObject*)self)->ob_type; + Sound *parent = (Sound*)type->tp_alloc(type, 0); if(parent != NULL) { @@ -690,6 +450,17 @@ Sound_pitch(Sound* self, PyObject* args) return (PyObject *)parent; } +PyDoc_STRVAR(M_aud_Sound_volume_doc, + "volume(volume)\n\n" + "Changes the volume of a sound.\n\n" + ":arg volume: The new volume..\n" + ":type volume: float\n" + ":return: The created aud.Sound object.\n" + ":rtype: aud.Sound\n\n" + ".. note:: Should be in the range [0, 1] to avoid clipping.\n\n" + ".. note:: This is a filter function, you might consider using " + "aud.Handle.pitch instead."); + static PyObject * Sound_volume(Sound* self, PyObject* args) { @@ -698,7 +469,8 @@ Sound_volume(Sound* self, PyObject* args) if(!PyArg_ParseTuple(args, "f:volume", &volume)) return NULL; - Sound *parent = (Sound*)SoundType.tp_alloc(&SoundType, 0); + PyTypeObject* type = ((PyObject*)self)->ob_type; + Sound *parent = (Sound*)type->tp_alloc(type, 0); if(parent != NULL) { @@ -720,6 +492,18 @@ Sound_volume(Sound* self, PyObject* args) return (PyObject *)parent; } +PyDoc_STRVAR(M_aud_Sound_fadein_doc, + "fadein(start, length)\n\n" + "Fades a sound in.\n\n" + ":arg start: Time in seconds when the fading should start.\n" + ":type start: float\n" + ":arg length: Time in seconds how long the fading should last.\n" + ":type length: float\n" + ":return: The created aud.Sound object.\n" + ":rtype: aud.Sound\n\n" + ".. note:: This is a filter function, you might consider using " + "aud.Handle.volume instead."); + static PyObject * Sound_fadein(Sound* self, PyObject* args) { @@ -728,7 +512,8 @@ Sound_fadein(Sound* self, PyObject* args) if(!PyArg_ParseTuple(args, "ff:fadein", &start, &length)) return NULL; - Sound *parent = (Sound*)SoundType.tp_alloc(&SoundType, 0); + PyTypeObject* type = ((PyObject*)self)->ob_type; + Sound *parent = (Sound*)type->tp_alloc(type, 0); if(parent != NULL) { @@ -750,6 +535,16 @@ Sound_fadein(Sound* self, PyObject* args) return (PyObject *)parent; } +PyDoc_STRVAR(M_aud_Sound_fadeout_doc, + "fadeout(start, length)\n\n" + "Fades a sound out.\n\n" + ":arg start: Time in seconds when the fading should start.\n" + ":type start: float\n" + ":arg length: Time in seconds how long the fading should last.\n" + ":type length: float\n" + ":return: The created aud.Sound object.\n" + ":rtype: aud.Sound"); + static PyObject * Sound_fadeout(Sound* self, PyObject* args) { @@ -758,7 +553,8 @@ Sound_fadeout(Sound* self, PyObject* args) if(!PyArg_ParseTuple(args, "ff:fadeout", &start, &length)) return NULL; - Sound *parent = (Sound*)SoundType.tp_alloc(&SoundType, 0); + PyTypeObject* type = ((PyObject*)self)->ob_type; + Sound *parent = (Sound*)type->tp_alloc(type, 0); if(parent != NULL) { @@ -780,6 +576,15 @@ Sound_fadeout(Sound* self, PyObject* args) return (PyObject *)parent; } +PyDoc_STRVAR(M_aud_Sound_loop_doc, + "loop(count)\n\n" + "Loops a sound.\n\n" + ":arg count: How often the sound should be looped. " + "Negative values mean endlessly.\n" + ":type count: integer\n" + ":return: The created aud.Sound object.\n" + ":rtype: aud.Sound"); + static PyObject * Sound_loop(Sound* self, PyObject* args) { @@ -788,7 +593,8 @@ Sound_loop(Sound* self, PyObject* args) if(!PyArg_ParseTuple(args, "i:loop", &loop)) return NULL; - Sound *parent = (Sound*)SoundType.tp_alloc(&SoundType, 0); + PyTypeObject* type = ((PyObject*)self)->ob_type; + Sound *parent = (Sound*)type->tp_alloc(type, 0); if(parent != NULL) { @@ -810,16 +616,28 @@ Sound_loop(Sound* self, PyObject* args) return (PyObject *)parent; } +PyDoc_STRVAR(M_aud_Sound_mix_doc, + "mix(sound)\n\n" + "Mixes two sounds.\n\n" + ":arg sound: The sound to mix over the other.\n" + ":type sound: aud.Sound\n" + ":return: The created aud.Sound object.\n" + ":rtype: aud.Sound\n\n" + ".. note:: The two sounds have to have the same specifications " + "(channels and samplerate)."); + static PyObject * Sound_mix(Sound* self, PyObject* object) { - if(!PyObject_TypeCheck(object, &SoundType)) + PyTypeObject* type = ((PyObject*)self)->ob_type; + + if(!PyObject_TypeCheck(object, type)) { PyErr_SetString(PyExc_TypeError, "Object is not of type aud.Sound!"); return NULL; } - Sound *parent = (Sound*)SoundType.tp_alloc(&SoundType, 0); + Sound *parent = (Sound*)type->tp_alloc(type, 0); Sound *child = (Sound*)object; if(parent != NULL) @@ -841,10 +659,18 @@ Sound_mix(Sound* self, PyObject* object) return (PyObject *)parent; } +PyDoc_STRVAR(M_aud_Sound_pingpong_doc, + "pingpong()\n\n" + "Plays a sound forward and then backward.\n\n" + ":return: The created aud.Sound object.\n" + ":rtype: aud.Sound\n\n" + ".. note:: The sound has to be buffered to be played reverse."); + static PyObject * Sound_pingpong(Sound* self) { - Sound *parent = (Sound*)SoundType.tp_alloc(&SoundType, 0); + PyTypeObject* type = ((PyObject*)self)->ob_type; + Sound *parent = (Sound*)type->tp_alloc(type, 0); if(parent != NULL) { @@ -866,10 +692,18 @@ Sound_pingpong(Sound* self) return (PyObject *)parent; } +PyDoc_STRVAR(M_aud_Sound_reverse_doc, + "reverse()\n\n" + "Plays a sound reversed.\n\n" + ":return: The created aud.Sound object.\n" + ":rtype: aud.Sound\n\n" + ".. note:: The sound has to be buffered to be played reverse."); + static PyObject * Sound_reverse(Sound* self) { - Sound *parent = (Sound*)SoundType.tp_alloc(&SoundType, 0); + PyTypeObject* type = ((PyObject*)self)->ob_type; + Sound *parent = (Sound*)type->tp_alloc(type, 0); if(parent != NULL) { @@ -891,10 +725,18 @@ Sound_reverse(Sound* self) return (PyObject *)parent; } +PyDoc_STRVAR(M_aud_Sound_buffer_doc, + "buffer()\n\n" + "Buffers a sound into RAM.\n\n" + ":return: The created aud.Sound object.\n" + ":rtype: aud.Sound\n\n" + ".. note:: Raw PCM data needs a lot of space, only buffer short sounds."); + static PyObject * Sound_buffer(Sound* self) { - Sound *parent = (Sound*)SoundType.tp_alloc(&SoundType, 0); + PyTypeObject* type = ((PyObject*)self)->ob_type; + Sound *parent = (Sound*)type->tp_alloc(type, 0); if(parent != NULL) { @@ -913,6 +755,14 @@ Sound_buffer(Sound* self) return (PyObject *)parent; } +PyDoc_STRVAR(M_aud_Sound_square_doc, + "squre([threshold = 0])\n\n" + "Makes a square wave out of an audio wave.\n\n" + ":arg threshold: Threshold value over which an amplitude counts non-zero.\n" + ":type threshold: float\n" + ":return: The created aud.Sound object.\n" + ":rtype: aud.Sound"); + static PyObject * Sound_square(Sound* self, PyObject* args) { @@ -921,7 +771,8 @@ Sound_square(Sound* self, PyObject* args) if(!PyArg_ParseTuple(args, "|f:square", &threshold)) return NULL; - Sound *parent = (Sound*)SoundType.tp_alloc(&SoundType, 0); + PyTypeObject* type = ((PyObject*)self)->ob_type; + Sound *parent = (Sound*)type->tp_alloc(type, 0); if(parent != NULL) { @@ -943,6 +794,16 @@ Sound_square(Sound* self, PyObject* args) return (PyObject *)parent; } +PyDoc_STRVAR(M_aud_Sound_filter_doc, + "filter(b[, a = (1)])\n\n" + "Filters a sound with the supplied IIR filter coefficients.\n\n" + ":arg b: The nominator filter coefficients.\n" + ":type b: sequence of float\n" + ":arg a: The denominator filter coefficients.\n" + ":type a: sequence of float\n" + ":return: The created aud.Sound object.\n" + ":rtype: aud.Sound"); + static PyObject * Sound_filter(Sound* self, PyObject* args) { @@ -1001,7 +862,8 @@ Sound_filter(Sound* self, PyObject* args) else a.push_back(1); - Sound *parent = (Sound*)SoundType.tp_alloc(&SoundType, 0); + PyTypeObject* type = ((PyObject*)self)->ob_type; + Sound *parent = (Sound*)type->tp_alloc(type, 0); if(parent != NULL) { @@ -1023,6 +885,109 @@ Sound_filter(Sound* self, PyObject* args) return (PyObject *)parent; } +static PyMethodDef Sound_methods[] = { + {"sine", (PyCFunction)Sound_sine, METH_VARARGS | METH_CLASS, + M_aud_Sound_sine_doc + }, + {"file", (PyCFunction)Sound_file, METH_VARARGS | METH_CLASS, + M_aud_Sound_file_doc + }, + {"lowpass", (PyCFunction)Sound_lowpass, METH_VARARGS, + M_aud_Sound_lowpass_doc + }, + {"delay", (PyCFunction)Sound_delay, METH_VARARGS, + M_aud_Sound_delay_doc + }, + {"join", (PyCFunction)Sound_join, METH_O, + M_aud_Sound_join_doc + }, + {"highpass", (PyCFunction)Sound_highpass, METH_VARARGS, + M_aud_Sound_highpass_doc + }, + {"limit", (PyCFunction)Sound_limit, METH_VARARGS, + M_aud_Sound_limit_doc + }, + {"pitch", (PyCFunction)Sound_pitch, METH_VARARGS, + M_aud_Sound_pitch_doc + }, + {"volume", (PyCFunction)Sound_volume, METH_VARARGS, + M_aud_Sound_volume_doc + }, + {"fadein", (PyCFunction)Sound_fadein, METH_VARARGS, + M_aud_Sound_fadein_doc + }, + {"fadeout", (PyCFunction)Sound_fadeout, METH_VARARGS, + M_aud_Sound_fadeout_doc + }, + {"loop", (PyCFunction)Sound_loop, METH_VARARGS, + M_aud_Sound_loop_doc + }, + {"mix", (PyCFunction)Sound_mix, METH_O, + M_aud_Sound_mix_doc + }, + {"pingpong", (PyCFunction)Sound_pingpong, METH_NOARGS, + M_aud_Sound_pingpong_doc + }, + {"reverse", (PyCFunction)Sound_reverse, METH_NOARGS, + M_aud_Sound_reverse_doc + }, + {"buffer", (PyCFunction)Sound_buffer, METH_NOARGS, + M_aud_Sound_buffer_doc + }, + {"square", (PyCFunction)Sound_square, METH_VARARGS, + M_aud_Sound_square_doc + }, + {"filter", (PyCFunction)Sound_filter, METH_VARARGS, + M_aud_Sound_filter_doc + }, + {NULL} /* Sentinel */ +}; + +PyDoc_STRVAR(M_aud_Sound_doc, + "Sound objects are immutable and represent a sound that can be " + "played simultaneously multiple times."); + +static PyTypeObject SoundType = { + PyVarObject_HEAD_INIT(NULL, 0) + "aud.Sound", /* tp_name */ + sizeof(Sound), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)Sound_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + M_aud_Sound_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + Sound_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + Sound_new, /* tp_new */ +}; + // ========== Handle ================================================== static void -- cgit v1.2.3