mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 09:35:23 -04:00
GC/Wii: fix music
This commit is contained in:
parent
2ecea55887
commit
b443562b7f
@ -1144,6 +1144,7 @@ struct AudioContext {
|
|||||||
int chanID, count, bufHead;
|
int chanID, count, bufHead;
|
||||||
struct AudioBuffer bufs[AUDIO_MAX_BUFFERS];
|
struct AudioBuffer bufs[AUDIO_MAX_BUFFERS];
|
||||||
int channels, sampleRate, volume;
|
int channels, sampleRate, volume;
|
||||||
|
cc_bool makeAvailable;
|
||||||
};
|
};
|
||||||
|
|
||||||
cc_bool AudioBackend_Init(void) {
|
cc_bool AudioBackend_Init(void) {
|
||||||
@ -1161,21 +1162,34 @@ void AudioBackend_Free(void) {
|
|||||||
|
|
||||||
void MusicCallback(s32 voice) {
|
void MusicCallback(s32 voice) {
|
||||||
struct AudioContext* ctx = &music_ctx;
|
struct AudioContext* ctx = &music_ctx;
|
||||||
struct AudioBuffer* buf = &ctx->bufs[ctx->bufHead];
|
|
||||||
struct AudioBuffer* nextBuf = &ctx->bufs[(ctx->bufHead + 1) % ctx->count];
|
struct AudioBuffer* nextBuf = &ctx->bufs[(ctx->bufHead + 1) % ctx->count];
|
||||||
|
|
||||||
if (ASND_AddVoice(voice, buf->samples, buf->size) == SND_OK) {
|
if (ASND_StatusVoice(voice) != SND_WORKING) return;
|
||||||
|
|
||||||
|
if (ASND_AddVoice(voice, nextBuf->samples, nextBuf->size) == SND_OK) {
|
||||||
ctx->bufHead = (ctx->bufHead + 1) % ctx->count;
|
ctx->bufHead = (ctx->bufHead + 1) % ctx->count;
|
||||||
buf->samples = NULL;
|
if (ctx->bufHead == 2) ctx->makeAvailable = true;
|
||||||
buf->available = true;
|
if (ctx->makeAvailable) {
|
||||||
|
int prev = ctx->bufHead - 2;
|
||||||
|
if (prev < 0) prev += 4;
|
||||||
|
ctx->bufs[prev].available = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int inUse;
|
||||||
|
Audio_Poll(ctx, &inUse);
|
||||||
|
if (!inUse) {
|
||||||
|
// music has finished, stop the voice so this function isn't called anymore
|
||||||
|
ASND_StopVoice(ctx->chanID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Audio_Init(struct AudioContext* ctx, int buffers) {
|
cc_result Audio_Init(struct AudioContext* ctx, int buffers) {
|
||||||
ctx->chanID = -1;
|
ctx->chanID = -1;
|
||||||
ctx->count = buffers;
|
ctx->count = buffers;
|
||||||
ctx->volume = 255;
|
ctx->volume = 255;
|
||||||
ctx->bufHead = 0;
|
ctx->bufHead = 0;
|
||||||
|
ctx->makeAvailable = false;
|
||||||
|
|
||||||
Mem_Set(ctx->bufs, 0, sizeof(ctx->bufs));
|
Mem_Set(ctx->bufs, 0, sizeof(ctx->bufs));
|
||||||
for (int i = 0; i < buffers; i++) {
|
for (int i = 0; i < buffers; i++) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user