summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--macosx/HBAudioTrack.m56
-rw-r--r--macosx/HBAudioTrackPreset.m40
2 files changed, 78 insertions, 18 deletions
diff --git a/macosx/HBAudioTrack.m b/macosx/HBAudioTrack.m
index 05f9789de..ed51df1af 100644
--- a/macosx/HBAudioTrack.m
+++ b/macosx/HBAudioTrack.m
@@ -33,7 +33,6 @@ NSString *keyAudioBitrate = @"bitrate";
static NSMutableArray *masterCodecArray = nil;
static NSMutableArray *masterMixdownArray = nil;
-static NSMutableArray *masterSampleRateArray = nil;
static NSMutableArray *masterBitRateArray = nil;
@interface NSArray (HBAudioSupport)
@@ -110,20 +109,6 @@ static NSMutableArray *masterBitRateArray = nil;
keyAudioMixdown: @(mixdown->amixdown)}];
}
- // Note that for the Auto value we use 0 for the sample rate because our controller will give back the track's
- // input sample rate when it finds this 0 value as the selected sample rate. We do this because the input
- // sample rate depends on the track, which means it depends on the title, so cannot be nicely set up here.
- masterSampleRateArray = [[NSMutableArray alloc] init]; // knowingly leaked
- [masterSampleRateArray addObject:@{keyAudioSampleRateName: @"Auto",
- keyAudioSamplerate: @0}];
- for (const hb_rate_t *audio_samplerate = hb_audio_samplerate_get_next(NULL);
- audio_samplerate != NULL;
- audio_samplerate = hb_audio_samplerate_get_next(audio_samplerate))
- {
- [masterSampleRateArray addObject:@{keyAudioSampleRateName: @(audio_samplerate->name),
- keyAudioSamplerate: @(audio_samplerate->rate)}];
- }
-
masterBitRateArray = [[NSMutableArray alloc] init]; // knowingly leaked
for (const hb_rate_t *audio_bitrate = hb_audio_bitrate_get_next(NULL);
audio_bitrate != NULL;
@@ -234,6 +219,22 @@ static NSMutableArray *masterBitRateArray = nil;
}
}
+- (void)validateSamplerate
+{
+ int codec = [self.codec[keyAudioCodec] intValue];
+ int samplerate = [self.sampleRate[keyAudioSamplerate] intValue];
+
+ if (codec & HB_ACODEC_PASS_FLAG)
+ {
+ [self setSampleRateFromName:@"Auto"];
+ }
+ else if (samplerate)
+ {
+ samplerate = hb_audio_samplerate_get_best(codec, samplerate, NULL);
+ [self setSampleRateFromName:@(hb_audio_samplerate_get_name(samplerate))];
+ }
+}
+
- (void) updateBitRates: (BOOL) shouldSetDefault
{
@@ -321,7 +322,29 @@ static NSMutableArray *masterBitRateArray = nil;
- (NSArray *) sampleRates
{
- return masterSampleRateArray;
+ NSMutableArray *samplerates = [[NSMutableArray alloc] init];
+
+ /*
+ * Note that for the Auto value we use 0 for the sample rate because our controller will give back the track's
+ * input sample rate when it finds this 0 value as the selected sample rate. We do this because the input
+ * sample rate depends on the track, which means it depends on the title, so cannot be nicely set up here.
+ */
+ [samplerates addObject:@{keyAudioSampleRateName: @"Auto",
+ keyAudioSamplerate: @0}];
+
+ int codec = [self.codec[keyAudioCodec] intValue];
+ for (const hb_rate_t *audio_samplerate = hb_audio_samplerate_get_next(NULL);
+ audio_samplerate != NULL;
+ audio_samplerate = hb_audio_samplerate_get_next(audio_samplerate))
+ {
+ int rate = audio_samplerate->rate;
+ if (rate == hb_audio_samplerate_get_best(codec, rate, NULL))
+ {
+ [samplerates addObject:@{keyAudioSampleRateName: @(audio_samplerate->name),
+ keyAudioSamplerate: @(rate)}];
+ }
+ }
+ return samplerates;
}
#pragma mark -
@@ -359,6 +382,7 @@ static NSMutableArray *masterBitRateArray = nil;
- (void)setCodec:(NSDictionary *)codec
{
_codec = codec;
+ [self validateSamplerate];
[self updateMixdowns: YES];
[self updateBitRates: YES];
}
diff --git a/macosx/HBAudioTrackPreset.m b/macosx/HBAudioTrackPreset.m
index 4ebb2071d..fc73fe333 100644
--- a/macosx/HBAudioTrackPreset.m
+++ b/macosx/HBAudioTrackPreset.m
@@ -56,6 +56,7 @@ static void *HBAudioEncoderContex = &HBAudioEncoderContex;
{
_encoder = encoder;
[self validateMixdown];
+ [self validateSamplerate];
[self validateBitrate];
}
@@ -85,9 +86,34 @@ static void *HBAudioEncoderContex = &HBAudioEncoderContex;
}
}
+- (void)validateSamplerate
+{
+ if (self.encoder & HB_ACODEC_PASS_FLAG)
+ {
+ self.sampleRate = 0; // Auto (same as source)
+ }
+ else if (self.sampleRate)
+ {
+ self.sampleRate = hb_audio_samplerate_get_best(self.encoder, self.sampleRate, NULL);
+ }
+}
+
- (void)validateBitrate
{
- self.bitRate = hb_audio_bitrate_get_best(self.encoder, self.bitRate, self.sampleRate, self.mixdown);
+ if (self.encoder & HB_ACODEC_PASS_FLAG)
+ {
+ self.bitRate = -1;
+ }
+ else if (self.bitRate == -1) // switching from passthru
+ {
+ self.bitRate = hb_audio_bitrate_get_default(self.encoder,
+ self.sampleRate ? self.sampleRate : DEFAULT_SAMPLERATE,
+ self.mixdown);
+ }
+ else
+ {
+ self.bitRate = hb_audio_bitrate_get_best(self.encoder, self.bitRate, self.sampleRate, self.mixdown);
+ }
}
- (BOOL)mixdownEnabled
@@ -184,7 +210,11 @@ static void *HBAudioEncoderContex = &HBAudioEncoderContex;
audio_samplerate != NULL;
audio_samplerate = hb_audio_samplerate_get_next(audio_samplerate))
{
- [samplerates addObject:@(audio_samplerate->name)];
+ int rate = audio_samplerate->rate;
+ if (rate == hb_audio_samplerate_get_best(self.encoder, rate, NULL))
+ {
+ [samplerates addObject:@(audio_samplerate->name)];
+ }
}
return samplerates;
}
@@ -400,6 +430,12 @@ static void *HBAudioEncoderContex = &HBAudioEncoderContex;
- (id)transformedValue:(id)value
{
+ // treat -1 as a special invalid value
+ // e.g. passthru has no bitrate since we have no source
+ if ([value intValue] == -1)
+ {
+ return @"N/A";
+ }
return [value stringValue];
}