Remove loop functions, set XM loop in update based on flag.
Formatting cleanups.
This commit is contained in:
parent
f8e5a87af5
commit
de06097261
60
src/raudio.c
60
src/raudio.c
|
|
@ -1322,8 +1322,7 @@ Music LoadMusicStreamFromMemory(const char *fileType, unsigned char* data, int d
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
int sampleSize = ctxWav->bitsPerSample;
|
int sampleSize = ctxWav->bitsPerSample;
|
||||||
if (ctxWav->bitsPerSample == 24)
|
if (ctxWav->bitsPerSample == 24) sampleSize = 16; // Forcing conversion to s16 on UpdateMusicStream()
|
||||||
sampleSize = 16; // Forcing conversion to s16 on UpdateMusicStream()
|
|
||||||
|
|
||||||
music.stream = InitAudioStream(ctxWav->sampleRate, sampleSize, ctxWav->channels);
|
music.stream = InitAudioStream(ctxWav->sampleRate, sampleSize, ctxWav->channels);
|
||||||
music.sampleCount = (unsigned int)ctxWav->totalPCMFrameCount*ctxWav->channels;
|
music.sampleCount = (unsigned int)ctxWav->totalPCMFrameCount*ctxWav->channels;
|
||||||
|
|
@ -1579,6 +1578,9 @@ void UpdateMusicStream(Music music)
|
||||||
if (music.stream.buffer == NULL)
|
if (music.stream.buffer == NULL)
|
||||||
return;
|
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;
|
||||||
|
|
||||||
unsigned int subBufferSizeInFrames = music.stream.buffer->sizeInFrames/2;
|
unsigned int subBufferSizeInFrames = music.stream.buffer->sizeInFrames/2;
|
||||||
|
|
@ -1592,15 +1594,12 @@ 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)
|
if (music.ctxType == MUSIC_MODULE_XM && music.looping) sampleLeft = subBufferSizeInFrames*4;
|
||||||
sampleLeft = subBufferSizeInFrames*4;
|
|
||||||
|
|
||||||
while (IsAudioStreamProcessed(music.stream))
|
while (IsAudioStreamProcessed(music.stream))
|
||||||
{
|
{
|
||||||
if ((sampleLeft/music.stream.channels) >= subBufferSizeInFrames)
|
if ((sampleLeft/music.stream.channels) >= subBufferSizeInFrames) samplesCount = subBufferSizeInFrames*music.stream.channels;
|
||||||
samplesCount = subBufferSizeInFrames*music.stream.channels;
|
else samplesCount = sampleLeft;
|
||||||
else
|
|
||||||
samplesCount = sampleLeft;
|
|
||||||
|
|
||||||
switch (music.ctxType)
|
switch (music.ctxType)
|
||||||
{
|
{
|
||||||
|
|
@ -1608,10 +1607,8 @@ void UpdateMusicStream(Music music)
|
||||||
case MUSIC_AUDIO_WAV:
|
case MUSIC_AUDIO_WAV:
|
||||||
{
|
{
|
||||||
// NOTE: Returns the number of samples to process (not required)
|
// NOTE: Returns the number of samples to process (not required)
|
||||||
if (music.stream.sampleSize == 16)
|
if (music.stream.sampleSize == 16) drwav_read_pcm_frames_s16((drwav *)music.ctxData, samplesCount/music.stream.channels, (short *)pcm);
|
||||||
drwav_read_pcm_frames_s16((drwav *)music.ctxData, samplesCount/music.stream.channels, (short *)pcm);
|
else if (music.stream.sampleSize == 32) drwav_read_pcm_frames_f32((drwav *)music.ctxData, samplesCount/music.stream.channels, (float *)pcm);
|
||||||
else if (music.stream.sampleSize == 32)
|
|
||||||
drwav_read_pcm_frames_f32((drwav *)music.ctxData, samplesCount/music.stream.channels, (float *)pcm);
|
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -1660,13 +1657,10 @@ void UpdateMusicStream(Music music)
|
||||||
|
|
||||||
if ((music.ctxType == MUSIC_MODULE_XM) || music.ctxType == MUSIC_MODULE_MOD)
|
if ((music.ctxType == MUSIC_MODULE_XM) || music.ctxType == MUSIC_MODULE_MOD)
|
||||||
{
|
{
|
||||||
if (samplesCount > 1)
|
if (samplesCount > 1) sampleLeft -= samplesCount / 2;
|
||||||
sampleLeft -= samplesCount / 2;
|
else sampleLeft -= samplesCount;
|
||||||
else
|
|
||||||
sampleLeft -= samplesCount;
|
|
||||||
}
|
}
|
||||||
else
|
else sampleLeft -= samplesCount;
|
||||||
sampleLeft -= samplesCount;
|
|
||||||
|
|
||||||
if (sampleLeft <= 0)
|
if (sampleLeft <= 0)
|
||||||
{
|
{
|
||||||
|
|
@ -1682,15 +1676,13 @@ void UpdateMusicStream(Music music)
|
||||||
if (streamEnding)
|
if (streamEnding)
|
||||||
{
|
{
|
||||||
StopMusicStream(music); // Stop music (and reset)
|
StopMusicStream(music); // Stop music (and reset)
|
||||||
if (music.looping)
|
if (music.looping) PlayMusicStream(music); // Play again
|
||||||
PlayMusicStream(music); // Play again
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// NOTE: In case window is minimized, music stream is stopped,
|
// NOTE: In case window is minimized, music stream is stopped,
|
||||||
// just make sure to play again on window restore
|
// just make sure to play again on window restore
|
||||||
if (IsMusicPlaying(music))
|
if (IsMusicPlaying(music)) PlayMusicStream(music);
|
||||||
PlayMusicStream(music);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1711,24 +1703,6 @@ void SetMusicPitch(Music music, float pitch)
|
||||||
{
|
{
|
||||||
SetAudioBufferPitch(music.stream.buffer, pitch);
|
SetAudioBufferPitch(music.stream.buffer, pitch);
|
||||||
}
|
}
|
||||||
// Set the music to loop or not
|
|
||||||
void SetMusicLooping(Music *music, bool loop)
|
|
||||||
{
|
|
||||||
music->looping = loop;
|
|
||||||
|
|
||||||
#if defined(SUPPORT_FILEFORMAT_XM)
|
|
||||||
if (music->ctxType == MUSIC_MODULE_XM)
|
|
||||||
{
|
|
||||||
jar_xm_set_max_loop_count(music->ctxData, loop ? 0 : 1);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the loop status of the music file
|
|
||||||
bool GetMusicLooping(Music music)
|
|
||||||
{
|
|
||||||
return music.looping;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get music time length (in seconds)
|
// Get music time length (in seconds)
|
||||||
float GetMusicTimeLength(Music music)
|
float GetMusicTimeLength(Music music)
|
||||||
|
|
@ -1838,8 +1812,7 @@ void UpdateAudioStream(AudioStream stream, const void *data, int samplesCount)
|
||||||
{
|
{
|
||||||
ma_uint32 framesToWrite = subBufferSizeInFrames;
|
ma_uint32 framesToWrite = subBufferSizeInFrames;
|
||||||
|
|
||||||
if (framesToWrite > ((ma_uint32)samplesCount/stream.channels))
|
if (framesToWrite > ((ma_uint32)samplesCount/stream.channels)) framesToWrite = (ma_uint32)samplesCount/stream.channels;
|
||||||
framesToWrite = (ma_uint32)samplesCount/stream.channels;
|
|
||||||
|
|
||||||
ma_uint32 bytesToWrite = framesToWrite*stream.channels*(stream.sampleSize/8);
|
ma_uint32 bytesToWrite = framesToWrite*stream.channels*(stream.sampleSize/8);
|
||||||
memcpy(subBuffer, data, bytesToWrite);
|
memcpy(subBuffer, data, bytesToWrite);
|
||||||
|
|
@ -1847,8 +1820,7 @@ void UpdateAudioStream(AudioStream stream, const void *data, int samplesCount)
|
||||||
// Any leftover frames should be filled with zeros.
|
// Any leftover frames should be filled with zeros.
|
||||||
ma_uint32 leftoverFrameCount = subBufferSizeInFrames - framesToWrite;
|
ma_uint32 leftoverFrameCount = subBufferSizeInFrames - framesToWrite;
|
||||||
|
|
||||||
if (leftoverFrameCount > 0)
|
if (leftoverFrameCount > 0) memset(subBuffer + bytesToWrite, 0, leftoverFrameCount*stream.channels*(stream.sampleSize/8));
|
||||||
memset(subBuffer + bytesToWrite, 0, leftoverFrameCount*stream.channels*(stream.sampleSize/8));
|
|
||||||
|
|
||||||
stream.buffer->isSubBufferProcessed[subBufferToUpdate] = false;
|
stream.buffer->isSubBufferProcessed[subBufferToUpdate] = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1489,13 +1489,11 @@ 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 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)
|
||||||
RLAPI bool GetMusicLooping(Music music); // Get the loop status of the music file
|
|
||||||
|
|
||||||
// AudioStream management functions
|
// AudioStream management functions
|
||||||
RLAPI AudioStream InitAudioStream(unsigned int sampleRate, unsigned int sampleSize, unsigned int channels); // Init audio stream (to stream raw audio pcm data)
|
RLAPI AudioStream InitAudioStream(unsigned int sampleRate, unsigned int sampleSize, unsigned int channels); // Init audio stream (to stream raw audio pcm data)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user