Mercurial > libavcodec.hg
comparison dca.c @ 8062:17aeecee2a97 libavcodec
Fix dca decoder with non simd float2int16 conversion
| author | banan |
|---|---|
| date | Sun, 26 Oct 2008 09:54:53 +0000 |
| parents | 8ce423998cca |
| children | 6bc70b15451d |
comparison
equal
deleted
inserted
replaced
| 8061:8ce423998cca | 8062:17aeecee2a97 |
|---|---|
| 65 #define DCA_CHANNEL_MASK 0x3F | 65 #define DCA_CHANNEL_MASK 0x3F |
| 66 | 66 |
| 67 #define DCA_LFE 0x80 | 67 #define DCA_LFE 0x80 |
| 68 | 68 |
| 69 #define HEADER_SIZE 14 | 69 #define HEADER_SIZE 14 |
| 70 #define CONVERT_BIAS 384 | |
| 71 | 70 |
| 72 #define DCA_MAX_FRAME_SIZE 16384 | 71 #define DCA_MAX_FRAME_SIZE 16384 |
| 73 | 72 |
| 74 /** Bit allocation */ | 73 /** Bit allocation */ |
| 75 typedef struct { | 74 typedef struct { |
| 157 DECLARE_ALIGNED_16(float, subband_fir_hist[DCA_PRIM_CHANNELS_MAX][512]); | 156 DECLARE_ALIGNED_16(float, subband_fir_hist[DCA_PRIM_CHANNELS_MAX][512]); |
| 158 float subband_fir_noidea[DCA_PRIM_CHANNELS_MAX][32]; | 157 float subband_fir_noidea[DCA_PRIM_CHANNELS_MAX][32]; |
| 159 int hist_index[DCA_PRIM_CHANNELS_MAX]; | 158 int hist_index[DCA_PRIM_CHANNELS_MAX]; |
| 160 | 159 |
| 161 int output; ///< type of output | 160 int output; ///< type of output |
| 162 int bias; ///< output bias | 161 float add_bias; ///< output bias |
| 162 float scale_bias; ///< output scale | |
| 163 | 163 |
| 164 DECLARE_ALIGNED_16(float, samples[1536]); /* 6 * 256 = 1536, might only need 5 */ | 164 DECLARE_ALIGNED_16(float, samples[1536]); /* 6 * 256 = 1536, might only need 5 */ |
| 165 const float *samples_chanptr[6]; | 165 const float *samples_chanptr[6]; |
| 166 | 166 |
| 167 uint8_t dca_buffer[DCA_MAX_FRAME_SIZE]; | 167 uint8_t dca_buffer[DCA_MAX_FRAME_SIZE]; |
| 227 { | 227 { |
| 228 int i, j; | 228 int i, j; |
| 229 static const float adj_table[4] = { 1.0, 1.1250, 1.2500, 1.4375 }; | 229 static const float adj_table[4] = { 1.0, 1.1250, 1.2500, 1.4375 }; |
| 230 static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 }; | 230 static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 }; |
| 231 static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 }; | 231 static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 }; |
| 232 | |
| 233 s->bias = CONVERT_BIAS; | |
| 234 | 232 |
| 235 init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8); | 233 init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8); |
| 236 | 234 |
| 237 /* Sync code */ | 235 /* Sync code */ |
| 238 get_bits(&s->gb, 32); | 236 get_bits(&s->gb, 32); |
| 746 for (k = 0; k < decifactor; k++) { | 744 for (k = 0; k < decifactor; k++) { |
| 747 float rTmp = 0.0; | 745 float rTmp = 0.0; |
| 748 //FIXME the coeffs are symetric, fix that | 746 //FIXME the coeffs are symetric, fix that |
| 749 for (j = 0; j < 512 / decifactor; j++) | 747 for (j = 0; j < 512 / decifactor; j++) |
| 750 rTmp += samples_in[deciindex - j] * prCoeff[k + j * decifactor]; | 748 rTmp += samples_in[deciindex - j] * prCoeff[k + j * decifactor]; |
| 751 samples_out[interp_index++] = rTmp / scale + bias; | 749 samples_out[interp_index++] = (rTmp * scale) + bias; |
| 752 } | 750 } |
| 753 } | 751 } |
| 754 } | 752 } |
| 755 | 753 |
| 756 /* downmixing routines */ | 754 /* downmixing routines */ |
| 982 /* 32 subbands QMF */ | 980 /* 32 subbands QMF */ |
| 983 for (k = 0; k < s->prim_channels; k++) { | 981 for (k = 0; k < s->prim_channels; k++) { |
| 984 /* static float pcm_to_double[8] = | 982 /* static float pcm_to_double[8] = |
| 985 {32768.0, 32768.0, 524288.0, 524288.0, 0, 8388608.0, 8388608.0};*/ | 983 {32768.0, 32768.0, 524288.0, 524288.0, 0, 8388608.0, 8388608.0};*/ |
| 986 qmf_32_subbands(s, k, subband_samples[k], &s->samples[256 * k], | 984 qmf_32_subbands(s, k, subband_samples[k], &s->samples[256 * k], |
| 987 M_SQRT1_2 /*pcm_to_double[s->source_pcm_res] */ , | 985 M_SQRT1_2*s->scale_bias /*pcm_to_double[s->source_pcm_res] */ , |
| 988 0 /*s->bias */ ); | 986 s->add_bias ); |
| 989 } | 987 } |
| 990 | 988 |
| 991 /* Down mixing */ | 989 /* Down mixing */ |
| 992 | 990 |
| 993 if (s->prim_channels > dca_channels[s->output & DCA_CHANNEL_MASK]) { | 991 if (s->prim_channels > dca_channels[s->output & DCA_CHANNEL_MASK]) { |
| 1001 | 999 |
| 1002 lfe_interpolation_fir(s->lfe, 2 * s->lfe, | 1000 lfe_interpolation_fir(s->lfe, 2 * s->lfe, |
| 1003 s->lfe_data + lfe_samples + | 1001 s->lfe_data + lfe_samples + |
| 1004 2 * s->lfe * subsubframe, | 1002 2 * s->lfe * subsubframe, |
| 1005 &s->samples[256 * i_channels], | 1003 &s->samples[256 * i_channels], |
| 1006 256.0, 0 /* s->bias */); | 1004 (1.0/256.0)*s->scale_bias, s->add_bias); |
| 1007 /* Outputs 20bits pcm samples */ | 1005 /* Outputs 20bits pcm samples */ |
| 1008 } | 1006 } |
| 1009 | 1007 |
| 1010 return 0; | 1008 return 0; |
| 1011 } | 1009 } |
| 1212 avctx->channels = avctx->request_channels; | 1210 avctx->channels = avctx->request_channels; |
| 1213 } | 1211 } |
| 1214 for(i = 0; i < 6; i++) | 1212 for(i = 0; i < 6; i++) |
| 1215 s->samples_chanptr[i] = s->samples + i * 256; | 1213 s->samples_chanptr[i] = s->samples + i * 256; |
| 1216 avctx->sample_fmt = SAMPLE_FMT_S16; | 1214 avctx->sample_fmt = SAMPLE_FMT_S16; |
| 1215 | |
| 1216 if(s->dsp.float_to_int16 == ff_float_to_int16_c) { | |
| 1217 s->add_bias = 385.0f; | |
| 1218 s->scale_bias = 1.0 / 32768.0; | |
| 1219 } else { | |
| 1220 s->add_bias = 0.0f; | |
| 1221 s->scale_bias = 1.0; | |
| 1222 } | |
| 1223 | |
| 1224 | |
| 1217 return 0; | 1225 return 0; |
| 1218 } | 1226 } |
| 1219 | 1227 |
| 1220 static av_cold int dca_decode_end(AVCodecContext * avctx) | 1228 static av_cold int dca_decode_end(AVCodecContext * avctx) |
| 1221 { | 1229 { |
