History

Add Dolby/DPLII downmix support to libavresample

John Stebbins committed 14 years ago

Commit 3971be01 parent 9fcda258 files · +72 −11Browse files

Unified · Split

8 files
  1. doc/APIchanges +3 −0
  2. libavresample/audio_mix.c +2 −1
  3. libavresample/audio_mix_matrix.c +52 −8
  4. libavresample/avresample.h +2 −1
  5. libavresample/internal.h +1 −0
  6. libavresample/options.c +4 −0
  7. libavresample/version.h +1 −1
  8. libavutil/audioconvert.h +7 −0
doc/APIchanges+3−0
@@ -13,6 +13,9 @@ libavutil: 2011-04-18 · 12 unmodified lines
13 13
14API changes, most recent first:14API changes, most recent first:
15 15
162012-xx-xx - xxxxxxx - lavr 0.0.3
17 Add a parameter to avresample_build_matrix() for Dolby/DPLII downmixing.
18
162012-xx-xx - xxxxxxx - lavfi 2.23.0 - avfilter.h192012-xx-xx - xxxxxxx - lavfi 2.23.0 - avfilter.h
17 Add AVFilterContext.nb_inputs/outputs. Deprecate20 Add AVFilterContext.nb_inputs/outputs. Deprecate
18 AVFilterContext.input/output_count.21 AVFilterContext.input/output_count.
libavresample/audio_mix.c+2−1
@@ -320,7 +320,8 @@ int ff_audio_mix_init(AVAudioResampleContext *avr) · 319 unmodified lines
320 avr->center_mix_level,320 avr->center_mix_level,
321 avr->surround_mix_level,321 avr->surround_mix_level,
322 avr->lfe_mix_level, 1, matrix_dbl,322 avr->lfe_mix_level, 1, matrix_dbl,
323 avr->in_channels);323 avr->in_channels,
324 avr->matrix_encoding);
324 if (ret < 0) {325 if (ret < 0) {
325 av_free(matrix_dbl);326 av_free(matrix_dbl);
326 return ret;327 return ret;
libavresample/audio_mix_matrix.c+52−8
@@ -54,6 +54,8 @@ · 53 unmodified lines
54#define SURROUND_DIRECT_LEFT 3354#define SURROUND_DIRECT_LEFT 33
55#define SURROUND_DIRECT_RIGHT 3455#define SURROUND_DIRECT_RIGHT 34
56 56
57#define SQRT3_2 1.22474487139158904909 /* sqrt(3/2) */
58
57static av_always_inline int even(uint64_t layout)59static av_always_inline int even(uint64_t layout)
58{60{
59 return (!layout || (layout & (layout - 1)));61 return (!layout || (layout & (layout - 1)));
@@ -83,14 +85,21 @@ static int sane_layout(uint64_t layout) · 23 unmodified lines
83int avresample_build_matrix(uint64_t in_layout, uint64_t out_layout,85int avresample_build_matrix(uint64_t in_layout, uint64_t out_layout,
84 double center_mix_level, double surround_mix_level,86 double center_mix_level, double surround_mix_level,
85 double lfe_mix_level, int normalize,87 double lfe_mix_level, int normalize,
86 double *matrix_out, int stride)88 double *matrix_out, int stride,
89 enum AVMatrixEncoding matrix_encoding)
87{90{
88 int i, j, out_i, out_j;91 int i, j, out_i, out_j;
89 double matrix[64][64] = {{0}};92 double matrix[64][64] = {{0}};
90 int64_t unaccounted = in_layout & ~out_layout;93 int64_t unaccounted;
91 double maxcoef = 0;94 double maxcoef = 0;
92 int in_channels, out_channels;95 int in_channels, out_channels;
93 96
97 if ((out_layout & AV_CH_LAYOUT_STEREO_DOWNMIX) == AV_CH_LAYOUT_STEREO_DOWNMIX) {
98 out_layout = AV_CH_LAYOUT_STEREO;
99 }
100
101 unaccounted = in_layout & ~out_layout;
102
94 in_channels = av_get_channel_layout_nb_channels( in_layout);103 in_channels = av_get_channel_layout_nb_channels( in_layout);
95 out_channels = av_get_channel_layout_nb_channels(out_layout);104 out_channels = av_get_channel_layout_nb_channels(out_layout);
96 105
@@ -140,8 +149,19 @@ int avresample_build_matrix(uint64_t in_layout, uint64_t out_layout, · 43 unmodified lines
140 matrix[SIDE_LEFT ][BACK_CENTER] += M_SQRT1_2;149 matrix[SIDE_LEFT ][BACK_CENTER] += M_SQRT1_2;
141 matrix[SIDE_RIGHT][BACK_CENTER] += M_SQRT1_2;150 matrix[SIDE_RIGHT][BACK_CENTER] += M_SQRT1_2;
142 } else if (out_layout & AV_CH_FRONT_LEFT) {151 } else if (out_layout & AV_CH_FRONT_LEFT) {
143 matrix[FRONT_LEFT ][BACK_CENTER] += surround_mix_level * M_SQRT1_2;152 if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY ||
144 matrix[FRONT_RIGHT][BACK_CENTER] += surround_mix_level * M_SQRT1_2;153 matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
154 if (unaccounted & (AV_CH_BACK_LEFT | AV_CH_SIDE_LEFT)) {
155 matrix[FRONT_LEFT ][BACK_CENTER] -= surround_mix_level * M_SQRT1_2;
156 matrix[FRONT_RIGHT][BACK_CENTER] += surround_mix_level * M_SQRT1_2;
157 } else {
158 matrix[FRONT_LEFT ][BACK_CENTER] -= surround_mix_level;
159 matrix[FRONT_RIGHT][BACK_CENTER] += surround_mix_level;
160 }
161 } else {
162 matrix[FRONT_LEFT ][BACK_CENTER] += surround_mix_level * M_SQRT1_2;
163 matrix[FRONT_RIGHT][BACK_CENTER] += surround_mix_level * M_SQRT1_2;
164 }
145 } else if (out_layout & AV_CH_FRONT_CENTER) {165 } else if (out_layout & AV_CH_FRONT_CENTER) {
146 matrix[FRONT_CENTER][BACK_CENTER] += surround_mix_level * M_SQRT1_2;166 matrix[FRONT_CENTER][BACK_CENTER] += surround_mix_level * M_SQRT1_2;
147 } else167 } else
@@ -163,8 +183,20 @@ int avresample_build_matrix(uint64_t in_layout, uint64_t out_layout, · 15 unmodified lines
163 matrix[SIDE_RIGHT][BACK_RIGHT] += 1.0;183 matrix[SIDE_RIGHT][BACK_RIGHT] += 1.0;
164 }184 }
165 } else if (out_layout & AV_CH_FRONT_LEFT) {185 } else if (out_layout & AV_CH_FRONT_LEFT) {
166 matrix[FRONT_LEFT ][BACK_LEFT ] += surround_mix_level;186 if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
167 matrix[FRONT_RIGHT][BACK_RIGHT] += surround_mix_level;187 matrix[FRONT_LEFT ][BACK_LEFT ] -= surround_mix_level * M_SQRT1_2;
188 matrix[FRONT_LEFT ][BACK_RIGHT] -= surround_mix_level * M_SQRT1_2;
189 matrix[FRONT_RIGHT][BACK_LEFT ] += surround_mix_level * M_SQRT1_2;
190 matrix[FRONT_RIGHT][BACK_RIGHT] += surround_mix_level * M_SQRT1_2;
191 } else if (matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
192 matrix[FRONT_LEFT ][BACK_LEFT ] -= surround_mix_level * SQRT3_2;
193 matrix[FRONT_LEFT ][BACK_RIGHT] -= surround_mix_level * M_SQRT1_2;
194 matrix[FRONT_RIGHT][BACK_LEFT ] += surround_mix_level * M_SQRT1_2;
195 matrix[FRONT_RIGHT][BACK_RIGHT] += surround_mix_level * SQRT3_2;
196 } else {
197 matrix[FRONT_LEFT ][BACK_LEFT ] += surround_mix_level;
198 matrix[FRONT_RIGHT][BACK_RIGHT] += surround_mix_level;
199 }
168 } else if (out_layout & AV_CH_FRONT_CENTER) {200 } else if (out_layout & AV_CH_FRONT_CENTER) {
169 matrix[FRONT_CENTER][BACK_LEFT ] += surround_mix_level * M_SQRT1_2;201 matrix[FRONT_CENTER][BACK_LEFT ] += surround_mix_level * M_SQRT1_2;
170 matrix[FRONT_CENTER][BACK_RIGHT] += surround_mix_level * M_SQRT1_2;202 matrix[FRONT_CENTER][BACK_RIGHT] += surround_mix_level * M_SQRT1_2;
@@ -187,8 +219,20 @@ int avresample_build_matrix(uint64_t in_layout, uint64_t out_layout, · 16 unmodified lines
187 matrix[BACK_CENTER][SIDE_LEFT ] += M_SQRT1_2;219 matrix[BACK_CENTER][SIDE_LEFT ] += M_SQRT1_2;
188 matrix[BACK_CENTER][SIDE_RIGHT] += M_SQRT1_2;220 matrix[BACK_CENTER][SIDE_RIGHT] += M_SQRT1_2;
189 } else if (out_layout & AV_CH_FRONT_LEFT) {221 } else if (out_layout & AV_CH_FRONT_LEFT) {
190 matrix[FRONT_LEFT ][SIDE_LEFT ] += surround_mix_level;222 if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
191 matrix[FRONT_RIGHT][SIDE_RIGHT] += surround_mix_level;223 matrix[FRONT_LEFT ][SIDE_LEFT ] -= surround_mix_level * M_SQRT1_2;
224 matrix[FRONT_LEFT ][SIDE_RIGHT] -= surround_mix_level * M_SQRT1_2;
225 matrix[FRONT_RIGHT][SIDE_LEFT ] += surround_mix_level * M_SQRT1_2;
226 matrix[FRONT_RIGHT][SIDE_RIGHT] += surround_mix_level * M_SQRT1_2;
227 } else if (matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
228 matrix[FRONT_LEFT ][SIDE_LEFT ] -= surround_mix_level * SQRT3_2;
229 matrix[FRONT_LEFT ][SIDE_RIGHT] -= surround_mix_level * M_SQRT1_2;
230 matrix[FRONT_RIGHT][SIDE_LEFT ] += surround_mix_level * M_SQRT1_2;
231 matrix[FRONT_RIGHT][SIDE_RIGHT] += surround_mix_level * SQRT3_2;
232 } else {
233 matrix[FRONT_LEFT ][SIDE_LEFT ] += surround_mix_level;
234 matrix[FRONT_RIGHT][SIDE_RIGHT] += surround_mix_level;
235 }
192 } else if (out_layout & AV_CH_FRONT_CENTER) {236 } else if (out_layout & AV_CH_FRONT_CENTER) {
193 matrix[FRONT_CENTER][SIDE_LEFT ] += surround_mix_level * M_SQRT1_2;237 matrix[FRONT_CENTER][SIDE_LEFT ] += surround_mix_level * M_SQRT1_2;
194 matrix[FRONT_CENTER][SIDE_RIGHT] += surround_mix_level * M_SQRT1_2;238 matrix[FRONT_CENTER][SIDE_RIGHT] += surround_mix_level * M_SQRT1_2;
libavresample/avresample.h+2−1
@@ -131,12 +131,13 @@ void avresample_free(AVAudioResampleContext **avr); · 130 unmodified lines
131 * the weight of input channel i in output channel o.131 * the weight of input channel i in output channel o.
132 * @param stride distance between adjacent input channels in the132 * @param stride distance between adjacent input channels in the
133 * matrix array133 * matrix array
134 * @param matrix_encoding matrixed stereo downmix mode (e.g. dplii)
134 * @return 0 on success, negative AVERROR code on failure135 * @return 0 on success, negative AVERROR code on failure
135 */136 */
136int avresample_build_matrix(uint64_t in_layout, uint64_t out_layout,137int avresample_build_matrix(uint64_t in_layout, uint64_t out_layout,
137 double center_mix_level, double surround_mix_level,138 double center_mix_level, double surround_mix_level,
138 double lfe_mix_level, int normalize, double *matrix,139 double lfe_mix_level, int normalize, double *matrix,
139 int stride);140 int stride, enum AVMatrixEncoding matrix_encoding);
140 141
141/**142/**
142 * Get the current channel mixing matrix.143 * Get the current channel mixing matrix.
libavresample/internal.h+1−0
@@ -70,6 +70,7 @@ struct AVAudioResampleContext { · 69 unmodified lines
70 AudioConvert *ac_out; /**< output sample format conversion context */70 AudioConvert *ac_out; /**< output sample format conversion context */
71 ResampleContext *resample; /**< resampling context */71 ResampleContext *resample; /**< resampling context */
72 AudioMix *am; /**< channel mixing context */72 AudioMix *am; /**< channel mixing context */
73 enum AVMatrixEncoding matrix_encoding; /**< matrixed stereo encoding */
73};74};
74 75
75#endif /* AVRESAMPLE_INTERNAL_H */76#endif /* AVRESAMPLE_INTERNAL_H */
libavresample/options.c+4−0
@@ -52,6 +52,10 @@ static const AVOption options[] = { · 51 unmodified lines
52 { "phase_shift", "Resampling Phase Shift", OFFSET(phase_shift), AV_OPT_TYPE_INT, { 10 }, 0, 30, /* ??? */ PARAM },52 { "phase_shift", "Resampling Phase Shift", OFFSET(phase_shift), AV_OPT_TYPE_INT, { 10 }, 0, 30, /* ??? */ PARAM },
53 { "linear_interp", "Use Linear Interpolation", OFFSET(linear_interp), AV_OPT_TYPE_INT, { 0 }, 0, 1, PARAM },53 { "linear_interp", "Use Linear Interpolation", OFFSET(linear_interp), AV_OPT_TYPE_INT, { 0 }, 0, 1, PARAM },
54 { "cutoff", "Cutoff Frequency Ratio", OFFSET(cutoff), AV_OPT_TYPE_DOUBLE, { 0.8 }, 0.0, 1.0, PARAM },54 { "cutoff", "Cutoff Frequency Ratio", OFFSET(cutoff), AV_OPT_TYPE_DOUBLE, { 0.8 }, 0.0, 1.0, PARAM },
55 { "matrix_encoding", "Matrixed Stereo Encoding", OFFSET(matrix_encoding), AV_OPT_TYPE_INT, { AV_MATRIX_ENCODING_NONE}, AV_MATRIX_ENCODING_NONE, AV_MATRIX_ENCODING_NB-1, PARAM, "matrix_encoding" },
56 { "none", "None", 0, AV_OPT_TYPE_CONST, { AV_MATRIX_ENCODING_NONE }, INT_MIN, INT_MAX, PARAM, "matrix_encoding" },
57 { "dolby", "Dolby", 0, AV_OPT_TYPE_CONST, { AV_MATRIX_ENCODING_DOLBY }, INT_MIN, INT_MAX, PARAM, "matrix_encoding" },
58 { "dplii", "Dolby Pro Logic II", 0, AV_OPT_TYPE_CONST, { AV_MATRIX_ENCODING_DPLII }, INT_MIN, INT_MAX, PARAM, "matrix_encoding" },
55 { NULL },59 { NULL },
56};60};
57 61
libavresample/version.h+1−1
@@ -21,7 +21,7 @@ · 20 unmodified lines
21 21
22#define LIBAVRESAMPLE_VERSION_MAJOR 022#define LIBAVRESAMPLE_VERSION_MAJOR 0
23#define LIBAVRESAMPLE_VERSION_MINOR 023#define LIBAVRESAMPLE_VERSION_MINOR 0
24#define LIBAVRESAMPLE_VERSION_MICRO 224#define LIBAVRESAMPLE_VERSION_MICRO 3
25 25
26#define LIBAVRESAMPLE_VERSION_INT AV_VERSION_INT(LIBAVRESAMPLE_VERSION_MAJOR, \26#define LIBAVRESAMPLE_VERSION_INT AV_VERSION_INT(LIBAVRESAMPLE_VERSION_MAJOR, \
27 LIBAVRESAMPLE_VERSION_MINOR, \27 LIBAVRESAMPLE_VERSION_MINOR, \
libavutil/audioconvert.h+7−0
@@ -101,6 +101,13 @@ · 100 unmodified lines
101#define AV_CH_LAYOUT_OCTAGONAL (AV_CH_LAYOUT_5POINT0|AV_CH_BACK_LEFT|AV_CH_BACK_CENTER|AV_CH_BACK_RIGHT)101#define AV_CH_LAYOUT_OCTAGONAL (AV_CH_LAYOUT_5POINT0|AV_CH_BACK_LEFT|AV_CH_BACK_CENTER|AV_CH_BACK_RIGHT)
102#define AV_CH_LAYOUT_STEREO_DOWNMIX (AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT)102#define AV_CH_LAYOUT_STEREO_DOWNMIX (AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT)
103 103
104enum AVMatrixEncoding {
105 AV_MATRIX_ENCODING_NONE,
106 AV_MATRIX_ENCODING_DOLBY,
107 AV_MATRIX_ENCODING_DPLII,
108 AV_MATRIX_ENCODING_NB
109};
110
104/**111/**
105 * @}112 * @}
106 */113 */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t