diff --git a/extras/miniaudio_split/miniaudio.c b/extras/miniaudio_split/miniaudio.c index 2a3489ea..2f472559 100644 --- a/extras/miniaudio_split/miniaudio.c +++ b/extras/miniaudio_split/miniaudio.c @@ -1,6 +1,6 @@ /* Audio playback and capture library. Choice of public domain or MIT-0. See license statements at the end of this file. -miniaudio - v0.10.30 - 2021-01-10 +miniaudio - v0.10.31 - 2020-01-17 David Reid - mackron@gmail.com @@ -815,6 +815,35 @@ MA_API int ma_strcpy_s(char* dst, size_t dstSizeInBytes, const char* src) return 34; } +MA_API int ma_wcscpy_s(wchar_t* dst, size_t dstSizeInBytes, const wchar_t* src) +{ + size_t i; + + if (dst == 0) { + return 22; + } + if (dstSizeInBytes == 0) { + return 34; + } + if (src == 0) { + dst[0] = '\0'; + return 22; + } + + for (i = 0; i < dstSizeInBytes && src[i] != '\0'; ++i) { + dst[i] = src[i]; + } + + if (i < dstSizeInBytes) { + dst[i] = '\0'; + return 0; + } + + dst[0] = '\0'; + return 34; +} + + MA_API int ma_strncpy_s(char* dst, size_t dstSizeInBytes, const char* src, size_t count) { size_t maxcount; @@ -1059,6 +1088,19 @@ MA_API char* ma_copy_string(const char* src, const ma_allocation_callbacks* pAll return dst; } +MA_API wchar_t* ma_copy_string_w(const wchar_t* src, const ma_allocation_callbacks* pAllocationCallbacks) +{ + size_t sz = wcslen(src)+1; + wchar_t* dst = (wchar_t*)ma_malloc(sz * sizeof(*dst), pAllocationCallbacks); + if (dst == NULL) { + return NULL; + } + + ma_wcscpy_s(dst, sz, src); + + return dst; +} + #include static ma_result ma_result_from_errno(int e) @@ -4319,76 +4361,6 @@ not officially supporting this, but I'm leaving it here in case it's useful for #endif #endif -/* -Check if we have the necessary development packages for each backend at the top so we can use this to determine whether or not -certain unused functions and variables can be excluded from the build to avoid warnings. -*/ -#ifdef MA_ENABLE_WASAPI - #define MA_HAS_WASAPI /* Every compiler should support WASAPI */ -#endif -#ifdef MA_ENABLE_DSOUND - #define MA_HAS_DSOUND /* Every compiler should support DirectSound. */ -#endif -#ifdef MA_ENABLE_WINMM - #define MA_HAS_WINMM /* Every compiler I'm aware of supports WinMM. */ -#endif -#ifdef MA_ENABLE_ALSA - #define MA_HAS_ALSA - #ifdef MA_NO_RUNTIME_LINKING - #ifdef __has_include - #if !__has_include() - #undef MA_HAS_ALSA - #endif - #endif - #endif -#endif -#ifdef MA_ENABLE_PULSEAUDIO - #define MA_HAS_PULSEAUDIO - #ifdef MA_NO_RUNTIME_LINKING - #ifdef __has_include - #if !__has_include() - #undef MA_HAS_PULSEAUDIO - #endif - #endif - #endif -#endif -#ifdef MA_ENABLE_JACK - #define MA_HAS_JACK - #ifdef MA_NO_RUNTIME_LINKING - #ifdef __has_include - #if !__has_include() - #undef MA_HAS_JACK - #endif - #endif - #endif -#endif -#ifdef MA_ENABLE_COREAUDIO - #define MA_HAS_COREAUDIO -#endif -#ifdef MA_ENABLE_SNDIO - #define MA_HAS_SNDIO -#endif -#ifdef MA_ENABLE_AUDIO4 - #define MA_HAS_AUDIO4 -#endif -#ifdef MA_ENABLE_OSS - #define MA_HAS_OSS -#endif -#ifdef MA_ENABLE_AAUDIO - #define MA_HAS_AAUDIO -#endif -#ifdef MA_ENABLE_OPENSL - #define MA_HAS_OPENSL -#endif -#ifdef MA_ENABLE_WEBAUDIO - #define MA_HAS_WEBAUDIO -#endif -#ifdef MA_ENABLE_CUSTOM - #define MA_HAS_CUSTOM -#endif -#ifdef MA_ENABLE_NULL - #define MA_HAS_NULL /* Everything supports the null backend. */ -#endif MA_API const char* ma_get_backend_name(ma_backend backend) { @@ -5722,7 +5694,7 @@ static ma_thread_result MA_THREADCALL ma_device_thread__null(void* pData) ma_event_wait(&pDevice->null_device.operationEvent); /* At this point an event should have been triggered. */ - operation = c89atomic_load_32(&pDevice->null_device.operation); + operation = pDevice->null_device.operation; /* Starting the device needs to put the thread into a loop. */ if (operation == MA_DEVICE_OP_START__NULL) { @@ -5730,7 +5702,7 @@ static ma_thread_result MA_THREADCALL ma_device_thread__null(void* pData) ma_timer_init(&pDevice->null_device.timer); /* Getting here means a suspend or kill operation has been requested. */ - c89atomic_exchange_32((c89atomic_uint32*)&pDevice->null_device.operationResult, MA_SUCCESS); + pDevice->null_device.operationResult = MA_SUCCESS; ma_event_signal(&pDevice->null_device.operationCompletionEvent); ma_semaphore_release(&pDevice->null_device.operationSemaphore); continue; @@ -5743,7 +5715,7 @@ static ma_thread_result MA_THREADCALL ma_device_thread__null(void* pData) ma_timer_init(&pDevice->null_device.timer); /* We're done. */ - c89atomic_exchange_32((c89atomic_uint32*)&pDevice->null_device.operationResult, MA_SUCCESS); + pDevice->null_device.operationResult = MA_SUCCESS; ma_event_signal(&pDevice->null_device.operationCompletionEvent); ma_semaphore_release(&pDevice->null_device.operationSemaphore); continue; @@ -5751,7 +5723,7 @@ static ma_thread_result MA_THREADCALL ma_device_thread__null(void* pData) /* Killing the device means we need to get out of this loop so that this thread can terminate. */ if (operation == MA_DEVICE_OP_KILL__NULL) { - c89atomic_exchange_32((c89atomic_uint32*)&pDevice->null_device.operationResult, MA_SUCCESS); + pDevice->null_device.operationResult = MA_SUCCESS; ma_event_signal(&pDevice->null_device.operationCompletionEvent); ma_semaphore_release(&pDevice->null_device.operationSemaphore); break; @@ -5760,7 +5732,7 @@ static ma_thread_result MA_THREADCALL ma_device_thread__null(void* pData) /* Getting a signal on a "none" operation probably means an error. Return invalid operation. */ if (operation == MA_DEVICE_OP_NONE__NULL) { MA_ASSERT(MA_FALSE); /* <-- Trigger this in debug mode to ensure developers are aware they're doing something wrong (or there's a bug in a miniaudio). */ - c89atomic_exchange_32((c89atomic_uint32*)&pDevice->null_device.operationResult, (c89atomic_uint32)MA_INVALID_OPERATION); + pDevice->null_device.operationResult = MA_INVALID_OPERATION; ma_event_signal(&pDevice->null_device.operationCompletionEvent); ma_semaphore_release(&pDevice->null_device.operationSemaphore); continue; /* Continue the loop. Don't terminate. */ @@ -5774,6 +5746,12 @@ static ma_result ma_device_do_operation__null(ma_device* pDevice, ma_uint32 oper { ma_result result; + /* + TODO: Need to review this and consider just using mutual exclusion. I think the original motivation + for this was to just post the event to a queue and return immediately, but that has since changed + and now this function is synchronous. I think this can be simplified to just use a mutex. + */ + /* The first thing to do is wait for an operation slot to become available. We only have a single slot for this, but we could extend this later to support queing of operations. @@ -5787,7 +5765,7 @@ static ma_result ma_device_do_operation__null(ma_device* pDevice, ma_uint32 oper When we get here it means the background thread is not referencing the operation code and it can be changed. After changing this we need to signal an event to the worker thread to let it know that it can start work. */ - c89atomic_exchange_32(&pDevice->null_device.operation, operation); + pDevice->null_device.operation = operation; /* Once the operation code has been set, the worker thread can start work. */ if (ma_event_signal(&pDevice->null_device.operationEvent) != MA_SUCCESS) { @@ -5799,7 +5777,7 @@ static ma_result ma_device_do_operation__null(ma_device* pDevice, ma_uint32 oper return MA_ERROR; } - return c89atomic_load_i32(&pDevice->null_device.operationResult); + return pDevice->null_device.operationResult; } static ma_uint64 ma_device_get_total_run_time_in_frames__null(ma_device* pDevice) @@ -5974,7 +5952,7 @@ static ma_result ma_device_start__null(ma_device* pDevice) ma_device_do_operation__null(pDevice, MA_DEVICE_OP_START__NULL); - c89atomic_exchange_32(&pDevice->null_device.isStarted, MA_TRUE); + c89atomic_exchange_8(&pDevice->null_device.isStarted, MA_TRUE); return MA_SUCCESS; } @@ -5984,7 +5962,7 @@ static ma_result ma_device_stop__null(ma_device* pDevice) ma_device_do_operation__null(pDevice, MA_DEVICE_OP_SUSPEND__NULL); - c89atomic_exchange_32(&pDevice->null_device.isStarted, MA_FALSE); + c89atomic_exchange_8(&pDevice->null_device.isStarted, MA_FALSE); return MA_SUCCESS; } @@ -5998,7 +5976,7 @@ static ma_result ma_device_write__null(ma_device* pDevice, const void* pPCMFrame *pFramesWritten = 0; } - wasStartedOnEntry = c89atomic_load_32(&pDevice->null_device.isStarted); + wasStartedOnEntry = c89atomic_load_8(&pDevice->null_device.isStarted); /* Keep going until everything has been read. */ totalPCMFramesProcessed = 0; @@ -6024,7 +6002,7 @@ static ma_result ma_device_write__null(ma_device* pDevice, const void* pPCMFrame if (pDevice->null_device.currentPeriodFramesRemainingPlayback == 0) { pDevice->null_device.currentPeriodFramesRemainingPlayback = 0; - if (!c89atomic_load_32(&pDevice->null_device.isStarted) && !wasStartedOnEntry) { + if (!c89atomic_load_8(&pDevice->null_device.isStarted) && !wasStartedOnEntry) { result = ma_device_start__null(pDevice); if (result != MA_SUCCESS) { break; @@ -6044,7 +6022,7 @@ static ma_result ma_device_write__null(ma_device* pDevice, const void* pPCMFrame ma_uint64 currentFrame; /* Stop waiting if the device has been stopped. */ - if (!c89atomic_load_32(&pDevice->null_device.isStarted)) { + if (!c89atomic_load_8(&pDevice->null_device.isStarted)) { break; } @@ -6115,7 +6093,7 @@ static ma_result ma_device_read__null(ma_device* pDevice, void* pPCMFrames, ma_u ma_uint64 currentFrame; /* Stop waiting if the device has been stopped. */ - if (!c89atomic_load_32(&pDevice->null_device.isStarted)) { + if (!c89atomic_load_8(&pDevice->null_device.isStarted)) { break; } @@ -6976,7 +6954,7 @@ typedef struct struct ma_completion_handler_uwp { ma_completion_handler_uwp_vtbl* lpVtbl; - volatile ma_uint32 counter; + MA_ATOMIC ma_uint32 counter; HANDLE hEvent; }; @@ -7187,10 +7165,10 @@ static HRESULT STDMETHODCALLTYPE ma_IMMNotificationClient_OnDefaultDeviceChanged that properly. */ if (dataFlow == ma_eRender && pThis->pDevice->type != ma_device_type_loopback) { - c89atomic_exchange_32(&pThis->pDevice->wasapi.hasDefaultPlaybackDeviceChanged, MA_TRUE); + c89atomic_exchange_8(&pThis->pDevice->wasapi.hasDefaultPlaybackDeviceChanged, MA_TRUE); } if (dataFlow == ma_eCapture || pThis->pDevice->type == ma_device_type_loopback) { - c89atomic_exchange_32(&pThis->pDevice->wasapi.hasDefaultCaptureDeviceChanged, MA_TRUE); + c89atomic_exchange_8(&pThis->pDevice->wasapi.hasDefaultCaptureDeviceChanged, MA_TRUE); } (void)pDefaultDeviceID; @@ -8375,7 +8353,7 @@ static ma_result ma_device_reinit__wasapi(ma_device* pDevice, ma_device_type dev ma_IAudioClient_GetBufferSize((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture, &pDevice->wasapi.actualPeriodSizeInFramesCapture); /* The device may be in a started state. If so we need to immediately restart it. */ - if (c89atomic_load_32(&pDevice->wasapi.isStartedCapture)) { + if (c89atomic_load_8(&pDevice->wasapi.isStartedCapture)) { HRESULT hr = ma_IAudioClient_Start((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture); if (FAILED(hr)) { return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to start internal capture device after reinitialization.", ma_result_from_HRESULT(hr)); @@ -8411,7 +8389,7 @@ static ma_result ma_device_reinit__wasapi(ma_device* pDevice, ma_device_type dev ma_IAudioClient_GetBufferSize((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, &pDevice->wasapi.actualPeriodSizeInFramesPlayback); /* The device may be in a started state. If so we need to immediately restart it. */ - if (c89atomic_load_32(&pDevice->wasapi.isStartedPlayback)) { + if (c89atomic_load_8(&pDevice->wasapi.isStartedPlayback)) { HRESULT hr = ma_IAudioClient_Start((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback); if (FAILED(hr)) { return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to start internal playback device after reinitialization.", ma_result_from_HRESULT(hr)); @@ -8628,8 +8606,8 @@ static ma_result ma_device_init__wasapi(ma_device* pDevice, const ma_device_conf } #endif - c89atomic_exchange_32(&pDevice->wasapi.isStartedCapture, MA_FALSE); - c89atomic_exchange_32(&pDevice->wasapi.isStartedPlayback, MA_FALSE); + c89atomic_exchange_8(&pDevice->wasapi.isStartedCapture, MA_FALSE); + c89atomic_exchange_8(&pDevice->wasapi.isStartedPlayback, MA_FALSE); return MA_SUCCESS; } @@ -8674,11 +8652,11 @@ static ma_bool32 ma_device_is_reroute_required__wasapi(ma_device* pDevice, ma_de MA_ASSERT(pDevice != NULL); if (deviceType == ma_device_type_playback) { - return c89atomic_load_32(&pDevice->wasapi.hasDefaultPlaybackDeviceChanged); + return c89atomic_load_8(&pDevice->wasapi.hasDefaultPlaybackDeviceChanged); } if (deviceType == ma_device_type_capture || deviceType == ma_device_type_loopback) { - return c89atomic_load_32(&pDevice->wasapi.hasDefaultCaptureDeviceChanged); + return c89atomic_load_8(&pDevice->wasapi.hasDefaultCaptureDeviceChanged); } return MA_FALSE; @@ -8693,10 +8671,10 @@ static ma_result ma_device_reroute__wasapi(ma_device* pDevice, ma_device_type de } if (deviceType == ma_device_type_playback) { - c89atomic_exchange_32(&pDevice->wasapi.hasDefaultPlaybackDeviceChanged, MA_FALSE); + c89atomic_exchange_8(&pDevice->wasapi.hasDefaultPlaybackDeviceChanged, MA_FALSE); } if (deviceType == ma_device_type_capture || deviceType == ma_device_type_loopback) { - c89atomic_exchange_32(&pDevice->wasapi.hasDefaultCaptureDeviceChanged, MA_FALSE); + c89atomic_exchange_8(&pDevice->wasapi.hasDefaultCaptureDeviceChanged, MA_FALSE); } @@ -8771,7 +8749,7 @@ static ma_result ma_device_audio_thread__wasapi(ma_device* pDevice) if (FAILED(hr)) { return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to start internal capture device.", ma_result_from_HRESULT(hr)); } - c89atomic_exchange_32(&pDevice->wasapi.isStartedCapture, MA_TRUE); + c89atomic_exchange_8(&pDevice->wasapi.isStartedCapture, MA_TRUE); } while (ma_device_get_state(pDevice) == MA_STATE_STARTED && !exitLoop) { @@ -9083,7 +9061,7 @@ static ma_result ma_device_audio_thread__wasapi(ma_device* pDevice) mappedDeviceBufferSizeInFramesPlayback = 0; } - if (!c89atomic_load_32(&pDevice->wasapi.isStartedPlayback)) { + if (!c89atomic_load_8(&pDevice->wasapi.isStartedPlayback)) { ma_uint32 startThreshold = pDevice->playback.internalPeriodSizeInFrames * 1; /* Prevent a deadlock. If we don't clamp against the actual buffer size we'll never end up starting the playback device which will result in a deadlock. */ @@ -9098,7 +9076,7 @@ static ma_result ma_device_audio_thread__wasapi(ma_device* pDevice) ma_IAudioClient_Reset((ma_IAudioClient*)pDevice->wasapi.pAudioClientCapture); return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to start internal playback device.", ma_result_from_HRESULT(hr)); } - c89atomic_exchange_32(&pDevice->wasapi.isStartedPlayback, MA_TRUE); + c89atomic_exchange_8(&pDevice->wasapi.isStartedPlayback, MA_TRUE); } } } break; @@ -9249,7 +9227,7 @@ static ma_result ma_device_audio_thread__wasapi(ma_device* pDevice) } framesWrittenToPlaybackDevice += framesAvailablePlayback; - if (!c89atomic_load_32(&pDevice->wasapi.isStartedPlayback)) { + if (!c89atomic_load_8(&pDevice->wasapi.isStartedPlayback)) { if (pDevice->playback.shareMode == ma_share_mode_exclusive || framesWrittenToPlaybackDevice >= pDevice->playback.internalPeriodSizeInFrames*1) { hr = ma_IAudioClient_Start((ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback); if (FAILED(hr)) { @@ -9257,7 +9235,7 @@ static ma_result ma_device_audio_thread__wasapi(ma_device* pDevice) exitLoop = MA_TRUE; break; } - c89atomic_exchange_32(&pDevice->wasapi.isStartedPlayback, MA_TRUE); + c89atomic_exchange_8(&pDevice->wasapi.isStartedPlayback, MA_TRUE); } } } break; @@ -9284,7 +9262,7 @@ static ma_result ma_device_audio_thread__wasapi(ma_device* pDevice) return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to reset internal capture device.", ma_result_from_HRESULT(hr)); } - c89atomic_exchange_32(&pDevice->wasapi.isStartedCapture, MA_FALSE); + c89atomic_exchange_8(&pDevice->wasapi.isStartedCapture, MA_FALSE); } if (pDevice->type == ma_device_type_playback || pDevice->type == ma_device_type_duplex) { @@ -9297,7 +9275,7 @@ static ma_result ma_device_audio_thread__wasapi(ma_device* pDevice) The buffer needs to be drained before stopping the device. Not doing this will result in the last few frames not getting output to the speakers. This is a problem for very short sounds because it'll result in a significant portion of it not getting played. */ - if (c89atomic_load_32(&pDevice->wasapi.isStartedPlayback)) { + if (c89atomic_load_8(&pDevice->wasapi.isStartedPlayback)) { /* We need to make sure we put a timeout here or else we'll risk getting stuck in a deadlock in some cases. */ DWORD waitTime = pDevice->wasapi.actualPeriodSizeInFramesPlayback / pDevice->playback.internalSampleRate; @@ -9342,7 +9320,7 @@ static ma_result ma_device_audio_thread__wasapi(ma_device* pDevice) return ma_post_error(pDevice, MA_LOG_LEVEL_ERROR, "[WASAPI] Failed to reset internal playback device.", ma_result_from_HRESULT(hr)); } - c89atomic_exchange_32(&pDevice->wasapi.isStartedPlayback, MA_FALSE); + c89atomic_exchange_8(&pDevice->wasapi.isStartedPlayback, MA_FALSE); } return MA_SUCCESS; @@ -30497,7 +30475,7 @@ MA_API ma_result ma_biquad_process_pcm_frames(ma_biquad* pBQ, void* pFramesOut, return MA_SUCCESS; } -MA_API ma_uint32 ma_biquad_get_latency(ma_biquad* pBQ) +MA_API ma_uint32 ma_biquad_get_latency(const ma_biquad* pBQ) { if (pBQ == NULL) { return 0; @@ -30673,7 +30651,7 @@ MA_API ma_result ma_lpf1_process_pcm_frames(ma_lpf1* pLPF, void* pFramesOut, con return MA_SUCCESS; } -MA_API ma_uint32 ma_lpf1_get_latency(ma_lpf1* pLPF) +MA_API ma_uint32 ma_lpf1_get_latency(const ma_lpf1* pLPF) { if (pLPF == NULL) { return 0; @@ -30774,7 +30752,7 @@ MA_API ma_result ma_lpf2_process_pcm_frames(ma_lpf2* pLPF, void* pFramesOut, con return ma_biquad_process_pcm_frames(&pLPF->bq, pFramesOut, pFramesIn, frameCount); } -MA_API ma_uint32 ma_lpf2_get_latency(ma_lpf2* pLPF) +MA_API ma_uint32 ma_lpf2_get_latency(const ma_lpf2* pLPF) { if (pLPF == NULL) { return 0; @@ -31005,7 +30983,7 @@ MA_API ma_result ma_lpf_process_pcm_frames(ma_lpf* pLPF, void* pFramesOut, const return MA_SUCCESS; } -MA_API ma_uint32 ma_lpf_get_latency(ma_lpf* pLPF) +MA_API ma_uint32 ma_lpf_get_latency(const ma_lpf* pLPF) { if (pLPF == NULL) { return 0; @@ -31180,7 +31158,7 @@ MA_API ma_result ma_hpf1_process_pcm_frames(ma_hpf1* pHPF, void* pFramesOut, con return MA_SUCCESS; } -MA_API ma_uint32 ma_hpf1_get_latency(ma_hpf1* pHPF) +MA_API ma_uint32 ma_hpf1_get_latency(const ma_hpf1* pHPF) { if (pHPF == NULL) { return 0; @@ -31281,7 +31259,7 @@ MA_API ma_result ma_hpf2_process_pcm_frames(ma_hpf2* pHPF, void* pFramesOut, con return ma_biquad_process_pcm_frames(&pHPF->bq, pFramesOut, pFramesIn, frameCount); } -MA_API ma_uint32 ma_hpf2_get_latency(ma_hpf2* pHPF) +MA_API ma_uint32 ma_hpf2_get_latency(const ma_hpf2* pHPF) { if (pHPF == NULL) { return 0; @@ -31494,7 +31472,7 @@ MA_API ma_result ma_hpf_process_pcm_frames(ma_hpf* pHPF, void* pFramesOut, const return MA_SUCCESS; } -MA_API ma_uint32 ma_hpf_get_latency(ma_hpf* pHPF) +MA_API ma_uint32 ma_hpf_get_latency(const ma_hpf* pHPF) { if (pHPF == NULL) { return 0; @@ -31620,7 +31598,7 @@ MA_API ma_result ma_bpf2_process_pcm_frames(ma_bpf2* pBPF, void* pFramesOut, con return ma_biquad_process_pcm_frames(&pBPF->bq, pFramesOut, pFramesIn, frameCount); } -MA_API ma_uint32 ma_bpf2_get_latency(ma_bpf2* pBPF) +MA_API ma_uint32 ma_bpf2_get_latency(const ma_bpf2* pBPF) { if (pBPF == NULL) { return 0; @@ -31796,7 +31774,7 @@ MA_API ma_result ma_bpf_process_pcm_frames(ma_bpf* pBPF, void* pFramesOut, const return MA_SUCCESS; } -MA_API ma_uint32 ma_bpf_get_latency(ma_bpf* pBPF) +MA_API ma_uint32 ma_bpf_get_latency(const ma_bpf* pBPF) { if (pBPF == NULL) { return 0; @@ -31921,7 +31899,7 @@ MA_API ma_result ma_notch2_process_pcm_frames(ma_notch2* pFilter, void* pFramesO return ma_biquad_process_pcm_frames(&pFilter->bq, pFramesOut, pFramesIn, frameCount); } -MA_API ma_uint32 ma_notch2_get_latency(ma_notch2* pFilter) +MA_API ma_uint32 ma_notch2_get_latency(const ma_notch2* pFilter) { if (pFilter == NULL) { return 0; @@ -32050,7 +32028,7 @@ MA_API ma_result ma_peak2_process_pcm_frames(ma_peak2* pFilter, void* pFramesOut return ma_biquad_process_pcm_frames(&pFilter->bq, pFramesOut, pFramesIn, frameCount); } -MA_API ma_uint32 ma_peak2_get_latency(ma_peak2* pFilter) +MA_API ma_uint32 ma_peak2_get_latency(const ma_peak2* pFilter) { if (pFilter == NULL) { return 0; @@ -32176,7 +32154,7 @@ MA_API ma_result ma_loshelf2_process_pcm_frames(ma_loshelf2* pFilter, void* pFra return ma_biquad_process_pcm_frames(&pFilter->bq, pFramesOut, pFramesIn, frameCount); } -MA_API ma_uint32 ma_loshelf2_get_latency(ma_loshelf2* pFilter) +MA_API ma_uint32 ma_loshelf2_get_latency(const ma_loshelf2* pFilter) { if (pFilter == NULL) { return 0; @@ -32302,7 +32280,7 @@ MA_API ma_result ma_hishelf2_process_pcm_frames(ma_hishelf2* pFilter, void* pFra return ma_biquad_process_pcm_frames(&pFilter->bq, pFramesOut, pFramesIn, frameCount); } -MA_API ma_uint32 ma_hishelf2_get_latency(ma_hishelf2* pFilter) +MA_API ma_uint32 ma_hishelf2_get_latency(const ma_hishelf2* pFilter) { if (pFilter == NULL) { return 0; @@ -32860,7 +32838,7 @@ MA_API ma_result ma_linear_resampler_set_rate_ratio(ma_linear_resampler* pResamp } -MA_API ma_uint64 ma_linear_resampler_get_required_input_frame_count(ma_linear_resampler* pResampler, ma_uint64 outputFrameCount) +MA_API ma_uint64 ma_linear_resampler_get_required_input_frame_count(const ma_linear_resampler* pResampler, ma_uint64 outputFrameCount) { ma_uint64 inputFrameCount; @@ -32883,7 +32861,7 @@ MA_API ma_uint64 ma_linear_resampler_get_required_input_frame_count(ma_linear_re return inputFrameCount; } -MA_API ma_uint64 ma_linear_resampler_get_expected_output_frame_count(ma_linear_resampler* pResampler, ma_uint64 inputFrameCount) +MA_API ma_uint64 ma_linear_resampler_get_expected_output_frame_count(const ma_linear_resampler* pResampler, ma_uint64 inputFrameCount) { ma_uint64 outputFrameCount; ma_uint64 preliminaryInputFrameCountFromFrac; @@ -32920,7 +32898,7 @@ MA_API ma_uint64 ma_linear_resampler_get_expected_output_frame_count(ma_linear_r return outputFrameCount; } -MA_API ma_uint64 ma_linear_resampler_get_input_latency(ma_linear_resampler* pResampler) +MA_API ma_uint64 ma_linear_resampler_get_input_latency(const ma_linear_resampler* pResampler) { if (pResampler == NULL) { return 0; @@ -32929,7 +32907,7 @@ MA_API ma_uint64 ma_linear_resampler_get_input_latency(ma_linear_resampler* pRes return 1 + ma_lpf_get_latency(&pResampler->lpf); } -MA_API ma_uint64 ma_linear_resampler_get_output_latency(ma_linear_resampler* pResampler) +MA_API ma_uint64 ma_linear_resampler_get_output_latency(const ma_linear_resampler* pResampler) { if (pResampler == NULL) { return 0; @@ -33359,7 +33337,7 @@ MA_API ma_result ma_resampler_set_rate_ratio(ma_resampler* pResampler, float rat } } -MA_API ma_uint64 ma_resampler_get_required_input_frame_count(ma_resampler* pResampler, ma_uint64 outputFrameCount) +MA_API ma_uint64 ma_resampler_get_required_input_frame_count(const ma_resampler* pResampler, ma_uint64 outputFrameCount) { if (pResampler == NULL) { return 0; @@ -33399,7 +33377,7 @@ MA_API ma_uint64 ma_resampler_get_required_input_frame_count(ma_resampler* pResa return 0; } -MA_API ma_uint64 ma_resampler_get_expected_output_frame_count(ma_resampler* pResampler, ma_uint64 inputFrameCount) +MA_API ma_uint64 ma_resampler_get_expected_output_frame_count(const ma_resampler* pResampler, ma_uint64 inputFrameCount) { if (pResampler == NULL) { return 0; /* Invalid args. */ @@ -33439,7 +33417,7 @@ MA_API ma_uint64 ma_resampler_get_expected_output_frame_count(ma_resampler* pRes return 0; } -MA_API ma_uint64 ma_resampler_get_input_latency(ma_resampler* pResampler) +MA_API ma_uint64 ma_resampler_get_input_latency(const ma_resampler* pResampler) { if (pResampler == NULL) { return 0; @@ -33469,7 +33447,7 @@ MA_API ma_uint64 ma_resampler_get_input_latency(ma_resampler* pResampler) return 0; } -MA_API ma_uint64 ma_resampler_get_output_latency(ma_resampler* pResampler) +MA_API ma_uint64 ma_resampler_get_output_latency(const ma_resampler* pResampler) { if (pResampler == NULL) { return 0; @@ -35253,7 +35231,7 @@ MA_API ma_result ma_data_converter_set_rate_ratio(ma_data_converter* pConverter, return ma_resampler_set_rate_ratio(&pConverter->resampler, ratioInOut); } -MA_API ma_uint64 ma_data_converter_get_required_input_frame_count(ma_data_converter* pConverter, ma_uint64 outputFrameCount) +MA_API ma_uint64 ma_data_converter_get_required_input_frame_count(const ma_data_converter* pConverter, ma_uint64 outputFrameCount) { if (pConverter == NULL) { return 0; @@ -35266,7 +35244,7 @@ MA_API ma_uint64 ma_data_converter_get_required_input_frame_count(ma_data_conver } } -MA_API ma_uint64 ma_data_converter_get_expected_output_frame_count(ma_data_converter* pConverter, ma_uint64 inputFrameCount) +MA_API ma_uint64 ma_data_converter_get_expected_output_frame_count(const ma_data_converter* pConverter, ma_uint64 inputFrameCount) { if (pConverter == NULL) { return 0; @@ -35279,7 +35257,7 @@ MA_API ma_uint64 ma_data_converter_get_expected_output_frame_count(ma_data_conve } } -MA_API ma_uint64 ma_data_converter_get_input_latency(ma_data_converter* pConverter) +MA_API ma_uint64 ma_data_converter_get_input_latency(const ma_data_converter* pConverter) { if (pConverter == NULL) { return 0; @@ -35292,7 +35270,7 @@ MA_API ma_uint64 ma_data_converter_get_input_latency(ma_data_converter* pConvert return 0; /* No latency without a resampler. */ } -MA_API ma_uint64 ma_data_converter_get_output_latency(ma_data_converter* pConverter) +MA_API ma_uint64 ma_data_converter_get_output_latency(const ma_data_converter* pConverter) { if (pConverter == NULL) { return 0; @@ -36949,6 +36927,12 @@ MA_API ma_uint32 ma_get_bytes_per_sample(ma_format format) MA_API ma_result ma_data_source_read_pcm_frames(ma_data_source* pDataSource, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead, ma_bool32 loop) { ma_data_source_callbacks* pCallbacks = (ma_data_source_callbacks*)pDataSource; + + /* Safety. */ + if (pFramesRead != NULL) { + *pFramesRead = 0; + } + if (pCallbacks == NULL) { return MA_INVALID_ARGS; } @@ -37132,6 +37116,245 @@ MA_API ma_result ma_data_source_get_length_in_pcm_frames(ma_data_source* pDataSo + +static ma_result ma_audio_buffer_ref__data_source_on_read(ma_data_source* pDataSource, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead) +{ + ma_uint64 framesRead = ma_audio_buffer_ref_read_pcm_frames((ma_audio_buffer_ref*)pDataSource, pFramesOut, frameCount, MA_FALSE); + + if (pFramesRead != NULL) { + *pFramesRead = framesRead; + } + + if (framesRead < frameCount) { + return MA_AT_END; + } + + return MA_SUCCESS; +} + +static ma_result ma_audio_buffer_ref__data_source_on_seek(ma_data_source* pDataSource, ma_uint64 frameIndex) +{ + return ma_audio_buffer_ref_seek_to_pcm_frame((ma_audio_buffer_ref*)pDataSource, frameIndex); +} + +static ma_result ma_audio_buffer_ref__data_source_on_map(ma_data_source* pDataSource, void** ppFramesOut, ma_uint64* pFrameCount) +{ + return ma_audio_buffer_ref_map((ma_audio_buffer_ref*)pDataSource, ppFramesOut, pFrameCount); +} + +static ma_result ma_audio_buffer_ref__data_source_on_unmap(ma_data_source* pDataSource, ma_uint64 frameCount) +{ + return ma_audio_buffer_ref_unmap((ma_audio_buffer_ref*)pDataSource, frameCount); +} + +static ma_result ma_audio_buffer_ref__data_source_on_get_data_format(ma_data_source* pDataSource, ma_format* pFormat, ma_uint32* pChannels, ma_uint32* pSampleRate) +{ + ma_audio_buffer_ref* pAudioBufferRef = (ma_audio_buffer_ref*)pDataSource; + + *pFormat = pAudioBufferRef->format; + *pChannels = pAudioBufferRef->channels; + *pSampleRate = 0; /* There is no notion of a sample rate with audio buffers. */ + + return MA_SUCCESS; +} + +static ma_result ma_audio_buffer_ref__data_source_on_get_cursor(ma_data_source* pDataSource, ma_uint64* pCursor) +{ + ma_audio_buffer_ref* pAudioBufferRef = (ma_audio_buffer_ref*)pDataSource; + + *pCursor = pAudioBufferRef->cursor; + + return MA_SUCCESS; +} + +static ma_result ma_audio_buffer_ref__data_source_on_get_length(ma_data_source* pDataSource, ma_uint64* pLength) +{ + ma_audio_buffer_ref* pAudioBufferRef = (ma_audio_buffer_ref*)pDataSource; + + *pLength = pAudioBufferRef->sizeInFrames; + + return MA_SUCCESS; +} + +MA_API ma_result ma_audio_buffer_ref_init(ma_format format, ma_uint32 channels, const void* pData, ma_uint64 sizeInFrames, ma_audio_buffer_ref* pAudioBufferRef) +{ + if (pAudioBufferRef == NULL) { + return MA_INVALID_ARGS; + } + + MA_ZERO_OBJECT(pAudioBufferRef); + + pAudioBufferRef->ds.onRead = ma_audio_buffer_ref__data_source_on_read; + pAudioBufferRef->ds.onSeek = ma_audio_buffer_ref__data_source_on_seek; + pAudioBufferRef->ds.onMap = ma_audio_buffer_ref__data_source_on_map; + pAudioBufferRef->ds.onUnmap = ma_audio_buffer_ref__data_source_on_unmap; + pAudioBufferRef->ds.onGetDataFormat = ma_audio_buffer_ref__data_source_on_get_data_format; + pAudioBufferRef->ds.onGetCursor = ma_audio_buffer_ref__data_source_on_get_cursor; + pAudioBufferRef->ds.onGetLength = ma_audio_buffer_ref__data_source_on_get_length; + pAudioBufferRef->format = format; + pAudioBufferRef->channels = channels; + pAudioBufferRef->cursor = 0; + pAudioBufferRef->sizeInFrames = sizeInFrames; + pAudioBufferRef->pData = pData; + + return MA_SUCCESS; +} + +MA_API ma_result ma_audio_buffer_ref_set_data(ma_audio_buffer_ref* pAudioBufferRef, const void* pData, ma_uint64 sizeInFrames) +{ + if (pAudioBufferRef == NULL) { + return MA_INVALID_ARGS; + } + + pAudioBufferRef->cursor = 0; + pAudioBufferRef->sizeInFrames = sizeInFrames; + pAudioBufferRef->pData = pData; + + return MA_SUCCESS; +} + +MA_API ma_uint64 ma_audio_buffer_ref_read_pcm_frames(ma_audio_buffer_ref* pAudioBufferRef, void* pFramesOut, ma_uint64 frameCount, ma_bool32 loop) +{ + ma_uint64 totalFramesRead = 0; + + if (pAudioBufferRef == NULL) { + return 0; + } + + if (frameCount == 0) { + return 0; + } + + while (totalFramesRead < frameCount) { + ma_uint64 framesAvailable = pAudioBufferRef->sizeInFrames - pAudioBufferRef->cursor; + ma_uint64 framesRemaining = frameCount - totalFramesRead; + ma_uint64 framesToRead; + + framesToRead = framesRemaining; + if (framesToRead > framesAvailable) { + framesToRead = framesAvailable; + } + + if (pFramesOut != NULL) { + ma_copy_pcm_frames(pFramesOut, ma_offset_ptr(pAudioBufferRef->pData, pAudioBufferRef->cursor * ma_get_bytes_per_frame(pAudioBufferRef->format, pAudioBufferRef->channels)), framesToRead, pAudioBufferRef->format, pAudioBufferRef->channels); + } + + totalFramesRead += framesToRead; + + pAudioBufferRef->cursor += framesToRead; + if (pAudioBufferRef->cursor == pAudioBufferRef->sizeInFrames) { + if (loop) { + pAudioBufferRef->cursor = 0; + } else { + break; /* We've reached the end and we're not looping. Done. */ + } + } + + MA_ASSERT(pAudioBufferRef->cursor < pAudioBufferRef->sizeInFrames); + } + + return totalFramesRead; +} + +MA_API ma_result ma_audio_buffer_ref_seek_to_pcm_frame(ma_audio_buffer_ref* pAudioBufferRef, ma_uint64 frameIndex) +{ + if (pAudioBufferRef == NULL) { + return MA_INVALID_ARGS; + } + + if (frameIndex > pAudioBufferRef->sizeInFrames) { + return MA_INVALID_ARGS; + } + + pAudioBufferRef->cursor = (size_t)frameIndex; + + return MA_SUCCESS; +} + +MA_API ma_result ma_audio_buffer_ref_map(ma_audio_buffer_ref* pAudioBufferRef, void** ppFramesOut, ma_uint64* pFrameCount) +{ + ma_uint64 framesAvailable; + ma_uint64 frameCount = 0; + + if (ppFramesOut != NULL) { + *ppFramesOut = NULL; /* Safety. */ + } + + if (pFrameCount != NULL) { + frameCount = *pFrameCount; + *pFrameCount = 0; /* Safety. */ + } + + if (pAudioBufferRef == NULL || ppFramesOut == NULL || pFrameCount == NULL) { + return MA_INVALID_ARGS; + } + + framesAvailable = pAudioBufferRef->sizeInFrames - pAudioBufferRef->cursor; + if (frameCount > framesAvailable) { + frameCount = framesAvailable; + } + + *ppFramesOut = ma_offset_ptr(pAudioBufferRef->pData, pAudioBufferRef->cursor * ma_get_bytes_per_frame(pAudioBufferRef->format, pAudioBufferRef->channels)); + *pFrameCount = frameCount; + + return MA_SUCCESS; +} + +MA_API ma_result ma_audio_buffer_ref_unmap(ma_audio_buffer_ref* pAudioBufferRef, ma_uint64 frameCount) +{ + ma_uint64 framesAvailable; + + if (pAudioBufferRef == NULL) { + return MA_INVALID_ARGS; + } + + framesAvailable = pAudioBufferRef->sizeInFrames - pAudioBufferRef->cursor; + if (frameCount > framesAvailable) { + return MA_INVALID_ARGS; /* The frame count was too big. This should never happen in an unmapping. Need to make sure the caller is aware of this. */ + } + + pAudioBufferRef->cursor += frameCount; + + if (pAudioBufferRef->cursor == pAudioBufferRef->sizeInFrames) { + return MA_AT_END; /* Successful. Need to tell the caller that the end has been reached so that it can loop if desired. */ + } else { + return MA_SUCCESS; + } +} + +MA_API ma_result ma_audio_buffer_ref_at_end(ma_audio_buffer_ref* pAudioBufferRef) +{ + if (pAudioBufferRef == NULL) { + return MA_FALSE; + } + + return pAudioBufferRef->cursor == pAudioBufferRef->sizeInFrames; +} + +MA_API ma_result ma_audio_buffer_ref_get_available_frames(ma_audio_buffer_ref* pAudioBufferRef, ma_uint64* pAvailableFrames) +{ + if (pAvailableFrames == NULL) { + return MA_INVALID_ARGS; + } + + *pAvailableFrames = 0; + + if (pAudioBufferRef == NULL) { + return MA_INVALID_ARGS; + } + + if (pAudioBufferRef->sizeInFrames <= pAudioBufferRef->cursor) { + *pAvailableFrames = 0; + } else { + *pAvailableFrames = pAudioBufferRef->sizeInFrames - pAudioBufferRef->cursor; + } + + return MA_SUCCESS; +} + + + + MA_API ma_audio_buffer_config ma_audio_buffer_config_init(ma_format format, ma_uint32 channels, ma_uint64 sizeInFrames, const void* pData, const ma_allocation_callbacks* pAllocationCallbacks) { ma_audio_buffer_config config; @@ -37146,68 +37369,10 @@ MA_API ma_audio_buffer_config ma_audio_buffer_config_init(ma_format format, ma_u return config; } - -static ma_result ma_audio_buffer__data_source_on_read(ma_data_source* pDataSource, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead) -{ - ma_uint64 framesRead = ma_audio_buffer_read_pcm_frames((ma_audio_buffer*)pDataSource, pFramesOut, frameCount, MA_FALSE); - - if (pFramesRead != NULL) { - *pFramesRead = framesRead; - } - - if (framesRead < frameCount) { - return MA_AT_END; - } - - return MA_SUCCESS; -} - -static ma_result ma_audio_buffer__data_source_on_seek(ma_data_source* pDataSource, ma_uint64 frameIndex) -{ - return ma_audio_buffer_seek_to_pcm_frame((ma_audio_buffer*)pDataSource, frameIndex); -} - -static ma_result ma_audio_buffer__data_source_on_map(ma_data_source* pDataSource, void** ppFramesOut, ma_uint64* pFrameCount) -{ - return ma_audio_buffer_map((ma_audio_buffer*)pDataSource, ppFramesOut, pFrameCount); -} - -static ma_result ma_audio_buffer__data_source_on_unmap(ma_data_source* pDataSource, ma_uint64 frameCount) -{ - return ma_audio_buffer_unmap((ma_audio_buffer*)pDataSource, frameCount); -} - -static ma_result ma_audio_buffer__data_source_on_get_data_format(ma_data_source* pDataSource, ma_format* pFormat, ma_uint32* pChannels, ma_uint32* pSampleRate) -{ - ma_audio_buffer* pAudioBuffer = (ma_audio_buffer*)pDataSource; - - *pFormat = pAudioBuffer->format; - *pChannels = pAudioBuffer->channels; - *pSampleRate = 0; /* There is no notion of a sample rate with audio buffers. */ - - return MA_SUCCESS; -} - -static ma_result ma_audio_buffer__data_source_on_get_cursor(ma_data_source* pDataSource, ma_uint64* pCursor) -{ - ma_audio_buffer* pAudioBuffer = (ma_audio_buffer*)pDataSource; - - *pCursor = pAudioBuffer->cursor; - - return MA_SUCCESS; -} - -static ma_result ma_audio_buffer__data_source_on_get_length(ma_data_source* pDataSource, ma_uint64* pLength) -{ - ma_audio_buffer* pAudioBuffer = (ma_audio_buffer*)pDataSource; - - *pLength = pAudioBuffer->sizeInFrames; - - return MA_SUCCESS; -} - static ma_result ma_audio_buffer_init_ex(const ma_audio_buffer_config* pConfig, ma_bool32 doCopy, ma_audio_buffer* pAudioBuffer) { + ma_result result; + if (pAudioBuffer == NULL) { return MA_INVALID_ARGS; } @@ -37222,25 +37387,18 @@ static ma_result ma_audio_buffer_init_ex(const ma_audio_buffer_config* pConfig, return MA_INVALID_ARGS; /* Not allowing buffer sizes of 0 frames. */ } - pAudioBuffer->ds.onRead = ma_audio_buffer__data_source_on_read; - pAudioBuffer->ds.onSeek = ma_audio_buffer__data_source_on_seek; - pAudioBuffer->ds.onMap = ma_audio_buffer__data_source_on_map; - pAudioBuffer->ds.onUnmap = ma_audio_buffer__data_source_on_unmap; - pAudioBuffer->ds.onGetDataFormat = ma_audio_buffer__data_source_on_get_data_format; - pAudioBuffer->ds.onGetCursor = ma_audio_buffer__data_source_on_get_cursor; - pAudioBuffer->ds.onGetLength = ma_audio_buffer__data_source_on_get_length; - pAudioBuffer->format = pConfig->format; - pAudioBuffer->channels = pConfig->channels; - pAudioBuffer->cursor = 0; - pAudioBuffer->sizeInFrames = pConfig->sizeInFrames; - pAudioBuffer->pData = NULL; /* Set properly later. */ + result = ma_audio_buffer_ref_init(pConfig->format, pConfig->channels, NULL, 0, &pAudioBuffer->ref); + if (result != MA_SUCCESS) { + return result; + } + ma_allocation_callbacks_init_copy(&pAudioBuffer->allocationCallbacks, &pConfig->allocationCallbacks); if (doCopy) { ma_uint64 allocationSizeInBytes; void* pData; - allocationSizeInBytes = pAudioBuffer->sizeInFrames * ma_get_bytes_per_frame(pAudioBuffer->format, pAudioBuffer->channels); + allocationSizeInBytes = pConfig->sizeInFrames * ma_get_bytes_per_frame(pConfig->format, pConfig->channels); if (allocationSizeInBytes > MA_SIZE_MAX) { return MA_OUT_OF_MEMORY; /* Too big. */ } @@ -37251,15 +37409,15 @@ static ma_result ma_audio_buffer_init_ex(const ma_audio_buffer_config* pConfig, } if (pConfig->pData != NULL) { - ma_copy_pcm_frames(pData, pConfig->pData, pAudioBuffer->sizeInFrames, pAudioBuffer->format, pAudioBuffer->channels); + ma_copy_pcm_frames(pData, pConfig->pData, pConfig->sizeInFrames, pConfig->format, pConfig->channels); } else { - ma_silence_pcm_frames(pData, pAudioBuffer->sizeInFrames, pAudioBuffer->format, pAudioBuffer->channels); + ma_silence_pcm_frames(pData, pConfig->sizeInFrames, pConfig->format, pConfig->channels); } - pAudioBuffer->pData = pData; + ma_audio_buffer_ref_set_data(&pAudioBuffer->ref, pData, pConfig->sizeInFrames); pAudioBuffer->ownsData = MA_TRUE; } else { - pAudioBuffer->pData = pConfig->pData; + ma_audio_buffer_ref_set_data(&pAudioBuffer->ref, pConfig->pData, pConfig->sizeInFrames); pAudioBuffer->ownsData = MA_FALSE; } @@ -37272,13 +37430,12 @@ static void ma_audio_buffer_uninit_ex(ma_audio_buffer* pAudioBuffer, ma_bool32 d return; } - if (pAudioBuffer->ownsData && pAudioBuffer->pData != &pAudioBuffer->_pExtraData[0]) { - ma__free_from_callbacks((void*)pAudioBuffer->pData, &pAudioBuffer->allocationCallbacks); /* Naugty const cast, but OK in this case since we've guarded it with the ownsData check. */ + if (pAudioBuffer->ownsData && pAudioBuffer->ref.pData != &pAudioBuffer->_pExtraData[0]) { + ma__free_from_callbacks((void*)pAudioBuffer->ref.pData, &pAudioBuffer->allocationCallbacks); /* Naugty const cast, but OK in this case since we've guarded it with the ownsData check. */ } if (doFree) { - ma_allocation_callbacks allocationCallbacks = pAudioBuffer->allocationCallbacks; - ma__free_from_callbacks(pAudioBuffer, &allocationCallbacks); + ma__free_from_callbacks(pAudioBuffer, &pAudioBuffer->allocationCallbacks); } } @@ -37353,45 +37510,11 @@ MA_API void ma_audio_buffer_uninit_and_free(ma_audio_buffer* pAudioBuffer) MA_API ma_uint64 ma_audio_buffer_read_pcm_frames(ma_audio_buffer* pAudioBuffer, void* pFramesOut, ma_uint64 frameCount, ma_bool32 loop) { - ma_uint64 totalFramesRead = 0; - if (pAudioBuffer == NULL) { return 0; } - if (frameCount == 0) { - return 0; - } - - while (totalFramesRead < frameCount) { - ma_uint64 framesAvailable = pAudioBuffer->sizeInFrames - pAudioBuffer->cursor; - ma_uint64 framesRemaining = frameCount - totalFramesRead; - ma_uint64 framesToRead; - - framesToRead = framesRemaining; - if (framesToRead > framesAvailable) { - framesToRead = framesAvailable; - } - - if (pFramesOut != NULL) { - ma_copy_pcm_frames(pFramesOut, ma_offset_ptr(pAudioBuffer->pData, pAudioBuffer->cursor * ma_get_bytes_per_frame(pAudioBuffer->format, pAudioBuffer->channels)), framesToRead, pAudioBuffer->format, pAudioBuffer->channels); - } - - totalFramesRead += framesToRead; - - pAudioBuffer->cursor += framesToRead; - if (pAudioBuffer->cursor == pAudioBuffer->sizeInFrames) { - if (loop) { - pAudioBuffer->cursor = 0; - } else { - break; /* We've reached the end and we're not looping. Done. */ - } - } - - MA_ASSERT(pAudioBuffer->cursor < pAudioBuffer->sizeInFrames); - } - - return totalFramesRead; + return ma_audio_buffer_ref_read_pcm_frames(&pAudioBuffer->ref, pFramesOut, frameCount, loop); } MA_API ma_result ma_audio_buffer_seek_to_pcm_frame(ma_audio_buffer* pAudioBuffer, ma_uint64 frameIndex) @@ -37400,64 +37523,33 @@ MA_API ma_result ma_audio_buffer_seek_to_pcm_frame(ma_audio_buffer* pAudioBuffer return MA_INVALID_ARGS; } - if (frameIndex > pAudioBuffer->sizeInFrames) { - return MA_INVALID_ARGS; - } - - pAudioBuffer->cursor = (size_t)frameIndex; - - return MA_SUCCESS; + return ma_audio_buffer_ref_seek_to_pcm_frame(&pAudioBuffer->ref, frameIndex); } MA_API ma_result ma_audio_buffer_map(ma_audio_buffer* pAudioBuffer, void** ppFramesOut, ma_uint64* pFrameCount) { - ma_uint64 framesAvailable; - ma_uint64 frameCount = 0; - if (ppFramesOut != NULL) { *ppFramesOut = NULL; /* Safety. */ } - if (pFrameCount != NULL) { - frameCount = *pFrameCount; - *pFrameCount = 0; /* Safety. */ - } + if (pAudioBuffer == NULL) { + if (pFrameCount != NULL) { + *pFrameCount = 0; + } - if (pAudioBuffer == NULL || ppFramesOut == NULL || pFrameCount == NULL) { return MA_INVALID_ARGS; } - framesAvailable = pAudioBuffer->sizeInFrames - pAudioBuffer->cursor; - if (frameCount > framesAvailable) { - frameCount = framesAvailable; - } - - *ppFramesOut = ma_offset_ptr(pAudioBuffer->pData, pAudioBuffer->cursor * ma_get_bytes_per_frame(pAudioBuffer->format, pAudioBuffer->channels)); - *pFrameCount = frameCount; - - return MA_SUCCESS; + return ma_audio_buffer_ref_map(&pAudioBuffer->ref, ppFramesOut, pFrameCount); } MA_API ma_result ma_audio_buffer_unmap(ma_audio_buffer* pAudioBuffer, ma_uint64 frameCount) { - ma_uint64 framesAvailable; - if (pAudioBuffer == NULL) { return MA_INVALID_ARGS; } - framesAvailable = pAudioBuffer->sizeInFrames - pAudioBuffer->cursor; - if (frameCount > framesAvailable) { - return MA_INVALID_ARGS; /* The frame count was too big. This should never happen in an unmapping. Need to make sure the caller is aware of this. */ - } - - pAudioBuffer->cursor += frameCount; - - if (pAudioBuffer->cursor == pAudioBuffer->sizeInFrames) { - return MA_AT_END; /* Successful. Need to tell the caller that the end has been reached so that it can loop if desired. */ - } else { - return MA_SUCCESS; - } + return ma_audio_buffer_ref_unmap(&pAudioBuffer->ref, frameCount); } MA_API ma_result ma_audio_buffer_at_end(ma_audio_buffer* pAudioBuffer) @@ -37466,7 +37558,7 @@ MA_API ma_result ma_audio_buffer_at_end(ma_audio_buffer* pAudioBuffer) return MA_FALSE; } - return pAudioBuffer->cursor == pAudioBuffer->sizeInFrames; + return ma_audio_buffer_ref_at_end(&pAudioBuffer->ref); } MA_API ma_result ma_audio_buffer_get_available_frames(ma_audio_buffer* pAudioBuffer, ma_uint64* pAvailableFrames) @@ -37481,13 +37573,7 @@ MA_API ma_result ma_audio_buffer_get_available_frames(ma_audio_buffer* pAudioBuf return MA_INVALID_ARGS; } - if (pAudioBuffer->sizeInFrames <= pAudioBuffer->cursor) { - *pAvailableFrames = 0; - } else { - *pAvailableFrames = pAudioBuffer->sizeInFrames - pAudioBuffer->cursor; - } - - return MA_SUCCESS; + return ma_audio_buffer_ref_get_available_frames(&pAudioBuffer->ref, pAvailableFrames); } @@ -37650,7 +37736,7 @@ MA_API ma_result ma_vfs_info(ma_vfs* pVFS, ma_vfs_file file, ma_file_info* pInfo } -static ma_result ma_vfs_open_and_read_file_ex(ma_vfs* pVFS, const char* pFilePath, void** ppData, size_t* pSize, const ma_allocation_callbacks* pAllocationCallbacks, ma_uint32 allocationType) +static ma_result ma_vfs_open_and_read_file_ex(ma_vfs* pVFS, const char* pFilePath, const wchar_t* pFilePathW, void** ppData, size_t* pSize, const ma_allocation_callbacks* pAllocationCallbacks, ma_uint32 allocationType) { ma_result result; ma_vfs_file file; @@ -37671,7 +37757,11 @@ static ma_result ma_vfs_open_and_read_file_ex(ma_vfs* pVFS, const char* pFilePat return MA_INVALID_ARGS; } - result = ma_vfs_open(pVFS, pFilePath, MA_OPEN_MODE_READ, &file); + if (pFilePath != NULL) { + result = ma_vfs_open(pVFS, pFilePath, MA_OPEN_MODE_READ, &file); + } else { + result = ma_vfs_open_w(pVFS, pFilePathW, MA_OPEN_MODE_READ, &file); + } if (result != MA_SUCCESS) { return result; } @@ -37711,9 +37801,14 @@ static ma_result ma_vfs_open_and_read_file_ex(ma_vfs* pVFS, const char* pFilePat return MA_SUCCESS; } -ma_result ma_vfs_open_and_read_file(ma_vfs* pVFS, const char* pFilePath, void** ppData, size_t* pSize, const ma_allocation_callbacks* pAllocationCallbacks) +MA_API ma_result ma_vfs_open_and_read_file(ma_vfs* pVFS, const char* pFilePath, void** ppData, size_t* pSize, const ma_allocation_callbacks* pAllocationCallbacks) { - return ma_vfs_open_and_read_file_ex(pVFS, pFilePath, ppData, pSize, pAllocationCallbacks, 0 /*MA_ALLOCATION_TYPE_GENERAL*/); + return ma_vfs_open_and_read_file_ex(pVFS, pFilePath, NULL, ppData, pSize, pAllocationCallbacks, 0 /*MA_ALLOCATION_TYPE_GENERAL*/); +} + +MA_API ma_result ma_vfs_open_and_read_file_w(ma_vfs* pVFS, const wchar_t* pFilePath, void** ppData, size_t* pSize, const ma_allocation_callbacks* pAllocationCallbacks) +{ + return ma_vfs_open_and_read_file_ex(pVFS, NULL, pFilePath, ppData, pSize, pAllocationCallbacks, 0 /*MA_ALLOCATION_TYPE_GENERAL*/); } @@ -38411,7 +38506,7 @@ extern "C" { #define DRWAV_XSTRINGIFY(x) DRWAV_STRINGIFY(x) #define DRWAV_VERSION_MAJOR 0 #define DRWAV_VERSION_MINOR 12 -#define DRWAV_VERSION_REVISION 16 +#define DRWAV_VERSION_REVISION 17 #define DRWAV_VERSION_STRING DRWAV_XSTRINGIFY(DRWAV_VERSION_MAJOR) "." DRWAV_XSTRINGIFY(DRWAV_VERSION_MINOR) "." DRWAV_XSTRINGIFY(DRWAV_VERSION_REVISION) #include typedef signed char drwav_int8; @@ -38784,7 +38879,7 @@ extern "C" { #define DRFLAC_XSTRINGIFY(x) DRFLAC_STRINGIFY(x) #define DRFLAC_VERSION_MAJOR 0 #define DRFLAC_VERSION_MINOR 12 -#define DRFLAC_VERSION_REVISION 25 +#define DRFLAC_VERSION_REVISION 26 #define DRFLAC_VERSION_STRING DRFLAC_XSTRINGIFY(DRFLAC_VERSION_MAJOR) "." DRFLAC_XSTRINGIFY(DRFLAC_VERSION_MINOR) "." DRFLAC_XSTRINGIFY(DRFLAC_VERSION_REVISION) #include typedef signed char drflac_int8; @@ -43103,24 +43198,6 @@ static const drwav_uint8 drwavGUID_W64_FMT [16] = {0x66,0x6D,0x74,0x20, 0xF3,0xA static const drwav_uint8 drwavGUID_W64_FACT[16] = {0x66,0x61,0x63,0x74, 0xF3,0xAC, 0xD3,0x11, 0x8C,0xD1, 0x00,0xC0,0x4F,0x8E,0xDB,0x8A}; static const drwav_uint8 drwavGUID_W64_DATA[16] = {0x64,0x61,0x74,0x61, 0xF3,0xAC, 0xD3,0x11, 0x8C,0xD1, 0x00,0xC0,0x4F,0x8E,0xDB,0x8A}; static const drwav_uint8 drwavGUID_W64_SMPL[16] = {0x73,0x6D,0x70,0x6C, 0xF3,0xAC, 0xD3,0x11, 0x8C,0xD1, 0x00,0xC0,0x4F,0x8E,0xDB,0x8A}; -static DRWAV_INLINE drwav_bool32 drwav__guid_equal(const drwav_uint8 a[16], const drwav_uint8 b[16]) -{ - int i; - for (i = 0; i < 16; i += 1) { - if (a[i] != b[i]) { - return DRWAV_FALSE; - } - } - return DRWAV_TRUE; -} -static DRWAV_INLINE drwav_bool32 drwav__fourcc_equal(const drwav_uint8* a, const char* b) -{ - return - a[0] == b[0] && - a[1] == b[1] && - a[2] == b[2] && - a[3] == b[3]; -} static DRWAV_INLINE int drwav__is_little_endian(void) { #if defined(DRWAV_X86) || defined(DRWAV_X64) @@ -43132,32 +43209,6 @@ static DRWAV_INLINE int drwav__is_little_endian(void) return (*(char*)&n) == 1; #endif } -static DRWAV_INLINE drwav_uint16 drwav__bytes_to_u16(const drwav_uint8* data) -{ - return (data[0] << 0) | (data[1] << 8); -} -static DRWAV_INLINE drwav_int16 drwav__bytes_to_s16(const drwav_uint8* data) -{ - return (short)drwav__bytes_to_u16(data); -} -static DRWAV_INLINE drwav_uint32 drwav__bytes_to_u32(const drwav_uint8* data) -{ - return (data[0] << 0) | (data[1] << 8) | (data[2] << 16) | (data[3] << 24); -} -static DRWAV_INLINE drwav_int32 drwav__bytes_to_s32(const drwav_uint8* data) -{ - return (drwav_int32)drwav__bytes_to_u32(data); -} -static DRWAV_INLINE drwav_uint64 drwav__bytes_to_u64(const drwav_uint8* data) -{ - return - ((drwav_uint64)data[0] << 0) | ((drwav_uint64)data[1] << 8) | ((drwav_uint64)data[2] << 16) | ((drwav_uint64)data[3] << 24) | - ((drwav_uint64)data[4] << 32) | ((drwav_uint64)data[5] << 40) | ((drwav_uint64)data[6] << 48) | ((drwav_uint64)data[7] << 56); -} -static DRWAV_INLINE drwav_int64 drwav__bytes_to_s64(const drwav_uint8* data) -{ - return (drwav_int64)drwav__bytes_to_u64(data); -} static DRWAV_INLINE void drwav__bytes_to_guid(const drwav_uint8* data, drwav_uint8* guid) { int i; @@ -43372,22 +43423,22 @@ static DRWAV_INLINE void drwav__bswap_samples(void* pSamples, drwav_uint64 sampl } break; } } -static void* drwav__malloc_default(size_t sz, void* pUserData) +DRWAV_PRIVATE void* drwav__malloc_default(size_t sz, void* pUserData) { (void)pUserData; return DRWAV_MALLOC(sz); } -static void* drwav__realloc_default(void* p, size_t sz, void* pUserData) +DRWAV_PRIVATE void* drwav__realloc_default(void* p, size_t sz, void* pUserData) { (void)pUserData; return DRWAV_REALLOC(p, sz); } -static void drwav__free_default(void* p, void* pUserData) +DRWAV_PRIVATE void drwav__free_default(void* p, void* pUserData) { (void)pUserData; DRWAV_FREE(p); } -static void* drwav__malloc_from_callbacks(size_t sz, const drwav_allocation_callbacks* pAllocationCallbacks) +DRWAV_PRIVATE void* drwav__malloc_from_callbacks(size_t sz, const drwav_allocation_callbacks* pAllocationCallbacks) { if (pAllocationCallbacks == NULL) { return NULL; @@ -43400,7 +43451,7 @@ static void* drwav__malloc_from_callbacks(size_t sz, const drwav_allocation_call } return NULL; } -static void* drwav__realloc_from_callbacks(void* p, size_t szNew, size_t szOld, const drwav_allocation_callbacks* pAllocationCallbacks) +DRWAV_PRIVATE void* drwav__realloc_from_callbacks(void* p, size_t szNew, size_t szOld, const drwav_allocation_callbacks* pAllocationCallbacks) { if (pAllocationCallbacks == NULL) { return NULL; @@ -43422,7 +43473,7 @@ static void* drwav__realloc_from_callbacks(void* p, size_t szNew, size_t szOld, } return NULL; } -static void drwav__free_from_callbacks(void* p, const drwav_allocation_callbacks* pAllocationCallbacks) +DRWAV_PRIVATE void drwav__free_from_callbacks(void* p, const drwav_allocation_callbacks* pAllocationCallbacks) { if (p == NULL || pAllocationCallbacks == NULL) { return; @@ -43431,7 +43482,7 @@ static void drwav__free_from_callbacks(void* p, const drwav_allocation_callbacks pAllocationCallbacks->onFree(p, pAllocationCallbacks->pUserData); } } -static drwav_allocation_callbacks drwav_copy_allocation_callbacks_or_defaults(const drwav_allocation_callbacks* pAllocationCallbacks) +DRWAV_PRIVATE drwav_allocation_callbacks drwav_copy_allocation_callbacks_or_defaults(const drwav_allocation_callbacks* pAllocationCallbacks) { if (pAllocationCallbacks != NULL) { return *pAllocationCallbacks; @@ -43450,18 +43501,18 @@ static DRWAV_INLINE drwav_bool32 drwav__is_compressed_format_tag(drwav_uint16 fo formatTag == DR_WAVE_FORMAT_ADPCM || formatTag == DR_WAVE_FORMAT_DVI_ADPCM; } -static unsigned int drwav__chunk_padding_size_riff(drwav_uint64 chunkSize) +DRWAV_PRIVATE unsigned int drwav__chunk_padding_size_riff(drwav_uint64 chunkSize) { return (unsigned int)(chunkSize % 2); } -static unsigned int drwav__chunk_padding_size_w64(drwav_uint64 chunkSize) +DRWAV_PRIVATE unsigned int drwav__chunk_padding_size_w64(drwav_uint64 chunkSize) { return (unsigned int)(chunkSize % 8); } -static drwav_uint64 drwav_read_pcm_frames_s16__msadpcm(drwav* pWav, drwav_uint64 samplesToRead, drwav_int16* pBufferOut); -static drwav_uint64 drwav_read_pcm_frames_s16__ima(drwav* pWav, drwav_uint64 samplesToRead, drwav_int16* pBufferOut); -static drwav_bool32 drwav_init_write__internal(drwav* pWav, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount); -static drwav_result drwav__read_chunk_header(drwav_read_proc onRead, void* pUserData, drwav_container container, drwav_uint64* pRunningBytesReadOut, drwav_chunk_header* pHeaderOut) +DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__msadpcm(drwav* pWav, drwav_uint64 samplesToRead, drwav_int16* pBufferOut); +DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__ima(drwav* pWav, drwav_uint64 samplesToRead, drwav_int16* pBufferOut); +DRWAV_PRIVATE drwav_bool32 drwav_init_write__internal(drwav* pWav, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount); +DRWAV_PRIVATE drwav_result drwav__read_chunk_header(drwav_read_proc onRead, void* pUserData, drwav_container container, drwav_uint64* pRunningBytesReadOut, drwav_chunk_header* pHeaderOut) { if (container == drwav_container_riff || container == drwav_container_rf64) { drwav_uint8 sizeInBytes[4]; @@ -43471,7 +43522,7 @@ static drwav_result drwav__read_chunk_header(drwav_read_proc onRead, void* pUser if (onRead(pUserData, sizeInBytes, 4) != 4) { return DRWAV_INVALID_FILE; } - pHeaderOut->sizeInBytes = drwav__bytes_to_u32(sizeInBytes); + pHeaderOut->sizeInBytes = drwav_bytes_to_u32(sizeInBytes); pHeaderOut->paddingSize = drwav__chunk_padding_size_riff(pHeaderOut->sizeInBytes); *pRunningBytesReadOut += 8; } else { @@ -43482,13 +43533,13 @@ static drwav_result drwav__read_chunk_header(drwav_read_proc onRead, void* pUser if (onRead(pUserData, sizeInBytes, 8) != 8) { return DRWAV_INVALID_FILE; } - pHeaderOut->sizeInBytes = drwav__bytes_to_u64(sizeInBytes) - 24; + pHeaderOut->sizeInBytes = drwav_bytes_to_u64(sizeInBytes) - 24; pHeaderOut->paddingSize = drwav__chunk_padding_size_w64(pHeaderOut->sizeInBytes); *pRunningBytesReadOut += 24; } return DRWAV_SUCCESS; } -static drwav_bool32 drwav__seek_forward(drwav_seek_proc onSeek, drwav_uint64 offset, void* pUserData) +DRWAV_PRIVATE drwav_bool32 drwav__seek_forward(drwav_seek_proc onSeek, drwav_uint64 offset, void* pUserData) { drwav_uint64 bytesRemainingToSeek = offset; while (bytesRemainingToSeek > 0) { @@ -43506,7 +43557,7 @@ static drwav_bool32 drwav__seek_forward(drwav_seek_proc onSeek, drwav_uint64 off } return DRWAV_TRUE; } -static drwav_bool32 drwav__seek_from_start(drwav_seek_proc onSeek, drwav_uint64 offset, void* pUserData) +DRWAV_PRIVATE drwav_bool32 drwav__seek_from_start(drwav_seek_proc onSeek, drwav_uint64 offset, void* pUserData) { if (offset <= 0x7FFFFFFF) { return onSeek(pUserData, (int)offset, drwav_seek_origin_start); @@ -43525,14 +43576,14 @@ static drwav_bool32 drwav__seek_from_start(drwav_seek_proc onSeek, drwav_uint64 offset -= 0x7FFFFFFF; } } -static drwav_bool32 drwav__read_fmt(drwav_read_proc onRead, drwav_seek_proc onSeek, void* pUserData, drwav_container container, drwav_uint64* pRunningBytesReadOut, drwav_fmt* fmtOut) +DRWAV_PRIVATE drwav_bool32 drwav__read_fmt(drwav_read_proc onRead, drwav_seek_proc onSeek, void* pUserData, drwav_container container, drwav_uint64* pRunningBytesReadOut, drwav_fmt* fmtOut) { drwav_chunk_header header; drwav_uint8 fmt[16]; if (drwav__read_chunk_header(onRead, pUserData, container, pRunningBytesReadOut, &header) != DRWAV_SUCCESS) { return DRWAV_FALSE; } - while (((container == drwav_container_riff || container == drwav_container_rf64) && !drwav__fourcc_equal(header.id.fourcc, "fmt ")) || (container == drwav_container_w64 && !drwav__guid_equal(header.id.guid, drwavGUID_W64_FMT))) { + while (((container == drwav_container_riff || container == drwav_container_rf64) && !drwav_fourcc_equal(header.id.fourcc, "fmt ")) || (container == drwav_container_w64 && !drwav_guid_equal(header.id.guid, drwavGUID_W64_FMT))) { if (!drwav__seek_forward(onSeek, header.sizeInBytes + header.paddingSize, pUserData)) { return DRWAV_FALSE; } @@ -43542,11 +43593,11 @@ static drwav_bool32 drwav__read_fmt(drwav_read_proc onRead, drwav_seek_proc onSe } } if (container == drwav_container_riff || container == drwav_container_rf64) { - if (!drwav__fourcc_equal(header.id.fourcc, "fmt ")) { + if (!drwav_fourcc_equal(header.id.fourcc, "fmt ")) { return DRWAV_FALSE; } } else { - if (!drwav__guid_equal(header.id.guid, drwavGUID_W64_FMT)) { + if (!drwav_guid_equal(header.id.guid, drwavGUID_W64_FMT)) { return DRWAV_FALSE; } } @@ -43554,12 +43605,12 @@ static drwav_bool32 drwav__read_fmt(drwav_read_proc onRead, drwav_seek_proc onSe return DRWAV_FALSE; } *pRunningBytesReadOut += sizeof(fmt); - fmtOut->formatTag = drwav__bytes_to_u16(fmt + 0); - fmtOut->channels = drwav__bytes_to_u16(fmt + 2); - fmtOut->sampleRate = drwav__bytes_to_u32(fmt + 4); - fmtOut->avgBytesPerSec = drwav__bytes_to_u32(fmt + 8); - fmtOut->blockAlign = drwav__bytes_to_u16(fmt + 12); - fmtOut->bitsPerSample = drwav__bytes_to_u16(fmt + 14); + fmtOut->formatTag = drwav_bytes_to_u16(fmt + 0); + fmtOut->channels = drwav_bytes_to_u16(fmt + 2); + fmtOut->sampleRate = drwav_bytes_to_u32(fmt + 4); + fmtOut->avgBytesPerSec = drwav_bytes_to_u32(fmt + 8); + fmtOut->blockAlign = drwav_bytes_to_u16(fmt + 12); + fmtOut->bitsPerSample = drwav_bytes_to_u16(fmt + 14); fmtOut->extendedSize = 0; fmtOut->validBitsPerSample = 0; fmtOut->channelMask = 0; @@ -43572,7 +43623,7 @@ static drwav_bool32 drwav__read_fmt(drwav_read_proc onRead, drwav_seek_proc onSe } *pRunningBytesReadOut += sizeof(fmt_cbSize); bytesReadSoFar = 18; - fmtOut->extendedSize = drwav__bytes_to_u16(fmt_cbSize); + fmtOut->extendedSize = drwav_bytes_to_u16(fmt_cbSize); if (fmtOut->extendedSize > 0) { if (fmtOut->formatTag == DR_WAVE_FORMAT_EXTENSIBLE) { if (fmtOut->extendedSize != 22) { @@ -43584,8 +43635,8 @@ static drwav_bool32 drwav__read_fmt(drwav_read_proc onRead, drwav_seek_proc onSe if (onRead(pUserData, fmtext, fmtOut->extendedSize) != fmtOut->extendedSize) { return DRWAV_FALSE; } - fmtOut->validBitsPerSample = drwav__bytes_to_u16(fmtext + 0); - fmtOut->channelMask = drwav__bytes_to_u32(fmtext + 2); + fmtOut->validBitsPerSample = drwav_bytes_to_u16(fmtext + 0); + fmtOut->channelMask = drwav_bytes_to_u32(fmtext + 2); drwav__bytes_to_guid(fmtext + 6, fmtOut->subFormat); } else { if (!onSeek(pUserData, fmtOut->extendedSize, drwav_seek_origin_current)) { @@ -43608,7 +43659,7 @@ static drwav_bool32 drwav__read_fmt(drwav_read_proc onRead, drwav_seek_proc onSe } return DRWAV_TRUE; } -static size_t drwav__on_read(drwav_read_proc onRead, void* pUserData, void* pBufferOut, size_t bytesToRead, drwav_uint64* pCursor) +DRWAV_PRIVATE size_t drwav__on_read(drwav_read_proc onRead, void* pUserData, void* pBufferOut, size_t bytesToRead, drwav_uint64* pCursor) { size_t bytesRead; DRWAV_ASSERT(onRead != NULL); @@ -43618,7 +43669,7 @@ static size_t drwav__on_read(drwav_read_proc onRead, void* pUserData, void* pBuf return bytesRead; } #if 0 -static drwav_bool32 drwav__on_seek(drwav_seek_proc onSeek, void* pUserData, int offset, drwav_seek_origin origin, drwav_uint64* pCursor) +DRWAV_PRIVATE drwav_bool32 drwav__on_seek(drwav_seek_proc onSeek, void* pUserData, int offset, drwav_seek_origin origin, drwav_uint64* pCursor) { DRWAV_ASSERT(onSeek != NULL); DRWAV_ASSERT(pCursor != NULL); @@ -43633,7 +43684,7 @@ static drwav_bool32 drwav__on_seek(drwav_seek_proc onSeek, void* pUserData, int return DRWAV_TRUE; } #endif -static drwav_uint32 drwav_get_bytes_per_pcm_frame(drwav* pWav) +DRWAV_PRIVATE drwav_uint32 drwav_get_bytes_per_pcm_frame(drwav* pWav) { if ((pWav->bitsPerSample & 0x7) == 0) { return (pWav->bitsPerSample * pWav->fmt.channels) >> 3; @@ -43649,10 +43700,10 @@ DRWAV_API drwav_uint16 drwav_fmt_get_format(const drwav_fmt* pFMT) if (pFMT->formatTag != DR_WAVE_FORMAT_EXTENSIBLE) { return pFMT->formatTag; } else { - return drwav__bytes_to_u16(pFMT->subFormat); + return drwav_bytes_to_u16(pFMT->subFormat); } } -static drwav_bool32 drwav_preinit(drwav* pWav, drwav_read_proc onRead, drwav_seek_proc onSeek, void* pReadSeekUserData, const drwav_allocation_callbacks* pAllocationCallbacks) +DRWAV_PRIVATE drwav_bool32 drwav_preinit(drwav* pWav, drwav_read_proc onRead, drwav_seek_proc onSeek, void* pReadSeekUserData, const drwav_allocation_callbacks* pAllocationCallbacks) { if (pWav == NULL || onRead == NULL || onSeek == NULL) { return DRWAV_FALSE; @@ -43667,7 +43718,7 @@ static drwav_bool32 drwav_preinit(drwav* pWav, drwav_read_proc onRead, drwav_see } return DRWAV_TRUE; } -static drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk, void* pChunkUserData, drwav_uint32 flags) +DRWAV_PRIVATE drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk, void* pChunkUserData, drwav_uint32 flags) { drwav_uint64 cursor; drwav_bool32 sequential; @@ -43683,9 +43734,9 @@ static drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk, if (drwav__on_read(pWav->onRead, pWav->pUserData, riff, sizeof(riff), &cursor) != sizeof(riff)) { return DRWAV_FALSE; } - if (drwav__fourcc_equal(riff, "RIFF")) { + if (drwav_fourcc_equal(riff, "RIFF")) { pWav->container = drwav_container_riff; - } else if (drwav__fourcc_equal(riff, "riff")) { + } else if (drwav_fourcc_equal(riff, "riff")) { int i; drwav_uint8 riff2[12]; pWav->container = drwav_container_w64; @@ -43697,7 +43748,7 @@ static drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk, return DRWAV_FALSE; } } - } else if (drwav__fourcc_equal(riff, "RF64")) { + } else if (drwav_fourcc_equal(riff, "RF64")) { pWav->container = drwav_container_rf64; } else { return DRWAV_FALSE; @@ -43709,18 +43760,18 @@ static drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk, return DRWAV_FALSE; } if (pWav->container == drwav_container_riff) { - if (drwav__bytes_to_u32(chunkSizeBytes) < 36) { + if (drwav_bytes_to_u32(chunkSizeBytes) < 36) { return DRWAV_FALSE; } } else { - if (drwav__bytes_to_u32(chunkSizeBytes) != 0xFFFFFFFF) { + if (drwav_bytes_to_u32(chunkSizeBytes) != 0xFFFFFFFF) { return DRWAV_FALSE; } } if (drwav__on_read(pWav->onRead, pWav->pUserData, wave, sizeof(wave), &cursor) != sizeof(wave)) { return DRWAV_FALSE; } - if (!drwav__fourcc_equal(wave, "WAVE")) { + if (!drwav_fourcc_equal(wave, "WAVE")) { return DRWAV_FALSE; } } else { @@ -43729,13 +43780,13 @@ static drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk, if (drwav__on_read(pWav->onRead, pWav->pUserData, chunkSizeBytes, sizeof(chunkSizeBytes), &cursor) != sizeof(chunkSizeBytes)) { return DRWAV_FALSE; } - if (drwav__bytes_to_u64(chunkSizeBytes) < 80) { + if (drwav_bytes_to_u64(chunkSizeBytes) < 80) { return DRWAV_FALSE; } if (drwav__on_read(pWav->onRead, pWav->pUserData, wave, sizeof(wave), &cursor) != sizeof(wave)) { return DRWAV_FALSE; } - if (!drwav__guid_equal(wave, drwavGUID_W64_WAVE)) { + if (!drwav_guid_equal(wave, drwavGUID_W64_WAVE)) { return DRWAV_FALSE; } } @@ -43747,7 +43798,7 @@ static drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk, if (result != DRWAV_SUCCESS) { return DRWAV_FALSE; } - if (!drwav__fourcc_equal(header.id.fourcc, "ds64")) { + if (!drwav_fourcc_equal(header.id.fourcc, "ds64")) { return DRWAV_FALSE; } bytesRemainingInChunk = header.sizeInBytes + header.paddingSize; @@ -43760,12 +43811,12 @@ static drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk, return DRWAV_FALSE; } bytesRemainingInChunk -= 8; - dataChunkSize = drwav__bytes_to_u64(sizeBytes); + dataChunkSize = drwav_bytes_to_u64(sizeBytes); if (drwav__on_read(pWav->onRead, pWav->pUserData, sizeBytes, sizeof(sizeBytes), &cursor) != sizeof(sizeBytes)) { return DRWAV_FALSE; } bytesRemainingInChunk -= 8; - sampleCountFromFactChunk = drwav__bytes_to_u64(sizeBytes); + sampleCountFromFactChunk = drwav_bytes_to_u64(sizeBytes); if (!drwav__seek_forward(pWav->onSeek, bytesRemainingInChunk, pWav->pUserData)) { return DRWAV_FALSE; } @@ -43782,7 +43833,7 @@ static drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk, } translatedFormatTag = fmt.formatTag; if (translatedFormatTag == DR_WAVE_FORMAT_EXTENSIBLE) { - translatedFormatTag = drwav__bytes_to_u16(fmt.subFormat + 0); + translatedFormatTag = drwav_bytes_to_u16(fmt.subFormat + 0); } foundDataChunk = DRWAV_FALSE; for (;;) @@ -43809,14 +43860,14 @@ static drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk, } chunkSize = header.sizeInBytes; if (pWav->container == drwav_container_riff || pWav->container == drwav_container_rf64) { - if (drwav__fourcc_equal(header.id.fourcc, "data")) { + if (drwav_fourcc_equal(header.id.fourcc, "data")) { foundDataChunk = DRWAV_TRUE; if (pWav->container != drwav_container_rf64) { dataChunkSize = chunkSize; } } } else { - if (drwav__guid_equal(header.id.guid, drwavGUID_W64_DATA)) { + if (drwav_guid_equal(header.id.guid, drwavGUID_W64_DATA)) { foundDataChunk = DRWAV_TRUE; dataChunkSize = chunkSize; } @@ -43825,7 +43876,7 @@ static drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk, break; } if (pWav->container == drwav_container_riff) { - if (drwav__fourcc_equal(header.id.fourcc, "fact")) { + if (drwav_fourcc_equal(header.id.fourcc, "fact")) { drwav_uint32 sampleCount; if (drwav__on_read(pWav->onRead, pWav->pUserData, &sampleCount, 4, &cursor) != 4) { return DRWAV_FALSE; @@ -43841,7 +43892,7 @@ static drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk, } } } else if (pWav->container == drwav_container_w64) { - if (drwav__guid_equal(header.id.guid, drwavGUID_W64_FACT)) { + if (drwav_guid_equal(header.id.guid, drwavGUID_W64_FACT)) { if (drwav__on_read(pWav->onRead, pWav->pUserData, &sampleCountFromFactChunk, 8, &cursor) != 8) { return DRWAV_FALSE; } @@ -43853,33 +43904,33 @@ static drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk, } else if (pWav->container == drwav_container_rf64) { } if (pWav->container == drwav_container_riff || pWav->container == drwav_container_rf64) { - if (drwav__fourcc_equal(header.id.fourcc, "smpl")) { + if (drwav_fourcc_equal(header.id.fourcc, "smpl")) { drwav_uint8 smplHeaderData[36]; if (chunkSize >= sizeof(smplHeaderData)) { drwav_uint64 bytesJustRead = drwav__on_read(pWav->onRead, pWav->pUserData, smplHeaderData, sizeof(smplHeaderData), &cursor); chunkSize -= bytesJustRead; if (bytesJustRead == sizeof(smplHeaderData)) { drwav_uint32 iLoop; - pWav->smpl.manufacturer = drwav__bytes_to_u32(smplHeaderData+0); - pWav->smpl.product = drwav__bytes_to_u32(smplHeaderData+4); - pWav->smpl.samplePeriod = drwav__bytes_to_u32(smplHeaderData+8); - pWav->smpl.midiUnityNotes = drwav__bytes_to_u32(smplHeaderData+12); - pWav->smpl.midiPitchFraction = drwav__bytes_to_u32(smplHeaderData+16); - pWav->smpl.smpteFormat = drwav__bytes_to_u32(smplHeaderData+20); - pWav->smpl.smpteOffset = drwav__bytes_to_u32(smplHeaderData+24); - pWav->smpl.numSampleLoops = drwav__bytes_to_u32(smplHeaderData+28); - pWav->smpl.samplerData = drwav__bytes_to_u32(smplHeaderData+32); + pWav->smpl.manufacturer = drwav_bytes_to_u32(smplHeaderData+0); + pWav->smpl.product = drwav_bytes_to_u32(smplHeaderData+4); + pWav->smpl.samplePeriod = drwav_bytes_to_u32(smplHeaderData+8); + pWav->smpl.midiUnityNotes = drwav_bytes_to_u32(smplHeaderData+12); + pWav->smpl.midiPitchFraction = drwav_bytes_to_u32(smplHeaderData+16); + pWav->smpl.smpteFormat = drwav_bytes_to_u32(smplHeaderData+20); + pWav->smpl.smpteOffset = drwav_bytes_to_u32(smplHeaderData+24); + pWav->smpl.numSampleLoops = drwav_bytes_to_u32(smplHeaderData+28); + pWav->smpl.samplerData = drwav_bytes_to_u32(smplHeaderData+32); for (iLoop = 0; iLoop < pWav->smpl.numSampleLoops && iLoop < drwav_countof(pWav->smpl.loops); ++iLoop) { drwav_uint8 smplLoopData[24]; bytesJustRead = drwav__on_read(pWav->onRead, pWav->pUserData, smplLoopData, sizeof(smplLoopData), &cursor); chunkSize -= bytesJustRead; if (bytesJustRead == sizeof(smplLoopData)) { - pWav->smpl.loops[iLoop].cuePointId = drwav__bytes_to_u32(smplLoopData+0); - pWav->smpl.loops[iLoop].type = drwav__bytes_to_u32(smplLoopData+4); - pWav->smpl.loops[iLoop].start = drwav__bytes_to_u32(smplLoopData+8); - pWav->smpl.loops[iLoop].end = drwav__bytes_to_u32(smplLoopData+12); - pWav->smpl.loops[iLoop].fraction = drwav__bytes_to_u32(smplLoopData+16); - pWav->smpl.loops[iLoop].playCount = drwav__bytes_to_u32(smplLoopData+20); + pWav->smpl.loops[iLoop].cuePointId = drwav_bytes_to_u32(smplLoopData+0); + pWav->smpl.loops[iLoop].type = drwav_bytes_to_u32(smplLoopData+4); + pWav->smpl.loops[iLoop].start = drwav_bytes_to_u32(smplLoopData+8); + pWav->smpl.loops[iLoop].end = drwav_bytes_to_u32(smplLoopData+12); + pWav->smpl.loops[iLoop].fraction = drwav_bytes_to_u32(smplLoopData+16); + pWav->smpl.loops[iLoop].playCount = drwav_bytes_to_u32(smplLoopData+20); } else { break; } @@ -43889,7 +43940,7 @@ static drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk, } } } else { - if (drwav__guid_equal(header.id.guid, drwavGUID_W64_SMPL)) { + if (drwav_guid_equal(header.id.guid, drwavGUID_W64_SMPL)) { } } chunkSize += header.paddingSize; @@ -43969,7 +44020,7 @@ DRWAV_API drwav_bool32 drwav_init_ex(drwav* pWav, drwav_read_proc onRead, drwav_ } return drwav_init__internal(pWav, onChunk, pChunkUserData, flags); } -static drwav_uint32 drwav__riff_chunk_size_riff(drwav_uint64 dataChunkSize) +DRWAV_PRIVATE drwav_uint32 drwav__riff_chunk_size_riff(drwav_uint64 dataChunkSize) { drwav_uint64 chunkSize = 4 + 24 + dataChunkSize + drwav__chunk_padding_size_riff(dataChunkSize); if (chunkSize > 0xFFFFFFFFUL) { @@ -43977,7 +44028,7 @@ static drwav_uint32 drwav__riff_chunk_size_riff(drwav_uint64 dataChunkSize) } return (drwav_uint32)chunkSize; } -static drwav_uint32 drwav__data_chunk_size_riff(drwav_uint64 dataChunkSize) +DRWAV_PRIVATE drwav_uint32 drwav__data_chunk_size_riff(drwav_uint64 dataChunkSize) { if (dataChunkSize <= 0xFFFFFFFFUL) { return (drwav_uint32)dataChunkSize; @@ -43985,16 +44036,16 @@ static drwav_uint32 drwav__data_chunk_size_riff(drwav_uint64 dataChunkSize) return 0xFFFFFFFFUL; } } -static drwav_uint64 drwav__riff_chunk_size_w64(drwav_uint64 dataChunkSize) +DRWAV_PRIVATE drwav_uint64 drwav__riff_chunk_size_w64(drwav_uint64 dataChunkSize) { drwav_uint64 dataSubchunkPaddingSize = drwav__chunk_padding_size_w64(dataChunkSize); return 80 + 24 + dataChunkSize + dataSubchunkPaddingSize; } -static drwav_uint64 drwav__data_chunk_size_w64(drwav_uint64 dataChunkSize) +DRWAV_PRIVATE drwav_uint64 drwav__data_chunk_size_w64(drwav_uint64 dataChunkSize) { return 24 + dataChunkSize; } -static drwav_uint64 drwav__riff_chunk_size_rf64(drwav_uint64 dataChunkSize) +DRWAV_PRIVATE drwav_uint64 drwav__riff_chunk_size_rf64(drwav_uint64 dataChunkSize) { drwav_uint64 chunkSize = 4 + 36 + 24 + dataChunkSize + drwav__chunk_padding_size_riff(dataChunkSize); if (chunkSize > 0xFFFFFFFFUL) { @@ -44002,17 +44053,17 @@ static drwav_uint64 drwav__riff_chunk_size_rf64(drwav_uint64 dataChunkSize) } return chunkSize; } -static drwav_uint64 drwav__data_chunk_size_rf64(drwav_uint64 dataChunkSize) +DRWAV_PRIVATE drwav_uint64 drwav__data_chunk_size_rf64(drwav_uint64 dataChunkSize) { return dataChunkSize; } -static size_t drwav__write(drwav* pWav, const void* pData, size_t dataSize) +DRWAV_PRIVATE size_t drwav__write(drwav* pWav, const void* pData, size_t dataSize) { DRWAV_ASSERT(pWav != NULL); DRWAV_ASSERT(pWav->onWrite != NULL); return pWav->onWrite(pWav->pUserData, pData, dataSize); } -static size_t drwav__write_u16ne_to_le(drwav* pWav, drwav_uint16 value) +DRWAV_PRIVATE size_t drwav__write_u16ne_to_le(drwav* pWav, drwav_uint16 value) { DRWAV_ASSERT(pWav != NULL); DRWAV_ASSERT(pWav->onWrite != NULL); @@ -44021,7 +44072,7 @@ static size_t drwav__write_u16ne_to_le(drwav* pWav, drwav_uint16 value) } return drwav__write(pWav, &value, 2); } -static size_t drwav__write_u32ne_to_le(drwav* pWav, drwav_uint32 value) +DRWAV_PRIVATE size_t drwav__write_u32ne_to_le(drwav* pWav, drwav_uint32 value) { DRWAV_ASSERT(pWav != NULL); DRWAV_ASSERT(pWav->onWrite != NULL); @@ -44030,7 +44081,7 @@ static size_t drwav__write_u32ne_to_le(drwav* pWav, drwav_uint32 value) } return drwav__write(pWav, &value, 4); } -static size_t drwav__write_u64ne_to_le(drwav* pWav, drwav_uint64 value) +DRWAV_PRIVATE size_t drwav__write_u64ne_to_le(drwav* pWav, drwav_uint64 value) { DRWAV_ASSERT(pWav != NULL); DRWAV_ASSERT(pWav->onWrite != NULL); @@ -44039,7 +44090,7 @@ static size_t drwav__write_u64ne_to_le(drwav* pWav, drwav_uint64 value) } return drwav__write(pWav, &value, 8); } -static drwav_bool32 drwav_preinit_write(drwav* pWav, const drwav_data_format* pFormat, drwav_bool32 isSequential, drwav_write_proc onWrite, drwav_seek_proc onSeek, void* pUserData, const drwav_allocation_callbacks* pAllocationCallbacks) +DRWAV_PRIVATE drwav_bool32 drwav_preinit_write(drwav* pWav, const drwav_data_format* pFormat, drwav_bool32 isSequential, drwav_write_proc onWrite, drwav_seek_proc onSeek, void* pUserData, const drwav_allocation_callbacks* pAllocationCallbacks) { if (pWav == NULL || onWrite == NULL) { return DRWAV_FALSE; @@ -44071,7 +44122,7 @@ static drwav_bool32 drwav_preinit_write(drwav* pWav, const drwav_data_format* pF pWav->isSequentialWrite = isSequential; return DRWAV_TRUE; } -static drwav_bool32 drwav_init_write__internal(drwav* pWav, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount) +DRWAV_PRIVATE drwav_bool32 drwav_init_write__internal(drwav* pWav, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount) { size_t runningPos = 0; drwav_uint64 initialDataChunkSize = 0; @@ -44186,7 +44237,7 @@ DRWAV_API drwav_uint64 drwav_target_write_size_bytes(const drwav_data_format* pF } #ifndef DR_WAV_NO_STDIO #include -static drwav_result drwav_result_from_errno(int e) +DRWAV_PRIVATE drwav_result drwav_result_from_errno(int e) { switch (e) { @@ -44587,7 +44638,7 @@ static drwav_result drwav_result_from_errno(int e) default: return DRWAV_ERROR; } } -static drwav_result drwav_fopen(FILE** ppFile, const char* pFilePath, const char* pOpenMode) +DRWAV_PRIVATE drwav_result drwav_fopen(FILE** ppFile, const char* pFilePath, const char* pOpenMode) { #if _MSC_VER && _MSC_VER >= 1400 errno_t err; @@ -44628,7 +44679,7 @@ static drwav_result drwav_fopen(FILE** ppFile, const char* pFilePath, const char #define DRWAV_HAS_WFOPEN #endif #endif -static drwav_result drwav_wfopen(FILE** ppFile, const wchar_t* pFilePath, const wchar_t* pOpenMode, const drwav_allocation_callbacks* pAllocationCallbacks) +DRWAV_PRIVATE drwav_result drwav_wfopen(FILE** ppFile, const wchar_t* pFilePath, const wchar_t* pOpenMode, const drwav_allocation_callbacks* pAllocationCallbacks) { if (ppFile != NULL) { *ppFile = NULL; @@ -44690,15 +44741,15 @@ static drwav_result drwav_wfopen(FILE** ppFile, const wchar_t* pFilePath, const #endif return DRWAV_SUCCESS; } -static size_t drwav__on_read_stdio(void* pUserData, void* pBufferOut, size_t bytesToRead) +DRWAV_PRIVATE size_t drwav__on_read_stdio(void* pUserData, void* pBufferOut, size_t bytesToRead) { return fread(pBufferOut, 1, bytesToRead, (FILE*)pUserData); } -static size_t drwav__on_write_stdio(void* pUserData, const void* pData, size_t bytesToWrite) +DRWAV_PRIVATE size_t drwav__on_write_stdio(void* pUserData, const void* pData, size_t bytesToWrite) { return fwrite(pData, 1, bytesToWrite, (FILE*)pUserData); } -static drwav_bool32 drwav__on_seek_stdio(void* pUserData, int offset, drwav_seek_origin origin) +DRWAV_PRIVATE drwav_bool32 drwav__on_seek_stdio(void* pUserData, int offset, drwav_seek_origin origin) { return fseek((FILE*)pUserData, offset, (origin == drwav_seek_origin_current) ? SEEK_CUR : SEEK_SET) == 0; } @@ -44706,7 +44757,7 @@ DRWAV_API drwav_bool32 drwav_init_file(drwav* pWav, const char* filename, const { return drwav_init_file_ex(pWav, filename, NULL, NULL, 0, pAllocationCallbacks); } -static drwav_bool32 drwav_init_file__internal_FILE(drwav* pWav, FILE* pFile, drwav_chunk_proc onChunk, void* pChunkUserData, drwav_uint32 flags, const drwav_allocation_callbacks* pAllocationCallbacks) +DRWAV_PRIVATE drwav_bool32 drwav_init_file__internal_FILE(drwav* pWav, FILE* pFile, drwav_chunk_proc onChunk, void* pChunkUserData, drwav_uint32 flags, const drwav_allocation_callbacks* pAllocationCallbacks) { drwav_bool32 result; result = drwav_preinit(pWav, drwav__on_read_stdio, drwav__on_seek_stdio, (void*)pFile, pAllocationCallbacks); @@ -44741,7 +44792,7 @@ DRWAV_API drwav_bool32 drwav_init_file_ex_w(drwav* pWav, const wchar_t* filename } return drwav_init_file__internal_FILE(pWav, pFile, onChunk, pChunkUserData, flags, pAllocationCallbacks); } -static drwav_bool32 drwav_init_file_write__internal_FILE(drwav* pWav, FILE* pFile, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount, drwav_bool32 isSequential, const drwav_allocation_callbacks* pAllocationCallbacks) +DRWAV_PRIVATE drwav_bool32 drwav_init_file_write__internal_FILE(drwav* pWav, FILE* pFile, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount, drwav_bool32 isSequential, const drwav_allocation_callbacks* pAllocationCallbacks) { drwav_bool32 result; result = drwav_preinit_write(pWav, pFormat, isSequential, drwav__on_write_stdio, drwav__on_seek_stdio, (void*)pFile, pAllocationCallbacks); @@ -44756,7 +44807,7 @@ static drwav_bool32 drwav_init_file_write__internal_FILE(drwav* pWav, FILE* pFil } return DRWAV_TRUE; } -static drwav_bool32 drwav_init_file_write__internal(drwav* pWav, const char* filename, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount, drwav_bool32 isSequential, const drwav_allocation_callbacks* pAllocationCallbacks) +DRWAV_PRIVATE drwav_bool32 drwav_init_file_write__internal(drwav* pWav, const char* filename, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount, drwav_bool32 isSequential, const drwav_allocation_callbacks* pAllocationCallbacks) { FILE* pFile; if (drwav_fopen(&pFile, filename, "wb") != DRWAV_SUCCESS) { @@ -44764,7 +44815,7 @@ static drwav_bool32 drwav_init_file_write__internal(drwav* pWav, const char* fil } return drwav_init_file_write__internal_FILE(pWav, pFile, pFormat, totalSampleCount, isSequential, pAllocationCallbacks); } -static drwav_bool32 drwav_init_file_write_w__internal(drwav* pWav, const wchar_t* filename, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount, drwav_bool32 isSequential, const drwav_allocation_callbacks* pAllocationCallbacks) +DRWAV_PRIVATE drwav_bool32 drwav_init_file_write_w__internal(drwav* pWav, const wchar_t* filename, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount, drwav_bool32 isSequential, const drwav_allocation_callbacks* pAllocationCallbacks) { FILE* pFile; if (drwav_wfopen(&pFile, filename, L"wb", pAllocationCallbacks) != DRWAV_SUCCESS) { @@ -44803,7 +44854,7 @@ DRWAV_API drwav_bool32 drwav_init_file_write_sequential_pcm_frames_w(drwav* pWav return drwav_init_file_write_sequential_w(pWav, filename, pFormat, totalPCMFrameCount*pFormat->channels, pAllocationCallbacks); } #endif -static size_t drwav__on_read_memory(void* pUserData, void* pBufferOut, size_t bytesToRead) +DRWAV_PRIVATE size_t drwav__on_read_memory(void* pUserData, void* pBufferOut, size_t bytesToRead) { drwav* pWav = (drwav*)pUserData; size_t bytesRemaining; @@ -44819,7 +44870,7 @@ static size_t drwav__on_read_memory(void* pUserData, void* pBufferOut, size_t by } return bytesToRead; } -static drwav_bool32 drwav__on_seek_memory(void* pUserData, int offset, drwav_seek_origin origin) +DRWAV_PRIVATE drwav_bool32 drwav__on_seek_memory(void* pUserData, int offset, drwav_seek_origin origin) { drwav* pWav = (drwav*)pUserData; DRWAV_ASSERT(pWav != NULL); @@ -44843,7 +44894,7 @@ static drwav_bool32 drwav__on_seek_memory(void* pUserData, int offset, drwav_see } return DRWAV_TRUE; } -static size_t drwav__on_write_memory(void* pUserData, const void* pDataIn, size_t bytesToWrite) +DRWAV_PRIVATE size_t drwav__on_write_memory(void* pUserData, const void* pDataIn, size_t bytesToWrite) { drwav* pWav = (drwav*)pUserData; size_t bytesRemaining; @@ -44871,7 +44922,7 @@ static size_t drwav__on_write_memory(void* pUserData, const void* pDataIn, size_ *pWav->memoryStreamWrite.pDataSize = pWav->memoryStreamWrite.dataSize; return bytesToWrite; } -static drwav_bool32 drwav__on_seek_memory_write(void* pUserData, int offset, drwav_seek_origin origin) +DRWAV_PRIVATE drwav_bool32 drwav__on_seek_memory_write(void* pUserData, int offset, drwav_seek_origin origin) { drwav* pWav = (drwav*)pUserData; DRWAV_ASSERT(pWav != NULL); @@ -44912,7 +44963,7 @@ DRWAV_API drwav_bool32 drwav_init_memory_ex(drwav* pWav, const void* data, size_ pWav->memoryStream.currentReadPos = 0; return drwav_init__internal(pWav, onChunk, pChunkUserData, flags); } -static drwav_bool32 drwav_init_memory_write__internal(drwav* pWav, void** ppData, size_t* pDataSize, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount, drwav_bool32 isSequential, const drwav_allocation_callbacks* pAllocationCallbacks) +DRWAV_PRIVATE drwav_bool32 drwav_init_memory_write__internal(drwav* pWav, void** ppData, size_t* pDataSize, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount, drwav_bool32 isSequential, const drwav_allocation_callbacks* pAllocationCallbacks) { if (ppData == NULL || pDataSize == NULL) { return DRWAV_FALSE; @@ -45084,7 +45135,7 @@ DRWAV_API drwav_uint64 drwav_read_pcm_frames(drwav* pWav, drwav_uint64 framesToR return drwav_read_pcm_frames_be(pWav, framesToRead, pBufferOut); } } -DRWAV_API drwav_bool32 drwav_seek_to_first_pcm_frame(drwav* pWav) +DRWAV_PRIVATE drwav_bool32 drwav_seek_to_first_pcm_frame(drwav* pWav) { if (pWav->onWrite != NULL) { return DRWAV_FALSE; @@ -45261,7 +45312,7 @@ DRWAV_API drwav_uint64 drwav_write_pcm_frames(drwav* pWav, drwav_uint64 framesTo return drwav_write_pcm_frames_be(pWav, framesToWrite, pData); } } -static drwav_uint64 drwav_read_pcm_frames_s16__msadpcm(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut) +DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__msadpcm(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut) { drwav_uint64 totalFramesRead = 0; DRWAV_ASSERT(pWav != NULL); @@ -45275,9 +45326,9 @@ static drwav_uint64 drwav_read_pcm_frames_s16__msadpcm(drwav* pWav, drwav_uint64 } pWav->msadpcm.bytesRemainingInBlock = pWav->fmt.blockAlign - sizeof(header); pWav->msadpcm.predictor[0] = header[0]; - pWav->msadpcm.delta[0] = drwav__bytes_to_s16(header + 1); - pWav->msadpcm.prevFrames[0][1] = (drwav_int32)drwav__bytes_to_s16(header + 3); - pWav->msadpcm.prevFrames[0][0] = (drwav_int32)drwav__bytes_to_s16(header + 5); + pWav->msadpcm.delta[0] = drwav_bytes_to_s16(header + 1); + pWav->msadpcm.prevFrames[0][1] = (drwav_int32)drwav_bytes_to_s16(header + 3); + pWav->msadpcm.prevFrames[0][0] = (drwav_int32)drwav_bytes_to_s16(header + 5); pWav->msadpcm.cachedFrames[2] = pWav->msadpcm.prevFrames[0][0]; pWav->msadpcm.cachedFrames[3] = pWav->msadpcm.prevFrames[0][1]; pWav->msadpcm.cachedFrameCount = 2; @@ -45289,12 +45340,12 @@ static drwav_uint64 drwav_read_pcm_frames_s16__msadpcm(drwav* pWav, drwav_uint64 pWav->msadpcm.bytesRemainingInBlock = pWav->fmt.blockAlign - sizeof(header); pWav->msadpcm.predictor[0] = header[0]; pWav->msadpcm.predictor[1] = header[1]; - pWav->msadpcm.delta[0] = drwav__bytes_to_s16(header + 2); - pWav->msadpcm.delta[1] = drwav__bytes_to_s16(header + 4); - pWav->msadpcm.prevFrames[0][1] = (drwav_int32)drwav__bytes_to_s16(header + 6); - pWav->msadpcm.prevFrames[1][1] = (drwav_int32)drwav__bytes_to_s16(header + 8); - pWav->msadpcm.prevFrames[0][0] = (drwav_int32)drwav__bytes_to_s16(header + 10); - pWav->msadpcm.prevFrames[1][0] = (drwav_int32)drwav__bytes_to_s16(header + 12); + pWav->msadpcm.delta[0] = drwav_bytes_to_s16(header + 2); + pWav->msadpcm.delta[1] = drwav_bytes_to_s16(header + 4); + pWav->msadpcm.prevFrames[0][1] = (drwav_int32)drwav_bytes_to_s16(header + 6); + pWav->msadpcm.prevFrames[1][1] = (drwav_int32)drwav_bytes_to_s16(header + 8); + pWav->msadpcm.prevFrames[0][0] = (drwav_int32)drwav_bytes_to_s16(header + 10); + pWav->msadpcm.prevFrames[1][0] = (drwav_int32)drwav_bytes_to_s16(header + 12); pWav->msadpcm.cachedFrames[0] = pWav->msadpcm.prevFrames[0][0]; pWav->msadpcm.cachedFrames[1] = pWav->msadpcm.prevFrames[1][0]; pWav->msadpcm.cachedFrames[2] = pWav->msadpcm.prevFrames[0][1]; @@ -45391,7 +45442,7 @@ static drwav_uint64 drwav_read_pcm_frames_s16__msadpcm(drwav* pWav, drwav_uint64 } return totalFramesRead; } -static drwav_uint64 drwav_read_pcm_frames_s16__ima(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut) +DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__ima(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut) { drwav_uint64 totalFramesRead = 0; drwav_uint32 iChannel; @@ -45425,7 +45476,7 @@ static drwav_uint64 drwav_read_pcm_frames_s16__ima(drwav* pWav, drwav_uint64 fra pWav->ima.bytesRemainingInBlock = 0; return totalFramesRead; } - pWav->ima.predictor[0] = drwav__bytes_to_s16(header + 0); + pWav->ima.predictor[0] = drwav_bytes_to_s16(header + 0); pWav->ima.stepIndex[0] = header[2]; pWav->ima.cachedFrames[drwav_countof(pWav->ima.cachedFrames) - 1] = pWav->ima.predictor[0]; pWav->ima.cachedFrameCount = 1; @@ -45440,9 +45491,9 @@ static drwav_uint64 drwav_read_pcm_frames_s16__ima(drwav* pWav, drwav_uint64 fra pWav->ima.bytesRemainingInBlock = 0; return totalFramesRead; } - pWav->ima.predictor[0] = drwav__bytes_to_s16(header + 0); + pWav->ima.predictor[0] = drwav_bytes_to_s16(header + 0); pWav->ima.stepIndex[0] = header[2]; - pWav->ima.predictor[1] = drwav__bytes_to_s16(header + 4); + pWav->ima.predictor[1] = drwav_bytes_to_s16(header + 4); pWav->ima.stepIndex[1] = header[6]; pWav->ima.cachedFrames[drwav_countof(pWav->ima.cachedFrames) - 2] = pWav->ima.predictor[0]; pWav->ima.cachedFrames[drwav_countof(pWav->ima.cachedFrames) - 1] = pWav->ima.predictor[1]; @@ -45555,7 +45606,7 @@ static DRWAV_INLINE drwav_int16 drwav__mulaw_to_s16(drwav_uint8 sampleIn) { return (short)g_drwavMulawTable[sampleIn]; } -static void drwav__pcm_to_s16(drwav_int16* pOut, const drwav_uint8* pIn, size_t totalSampleCount, unsigned int bytesPerSample) +DRWAV_PRIVATE void drwav__pcm_to_s16(drwav_int16* pOut, const drwav_uint8* pIn, size_t totalSampleCount, unsigned int bytesPerSample) { unsigned int i; if (bytesPerSample == 1) { @@ -45593,7 +45644,7 @@ static void drwav__pcm_to_s16(drwav_int16* pOut, const drwav_uint8* pIn, size_t *pOut++ = (drwav_int16)((drwav_int64)sample >> 48); } } -static void drwav__ieee_to_s16(drwav_int16* pOut, const drwav_uint8* pIn, size_t totalSampleCount, unsigned int bytesPerSample) +DRWAV_PRIVATE void drwav__ieee_to_s16(drwav_int16* pOut, const drwav_uint8* pIn, size_t totalSampleCount, unsigned int bytesPerSample) { if (bytesPerSample == 4) { drwav_f32_to_s16(pOut, (const float*)pIn, totalSampleCount); @@ -45606,11 +45657,11 @@ static void drwav__ieee_to_s16(drwav_int16* pOut, const drwav_uint8* pIn, size_t return; } } -static drwav_uint64 drwav_read_pcm_frames_s16__pcm(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut) +DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__pcm(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut) { - drwav_uint32 bytesPerFrame; drwav_uint64 totalFramesRead; drwav_uint8 sampleData[4096]; + drwav_uint32 bytesPerFrame; if ((pWav->translatedFormatTag == DR_WAVE_FORMAT_PCM && pWav->bitsPerSample == 16) || pBufferOut == NULL) { return drwav_read_pcm_frames(pWav, framesToRead, pBufferOut); } @@ -45631,7 +45682,7 @@ static drwav_uint64 drwav_read_pcm_frames_s16__pcm(drwav* pWav, drwav_uint64 fra } return totalFramesRead; } -static drwav_uint64 drwav_read_pcm_frames_s16__ieee(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut) +DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__ieee(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut) { drwav_uint64 totalFramesRead; drwav_uint8 sampleData[4096]; @@ -45656,7 +45707,7 @@ static drwav_uint64 drwav_read_pcm_frames_s16__ieee(drwav* pWav, drwav_uint64 fr } return totalFramesRead; } -static drwav_uint64 drwav_read_pcm_frames_s16__alaw(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut) +DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__alaw(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut) { drwav_uint64 totalFramesRead; drwav_uint8 sampleData[4096]; @@ -45681,7 +45732,7 @@ static drwav_uint64 drwav_read_pcm_frames_s16__alaw(drwav* pWav, drwav_uint64 fr } return totalFramesRead; } -static drwav_uint64 drwav_read_pcm_frames_s16__mulaw(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut) +DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s16__mulaw(drwav* pWav, drwav_uint64 framesToRead, drwav_int16* pBufferOut) { drwav_uint64 totalFramesRead; drwav_uint8 sampleData[4096]; @@ -45826,7 +45877,7 @@ DRWAV_API void drwav_mulaw_to_s16(drwav_int16* pOut, const drwav_uint8* pIn, siz pOut[i] = drwav__mulaw_to_s16(pIn[i]); } } -static void drwav__pcm_to_f32(float* pOut, const drwav_uint8* pIn, size_t sampleCount, unsigned int bytesPerSample) +DRWAV_PRIVATE void drwav__pcm_to_f32(float* pOut, const drwav_uint8* pIn, size_t sampleCount, unsigned int bytesPerSample) { unsigned int i; if (bytesPerSample == 1) { @@ -45862,7 +45913,7 @@ static void drwav__pcm_to_f32(float* pOut, const drwav_uint8* pIn, size_t sample *pOut++ = (float)((drwav_int64)sample / 9223372036854775807.0); } } -static void drwav__ieee_to_f32(float* pOut, const drwav_uint8* pIn, size_t sampleCount, unsigned int bytesPerSample) +DRWAV_PRIVATE void drwav__ieee_to_f32(float* pOut, const drwav_uint8* pIn, size_t sampleCount, unsigned int bytesPerSample) { if (bytesPerSample == 4) { unsigned int i; @@ -45878,7 +45929,7 @@ static void drwav__ieee_to_f32(float* pOut, const drwav_uint8* pIn, size_t sampl return; } } -static drwav_uint64 drwav_read_pcm_frames_f32__pcm(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut) +DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__pcm(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut) { drwav_uint64 totalFramesRead; drwav_uint8 sampleData[4096]; @@ -45899,7 +45950,7 @@ static drwav_uint64 drwav_read_pcm_frames_f32__pcm(drwav* pWav, drwav_uint64 fra } return totalFramesRead; } -static drwav_uint64 drwav_read_pcm_frames_f32__msadpcm(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut) +DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__msadpcm(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut) { drwav_uint64 totalFramesRead = 0; drwav_int16 samples16[2048]; @@ -45915,7 +45966,7 @@ static drwav_uint64 drwav_read_pcm_frames_f32__msadpcm(drwav* pWav, drwav_uint64 } return totalFramesRead; } -static drwav_uint64 drwav_read_pcm_frames_f32__ima(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut) +DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__ima(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut) { drwav_uint64 totalFramesRead = 0; drwav_int16 samples16[2048]; @@ -45931,7 +45982,7 @@ static drwav_uint64 drwav_read_pcm_frames_f32__ima(drwav* pWav, drwav_uint64 fra } return totalFramesRead; } -static drwav_uint64 drwav_read_pcm_frames_f32__ieee(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut) +DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__ieee(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut) { drwav_uint64 totalFramesRead; drwav_uint8 sampleData[4096]; @@ -45956,7 +46007,7 @@ static drwav_uint64 drwav_read_pcm_frames_f32__ieee(drwav* pWav, drwav_uint64 fr } return totalFramesRead; } -static drwav_uint64 drwav_read_pcm_frames_f32__alaw(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut) +DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__alaw(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut) { drwav_uint64 totalFramesRead; drwav_uint8 sampleData[4096]; @@ -45977,7 +46028,7 @@ static drwav_uint64 drwav_read_pcm_frames_f32__alaw(drwav* pWav, drwav_uint64 fr } return totalFramesRead; } -static drwav_uint64 drwav_read_pcm_frames_f32__mulaw(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut) +DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_f32__mulaw(drwav* pWav, drwav_uint64 framesToRead, float* pBufferOut) { drwav_uint64 totalFramesRead; drwav_uint8 sampleData[4096]; @@ -46129,7 +46180,7 @@ DRWAV_API void drwav_mulaw_to_f32(float* pOut, const drwav_uint8* pIn, size_t sa *pOut++ = drwav__mulaw_to_s16(pIn[i]) / 32768.0f; } } -static void drwav__pcm_to_s32(drwav_int32* pOut, const drwav_uint8* pIn, size_t totalSampleCount, unsigned int bytesPerSample) +DRWAV_PRIVATE void drwav__pcm_to_s32(drwav_int32* pOut, const drwav_uint8* pIn, size_t totalSampleCount, unsigned int bytesPerSample) { unsigned int i; if (bytesPerSample == 1) { @@ -46167,7 +46218,7 @@ static void drwav__pcm_to_s32(drwav_int32* pOut, const drwav_uint8* pIn, size_t *pOut++ = (drwav_int32)((drwav_int64)sample >> 32); } } -static void drwav__ieee_to_s32(drwav_int32* pOut, const drwav_uint8* pIn, size_t totalSampleCount, unsigned int bytesPerSample) +DRWAV_PRIVATE void drwav__ieee_to_s32(drwav_int32* pOut, const drwav_uint8* pIn, size_t totalSampleCount, unsigned int bytesPerSample) { if (bytesPerSample == 4) { drwav_f32_to_s32(pOut, (const float*)pIn, totalSampleCount); @@ -46180,7 +46231,7 @@ static void drwav__ieee_to_s32(drwav_int32* pOut, const drwav_uint8* pIn, size_t return; } } -static drwav_uint64 drwav_read_pcm_frames_s32__pcm(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut) +DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__pcm(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut) { drwav_uint64 totalFramesRead; drwav_uint8 sampleData[4096]; @@ -46205,7 +46256,7 @@ static drwav_uint64 drwav_read_pcm_frames_s32__pcm(drwav* pWav, drwav_uint64 fra } return totalFramesRead; } -static drwav_uint64 drwav_read_pcm_frames_s32__msadpcm(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut) +DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__msadpcm(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut) { drwav_uint64 totalFramesRead = 0; drwav_int16 samples16[2048]; @@ -46221,7 +46272,7 @@ static drwav_uint64 drwav_read_pcm_frames_s32__msadpcm(drwav* pWav, drwav_uint64 } return totalFramesRead; } -static drwav_uint64 drwav_read_pcm_frames_s32__ima(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut) +DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__ima(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut) { drwav_uint64 totalFramesRead = 0; drwav_int16 samples16[2048]; @@ -46237,7 +46288,7 @@ static drwav_uint64 drwav_read_pcm_frames_s32__ima(drwav* pWav, drwav_uint64 fra } return totalFramesRead; } -static drwav_uint64 drwav_read_pcm_frames_s32__ieee(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut) +DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__ieee(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut) { drwav_uint64 totalFramesRead; drwav_uint8 sampleData[4096]; @@ -46258,7 +46309,7 @@ static drwav_uint64 drwav_read_pcm_frames_s32__ieee(drwav* pWav, drwav_uint64 fr } return totalFramesRead; } -static drwav_uint64 drwav_read_pcm_frames_s32__alaw(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut) +DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__alaw(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut) { drwav_uint64 totalFramesRead; drwav_uint8 sampleData[4096]; @@ -46279,7 +46330,7 @@ static drwav_uint64 drwav_read_pcm_frames_s32__alaw(drwav* pWav, drwav_uint64 fr } return totalFramesRead; } -static drwav_uint64 drwav_read_pcm_frames_s32__mulaw(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut) +DRWAV_PRIVATE drwav_uint64 drwav_read_pcm_frames_s32__mulaw(drwav* pWav, drwav_uint64 framesToRead, drwav_int32* pBufferOut) { drwav_uint64 totalFramesRead; drwav_uint8 sampleData[4096]; @@ -46421,7 +46472,7 @@ DRWAV_API void drwav_mulaw_to_s32(drwav_int32* pOut, const drwav_uint8* pIn, siz *pOut++ = ((drwav_int32)drwav__mulaw_to_s16(pIn[i])) << 16; } } -static drwav_int16* drwav__read_pcm_frames_and_close_s16(drwav* pWav, unsigned int* channels, unsigned int* sampleRate, drwav_uint64* totalFrameCount) +DRWAV_PRIVATE drwav_int16* drwav__read_pcm_frames_and_close_s16(drwav* pWav, unsigned int* channels, unsigned int* sampleRate, drwav_uint64* totalFrameCount) { drwav_uint64 sampleDataSize; drwav_int16* pSampleData; @@ -46455,7 +46506,7 @@ static drwav_int16* drwav__read_pcm_frames_and_close_s16(drwav* pWav, unsigned i } return pSampleData; } -static float* drwav__read_pcm_frames_and_close_f32(drwav* pWav, unsigned int* channels, unsigned int* sampleRate, drwav_uint64* totalFrameCount) +DRWAV_PRIVATE float* drwav__read_pcm_frames_and_close_f32(drwav* pWav, unsigned int* channels, unsigned int* sampleRate, drwav_uint64* totalFrameCount) { drwav_uint64 sampleDataSize; float* pSampleData; @@ -46489,7 +46540,7 @@ static float* drwav__read_pcm_frames_and_close_f32(drwav* pWav, unsigned int* ch } return pSampleData; } -static drwav_int32* drwav__read_pcm_frames_and_close_s32(drwav* pWav, unsigned int* channels, unsigned int* sampleRate, drwav_uint64* totalFrameCount) +DRWAV_PRIVATE drwav_int32* drwav__read_pcm_frames_and_close_s32(drwav* pWav, unsigned int* channels, unsigned int* sampleRate, drwav_uint64* totalFrameCount) { drwav_uint64 sampleDataSize; drwav_int32* pSampleData; @@ -46740,35 +46791,47 @@ DRWAV_API void drwav_free(void* p, const drwav_allocation_callbacks* pAllocation } DRWAV_API drwav_uint16 drwav_bytes_to_u16(const drwav_uint8* data) { - return drwav__bytes_to_u16(data); + return (data[0] << 0) | (data[1] << 8); } DRWAV_API drwav_int16 drwav_bytes_to_s16(const drwav_uint8* data) { - return drwav__bytes_to_s16(data); + return (short)drwav_bytes_to_u16(data); } DRWAV_API drwav_uint32 drwav_bytes_to_u32(const drwav_uint8* data) { - return drwav__bytes_to_u32(data); + return (data[0] << 0) | (data[1] << 8) | (data[2] << 16) | (data[3] << 24); } DRWAV_API drwav_int32 drwav_bytes_to_s32(const drwav_uint8* data) { - return drwav__bytes_to_s32(data); + return (drwav_int32)drwav_bytes_to_u32(data); } DRWAV_API drwav_uint64 drwav_bytes_to_u64(const drwav_uint8* data) { - return drwav__bytes_to_u64(data); + return + ((drwav_uint64)data[0] << 0) | ((drwav_uint64)data[1] << 8) | ((drwav_uint64)data[2] << 16) | ((drwav_uint64)data[3] << 24) | + ((drwav_uint64)data[4] << 32) | ((drwav_uint64)data[5] << 40) | ((drwav_uint64)data[6] << 48) | ((drwav_uint64)data[7] << 56); } DRWAV_API drwav_int64 drwav_bytes_to_s64(const drwav_uint8* data) { - return drwav__bytes_to_s64(data); + return (drwav_int64)drwav_bytes_to_u64(data); } DRWAV_API drwav_bool32 drwav_guid_equal(const drwav_uint8 a[16], const drwav_uint8 b[16]) { - return drwav__guid_equal(a, b); + int i; + for (i = 0; i < 16; i += 1) { + if (a[i] != b[i]) { + return DRWAV_FALSE; + } + } + return DRWAV_TRUE; } DRWAV_API drwav_bool32 drwav_fourcc_equal(const drwav_uint8* a, const char* b) { - return drwav__fourcc_equal(a, b); + return + a[0] == b[0] && + a[1] == b[1] && + a[2] == b[2] && + a[3] == b[3]; } #endif /* dr_wav_c end */ @@ -46790,6 +46853,9 @@ DRWAV_API drwav_bool32 drwav_fourcc_equal(const drwav_uint8* a, const char* b) #ifndef _BSD_SOURCE #define _BSD_SOURCE #endif + #ifndef _DEFAULT_SOURCE + #define _DEFAULT_SOURCE + #endif #ifndef __USE_BSD #define __USE_BSD #endif diff --git a/extras/miniaudio_split/miniaudio.h b/extras/miniaudio_split/miniaudio.h index 5ad2e1e7..fa2648b7 100644 --- a/extras/miniaudio_split/miniaudio.h +++ b/extras/miniaudio_split/miniaudio.h @@ -1,6 +1,6 @@ /* Audio playback and capture library. Choice of public domain or MIT-0. See license statements at the end of this file. -miniaudio - v0.10.30 - 2021-01-10 +miniaudio - v0.10.31 - 2020-01-17 David Reid - mackron@gmail.com @@ -20,7 +20,7 @@ extern "C" { #define MA_VERSION_MAJOR 0 #define MA_VERSION_MINOR 10 -#define MA_VERSION_REVISION 30 +#define MA_VERSION_REVISION 31 #define MA_VERSION_STRING MA_XSTRINGIFY(MA_VERSION_MAJOR) "." MA_XSTRINGIFY(MA_VERSION_MINOR) "." MA_XSTRINGIFY(MA_VERSION_REVISION) #if defined(_MSC_VER) && !defined(__clang__) @@ -213,6 +213,12 @@ MA_LOG_LEVEL_ERROR #define MA_LOG_LEVEL MA_LOG_LEVEL_ERROR #endif +/* +An annotation for variables which must be used atomically. This doesn't actually do anything - it's +just used as a way for humans to identify variables that should be used atomically. +*/ +#define MA_ATOMIC + typedef struct ma_context ma_context; typedef struct ma_device ma_device; @@ -569,7 +575,7 @@ typedef struct MA_API ma_result ma_biquad_init(const ma_biquad_config* pConfig, ma_biquad* pBQ); MA_API ma_result ma_biquad_reinit(const ma_biquad_config* pConfig, ma_biquad* pBQ); MA_API ma_result ma_biquad_process_pcm_frames(ma_biquad* pBQ, void* pFramesOut, const void* pFramesIn, ma_uint64 frameCount); -MA_API ma_uint32 ma_biquad_get_latency(ma_biquad* pBQ); +MA_API ma_uint32 ma_biquad_get_latency(const ma_biquad* pBQ); /************************************************************************************************************************************************************** @@ -600,7 +606,7 @@ typedef struct MA_API ma_result ma_lpf1_init(const ma_lpf1_config* pConfig, ma_lpf1* pLPF); MA_API ma_result ma_lpf1_reinit(const ma_lpf1_config* pConfig, ma_lpf1* pLPF); MA_API ma_result ma_lpf1_process_pcm_frames(ma_lpf1* pLPF, void* pFramesOut, const void* pFramesIn, ma_uint64 frameCount); -MA_API ma_uint32 ma_lpf1_get_latency(ma_lpf1* pLPF); +MA_API ma_uint32 ma_lpf1_get_latency(const ma_lpf1* pLPF); typedef struct { @@ -610,7 +616,7 @@ typedef struct MA_API ma_result ma_lpf2_init(const ma_lpf2_config* pConfig, ma_lpf2* pLPF); MA_API ma_result ma_lpf2_reinit(const ma_lpf2_config* pConfig, ma_lpf2* pLPF); MA_API ma_result ma_lpf2_process_pcm_frames(ma_lpf2* pLPF, void* pFramesOut, const void* pFramesIn, ma_uint64 frameCount); -MA_API ma_uint32 ma_lpf2_get_latency(ma_lpf2* pLPF); +MA_API ma_uint32 ma_lpf2_get_latency(const ma_lpf2* pLPF); typedef struct @@ -638,7 +644,7 @@ typedef struct MA_API ma_result ma_lpf_init(const ma_lpf_config* pConfig, ma_lpf* pLPF); MA_API ma_result ma_lpf_reinit(const ma_lpf_config* pConfig, ma_lpf* pLPF); MA_API ma_result ma_lpf_process_pcm_frames(ma_lpf* pLPF, void* pFramesOut, const void* pFramesIn, ma_uint64 frameCount); -MA_API ma_uint32 ma_lpf_get_latency(ma_lpf* pLPF); +MA_API ma_uint32 ma_lpf_get_latency(const ma_lpf* pLPF); /************************************************************************************************************************************************************** @@ -669,7 +675,7 @@ typedef struct MA_API ma_result ma_hpf1_init(const ma_hpf1_config* pConfig, ma_hpf1* pHPF); MA_API ma_result ma_hpf1_reinit(const ma_hpf1_config* pConfig, ma_hpf1* pHPF); MA_API ma_result ma_hpf1_process_pcm_frames(ma_hpf1* pHPF, void* pFramesOut, const void* pFramesIn, ma_uint64 frameCount); -MA_API ma_uint32 ma_hpf1_get_latency(ma_hpf1* pHPF); +MA_API ma_uint32 ma_hpf1_get_latency(const ma_hpf1* pHPF); typedef struct { @@ -679,7 +685,7 @@ typedef struct MA_API ma_result ma_hpf2_init(const ma_hpf2_config* pConfig, ma_hpf2* pHPF); MA_API ma_result ma_hpf2_reinit(const ma_hpf2_config* pConfig, ma_hpf2* pHPF); MA_API ma_result ma_hpf2_process_pcm_frames(ma_hpf2* pHPF, void* pFramesOut, const void* pFramesIn, ma_uint64 frameCount); -MA_API ma_uint32 ma_hpf2_get_latency(ma_hpf2* pHPF); +MA_API ma_uint32 ma_hpf2_get_latency(const ma_hpf2* pHPF); typedef struct @@ -707,7 +713,7 @@ typedef struct MA_API ma_result ma_hpf_init(const ma_hpf_config* pConfig, ma_hpf* pHPF); MA_API ma_result ma_hpf_reinit(const ma_hpf_config* pConfig, ma_hpf* pHPF); MA_API ma_result ma_hpf_process_pcm_frames(ma_hpf* pHPF, void* pFramesOut, const void* pFramesIn, ma_uint64 frameCount); -MA_API ma_uint32 ma_hpf_get_latency(ma_hpf* pHPF); +MA_API ma_uint32 ma_hpf_get_latency(const ma_hpf* pHPF); /************************************************************************************************************************************************************** @@ -734,7 +740,7 @@ typedef struct MA_API ma_result ma_bpf2_init(const ma_bpf2_config* pConfig, ma_bpf2* pBPF); MA_API ma_result ma_bpf2_reinit(const ma_bpf2_config* pConfig, ma_bpf2* pBPF); MA_API ma_result ma_bpf2_process_pcm_frames(ma_bpf2* pBPF, void* pFramesOut, const void* pFramesIn, ma_uint64 frameCount); -MA_API ma_uint32 ma_bpf2_get_latency(ma_bpf2* pBPF); +MA_API ma_uint32 ma_bpf2_get_latency(const ma_bpf2* pBPF); typedef struct @@ -759,7 +765,7 @@ typedef struct MA_API ma_result ma_bpf_init(const ma_bpf_config* pConfig, ma_bpf* pBPF); MA_API ma_result ma_bpf_reinit(const ma_bpf_config* pConfig, ma_bpf* pBPF); MA_API ma_result ma_bpf_process_pcm_frames(ma_bpf* pBPF, void* pFramesOut, const void* pFramesIn, ma_uint64 frameCount); -MA_API ma_uint32 ma_bpf_get_latency(ma_bpf* pBPF); +MA_API ma_uint32 ma_bpf_get_latency(const ma_bpf* pBPF); /************************************************************************************************************************************************************** @@ -786,7 +792,7 @@ typedef struct MA_API ma_result ma_notch2_init(const ma_notch2_config* pConfig, ma_notch2* pFilter); MA_API ma_result ma_notch2_reinit(const ma_notch2_config* pConfig, ma_notch2* pFilter); MA_API ma_result ma_notch2_process_pcm_frames(ma_notch2* pFilter, void* pFramesOut, const void* pFramesIn, ma_uint64 frameCount); -MA_API ma_uint32 ma_notch2_get_latency(ma_notch2* pFilter); +MA_API ma_uint32 ma_notch2_get_latency(const ma_notch2* pFilter); /************************************************************************************************************************************************************** @@ -814,7 +820,7 @@ typedef struct MA_API ma_result ma_peak2_init(const ma_peak2_config* pConfig, ma_peak2* pFilter); MA_API ma_result ma_peak2_reinit(const ma_peak2_config* pConfig, ma_peak2* pFilter); MA_API ma_result ma_peak2_process_pcm_frames(ma_peak2* pFilter, void* pFramesOut, const void* pFramesIn, ma_uint64 frameCount); -MA_API ma_uint32 ma_peak2_get_latency(ma_peak2* pFilter); +MA_API ma_uint32 ma_peak2_get_latency(const ma_peak2* pFilter); /************************************************************************************************************************************************************** @@ -842,7 +848,7 @@ typedef struct MA_API ma_result ma_loshelf2_init(const ma_loshelf2_config* pConfig, ma_loshelf2* pFilter); MA_API ma_result ma_loshelf2_reinit(const ma_loshelf2_config* pConfig, ma_loshelf2* pFilter); MA_API ma_result ma_loshelf2_process_pcm_frames(ma_loshelf2* pFilter, void* pFramesOut, const void* pFramesIn, ma_uint64 frameCount); -MA_API ma_uint32 ma_loshelf2_get_latency(ma_loshelf2* pFilter); +MA_API ma_uint32 ma_loshelf2_get_latency(const ma_loshelf2* pFilter); /************************************************************************************************************************************************************** @@ -870,7 +876,7 @@ typedef struct MA_API ma_result ma_hishelf2_init(const ma_hishelf2_config* pConfig, ma_hishelf2* pFilter); MA_API ma_result ma_hishelf2_reinit(const ma_hishelf2_config* pConfig, ma_hishelf2* pFilter); MA_API ma_result ma_hishelf2_process_pcm_frames(ma_hishelf2* pFilter, void* pFramesOut, const void* pFramesIn, ma_uint64 frameCount); -MA_API ma_uint32 ma_hishelf2_get_latency(ma_hishelf2* pFilter); +MA_API ma_uint32 ma_hishelf2_get_latency(const ma_hishelf2* pFilter); @@ -927,10 +933,10 @@ MA_API void ma_linear_resampler_uninit(ma_linear_resampler* pResampler); MA_API ma_result ma_linear_resampler_process_pcm_frames(ma_linear_resampler* pResampler, const void* pFramesIn, ma_uint64* pFrameCountIn, void* pFramesOut, ma_uint64* pFrameCountOut); MA_API ma_result ma_linear_resampler_set_rate(ma_linear_resampler* pResampler, ma_uint32 sampleRateIn, ma_uint32 sampleRateOut); MA_API ma_result ma_linear_resampler_set_rate_ratio(ma_linear_resampler* pResampler, float ratioInOut); -MA_API ma_uint64 ma_linear_resampler_get_required_input_frame_count(ma_linear_resampler* pResampler, ma_uint64 outputFrameCount); -MA_API ma_uint64 ma_linear_resampler_get_expected_output_frame_count(ma_linear_resampler* pResampler, ma_uint64 inputFrameCount); -MA_API ma_uint64 ma_linear_resampler_get_input_latency(ma_linear_resampler* pResampler); -MA_API ma_uint64 ma_linear_resampler_get_output_latency(ma_linear_resampler* pResampler); +MA_API ma_uint64 ma_linear_resampler_get_required_input_frame_count(const ma_linear_resampler* pResampler, ma_uint64 outputFrameCount); +MA_API ma_uint64 ma_linear_resampler_get_expected_output_frame_count(const ma_linear_resampler* pResampler, ma_uint64 inputFrameCount); +MA_API ma_uint64 ma_linear_resampler_get_input_latency(const ma_linear_resampler* pResampler); +MA_API ma_uint64 ma_linear_resampler_get_output_latency(const ma_linear_resampler* pResampler); typedef enum { @@ -1026,24 +1032,24 @@ number of output frames. The returned value does not include cached input frames. It only returns the number of extra frames that would need to be read from the input buffer in order to output the specified number of output frames. */ -MA_API ma_uint64 ma_resampler_get_required_input_frame_count(ma_resampler* pResampler, ma_uint64 outputFrameCount); +MA_API ma_uint64 ma_resampler_get_required_input_frame_count(const ma_resampler* pResampler, ma_uint64 outputFrameCount); /* Calculates the number of whole output frames that would be output after fully reading and consuming the specified number of input frames. */ -MA_API ma_uint64 ma_resampler_get_expected_output_frame_count(ma_resampler* pResampler, ma_uint64 inputFrameCount); +MA_API ma_uint64 ma_resampler_get_expected_output_frame_count(const ma_resampler* pResampler, ma_uint64 inputFrameCount); /* Retrieves the latency introduced by the resampler in input frames. */ -MA_API ma_uint64 ma_resampler_get_input_latency(ma_resampler* pResampler); +MA_API ma_uint64 ma_resampler_get_input_latency(const ma_resampler* pResampler); /* Retrieves the latency introduced by the resampler in output frames. */ -MA_API ma_uint64 ma_resampler_get_output_latency(ma_resampler* pResampler); +MA_API ma_uint64 ma_resampler_get_output_latency(const ma_resampler* pResampler); @@ -1144,10 +1150,10 @@ MA_API void ma_data_converter_uninit(ma_data_converter* pConverter); MA_API ma_result ma_data_converter_process_pcm_frames(ma_data_converter* pConverter, const void* pFramesIn, ma_uint64* pFrameCountIn, void* pFramesOut, ma_uint64* pFrameCountOut); MA_API ma_result ma_data_converter_set_rate(ma_data_converter* pConverter, ma_uint32 sampleRateIn, ma_uint32 sampleRateOut); MA_API ma_result ma_data_converter_set_rate_ratio(ma_data_converter* pConverter, float ratioInOut); -MA_API ma_uint64 ma_data_converter_get_required_input_frame_count(ma_data_converter* pConverter, ma_uint64 outputFrameCount); -MA_API ma_uint64 ma_data_converter_get_expected_output_frame_count(ma_data_converter* pConverter, ma_uint64 inputFrameCount); -MA_API ma_uint64 ma_data_converter_get_input_latency(ma_data_converter* pConverter); -MA_API ma_uint64 ma_data_converter_get_output_latency(ma_data_converter* pConverter); +MA_API ma_uint64 ma_data_converter_get_required_input_frame_count(const ma_data_converter* pConverter, ma_uint64 outputFrameCount); +MA_API ma_uint64 ma_data_converter_get_expected_output_frame_count(const ma_data_converter* pConverter, ma_uint64 inputFrameCount); +MA_API ma_uint64 ma_data_converter_get_input_latency(const ma_data_converter* pConverter); +MA_API ma_uint64 ma_data_converter_get_output_latency(const ma_data_converter* pConverter); /************************************************************************************************************************************************************ @@ -1292,10 +1298,10 @@ typedef struct ma_uint32 subbufferSizeInBytes; ma_uint32 subbufferCount; ma_uint32 subbufferStrideInBytes; - volatile ma_uint32 encodedReadOffset; /* Most significant bit is the loop flag. Lower 31 bits contains the actual offset in bytes. */ - volatile ma_uint32 encodedWriteOffset; /* Most significant bit is the loop flag. Lower 31 bits contains the actual offset in bytes. */ - ma_bool8 ownsBuffer; /* Used to know whether or not miniaudio is responsible for free()-ing the buffer. */ - ma_bool8 clearOnWriteAcquire; /* When set, clears the acquired write buffer before returning from ma_rb_acquire_write(). */ + MA_ATOMIC ma_uint32 encodedReadOffset; /* Most significant bit is the loop flag. Lower 31 bits contains the actual offset in bytes. Must be used atomically. */ + MA_ATOMIC ma_uint32 encodedWriteOffset; /* Most significant bit is the loop flag. Lower 31 bits contains the actual offset in bytes. Must be used atomically. */ + ma_bool8 ownsBuffer; /* Used to know whether or not miniaudio is responsible for free()-ing the buffer. */ + ma_bool8 clearOnWriteAcquire; /* When set, clears the acquired write buffer before returning from ma_rb_acquire_write(). */ ma_allocation_callbacks allocationCallbacks; } ma_rb; @@ -1486,50 +1492,50 @@ This section contains the APIs for device playback and capture. Here is where yo #endif -#if !defined(MA_NO_WASAPI) && defined(MA_SUPPORT_WASAPI) - #define MA_ENABLE_WASAPI +#if defined(MA_SUPPORT_WASAPI) && !defined(MA_NO_WASAPI) && (!defined(MA_ENABLE_ONLY_SPECIFIC_BACKENDS) || defined(MA_ENABLE_WASAPI)) + #define MA_HAS_WASAPI #endif -#if !defined(MA_NO_DSOUND) && defined(MA_SUPPORT_DSOUND) - #define MA_ENABLE_DSOUND +#if defined(MA_SUPPORT_DSOUND) && !defined(MA_NO_DSOUND) && (!defined(MA_ENABLE_ONLY_SPECIFIC_BACKENDS) || defined(MA_ENABLE_DSOUND)) + #define MA_HAS_DSOUND #endif -#if !defined(MA_NO_WINMM) && defined(MA_SUPPORT_WINMM) - #define MA_ENABLE_WINMM +#if defined(MA_SUPPORT_WINMM) && !defined(MA_NO_WINMM) && (!defined(MA_ENABLE_ONLY_SPECIFIC_BACKENDS) || defined(MA_ENABLE_WINMM)) + #define MA_HAS_WINMM #endif -#if !defined(MA_NO_ALSA) && defined(MA_SUPPORT_ALSA) - #define MA_ENABLE_ALSA +#if defined(MA_SUPPORT_ALSA) && !defined(MA_NO_ALSA) && (!defined(MA_ENABLE_ONLY_SPECIFIC_BACKENDS) || defined(MA_ENABLE_ALSA)) + #define MA_HAS_ALSA #endif -#if !defined(MA_NO_PULSEAUDIO) && defined(MA_SUPPORT_PULSEAUDIO) - #define MA_ENABLE_PULSEAUDIO +#if defined(MA_SUPPORT_PULSEAUDIO) && !defined(MA_NO_PULSEAUDIO) && (!defined(MA_ENABLE_ONLY_SPECIFIC_BACKENDS) || defined(MA_ENABLE_PULSEAUDIO)) + #define MA_HAS_PULSEAUDIO #endif -#if !defined(MA_NO_JACK) && defined(MA_SUPPORT_JACK) - #define MA_ENABLE_JACK +#if defined(MA_SUPPORT_JACK) && !defined(MA_NO_JACK) && (!defined(MA_ENABLE_ONLY_SPECIFIC_BACKENDS) || defined(MA_ENABLE_JACK)) + #define MA_HAS_JACK #endif -#if !defined(MA_NO_COREAUDIO) && defined(MA_SUPPORT_COREAUDIO) - #define MA_ENABLE_COREAUDIO +#if defined(MA_SUPPORT_COREAUDIO) && !defined(MA_NO_COREAUDIO) && (!defined(MA_ENABLE_ONLY_SPECIFIC_BACKENDS) || defined(MA_ENABLE_COREAUDIO)) + #define MA_HAS_COREAUDIO #endif -#if !defined(MA_NO_SNDIO) && defined(MA_SUPPORT_SNDIO) - #define MA_ENABLE_SNDIO +#if defined(MA_SUPPORT_SNDIO) && !defined(MA_NO_SNDIO) && (!defined(MA_ENABLE_ONLY_SPECIFIC_BACKENDS) || defined(MA_ENABLE_SNDIO)) + #define MA_HAS_SNDIO #endif -#if !defined(MA_NO_AUDIO4) && defined(MA_SUPPORT_AUDIO4) - #define MA_ENABLE_AUDIO4 +#if defined(MA_SUPPORT_AUDIO4) && !defined(MA_NO_AUDIO4) && (!defined(MA_ENABLE_ONLY_SPECIFIC_BACKENDS) || defined(MA_ENABLE_AUDIO4)) + #define MA_HAS_AUDIO4 #endif -#if !defined(MA_NO_OSS) && defined(MA_SUPPORT_OSS) - #define MA_ENABLE_OSS +#if defined(MA_SUPPORT_OSS) && !defined(MA_NO_OSS) && (!defined(MA_ENABLE_ONLY_SPECIFIC_BACKENDS) || defined(MA_ENABLE_OSS)) + #define MA_HAS_OSS #endif -#if !defined(MA_NO_AAUDIO) && defined(MA_SUPPORT_AAUDIO) - #define MA_ENABLE_AAUDIO +#if defined(MA_SUPPORT_AAUDIO) && !defined(MA_NO_AAUDIO) && (!defined(MA_ENABLE_ONLY_SPECIFIC_BACKENDS) || defined(MA_ENABLE_AAUDIO)) + #define MA_HAS_AAUDIO #endif -#if !defined(MA_NO_OPENSL) && defined(MA_SUPPORT_OPENSL) - #define MA_ENABLE_OPENSL +#if defined(MA_SUPPORT_OPENSL) && !defined(MA_NO_OPENSL) && (!defined(MA_ENABLE_ONLY_SPECIFIC_BACKENDS) || defined(MA_ENABLE_OPENSL)) + #define MA_HAS_OPENSL #endif -#if !defined(MA_NO_WEBAUDIO) && defined(MA_SUPPORT_WEBAUDIO) - #define MA_ENABLE_WEBAUDIO +#if defined(MA_SUPPORT_WEBAUDIO) && !defined(MA_NO_WEBAUDIO) && (!defined(MA_ENABLE_ONLY_SPECIFIC_BACKENDS) || defined(MA_ENABLE_WEBAUDIO)) + #define MA_HAS_WEBAUDIO #endif -#if !defined(MA_NO_CUSTOM) && defined(MA_SUPPORT_CUSTOM) - #define MA_ENABLE_CUSTOM +#if defined(MA_SUPPORT_CUSTOM) && !defined(MA_NO_CUSTOM) && (!defined(MA_ENABLE_ONLY_SPECIFIC_BACKENDS) || defined(MA_ENABLE_CUSTOM)) + #define MA_HAS_CUSTOM #endif -#if !defined(MA_NO_NULL) && defined(MA_SUPPORT_NULL) - #define MA_ENABLE_NULL +#if defined(MA_SUPPORT_NULL) && !defined(MA_NO_NULL) && (!defined(MA_ENABLE_ONLY_SPECIFIC_BACKENDS) || defined(MA_ENABLE_NULL)) + #define MA_HAS_NULL #endif #define MA_STATE_UNINITIALIZED 0 @@ -2481,7 +2487,7 @@ struct ma_device ma_context* pContext; ma_device_type type; ma_uint32 sampleRate; - volatile ma_uint32 state; /* The state of the device is variable and can change at any time on any thread, so tell the compiler as such with `volatile`. */ + MA_ATOMIC ma_uint32 state; /* The state of the device is variable and can change at any time on any thread. Must be used atomically. */ ma_device_callback_proc onData; /* Set once at initialization time and should not be changed after. */ ma_stop_proc onStop; /* Set once at initialization time and should not be changed after. */ void* pUserData; /* Application defined data. */ @@ -2497,7 +2503,7 @@ struct ma_device ma_bool8 isOwnerOfContext; /* When set to true, uninitializing the device will also uninitialize the context. Set to true when NULL is passed into ma_device_init(). */ ma_bool8 noPreZeroedOutputBuffer; ma_bool8 noClip; - volatile float masterVolumeFactor; /* Volatile so we can use some thread safety when applying volume to periods. */ + MA_ATOMIC float masterVolumeFactor; /* Linear 0..1. Can be read and written simultaneously by different threads. Must be used atomically. */ ma_duplex_rb duplexRB; /* Intermediary buffer for duplex device on asynchronous backends. */ struct { @@ -2561,24 +2567,24 @@ struct ma_device /*IAudioClient**/ ma_ptr pAudioClientCapture; /*IAudioRenderClient**/ ma_ptr pRenderClient; /*IAudioCaptureClient**/ ma_ptr pCaptureClient; - /*IMMDeviceEnumerator**/ ma_ptr pDeviceEnumerator; /* Used for IMMNotificationClient notifications. Required for detecting default device changes. */ + /*IMMDeviceEnumerator**/ ma_ptr pDeviceEnumerator; /* Used for IMMNotificationClient notifications. Required for detecting default device changes. */ ma_IMMNotificationClient notificationClient; - /*HANDLE*/ ma_handle hEventPlayback; /* Auto reset. Initialized to signaled. */ - /*HANDLE*/ ma_handle hEventCapture; /* Auto reset. Initialized to unsignaled. */ - ma_uint32 actualPeriodSizeInFramesPlayback; /* Value from GetBufferSize(). internalPeriodSizeInFrames is not set to the _actual_ buffer size when low-latency shared mode is being used due to the way the IAudioClient3 API works. */ + /*HANDLE*/ ma_handle hEventPlayback; /* Auto reset. Initialized to signaled. */ + /*HANDLE*/ ma_handle hEventCapture; /* Auto reset. Initialized to unsignaled. */ + ma_uint32 actualPeriodSizeInFramesPlayback; /* Value from GetBufferSize(). internalPeriodSizeInFrames is not set to the _actual_ buffer size when low-latency shared mode is being used due to the way the IAudioClient3 API works. */ ma_uint32 actualPeriodSizeInFramesCapture; ma_uint32 originalPeriodSizeInFrames; ma_uint32 originalPeriodSizeInMilliseconds; ma_uint32 originalPeriods; ma_performance_profile originalPerformanceProfile; - volatile ma_bool32 hasDefaultPlaybackDeviceChanged; /* <-- Make sure this is always a whole 32-bits because we use atomic assignments. */ - volatile ma_bool32 hasDefaultCaptureDeviceChanged; /* <-- Make sure this is always a whole 32-bits because we use atomic assignments. */ ma_uint32 periodSizeInFramesPlayback; ma_uint32 periodSizeInFramesCapture; - volatile ma_bool32 isStartedCapture; /* <-- Make sure this is always a whole 32-bits because we use atomic assignments. */ - volatile ma_bool32 isStartedPlayback; /* <-- Make sure this is always a whole 32-bits because we use atomic assignments. */ - ma_bool8 noAutoConvertSRC; /* When set to true, disables the use of AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM. */ - ma_bool8 noDefaultQualitySRC; /* When set to true, disables the use of AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY. */ + MA_ATOMIC ma_bool8 hasDefaultPlaybackDeviceChanged; /* Can be read and written simultaneously across different threads. Must be used atomically. */ + MA_ATOMIC ma_bool8 hasDefaultCaptureDeviceChanged; /* Can be read and written simultaneously across different threads. Must be used atomically. */ + MA_ATOMIC ma_bool8 isStartedCapture; /* Can be read and written simultaneously across different threads. Must be used atomically. */ + MA_ATOMIC ma_bool8 isStartedPlayback; /* Can be read and written simultaneously across different threads. Must be used atomically. */ + ma_bool8 noAutoConvertSRC; /* When set to true, disables the use of AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM. */ + ma_bool8 noDefaultQualitySRC; /* When set to true, disables the use of AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY. */ ma_bool8 noHardwareOffloading; ma_bool8 allowCaptureAutoStreamRouting; ma_bool8 allowPlaybackAutoStreamRouting; @@ -2727,14 +2733,14 @@ struct ma_device ma_event operationCompletionEvent; ma_semaphore operationSemaphore; ma_uint32 operation; - volatile ma_result operationResult; + ma_result operationResult; ma_timer timer; double priorRunTime; ma_uint32 currentPeriodFramesRemainingPlayback; ma_uint32 currentPeriodFramesRemainingCapture; ma_uint64 lastProcessedFramePlayback; ma_uint64 lastProcessedFrameCapture; - volatile ma_bool32 isStarted; + MA_ATOMIC ma_bool8 isStarted; /* Read and written by multiple threads. Must be used atomically. */ } null_device; #endif }; @@ -4316,6 +4322,29 @@ MA_API ma_result ma_data_source_get_cursor_in_pcm_frames(ma_data_source* pDataSo MA_API ma_result ma_data_source_get_length_in_pcm_frames(ma_data_source* pDataSource, ma_uint64* pLength); /* Returns MA_NOT_IMPLEMENTED if the length is unknown or cannot be determined. Decoders can return this. */ + + +typedef struct +{ + ma_data_source_callbacks ds; + ma_format format; + ma_uint32 channels; + ma_uint64 cursor; + ma_uint64 sizeInFrames; + const void* pData; +} ma_audio_buffer_ref; + +MA_API ma_result ma_audio_buffer_ref_init(ma_format format, ma_uint32 channels, const void* pData, ma_uint64 sizeInFrames, ma_audio_buffer_ref* pAudioBufferRef); +MA_API ma_result ma_audio_buffer_ref_set_data(ma_audio_buffer_ref* pAudioBufferRef, const void* pData, ma_uint64 sizeInFrames); +MA_API ma_uint64 ma_audio_buffer_ref_read_pcm_frames(ma_audio_buffer_ref* pAudioBufferRef, void* pFramesOut, ma_uint64 frameCount, ma_bool32 loop); +MA_API ma_result ma_audio_buffer_ref_seek_to_pcm_frame(ma_audio_buffer_ref* pAudioBufferRef, ma_uint64 frameIndex); +MA_API ma_result ma_audio_buffer_ref_map(ma_audio_buffer_ref* pAudioBufferRef, void** ppFramesOut, ma_uint64* pFrameCount); +MA_API ma_result ma_audio_buffer_ref_unmap(ma_audio_buffer_ref* pAudioBufferRef, ma_uint64 frameCount); /* Returns MA_AT_END if the end has been reached. This should be considered successful. */ +MA_API ma_result ma_audio_buffer_ref_at_end(ma_audio_buffer_ref* pAudioBufferRef); +MA_API ma_result ma_audio_buffer_ref_get_available_frames(ma_audio_buffer_ref* pAudioBufferRef, ma_uint64* pAvailableFrames); + + + typedef struct { ma_format format; @@ -4329,12 +4358,7 @@ MA_API ma_audio_buffer_config ma_audio_buffer_config_init(ma_format format, ma_u typedef struct { - ma_data_source_callbacks ds; - ma_format format; - ma_uint32 channels; - ma_uint64 cursor; - ma_uint64 sizeInFrames; - const void* pData; + ma_audio_buffer_ref ref; ma_allocation_callbacks allocationCallbacks; ma_bool32 ownsData; /* Used to control whether or not miniaudio owns the data buffer. If set to true, pData will be freed in ma_audio_buffer_uninit(). */ ma_uint8 _pExtraData[1]; /* For allocating a buffer with the memory located directly after the other memory of the structure. */ diff --git a/miniaudio.h b/miniaudio.h index 48135db2..08cc9ee9 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -1,6 +1,6 @@ /* Audio playback and capture library. Choice of public domain or MIT-0. See license statements at the end of this file. -miniaudio - v0.10.31 - TBD +miniaudio - v0.10.31 - 2020-01-17 David Reid - mackron@gmail.com @@ -64828,7 +64828,7 @@ The following miscellaneous changes have also been made. /* REVISION HISTORY ================ -v0.10.31 - TBD +v0.10.31 - 2020-01-17 - Make some functions const correct. - Update ma_data_source_read_pcm_frames() to initialize pFramesRead to 0 for safety. - Add the MA_ATOMIC annotation for use with variables that should be used atomically and remove unnecessary volatile qualifiers.