Virtual Surround: Cleanup properly

The filter wasn't properly freeing its FFT setup state, and also was
unnecessarily null checking the pointers before passing them to the
aligned free function, which already does null checking.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
CQTexperiment
Christopher Snowhill 2022-01-25 22:06:53 -08:00
parent c7c3c82c18
commit 778ac0699e
2 changed files with 44 additions and 41 deletions

View File

@ -36,7 +36,8 @@
float * paddedSignal; float * paddedSignal;
float * prevOverlap[2]; float * prevOverlapLeft;
float * prevOverlapRight;
int prevOverlapLength; int prevOverlapLength;
} }

View File

@ -298,9 +298,9 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
if (!left_result || !right_result) if (!left_result || !right_result)
return nil; return nil;
prevOverlap[0] = (float *) memalign_calloc(16, sizeof(float), fftSize); prevOverlapLeft = (float *) memalign_calloc(16, sizeof(float), fftSize);
prevOverlap[1] = (float *) memalign_calloc(16, sizeof(float), fftSize); prevOverlapRight = (float *) memalign_calloc(16, sizeof(float), fftSize);
if (!prevOverlap[0] || !prevOverlap[1]) if (!prevOverlapLeft || !prevOverlapRight)
return nil; return nil;
left_mix_result = (float *) memalign_calloc(16, sizeof(float), fftSize); left_mix_result = (float *) memalign_calloc(16, sizeof(float), fftSize);
@ -315,20 +315,22 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
} }
- (void)dealloc { - (void)dealloc {
if (paddedSignal) memalign_free(paddedSignal); if (fftSetup) vDSP_destroy_fftsetup(fftSetup);
if (signal_fft.realp) memalign_free(signal_fft.realp); memalign_free(paddedSignal);
if (signal_fft.imagp) memalign_free(signal_fft.imagp);
if (input_filtered_signal_per_channel[0].realp) memalign_free(input_filtered_signal_per_channel[0].realp); memalign_free(signal_fft.realp);
if (input_filtered_signal_per_channel[0].imagp) memalign_free(input_filtered_signal_per_channel[0].imagp); memalign_free(signal_fft.imagp);
if (input_filtered_signal_per_channel[1].realp) memalign_free(input_filtered_signal_per_channel[1].realp);
if (input_filtered_signal_per_channel[1].imagp) memalign_free(input_filtered_signal_per_channel[1].imagp); memalign_free(input_filtered_signal_per_channel[0].realp);
memalign_free(input_filtered_signal_per_channel[0].imagp);
memalign_free(input_filtered_signal_per_channel[1].realp);
memalign_free(input_filtered_signal_per_channel[1].imagp);
if (impulse_responses) { if (impulse_responses) {
for (size_t i = 0; i < channelCount * 2; ++i) { for (size_t i = 0; i < channelCount * 2; ++i) {
if (impulse_responses[i].realp) memalign_free(impulse_responses[i].realp); memalign_free(impulse_responses[i].realp);
if (impulse_responses[i].imagp) memalign_free(impulse_responses[i].imagp); memalign_free(impulse_responses[i].imagp);
} }
free(impulse_responses); free(impulse_responses);
} }
@ -336,15 +338,15 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
memalign_free(left_result); memalign_free(left_result);
memalign_free(right_result); memalign_free(right_result);
if (prevOverlap[0]) memalign_free(prevOverlap[0]); memalign_free(prevOverlapLeft);
if (prevOverlap[1]) memalign_free(prevOverlap[1]); memalign_free(prevOverlapRight);
memalign_free(left_mix_result); memalign_free(left_mix_result);
memalign_free(right_mix_result); memalign_free(right_mix_result);
} }
- (void)process:(const float*)inBuffer sampleCount:(size_t)count toBuffer:(float *)outBuffer { - (void)process:(const float*)inBuffer sampleCount:(size_t)count toBuffer:(float *)outBuffer {
float scale = 1.0 / (8.0 * (float)fftSize); const float scale = 1.0 / (8.0 * (float)fftSize);
while (count > 0) { while (count > 0) {
size_t countToDo = (count > bufferSize) ? bufferSize : count; size_t countToDo = (count > bufferSize) ? bufferSize : count;
@ -393,14 +395,14 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
// Integrate previous overlap // Integrate previous overlap
if (prevOverlapLength) { if (prevOverlapLength) {
vDSP_vadd(prevOverlap[0], 1, left_mix_result, 1, left_mix_result, 1, prevOverlapLength); vDSP_vadd(prevOverlapLeft, 1, left_mix_result, 1, left_mix_result, 1, prevOverlapLength);
vDSP_vadd(prevOverlap[1], 1, right_mix_result, 1, right_mix_result, 1, prevOverlapLength); vDSP_vadd(prevOverlapRight, 1, right_mix_result, 1, right_mix_result, 1, prevOverlapLength);
} }
prevOverlapLength = (int)(fftSize - countToDo); prevOverlapLength = (int)(fftSize - countToDo);
cblas_scopy(prevOverlapLength, left_mix_result + countToDo, 1, prevOverlap[0], 1); cblas_scopy(prevOverlapLength, left_mix_result + countToDo, 1, prevOverlapLeft, 1);
cblas_scopy(prevOverlapLength, right_mix_result + countToDo, 1, prevOverlap[1], 1); cblas_scopy(prevOverlapLength, right_mix_result + countToDo, 1, prevOverlapRight, 1);
vDSP_vsmul(left_mix_result, 1, &scale, left_mix_result, 1, countToDo); vDSP_vsmul(left_mix_result, 1, &scale, left_mix_result, 1, countToDo);
vDSP_vsmul(right_mix_result, 1, &scale, right_mix_result, 1, countToDo); vDSP_vsmul(right_mix_result, 1, &scale, right_mix_result, 1, countToDo);