Add support for preallocation for biquad filters.

This commit is contained in:
David Reid
2021-07-25 09:26:16 +10:00
parent ccc01563ba
commit ebbeebc857
+302 -22
View File
@@ -3097,6 +3097,8 @@ typedef struct
ma_biquad bq; /* The second order low-pass filter is implemented as a biquad filter. */ ma_biquad bq; /* The second order low-pass filter is implemented as a biquad filter. */
} ma_lpf2; } ma_lpf2;
MA_API ma_result ma_lpf2_get_heap_size(const ma_lpf2_config* pConfig, size_t* pHeapSizeInBytes);
MA_API ma_result ma_lpf2_init_preallocated(const ma_lpf2_config* pConfig, void* pHeap, ma_lpf2* pHPF);
MA_API ma_result ma_lpf2_init(const ma_lpf2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_lpf2* pLPF); MA_API ma_result ma_lpf2_init(const ma_lpf2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_lpf2* pLPF);
MA_API void ma_lpf2_uninit(ma_lpf2* pLPF, const ma_allocation_callbacks* pAllocationCallbacks); MA_API void ma_lpf2_uninit(ma_lpf2* pLPF, const ma_allocation_callbacks* pAllocationCallbacks);
MA_API ma_result ma_lpf2_reinit(const ma_lpf2_config* pConfig, ma_lpf2* pLPF); MA_API ma_result ma_lpf2_reinit(const ma_lpf2_config* pConfig, ma_lpf2* pLPF);
@@ -3169,6 +3171,8 @@ typedef struct
ma_biquad bq; /* The second order high-pass filter is implemented as a biquad filter. */ ma_biquad bq; /* The second order high-pass filter is implemented as a biquad filter. */
} ma_hpf2; } ma_hpf2;
MA_API ma_result ma_hpf2_get_heap_size(const ma_hpf2_config* pConfig, size_t* pHeapSizeInBytes);
MA_API ma_result ma_hpf2_init_preallocated(const ma_hpf2_config* pConfig, void* pHeap, ma_hpf2* pHPF);
MA_API ma_result ma_hpf2_init(const ma_hpf2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_hpf2* pHPF); MA_API ma_result ma_hpf2_init(const ma_hpf2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_hpf2* pHPF);
MA_API void ma_hpf2_uninit(ma_hpf2* pHPF, const ma_allocation_callbacks* pAllocationCallbacks); MA_API void ma_hpf2_uninit(ma_hpf2* pHPF, const ma_allocation_callbacks* pAllocationCallbacks);
MA_API ma_result ma_hpf2_reinit(const ma_hpf2_config* pConfig, ma_hpf2* pHPF); MA_API ma_result ma_hpf2_reinit(const ma_hpf2_config* pConfig, ma_hpf2* pHPF);
@@ -3226,6 +3230,8 @@ typedef struct
ma_biquad bq; /* The second order band-pass filter is implemented as a biquad filter. */ ma_biquad bq; /* The second order band-pass filter is implemented as a biquad filter. */
} ma_bpf2; } ma_bpf2;
MA_API ma_result ma_bpf2_get_heap_size(const ma_bpf2_config* pConfig, size_t* pHeapSizeInBytes);
MA_API ma_result ma_bpf2_init_preallocated(const ma_bpf2_config* pConfig, void* pHeap, ma_bpf2* pBPF);
MA_API ma_result ma_bpf2_init(const ma_bpf2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_bpf2* pBPF); MA_API ma_result ma_bpf2_init(const ma_bpf2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_bpf2* pBPF);
MA_API void ma_bpf2_uninit(ma_bpf2* pBPF, const ma_allocation_callbacks* pAllocationCallbacks); MA_API void ma_bpf2_uninit(ma_bpf2* pBPF, const ma_allocation_callbacks* pAllocationCallbacks);
MA_API ma_result ma_bpf2_reinit(const ma_bpf2_config* pConfig, ma_bpf2* pBPF); MA_API ma_result ma_bpf2_reinit(const ma_bpf2_config* pConfig, ma_bpf2* pBPF);
@@ -3280,6 +3286,8 @@ typedef struct
ma_biquad bq; ma_biquad bq;
} ma_notch2; } ma_notch2;
MA_API ma_result ma_notch2_get_heap_size(const ma_notch2_config* pConfig, size_t* pHeapSizeInBytes);
MA_API ma_result ma_notch2_init_preallocated(const ma_notch2_config* pConfig, void* pHeap, ma_notch2* pFilter);
MA_API ma_result ma_notch2_init(const ma_notch2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_notch2* pFilter); MA_API ma_result ma_notch2_init(const ma_notch2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_notch2* pFilter);
MA_API void ma_notch2_uninit(ma_notch2* pFilter, const ma_allocation_callbacks* pAllocationCallbacks); MA_API void ma_notch2_uninit(ma_notch2* pFilter, const ma_allocation_callbacks* pAllocationCallbacks);
MA_API ma_result ma_notch2_reinit(const ma_notch2_config* pConfig, ma_notch2* pFilter); MA_API ma_result ma_notch2_reinit(const ma_notch2_config* pConfig, ma_notch2* pFilter);
@@ -3309,6 +3317,8 @@ typedef struct
ma_biquad bq; ma_biquad bq;
} ma_peak2; } ma_peak2;
MA_API ma_result ma_peak2_get_heap_size(const ma_peak2_config* pConfig, size_t* pHeapSizeInBytes);
MA_API ma_result ma_peak2_init_preallocated(const ma_peak2_config* pConfig, void* pHeap, ma_peak2* pFilter);
MA_API ma_result ma_peak2_init(const ma_peak2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_peak2* pFilter); MA_API ma_result ma_peak2_init(const ma_peak2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_peak2* pFilter);
MA_API void ma_peak2_uninit(ma_peak2* pFilter, const ma_allocation_callbacks* pAllocationCallbacks); MA_API void ma_peak2_uninit(ma_peak2* pFilter, const ma_allocation_callbacks* pAllocationCallbacks);
MA_API ma_result ma_peak2_reinit(const ma_peak2_config* pConfig, ma_peak2* pFilter); MA_API ma_result ma_peak2_reinit(const ma_peak2_config* pConfig, ma_peak2* pFilter);
@@ -3338,6 +3348,8 @@ typedef struct
ma_biquad bq; ma_biquad bq;
} ma_loshelf2; } ma_loshelf2;
MA_API ma_result ma_loshelf2_get_heap_size(const ma_loshelf2_config* pConfig, size_t* pHeapSizeInBytes);
MA_API ma_result ma_loshelf2_init_preallocated(const ma_loshelf2_config* pConfig, void* pHeap, ma_loshelf2* pFilter);
MA_API ma_result ma_loshelf2_init(const ma_loshelf2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_loshelf2* pFilter); MA_API ma_result ma_loshelf2_init(const ma_loshelf2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_loshelf2* pFilter);
MA_API void ma_loshelf2_uninit(ma_loshelf2* pFilter, const ma_allocation_callbacks* pAllocationCallbacks); MA_API void ma_loshelf2_uninit(ma_loshelf2* pFilter, const ma_allocation_callbacks* pAllocationCallbacks);
MA_API ma_result ma_loshelf2_reinit(const ma_loshelf2_config* pConfig, ma_loshelf2* pFilter); MA_API ma_result ma_loshelf2_reinit(const ma_loshelf2_config* pConfig, ma_loshelf2* pFilter);
@@ -3367,6 +3379,8 @@ typedef struct
ma_biquad bq; ma_biquad bq;
} ma_hishelf2; } ma_hishelf2;
MA_API ma_result ma_hishelf2_get_heap_size(const ma_hishelf2_config* pConfig, size_t* pHeapSizeInBytes);
MA_API ma_result ma_hishelf2_init_preallocated(const ma_hishelf2_config* pConfig, void* pHeap, ma_hishelf2* pFilter);
MA_API ma_result ma_hishelf2_init(const ma_hishelf2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_hishelf2* pFilter); MA_API ma_result ma_hishelf2_init(const ma_hishelf2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_hishelf2* pFilter);
MA_API void ma_hishelf2_uninit(ma_hishelf2* pFilter, const ma_allocation_callbacks* pAllocationCallbacks); MA_API void ma_hishelf2_uninit(ma_hishelf2* pFilter, const ma_allocation_callbacks* pAllocationCallbacks);
MA_API ma_result ma_hishelf2_reinit(const ma_hishelf2_config* pConfig, ma_hishelf2* pFilter); MA_API ma_result ma_hishelf2_reinit(const ma_hishelf2_config* pConfig, ma_hishelf2* pFilter);
@@ -40821,7 +40835,15 @@ static MA_INLINE ma_biquad_config ma_lpf2__get_biquad_config(const ma_lpf2_confi
return bqConfig; return bqConfig;
} }
MA_API ma_result ma_lpf2_init(const ma_lpf2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_lpf2* pLPF) MA_API ma_result ma_lpf2_get_heap_size(const ma_lpf2_config* pConfig, size_t* pHeapSizeInBytes)
{
ma_biquad_config bqConfig;
bqConfig = ma_lpf2__get_biquad_config(pConfig);
return ma_biquad_get_heap_size(&bqConfig, pHeapSizeInBytes);
}
MA_API ma_result ma_lpf2_init_preallocated(const ma_lpf2_config* pConfig, void* pHeap, ma_lpf2* pLPF)
{ {
ma_result result; ma_result result;
ma_biquad_config bqConfig; ma_biquad_config bqConfig;
@@ -40837,7 +40859,7 @@ MA_API ma_result ma_lpf2_init(const ma_lpf2_config* pConfig, const ma_allocation
} }
bqConfig = ma_lpf2__get_biquad_config(pConfig); bqConfig = ma_lpf2__get_biquad_config(pConfig);
result = ma_biquad_init(&bqConfig, pAllocationCallbacks, &pLPF->bq); result = ma_biquad_init_preallocated(&bqConfig, pHeap, &pLPF->bq);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
return result; return result;
} }
@@ -40845,13 +40867,43 @@ MA_API ma_result ma_lpf2_init(const ma_lpf2_config* pConfig, const ma_allocation
return MA_SUCCESS; return MA_SUCCESS;
} }
MA_API ma_result ma_lpf2_init(const ma_lpf2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_lpf2* pLPF)
{
ma_result result;
size_t heapSizeInBytes;
void* pHeap;
result = ma_lpf2_get_heap_size(pConfig, &heapSizeInBytes);
if (result != MA_SUCCESS) {
return result;
}
if (heapSizeInBytes > 0) {
pHeap = ma_malloc(heapSizeInBytes, pAllocationCallbacks);
if (pHeap == NULL) {
return MA_OUT_OF_MEMORY;
}
} else {
pHeap = NULL;
}
result = ma_lpf2_init_preallocated(pConfig, pHeap, pLPF);
if (result != MA_SUCCESS) {
ma_free(pHeap, pAllocationCallbacks);
return result;
}
pLPF->bq._ownsHeap = MA_TRUE; /* <-- This will cause the biquad to take ownership of the heap and free it when it's uninitialized. */
return MA_SUCCESS;
}
MA_API void ma_lpf2_uninit(ma_lpf2* pLPF, const ma_allocation_callbacks* pAllocationCallbacks) MA_API void ma_lpf2_uninit(ma_lpf2* pLPF, const ma_allocation_callbacks* pAllocationCallbacks)
{ {
if (pLPF == NULL) { if (pLPF == NULL) {
return; return;
} }
ma_biquad_uninit(&pLPF->bq, pAllocationCallbacks); ma_biquad_uninit(&pLPF->bq, pAllocationCallbacks); /* <-- This will free the heap allocation. */
} }
MA_API ma_result ma_lpf2_reinit(const ma_lpf2_config* pConfig, ma_lpf2* pLPF) MA_API ma_result ma_lpf2_reinit(const ma_lpf2_config* pConfig, ma_lpf2* pLPF)
@@ -41370,7 +41422,15 @@ static MA_INLINE ma_biquad_config ma_hpf2__get_biquad_config(const ma_hpf2_confi
return bqConfig; return bqConfig;
} }
MA_API ma_result ma_hpf2_init(const ma_hpf2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_hpf2* pHPF) MA_API ma_result ma_hpf2_get_heap_size(const ma_hpf2_config* pConfig, size_t* pHeapSizeInBytes)
{
ma_biquad_config bqConfig;
bqConfig = ma_hpf2__get_biquad_config(pConfig);
return ma_biquad_get_heap_size(&bqConfig, pHeapSizeInBytes);
}
MA_API ma_result ma_hpf2_init_preallocated(const ma_hpf2_config* pConfig, void* pHeap, ma_hpf2* pHPF)
{ {
ma_result result; ma_result result;
ma_biquad_config bqConfig; ma_biquad_config bqConfig;
@@ -41386,7 +41446,7 @@ MA_API ma_result ma_hpf2_init(const ma_hpf2_config* pConfig, const ma_allocation
} }
bqConfig = ma_hpf2__get_biquad_config(pConfig); bqConfig = ma_hpf2__get_biquad_config(pConfig);
result = ma_biquad_init(&bqConfig, pAllocationCallbacks, &pHPF->bq); result = ma_biquad_init_preallocated(&bqConfig, pHeap, &pHPF->bq);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
return result; return result;
} }
@@ -41394,13 +41454,43 @@ MA_API ma_result ma_hpf2_init(const ma_hpf2_config* pConfig, const ma_allocation
return MA_SUCCESS; return MA_SUCCESS;
} }
MA_API ma_result ma_hpf2_init(const ma_hpf2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_hpf2* pHPF)
{
ma_result result;
size_t heapSizeInBytes;
void* pHeap;
result = ma_hpf2_get_heap_size(pConfig, &heapSizeInBytes);
if (result != MA_SUCCESS) {
return result;
}
if (heapSizeInBytes > 0) {
pHeap = ma_malloc(heapSizeInBytes, pAllocationCallbacks);
if (pHeap == NULL) {
return MA_OUT_OF_MEMORY;
}
} else {
pHeap = NULL;
}
result = ma_hpf2_init_preallocated(pConfig, pHeap, pHPF);
if (result != MA_SUCCESS) {
ma_free(pHeap, pAllocationCallbacks);
return result;
}
pHPF->bq._ownsHeap = MA_TRUE; /* <-- This will cause the biquad to take ownership of the heap and free it when it's uninitialized. */
return MA_SUCCESS;
}
MA_API void ma_hpf2_uninit(ma_hpf2* pHPF, const ma_allocation_callbacks* pAllocationCallbacks) MA_API void ma_hpf2_uninit(ma_hpf2* pHPF, const ma_allocation_callbacks* pAllocationCallbacks)
{ {
if (pHPF == NULL) { if (pHPF == NULL) {
return; return;
} }
ma_biquad_uninit(&pHPF->bq, pAllocationCallbacks); ma_biquad_uninit(&pHPF->bq, pAllocationCallbacks); /* <-- This will free the heap allocation. */
} }
MA_API ma_result ma_hpf2_reinit(const ma_hpf2_config* pConfig, ma_hpf2* pHPF) MA_API ma_result ma_hpf2_reinit(const ma_hpf2_config* pConfig, ma_hpf2* pHPF)
@@ -41736,7 +41826,15 @@ static MA_INLINE ma_biquad_config ma_bpf2__get_biquad_config(const ma_bpf2_confi
return bqConfig; return bqConfig;
} }
MA_API ma_result ma_bpf2_init(const ma_bpf2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_bpf2* pBPF) MA_API ma_result ma_bpf2_get_heap_size(const ma_bpf2_config* pConfig, size_t* pHeapSizeInBytes)
{
ma_biquad_config bqConfig;
bqConfig = ma_bpf2__get_biquad_config(pConfig);
return ma_biquad_get_heap_size(&bqConfig, pHeapSizeInBytes);
}
MA_API ma_result ma_bpf2_init_preallocated(const ma_bpf2_config* pConfig, void* pHeap, ma_bpf2* pBPF)
{ {
ma_result result; ma_result result;
ma_biquad_config bqConfig; ma_biquad_config bqConfig;
@@ -41752,7 +41850,7 @@ MA_API ma_result ma_bpf2_init(const ma_bpf2_config* pConfig, const ma_allocation
} }
bqConfig = ma_bpf2__get_biquad_config(pConfig); bqConfig = ma_bpf2__get_biquad_config(pConfig);
result = ma_biquad_init(&bqConfig, pAllocationCallbacks, &pBPF->bq); result = ma_biquad_init_preallocated(&bqConfig, pHeap, &pBPF->bq);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
return result; return result;
} }
@@ -41760,13 +41858,43 @@ MA_API ma_result ma_bpf2_init(const ma_bpf2_config* pConfig, const ma_allocation
return MA_SUCCESS; return MA_SUCCESS;
} }
MA_API ma_result ma_bpf2_init(const ma_bpf2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_bpf2* pBPF)
{
ma_result result;
size_t heapSizeInBytes;
void* pHeap;
result = ma_bpf2_get_heap_size(pConfig, &heapSizeInBytes);
if (result != MA_SUCCESS) {
return result;
}
if (heapSizeInBytes > 0) {
pHeap = ma_malloc(heapSizeInBytes, pAllocationCallbacks);
if (pHeap == NULL) {
return MA_OUT_OF_MEMORY;
}
} else {
pHeap = NULL;
}
result = ma_bpf2_init_preallocated(pConfig, pHeap, pBPF);
if (result != MA_SUCCESS) {
ma_free(pHeap, pAllocationCallbacks);
return result;
}
pBPF->bq._ownsHeap = MA_TRUE; /* <-- This will cause the biquad to take ownership of the heap and free it when it's uninitialized. */
return MA_SUCCESS;
}
MA_API void ma_bpf2_uninit(ma_bpf2* pBPF, const ma_allocation_callbacks* pAllocationCallbacks) MA_API void ma_bpf2_uninit(ma_bpf2* pBPF, const ma_allocation_callbacks* pAllocationCallbacks)
{ {
if (pBPF == NULL) { if (pBPF == NULL) {
return; return;
} }
ma_biquad_uninit(&pBPF->bq, pAllocationCallbacks); ma_biquad_uninit(&pBPF->bq, pAllocationCallbacks); /* <-- This will free the heap allocation. */
} }
MA_API ma_result ma_bpf2_reinit(const ma_bpf2_config* pConfig, ma_bpf2* pBPF) MA_API ma_result ma_bpf2_reinit(const ma_bpf2_config* pConfig, ma_bpf2* pBPF)
@@ -42059,7 +42187,15 @@ static MA_INLINE ma_biquad_config ma_notch2__get_biquad_config(const ma_notch2_c
return bqConfig; return bqConfig;
} }
MA_API ma_result ma_notch2_init(const ma_notch2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_notch2* pFilter) MA_API ma_result ma_notch2_get_heap_size(const ma_notch2_config* pConfig, size_t* pHeapSizeInBytes)
{
ma_biquad_config bqConfig;
bqConfig = ma_notch2__get_biquad_config(pConfig);
return ma_biquad_get_heap_size(&bqConfig, pHeapSizeInBytes);
}
MA_API ma_result ma_notch2_init_preallocated(const ma_notch2_config* pConfig, void* pHeap, ma_notch2* pFilter)
{ {
ma_result result; ma_result result;
ma_biquad_config bqConfig; ma_biquad_config bqConfig;
@@ -42075,7 +42211,7 @@ MA_API ma_result ma_notch2_init(const ma_notch2_config* pConfig, const ma_alloca
} }
bqConfig = ma_notch2__get_biquad_config(pConfig); bqConfig = ma_notch2__get_biquad_config(pConfig);
result = ma_biquad_init(&bqConfig, pAllocationCallbacks, &pFilter->bq); result = ma_biquad_init_preallocated(&bqConfig, pHeap, &pFilter->bq);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
return result; return result;
} }
@@ -42083,13 +42219,43 @@ MA_API ma_result ma_notch2_init(const ma_notch2_config* pConfig, const ma_alloca
return MA_SUCCESS; return MA_SUCCESS;
} }
MA_API ma_result ma_notch2_init(const ma_notch2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_notch2* pFilter)
{
ma_result result;
size_t heapSizeInBytes;
void* pHeap;
result = ma_notch2_get_heap_size(pConfig, &heapSizeInBytes);
if (result != MA_SUCCESS) {
return result;
}
if (heapSizeInBytes > 0) {
pHeap = ma_malloc(heapSizeInBytes, pAllocationCallbacks);
if (pHeap == NULL) {
return MA_OUT_OF_MEMORY;
}
} else {
pHeap = NULL;
}
result = ma_notch2_init_preallocated(pConfig, pHeap, pFilter);
if (result != MA_SUCCESS) {
ma_free(pHeap, pAllocationCallbacks);
return result;
}
pFilter->bq._ownsHeap = MA_TRUE; /* <-- This will cause the biquad to take ownership of the heap and free it when it's uninitialized. */
return MA_SUCCESS;
}
MA_API void ma_notch2_uninit(ma_notch2* pFilter, const ma_allocation_callbacks* pAllocationCallbacks) MA_API void ma_notch2_uninit(ma_notch2* pFilter, const ma_allocation_callbacks* pAllocationCallbacks)
{ {
if (pFilter == NULL) { if (pFilter == NULL) {
return; return;
} }
ma_biquad_uninit(&pFilter->bq, pAllocationCallbacks); ma_biquad_uninit(&pFilter->bq, pAllocationCallbacks); /* <-- This will free the heap allocation. */
} }
MA_API ma_result ma_notch2_reinit(const ma_notch2_config* pConfig, ma_notch2* pFilter) MA_API ma_result ma_notch2_reinit(const ma_notch2_config* pConfig, ma_notch2* pFilter)
@@ -42197,7 +42363,15 @@ static MA_INLINE ma_biquad_config ma_peak2__get_biquad_config(const ma_peak2_con
return bqConfig; return bqConfig;
} }
MA_API ma_result ma_peak2_init(const ma_peak2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_peak2* pFilter) MA_API ma_result ma_peak2_get_heap_size(const ma_peak2_config* pConfig, size_t* pHeapSizeInBytes)
{
ma_biquad_config bqConfig;
bqConfig = ma_peak2__get_biquad_config(pConfig);
return ma_biquad_get_heap_size(&bqConfig, pHeapSizeInBytes);
}
MA_API ma_result ma_peak2_init_preallocated(const ma_peak2_config* pConfig, void* pHeap, ma_peak2* pFilter)
{ {
ma_result result; ma_result result;
ma_biquad_config bqConfig; ma_biquad_config bqConfig;
@@ -42213,7 +42387,7 @@ MA_API ma_result ma_peak2_init(const ma_peak2_config* pConfig, const ma_allocati
} }
bqConfig = ma_peak2__get_biquad_config(pConfig); bqConfig = ma_peak2__get_biquad_config(pConfig);
result = ma_biquad_init(&bqConfig, pAllocationCallbacks, &pFilter->bq); result = ma_biquad_init_preallocated(&bqConfig, pHeap, &pFilter->bq);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
return result; return result;
} }
@@ -42221,13 +42395,43 @@ MA_API ma_result ma_peak2_init(const ma_peak2_config* pConfig, const ma_allocati
return MA_SUCCESS; return MA_SUCCESS;
} }
MA_API ma_result ma_peak2_init(const ma_peak2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_peak2* pFilter)
{
ma_result result;
size_t heapSizeInBytes;
void* pHeap;
result = ma_peak2_get_heap_size(pConfig, &heapSizeInBytes);
if (result != MA_SUCCESS) {
return result;
}
if (heapSizeInBytes > 0) {
pHeap = ma_malloc(heapSizeInBytes, pAllocationCallbacks);
if (pHeap == NULL) {
return MA_OUT_OF_MEMORY;
}
} else {
pHeap = NULL;
}
result = ma_peak2_init_preallocated(pConfig, pHeap, pFilter);
if (result != MA_SUCCESS) {
ma_free(pHeap, pAllocationCallbacks);
return result;
}
pFilter->bq._ownsHeap = MA_TRUE; /* <-- This will cause the biquad to take ownership of the heap and free it when it's uninitialized. */
return MA_SUCCESS;
}
MA_API void ma_peak2_uninit(ma_peak2* pFilter, const ma_allocation_callbacks* pAllocationCallbacks) MA_API void ma_peak2_uninit(ma_peak2* pFilter, const ma_allocation_callbacks* pAllocationCallbacks)
{ {
if (pFilter == NULL) { if (pFilter == NULL) {
return; return;
} }
ma_biquad_uninit(&pFilter->bq, pAllocationCallbacks); ma_biquad_uninit(&pFilter->bq, pAllocationCallbacks); /* <-- This will free the heap allocation. */
} }
MA_API ma_result ma_peak2_reinit(const ma_peak2_config* pConfig, ma_peak2* pFilter) MA_API ma_result ma_peak2_reinit(const ma_peak2_config* pConfig, ma_peak2* pFilter)
@@ -42332,7 +42536,15 @@ static MA_INLINE ma_biquad_config ma_loshelf2__get_biquad_config(const ma_loshel
return bqConfig; return bqConfig;
} }
MA_API ma_result ma_loshelf2_init(const ma_loshelf2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_loshelf2* pFilter) MA_API ma_result ma_loshelf2_get_heap_size(const ma_loshelf2_config* pConfig, size_t* pHeapSizeInBytes)
{
ma_biquad_config bqConfig;
bqConfig = ma_loshelf2__get_biquad_config(pConfig);
return ma_biquad_get_heap_size(&bqConfig, pHeapSizeInBytes);
}
MA_API ma_result ma_loshelf2_init_preallocated(const ma_loshelf2_config* pConfig, void* pHeap, ma_loshelf2* pFilter)
{ {
ma_result result; ma_result result;
ma_biquad_config bqConfig; ma_biquad_config bqConfig;
@@ -42348,7 +42560,7 @@ MA_API ma_result ma_loshelf2_init(const ma_loshelf2_config* pConfig, const ma_al
} }
bqConfig = ma_loshelf2__get_biquad_config(pConfig); bqConfig = ma_loshelf2__get_biquad_config(pConfig);
result = ma_biquad_init(&bqConfig, pAllocationCallbacks, &pFilter->bq); result = ma_biquad_init_preallocated(&bqConfig, pHeap, &pFilter->bq);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
return result; return result;
} }
@@ -42356,13 +42568,43 @@ MA_API ma_result ma_loshelf2_init(const ma_loshelf2_config* pConfig, const ma_al
return MA_SUCCESS; return MA_SUCCESS;
} }
MA_API ma_result ma_loshelf2_init(const ma_loshelf2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_loshelf2* pFilter)
{
ma_result result;
size_t heapSizeInBytes;
void* pHeap;
result = ma_loshelf2_get_heap_size(pConfig, &heapSizeInBytes);
if (result != MA_SUCCESS) {
return result;
}
if (heapSizeInBytes > 0) {
pHeap = ma_malloc(heapSizeInBytes, pAllocationCallbacks);
if (pHeap == NULL) {
return MA_OUT_OF_MEMORY;
}
} else {
pHeap = NULL;
}
result = ma_loshelf2_init_preallocated(pConfig, pHeap, pFilter);
if (result != MA_SUCCESS) {
ma_free(pHeap, pAllocationCallbacks);
return result;
}
pFilter->bq._ownsHeap = MA_TRUE; /* <-- This will cause the biquad to take ownership of the heap and free it when it's uninitialized. */
return MA_SUCCESS;
}
MA_API void ma_loshelf2_uninit(ma_loshelf2* pFilter, const ma_allocation_callbacks* pAllocationCallbacks) MA_API void ma_loshelf2_uninit(ma_loshelf2* pFilter, const ma_allocation_callbacks* pAllocationCallbacks)
{ {
if (pFilter == NULL) { if (pFilter == NULL) {
return; return;
} }
ma_biquad_uninit(&pFilter->bq, pAllocationCallbacks); ma_biquad_uninit(&pFilter->bq, pAllocationCallbacks); /* <-- This will free the heap allocation. */
} }
MA_API ma_result ma_loshelf2_reinit(const ma_loshelf2_config* pConfig, ma_loshelf2* pFilter) MA_API ma_result ma_loshelf2_reinit(const ma_loshelf2_config* pConfig, ma_loshelf2* pFilter)
@@ -42467,7 +42709,15 @@ static MA_INLINE ma_biquad_config ma_hishelf2__get_biquad_config(const ma_hishel
return bqConfig; return bqConfig;
} }
MA_API ma_result ma_hishelf2_init(const ma_hishelf2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_hishelf2* pFilter) MA_API ma_result ma_hishelf2_get_heap_size(const ma_hishelf2_config* pConfig, size_t* pHeapSizeInBytes)
{
ma_biquad_config bqConfig;
bqConfig = ma_hishelf2__get_biquad_config(pConfig);
return ma_biquad_get_heap_size(&bqConfig, pHeapSizeInBytes);
}
MA_API ma_result ma_hishelf2_init_preallocated(const ma_hishelf2_config* pConfig, void* pHeap, ma_hishelf2* pFilter)
{ {
ma_result result; ma_result result;
ma_biquad_config bqConfig; ma_biquad_config bqConfig;
@@ -42483,7 +42733,7 @@ MA_API ma_result ma_hishelf2_init(const ma_hishelf2_config* pConfig, const ma_al
} }
bqConfig = ma_hishelf2__get_biquad_config(pConfig); bqConfig = ma_hishelf2__get_biquad_config(pConfig);
result = ma_biquad_init(&bqConfig, pAllocationCallbacks, &pFilter->bq); result = ma_biquad_init_preallocated(&bqConfig, pHeap, &pFilter->bq);
if (result != MA_SUCCESS) { if (result != MA_SUCCESS) {
return result; return result;
} }
@@ -42491,13 +42741,43 @@ MA_API ma_result ma_hishelf2_init(const ma_hishelf2_config* pConfig, const ma_al
return MA_SUCCESS; return MA_SUCCESS;
} }
MA_API ma_result ma_hishelf2_init(const ma_hishelf2_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_hishelf2* pFilter)
{
ma_result result;
size_t heapSizeInBytes;
void* pHeap;
result = ma_hishelf2_get_heap_size(pConfig, &heapSizeInBytes);
if (result != MA_SUCCESS) {
return result;
}
if (heapSizeInBytes > 0) {
pHeap = ma_malloc(heapSizeInBytes, pAllocationCallbacks);
if (pHeap == NULL) {
return MA_OUT_OF_MEMORY;
}
} else {
pHeap = NULL;
}
result = ma_hishelf2_init_preallocated(pConfig, pHeap, pFilter);
if (result != MA_SUCCESS) {
ma_free(pHeap, pAllocationCallbacks);
return result;
}
pFilter->bq._ownsHeap = MA_TRUE; /* <-- This will cause the biquad to take ownership of the heap and free it when it's uninitialized. */
return MA_SUCCESS;
}
MA_API void ma_hishelf2_uninit(ma_hishelf2* pFilter, const ma_allocation_callbacks* pAllocationCallbacks) MA_API void ma_hishelf2_uninit(ma_hishelf2* pFilter, const ma_allocation_callbacks* pAllocationCallbacks)
{ {
if (pFilter == NULL) { if (pFilter == NULL) {
return; return;
} }
ma_biquad_uninit(&pFilter->bq, pAllocationCallbacks); ma_biquad_uninit(&pFilter->bq, pAllocationCallbacks); /* <-- This will free the heap allocation. */
} }
MA_API ma_result ma_hishelf2_reinit(const ma_hishelf2_config* pConfig, ma_hishelf2* pFilter) MA_API ma_result ma_hishelf2_reinit(const ma_hishelf2_config* pConfig, ma_hishelf2* pFilter)
@@ -42691,7 +42971,7 @@ MA_API void ma_linear_resampler_uninit(ma_linear_resampler* pResampler, const ma
return; return;
} }
(void)pAllocationCallbacks; ma_lpf_uninit(&pResampler->lpf, pAllocationCallbacks);
} }
static MA_INLINE ma_int16 ma_linear_resampler_mix_s16(ma_int16 x, ma_int16 y, ma_int32 a, const ma_int32 shift) static MA_INLINE ma_int16 ma_linear_resampler_mix_s16(ma_int16 x, ma_int16 y, ma_int32 a, const ma_int32 shift)