From ea4b5552c2b4ff8a907dd1fefc084317187af168 Mon Sep 17 00:00:00 2001 From: Joshua Reisenauer Date: Sat, 14 May 2016 00:25:40 -0700 Subject: [PATCH] corrected typos --- src/audio.c | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/audio.c b/src/audio.c index d19d3306..c53d6318 100644 --- a/src/audio.c +++ b/src/audio.c @@ -85,7 +85,7 @@ typedef struct AudioContext_t { unsigned char channels; // 1=mono,2=stereo unsigned char mixChannel; // 0-3 or mixA-mixD, each mix channel can receive up to one dedicated audio stream bool floatingPoint; // if false then the short datatype is used instead - bool playing; + bool playing; // false if paused ALenum alFormat; // openAL format specifier ALuint alSource; // openAL source ALuint alBuffer[MAX_STREAM_BUFFERS]; // openAL sample buffer @@ -165,13 +165,14 @@ void InitAudioDevice(void) alListener3f(AL_ORIENTATION, 0, 0, -1); } -// Close the audio device for the current context, and destroys the context +// Close the audio device for all contexts void CloseAudioDevice(void) { for(int index=0; indexplaying = true; currentMusic[musicIndex].totalSamplesLeft = stb_vorbis_stream_length_in_samples(currentMusic[musicIndex].stream) * info.channels; currentMusic[musicIndex].totalLengthSeconds = stb_vorbis_stream_length_in_seconds(currentMusic[musicIndex].stream); @@ -822,6 +824,7 @@ int PlayMusicStream(int musicIndex, char *fileName) currentMusic[musicIndex].totalSamplesLeft = jar_xm_get_remaining_samples(currentMusic[musicIndex].chipctx); currentMusic[musicIndex].totalLengthSeconds = ((float)currentMusic[musicIndex].totalSamplesLeft) / 48000.f; musicEnabled = true; + currentMusic[musicIndex].ctx->playing = true; TraceLog(INFO, "[%s] XM number of samples: %i", fileName, currentMusic[musicIndex].totalSamplesLeft); TraceLog(INFO, "[%s] XM track length: %11.6f sec", fileName, currentMusic[musicIndex].totalLengthSeconds); @@ -859,16 +862,21 @@ void StopMusicStream(int index) } if(!getMusicStreamCount()) musicEnabled = false; + if(currentMusic[index].stream || currentMusic[index].chipctx) + { + currentMusic[index].stream = NULL; + currentMusic[index].chipctx = NULL; + } } } //get number of music channels active at this time, this does not mean they are playing int getMusicStreamCount(void) { - int musicCount; + int musicCount = 0; for(int musicIndex = 0; musicIndex < MAX_MUSIC_STREAMS; musicIndex++) // find empty music slot if(currentMusic[musicIndex].stream != NULL || currentMusic[musicIndex].chipTune) musicCount++; - + return musicCount; } @@ -876,11 +884,11 @@ int getMusicStreamCount(void) void PauseMusicStream(int index) { // Pause music stream if music available! - if (musicEnabled) + if (currentMusic[index].ctx && musicEnabled) { TraceLog(INFO, "Pausing music stream"); - UpdateAudioContext(currentMusic[index].ctx, NULL, 0); // pushing null data auto pauses stream - musicEnabled = false; + alSourcePause(currentMusic[index].ctx->alSource); + currentMusic[index].ctx->playing = false; } } @@ -895,7 +903,7 @@ void ResumeMusicStream(int index) { TraceLog(INFO, "Resuming music stream"); alSourcePlay(currentMusic[index].ctx->alSource); - musicEnabled = true; + currentMusic[index].ctx->playing = true; } } } @@ -981,13 +989,17 @@ static bool BufferMusicStream(int index) if (musicEnabled) { + if(!currentMusic[index].ctx->playing) + { + UpdateAudioContext(currentMusic[index].ctx, NULL, 0); + return false; + } + if (currentMusic[index].chipTune) // There is no end of stream for xmfiles, once the end is reached zeros are generated for non looped chiptunes. { - int readlen = MUSIC_BUFFER_SIZE_FLOAT / 2; - jar_xm_generate_samples(currentMusic[index].chipctx, pcmf, readlen); // reads 2*readlen shorts and moves them to buffer+size memory location + jar_xm_generate_samples(currentMusic[index].chipctx, pcmf, MUSIC_BUFFER_SIZE_FLOAT / 2); // reads 2*readlen shorts and moves them to buffer+size memory location UpdateAudioContext(currentMusic[index].ctx, pcmf, MUSIC_BUFFER_SIZE_FLOAT); - size += readlen * currentMusic[index].ctx->channels; // Not sure if this is what it needs - currentMusic[index].totalSamplesLeft -= size; + currentMusic[index].totalSamplesLeft -= MUSIC_BUFFER_SIZE_FLOAT; if(currentMusic[index].totalSamplesLeft <= 0) active = false; } else @@ -997,7 +1009,7 @@ static bool BufferMusicStream(int index) currentMusic[index].totalSamplesLeft -= streamedBytes*currentMusic[index].ctx->channels; if(currentMusic[index].totalSamplesLeft <= 0) active = false; } - // TraceLog(DEBUG, "Streaming music data to buffer. Bytes streamed: %i", size); + TraceLog(DEBUG, "Buffering index:%i, chiptune:%i", index, (int)currentMusic[index].chipTune); } return active;