mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 01:55:19 -04:00
Split up Audio_Close and mostly move into backend
This commit is contained in:
parent
a3e81f3f57
commit
37dfbcfefd
80
src/Audio.c
80
src/Audio.c
@ -52,6 +52,7 @@ static int GetVolume(const char* volKey, const char* boolKey) {
|
|||||||
static void AudioWarn(cc_result res, const char* action) {
|
static void AudioWarn(cc_result res, const char* action) {
|
||||||
Logger_Warn(res, action, Audio_DescribeError);
|
Logger_Warn(res, action, Audio_DescribeError);
|
||||||
}
|
}
|
||||||
|
static void AudioContext_Clear(struct AudioContext* ctx);
|
||||||
|
|
||||||
|
|
||||||
#if defined CC_BUILD_OPENAL
|
#if defined CC_BUILD_OPENAL
|
||||||
@ -200,15 +201,26 @@ void Audio_Init(struct AudioContext* ctx, int buffers) {
|
|||||||
ctx->count = buffers;
|
ctx->count = buffers;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AudioBackend_Reset(struct AudioContext* ctx) {
|
static void Audio_Stop(struct AudioContext* ctx) {
|
||||||
ClearFree(ctx);
|
_alSourceStop(ctx->source);
|
||||||
if (!ctx->source) return;
|
}
|
||||||
|
|
||||||
_alDeleteSources(1, &ctx->source);
|
static void Audio_Reset(struct AudioContext* ctx) {
|
||||||
|
_alDeleteSources(1, &ctx->source);
|
||||||
_alDeleteBuffers(ctx->count, ctx->buffers);
|
_alDeleteBuffers(ctx->count, ctx->buffers);
|
||||||
ctx->source = 0;
|
ctx->source = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Audio_Close(struct AudioContext* ctx) {
|
||||||
|
if (ctx->source) {
|
||||||
|
Audio_Stop(ctx);
|
||||||
|
Audio_Reset(ctx);
|
||||||
|
_alGetError();
|
||||||
|
}
|
||||||
|
ClearFree(ctx->source);
|
||||||
|
AudioContext_Clear(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
cc_result Audio_SetFormat(struct AudioContext* ctx, int channels, int sampleRate) {
|
cc_result Audio_SetFormat(struct AudioContext* ctx, int channels, int sampleRate) {
|
||||||
ALenum i, err;
|
ALenum i, err;
|
||||||
if (!ctx->source) {
|
if (!ctx->source) {
|
||||||
@ -254,13 +266,6 @@ cc_result Audio_Play(struct AudioContext* ctx) {
|
|||||||
return _alGetError();
|
return _alGetError();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AudioBackend_Stop(struct AudioContext* ctx) {
|
|
||||||
if (!ctx->source) return;
|
|
||||||
|
|
||||||
_alSourceStop(ctx->source);
|
|
||||||
_alGetError();
|
|
||||||
}
|
|
||||||
|
|
||||||
cc_result Audio_Poll(struct AudioContext* ctx, int* inUse) {
|
cc_result Audio_Poll(struct AudioContext* ctx, int* inUse) {
|
||||||
ALint processed = 0;
|
ALint processed = 0;
|
||||||
ALuint buffer;
|
ALuint buffer;
|
||||||
@ -377,7 +382,11 @@ void Audio_Init(struct AudioContext* ctx, int buffers) {
|
|||||||
ctx->count = buffers;
|
ctx->count = buffers;
|
||||||
}
|
}
|
||||||
|
|
||||||
static cc_result AudioBackend_Reset(struct AudioContext* ctx) {
|
static void Audio_Stop(struct AudioContext* ctx) {
|
||||||
|
waveOutReset(ctx->handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
static cc_result Audio_Reset(struct AudioContext* ctx) {
|
||||||
cc_result res;
|
cc_result res;
|
||||||
if (!ctx->handle) return 0;
|
if (!ctx->handle) return 0;
|
||||||
|
|
||||||
@ -386,6 +395,16 @@ static cc_result AudioBackend_Reset(struct AudioContext* ctx) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Audio_Close(struct AudioContext* ctx) {
|
||||||
|
int inUse;
|
||||||
|
if (ctx->handle) {
|
||||||
|
Audio_Stop(ctx);
|
||||||
|
Audio_Poll(ctx, &inUse); /* unprepare buffers */
|
||||||
|
Audio_Reset(ctx);
|
||||||
|
}
|
||||||
|
AudioContext_Clear(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
cc_result Audio_SetFormat(struct AudioContext* ctx, int channels, int sampleRate) {
|
cc_result Audio_SetFormat(struct AudioContext* ctx, int channels, int sampleRate) {
|
||||||
WAVEFORMATEX fmt;
|
WAVEFORMATEX fmt;
|
||||||
cc_result res;
|
cc_result res;
|
||||||
@ -396,7 +415,7 @@ cc_result Audio_SetFormat(struct AudioContext* ctx, int channels, int sampleRate
|
|||||||
ctx->sampleRate = sampleRate;
|
ctx->sampleRate = sampleRate;
|
||||||
|
|
||||||
sampleSize = channels * 2; /* 16 bits per sample / 8 */
|
sampleSize = channels * 2; /* 16 bits per sample / 8 */
|
||||||
if ((res = AudioBackend_Reset(ctx))) return res;
|
if ((res = Audio_Reset(ctx))) return res;
|
||||||
|
|
||||||
fmt.wFormatTag = WAVE_FORMAT_PCM;
|
fmt.wFormatTag = WAVE_FORMAT_PCM;
|
||||||
fmt.nChannels = channels;
|
fmt.nChannels = channels;
|
||||||
@ -432,10 +451,6 @@ cc_result Audio_QueueData(struct AudioContext* ctx, void* data, cc_uint32 dataSi
|
|||||||
|
|
||||||
cc_result Audio_Play(struct AudioContext* ctx) { return 0; }
|
cc_result Audio_Play(struct AudioContext* ctx) { return 0; }
|
||||||
|
|
||||||
static void AudioBackend_Stop(struct AudioContext* ctx) {
|
|
||||||
if (ctx->handle) waveOutReset(ctx->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
cc_result Audio_Poll(struct AudioContext* ctx, int* inUse) {
|
cc_result Audio_Poll(struct AudioContext* ctx, int* inUse) {
|
||||||
cc_result res = 0;
|
cc_result res = 0;
|
||||||
WAVEHDR* hdr;
|
WAVEHDR* hdr;
|
||||||
@ -557,7 +572,14 @@ void Audio_Init(struct AudioContext* ctx, int buffers) {
|
|||||||
ctx->count = buffers;
|
ctx->count = buffers;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AudioBackend_Reset(struct AudioContext* ctx) {
|
static void Audio_Stop(struct AudioContext* ctx) {
|
||||||
|
if (!ctx->bqPlayerPlayer) return;
|
||||||
|
|
||||||
|
(*ctx->bqPlayerQueue)->Clear(ctx->bqPlayerQueue);
|
||||||
|
(*ctx->bqPlayerPlayer)->SetPlayState(ctx->bqPlayerPlayer, SL_PLAYSTATE_STOPPED);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Audio_Reset(struct AudioContext* ctx) {
|
||||||
SLObjectItf bqPlayerObject = ctx->bqPlayerObject;
|
SLObjectItf bqPlayerObject = ctx->bqPlayerObject;
|
||||||
if (!bqPlayerObject) return;
|
if (!bqPlayerObject) return;
|
||||||
|
|
||||||
@ -567,6 +589,12 @@ static void AudioBackend_Reset(struct AudioContext* ctx) {
|
|||||||
ctx->bqPlayerQueue = NULL;
|
ctx->bqPlayerQueue = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Audio_Close(struct AudioContext* ctx) {
|
||||||
|
Audio_Stop(ctx);
|
||||||
|
Audio_Reset(ctx);
|
||||||
|
AudioContext_Clear(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
cc_result Audio_SetFormat(struct AudioContext* ctx, int channels, int sampleRate) {
|
cc_result Audio_SetFormat(struct AudioContext* ctx, int channels, int sampleRate) {
|
||||||
SLDataLocator_AndroidSimpleBufferQueue input;
|
SLDataLocator_AndroidSimpleBufferQueue input;
|
||||||
SLDataLocator_OutputMix output;
|
SLDataLocator_OutputMix output;
|
||||||
@ -581,7 +609,7 @@ cc_result Audio_SetFormat(struct AudioContext* ctx, int channels, int sampleRate
|
|||||||
if (ctx->channels == channels && ctx->sampleRate == sampleRate) return 0;
|
if (ctx->channels == channels && ctx->sampleRate == sampleRate) return 0;
|
||||||
ctx->channels = channels;
|
ctx->channels = channels;
|
||||||
ctx->sampleRate = sampleRate;
|
ctx->sampleRate = sampleRate;
|
||||||
AudioBackend_Reset(ctx);
|
Audio_Reset(ctx);
|
||||||
|
|
||||||
fmt.formatType = SL_DATAFORMAT_PCM;
|
fmt.formatType = SL_DATAFORMAT_PCM;
|
||||||
fmt.numChannels = channels;
|
fmt.numChannels = channels;
|
||||||
@ -626,13 +654,6 @@ cc_result Audio_Play(struct AudioContext* ctx) {
|
|||||||
return (*ctx->bqPlayerPlayer)->SetPlayState(ctx->bqPlayerPlayer, SL_PLAYSTATE_PLAYING);
|
return (*ctx->bqPlayerPlayer)->SetPlayState(ctx->bqPlayerPlayer, SL_PLAYSTATE_PLAYING);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AudioBackend_Stop(struct AudioContext* ctx) {
|
|
||||||
if (!ctx->bqPlayerPlayer) return;
|
|
||||||
|
|
||||||
(*ctx->bqPlayerQueue)->Clear(ctx->bqPlayerQueue);
|
|
||||||
(*ctx->bqPlayerPlayer)->SetPlayState(ctx->bqPlayerPlayer, SL_PLAYSTATE_STOPPED);
|
|
||||||
}
|
|
||||||
|
|
||||||
cc_result Audio_Poll(struct AudioContext* ctx, int* inUse) {
|
cc_result Audio_Poll(struct AudioContext* ctx, int* inUse) {
|
||||||
SLBufferQueueState state = { 0 };
|
SLBufferQueueState state = { 0 };
|
||||||
cc_result res = 0;
|
cc_result res = 0;
|
||||||
@ -683,11 +704,7 @@ cc_bool Audio_DescribeError(cc_result res, cc_string* dst) {
|
|||||||
#ifndef AUDIO_HAS_BACKEND
|
#ifndef AUDIO_HAS_BACKEND
|
||||||
static void AudioBackend_Free(void) { }
|
static void AudioBackend_Free(void) { }
|
||||||
#else
|
#else
|
||||||
void Audio_Close(struct AudioContext* ctx) {
|
static void AudioContext_Clear(struct AudioContext* ctx) {
|
||||||
int inUse;
|
|
||||||
AudioBackend_Stop(ctx);
|
|
||||||
Audio_Poll(ctx, &inUse); /* unqueue buffers */
|
|
||||||
|
|
||||||
ctx->count = 0;
|
ctx->count = 0;
|
||||||
ctx->channels = 0;
|
ctx->channels = 0;
|
||||||
ctx->sampleRate = 0;
|
ctx->sampleRate = 0;
|
||||||
@ -695,7 +712,6 @@ void Audio_Close(struct AudioContext* ctx) {
|
|||||||
Mem_Free(ctx->_tmpData);
|
Mem_Free(ctx->_tmpData);
|
||||||
ctx->_tmpData = NULL;
|
ctx->_tmpData = NULL;
|
||||||
ctx->_tmpSize = 0;
|
ctx->_tmpSize = 0;
|
||||||
AudioBackend_Reset(ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Audio_PlaySound(struct AudioContext* ctx, struct Sound* snd, int volume) {
|
cc_result Audio_PlaySound(struct AudioContext* ctx, struct Sound* snd, int volume) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user