mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-23 09:34:35 -05:00
Fix non-working common audio code oops
This commit is contained in:
parent
b2fdf80be1
commit
56177f94f5
1 changed files with 33 additions and 34 deletions
|
@ -12,7 +12,7 @@ void Audio_Warn(cc_result res, const char* action) {
|
||||||
|
|
||||||
/* Common/Base methods */
|
/* Common/Base methods */
|
||||||
static void AudioBase_Clear(struct AudioContext* ctx);
|
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_AllocChunks(int size, void** chunks, int numChunks);
|
||||||
static void AudioBase_FreeChunks(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;
|
WAVEHDR* hdr;
|
||||||
int i;
|
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;
|
if (!ok) return ERR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
for (i = 0; i < ctx->count; i++) {
|
for (i = 0; i < ctx->count; i++) {
|
||||||
|
@ -1404,32 +1404,31 @@ static void AudioBase_Clear(struct AudioContext* ctx) {
|
||||||
ctx->_tmpSize = 0;
|
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;
|
void* audio;
|
||||||
if (ctx->volume >= 100) {
|
cc_uint32 src_size = *size;
|
||||||
ctx->_tmpData = data;
|
if (ctx->volume >= 100) return true;
|
||||||
ctx->_tmpSize = size;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* copy to temp buffer to apply volume */
|
/* 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 */
|
/* TODO: check if we can realloc NULL without a problem */
|
||||||
if (ctx->_tmpData) {
|
if (ctx->_tmpData) {
|
||||||
audio = Mem_TryRealloc(ctx->_tmpData, data->size, 1);
|
audio = Mem_TryRealloc(ctx->_tmpData, src_size, 1);
|
||||||
} else {
|
} else {
|
||||||
audio = Mem_TryAlloc(data->size, 1);
|
audio = Mem_TryAlloc(src_size, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data) return false;
|
if (!data) return false;
|
||||||
ctx->_tmpData = audio;
|
ctx->_tmpData = audio;
|
||||||
ctx->_tmpSize = data->size;
|
ctx->_tmpSize = src_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
audio = ctx->_tmpData;
|
audio = ctx->_tmpData;
|
||||||
Mem_Copy(audio, data->data, data->size);
|
Mem_Copy(audio, *data, src_size);
|
||||||
ApplyVolume((cc_int16*)audio, data->size / 2, ctx->volume);
|
ApplyVolume((cc_int16*)audio, src_size / 2, ctx->volume);
|
||||||
data->data = audio;
|
|
||||||
|
*data = audio;
|
||||||
|
*size = src_size;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue