aboutsummaryrefslogtreecommitdiff
path: root/src/audio.c
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2016-08-29 11:17:58 +0200
committerraysan5 <raysan5@gmail.com>2016-08-29 11:17:58 +0200
commitbe97583f00997fa918a15d0164190ae6876d0571 (patch)
tree66710f4b0574bf65beae0168601c614554ae8348 /src/audio.c
parent7dbb17792afa7e91bf56216dff11022d5d147e31 (diff)
downloadraylib-be97583f00997fa918a15d0164190ae6876d0571.tar.gz
raylib-be97583f00997fa918a15d0164190ae6876d0571.zip
Added function: UpdateSound()
Diffstat (limited to 'src/audio.c')
-rw-r--r--src/audio.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/audio.c b/src/audio.c
index 1772196f..3bace5f7 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -284,6 +284,7 @@ Sound LoadSoundFromWave(Wave wave)
sound.source = source;
sound.buffer = buffer;
+ sound.format = format;
}
return sound;
@@ -409,6 +410,33 @@ void UnloadSound(Sound sound)
TraceLog(INFO, "[SND ID %i][BUFR ID %i] Unloaded sound data from RAM", sound.source, sound.buffer);
}
+// Update sound buffer with new data
+// NOTE: data must match sound.format
+void UpdateSound(Sound sound, void *data, int numSamples)
+{
+ ALint sampleRate, sampleSize, channels;
+ alGetBufferi(sound.buffer, AL_FREQUENCY, &sampleRate);
+ alGetBufferi(sound.buffer, AL_BITS, &sampleSize); // It could also be retrieved from sound.format
+ alGetBufferi(sound.buffer, AL_CHANNELS, &channels); // It could also be retrieved from sound.format
+
+ TraceLog(DEBUG, "UpdateSound() : AL_FREQUENCY: %i", sampleRate);
+ TraceLog(DEBUG, "UpdateSound() : AL_BITS: %i", sampleSize);
+ TraceLog(DEBUG, "UpdateSound() : AL_CHANNELS: %i", channels);
+
+ unsigned int dataSize = numSamples*sampleSize/8; // Size of data in bytes
+
+ alSourceStop(sound.source); // Stop sound
+ alSourcei(sound.source, AL_BUFFER, 0); // Unbind buffer from sound to update
+ //alDeleteBuffers(1, &sound.buffer); // Delete current buffer data
+ //alGenBuffers(1, &sound.buffer); // Generate new buffer
+
+ // Upload new data to sound buffer
+ alBufferData(sound.buffer, sound.format, data, dataSize, sampleRate);
+
+ // Attach sound buffer to source again
+ alSourcei(sound.source, AL_BUFFER, sound.buffer);
+}
+
// Play a sound
void PlaySound(Sound sound)
{