mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 11:06:06 -04:00
WIP refactoring audio, part 2
This commit is contained in:
parent
d1cdb915f4
commit
c4a9dfb191
@ -99,9 +99,12 @@ void AudioPool_Close(void);
|
||||
*------------------------------------------------------Sound context------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
/* Whether the given audio data can be played without recreating the underlying audio device */
|
||||
cc_bool SoundContext_FastPlay(struct AudioContext* ctx, struct AudioData* data);
|
||||
cc_bool SoundContext_FastPlay(struct AudioContext* ctx, struct AudioData* data);
|
||||
/* Plays the given audio data */
|
||||
cc_result SoundContext_PlayData(struct AudioContext* ctx, struct AudioData* data);
|
||||
/* Polls the audio context and then potentially unqueues internal buffers */
|
||||
/* Returns whether the audio context is currently playing audio */
|
||||
cc_result SoundContext_PollBusy(struct AudioContext* ctx, cc_bool* isBusy);
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
|
@ -135,6 +135,26 @@ cc_bool SoundContext_FastPlay(struct AudioContext* ctx, struct AudioData* data)
|
||||
return true;
|
||||
}
|
||||
|
||||
cc_result SoundContext_PlayData(struct AudioContext* ctx, struct AudioData* data) {
|
||||
cc_result res;
|
||||
Audio_SetVolume(ctx, data->volume);
|
||||
|
||||
if ((res = Audio_SetFormat(ctx, data->channels, data->sampleRate, data->rate))) return res;
|
||||
if ((res = Audio_QueueChunk(ctx, &data->chunk))) return res;
|
||||
if ((res = Audio_Play(ctx))) return res;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
cc_result SoundContext_PollBusy(struct AudioContext* ctx, cc_bool* isBusy) {
|
||||
int inUse = 1;
|
||||
cc_result res;
|
||||
if ((res = Audio_Poll(ctx, &inUse))) return res;
|
||||
|
||||
*isBusy = inUse > 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*--------------------------------------------------------Audio misc-------------------------------------------------------*
|
||||
|
@ -142,6 +142,26 @@ cc_bool SoundContext_FastPlay(struct AudioContext* ctx, struct AudioData* data)
|
||||
return true;
|
||||
}
|
||||
|
||||
cc_result SoundContext_PlayData(struct AudioContext* ctx, struct AudioData* data) {
|
||||
cc_result res;
|
||||
Audio_SetVolume(ctx, data->volume);
|
||||
|
||||
if ((res = Audio_SetFormat(ctx, data->channels, data->sampleRate, data->rate))) return res;
|
||||
if ((res = Audio_QueueChunk(ctx, &data->chunk))) return res;
|
||||
if ((res = Audio_Play(ctx))) return res;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
cc_result SoundContext_PollBusy(struct AudioContext* ctx, cc_bool* isBusy) {
|
||||
int inUse = 1;
|
||||
cc_result res;
|
||||
if ((res = Audio_Poll(ctx, &inUse))) return res;
|
||||
|
||||
*isBusy = inUse > 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*--------------------------------------------------------Audio misc-------------------------------------------------------*
|
||||
|
@ -149,6 +149,26 @@ cc_bool SoundContext_FastPlay(struct AudioContext* ctx, struct AudioData* data)
|
||||
return true;
|
||||
}
|
||||
|
||||
cc_result SoundContext_PlayData(struct AudioContext* ctx, struct AudioData* data) {
|
||||
cc_result res;
|
||||
Audio_SetVolume(ctx, data->volume);
|
||||
|
||||
if ((res = Audio_SetFormat(ctx, data->channels, data->sampleRate, data->rate))) return res;
|
||||
if ((res = Audio_QueueChunk(ctx, &data->chunk))) return res;
|
||||
if ((res = Audio_Play(ctx))) return res;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
cc_result SoundContext_PollBusy(struct AudioContext* ctx, cc_bool* isBusy) {
|
||||
int inUse = 1;
|
||||
cc_result res;
|
||||
if ((res = Audio_Poll(ctx, &inUse))) return res;
|
||||
|
||||
*isBusy = inUse > 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*--------------------------------------------------------Audio misc-------------------------------------------------------*
|
||||
|
@ -5,7 +5,6 @@ struct AudioContext { int count; };
|
||||
|
||||
#define AUDIO_OVERRIDE_SOUNDS
|
||||
#define AUDIO_OVERRIDE_ALLOC
|
||||
#define AUDIO_OVERRIDE_SOUNDPLAY
|
||||
#include "_AudioBase.h"
|
||||
|
||||
cc_bool AudioBackend_Init(void) { return false; }
|
||||
@ -50,6 +49,10 @@ cc_result SoundContext_PlayData(struct AudioContext* ctx, struct AudioData* data
|
||||
return ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
cc_result SoundContext_PollBusy(struct AudioContext* ctx, cc_bool* isBusy) {
|
||||
return ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*--------------------------------------------------------Audio misc-------------------------------------------------------*
|
||||
|
@ -180,6 +180,26 @@ cc_bool SoundContext_FastPlay(struct AudioContext* ctx, struct AudioData* data)
|
||||
return false;
|
||||
}
|
||||
|
||||
cc_result SoundContext_PlayData(struct AudioContext* ctx, struct AudioData* data) {
|
||||
cc_result res;
|
||||
Audio_SetVolume(ctx, data->volume);
|
||||
|
||||
if ((res = Audio_SetFormat(ctx, data->channels, data->sampleRate, data->rate))) return res;
|
||||
if ((res = Audio_QueueChunk(ctx, &data->chunk))) return res;
|
||||
if ((res = Audio_Play(ctx))) return res;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
cc_result SoundContext_PollBusy(struct AudioContext* ctx, cc_bool* isBusy) {
|
||||
int inUse = 1;
|
||||
cc_result res;
|
||||
if ((res = Audio_Poll(ctx, &inUse))) return res;
|
||||
|
||||
*isBusy = inUse > 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*--------------------------------------------------------Audio misc-------------------------------------------------------*
|
||||
|
@ -265,6 +265,26 @@ cc_bool SoundContext_FastPlay(struct AudioContext* ctx, struct AudioData* data)
|
||||
return true;
|
||||
}
|
||||
|
||||
cc_result SoundContext_PlayData(struct AudioContext* ctx, struct AudioData* data) {
|
||||
cc_result res;
|
||||
Audio_SetVolume(ctx, data->volume);
|
||||
|
||||
if ((res = Audio_SetFormat(ctx, data->channels, data->sampleRate, data->rate))) return res;
|
||||
if ((res = Audio_QueueChunk(ctx, &data->chunk))) return res;
|
||||
if ((res = Audio_Play(ctx))) return res;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
cc_result SoundContext_PollBusy(struct AudioContext* ctx, cc_bool* isBusy) {
|
||||
int inUse = 1;
|
||||
cc_result res;
|
||||
if ((res = Audio_Poll(ctx, &inUse))) return res;
|
||||
|
||||
*isBusy = inUse > 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*--------------------------------------------------------Audio misc-------------------------------------------------------*
|
||||
|
@ -231,6 +231,26 @@ cc_bool SoundContext_FastPlay(struct AudioContext* ctx, struct AudioData* data)
|
||||
return !ctx->channels || (ctx->channels == data->channels && ctx->sampleRate == data->sampleRate);
|
||||
}
|
||||
|
||||
cc_result SoundContext_PlayData(struct AudioContext* ctx, struct AudioData* data) {
|
||||
cc_result res;
|
||||
Audio_SetVolume(ctx, data->volume);
|
||||
|
||||
if ((res = Audio_SetFormat(ctx, data->channels, data->sampleRate, data->rate))) return res;
|
||||
if ((res = Audio_QueueChunk(ctx, &data->chunk))) return res;
|
||||
if ((res = Audio_Play(ctx))) return res;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
cc_result SoundContext_PollBusy(struct AudioContext* ctx, cc_bool* isBusy) {
|
||||
int inUse = 1;
|
||||
cc_result res;
|
||||
if ((res = Audio_Poll(ctx, &inUse))) return res;
|
||||
|
||||
*isBusy = inUse > 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*--------------------------------------------------------Audio misc-------------------------------------------------------*
|
||||
|
@ -181,6 +181,26 @@ cc_bool SoundContext_FastPlay(struct AudioContext* ctx, struct AudioData* data)
|
||||
return true;
|
||||
}
|
||||
|
||||
cc_result SoundContext_PlayData(struct AudioContext* ctx, struct AudioData* data) {
|
||||
cc_result res;
|
||||
Audio_SetVolume(ctx, data->volume);
|
||||
|
||||
if ((res = Audio_SetFormat(ctx, data->channels, data->sampleRate, data->rate))) return res;
|
||||
if ((res = Audio_QueueChunk(ctx, &data->chunk))) return res;
|
||||
if ((res = Audio_Play(ctx))) return res;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
cc_result SoundContext_PollBusy(struct AudioContext* ctx, cc_bool* isBusy) {
|
||||
int inUse = 1;
|
||||
cc_result res;
|
||||
if ((res = Audio_Poll(ctx, &inUse))) return res;
|
||||
|
||||
*isBusy = inUse > 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*--------------------------------------------------------Audio misc-------------------------------------------------------*
|
||||
|
@ -367,6 +367,26 @@ cc_bool SoundContext_FastPlay(struct AudioContext* ctx, struct AudioData* data)
|
||||
return !ctx->channels || (ctx->channels == channels && ctx->sampleRate == sampleRate);
|
||||
}
|
||||
|
||||
cc_result SoundContext_PlayData(struct AudioContext* ctx, struct AudioData* data) {
|
||||
cc_result res;
|
||||
Audio_SetVolume(ctx, data->volume);
|
||||
|
||||
if ((res = Audio_SetFormat(ctx, data->channels, data->sampleRate, data->rate))) return res;
|
||||
if ((res = Audio_QueueChunk(ctx, &data->chunk))) return res;
|
||||
if ((res = Audio_Play(ctx))) return res;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
cc_result SoundContext_PollBusy(struct AudioContext* ctx, cc_bool* isBusy) {
|
||||
int inUse = 1;
|
||||
cc_result res;
|
||||
if ((res = Audio_Poll(ctx, &inUse))) return res;
|
||||
|
||||
*isBusy = inUse > 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*--------------------------------------------------------Audio misc-------------------------------------------------------*
|
||||
|
@ -67,6 +67,26 @@ cc_bool SoundContext_FastPlay(struct AudioContext* ctx, struct AudioData* data)
|
||||
return true;
|
||||
}
|
||||
|
||||
cc_result SoundContext_PlayData(struct AudioContext* ctx, struct AudioData* data) {
|
||||
cc_result res;
|
||||
Audio_SetVolume(ctx, data->volume);
|
||||
|
||||
if ((res = Audio_SetFormat(ctx, data->channels, data->sampleRate, data->rate))) return res;
|
||||
if ((res = Audio_QueueChunk(ctx, &data->chunk))) return res;
|
||||
if ((res = Audio_Play(ctx))) return res;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
cc_result SoundContext_PollBusy(struct AudioContext* ctx, cc_bool* isBusy) {
|
||||
int inUse = 1;
|
||||
cc_result res;
|
||||
if ((res = Audio_Poll(ctx, &inUse))) return res;
|
||||
|
||||
*isBusy = inUse > 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*--------------------------------------------------------Audio misc-------------------------------------------------------*
|
||||
|
@ -64,6 +64,26 @@ cc_bool SoundContext_FastPlay(struct AudioContext* ctx, struct AudioData* data)
|
||||
return true;
|
||||
}
|
||||
|
||||
cc_result SoundContext_PlayData(struct AudioContext* ctx, struct AudioData* data) {
|
||||
cc_result res;
|
||||
Audio_SetVolume(ctx, data->volume);
|
||||
|
||||
if ((res = Audio_SetFormat(ctx, data->channels, data->sampleRate, data->rate))) return res;
|
||||
if ((res = Audio_QueueChunk(ctx, &data->chunk))) return res;
|
||||
if ((res = Audio_Play(ctx))) return res;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
cc_result SoundContext_PollBusy(struct AudioContext* ctx, cc_bool* isBusy) {
|
||||
int inUse = 1;
|
||||
cc_result res;
|
||||
if ((res = Audio_Poll(ctx, &inUse))) return res;
|
||||
|
||||
*isBusy = inUse > 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*--------------------------------------------------------Audio misc-------------------------------------------------------*
|
||||
|
@ -153,6 +153,26 @@ cc_bool SoundContext_FastPlay(struct AudioContext* ctx, struct AudioData* data)
|
||||
return !ctx->channels || (ctx->channels == channels && ctx->sampleRate == sampleRate);
|
||||
}
|
||||
|
||||
cc_result SoundContext_PlayData(struct AudioContext* ctx, struct AudioData* data) {
|
||||
cc_result res;
|
||||
Audio_SetVolume(ctx, data->volume);
|
||||
|
||||
if ((res = Audio_SetFormat(ctx, data->channels, data->sampleRate, data->rate))) return res;
|
||||
if ((res = Audio_QueueChunk(ctx, &data->chunk))) return res;
|
||||
if ((res = Audio_Play(ctx))) return res;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
cc_result SoundContext_PollBusy(struct AudioContext* ctx, cc_bool* isBusy) {
|
||||
int inUse = 1;
|
||||
cc_result res;
|
||||
if ((res = Audio_Poll(ctx, &inUse))) return res;
|
||||
|
||||
*isBusy = inUse > 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*--------------------------------------------------------Audio misc-------------------------------------------------------*
|
||||
|
@ -236,7 +236,7 @@ static int VMUFile_Do(cc_file* file, int mode) {
|
||||
data = Mem_Alloc(len, 1, "VMU data");
|
||||
fs_read(fd, data, len);
|
||||
|
||||
err = vmu_pkg_parse(data, &pkg);
|
||||
err = vmu_pkg_parse(data, len, &pkg);
|
||||
fs_close(fd);
|
||||
}
|
||||
|
||||
|
@ -106,23 +106,6 @@ void AudioBackend_LoadSounds(void) { Sounds_LoadDefault(); }
|
||||
#endif
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*------------------------------------------------------Sound context------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
#ifndef AUDIO_OVERRIDE_SOUNDPLAY
|
||||
cc_result SoundContext_PlayData(struct AudioContext* ctx, struct AudioData* data) {
|
||||
cc_result res;
|
||||
Audio_SetVolume(ctx, data->volume);
|
||||
|
||||
if ((res = Audio_SetFormat(ctx, data->channels, data->sampleRate, data->rate))) return res;
|
||||
if ((res = Audio_QueueChunk(ctx, &data->chunk))) return res;
|
||||
if ((res = Audio_Play(ctx))) return res;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*---------------------------------------------------Audio context code----------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
@ -133,8 +116,9 @@ static struct AudioContext context_pool[POOL_MAX_CONTEXTS];
|
||||
#ifndef CC_BUILD_NOSOUNDS
|
||||
cc_result AudioPool_Play(struct AudioData* data) {
|
||||
struct AudioContext* ctx;
|
||||
int inUse, i;
|
||||
cc_bool isBusy;
|
||||
cc_result res;
|
||||
int i;
|
||||
|
||||
/* Try to play on a context that doesn't need to be recreated */
|
||||
for (i = 0; i < POOL_MAX_CONTEXTS; i++)
|
||||
@ -142,8 +126,8 @@ cc_result AudioPool_Play(struct AudioData* data) {
|
||||
ctx = &context_pool[i];
|
||||
if (!ctx->count && (res = Audio_Init(ctx, 1))) return res;
|
||||
|
||||
if ((res = Audio_Poll(ctx, &inUse))) return res;
|
||||
if (inUse > 0) continue;
|
||||
if ((res = SoundContext_PollBusy(ctx, &isBusy))) return res;
|
||||
if (isBusy) continue;
|
||||
|
||||
if (!SoundContext_FastPlay(ctx, data)) continue;
|
||||
return SoundContext_PlayData(ctx, data);
|
||||
@ -153,10 +137,10 @@ cc_result AudioPool_Play(struct AudioData* data) {
|
||||
for (i = 0; i < POOL_MAX_CONTEXTS; i++)
|
||||
{
|
||||
ctx = &context_pool[i];
|
||||
res = Audio_Poll(ctx, &inUse);
|
||||
res = SoundContext_PollBusy(ctx, &isBusy);
|
||||
|
||||
if (res) return res;
|
||||
if (inUse > 0) continue;
|
||||
if (isBusy) continue;
|
||||
|
||||
return SoundContext_PlayData(ctx, data);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user