Update sound and sound stream classes
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1064 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
27c7d487a0
commit
12af32c083
@ -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"
|
||||
|
@ -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")
|
||||
|
@ -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 "},
|
||||
|
@ -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\
|
||||
|
Loading…
Reference in New Issue
Block a user