add SetSoundLoop

This commit is contained in:
ftk 2019-02-23 10:47:24 +00:00
parent 374811c440
commit e815b2bff4
2 changed files with 20 additions and 2 deletions

View File

@ -267,6 +267,7 @@ void PauseAudioBuffer(AudioBuffer *audioBuffer);
void ResumeAudioBuffer(AudioBuffer *audioBuffer);
void SetAudioBufferVolume(AudioBuffer *audioBuffer, float volume);
void SetAudioBufferPitch(AudioBuffer *audioBuffer, float pitch);
void SetAudioBufferLoop(AudioBuffer *audioBuffer, bool toggle);
void TrackAudioBuffer(AudioBuffer *audioBuffer);
void UntrackAudioBuffer(AudioBuffer *audioBuffer);
@ -342,7 +343,6 @@ static mal_uint32 OnSendAudioDataToDevice(mal_device *pDevice, mal_uint32 frameC
}
else
{
// Should never get here, but just for safety,
// move the cursor position back to the start and continue the loop.
audioBuffer->frameCursorPos = 0;
continue;
@ -720,6 +720,17 @@ void SetAudioBufferPitch(AudioBuffer *audioBuffer, float pitch)
mal_dsp_set_output_sample_rate(&audioBuffer->dsp, newOutputSampleRate);
}
// Toggle looping for a sound buffer
void SetAudioBufferLoop(AudioBuffer *audioBuffer, bool toggle)
{
if (audioBuffer == NULL)
{
TraceLog(LOG_ERROR, "SetAudioBufferLoop() : No audio buffer");
return;
}
audioBuffer->looping = toggle;
}
// Track audio buffer to linked list next position
void TrackAudioBuffer(AudioBuffer *audioBuffer)
{
@ -994,6 +1005,12 @@ void SetSoundPitch(Sound sound, float pitch)
SetAudioBufferPitch((AudioBuffer *)sound.audioBuffer, pitch);
}
// Toggle looping for a sound
void SetSoundLoop(Sound sound, bool toggle)
{
SetAudioBufferLoop((AudioBuffer *)sound.audioBuffer, toggle);
}
// Convert wave data to desired format
void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels)
{

View File

@ -137,6 +137,7 @@ void StopSound(Sound sound); // Stop playing
bool IsSoundPlaying(Sound sound); // Check if a sound is currently playing
void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level)
void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level)
void SetSoundLoop(Sound sound, bool toggle); // Set whether a sound should be looped
void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels); // Convert wave data to desired format
Wave WaveCopy(Wave wave); // Copy a wave to a new wave
void WaveCrop(Wave *wave, int initSample, int finalSample); // Crop a wave to defined samples range