2012-07-15 16:40:46 +00:00
|
|
|
/* audio_resample.c
|
|
|
|
*
|
2025-01-22 09:11:40 +01:00
|
|
|
* Copyright (c) 2003-2025 HandBrake Team
|
2012-07-15 16:40:46 +00:00
|
|
|
* This file is part of the HandBrake source code
|
|
|
|
* Homepage: <http://handbrake.fr/>
|
|
|
|
* It may be used under the terms of the GNU General Public License v2.
|
|
|
|
* For full terms see the file COPYING file or visit http://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
|
|
|
|
2019-09-11 09:56:06 -07:00
|
|
|
#include "handbrake/common.h"
|
|
|
|
#include "handbrake/hbffmpeg.h"
|
|
|
|
#include "handbrake/audio_resample.h"
|
2012-07-15 16:40:46 +00:00
|
|
|
|
2012-08-27 22:00:28 +00:00
|
|
|
hb_audio_resample_t* hb_audio_resample_init(enum AVSampleFormat sample_fmt,
|
2019-05-30 08:45:13 -07:00
|
|
|
int sample_rate,
|
2012-11-21 18:29:34 +00:00
|
|
|
int hb_amixdown, int normalize_mix)
|
2012-07-15 16:40:46 +00:00
|
|
|
{
|
2012-09-13 20:13:59 +00:00
|
|
|
hb_audio_resample_t *resample = calloc(1, sizeof(hb_audio_resample_t));
|
2012-07-15 16:40:46 +00:00
|
|
|
if (resample == NULL)
|
2012-08-02 21:43:22 +00:00
|
|
|
{
|
|
|
|
hb_error("hb_audio_resample_init: failed to allocate resample");
|
2012-11-21 18:29:34 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2018-06-14 17:20:58 -07:00
|
|
|
// swresample context, initialized in hb_audio_resample_update()
|
|
|
|
resample->swresample = NULL;
|
2012-11-21 18:29:34 +00:00
|
|
|
|
|
|
|
// we don't support planar output yet
|
|
|
|
if (av_sample_fmt_is_planar(sample_fmt))
|
|
|
|
{
|
|
|
|
hb_error("hb_audio_resample_init: planar output not supported ('%s')",
|
|
|
|
av_get_sample_fmt_name(sample_fmt));
|
|
|
|
goto fail;
|
2012-08-02 21:43:22 +00:00
|
|
|
}
|
2012-07-15 16:40:46 +00:00
|
|
|
|
2012-08-27 22:00:28 +00:00
|
|
|
// convert mixdown to channel_layout/matrix_encoding combo
|
2012-11-21 18:29:34 +00:00
|
|
|
int matrix_encoding;
|
2012-08-27 22:00:28 +00:00
|
|
|
uint64_t channel_layout = hb_ff_mixdown_xlat(hb_amixdown, &matrix_encoding);
|
|
|
|
|
2012-11-21 18:29:34 +00:00
|
|
|
/*
|
|
|
|
* When downmixing, Dual Mono to Mono is a special case:
|
|
|
|
* the audio must remain 2-channel until all conversions are done.
|
|
|
|
*/
|
|
|
|
if (hb_amixdown == HB_AMIXDOWN_LEFT || hb_amixdown == HB_AMIXDOWN_RIGHT)
|
Audio improvements.
New supported samplerates: 8, 11.025, 12, 16 kHz.
Now 8, 11.025, 12, 16, 22.05, 24, 42, 44.1, 48 Khz are supported.
Unsupported samplerates are sanitized to the closest samplerate for all encoders.
Samplerates < 32 kHz are now forbidden for AC3 encoding (sanitized to 32 kHz). Most AC3 decoders don't support such samplerates.
New upmixing: 3.0 (Front Left, Right & Center) can now be upmixed to 5.1 to preserve the center channel.
New mixdowns:
6.1 (Front Left, Right & Center, Surround Left, Right & Center, LFE)
7.1 (Front Left, Right & Center, Surround Left & Right, Rear Left & Right, LFE)
-> available to Vorbis & FLAC encoders for compatible input channel layouts
7.1 (Front Left, Right & Center, Front Left & Right of Center, Surround Left & Right, LFE)
-> available to AAC encoders (ca_aac, ca_haac, faac) for compatible input channel layouts
Mono (Left Only): Stereo to Mono by discarding the Right channel
Mono (Right Only): Stereo to Mono by discarding the Left channel
-> available to all encoders for non-Dolby Stereo input
The "6-channel discrete" mixdown becomes "5.1 Channels".
New bitrates: 960 - 1536 Kbps.
This lets users work around poor audio quality in crappy encoders by throwing more bits at them.
Bitrate limits have been re-worked and re-tested for all encoders.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4930 b64f7644-9d1e-0410-96f1-a4d463321fa5
2012-09-03 12:37:16 +00:00
|
|
|
{
|
|
|
|
channel_layout = AV_CH_LAYOUT_STEREO;
|
|
|
|
resample->dual_mono_downmix = 1;
|
|
|
|
resample->dual_mono_right_only = (hb_amixdown == HB_AMIXDOWN_RIGHT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
resample->dual_mono_downmix = 0;
|
|
|
|
}
|
|
|
|
|
2012-11-21 18:29:34 +00:00
|
|
|
// requested output channel_layout, sample_fmt
|
2024-03-22 08:31:57 +01:00
|
|
|
av_channel_layout_from_mask(&resample->out.ch_layout, channel_layout);
|
2012-08-01 23:05:00 +00:00
|
|
|
resample->out.matrix_encoding = matrix_encoding;
|
2012-08-27 22:00:28 +00:00
|
|
|
resample->out.sample_fmt = sample_fmt;
|
2019-05-30 08:45:13 -07:00
|
|
|
resample->out.sample_rate = sample_rate;
|
2018-06-14 17:20:58 -07:00
|
|
|
if (normalize_mix)
|
|
|
|
{
|
|
|
|
resample->out.maxval = 1.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
resample->out.maxval = 1000;
|
|
|
|
}
|
2012-08-27 22:00:28 +00:00
|
|
|
resample->out.sample_size = av_get_bytes_per_sample(sample_fmt);
|
2012-07-15 16:40:46 +00:00
|
|
|
|
2012-08-27 21:17:59 +00:00
|
|
|
// set default input characteristics
|
2012-11-21 18:29:34 +00:00
|
|
|
resample->in.sample_fmt = resample->out.sample_fmt;
|
2019-05-30 08:45:13 -07:00
|
|
|
resample->in.sample_rate = resample->out.sample_rate;
|
2024-03-22 08:31:57 +01:00
|
|
|
av_channel_layout_copy(&resample->in.ch_layout, &resample->out.ch_layout);
|
2014-02-18 02:26:52 +00:00
|
|
|
resample->in.lfe_mix_level = HB_MIXLEV_ZERO;
|
2012-11-21 18:29:34 +00:00
|
|
|
resample->in.center_mix_level = HB_MIXLEV_DEFAULT;
|
|
|
|
resample->in.surround_mix_level = HB_MIXLEV_DEFAULT;
|
2012-08-27 22:00:28 +00:00
|
|
|
|
|
|
|
// by default, no conversion needed
|
2012-11-21 18:29:34 +00:00
|
|
|
resample->resample_needed = 0;
|
2012-07-15 16:40:46 +00:00
|
|
|
return resample;
|
2012-11-21 18:29:34 +00:00
|
|
|
|
|
|
|
fail:
|
|
|
|
hb_audio_resample_free(resample);
|
|
|
|
return NULL;
|
2012-07-15 16:40:46 +00:00
|
|
|
}
|
|
|
|
|
2024-03-22 08:31:57 +01:00
|
|
|
void hb_audio_resample_set_ch_layout(hb_audio_resample_t *resample,
|
|
|
|
const AVChannelLayout *ch_layout)
|
2012-08-27 21:17:59 +00:00
|
|
|
{
|
2012-11-21 18:29:34 +00:00
|
|
|
if (resample != NULL)
|
2012-08-27 21:17:59 +00:00
|
|
|
{
|
2024-03-22 08:31:57 +01:00
|
|
|
AVChannelLayout mono = AV_CHANNEL_LAYOUT_MONO;
|
|
|
|
AVChannelLayout stereo_dowmix = AV_CHANNEL_LAYOUT_STEREO_DOWNMIX;
|
|
|
|
if (av_channel_layout_compare(ch_layout, &stereo_dowmix) == 0)
|
2012-08-27 21:17:59 +00:00
|
|
|
{
|
|
|
|
// Dolby Surround is Stereo when it comes to remixing
|
2024-09-24 10:49:29 +02:00
|
|
|
AVChannelLayout stereo = AV_CHANNEL_LAYOUT_STEREO;
|
2024-03-22 08:31:57 +01:00
|
|
|
av_channel_layout_copy(&resample->in.ch_layout, &stereo);
|
2012-08-27 21:17:59 +00:00
|
|
|
}
|
2018-06-14 17:20:58 -07:00
|
|
|
// swresample can't remap a single-channel layout to
|
2017-02-24 10:28:33 -07:00
|
|
|
// another single-channel layout
|
2024-03-22 08:31:57 +01:00
|
|
|
else if (av_channel_layout_compare(ch_layout, &mono) == 0 &&
|
|
|
|
ch_layout->nb_channels == 1)
|
2017-02-24 10:28:33 -07:00
|
|
|
{
|
2024-03-22 08:31:57 +01:00
|
|
|
av_channel_layout_copy(&resample->in.ch_layout, &mono);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
av_channel_layout_copy(&resample->in.ch_layout, ch_layout);
|
2017-02-24 10:28:33 -07:00
|
|
|
}
|
2012-08-27 21:17:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void hb_audio_resample_set_mix_levels(hb_audio_resample_t *resample,
|
|
|
|
double surround_mix_level,
|
2014-02-18 02:26:52 +00:00
|
|
|
double center_mix_level,
|
|
|
|
double lfe_mix_level)
|
2012-08-27 21:17:59 +00:00
|
|
|
{
|
2012-11-21 18:29:34 +00:00
|
|
|
if (resample != NULL)
|
2012-08-27 21:17:59 +00:00
|
|
|
{
|
2014-02-18 02:26:52 +00:00
|
|
|
resample->in.lfe_mix_level = lfe_mix_level;
|
2012-08-27 21:17:59 +00:00
|
|
|
resample->in.center_mix_level = center_mix_level;
|
|
|
|
resample->in.surround_mix_level = surround_mix_level;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void hb_audio_resample_set_sample_fmt(hb_audio_resample_t *resample,
|
|
|
|
enum AVSampleFormat sample_fmt)
|
|
|
|
{
|
|
|
|
if (resample != NULL)
|
|
|
|
{
|
|
|
|
resample->in.sample_fmt = sample_fmt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-30 08:45:13 -07:00
|
|
|
void hb_audio_resample_set_sample_rate(hb_audio_resample_t *resample,
|
|
|
|
int sample_rate)
|
|
|
|
{
|
|
|
|
if (resample != NULL)
|
|
|
|
{
|
|
|
|
resample->in.sample_rate = sample_rate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-27 21:17:59 +00:00
|
|
|
int hb_audio_resample_update(hb_audio_resample_t *resample)
|
2012-07-15 16:40:46 +00:00
|
|
|
{
|
|
|
|
if (resample == NULL)
|
|
|
|
{
|
|
|
|
hb_error("hb_audio_resample_update: resample is NULL");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-08-10 18:48:42 +00:00
|
|
|
int ret, resample_changed;
|
|
|
|
|
2012-07-15 16:40:46 +00:00
|
|
|
resample->resample_needed =
|
2012-09-16 18:33:09 +00:00
|
|
|
(resample->out.sample_fmt != resample->in.sample_fmt ||
|
2019-05-30 08:45:13 -07:00
|
|
|
resample->out.sample_rate != resample->in.sample_rate ||
|
2024-03-22 08:31:57 +01:00
|
|
|
av_channel_layout_compare(&resample->out.ch_layout, &resample->in.ch_layout));
|
2012-07-15 16:40:46 +00:00
|
|
|
|
2012-08-10 18:48:42 +00:00
|
|
|
resample_changed =
|
2012-07-15 16:40:46 +00:00
|
|
|
(resample->resample_needed &&
|
2012-08-27 21:17:59 +00:00
|
|
|
(resample->resample.sample_fmt != resample->in.sample_fmt ||
|
2019-05-30 08:45:13 -07:00
|
|
|
resample->resample.sample_rate != resample->in.sample_rate ||
|
2024-03-22 08:31:57 +01:00
|
|
|
av_channel_layout_compare(&resample->resample.ch_layout, &resample->in.ch_layout) ||
|
2014-02-18 02:26:52 +00:00
|
|
|
resample->resample.lfe_mix_level != resample->in.lfe_mix_level ||
|
2012-08-27 21:17:59 +00:00
|
|
|
resample->resample.center_mix_level != resample->in.center_mix_level ||
|
|
|
|
resample->resample.surround_mix_level != resample->in.surround_mix_level));
|
2012-07-15 16:40:46 +00:00
|
|
|
|
|
|
|
if (resample_changed || (resample->resample_needed &&
|
2018-06-14 17:20:58 -07:00
|
|
|
resample->swresample == NULL))
|
2012-07-15 16:40:46 +00:00
|
|
|
{
|
2018-06-14 17:20:58 -07:00
|
|
|
if (resample->swresample == NULL)
|
2012-07-15 16:40:46 +00:00
|
|
|
{
|
2018-06-14 17:20:58 -07:00
|
|
|
resample->swresample = swr_alloc();
|
|
|
|
if (resample->swresample == NULL)
|
2012-07-15 16:40:46 +00:00
|
|
|
{
|
2018-06-14 17:20:58 -07:00
|
|
|
hb_error("hb_audio_resample_update: swr_alloc() failed");
|
2012-07-15 16:40:46 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-06-14 17:20:58 -07:00
|
|
|
av_opt_set_int(resample->swresample, "out_sample_fmt",
|
2012-07-15 16:40:46 +00:00
|
|
|
resample->out.sample_fmt, 0);
|
2019-05-30 08:45:13 -07:00
|
|
|
av_opt_set_int(resample->swresample, "out_sample_rate",
|
|
|
|
resample->out.sample_rate, 0);
|
2024-03-22 08:31:57 +01:00
|
|
|
av_opt_set_chlayout(resample->swresample, "out_chlayout",
|
|
|
|
&resample->out.ch_layout, 0);
|
2018-06-14 17:20:58 -07:00
|
|
|
av_opt_set_int(resample->swresample, "matrix_encoding",
|
2012-07-15 16:40:46 +00:00
|
|
|
resample->out.matrix_encoding, 0);
|
2018-06-14 17:20:58 -07:00
|
|
|
av_opt_set_double(resample->swresample, "rematrix_maxval",
|
|
|
|
resample->out.maxval, 0);
|
2012-07-15 16:40:46 +00:00
|
|
|
}
|
|
|
|
|
2018-06-14 17:20:58 -07:00
|
|
|
av_opt_set_int(resample->swresample, "in_sample_fmt",
|
2012-08-27 21:17:59 +00:00
|
|
|
resample->in.sample_fmt, 0);
|
2019-05-30 08:45:13 -07:00
|
|
|
av_opt_set_int(resample->swresample, "in_sample_rate",
|
|
|
|
resample->in.sample_rate, 0);
|
2024-03-22 08:31:57 +01:00
|
|
|
av_opt_set_chlayout(resample->swresample, "in_chlayout",
|
|
|
|
&resample->in.ch_layout, 0);
|
2018-06-14 17:20:58 -07:00
|
|
|
av_opt_set_double(resample->swresample, "lfe_mix_level",
|
2014-02-18 02:26:52 +00:00
|
|
|
resample->in.lfe_mix_level, 0);
|
2018-06-14 17:20:58 -07:00
|
|
|
av_opt_set_double(resample->swresample, "center_mix_level",
|
2012-08-27 21:17:59 +00:00
|
|
|
resample->in.center_mix_level, 0);
|
2018-06-14 17:20:58 -07:00
|
|
|
av_opt_set_double(resample->swresample, "surround_mix_level",
|
2012-08-27 21:17:59 +00:00
|
|
|
resample->in.surround_mix_level, 0);
|
2012-07-15 16:40:46 +00:00
|
|
|
|
2018-06-14 17:20:58 -07:00
|
|
|
if ((ret = swr_init(resample->swresample)))
|
2012-07-15 16:40:46 +00:00
|
|
|
{
|
2012-08-10 18:48:42 +00:00
|
|
|
char err_desc[64];
|
|
|
|
av_strerror(ret, err_desc, 63);
|
2018-06-14 17:20:58 -07:00
|
|
|
hb_error("hb_audio_resample_update: swr_init() failed (%s)",
|
2012-08-10 18:48:42 +00:00
|
|
|
err_desc);
|
2018-06-14 17:20:58 -07:00
|
|
|
// swresample won't open, start over
|
|
|
|
swr_free(&resample->swresample);
|
2012-08-10 18:48:42 +00:00
|
|
|
return ret;
|
2012-07-15 16:40:46 +00:00
|
|
|
}
|
|
|
|
|
2012-08-27 21:17:59 +00:00
|
|
|
resample->resample.sample_fmt = resample->in.sample_fmt;
|
2019-05-30 08:45:13 -07:00
|
|
|
resample->resample.sample_rate = resample->in.sample_rate;
|
2024-03-22 08:31:57 +01:00
|
|
|
av_channel_layout_copy(&resample->resample.ch_layout, &resample->in.ch_layout);
|
2014-02-18 02:26:52 +00:00
|
|
|
resample->resample.lfe_mix_level = resample->in.lfe_mix_level;
|
2012-08-27 21:17:59 +00:00
|
|
|
resample->resample.center_mix_level = resample->in.center_mix_level;
|
|
|
|
resample->resample.surround_mix_level = resample->in.surround_mix_level;
|
2012-07-15 16:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void hb_audio_resample_free(hb_audio_resample_t *resample)
|
|
|
|
{
|
|
|
|
if (resample != NULL)
|
|
|
|
{
|
2024-03-22 08:31:57 +01:00
|
|
|
av_channel_layout_uninit(&resample->in.ch_layout);
|
|
|
|
av_channel_layout_uninit(&resample->resample.ch_layout);
|
|
|
|
av_channel_layout_uninit(&resample->out.ch_layout);
|
|
|
|
|
2018-06-14 17:20:58 -07:00
|
|
|
if (resample->swresample != NULL)
|
2012-07-15 16:40:46 +00:00
|
|
|
{
|
2018-06-14 17:20:58 -07:00
|
|
|
swr_free(&resample->swresample);
|
2012-07-15 16:40:46 +00:00
|
|
|
}
|
|
|
|
free(resample);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hb_buffer_t* hb_audio_resample(hb_audio_resample_t *resample,
|
2018-06-14 17:20:58 -07:00
|
|
|
const uint8_t **samples, int nsamples)
|
2012-07-15 16:40:46 +00:00
|
|
|
{
|
|
|
|
if (resample == NULL)
|
|
|
|
{
|
|
|
|
hb_error("hb_audio_resample: resample is NULL");
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-06-14 17:20:58 -07:00
|
|
|
if (resample->resample_needed && resample->swresample == NULL)
|
2012-07-15 16:40:46 +00:00
|
|
|
{
|
2018-06-14 17:20:58 -07:00
|
|
|
hb_error("hb_audio_resample: resample needed but libswresample context "
|
2012-07-15 16:40:46 +00:00
|
|
|
"is NULL");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hb_buffer_t *out;
|
Audio improvements.
New supported samplerates: 8, 11.025, 12, 16 kHz.
Now 8, 11.025, 12, 16, 22.05, 24, 42, 44.1, 48 Khz are supported.
Unsupported samplerates are sanitized to the closest samplerate for all encoders.
Samplerates < 32 kHz are now forbidden for AC3 encoding (sanitized to 32 kHz). Most AC3 decoders don't support such samplerates.
New upmixing: 3.0 (Front Left, Right & Center) can now be upmixed to 5.1 to preserve the center channel.
New mixdowns:
6.1 (Front Left, Right & Center, Surround Left, Right & Center, LFE)
7.1 (Front Left, Right & Center, Surround Left & Right, Rear Left & Right, LFE)
-> available to Vorbis & FLAC encoders for compatible input channel layouts
7.1 (Front Left, Right & Center, Front Left & Right of Center, Surround Left & Right, LFE)
-> available to AAC encoders (ca_aac, ca_haac, faac) for compatible input channel layouts
Mono (Left Only): Stereo to Mono by discarding the Right channel
Mono (Right Only): Stereo to Mono by discarding the Left channel
-> available to all encoders for non-Dolby Stereo input
The "6-channel discrete" mixdown becomes "5.1 Channels".
New bitrates: 960 - 1536 Kbps.
This lets users work around poor audio quality in crappy encoders by throwing more bits at them.
Bitrate limits have been re-worked and re-tested for all encoders.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4930 b64f7644-9d1e-0410-96f1-a4d463321fa5
2012-09-03 12:37:16 +00:00
|
|
|
int out_size, out_samples;
|
2012-07-15 16:40:46 +00:00
|
|
|
|
|
|
|
if (resample->resample_needed)
|
|
|
|
{
|
2019-08-11 10:35:58 -07:00
|
|
|
out_samples = nsamples * resample->out.sample_rate /
|
|
|
|
resample->in.sample_rate + 1;
|
2024-04-11 08:23:26 +02:00
|
|
|
out_size = av_samples_get_buffer_size(NULL, resample->out.ch_layout.nb_channels,
|
2019-05-30 08:45:13 -07:00
|
|
|
out_samples,
|
2012-07-15 16:40:46 +00:00
|
|
|
resample->out.sample_fmt, 0);
|
|
|
|
out = hb_buffer_init(out_size);
|
2019-05-30 08:45:13 -07:00
|
|
|
out_samples = swr_convert(resample->swresample, &out->data, out_samples,
|
2018-06-14 17:20:58 -07:00
|
|
|
samples, nsamples);
|
2012-07-15 16:40:46 +00:00
|
|
|
|
2012-08-15 15:43:33 +00:00
|
|
|
if (out_samples <= 0)
|
2012-07-15 16:40:46 +00:00
|
|
|
{
|
2012-08-15 15:43:33 +00:00
|
|
|
if (out_samples < 0)
|
2019-08-11 10:35:58 -07:00
|
|
|
{
|
2018-06-14 17:20:58 -07:00
|
|
|
hb_log("hb_audio_resample: swr_convert() failed");
|
2019-08-11 10:35:58 -07:00
|
|
|
}
|
2012-08-15 15:43:33 +00:00
|
|
|
// don't send empty buffers downstream (EOF)
|
2012-07-15 16:40:46 +00:00
|
|
|
hb_buffer_close(&out);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
out->size = (out_samples *
|
2024-03-22 08:31:57 +01:00
|
|
|
resample->out.sample_size * resample->out.ch_layout.nb_channels);
|
2012-07-15 16:40:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
Audio improvements.
New supported samplerates: 8, 11.025, 12, 16 kHz.
Now 8, 11.025, 12, 16, 22.05, 24, 42, 44.1, 48 Khz are supported.
Unsupported samplerates are sanitized to the closest samplerate for all encoders.
Samplerates < 32 kHz are now forbidden for AC3 encoding (sanitized to 32 kHz). Most AC3 decoders don't support such samplerates.
New upmixing: 3.0 (Front Left, Right & Center) can now be upmixed to 5.1 to preserve the center channel.
New mixdowns:
6.1 (Front Left, Right & Center, Surround Left, Right & Center, LFE)
7.1 (Front Left, Right & Center, Surround Left & Right, Rear Left & Right, LFE)
-> available to Vorbis & FLAC encoders for compatible input channel layouts
7.1 (Front Left, Right & Center, Front Left & Right of Center, Surround Left & Right, LFE)
-> available to AAC encoders (ca_aac, ca_haac, faac) for compatible input channel layouts
Mono (Left Only): Stereo to Mono by discarding the Right channel
Mono (Right Only): Stereo to Mono by discarding the Left channel
-> available to all encoders for non-Dolby Stereo input
The "6-channel discrete" mixdown becomes "5.1 Channels".
New bitrates: 960 - 1536 Kbps.
This lets users work around poor audio quality in crappy encoders by throwing more bits at them.
Bitrate limits have been re-worked and re-tested for all encoders.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4930 b64f7644-9d1e-0410-96f1-a4d463321fa5
2012-09-03 12:37:16 +00:00
|
|
|
out_samples = nsamples;
|
|
|
|
out_size = (out_samples *
|
2024-03-22 08:31:57 +01:00
|
|
|
resample->out.sample_size * resample->out.ch_layout.nb_channels);
|
2012-07-15 16:40:46 +00:00
|
|
|
out = hb_buffer_init(out_size);
|
2012-11-21 18:29:34 +00:00
|
|
|
memcpy(out->data, samples[0], out_size);
|
2012-07-15 16:40:46 +00:00
|
|
|
}
|
|
|
|
|
2012-11-21 18:29:34 +00:00
|
|
|
/*
|
|
|
|
* Dual Mono to Mono.
|
Audio improvements.
New supported samplerates: 8, 11.025, 12, 16 kHz.
Now 8, 11.025, 12, 16, 22.05, 24, 42, 44.1, 48 Khz are supported.
Unsupported samplerates are sanitized to the closest samplerate for all encoders.
Samplerates < 32 kHz are now forbidden for AC3 encoding (sanitized to 32 kHz). Most AC3 decoders don't support such samplerates.
New upmixing: 3.0 (Front Left, Right & Center) can now be upmixed to 5.1 to preserve the center channel.
New mixdowns:
6.1 (Front Left, Right & Center, Surround Left, Right & Center, LFE)
7.1 (Front Left, Right & Center, Surround Left & Right, Rear Left & Right, LFE)
-> available to Vorbis & FLAC encoders for compatible input channel layouts
7.1 (Front Left, Right & Center, Front Left & Right of Center, Surround Left & Right, LFE)
-> available to AAC encoders (ca_aac, ca_haac, faac) for compatible input channel layouts
Mono (Left Only): Stereo to Mono by discarding the Right channel
Mono (Right Only): Stereo to Mono by discarding the Left channel
-> available to all encoders for non-Dolby Stereo input
The "6-channel discrete" mixdown becomes "5.1 Channels".
New bitrates: 960 - 1536 Kbps.
This lets users work around poor audio quality in crappy encoders by throwing more bits at them.
Bitrate limits have been re-worked and re-tested for all encoders.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4930 b64f7644-9d1e-0410-96f1-a4d463321fa5
2012-09-03 12:37:16 +00:00
|
|
|
*
|
2012-11-21 18:29:34 +00:00
|
|
|
* Copy all left or right samples to the first half of the buffer and halve
|
|
|
|
* the buffer size.
|
|
|
|
*/
|
Audio improvements.
New supported samplerates: 8, 11.025, 12, 16 kHz.
Now 8, 11.025, 12, 16, 22.05, 24, 42, 44.1, 48 Khz are supported.
Unsupported samplerates are sanitized to the closest samplerate for all encoders.
Samplerates < 32 kHz are now forbidden for AC3 encoding (sanitized to 32 kHz). Most AC3 decoders don't support such samplerates.
New upmixing: 3.0 (Front Left, Right & Center) can now be upmixed to 5.1 to preserve the center channel.
New mixdowns:
6.1 (Front Left, Right & Center, Surround Left, Right & Center, LFE)
7.1 (Front Left, Right & Center, Surround Left & Right, Rear Left & Right, LFE)
-> available to Vorbis & FLAC encoders for compatible input channel layouts
7.1 (Front Left, Right & Center, Front Left & Right of Center, Surround Left & Right, LFE)
-> available to AAC encoders (ca_aac, ca_haac, faac) for compatible input channel layouts
Mono (Left Only): Stereo to Mono by discarding the Right channel
Mono (Right Only): Stereo to Mono by discarding the Left channel
-> available to all encoders for non-Dolby Stereo input
The "6-channel discrete" mixdown becomes "5.1 Channels".
New bitrates: 960 - 1536 Kbps.
This lets users work around poor audio quality in crappy encoders by throwing more bits at them.
Bitrate limits have been re-worked and re-tested for all encoders.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4930 b64f7644-9d1e-0410-96f1-a4d463321fa5
2012-09-03 12:37:16 +00:00
|
|
|
if (resample->dual_mono_downmix)
|
|
|
|
{
|
2012-11-21 18:29:34 +00:00
|
|
|
int ii, jj = !!resample->dual_mono_right_only;
|
|
|
|
int sample_size = resample->out.sample_size;
|
|
|
|
uint8_t *audio_samples = out->data;
|
Audio improvements.
New supported samplerates: 8, 11.025, 12, 16 kHz.
Now 8, 11.025, 12, 16, 22.05, 24, 42, 44.1, 48 Khz are supported.
Unsupported samplerates are sanitized to the closest samplerate for all encoders.
Samplerates < 32 kHz are now forbidden for AC3 encoding (sanitized to 32 kHz). Most AC3 decoders don't support such samplerates.
New upmixing: 3.0 (Front Left, Right & Center) can now be upmixed to 5.1 to preserve the center channel.
New mixdowns:
6.1 (Front Left, Right & Center, Surround Left, Right & Center, LFE)
7.1 (Front Left, Right & Center, Surround Left & Right, Rear Left & Right, LFE)
-> available to Vorbis & FLAC encoders for compatible input channel layouts
7.1 (Front Left, Right & Center, Front Left & Right of Center, Surround Left & Right, LFE)
-> available to AAC encoders (ca_aac, ca_haac, faac) for compatible input channel layouts
Mono (Left Only): Stereo to Mono by discarding the Right channel
Mono (Right Only): Stereo to Mono by discarding the Left channel
-> available to all encoders for non-Dolby Stereo input
The "6-channel discrete" mixdown becomes "5.1 Channels".
New bitrates: 960 - 1536 Kbps.
This lets users work around poor audio quality in crappy encoders by throwing more bits at them.
Bitrate limits have been re-worked and re-tested for all encoders.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4930 b64f7644-9d1e-0410-96f1-a4d463321fa5
2012-09-03 12:37:16 +00:00
|
|
|
for (ii = 0; ii < out_samples; ii++)
|
|
|
|
{
|
2012-11-21 18:29:34 +00:00
|
|
|
memcpy(audio_samples + (ii * sample_size),
|
|
|
|
audio_samples + (jj * sample_size), sample_size);
|
Audio improvements.
New supported samplerates: 8, 11.025, 12, 16 kHz.
Now 8, 11.025, 12, 16, 22.05, 24, 42, 44.1, 48 Khz are supported.
Unsupported samplerates are sanitized to the closest samplerate for all encoders.
Samplerates < 32 kHz are now forbidden for AC3 encoding (sanitized to 32 kHz). Most AC3 decoders don't support such samplerates.
New upmixing: 3.0 (Front Left, Right & Center) can now be upmixed to 5.1 to preserve the center channel.
New mixdowns:
6.1 (Front Left, Right & Center, Surround Left, Right & Center, LFE)
7.1 (Front Left, Right & Center, Surround Left & Right, Rear Left & Right, LFE)
-> available to Vorbis & FLAC encoders for compatible input channel layouts
7.1 (Front Left, Right & Center, Front Left & Right of Center, Surround Left & Right, LFE)
-> available to AAC encoders (ca_aac, ca_haac, faac) for compatible input channel layouts
Mono (Left Only): Stereo to Mono by discarding the Right channel
Mono (Right Only): Stereo to Mono by discarding the Left channel
-> available to all encoders for non-Dolby Stereo input
The "6-channel discrete" mixdown becomes "5.1 Channels".
New bitrates: 960 - 1536 Kbps.
This lets users work around poor audio quality in crappy encoders by throwing more bits at them.
Bitrate limits have been re-worked and re-tested for all encoders.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4930 b64f7644-9d1e-0410-96f1-a4d463321fa5
2012-09-03 12:37:16 +00:00
|
|
|
jj += 2;
|
|
|
|
}
|
2012-11-21 18:29:34 +00:00
|
|
|
out->size = out_samples * sample_size;
|
Audio improvements.
New supported samplerates: 8, 11.025, 12, 16 kHz.
Now 8, 11.025, 12, 16, 22.05, 24, 42, 44.1, 48 Khz are supported.
Unsupported samplerates are sanitized to the closest samplerate for all encoders.
Samplerates < 32 kHz are now forbidden for AC3 encoding (sanitized to 32 kHz). Most AC3 decoders don't support such samplerates.
New upmixing: 3.0 (Front Left, Right & Center) can now be upmixed to 5.1 to preserve the center channel.
New mixdowns:
6.1 (Front Left, Right & Center, Surround Left, Right & Center, LFE)
7.1 (Front Left, Right & Center, Surround Left & Right, Rear Left & Right, LFE)
-> available to Vorbis & FLAC encoders for compatible input channel layouts
7.1 (Front Left, Right & Center, Front Left & Right of Center, Surround Left & Right, LFE)
-> available to AAC encoders (ca_aac, ca_haac, faac) for compatible input channel layouts
Mono (Left Only): Stereo to Mono by discarding the Right channel
Mono (Right Only): Stereo to Mono by discarding the Left channel
-> available to all encoders for non-Dolby Stereo input
The "6-channel discrete" mixdown becomes "5.1 Channels".
New bitrates: 960 - 1536 Kbps.
This lets users work around poor audio quality in crappy encoders by throwing more bits at them.
Bitrate limits have been re-worked and re-tested for all encoders.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4930 b64f7644-9d1e-0410-96f1-a4d463321fa5
2012-09-03 12:37:16 +00:00
|
|
|
}
|
2019-08-11 10:35:58 -07:00
|
|
|
out->s.duration = 90000. * out_samples / resample->out.sample_rate;
|
Audio improvements.
New supported samplerates: 8, 11.025, 12, 16 kHz.
Now 8, 11.025, 12, 16, 22.05, 24, 42, 44.1, 48 Khz are supported.
Unsupported samplerates are sanitized to the closest samplerate for all encoders.
Samplerates < 32 kHz are now forbidden for AC3 encoding (sanitized to 32 kHz). Most AC3 decoders don't support such samplerates.
New upmixing: 3.0 (Front Left, Right & Center) can now be upmixed to 5.1 to preserve the center channel.
New mixdowns:
6.1 (Front Left, Right & Center, Surround Left, Right & Center, LFE)
7.1 (Front Left, Right & Center, Surround Left & Right, Rear Left & Right, LFE)
-> available to Vorbis & FLAC encoders for compatible input channel layouts
7.1 (Front Left, Right & Center, Front Left & Right of Center, Surround Left & Right, LFE)
-> available to AAC encoders (ca_aac, ca_haac, faac) for compatible input channel layouts
Mono (Left Only): Stereo to Mono by discarding the Right channel
Mono (Right Only): Stereo to Mono by discarding the Left channel
-> available to all encoders for non-Dolby Stereo input
The "6-channel discrete" mixdown becomes "5.1 Channels".
New bitrates: 960 - 1536 Kbps.
This lets users work around poor audio quality in crappy encoders by throwing more bits at them.
Bitrate limits have been re-worked and re-tested for all encoders.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4930 b64f7644-9d1e-0410-96f1-a4d463321fa5
2012-09-03 12:37:16 +00:00
|
|
|
|
2012-07-15 16:40:46 +00:00
|
|
|
return out;
|
|
|
|
}
|