aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoshua Reisenauer <kd7tck@msn.com>2016-05-03 02:52:45 -0700
committerJoshua Reisenauer <kd7tck@msn.com>2016-05-03 02:52:45 -0700
commitd6feeb14ffc11e54a82f51dbbe899f720d6997e8 (patch)
tree4c297f995075bd6e1465f85da9001c6d701006ab /src
parent9d09ada33b26704a7f5d285d2f0d115e41df41bf (diff)
downloadraylib-d6feeb14ffc11e54a82f51dbbe899f720d6997e8.tar.gz
raylib-d6feeb14ffc11e54a82f51dbbe899f720d6997e8.zip
pause on no data
Diffstat (limited to 'src')
-rw-r--r--src/audio.c31
-rw-r--r--src/easings.h17
2 files changed, 32 insertions, 16 deletions
diff --git a/src/audio.c b/src/audio.c
index dc063796..a46aa00a 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -114,11 +114,10 @@ typedef enum { INFO = 0, ERROR, WARNING, DEBUG, OTHER } TraceLogType;
//----------------------------------------------------------------------------------
// Global Variables Definition
//----------------------------------------------------------------------------------
-static AudioContext_t* mixChannelsActive_g[MAX_AUDIO_CONTEXTS]; // What mix channels are currently active
+static AudioContext_t* mixChannelsActive_g[MAX_AUDIO_CONTEXTS]; // What mix channels are currently active
static bool musicEnabled = false;
static Music currentMusic; // Current music loaded
// NOTE: Only one music file playing at a time
-
//----------------------------------------------------------------------------------
// Module specific Functions Declaration
//----------------------------------------------------------------------------------
@@ -286,34 +285,34 @@ void CloseAudioContext(AudioContext ctx)
}
// Pushes more audio data into context mix channel, if none are ever pushed then zeros are fed in.
-// Call "UpdateAudioContext(ctx, NULL, 0)" every game tick if you want to pause the audio.
+// Call "UpdateAudioContext(ctx, NULL, 0)" if you want to pause the audio.
// @Returns number of samples that where processed.
// All data streams should be of a length that is evenly divisible by MUSIC_BUFFER_SIZE,
// otherwise the remaining data will not be pushed.
unsigned short UpdateAudioContext(AudioContext ctx, void *data, unsigned short numberElements)
{
- unsigned short numberProcessed = 0;
- unsigned short numberRemaining = numberElements;
AudioContext_t *context = (AudioContext_t*)ctx;
+ if(context && context->channels == 2 && numberElements % 2 != 0) return 0; // when there is two channels there must be an even number of samples
+
+ if (!data || !numberElements) alSourcePause(context->alSource); // pauses audio until data is given
+ else{ // restart audio otherwise
+ ALint state;
+ alGetSourcei(context->alSource, AL_SOURCE_STATE, &state);
+ if (state != AL_PLAYING) alSourcePlay(context->alSource);
+ }
+
if (context && mixChannelsActive_g[context->mixChannel] == context)
{
ALint processed = 0;
ALuint buffer = 0;
- alGetSourcei(context->alSource, AL_BUFFERS_PROCESSED, &processed); // Get the number of already processed buffers (if any)
+ unsigned short numberProcessed = 0;
+ unsigned short numberRemaining = numberElements;
+
+ alGetSourcei(context->alSource, AL_BUFFERS_PROCESSED, &processed); // Get the number of already processed buffers (if any)
if(!processed) return 0;//nothing to process, queue is still full
- if (!data || !numberElements)// play silence
- {
- while (processed > 0)
- {
- alSourceUnqueueBuffers(context->alSource, 1, &buffer);
- numberProcessed += FillAlBufferWithSilence(context, buffer);
- alSourceQueueBuffers(context->alSource, 1, &buffer);
- processed--;
- }
- }
if(numberRemaining)// buffer data stream in increments of MUSIC_BUFFER_SIZE
{
while (processed > 0)
diff --git a/src/easings.h b/src/easings.h
index a198be4d..e1e5465a 100644
--- a/src/easings.h
+++ b/src/easings.h
@@ -7,6 +7,23 @@
* This header uses:
* #define EASINGS_STATIC_INLINE // Inlines all functions code, so it runs faster.
* // This requires lots of memory on system.
+* How to use:
+* The four inputs t,b,c,d are defined as follows:
+* t = current time in milliseconds
+* b = starting position in only one dimension [X || Y || Z] your choice
+* c = the total change in value of b that needs to occur
+* d = total time it should take to complete
+*
+* Example:
+* float speed = 1.f;
+* float currentTime = 0.f;
+* float currentPos[2] = {0,0};
+* float newPos[2] = {1,1};
+* float tempPosition[2] = currentPos;//x,y positions
+* while(currentPos[0] < newPos[0])
+* currentPos[0] = EaseSineIn(currentTime, tempPosition[0], tempPosition[0]-newPos[0], speed);
+* currentPos[1] = EaseSineIn(currentTime, tempPosition[1], tempPosition[1]-newPos[0], speed);
+* currentTime += diffTime();
*
* A port of Robert Penner's easing equations to C (http://robertpenner.com/easing/)
*