浏览代码

[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 4 年前
committed by GitHub
父节点
当前提交
2c0a533948
找不到此签名对应的密钥 GPG 密钥 ID: 4AEE18F83AFDEB23
共有 2 个文件被更改,包括 21 次插入6 次删除
  1. +20
    -5
      src/raudio.c
  2. +1
    -1
      src/raylib.h

+ 20
- 5
src/raudio.c 查看文件

@ -1575,7 +1575,11 @@ void StopMusicStream(Music music)
// Update (re-fill) music buffers if data already processed // Update (re-fill) music buffers if data already processed
void UpdateMusicStream(Music music) 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; 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; //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); 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)) while (IsAudioStreamProcessed(music.stream))
{ {
if ((sampleLeft/music.stream.channels) >= subBufferSizeInFrames) samplesCount = subBufferSizeInFrames*music.stream.channels; if ((sampleLeft/music.stream.channels) >= subBufferSizeInFrames) samplesCount = subBufferSizeInFrames*music.stream.channels;
@ -1649,10 +1655,10 @@ void UpdateMusicStream(Music music)
UpdateAudioStream(music.stream, pcm, samplesCount); 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; else sampleLeft -= samplesCount;
@ -1711,8 +1717,17 @@ float GetMusicTimeLength(Music music)
// Get current music time played (in seconds) // Get current music time played (in seconds)
float GetMusicTimePlayed(Music music) 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; float secondsPlayed = 0.0f;
if (music.stream.buffer != NULL) 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; //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 查看文件

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

正在加载...
取消
保存