Mercurial > libavcodec.hg
comparison dca.c @ 8148:146ac82af1e5 libavcodec
Proper channel output reordering for the dca decoder.
author | banan |
---|---|
date | Sat, 15 Nov 2008 20:31:03 +0000 |
parents | 257459ea9e7b |
children | ee1b8c54a603 |
comparison
equal
deleted
inserted
replaced
8147:3b9eefe120e6 | 8148:146ac82af1e5 |
---|---|
86 CH_FRONT_LEFT_OF_CENTER|CH_FRONT_CENTER|CH_FRONT_RIGHT_OF_CENTER|CH_LAYOUT_STEREO|CH_SIDE_LEFT|CH_SIDE_RIGHT, ///< 7, CL + C + CR + L + R + SL + SR | 86 CH_FRONT_LEFT_OF_CENTER|CH_FRONT_CENTER|CH_FRONT_RIGHT_OF_CENTER|CH_LAYOUT_STEREO|CH_SIDE_LEFT|CH_SIDE_RIGHT, ///< 7, CL + C + CR + L + R + SL + SR |
87 CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER|CH_LAYOUT_STEREO|CH_SIDE_LEFT|CH_SIDE_RIGHT|CH_BACK_LEFT|CH_BACK_RIGHT, ///< 8, CL + CR + L + R + SL1 + SL2+ SR1 + SR2 | 87 CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER|CH_LAYOUT_STEREO|CH_SIDE_LEFT|CH_SIDE_RIGHT|CH_BACK_LEFT|CH_BACK_RIGHT, ///< 8, CL + CR + L + R + SL1 + SL2+ SR1 + SR2 |
88 CH_FRONT_LEFT_OF_CENTER|CH_FRONT_CENTER|CH_FRONT_RIGHT_OF_CENTER|CH_LAYOUT_STEREO|CH_SIDE_LEFT|CH_BACK_CENTER|CH_SIDE_RIGHT, ///< 8, CL + C+ CR + L + R + SL + S+ SR | 88 CH_FRONT_LEFT_OF_CENTER|CH_FRONT_CENTER|CH_FRONT_RIGHT_OF_CENTER|CH_LAYOUT_STEREO|CH_SIDE_LEFT|CH_BACK_CENTER|CH_SIDE_RIGHT, ///< 8, CL + C+ CR + L + R + SL + S+ SR |
89 }; | 89 }; |
90 | 90 |
91 static const int8_t dca_lfe_index[] = { | |
92 1,2,2,2,2,3,2,3,2,3,2,3,1,3,2,3 | |
93 }; | |
94 | |
95 static const int8_t dca_channel_reorder_lfe[][8] = { | |
96 { 0, -1, -1, -1, -1, -1, -1, -1}, | |
97 { 0, 1, -1, -1, -1, -1, -1, -1}, | |
98 { 0, 1, -1, -1, -1, -1, -1, -1}, | |
99 { 0, 1, -1, -1, -1, -1, -1, -1}, | |
100 { 0, 1, -1, -1, -1, -1, -1, -1}, | |
101 { 2, 0, 1, -1, -1, -1, -1, -1}, | |
102 { 0, 1, 3, -1, -1, -1, -1, -1}, | |
103 { 2, 0, 1, 4, -1, -1, -1, -1}, | |
104 { 0, 1, 3, 4, -1, -1, -1, -1}, | |
105 { 2, 0, 1, 4, 5, -1, -1, -1}, | |
106 { 3, 4, 0, 1, 5, 6, -1, -1}, | |
107 { 2, 0, 1, 4, 5, 6, -1, -1}, | |
108 { 0, 6, 4, 5, 2, 3, -1, -1}, | |
109 { 4, 2, 5, 0, 1, 6, 7, -1}, | |
110 { 5, 6, 0, 1, 7, 3, 8, 4}, | |
111 { 4, 2, 5, 0, 1, 6, 8, 7}, | |
112 }; | |
113 | |
114 static const int8_t dca_channel_reorder_nolfe[][8] = { | |
115 { 0, -1, -1, -1, -1, -1, -1, -1}, | |
116 { 0, 1, -1, -1, -1, -1, -1, -1}, | |
117 { 0, 1, -1, -1, -1, -1, -1, -1}, | |
118 { 0, 1, -1, -1, -1, -1, -1, -1}, | |
119 { 0, 1, -1, -1, -1, -1, -1, -1}, | |
120 { 2, 0, 1, -1, -1, -1, -1, -1}, | |
121 { 0, 1, 2, -1, -1, -1, -1, -1}, | |
122 { 2, 0, 1, 3, -1, -1, -1, -1}, | |
123 { 0, 1, 2, 3, -1, -1, -1, -1}, | |
124 { 2, 0, 1, 3, 4, -1, -1, -1}, | |
125 { 2, 3, 0, 1, 4, 5, -1, -1}, | |
126 { 2, 0, 1, 3, 4, 5, -1, -1}, | |
127 { 0, 5, 3, 4, 1, 2, -1, -1}, | |
128 { 3, 2, 4, 0, 1, 5, 6, -1}, | |
129 { 4, 5, 0, 1, 6, 2, 7, 3}, | |
130 { 3, 2, 4, 0, 1, 5, 7, 6}, | |
131 }; | |
132 | |
91 | 133 |
92 #define DCA_DOLBY 101 /* FIXME */ | 134 #define DCA_DOLBY 101 /* FIXME */ |
93 | 135 |
94 #define DCA_CHANNEL_BITS 6 | 136 #define DCA_CHANNEL_BITS 6 |
95 #define DCA_CHANNEL_MASK 0x3F | 137 #define DCA_CHANNEL_MASK 0x3F |
196 const float *samples_chanptr[6]; | 238 const float *samples_chanptr[6]; |
197 | 239 |
198 uint8_t dca_buffer[DCA_MAX_FRAME_SIZE]; | 240 uint8_t dca_buffer[DCA_MAX_FRAME_SIZE]; |
199 int dca_buffer_size; ///< how much data is in the dca_buffer | 241 int dca_buffer_size; ///< how much data is in the dca_buffer |
200 | 242 |
243 const int8_t* channel_order_tab; ///< channel reordering table, lfe and non lfe | |
201 GetBitContext gb; | 244 GetBitContext gb; |
202 /* Current position in DCA frame */ | 245 /* Current position in DCA frame */ |
203 int current_subframe; | 246 int current_subframe; |
204 int current_subsubframe; | 247 int current_subsubframe; |
205 | 248 |
1011 | 1054 |
1012 /* 32 subbands QMF */ | 1055 /* 32 subbands QMF */ |
1013 for (k = 0; k < s->prim_channels; k++) { | 1056 for (k = 0; k < s->prim_channels; k++) { |
1014 /* static float pcm_to_double[8] = | 1057 /* static float pcm_to_double[8] = |
1015 {32768.0, 32768.0, 524288.0, 524288.0, 0, 8388608.0, 8388608.0};*/ | 1058 {32768.0, 32768.0, 524288.0, 524288.0, 0, 8388608.0, 8388608.0};*/ |
1016 qmf_32_subbands(s, k, subband_samples[k], &s->samples[256 * k], | 1059 qmf_32_subbands(s, k, subband_samples[k], &s->samples[256 * s->channel_order_tab[k]], |
1017 M_SQRT1_2*s->scale_bias /*pcm_to_double[s->source_pcm_res] */ , | 1060 M_SQRT1_2*s->scale_bias /*pcm_to_double[s->source_pcm_res] */ , |
1018 s->add_bias ); | 1061 s->add_bias ); |
1019 } | 1062 } |
1020 | 1063 |
1021 /* Down mixing */ | 1064 /* Down mixing */ |
1025 } | 1068 } |
1026 | 1069 |
1027 /* Generate LFE samples for this subsubframe FIXME!!! */ | 1070 /* Generate LFE samples for this subsubframe FIXME!!! */ |
1028 if (s->output & DCA_LFE) { | 1071 if (s->output & DCA_LFE) { |
1029 int lfe_samples = 2 * s->lfe * s->subsubframes; | 1072 int lfe_samples = 2 * s->lfe * s->subsubframes; |
1030 int i_channels = dca_channels[s->output & DCA_CHANNEL_MASK]; | |
1031 | 1073 |
1032 lfe_interpolation_fir(s->lfe, 2 * s->lfe, | 1074 lfe_interpolation_fir(s->lfe, 2 * s->lfe, |
1033 s->lfe_data + lfe_samples + | 1075 s->lfe_data + lfe_samples + |
1034 2 * s->lfe * subsubframe, | 1076 2 * s->lfe * subsubframe, |
1035 &s->samples[256 * i_channels], | 1077 &s->samples[256 * dca_lfe_index[s->amode]], |
1036 (1.0/256.0)*s->scale_bias, s->add_bias); | 1078 (1.0/256.0)*s->scale_bias, s->add_bias); |
1037 /* Outputs 20bits pcm samples */ | 1079 /* Outputs 20bits pcm samples */ |
1038 } | 1080 } |
1039 | 1081 |
1040 return 0; | 1082 return 0; |
1190 //set AVCodec values with parsed data | 1232 //set AVCodec values with parsed data |
1191 avctx->sample_rate = s->sample_rate; | 1233 avctx->sample_rate = s->sample_rate; |
1192 avctx->bit_rate = s->bit_rate; | 1234 avctx->bit_rate = s->bit_rate; |
1193 | 1235 |
1194 channels = s->prim_channels + !!s->lfe; | 1236 channels = s->prim_channels + !!s->lfe; |
1195 if(avctx->request_channels == 2 && s->prim_channels > 2) { | 1237 |
1196 channels = 2; | 1238 if (s->amode<16) { |
1197 s->output = DCA_STEREO; | |
1198 avctx->channel_layout = CH_LAYOUT_STEREO; | |
1199 } | |
1200 if (s->amode<16) | |
1201 avctx->channel_layout = dca_core_channel_layout[s->amode]; | 1239 avctx->channel_layout = dca_core_channel_layout[s->amode]; |
1202 | 1240 |
1203 if (s->lfe) avctx->channel_layout |= CH_LOW_FREQUENCY; | 1241 if (s->lfe) { |
1242 avctx->channel_layout |= CH_LOW_FREQUENCY; | |
1243 s->channel_order_tab = dca_channel_reorder_lfe[s->amode]; | |
1244 } else | |
1245 s->channel_order_tab = dca_channel_reorder_nolfe[s->amode]; | |
1246 | |
1247 if(avctx->request_channels == 2 && s->prim_channels > 2) { | |
1248 channels = 2; | |
1249 s->output = DCA_STEREO; | |
1250 avctx->channel_layout = CH_LAYOUT_STEREO; | |
1251 } | |
1252 } else { | |
1253 av_log(avctx, AV_LOG_ERROR, "Non standard configuration %d !\n",s->amode); | |
1254 return -1; | |
1255 } | |
1256 | |
1204 | 1257 |
1205 /* There is nothing that prevents a dts frame to change channel configuration | 1258 /* There is nothing that prevents a dts frame to change channel configuration |
1206 but FFmpeg doesn't support that so only set the channels if it is previously | 1259 but FFmpeg doesn't support that so only set the channels if it is previously |
1207 unset. Ideally during the first probe for channels the crc should be checked | 1260 unset. Ideally during the first probe for channels the crc should be checked |
1208 and only set avctx->channels when the crc is ok. Right now the decoder could | 1261 and only set avctx->channels when the crc is ok. Right now the decoder could |