bool return for failed update
This commit is contained in:
parent
289a53221d
commit
790bc72806
3 changed files with 9 additions and 4 deletions
|
@ -256,6 +256,7 @@ void CloseAudioContext(AudioContext ctx)
|
||||||
queued--;
|
queued--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//delete source and buffers
|
||||||
alDeleteSources(1, &context->alSource);
|
alDeleteSources(1, &context->alSource);
|
||||||
alDeleteBuffers(2, context->alBuffer);
|
alDeleteBuffers(2, context->alBuffer);
|
||||||
mixChannelsActive_g[context->mixChannel] = NULL;
|
mixChannelsActive_g[context->mixChannel] = NULL;
|
||||||
|
@ -266,7 +267,8 @@ void CloseAudioContext(AudioContext ctx)
|
||||||
|
|
||||||
// Pushes more audio data into context mix channel, if none are ever pushed then zeros are fed in
|
// 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)" every game tick if you want to pause the audio
|
||||||
void UpdateAudioContext(AudioContext ctx, float *data, unsigned short dataLength)
|
// Returns true if data was pushed onto queue, otherwise if queue is full then no data is added and false is returned
|
||||||
|
bool UpdateAudioContext(AudioContext ctx, float *data, unsigned short dataLength)
|
||||||
{
|
{
|
||||||
AudioContext_t *context = (AudioContext_t*)ctx;
|
AudioContext_t *context = (AudioContext_t*)ctx;
|
||||||
if (context && mixChannelsActive_g[context->mixChannel] == context)
|
if (context && mixChannelsActive_g[context->mixChannel] == context)
|
||||||
|
@ -274,7 +276,9 @@ void UpdateAudioContext(AudioContext ctx, float *data, unsigned short dataLength
|
||||||
ALint processed = 0;
|
ALint processed = 0;
|
||||||
ALuint buffer = 0;
|
ALuint buffer = 0;
|
||||||
alGetSourcei(context->alSource, AL_BUFFERS_PROCESSED, &processed); // Get the number of already processed buffers (if any)
|
alGetSourcei(context->alSource, AL_BUFFERS_PROCESSED, &processed); // Get the number of already processed buffers (if any)
|
||||||
|
|
||||||
|
if(!processed) return false;//nothing to process, queue is still full
|
||||||
|
|
||||||
if (!data || !dataLength)// play silence
|
if (!data || !dataLength)// play silence
|
||||||
while (processed > 0)
|
while (processed > 0)
|
||||||
{
|
{
|
||||||
|
@ -283,6 +287,7 @@ void UpdateAudioContext(AudioContext ctx, float *data, unsigned short dataLength
|
||||||
alSourceQueueBuffers(context->alSource, 1, &buffer);
|
alSourceQueueBuffers(context->alSource, 1, &buffer);
|
||||||
processed--;
|
processed--;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ bool IsAudioDeviceReady(void); // True if call
|
||||||
// all samples are floating point stereo by default
|
// all samples are floating point stereo by default
|
||||||
AudioContext InitAudioContext(unsigned short sampleRate, unsigned char mixChannel);
|
AudioContext InitAudioContext(unsigned short sampleRate, unsigned char mixChannel);
|
||||||
void CloseAudioContext(AudioContext ctx); // Frees audio context
|
void CloseAudioContext(AudioContext ctx); // Frees audio context
|
||||||
void UpdateAudioContext(AudioContext ctx, float *data, unsigned short dataLength); // Pushes more audio data into context mix channel, if NULL is passed to data then zeros are played
|
bool UpdateAudioContext(AudioContext ctx, float *data, unsigned short dataLength); // Pushes more audio data into context mix channel, if NULL is passed to data then zeros are played
|
||||||
|
|
||||||
Sound LoadSound(char *fileName); // Load sound to memory
|
Sound LoadSound(char *fileName); // Load sound to memory
|
||||||
Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data
|
Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data
|
||||||
|
|
|
@ -874,7 +874,7 @@ bool IsAudioDeviceReady(void); // True if call
|
||||||
// all samples are floating point stereo by default
|
// all samples are floating point stereo by default
|
||||||
AudioContext InitAudioContext(unsigned short sampleRate, unsigned char mixChannel);
|
AudioContext InitAudioContext(unsigned short sampleRate, unsigned char mixChannel);
|
||||||
void CloseAudioContext(AudioContext ctx); // Frees audio context
|
void CloseAudioContext(AudioContext ctx); // Frees audio context
|
||||||
void UpdateAudioContext(AudioContext ctx, float *data, unsigned short dataLength); // Pushes more audio data into context mix channel, if NULL is passed to data then zeros are played
|
bool UpdateAudioContext(AudioContext ctx, float *data, unsigned short dataLength); // Pushes more audio data into context mix channel, if NULL is passed to data then zeros are played
|
||||||
|
|
||||||
Sound LoadSound(char *fileName); // Load sound to memory
|
Sound LoadSound(char *fileName); // Load sound to memory
|
||||||
Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data
|
Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue