History

swr/auto_matrix: move layouts to local variables

Michael Niedermayer committed 14 years ago

Commit ebc854e1 parent 9ab538e1 file · +37 −35Browse files

Unified · Split

libswresample/rematrix.c+37−35
@@ -123,35 +123,37 @@ static int auto_matrix(SwrContext *s) · 122 unmodified lines
123123 {
124124 int i, j, out_i;
125125 double matrix[64][64]={{0}};
126− int64_t unaccounted= s->in_ch_layout & ~s->out_ch_layout;
126+ int64_t unaccounted, in_ch_layout = s->in_ch_layout, out_ch_layout = s->out_ch_layout;
127127 double maxcoef=0;
128128 char buf[128];
129129 const int matrix_encoding = s->matrix_encoding;
130130
131− memset(s->matrix, 0, sizeof(s->matrix));
132− for(i=0; i<64; i++){
133− if(s->in_ch_layout & s->out_ch_layout & (1LL<<i))
134− matrix[i][i]= 1.0;
135− }
136−
137− if(!sane_layout(s->in_ch_layout)){
131+ if(!sane_layout(in_ch_layout)){
138132 av_get_channel_layout_string(buf, sizeof(buf), -1, s->in_ch_layout);
139133 av_log(s, AV_LOG_ERROR, "Input channel layout '%s' is not supported\n", buf);
140134 return AVERROR(EINVAL);
141135 }
142− if(!sane_layout(s->out_ch_layout)){
136+ if(!sane_layout(out_ch_layout)){
143137 av_get_channel_layout_string(buf, sizeof(buf), -1, s->out_ch_layout);
144138 av_log(s, AV_LOG_ERROR, "Output channel layout '%s' is not supported\n", buf);
145139 return AVERROR(EINVAL);
146140 }
147141
142+ memset(s->matrix, 0, sizeof(s->matrix));
143+ for(i=0; i<64; i++){
144+ if(in_ch_layout & out_ch_layout & (1LL<<i))
145+ matrix[i][i]= 1.0;
146+ }
147+
148+ unaccounted= in_ch_layout & ~out_ch_layout;
149+
148150 //FIXME implement dolby surround
149151 //FIXME implement full ac3
150152
151153
152154 if(unaccounted & AV_CH_FRONT_CENTER){
153− if((s->out_ch_layout & AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO){
154− if(s->in_ch_layout & AV_CH_LAYOUT_STEREO) {
155+ if((out_ch_layout & AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO){
156+ if(in_ch_layout & AV_CH_LAYOUT_STEREO) {
155157 matrix[ FRONT_LEFT][FRONT_CENTER]+= s->clev;
156158 matrix[FRONT_RIGHT][FRONT_CENTER]+= s->clev;
157159 } else {
@@ -162,23 +164,23 @@ static int auto_matrix(SwrContext *s) · 4 unmodified lines
162164 av_assert0(0);
163165 }
164166 if(unaccounted & AV_CH_LAYOUT_STEREO){
165− if(s->out_ch_layout & AV_CH_FRONT_CENTER){
167+ if(out_ch_layout & AV_CH_FRONT_CENTER){
166168 matrix[FRONT_CENTER][ FRONT_LEFT]+= M_SQRT1_2;
167169 matrix[FRONT_CENTER][FRONT_RIGHT]+= M_SQRT1_2;
168− if(s->in_ch_layout & AV_CH_FRONT_CENTER)
170+ if(in_ch_layout & AV_CH_FRONT_CENTER)
169171 matrix[FRONT_CENTER][ FRONT_CENTER] = s->clev*sqrt(2);
170172 }else
171173 av_assert0(0);
172174 }
173175
174176 if(unaccounted & AV_CH_BACK_CENTER){
175− if(s->out_ch_layout & AV_CH_BACK_LEFT){
177+ if(out_ch_layout & AV_CH_BACK_LEFT){
176178 matrix[ BACK_LEFT][BACK_CENTER]+= M_SQRT1_2;
177179 matrix[BACK_RIGHT][BACK_CENTER]+= M_SQRT1_2;
178− }else if(s->out_ch_layout & AV_CH_SIDE_LEFT){
180+ }else if(out_ch_layout & AV_CH_SIDE_LEFT){
179181 matrix[ SIDE_LEFT][BACK_CENTER]+= M_SQRT1_2;
180182 matrix[SIDE_RIGHT][BACK_CENTER]+= M_SQRT1_2;
181− }else if(s->out_ch_layout & AV_CH_FRONT_LEFT){
183+ }else if(out_ch_layout & AV_CH_FRONT_LEFT){
182184 if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY ||
183185 matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
184186 if (unaccounted & (AV_CH_BACK_LEFT | AV_CH_SIDE_LEFT)) {
@@ -192,24 +194,24 @@ static int auto_matrix(SwrContext *s) · 7 unmodified lines
192194 matrix[ FRONT_LEFT][BACK_CENTER]+= s->slev*M_SQRT1_2;
193195 matrix[FRONT_RIGHT][BACK_CENTER]+= s->slev*M_SQRT1_2;
194196 }
195− }else if(s->out_ch_layout & AV_CH_FRONT_CENTER){
197+ }else if(out_ch_layout & AV_CH_FRONT_CENTER){
196198 matrix[ FRONT_CENTER][BACK_CENTER]+= s->slev*M_SQRT1_2;
197199 }else
198200 av_assert0(0);
199201 }
200202 if(unaccounted & AV_CH_BACK_LEFT){
201− if(s->out_ch_layout & AV_CH_BACK_CENTER){
203+ if(out_ch_layout & AV_CH_BACK_CENTER){
202204 matrix[BACK_CENTER][ BACK_LEFT]+= M_SQRT1_2;
203205 matrix[BACK_CENTER][BACK_RIGHT]+= M_SQRT1_2;
204− }else if(s->out_ch_layout & AV_CH_SIDE_LEFT){
205− if(s->in_ch_layout & AV_CH_SIDE_LEFT){
206+ }else if(out_ch_layout & AV_CH_SIDE_LEFT){
207+ if(in_ch_layout & AV_CH_SIDE_LEFT){
206208 matrix[ SIDE_LEFT][ BACK_LEFT]+= M_SQRT1_2;
207209 matrix[SIDE_RIGHT][BACK_RIGHT]+= M_SQRT1_2;
208210 }else{
209211 matrix[ SIDE_LEFT][ BACK_LEFT]+= 1.0;
210212 matrix[SIDE_RIGHT][BACK_RIGHT]+= 1.0;
211213 }
212− }else if(s->out_ch_layout & AV_CH_FRONT_LEFT){
214+ }else if(out_ch_layout & AV_CH_FRONT_LEFT){
213215 if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
214216 matrix[FRONT_LEFT ][BACK_LEFT ] -= s->slev * M_SQRT1_2;
215217 matrix[FRONT_LEFT ][BACK_RIGHT] -= s->slev * M_SQRT1_2;
@@ -224,7 +226,7 @@ static int auto_matrix(SwrContext *s) · 8 unmodified lines
224226 matrix[ FRONT_LEFT][ BACK_LEFT] += s->slev;
225227 matrix[FRONT_RIGHT][BACK_RIGHT] += s->slev;
226228 }
227− }else if(s->out_ch_layout & AV_CH_FRONT_CENTER){
229+ }else if(out_ch_layout & AV_CH_FRONT_CENTER){
228230 matrix[ FRONT_CENTER][BACK_LEFT ]+= s->slev*M_SQRT1_2;
229231 matrix[ FRONT_CENTER][BACK_RIGHT]+= s->slev*M_SQRT1_2;
230232 }else
@@ -232,20 +234,20 @@ static int auto_matrix(SwrContext *s) · 1 unmodified line
232234 }
233235
234236 if(unaccounted & AV_CH_SIDE_LEFT){
235− if(s->out_ch_layout & AV_CH_BACK_LEFT){
237+ if(out_ch_layout & AV_CH_BACK_LEFT){
236238 /* if back channels do not exist in the input, just copy side
237239 channels to back channels, otherwise mix side into back */
238− if (s->in_ch_layout & AV_CH_BACK_LEFT) {
240+ if (in_ch_layout & AV_CH_BACK_LEFT) {
239241 matrix[BACK_LEFT ][SIDE_LEFT ] += M_SQRT1_2;
240242 matrix[BACK_RIGHT][SIDE_RIGHT] += M_SQRT1_2;
241243 } else {
242244 matrix[BACK_LEFT ][SIDE_LEFT ] += 1.0;
243245 matrix[BACK_RIGHT][SIDE_RIGHT] += 1.0;
244246 }
245− }else if(s->out_ch_layout & AV_CH_BACK_CENTER){
247+ }else if(out_ch_layout & AV_CH_BACK_CENTER){
246248 matrix[BACK_CENTER][ SIDE_LEFT]+= M_SQRT1_2;
247249 matrix[BACK_CENTER][SIDE_RIGHT]+= M_SQRT1_2;
248− }else if(s->out_ch_layout & AV_CH_FRONT_LEFT){
250+ }else if(out_ch_layout & AV_CH_FRONT_LEFT){
249251 if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
250252 matrix[FRONT_LEFT ][SIDE_LEFT ] -= s->slev * M_SQRT1_2;
251253 matrix[FRONT_LEFT ][SIDE_RIGHT] -= s->slev * M_SQRT1_2;
@@ -260,7 +262,7 @@ static int auto_matrix(SwrContext *s) · 8 unmodified lines
260262 matrix[ FRONT_LEFT][ SIDE_LEFT] += s->slev;
261263 matrix[FRONT_RIGHT][SIDE_RIGHT] += s->slev;
262264 }
263− }else if(s->out_ch_layout & AV_CH_FRONT_CENTER){
265+ }else if(out_ch_layout & AV_CH_FRONT_CENTER){
264266 matrix[ FRONT_CENTER][SIDE_LEFT ]+= s->slev*M_SQRT1_2;
265267 matrix[ FRONT_CENTER][SIDE_RIGHT]+= s->slev*M_SQRT1_2;
266268 }else
@@ -268,10 +270,10 @@ static int auto_matrix(SwrContext *s) · 1 unmodified line
268270 }
269271
270272 if(unaccounted & AV_CH_FRONT_LEFT_OF_CENTER){
271− if(s->out_ch_layout & AV_CH_FRONT_LEFT){
273+ if(out_ch_layout & AV_CH_FRONT_LEFT){
272274 matrix[ FRONT_LEFT][ FRONT_LEFT_OF_CENTER]+= 1.0;
273275 matrix[FRONT_RIGHT][FRONT_RIGHT_OF_CENTER]+= 1.0;
274− }else if(s->out_ch_layout & AV_CH_FRONT_CENTER){
276+ }else if(out_ch_layout & AV_CH_FRONT_CENTER){
275277 matrix[ FRONT_CENTER][ FRONT_LEFT_OF_CENTER]+= M_SQRT1_2;
276278 matrix[ FRONT_CENTER][FRONT_RIGHT_OF_CENTER]+= M_SQRT1_2;
277279 }else
@@ -279,9 +281,9 @@ static int auto_matrix(SwrContext *s) · 1 unmodified line
279281 }
280282 /* mix LFE into front left/right or center */
281283 if (unaccounted & AV_CH_LOW_FREQUENCY) {
282− if (s->out_ch_layout & AV_CH_FRONT_CENTER) {
284+ if (out_ch_layout & AV_CH_FRONT_CENTER) {
283285 matrix[FRONT_CENTER][LOW_FREQUENCY] += s->lfe_mix_level;
284− } else if (s->out_ch_layout & AV_CH_FRONT_LEFT) {
286+ } else if (out_ch_layout & AV_CH_FRONT_LEFT) {
285287 matrix[FRONT_LEFT ][LOW_FREQUENCY] += s->lfe_mix_level * M_SQRT1_2;
286288 matrix[FRONT_RIGHT][LOW_FREQUENCY] += s->lfe_mix_level * M_SQRT1_2;
287289 } else
@@ -296,11 +298,11 @@ static int auto_matrix(SwrContext *s) · 8 unmodified lines
296298 if(matrix[i][j]){
297299 sum += fabs(matrix[i][j]);
298300 }
299− if(s->in_ch_layout & (1ULL<<j))
301+ if(in_ch_layout & (1ULL<<j))
300302 in_i++;
301303 }
302304 maxcoef= FFMAX(maxcoef, sum);
303− if(s->out_ch_layout & (1ULL<<i))
305+ if(out_ch_layout & (1ULL<<i))
304306 out_i++;
305307 }
306308 if(s->rematrix_volume < 0)
@@ -321,8 +323,8 @@ static int auto_matrix(SwrContext *s) · 14 unmodified lines
321323 }
322324 }
323325
324− for(i=0; i<av_get_channel_layout_nb_channels(s->out_ch_layout); i++){
325− for(j=0; j<av_get_channel_layout_nb_channels(s->in_ch_layout); j++){
326+ for(i=0; i<av_get_channel_layout_nb_channels(out_ch_layout); i++){
327+ for(j=0; j<av_get_channel_layout_nb_channels(in_ch_layout); j++){
326328 av_log(NULL, AV_LOG_DEBUG, "%f ", s->matrix[i][j]);
327329 }
328330 av_log(NULL, AV_LOG_DEBUG, "\n");

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