diff --git a/examples/audio/audio_module_playing.c b/examples/audio/audio_module_playing.c index 557fcb09..1bb996a7 100644 --- a/examples/audio/audio_module_playing.c +++ b/examples/audio/audio_module_playing.c @@ -51,6 +51,7 @@ int main(void) } Music music = LoadMusicStream("resources/mini1111.xm"); + music.looping = false; PlayMusicStream(music); diff --git a/src/raudio.c b/src/raudio.c index dddb08e6..21f6dffd 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -1060,7 +1060,7 @@ Music LoadMusicStream(const char *fileName) // OGG bit rate defaults to 16 bit, it's enough for compressed format music.stream = InitAudioStream(info.sample_rate, 16, info.channels); music.sampleCount = (unsigned int)stb_vorbis_stream_length_in_samples((stb_vorbis *)music.ctxData)*info.channels; - music.loopCount = 0; // Infinite loop by default + music.looping = true; // Looping enabled by default musicLoaded = true; } } @@ -1077,7 +1077,7 @@ Music LoadMusicStream(const char *fileName) music.stream = InitAudioStream(ctxFlac->sampleRate, ctxFlac->bitsPerSample, ctxFlac->channels); music.sampleCount = (unsigned int)ctxFlac->totalSampleCount; - music.loopCount = 0; // Infinite loop by default + music.looping = true; // Looping enabled by default musicLoaded = true; } } @@ -1096,7 +1096,7 @@ Music LoadMusicStream(const char *fileName) music.stream = InitAudioStream(ctxMp3->sampleRate, 32, ctxMp3->channels); music.sampleCount = (unsigned int)drmp3_get_pcm_frame_count(ctxMp3)*ctxMp3->channels; - music.loopCount = 0; // Infinite loop by default + music.looping = true; // Looping enabled by default musicLoaded = true; } } @@ -1116,7 +1116,7 @@ Music LoadMusicStream(const char *fileName) // NOTE: Only stereo is supported for XM music.stream = InitAudioStream(48000, 16, 2); music.sampleCount = (unsigned int)jar_xm_get_remaining_samples(ctxXm)*2; - music.loopCount = 0; // Infinite loop by default + music.looping = true; // Looping enabled by default jar_xm_reset(ctxXm); // make sure we start at the beginning of the song musicLoaded = true; @@ -1139,7 +1139,7 @@ Music LoadMusicStream(const char *fileName) // NOTE: Only stereo is supported for MOD music.stream = InitAudioStream(48000, 16, 2); music.sampleCount = (unsigned int)jar_mod_max_samples(ctxMod)*2; - music.loopCount = 0; // Infinite loop by default + music.looping = true; // Looping enabled by default musicLoaded = true; music.ctxData = ctxMod; @@ -1346,15 +1346,8 @@ void UpdateMusicStream(Music music) // Reset audio stream for looping if (streamEnding) { - StopMusicStream(music); // Stop music (and reset) - - // Decrease loopCount to stop when required - if (music.loopCount > 1) - { - music.loopCount--; // Decrease loop count - PlayMusicStream(music); // Play again - } - else if (music.loopCount == 0) PlayMusicStream(music); + StopMusicStream(music); // Stop music (and reset) + if (music.looping) PlayMusicStream(music); // Play again } else { @@ -1382,13 +1375,6 @@ void SetMusicPitch(Music music, float pitch) SetAudioStreamPitch(music.stream, pitch); } -// Set music loop count (loop repeats) -// NOTE: If set to 0, means infinite loop -void SetMusicLoopCount(Music music, int count) -{ - music.loopCount = count; -} - // Get music time length (in seconds) float GetMusicTimeLength(Music music) { diff --git a/src/raudio.h b/src/raudio.h index 154ae8e5..8056a37e 100644 --- a/src/raudio.h +++ b/src/raudio.h @@ -111,8 +111,8 @@ typedef struct Music { int ctxType; // Type of music context (audio filetype) void *ctxData; // Audio context data, depends on type + bool looping; // Music looping enable unsigned int sampleCount; // Total number of samples - unsigned int loopCount; // Loops count (times music will play), 0 means infinite loop AudioStream stream; // Audio stream } Music; @@ -173,7 +173,6 @@ void ResumeMusicStream(Music music); // Resume playin bool IsMusicPlaying(Music music); // Check if music is playing void SetMusicVolume(Music music, float volume); // Set volume for music (1.0 is max level) void SetMusicPitch(Music music, float pitch); // Set pitch for a music (1.0 is base level) -void SetMusicLoopCount(Music music, int count); // Set music loop count (loop repeats) float GetMusicTimeLength(Music music); // Get music time length (in seconds) float GetMusicTimePlayed(Music music); // Get current music time played (in seconds) diff --git a/src/raylib.h b/src/raylib.h index e6dbf578..d75855d0 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -440,8 +440,8 @@ typedef struct Music { int ctxType; // Type of music context (audio filetype) void *ctxData; // Audio context data, depends on type + bool looping; // Music looping enable unsigned int sampleCount; // Total number of samples - unsigned int loopCount; // Loops count (times music will play), 0 means infinite loop AudioStream stream; // Audio stream } Music; @@ -1435,7 +1435,6 @@ RLAPI void ResumeMusicStream(Music music); // Resume RLAPI bool IsMusicPlaying(Music music); // Check if music is playing RLAPI void SetMusicVolume(Music music, float volume); // Set volume for music (1.0 is max level) RLAPI void SetMusicPitch(Music music, float pitch); // Set pitch for a music (1.0 is base level) -RLAPI void SetMusicLoopCount(Music music, int count); // Set music loop count (loop repeats) RLAPI float GetMusicTimeLength(Music music); // Get music time length (in seconds) RLAPI float GetMusicTimePlayed(Music music); // Get current music time played (in seconds)