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
1313
1414 API changes, most recent first:
1515
16+2012-xx-xx - xxxxxxx - lavr 0.0.3
17+ Add a parameter to avresample_build_matrix() for Dolby/DPLII downmixing.
18+
1619 2012-xx-xx - xxxxxxx - lavfi 2.23.0 - avfilter.h
1720 Add AVFilterContext.nb_inputs/outputs. Deprecate
1821 AVFilterContext.input/output_count.
libavresample/audio_mix.c+2−1
@@ -320,7 +320,8 @@ int ff_audio_mix_init(AVAudioResampleContext *avr) · 319 unmodified lines
320320 avr->center_mix_level,
321321 avr->surround_mix_level,
322322 avr->lfe_mix_level, 1, matrix_dbl,
323− avr->in_channels);
323+ avr->in_channels,
324+ avr->matrix_encoding);
324325 if (ret < 0) {
325326 av_free(matrix_dbl);
326327 return ret;
libavresample/audio_mix_matrix.c+52−8
@@ -54,6 +54,8 @@ · 53 unmodified lines
5454 #define SURROUND_DIRECT_LEFT 33
5555 #define SURROUND_DIRECT_RIGHT 34
5656
57+#define SQRT3_2 1.22474487139158904909 /* sqrt(3/2) */
58+
5759 static av_always_inline int even(uint64_t layout)
5860 {
5961 return (!layout || (layout & (layout - 1)));
@@ -83,14 +85,21 @@ static int sane_layout(uint64_t layout) · 23 unmodified lines
8385 int avresample_build_matrix(uint64_t in_layout, uint64_t out_layout,
8486 double center_mix_level, double surround_mix_level,
8587 double lfe_mix_level, int normalize,
86− double *matrix_out, int stride)
88+ double *matrix_out, int stride,
89+ enum AVMatrixEncoding matrix_encoding)
8790 {
8891 int i, j, out_i, out_j;
8992 double matrix[64][64] = {{0}};
90− int64_t unaccounted = in_layout & ~out_layout;
93+ int64_t unaccounted;
9194 double maxcoef = 0;
9295 int in_channels, out_channels;
9396
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+
94103 in_channels = av_get_channel_layout_nb_channels( in_layout);
95104 out_channels = av_get_channel_layout_nb_channels(out_layout);
96105
@@ -140,8 +149,19 @@ int avresample_build_matrix(uint64_t in_layout, uint64_t out_layout, · 43 unmodified lines
140149 matrix[SIDE_LEFT ][BACK_CENTER] += M_SQRT1_2;
141150 matrix[SIDE_RIGHT][BACK_CENTER] += M_SQRT1_2;
142151 } else if (out_layout & AV_CH_FRONT_LEFT) {
143− matrix[FRONT_LEFT ][BACK_CENTER] += surround_mix_level * M_SQRT1_2;
144− matrix[FRONT_RIGHT][BACK_CENTER] += surround_mix_level * M_SQRT1_2;
152+ if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY ||
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+ }
145165 } else if (out_layout & AV_CH_FRONT_CENTER) {
146166 matrix[FRONT_CENTER][BACK_CENTER] += surround_mix_level * M_SQRT1_2;
147167 } else
@@ -163,8 +183,20 @@ int avresample_build_matrix(uint64_t in_layout, uint64_t out_layout, · 15 unmodified lines
163183 matrix[SIDE_RIGHT][BACK_RIGHT] += 1.0;
164184 }
165185 } else if (out_layout & AV_CH_FRONT_LEFT) {
166− matrix[FRONT_LEFT ][BACK_LEFT ] += surround_mix_level;
167− matrix[FRONT_RIGHT][BACK_RIGHT] += surround_mix_level;
186+ if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
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+ }
168200 } else if (out_layout & AV_CH_FRONT_CENTER) {
169201 matrix[FRONT_CENTER][BACK_LEFT ] += surround_mix_level * M_SQRT1_2;
170202 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
187219 matrix[BACK_CENTER][SIDE_LEFT ] += M_SQRT1_2;
188220 matrix[BACK_CENTER][SIDE_RIGHT] += M_SQRT1_2;
189221 } else if (out_layout & AV_CH_FRONT_LEFT) {
190− matrix[FRONT_LEFT ][SIDE_LEFT ] += surround_mix_level;
191− matrix[FRONT_RIGHT][SIDE_RIGHT] += surround_mix_level;
222+ if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
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+ }
192236 } else if (out_layout & AV_CH_FRONT_CENTER) {
193237 matrix[FRONT_CENTER][SIDE_LEFT ] += surround_mix_level * M_SQRT1_2;
194238 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
131131 * the weight of input channel i in output channel o.
132132 * @param stride distance between adjacent input channels in the
133133 * matrix array
134+ * @param matrix_encoding matrixed stereo downmix mode (e.g. dplii)
134135 * @return 0 on success, negative AVERROR code on failure
135136 */
136137 int avresample_build_matrix(uint64_t in_layout, uint64_t out_layout,
137138 double center_mix_level, double surround_mix_level,
138139 double lfe_mix_level, int normalize, double *matrix,
139− int stride);
140+ int stride, enum AVMatrixEncoding matrix_encoding);
140141
141142 /**
142143 * Get the current channel mixing matrix.
libavresample/internal.h+1−0
@@ -70,6 +70,7 @@ struct AVAudioResampleContext { · 69 unmodified lines
7070 AudioConvert *ac_out; /**< output sample format conversion context */
7171 ResampleContext *resample; /**< resampling context */
7272 AudioMix *am; /**< channel mixing context */
73+ enum AVMatrixEncoding matrix_encoding; /**< matrixed stereo encoding */
7374 };
7475
7576 #endif /* AVRESAMPLE_INTERNAL_H */
libavresample/options.c+4−0
@@ -52,6 +52,10 @@ static const AVOption options[] = { · 51 unmodified lines
5252 { "phase_shift", "Resampling Phase Shift", OFFSET(phase_shift), AV_OPT_TYPE_INT, { 10 }, 0, 30, /* ??? */ PARAM },
5353 { "linear_interp", "Use Linear Interpolation", OFFSET(linear_interp), AV_OPT_TYPE_INT, { 0 }, 0, 1, PARAM },
5454 { "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" },
5559 { NULL },
5660 };
5761
libavresample/version.h+1−1
@@ -21,7 +21,7 @@ · 20 unmodified lines
2121
2222 #define LIBAVRESAMPLE_VERSION_MAJOR 0
2323 #define LIBAVRESAMPLE_VERSION_MINOR 0
24−#define LIBAVRESAMPLE_VERSION_MICRO 2
24+#define LIBAVRESAMPLE_VERSION_MICRO 3
2525
2626 #define LIBAVRESAMPLE_VERSION_INT AV_VERSION_INT(LIBAVRESAMPLE_VERSION_MAJOR, \
2727 LIBAVRESAMPLE_VERSION_MINOR, \
libavutil/audioconvert.h+7−0
@@ -101,6 +101,13 @@ · 100 unmodified lines
101101 #define AV_CH_LAYOUT_OCTAGONAL (AV_CH_LAYOUT_5POINT0|AV_CH_BACK_LEFT|AV_CH_BACK_CENTER|AV_CH_BACK_RIGHT)
102102 #define AV_CH_LAYOUT_STEREO_DOWNMIX (AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT)
103103
104+enum AVMatrixEncoding {
105+ AV_MATRIX_ENCODING_NONE,
106+ AV_MATRIX_ENCODING_DOLBY,
107+ AV_MATRIX_ENCODING_DPLII,
108+ AV_MATRIX_ENCODING_NB
109+};
110+
104111 /**
105112 * @}
106113 */

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