MCPcopy Create free account
hub / github.com/HandBrake/HandBrake / hb_audio_resample_init

Function hb_audio_resample_init

libhb/audio_resample.c:14–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12#include "handbrake/audio_resample.h"
13
14hb_audio_resample_t* hb_audio_resample_init(enum AVSampleFormat sample_fmt,
15 int sample_rate,
16 int hb_amixdown, int normalize_mix)
17{
18 hb_audio_resample_t *resample = calloc(1, sizeof(hb_audio_resample_t));
19 if (resample == NULL)
20 {
21 hb_error("hb_audio_resample_init: failed to allocate resample");
22 goto fail;
23 }
24
25 // swresample context, initialized in hb_audio_resample_update()
26 resample->swresample = NULL;
27
28 // we don't support planar output yet
29 if (av_sample_fmt_is_planar(sample_fmt))
30 {
31 hb_error("hb_audio_resample_init: planar output not supported ('%s')",
32 av_get_sample_fmt_name(sample_fmt));
33 goto fail;
34 }
35
36 // convert mixdown to channel_layout/matrix_encoding combo
37 int matrix_encoding;
38 uint64_t channel_layout = hb_ff_mixdown_xlat(hb_amixdown, &matrix_encoding);
39
40 /*
41 * When downmixing, Dual Mono to Mono is a special case:
42 * the audio must remain 2-channel until all conversions are done.
43 */
44 if (hb_amixdown == HB_AMIXDOWN_LEFT || hb_amixdown == HB_AMIXDOWN_RIGHT)
45 {
46 channel_layout = AV_CH_LAYOUT_STEREO;
47 resample->dual_mono_downmix = 1;
48 resample->dual_mono_right_only = (hb_amixdown == HB_AMIXDOWN_RIGHT);
49 }
50 else
51 {
52 resample->dual_mono_downmix = 0;
53 }
54
55 // requested output channel_layout, sample_fmt
56 av_channel_layout_from_mask(&resample->out.ch_layout, channel_layout);
57 resample->out.matrix_encoding = matrix_encoding;
58 resample->out.sample_fmt = sample_fmt;
59 resample->out.sample_rate = sample_rate;
60 if (normalize_mix)
61 {
62 resample->out.maxval = 1.0;
63 }
64 else
65 {
66 resample->out.maxval = 1000;
67 }
68 resample->out.sample_size = av_get_bytes_per_sample(sample_fmt);
69
70 // set default input characteristics
71 resample->in.sample_fmt = resample->out.sample_fmt;

Callers 3

InitAudioFunction · 0.85
declpcmInitFunction · 0.85
decavcodecaInitFunction · 0.85

Calls 3

hb_errorFunction · 0.85
hb_ff_mixdown_xlatFunction · 0.85
hb_audio_resample_freeFunction · 0.85

Tested by

no test coverage detected