[fixed] For OpenAL, now properly disconnect the Sound buffer from the stream before deleting the buffer.
int state = alGetSourcei(streamID, AL_SOURCE_STATE);\r
if (state != AL_PLAYING && state != AL_PAUSED) {\r
if (isMusic) idleStreams.removeIndex(i);\r
+ alSourceStop(streamID);\r
+ alSourcei(streamID, AL_BUFFER, 0);\r
return streamID;\r
}\r
}\r
idleStreams.add(streamID);\r
}\r
\r
+ void freeBuffer (int bufferID) {\r
+ for (int i = 0, n = idleStreams.size; i < n; i++) {\r
+ int streamID = idleStreams.get(i);\r
+ if (alGetSourcei(streamID, AL_BUFFER) == bufferID) alSourcei(streamID, AL_BUFFER, 0);\r
+ }\r
+ }\r
+\r
+ void stopStreamsWithBuffer (int bufferID) {\r
+ for (int i = 0, n = idleStreams.size; i < n; i++) {\r
+ int streamID = idleStreams.get(i);\r
+ if (alGetSourcei(streamID, AL_BUFFER) == bufferID) alSourceStop(streamID);\r
+ }\r
+ }\r
+\r
public void update () {\r
for (int i = 0; i < music.size; i++)\r
music.items[i].update();\r
if (streamID == -1) {\r
streamID = audio.obtainStream(true);\r
if (streamID == -1) return;\r
- alSourceStop(streamID);\r
- alSourcei(streamID, AL_BUFFER, 0);\r
alSourcei(streamID, AL_LOOPING, AL_FALSE);\r
alSourcef(streamID, AL_GAIN, volume);\r
for (int i = 0; i < bufferCount; i++)\r
public void play (float volume) {\r
int streamID = audio.obtainStream(false);\r
if (streamID == -1) return;\r
- alSourceStop(streamID);\r
- alSourcei(streamID, AL_BUFFER, 0);\r
alSourcei(streamID, AL_BUFFER, bufferID);\r
alSourcei(streamID, AL_LOOPING, AL_FALSE);\r
alSourcef(streamID, AL_GAIN, volume);\r
public void loop () {\r
int streamID = audio.obtainStream(false);\r
if (streamID == -1) return;\r
- alSourceStop(streamID);\r
- alSourcei(streamID, AL_BUFFER, 0);\r
alSourcei(streamID, AL_BUFFER, bufferID);\r
alSourcei(streamID, AL_LOOPING, AL_TRUE);\r
alSourcePlay(streamID);\r
}\r
\r
+ public void stop () {\r
+ audio.stopStreamsWithBuffer(bufferID);\r
+ }\r
+\r
public void dispose () {\r
if (bufferID == -1) return;\r
+ audio.freeBuffer(bufferID);\r
alDeleteBuffers(bufferID);\r
bufferID = -1;\r
}\r
public void play (float volume);\r
\r
/**\r
+ * Stops playing all instances of this sound.\r
+ */\r
+ public void stop ();\r
+\r
+ /**\r
* Releases all the resources.\r
*/\r
public void dispose ();\r