3 * Copyright (c) 2003-2015 HandBrake Team
4 * This file is part of the HandBrake source code
5 * Homepage: <http://handbrake.fr/>
6 * It may be used under the terms of the GNU General Public License v2.
7 * For full terms see the file COPYING file or visit http://www.gnu.org/licenses/gpl-2.0.html
10 /* Implements a libavresample wrapper for convenience.
12 * Supports sample_fmt and channel_layout conversion.
14 * sample_rate conversion will come later (libavresample doesn't support
15 * sample_rate conversion with float samples yet). */
17 #ifndef AUDIO_RESAMPLE_H
18 #define AUDIO_RESAMPLE_H
22 #include "libavutil/channel_layout.h"
23 #include "libavresample/avresample.h"
25 /* Default mix level for center and surround channels */
26 #define HB_MIXLEV_DEFAULT ((double)M_SQRT1_2)
27 /* Default mix level for LFE channel */
28 #define HB_MIXLEV_ZERO ((double)0.0)
32 int dual_mono_downmix
;
33 int dual_mono_right_only
;
36 AVAudioResampleContext
*avresample
;
40 uint64_t channel_layout
;
42 double center_mix_level
;
43 double surround_mix_level
;
44 enum AVSampleFormat sample_fmt
;
50 uint64_t channel_layout
;
52 double center_mix_level
;
53 double surround_mix_level
;
54 enum AVSampleFormat sample_fmt
;
61 int normalize_mix_level
;
62 uint64_t channel_layout
;
63 enum AVSampleFormat sample_fmt
;
64 enum AVMatrixEncoding matrix_encoding
;
66 } hb_audio_resample_t
;
68 /* Initialize an hb_audio_resample_t for converting audio to the requested
69 * sample_fmt and mixdown.
71 * Also sets the default audio input characteristics, so that they are the same
72 * as the output characteristics (no conversion needed).
74 hb_audio_resample_t
* hb_audio_resample_init(enum AVSampleFormat sample_fmt
,
75 int hb_amixdown
, int normalize_mix
);
77 /* The following functions set the audio input characteristics.
79 * They should be called whenever the relevant characteristic(s) differ from the
80 * requested output characteristics, or if they may have changed in the source.
83 void hb_audio_resample_set_channel_layout(hb_audio_resample_t
*resample
,
84 uint64_t channel_layout
);
86 void hb_audio_resample_set_mix_levels(hb_audio_resample_t
*resample
,
87 double surround_mix_level
,
88 double center_mix_level
,
89 double lfe_mix_level
);
91 void hb_audio_resample_set_sample_fmt(hb_audio_resample_t
*resample
,
92 enum AVSampleFormat sample_fmt
);
94 /* Update an hb_audio_resample_t.
96 * Must be called after using any of the above functions.
98 int hb_audio_resample_update(hb_audio_resample_t
*resample
);
100 /* Free an hb_audio_remsample_t. */
101 void hb_audio_resample_free(hb_audio_resample_t
*resample
);
103 /* Convert input samples to the requested output characteristics
104 * (sample_fmt and channel_layout + matrix_encoding).
106 * Returns an hb_buffer_t with the converted output.
108 * resampling is only done when necessary.
110 hb_buffer_t
* hb_audio_resample(hb_audio_resample_t
*resample
,
111 uint8_t **samples
, int nsamples
);
113 #endif /* AUDIO_RESAMPLE_H */