Virtual Surround: General cleanup

This should fix some coding issues, and also fix some potential memory
leaks in the file verifier, assuming it didn't already release the
files it was pulling the stats from.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
CQTexperiment
Christopher Snowhill 2022-01-26 01:00:28 -08:00
parent e6b056d7ae
commit 7b5925d7d2
1 changed files with 68 additions and 25 deletions

View File

@ -14,28 +14,44 @@
@implementation HeadphoneFilter @implementation HeadphoneFilter
// Symmetrical / no-echo sets // Symmetrical / no-reverb sets
static const int8_t speakers_to_hesuvi_7[8][2][8] = { static const int8_t speakers_to_hesuvi_7[8][2][8] = {
{ { 6 }, { 6 } }, // mono/center // mono/center
{ { 0, 1 }, { 1, 0 } }, // left/right { { 6 }, { 6 } },
{ { 0, 1, 6 }, { 1, 0, 6 } }, // left/right/center // left/right
{ { 0, 1, 4, 5 }, { 1, 0, 5, 4 } },// left/right/left back/right back { { 0, 1 }, { 1, 0 } },
{ { 0, 1, 6, 4, 5 }, { 1, 0, 6, 5, 4 } }, // left/right/center/back left/back right // left/right/center
{ { 0, 1, 6, 6, 4, 5 }, { 1, 0, 6, 6, 5, 4 } }, // left/right/center/lfe(center)/back left/back right { { 0, 1, 6 }, { 1, 0, 6 } },
{ { 0, 1, 6, 6, -1, 2, 3 }, { 1, 0, 6, 6, -1, 3, 2 } }, // left/right/center/lfe(center)/back center(special)/side left/side right // left/right/back lef/back right
{ { 0, 1, 6, 6, 4, 5, 2, 3 }, { 1, 0, 6, 6, 5, 4, 3, 2 } } // left/right/center/lfe(center)/back left/back right/side left/side right { { 0, 1, 4, 5 }, { 1, 0, 5, 4 } },
// left/right/center/back left/back right
{ { 0, 1, 6, 4, 5 }, { 1, 0, 6, 5, 4 } },
// left/right/center/lfe(center)/back left/back right
{ { 0, 1, 6, 6, 4, 5 }, { 1, 0, 6, 6, 5, 4 } },
// left/right/center/lfe(center)/back center(special)/side left/side right
{ { 0, 1, 6, 6, -1, 2, 3 }, { 1, 0, 6, 6, -1, 3, 2 } },
// left/right/center/lfe(center)/back left/back right/side left/side right
{ { 0, 1, 6, 6, 4, 5, 2, 3 }, { 1, 0, 6, 6, 5, 4, 3, 2 } }
}; };
// Asymmetrical / echo sets // Asymmetrical / reverb sets
static const int8_t speakers_to_hesuvi_14[8][2][8] = { static const int8_t speakers_to_hesuvi_14[8][2][8] = {
{ { 6 }, { 13 } }, // mono/center // mono/center
{ { 0, 8 }, { 1, 7 } }, // left/right { { 6 }, { 13 } },
{ { 0, 8, 6 }, { 1, 7, 13 } }, // left/right/center // left/right
{ { 0, 8, 4, 12 }, { 1, 7, 5, 11 } },// left/right/left back/right back { { 0, 8 }, { 1, 7 } },
{ { 0, 8, 6, 4, 12 }, { 1, 7, 13, 5, 11 } }, // left/right/center/back left/back right // left/right/center
{ { 0, 8, 6, 6, 4, 12 }, { 1, 7, 13, 13, 5, 11 } }, // left/right/center/lfe(center)/back left/back right { { 0, 8, 6 }, { 1, 7, 13 } },
{ { 0, 8, 6, 6, -1, 2, 10 }, { 1, 7, 13, 13, -1, 3, 9 } }, // left/right/center/lfe(center)/back center(special)/side left/side right // left/right/back left/back right
{ { 0, 8, 6, 6, 4, 12, 2, 10 }, { 1, 7, 13, 13, 5, 11, 3, 9 } } // left/right/center/lfe(center)/back left/back right/side left/side right { { 0, 8, 4, 12 }, { 1, 7, 5, 11 } },
// left/right/center/back left/back right
{ { 0, 8, 6, 4, 12 }, { 1, 7, 13, 5, 11 } },
// left/right/center/lfe(center)/back left/back right
{ { 0, 8, 6, 6, 4, 12 }, { 1, 7, 13, 13, 5, 11 } },
// left/right/center/lfe(center)/back center(special)/side left/side right
{ { 0, 8, 6, 6, -1, 2, 10 }, { 1, 7, 13, 13, -1, 3, 9 } },
// left/right/center/lfe(center)/back left/back right/side left/side right
{ { 0, 8, 6, 6, 4, 12, 2, 10 }, { 1, 7, 13, 13, 5, 11, 3, 9 } }
}; };
+ (BOOL)validateImpulseFile:(NSURL *)url { + (BOOL)validateImpulseFile:(NSURL *)url {
@ -48,16 +64,27 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
id<CogDecoder> decoder = [AudioDecoder audioDecoderForSource:source]; id<CogDecoder> decoder = [AudioDecoder audioDecoderForSource:source];
if (decoder == nil) if (decoder == nil) {
[source close];
source = nil;
return NO; return NO;
}
if (![decoder open:source]) if (![decoder open:source])
{ {
decoder = nil;
[source close];
source = nil;
return NO; return NO;
} }
NSDictionary *properties = [decoder properties]; NSDictionary *properties = [decoder properties];
[decoder close];
decoder = nil;
[source close];
source = nil;
int impulseChannels = [[properties objectForKey:@"channels"] intValue]; int impulseChannels = [[properties objectForKey:@"channels"] intValue];
if ([[properties objectForKey:@"floatingPoint"] boolValue] != YES || if ([[properties objectForKey:@"floatingPoint"] boolValue] != YES ||
@ -83,11 +110,17 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
id<CogDecoder> decoder = [AudioDecoder audioDecoderForSource:source]; id<CogDecoder> decoder = [AudioDecoder audioDecoderForSource:source];
if (decoder == nil) if (decoder == nil) {
[source close];
source = nil;
return nil; return nil;
}
if (![decoder open:source]) if (![decoder open:source])
{ {
decoder = nil;
[source close];
source = nil;
return nil; return nil;
} }
@ -109,11 +142,17 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
if (!impulseBuffer) if (!impulseBuffer)
return nil; return nil;
if ([decoder readAudio:impulseBuffer frames:sampleCount] != sampleCount) if ([decoder readAudio:impulseBuffer frames:sampleCount] != sampleCount) {
[decoder close];
decoder = nil;
[source close];
source = nil;
return nil; return nil;
}
[decoder close]; [decoder close];
decoder = nil; decoder = nil;
[source close];
source = nil; source = nil;
if (sampleRateOfSource != sampleRate) { if (sampleRateOfSource != sampleRate) {
@ -132,6 +171,10 @@ static const int8_t speakers_to_hesuvi_14[8][2][8] = {
int resamplerLatencyOut = (int)ceil(resamplerLatencyIn * sampleRatio); int resamplerLatencyOut = (int)ceil(resamplerLatencyIn * sampleRatio);
float * resampledImpulse = calloc(sizeof(float), (resampledCount + resamplerLatencyOut * 2 + 128) * sizeof(float) * impulseChannels); float * resampledImpulse = calloc(sizeof(float), (resampledCount + resamplerLatencyOut * 2 + 128) * sizeof(float) * impulseChannels);
if (!resampledImpulse) {
free(impulseBuffer);
return nil;
}
memmove(impulseBuffer + resamplerLatencyIn * impulseChannels, impulseBuffer, sampleCount * sizeof(float) * impulseChannels); memmove(impulseBuffer + resamplerLatencyIn * impulseChannels, impulseBuffer, sampleCount * sizeof(float) * impulseChannels);
memset(impulseBuffer, 0, resamplerLatencyIn * sizeof(float) * impulseChannels); memset(impulseBuffer, 0, resamplerLatencyIn * sizeof(float) * impulseChannels);