[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30152] branches/soc-2010-nexyon: Audaspace:
Joerg Mueller
nexyon at gmail.com
Fri Jul 9 14:35:40 CEST 2010
Revision: 30152
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30152
Author: nexyon
Date: 2010-07-09 14:35:40 +0200 (Fri, 09 Jul 2010)
Log Message:
-----------
Audaspace:
* Renamed AUD_Handle to AUD_Channel in the C-API to prevent errors with the C++ version of AUD_Handle.
* Added Python API!!!
Modified Paths:
--------------
branches/soc-2010-nexyon/intern/audaspace/CMakeLists.txt
branches/soc-2010-nexyon/intern/audaspace/SConscript
branches/soc-2010-nexyon/intern/audaspace/intern/AUD_C-API.cpp
branches/soc-2010-nexyon/intern/audaspace/intern/AUD_C-API.h
branches/soc-2010-nexyon/source/blender/python/CMakeLists.txt
branches/soc-2010-nexyon/source/blender/python/SConscript
branches/soc-2010-nexyon/source/blender/python/intern/bpy.c
branches/soc-2010-nexyon/source/gameengine/Ketsji/KX_PythonInit.cpp
branches/soc-2010-nexyon/source/gameengine/Ketsji/KX_SoundActuator.h
Added Paths:
-----------
branches/soc-2010-nexyon/intern/audaspace/Python/
branches/soc-2010-nexyon/intern/audaspace/Python/AUD_PyAPI.cpp
branches/soc-2010-nexyon/intern/audaspace/Python/AUD_PyAPI.h
Modified: branches/soc-2010-nexyon/intern/audaspace/CMakeLists.txt
===================================================================
--- branches/soc-2010-nexyon/intern/audaspace/CMakeLists.txt 2010-07-09 11:48:51 UTC (rev 30151)
+++ branches/soc-2010-nexyon/intern/audaspace/CMakeLists.txt 2010-07-09 12:35:40 UTC (rev 30152)
@@ -60,6 +60,12 @@
ADD_DEFINITIONS(-DWITH_FFTW3)
ENDIF(WITH_FFTW3)
-SET(SRC ${SRC} ${FFMPEGSRC} ${SNDFILESRC} ${FFTW3SRC} ${SDLSRC} ${OPENALSRC} ${JACKSRC})
+IF(WITH_PYTHON)
+ SET(INC ${INC} Python ${PYTHON_INC})
+ FILE(GLOB PYTHONSRC Python/*.cpp)
+ ADD_DEFINITIONS(-DWITH_PYTHON)
+ENDIF(WITH_PYTHON)
+SET(SRC ${SRC} ${FFMPEGSRC} ${SNDFILESRC} ${FFTW3SRC} ${SDLSRC} ${OPENALSRC} ${JACKSRC} ${PYTHONSRC})
+
BLENDERLIB(bf_audaspace "${SRC}" "${INC}")
Added: branches/soc-2010-nexyon/intern/audaspace/Python/AUD_PyAPI.cpp
===================================================================
--- branches/soc-2010-nexyon/intern/audaspace/Python/AUD_PyAPI.cpp (rev 0)
+++ branches/soc-2010-nexyon/intern/audaspace/Python/AUD_PyAPI.cpp 2010-07-09 12:35:40 UTC (rev 30152)
@@ -0,0 +1,3149 @@
+/*
+ * $Id$
+ *
+ * ***** BEGIN LGPL LICENSE BLOCK *****
+ *
+ * Copyright 2009 Jörg Hermann Müller
+ *
+ * This file is part of AudaSpace.
+ *
+ * AudaSpace is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * AudaSpace is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with AudaSpace. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * ***** END LGPL LICENSE BLOCK *****
+ */
+
+#include "AUD_PyAPI.h"
+#include "structmember.h"
+
+#include "AUD_NULLDevice.h"
+#include "AUD_SourceCaps.h"
+#include "AUD_DelayFactory.h"
+#include "AUD_DoubleFactory.h"
+#include "AUD_FaderFactory.h"
+#include "AUD_HighpassFactory.h"
+#include "AUD_LimiterFactory.h"
+#include "AUD_LoopFactory.h"
+#include "AUD_LowpassFactory.h"
+#include "AUD_PingPongFactory.h"
+#include "AUD_PitchFactory.h"
+#include "AUD_ReverseFactory.h"
+#include "AUD_SinusFactory.h"
+#include "AUD_FileFactory.h"
+#include "AUD_SquareFactory.h"
+#include "AUD_StreamBufferFactory.h"
+#include "AUD_SuperposeFactory.h"
+#include "AUD_VolumeFactory.h"
+
+#ifdef WITH_SDL
+#include "AUD_SDLDevice.h"
+#endif
+
+#ifdef WITH_OPENAL
+#include "AUD_OpenALDevice.h"
+#endif
+
+#ifdef WITH_JACK
+#include "AUD_JackDevice.h"
+#endif
+
+#include <cstdlib>
+#include <unistd.h>
+
+#define PY_MODULE_ADD_CONSTANT(module, name) PyModule_AddIntConstant(module, #name, name)
+
+static PyObject* AUDError;
+
+// ====================================================================
+
+static void
+Sound_dealloc(Sound* self)
+{
+ if(self->factory)
+ delete self->factory;
+ Py_XDECREF(self->child_list);
+ Py_TYPE(self)->tp_free((PyObject*)self);
+}
+
+static PyObject *
+Sound_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ Sound *self;
+
+ self = (Sound*)type->tp_alloc(type, 0);
+ if(self != NULL)
+ {
+ static char *kwlist[] = {"filename", NULL};
+ const char* filename = NULL;
+
+ if(!PyArg_ParseTupleAndKeywords(args, kwds, "|s", kwlist, &filename))
+ {
+ Py_DECREF(self);
+ return NULL;
+ }
+ else if(filename == NULL)
+ {
+ Py_DECREF(self);
+ PyErr_SetString(AUDError, "Missing filename parameter!");
+ return NULL;
+ }
+
+ try
+ {
+ self->factory = new AUD_FileFactory(filename);
+ }
+ catch(AUD_Exception&)
+ {
+ Py_DECREF(self);
+ PyErr_SetString(AUDError, "Filefactory couldn't be created!");
+ return NULL;
+ }
+ }
+
+ return (PyObject *)self;
+}
+
+static PyObject *
+Sound_sine(PyObject* nothing, PyObject* args);
+
+static PyObject *
+Sound_file(PyObject* nothing, PyObject* args);
+
+static PyObject *
+Sound_lowpass(PyObject* nothing, PyObject* args);
+
+static PyObject *
+Sound_delay(PyObject* nothing, PyObject* args);
+
+static PyObject *
+Sound_double(PyObject* nothing, PyObject* args);
+
+static PyObject *
+Sound_highpass(PyObject* nothing, PyObject* args);
+
+static PyObject *
+Sound_limiter(PyObject* nothing, PyObject* args);
+
+static PyObject *
+Sound_pitch(PyObject* nothing, PyObject* args);
+
+static PyObject *
+Sound_volume(PyObject* nothing, PyObject* args);
+
+static PyObject *
+Sound_fadein(PyObject* nothing, PyObject* args);
+
+static PyObject *
+Sound_fadeout(PyObject* nothing, PyObject* args);
+
+static PyObject *
+Sound_loop(PyObject* nothing, PyObject* args);
+
+static PyObject *
+Sound_superpose(PyObject* nothing, PyObject* args);
+
+static PyObject *
+Sound_pingpong(PyObject* nothing, PyObject* args);
+
+static PyObject *
+Sound_reverse(PyObject* nothing, PyObject* args);
+
+static PyObject *
+Sound_buffer(PyObject* nothing, PyObject* args);
+
+static PyObject *
+Sound_square(PyObject* nothing, PyObject* args);
+
+static PyMethodDef Sound_methods[] = {
+ {"sine", (PyCFunction)Sound_sine, METH_VARARGS | METH_STATIC,
+ "Creates a sine sound at a specific frequency."
+ },
+ {"file", (PyCFunction)Sound_file, METH_VARARGS | METH_STATIC,
+ "Creates a sound object of a sound file."
+ },
+ {"lowpass", (PyCFunction)Sound_lowpass, METH_VARARGS | METH_STATIC,
+ "Creates a lowpass filter with a specific cut off frequency."
+ },
+ {"delay", (PyCFunction)Sound_delay, METH_VARARGS | METH_STATIC,
+ "Delays a sound by a specific amount of seconds."
+ },
+ {"double", (PyCFunction)Sound_double, METH_VARARGS | METH_STATIC,
+ "Plays two sounds of the same specs in sequence."
+ },
+ {"highpass", (PyCFunction)Sound_highpass, METH_VARARGS | METH_STATIC,
+ "Creates a highpass filter with a specific cut off frequency."
+ },
+ {"limiter", (PyCFunction)Sound_limiter, METH_VARARGS | METH_STATIC,
+ "Limits a sound within a specific start and end time."
+ },
+ {"pitch", (PyCFunction)Sound_pitch, METH_VARARGS | METH_STATIC,
+ "Changes the pitch of a sound with a specific factor."
+ },
+ {"volume", (PyCFunction)Sound_volume, METH_VARARGS | METH_STATIC,
+ "Changes the volume of a sound with a specific factor."
+ },
+ {"fadein", (PyCFunction)Sound_fadein, METH_VARARGS | METH_STATIC,
+ "Fades a sound in from a specific start time and with a specific length."
+ },
+ {"fadeout", (PyCFunction)Sound_fadeout, METH_VARARGS | METH_STATIC,
+ "Fades a sound out from a specific start time and with a specific length."
+ },
+ {"loop", (PyCFunction)Sound_loop, METH_VARARGS | METH_STATIC,
+ "Loops a sound a specific amount of times, negative values mean endlessly."
+ },
+ {"superpose", (PyCFunction)Sound_superpose, METH_VARARGS | METH_STATIC,
+ "Mixes two sounds of the same specs."
+ },
+ {"pingpong", (PyCFunction)Sound_pingpong, METH_O | METH_STATIC,
+ "Plays a sound forward and then backward."
+ },
+ {"reverse", (PyCFunction)Sound_reverse, METH_O | METH_STATIC,
+ "Plays a sound reversed."
+ },
+ {"buffer", (PyCFunction)Sound_buffer, METH_O | METH_STATIC,
+ "Buffers a sound into RAM."
+ },
+ {"square", (PyCFunction)Sound_square, METH_VARARGS | METH_STATIC,
+ "Makes a square wave out of an audio wave depending on a threshold value."
+ },
+ {NULL} /* Sentinel */
+};
+
+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 */
+ "Sound object", /* 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)
+{
+ double frequency;
+
+ if(!PyArg_ParseTuple(args, "d", &frequency))
+ return NULL;
+
+ Sound *self;
+
+ self = (Sound*)SoundType.tp_alloc(&SoundType, 0);
+ if(self != NULL)
+ {
+ try
+ {
+ self->factory = new AUD_SinusFactory(frequency, (AUD_SampleRate)44100);
+ }
+ catch(AUD_Exception&)
+ {
+ Py_DECREF(self);
+ PyErr_SetString(AUDError, "Sinusfactory couldn't be created!");
+ return NULL;
+ }
+ }
+
+ return (PyObject *)self;
+}
+
+static PyObject *
+Sound_file(PyObject* nothing, PyObject* args)
+{
+ const char* filename = NULL;
+
+ if(!PyArg_ParseTuple(args, "s", &filename))
+ return NULL;
+
+ Sound *self;
+
+ self = (Sound*)SoundType.tp_alloc(&SoundType, 0);
+ if(self != NULL)
+ {
+ try
+ {
+ self->factory = new AUD_FileFactory(filename);
+ }
+ catch(AUD_Exception&)
+ {
+ Py_DECREF(self);
+ PyErr_SetString(AUDError, "Filefactory couldn't be created!");
+ return NULL;
+ }
+ }
+
+ return (PyObject *)self;
+}
+
+static PyObject *
+Sound_lowpass(PyObject* nothing, PyObject* args)
+{
+ float frequency;
+ PyObject* object;
+
+ if(!PyArg_ParseTuple(args, "Of", &object, &frequency))
+ return NULL;
+
+ if(!PyObject_TypeCheck(object, &SoundType))
+ {
+ PyErr_SetString(PyExc_TypeError, "Object is not of type aud.Sound!");
+ return NULL;
+ }
+
+ Sound *self;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list