Quellcode durchsuchen

[AUDIO] Music Looping enhancements (#1665)

* Add loop functions for music files.
Tell xm tracker to loop tracker when loop state changes.
Don't let looped xm tracker streams restart, they are infinite
Use modulo to make time tracker for xm looped streams work correctly.

* Remove loop functions, set XM loop in update based on flag.
Formatting cleanups.

Co-authored-by: Jeffery Myers <JefMyers@blizzard.com>
pull/1669/head
Jeffery Myers vor 4 Jahren
committed von GitHub
Ursprung
Commit
2c0a533948
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 21 neuen und 6 gelöschten Zeilen
  1. +20
    -5
      src/raudio.c
  2. +1
    -1
      src/raylib.h

+ 20
- 5
src/raudio.c Datei anzeigen

@ -1575,7 +1575,11 @@ void StopMusicStream(Music music)
// Update (re-fill) music buffers if data already processed
void UpdateMusicStream(Music music)
{
if (music.stream.buffer == NULL) return;
if (music.stream.buffer == NULL)
return;
if (music.ctxType == MUSIC_MODULE_XM)
jar_xm_set_max_loop_count(music.ctxData, music.looping ? 0 : 1);
bool streamEnding = false;
@ -1590,6 +1594,8 @@ void UpdateMusicStream(Music music)
//ma_uint32 frameSizeInBytes = ma_get_bytes_per_sample(music.stream.buffer->dsp.formatConverterIn.config.formatIn)*music.stream.buffer->dsp.formatConverterIn.config.channels;
int sampleLeft = music.sampleCount - (music.stream.buffer->totalFramesProcessed*music.stream.channels);
if (music.ctxType == MUSIC_MODULE_XM && music.looping) sampleLeft = subBufferSizeInFrames*4;
while (IsAudioStreamProcessed(music.stream))
{
if ((sampleLeft/music.stream.channels) >= subBufferSizeInFrames) samplesCount = subBufferSizeInFrames*music.stream.channels;
@ -1649,10 +1655,10 @@ void UpdateMusicStream(Music music)
UpdateAudioStream(music.stream, pcm, samplesCount);
if ((music.ctxType == MUSIC_MODULE_XM) || p">(music.ctxType == MUSIC_MODULE_MOD))
if ((music.ctxType == MUSIC_MODULE_XM) || music.ctxType == MUSIC_MODULE_MOD)
{
if (samplesCount > 1) sampleLeft -= samplesCount/2;
else sampleLeft -= samplesCount;
if (samplesCount > 1) sampleLeft -= samplesCount / 2;
else sampleLeft -= samplesCount;
}
else sampleLeft -= samplesCount;
@ -1711,8 +1717,17 @@ float GetMusicTimeLength(Music music)
// Get current music time played (in seconds)
float GetMusicTimePlayed(Music music)
{
#if defined(SUPPORT_FILEFORMAT_XM)
if (music.ctxType == MUSIC_MODULE_XM)
{
uint64_t samples = 0;
jar_xm_get_position(music.ctxData, NULL, NULL, NULL, &samples);
samples = samples % (music.sampleCount);
return (float)(samples) / (music.stream.sampleRate * music.stream.channels);
}
#endif
float secondsPlayed = 0.0f;
if (music.stream.buffer != NULL)
{
//ma_uint32 frameSizeInBytes = ma_get_bytes_per_sample(music.stream.buffer->dsp.formatConverterIn.config.formatIn)*music.stream.buffer->dsp.formatConverterIn.config.channels;

+ 1
- 1
src/raylib.h Datei anzeigen

@ -1489,9 +1489,9 @@ RLAPI void UpdateMusicStream(Music music); // Updates
RLAPI void StopMusicStream(Music music); // Stop music playing
RLAPI void PauseMusicStream(Music music); // Pause music playing
RLAPI void ResumeMusicStream(Music music); // Resume playing paused music
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 SetMusicLooping(Music *music, bool loop); // Set the music to loop or not
RLAPI float GetMusicTimeLength(Music music); // Get music time length (in seconds)
RLAPI float GetMusicTimePlayed(Music music); // Get current music time played (in seconds)

Laden…
Abbrechen
Speichern