summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJeffery Myers <[email protected]>2021-04-09 02:00:21 -0700
committerGitHub <[email protected]>2021-04-09 11:00:21 +0200
commitf6f9a3d9251e5c5d79fafa4c423eca84b689fe7f (patch)
tree2c7629a3c59ce1284463655387373fc2b2a79ecd /src
parent09e6f42f2e6ebfdd0db5fb0258a71f3ef49c7d18 (diff)
downloadraylib-f6f9a3d9251e5c5d79fafa4c423eca84b689fe7f.tar.gz
raylib-f6f9a3d9251e5c5d79fafa4c423eca84b689fe7f.zip
use xm streams in the same sample sample size as the output device (#1716)
Diffstat (limited to 'src')
-rw-r--r--src/raudio.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/src/raudio.c b/src/raudio.c
index b8b98d75..a25245ec 100644
--- a/src/raudio.c
+++ b/src/raudio.c
@@ -1230,8 +1230,14 @@ Music LoadMusicStream(const char *fileName)
{
jar_xm_set_max_loop_count(ctxXm, 0); // Set infinite number of loops
+ unsigned int bits = 32;
+ if (AUDIO_DEVICE_FORMAT == ma_format_s16)
+ bits = 16;
+ else if (AUDIO_DEVICE_FORMAT == ma_format_u8)
+ bits = 8;
+
// NOTE: Only stereo is supported for XM
- music.stream = InitAudioStream(AUDIO.System.device.sampleRate, 16, AUDIO_DEVICE_CHANNELS);
+ music.stream = InitAudioStream(AUDIO.System.device.sampleRate, bits, AUDIO_DEVICE_CHANNELS);
music.sampleCount = (unsigned int)jar_xm_get_remaining_samples(ctxXm)*2; // 2 channels
music.looping = true; // Looping enabled by default
jar_xm_reset(ctxXm); // make sure we start at the beginning of the song
@@ -1398,8 +1404,14 @@ Music LoadMusicStreamFromMemory(const char *fileType, unsigned char* data, int d
music.ctxType = MUSIC_MODULE_XM;
jar_xm_set_max_loop_count(ctxXm, 0); // Set infinite number of loops
+ unsigned int bits = 32;
+ if (AUDIO_DEVICE_FORMAT == ma_format_s16)
+ bits = 16;
+ else if (AUDIO_DEVICE_FORMAT == ma_format_u8)
+ bits = 8;
+
// NOTE: Only stereo is supported for XM
- music.stream = InitAudioStream(AUDIO.System.device.sampleRate, 16, 2);
+ music.stream = InitAudioStream(AUDIO.System.device.sampleRate, bits, 2);
music.sampleCount = (unsigned int)jar_xm_get_remaining_samples(ctxXm)*2; // 2 channels
music.looping = true; // Looping enabled by default
jar_xm_reset(ctxXm); // make sure we start at the beginning of the song
@@ -1639,8 +1651,24 @@ void UpdateMusicStream(Music music)
#if defined(SUPPORT_FILEFORMAT_XM)
case MUSIC_MODULE_XM:
{
- // NOTE: Internally this function considers 2 channels generation, so samplesCount/2
- jar_xm_generate_samples_16bit((jar_xm_context_t *)music.ctxData, (short *)pcm, samplesCount/2);
+ switch (AUDIO_DEVICE_FORMAT)
+ {
+ case ma_format_f32:
+ // NOTE: Internally this function considers 2 channels generation, so samplesCount/2
+ jar_xm_generate_samples((jar_xm_context_t*)music.ctxData, (float*)pcm, samplesCount / 2);
+ break;
+
+ case ma_format_s16:
+ // NOTE: Internally this function considers 2 channels generation, so samplesCount/2
+ jar_xm_generate_samples_16bit((jar_xm_context_t*)music.ctxData, (short*)pcm, samplesCount / 2);
+ break;
+
+ case ma_format_u8:
+ // NOTE: Internally this function considers 2 channels generation, so samplesCount/2
+ jar_xm_generate_samples_8bit((jar_xm_context_t*)music.ctxData, (char*)pcm, samplesCount / 2);
+ break;
+ }
+
} break;
#endif
#if defined(SUPPORT_FILEFORMAT_MOD)