From 12af32c08399520a69271c72f3a9157e928c4609 Mon Sep 17 00:00:00 2001 From: remi-k Date: Fri, 27 Mar 2009 19:42:22 +0000 Subject: [PATCH] Update sound and sound stream classes git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1064 4e206d99-4929-0410-ac5d-dfc041789085 --- python/samples/sound_stream.py | 2 +- python/samples/sound_stream_py3.py | 2 +- python/src/Sound.cpp | 15 +++++++++++++++ python/src/SoundStream.cpp | 25 +++++++++++++++++++------ 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/python/samples/sound_stream.py b/python/samples/sound_stream.py index e3d588be6..a4e7a470a 100755 --- a/python/samples/sound_stream.py +++ b/python/samples/sound_stream.py @@ -24,7 +24,7 @@ class MyCustomStream(sf.SoundStream): # Check if there is enough data to stream if self.myOffset > len(self.myBuffer): # Returning something else than a string means that we want to stop playing the stream - return False + return "" # Data contains the string of samples we will return if self.myOffset + self.myBufferSize >= len(self.myBuffer): print "End of audio data reached" diff --git a/python/samples/sound_stream_py3.py b/python/samples/sound_stream_py3.py index 9cae12797..bd1a73f8e 100755 --- a/python/samples/sound_stream_py3.py +++ b/python/samples/sound_stream_py3.py @@ -24,7 +24,7 @@ class MyCustomStream(sf.SoundStream): # Check if there is enough data to stream if self.myOffset > len(self.myBuffer): # Returning something else than a string means that we want to stop playing the stream - return False + return "" # Data contains the string of samples we will return if self.myOffset + self.myBufferSize >= len(self.myBuffer): print("End of audio data reached") diff --git a/python/src/Sound.cpp b/python/src/Sound.cpp index bd3418a9c..926d2c69d 100644 --- a/python/src/Sound.cpp +++ b/python/src/Sound.cpp @@ -83,6 +83,19 @@ PySfSound_SetLoop(PySfSound *self, PyObject *args) Py_RETURN_NONE; } +static PyObject* +PySfSound_SetRelativeToListener(PySfSound *self, PyObject *args) +{ + self->obj->SetRelativeToListener(PyBool_AsBool(args)); + Py_RETURN_NONE; +} + +static PyObject* +PySfSound_IsRelativeToListener(PySfSound *self) +{ + return PyBool_FromLong(self->obj->IsRelativeToListener()); +} + static PyObject* PySfSound_SetPitch(PySfSound *self, PyObject *args) { @@ -210,6 +223,8 @@ PySfSound_SetPlayingOffset(PySfSound *self, PyObject *args) } static PyMethodDef PySfSound_methods[] = { + {"SetRelativeToListener", (PyCFunction)PySfSound_SetRelativeToListener, METH_O, "SetRelativeToListener(Relative)\nMake the sound's position relative to the listener's position, or absolute. The default value is false (absolute)\n Relative : True to set the position relative, false to set it absolute"}, + {"IsRelativeToListener", (PyCFunction)PySfSound_IsRelativeToListener, METH_NOARGS, "IsRelativeToListener()\nTell if the sound's position is relative to the listener's position, or if it's absolute."}, {"SetPlayingOffset", (PyCFunction)PySfSound_SetPlayingOffset, METH_O, "SetPlayingOffset(TimeOffset)\nSet the current playing position of the sound.\n TimeOffset : New playing position, expressed in seconds"}, {"SetLoop", (PyCFunction)PySfSound_SetLoop, METH_O, "SetLoop(Loop)\nSet the Sound loop state.\n Loop : True to play in loop, false to play once"}, {"SetBuffer", (PyCFunction)PySfSound_SetBuffer, METH_O, "SetBuffer(Buffer)\nSet the source buffer.\n Buffer : New sound buffer to bind to the sound "}, diff --git a/python/src/SoundStream.cpp b/python/src/SoundStream.cpp index 2a2f0d54c..bc75ecb60 100644 --- a/python/src/SoundStream.cpp +++ b/python/src/SoundStream.cpp @@ -49,11 +49,10 @@ bool CustomSoundStream::OnStart() bool CustomSoundStream::OnGetData(Chunk& Data) { bool result = false; - Py_XDECREF(PyData); - PyData = NULL; - if (PyObject_HasAttrString(SoundStream, "OnGetData")) + Py_CLEAR(PyData); + PyObject *Function = PyObject_GetAttrString(SoundStream, "OnGetData"); + if (Function != NULL) { - PyObject *Function = PyObject_GetAttrString(SoundStream, "OnGetData"); PyData = PyObject_CallFunction(Function, NULL); if (PyData != NULL) { @@ -69,8 +68,7 @@ bool CustomSoundStream::OnGetData(Chunk& Data) if (PyErr_Occurred()) { PyErr_Print(); - Py_XDECREF(PyData); - PyData = NULL; + Py_CLEAR(PyData); return false; } return result; @@ -239,7 +237,22 @@ PySfSoundStream_GetPlayingOffset(PySfSoundStream *self) return PyFloat_FromDouble(self->obj->GetPlayingOffset()); } +static PyObject* +PySfSoundStream_SetRelativeToListener(PySfSoundStream *self, PyObject *args) +{ + self->obj->SetRelativeToListener(PyBool_AsBool(args)); + Py_RETURN_NONE; +} + +static PyObject* +PySfSoundStream_IsRelativeToListener(PySfSoundStream *self) +{ + return PyBool_FromLong(self->obj->IsRelativeToListener()); +} + static PyMethodDef PySfSoundStream_methods[] = { + {"SetRelativeToListener", (PyCFunction)PySfSoundStream_SetRelativeToListener, METH_O, "SetRelativeToListener(Relative)\nMake the sound's position relative to the listener's position, or absolute. The default value is false (absolute)\n Relative : True to set the position relative, false to set it absolute"}, + {"IsRelativeToListener", (PyCFunction)PySfSoundStream_IsRelativeToListener, METH_NOARGS, "IsRelativeToListener()\nTell if the sound's position is relative to the listener's position, or if it's absolute."}, {"Initialize", (PyCFunction)PySfSoundStream_Initialize, METH_VARARGS, "Initialize(ChannelsCount, SampleRate)\n\ Set the audio stream parameters, you must call it before Play()\n\ ChannelsCount : Number of channels\n\