Update miniaudio backend
This commit is contained in:
parent
3fa4a91dc1
commit
f64f924b54
1 changed files with 34 additions and 17 deletions
|
@ -23,13 +23,8 @@ static unsigned long output_frequency;
|
|||
static void (*organya_callback)(void);
|
||||
static unsigned int organya_callback_milliseconds;
|
||||
|
||||
static void Callback(ma_device *device, void *output_stream, const void *input_stream, ma_uint32 frames_total)
|
||||
static void MixSoundsAndUpdateOrganya(long *stream, size_t frames_total)
|
||||
{
|
||||
(void)device;
|
||||
(void)input_stream;
|
||||
|
||||
short *stream = (short*)output_stream;
|
||||
|
||||
ma_mutex_lock(&organya_mutex);
|
||||
|
||||
if (organya_callback_milliseconds == 0)
|
||||
|
@ -68,18 +63,40 @@ static void Callback(ma_device *device, void *output_stream, const void *input_s
|
|||
}
|
||||
}
|
||||
|
||||
// Clamp output, and convert from 8-bit to 16-bit
|
||||
for (unsigned int i = 0; i < frames_total * 2; ++i)
|
||||
ma_mutex_unlock(&organya_mutex);
|
||||
}
|
||||
|
||||
static void Callback(ma_device *device, void *output_stream, const void *input_stream, ma_uint32 frames_total)
|
||||
{
|
||||
(void)device;
|
||||
(void)input_stream;
|
||||
|
||||
short *stream = (short*)output_stream;
|
||||
|
||||
size_t frames_done = 0;
|
||||
|
||||
while (frames_done != frames_total)
|
||||
{
|
||||
if (stream[i] > 0x7F)
|
||||
stream[i] = 0x7F00;
|
||||
else if (stream[i] < -0x7F)
|
||||
stream[i] = -0x7F00;
|
||||
long mix_buffer[0x800 * 2]; // 2 because stereo
|
||||
|
||||
size_t subframes = MIN(0x800, frames_total - frames_done);
|
||||
|
||||
memset(mix_buffer, 0, subframes * sizeof(long) * 2);
|
||||
|
||||
MixSoundsAndUpdateOrganya(mix_buffer, subframes);
|
||||
|
||||
for (size_t i = 0; i < subframes * 2; ++i)
|
||||
{
|
||||
if (mix_buffer[i] > 0x7FFF)
|
||||
*stream++ = 0x7FFF;
|
||||
else if (mix_buffer[i] < -0x7FFF)
|
||||
*stream++ = -0x7FFF;
|
||||
else
|
||||
stream[i] <<= 8;
|
||||
*stream++ = mix_buffer[i];
|
||||
}
|
||||
|
||||
ma_mutex_unlock(&organya_mutex);
|
||||
frames_done += subframes;
|
||||
}
|
||||
}
|
||||
|
||||
bool AudioBackend_Init(void)
|
||||
|
|
Loading…
Add table
Reference in a new issue