diff options
| author | Ray San <[email protected]> | 2017-01-18 17:04:20 +0100 |
|---|---|---|
| committer | Ray San <[email protected]> | 2017-01-18 17:04:20 +0100 |
| commit | 46f95a730a68d50c9d369739af61e60961166721 (patch) | |
| tree | eed09414313f7e191c82a6ec5ba873ccb60ea895 /src/audio.c | |
| parent | 6d6659205c04e52b88d5f22eda1722c352f548a9 (diff) | |
| download | raylib-46f95a730a68d50c9d369739af61e60961166721.tar.gz raylib-46f95a730a68d50c9d369739af61e60961166721.zip | |
Corrected bug on OGG sound loading
Diffstat (limited to 'src/audio.c')
| -rw-r--r-- | src/audio.c | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/audio.c b/src/audio.c index 9dedefba..c70c9004 100644 --- a/src/audio.c +++ b/src/audio.c @@ -608,7 +608,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->totalSamples = (unsigned int)stb_vorbis_stream_length_in_samples(music->ctxOgg); + music->totalSamples = (unsigned int)stb_vorbis_stream_length_in_samples(music->ctxOgg); // Independent by channel music->samplesLeft = music->totalSamples; music->ctxType = MUSIC_AUDIO_OGG; music->loop = true; // We loop by default @@ -1134,20 +1134,17 @@ static Wave LoadOGG(const char *fileName) wave.sampleRate = info.sample_rate; wave.sampleSize = 16; // 16 bit per sample (short) wave.channels = info.channels; - - int totalSamplesLength = (stb_vorbis_stream_length_in_samples(oggFile)*info.channels); + wave.sampleCount = (int)stb_vorbis_stream_length_in_samples(oggFile); + float totalSeconds = stb_vorbis_stream_length_in_seconds(oggFile); - if (totalSeconds > 10) TraceLog(WARNING, "[%s] Ogg audio lenght is larger than 10 seconds (%f), that's a big file in memory, consider music streaming", fileName, totalSeconds); - int totalSamples = (int)(totalSeconds*info.sample_rate*info.channels); - wave.sampleCount = totalSamples; - - wave.data = (short *)malloc(totalSamplesLength*sizeof(short)); + wave.data = (short *)malloc(wave.sampleCount*wave.channels*sizeof(short)); - int samplesObtained = stb_vorbis_get_samples_short_interleaved(oggFile, info.channels, (short *)wave.data, totalSamplesLength); + // NOTE: Returns the number of samples to process (be careful! we ask for number of shorts!) + int numSamplesOgg = stb_vorbis_get_samples_short_interleaved(oggFile, info.channels, (short *)wave.data, wave.sampleCount*wave.channels); - TraceLog(DEBUG, "[%s] Samples obtained: %i", fileName, samplesObtained); + TraceLog(DEBUG, "[%s] Samples obtained: %i", fileName, numSamplesOgg); TraceLog(INFO, "[%s] OGG file loaded successfully (%i Hz, %i bit, %s)", fileName, wave.sampleRate, wave.sampleSize, (wave.channels == 1) ? "Mono" : "Stereo"); |
