From b30995e14a3d20d3ad9a05dd0e77669cf09d6840 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 29 Jul 2021 18:50:54 +1000 Subject: [PATCH] Remove Audio_Stop from API --- src/Audio.c | 15 ++++++++------- src/Audio.h | 6 ++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Audio.c b/src/Audio.c index 5c74fd887..c83f8efa2 100644 --- a/src/Audio.c +++ b/src/Audio.c @@ -242,7 +242,9 @@ cc_result Audio_Play(struct AudioContext* ctx) { return _alGetError(); } -void Audio_Stop(struct AudioContext* ctx) { +static void Backend_Stop(struct AudioContext* ctx) { + if (ctx->source == -1) return; + _alSourceStop(ctx->source); _alGetError(); } @@ -387,7 +389,7 @@ cc_result Audio_BufferData(struct AudioContext* ctx, int idx, void* data, cc_uin cc_result Audio_Play(struct AudioContext* ctx) { return 0; } -void Audio_Stop(struct AudioContext* ctx) { +static void Backend_Stop(struct AudioContext* ctx) { if (ctx->handle) waveOutReset(ctx->handle); } @@ -575,7 +577,7 @@ cc_result Audio_Play(struct AudioContext* ctx) { return (*ctx->bqPlayerPlayer)->SetPlayState(ctx->bqPlayerPlayer, SL_PLAYSTATE_PLAYING); } -void Audio_Stop(struct AudioContext* ctx) { +static void Backend_Stop(struct AudioContext* ctx) { if (!ctx->bqPlayerPlayer) return; (*ctx->bqPlayerQueue)->Clear(ctx->bqPlayerQueue); @@ -635,7 +637,7 @@ cc_result Audio_SetFormat(struct AudioContext* ctx, struct AudioFormat* format) void Audio_Close(struct AudioContext* ctx) { cc_bool finished; - Audio_Stop(ctx); + Backend_Stop(ctx); Audio_IsFinished(ctx, &finished); /* unqueue buffers */ ctx->count = 0; @@ -812,7 +814,6 @@ static void Sounds_PlayRaw(struct SoundOutput* output, struct Sound* snd, struct void* data = snd->data; void* tmp; cc_result res; - if ((res = Audio_SetFormat(&output->ctx, fmt))) { Sounds_Fail(res); return; } /* copy to temp buffer to apply volume */ if (volume < 100) { @@ -835,6 +836,7 @@ static void Sounds_PlayRaw(struct SoundOutput* output, struct Sound* snd, struct Volume_Mix16((cc_int16*)data, snd->size / 2, volume); } + if ((res = Audio_SetFormat(&output->ctx, fmt))) { Sounds_Fail(res); return; } if ((res = Audio_BufferData(&output->ctx, 0, data, snd->size))) { Sounds_Fail(res); return; } if ((res = Audio_Play(&output->ctx))) { Sounds_Fail(res); return; } } @@ -1027,9 +1029,8 @@ static cc_result Music_PlayOgg(struct Stream* source) { if (res) break; } - if (music_pendingStop) Audio_Stop(&music_ctx); /* Wait until the buffers finished playing */ - for (;;) { + while (!music_pendingStop) { if (Audio_IsFinished(&music_ctx, &finished) || finished) break; Thread_Sleep(10); } diff --git a/src/Audio.h b/src/Audio.h index 29e540a25..f351ef895 100644 --- a/src/Audio.h +++ b/src/Audio.h @@ -22,12 +22,12 @@ void Audio_PlayStepSound(cc_uint8 type); #define AUDIO_MAX_BUFFERS 4 /* Information about a source of audio. */ -struct AudioFormat { cc_uint16 channels; int sampleRate; }; +struct AudioFormat { int channels, sampleRate; }; #define AudioFormat_Eq(a, b) ((a)->channels == (b)->channels && (a)->sampleRate == (b)->sampleRate) /* Initialises an audio context. */ void Audio_Init(struct AudioContext* ctx, int buffers); -/* Stops playing audio, and then frees the audio context. */ +/* Stops any playing audio and then frees the audio context. */ void Audio_Close(struct AudioContext* ctx); /* Returns the format audio is played in. */ struct AudioFormat* Audio_GetFormat(struct AudioContext* ctx); @@ -39,8 +39,6 @@ cc_result Audio_SetFormat(struct AudioContext* ctx, struct AudioFormat* format); cc_result Audio_BufferData(struct AudioContext* ctx, int idx, void* data, cc_uint32 size); /* Begins playing audio. Audio_BufferData must have been used before this. */ cc_result Audio_Play(struct AudioContext* ctx); -/* Immediately stops the currently playing audio. */ -void Audio_Stop(struct AudioContext* ctx); /* Returns whether the given buffer is available for playing data. */ cc_result Audio_IsAvailable(struct AudioContext* ctx, int idx, cc_bool* available); /* Returns whether all buffers have finished playing. */