|
|
@ -367,9 +367,6 @@ static void OnLog(ma_context *pContext, ma_device *pDevice, ma_uint32 logLevel, |
|
|
|
static void OnSendAudioDataToDevice(ma_device *pDevice, void *pFramesOut, const void *pFramesInput, ma_uint32 frameCount); |
|
|
|
static void MixAudioFrames(float *framesOut, const float *framesIn, ma_uint32 frameCount, float localVolume); |
|
|
|
|
|
|
|
static void InitAudioBufferPool(void); // Initialise the multichannel buffer pool |
|
|
|
static void CloseAudioBufferPool(void); // Close the audio buffers pool |
|
|
|
|
|
|
|
#if defined(SUPPORT_FILEFORMAT_WAV) |
|
|
|
static Wave LoadWAV(const unsigned char *fileData, unsigned int fileSize); // Load WAV file |
|
|
|
static int SaveWAV(Wave wave, const char *fileName); // Save wave data as WAV file |
|
|
@ -468,6 +465,14 @@ void InitAudioDevice(void) |
|
|
|
ma_context_uninit(&AUDIO.System.context); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// Init dummy audio buffers pool for multichannel sound playing |
|
|
|
for (int i = 0; i < MAX_AUDIO_BUFFER_POOL_CHANNELS; i++) |
|
|
|
{ |
|
|
|
// WARNING: An empty audioBuffer is created (data = 0) |
|
|
|
// AudioBuffer data just points to loaded sound data |
|
|
|
AUDIO.MultiChannel.pool[i] = LoadAudioBuffer(AUDIO_DEVICE_FORMAT, AUDIO_DEVICE_CHANNELS, AUDIO_DEVICE_SAMPLE_RATE, 0, AUDIO_BUFFER_USAGE_STATIC); |
|
|
|
} |
|
|
|
|
|
|
|
TRACELOG(LOG_INFO, "AUDIO: Device initialized successfully"); |
|
|
|
TRACELOG(LOG_INFO, " > Backend: miniaudio / %s", ma_get_backend_name(AUDIO.System.context.backend)); |
|
|
@ -476,8 +481,6 @@ void InitAudioDevice(void) |
|
|
|
TRACELOG(LOG_INFO, " > Sample rate: %d -> %d", AUDIO.System.device.sampleRate, AUDIO.System.device.playback.internalSampleRate); |
|
|
|
TRACELOG(LOG_INFO, " > Periods size: %d", AUDIO.System.device.playback.internalPeriodSizeInFrames*AUDIO.System.device.playback.internalPeriods); |
|
|
|
|
|
|
|
InitAudioBufferPool(); |
|
|
|
|
|
|
|
AUDIO.System.isReady = true; |
|
|
|
} |
|
|
|
|
|
|
@ -486,12 +489,24 @@ void CloseAudioDevice(void) |
|
|
|
{ |
|
|
|
if (AUDIO.System.isReady) |
|
|
|
{ |
|
|
|
// Unload dummy audio buffers pool |
|
|
|
// WARNING: They can be pointing to already unloaded data |
|
|
|
for (int i = 0; i < MAX_AUDIO_BUFFER_POOL_CHANNELS; i++) |
|
|
|
{ |
|
|
|
//UnloadAudioBuffer(AUDIO.MultiChannel.pool[i]); |
|
|
|
if (AUDIO.MultiChannel.pool[i] != NULL) |
|
|
|
{ |
|
|
|
ma_data_converter_uninit(&AUDIO.MultiChannel.pool[i]->converter); |
|
|
|
UntrackAudioBuffer(AUDIO.MultiChannel.pool[i]); |
|
|
|
//RL_FREE(buffer->data); // Already unloaded by UnloadSound() |
|
|
|
RL_FREE(AUDIO.MultiChannel.pool[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ma_mutex_uninit(&AUDIO.System.lock); |
|
|
|
ma_device_uninit(&AUDIO.System.device); |
|
|
|
ma_context_uninit(&AUDIO.System.context); |
|
|
|
|
|
|
|
CloseAudioBufferPool(); |
|
|
|
|
|
|
|
AUDIO.System.isReady = false; |
|
|
|
|
|
|
|
TRACELOG(LOG_INFO, "AUDIO: Device closed successfully"); |
|
|
@ -1909,26 +1924,6 @@ static void MixAudioFrames(float *framesOut, const float *framesIn, ma_uint32 fr |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Initialise the multichannel buffer pool |
|
|
|
static void InitAudioBufferPool(void) |
|
|
|
{ |
|
|
|
// Dummy buffers |
|
|
|
for (int i = 0; i < MAX_AUDIO_BUFFER_POOL_CHANNELS; i++) |
|
|
|
{ |
|
|
|
// WARNING: An empty audioBuffer is created (data = 0) |
|
|
|
AUDIO.MultiChannel.pool[i] = LoadAudioBuffer(AUDIO_DEVICE_FORMAT, AUDIO_DEVICE_CHANNELS, AUDIO_DEVICE_SAMPLE_RATE, 0, AUDIO_BUFFER_USAGE_STATIC); |
|
|
|
} |
|
|
|
|
|
|
|
// TODO: Verification required for log |
|
|
|
TRACELOG(LOG_INFO, "AUDIO: Multichannel pool size: %i", MAX_AUDIO_BUFFER_POOL_CHANNELS); |
|
|
|
} |
|
|
|
|
|
|
|
// Close the audio buffers pool |
|
|
|
static void CloseAudioBufferPool(void) |
|
|
|
{ |
|
|
|
for (int i = 0; i < MAX_AUDIO_BUFFER_POOL_CHANNELS; i++) UnloadAudioBuffer(AUDIO.MultiChannel.pool[i]); |
|
|
|
} |
|
|
|
|
|
|
|
#if defined(SUPPORT_FILEFORMAT_WAV) |
|
|
|
// Load WAV file data into Wave structure |
|
|
|
// NOTE: Using dr_wav library |
|
|
|