Fix non-working common audio code oops

This commit is contained in:
UnknownShadow200 2024-03-25 20:51:16 +11:00
parent b2fdf80be1
commit 56177f94f5

View file

@ -12,7 +12,7 @@ void Audio_Warn(cc_result res, const char* action) {
/* Common/Base methods */
static void AudioBase_Clear(struct AudioContext* ctx);
static cc_bool AudioBase_AdjustSound(struct AudioContext* ctx, void* data, cc_uint32 size);
static cc_bool AudioBase_AdjustSound(struct AudioContext* ctx, void** data, cc_uint32* size);
static void AudioBase_AllocChunks(int size, void** chunks, int numChunks);
static void AudioBase_FreeChunks(void** chunks, int numChunks);
@ -434,7 +434,7 @@ cc_result Audio_QueueChunk(struct AudioContext* ctx, void* chunk, cc_uint32 data
WAVEHDR* hdr;
int i;
cc_bool ok = AudioBase_AdjustSound(ctx, chunk, dataSize);
cc_bool ok = AudioBase_AdjustSound(ctx, &chunk, &dataSize);
if (!ok) return ERR_OUT_OF_MEMORY;
for (i = 0; i < ctx->count; i++) {
@ -1404,32 +1404,31 @@ static void AudioBase_Clear(struct AudioContext* ctx) {
ctx->_tmpSize = 0;
}
static cc_bool AudioBase_AdjustSound(struct AudioContext* ctx, void* data, cc_uint32 size) {
static cc_bool AudioBase_AdjustSound(struct AudioContext* ctx, void** data, cc_uint32* size) {
void* audio;
if (ctx->volume >= 100) {
ctx->_tmpData = data;
ctx->_tmpSize = size;
return true;
}
cc_uint32 src_size = *size;
if (ctx->volume >= 100) return true;
/* copy to temp buffer to apply volume */
if (ctx->_tmpSize < data->size) {
if (ctx->_tmpSize < src_size) {
/* TODO: check if we can realloc NULL without a problem */
if (ctx->_tmpData) {
audio = Mem_TryRealloc(ctx->_tmpData, data->size, 1);
audio = Mem_TryRealloc(ctx->_tmpData, src_size, 1);
} else {
audio = Mem_TryAlloc(data->size, 1);
audio = Mem_TryAlloc(src_size, 1);
}
if (!data) return false;
ctx->_tmpData = audio;
ctx->_tmpSize = data->size;
ctx->_tmpSize = src_size;
}
audio = ctx->_tmpData;
Mem_Copy(audio, data->data, data->size);
ApplyVolume((cc_int16*)audio, data->size / 2, ctx->volume);
data->data = audio;
Mem_Copy(audio, *data, src_size);
ApplyVolume((cc_int16*)audio, src_size / 2, ctx->volume);
*data = audio;
*size = src_size;
return true;
}
#endif