* ensuring that non-AAC audio formats always use a stereo mix (rather than mono)
* ensuring that Dolby Surround (Pro Logic) source is passed through as Dolby Surround (Pro Logic), and not mixed down to Stereo
* storing the ac3 flags with the job for later reference
Note: this is still using the settings for the last selected soundtrack for *all* soundtracks. This needs improving, as they may not be of the same format!
Tested with mono, stereo, pro logic and 5.1 AC3 sources, to all output audio formats, with success all round :)
git-svn-id: svn://svn.handbrake.fr/HandBrake/branches/0.8.0_beta2_5.1@319
b64f7644-9d1e-0410-96f1-
a4d463321fa5
channelsused: The # of channels we will actually use for this job -
calculated based on surround, channels and lfechannels
in work.c
+ ac3flags: stores the flags from the AC3 source, as found in scan.c
surround: 1 if 5.1 should be preserved for AAC, 0 otherwise */
int audios[8];
int channels;
int lfechannels;
int channelsused;
+ int ac3flags;
int surround;
/* Audio settings:
int channels;
/* indicates the number of lfe channels the source audio has */
int lfechannels;
+ /* stores the flags from the AC3 source, as found in scan.c */
+ int ac3flags;
#ifdef __LIBMEDIAFORK__
/* Internal data */
pv->list = hb_list_init();
pv->state = a52_init( 0 );
+ /* Decide what format we want out of a52dec
+ work.c has already done some of this deduction for us in do_job() */
+
if (job->channelsused == 6) {
/* we're going to be encoding to AAC,
and have turned on the "preserve 5.1" flag */
pv->flags_out = A52_3F2R | A52_LFE;
} else if (job->channelsused == 1) {
- /* keep the mono-ness of the source audio */
+ /* we're going to be encoding to AAC,
+ /* and want to keep the mono-ness of the source audio */
pv->flags_out = A52_MONO;
} else if (job->channelsused == 2 && job->channels == 5 && job->lfechannels == 1) {
/* we are mixing a 5.1 source down to stereo, so use dolby surround */
pv->flags_out = A52_DOLBY;
+ } else if (job->channelsused == 2 && ((job->ac3flags & A52_CHANNEL_MASK) == A52_DOLBY)) {
+ /* we have a dolby stereo surround source, so preserve it */
+ pv->flags_out = A52_DOLBY;
} else {
- /* mix everything else down to stereo */
+ /* mix everything else down to plain stereo */
pv->flags_out = A52_STEREO;
}
} else {
audio->lfechannels = 0;
}
+
+ /* store the AC3 tags for future reference
+ This enables us to find out if we had a stereo or Dolby source later on */
+ audio->ac3flags = flags;
/* XXX */
sprintf( audio->lang + strlen( audio->lang ),
/* store this audio's channel counts with the job */
/* this should be an array -
we just use the last channel count for now */
+
+ /* we will only end up with a channelsused value other than 2
+ if we are encoding to AAC. All other audio encodings will get
+ a stereo mix. */
+
if (audio->channels == 5 && audio->lfechannels == 1) {
/* we have a 5.1 AC-3 source soundtrack */
if (job->acodec == HB_ACODEC_FAAC && job->surround) {
and have turned on the "preserve 5.1" flag */
job->channelsused = 6;
} else {
- /* mix 5.1 down to Dolby Digital (2-channel) */
+ /* mix 5.1 down to Dolby Digital (2-channel) for
+ non-AAC audio, or for AAC without 5.1 preservation */
job->channelsused = 2;
}
} else if (audio->channels == 1 && audio->lfechannels == 0) {
- /* keep the mono-ness of the source audio */
- job->channelsused = 1;
+ /* we have a 1.0 mono AC-3 source soundtrack */
+ if (job->acodec == HB_ACODEC_FAAC) {
+ /* we're going to be encoding to AAC,
+ so mix down to a mono AAC track */
+ job->channelsused = 1;
+ } else {
+ /* mix up the mono track to stereo for non-AAC formats */
+ job->channelsused = 2;
+ }
} else {
/* mix everything else down to stereo */
+ /* dolby pro-logic will be preserved in deca52.c if necessary
+ by referring to the value of job->ac3flags stored below */
job->channelsused = 2;
}
job->channels = audio->channels;
job->lfechannels = audio->lfechannels;
+ /* remember the AC3 flags for future reference */
+ /* again, we are using the last channel's flags for now */
+ job->ac3flags = audio->ac3flags;
+
}
/* Init read & write threads */