Mercurial > libavcodec.hg
comparison wmaprodec.c @ 10138:a3e378408d5c libavcodec
avoid extra memcpy during scale factor decoding
author | faust3 |
---|---|
date | Sun, 06 Sep 2009 06:56:25 +0000 |
parents | c2d08aedeeed |
children | de9335d4b6b1 |
comparison
equal
deleted
inserted
replaced
10137:9a670cfd1941 | 10138:a3e378408d5c |
---|---|
135 uint8_t grouped; ///< channel is part of a group | 135 uint8_t grouped; ///< channel is part of a group |
136 int quant_step; ///< quantization step for the current subframe | 136 int quant_step; ///< quantization step for the current subframe |
137 int8_t reuse_sf; ///< share scale factors between subframes | 137 int8_t reuse_sf; ///< share scale factors between subframes |
138 int8_t scale_factor_step; ///< scaling step for the current subframe | 138 int8_t scale_factor_step; ///< scaling step for the current subframe |
139 int max_scale_factor; ///< maximum scale factor for the current subframe | 139 int max_scale_factor; ///< maximum scale factor for the current subframe |
140 int scale_factors[MAX_BANDS]; ///< scale factor values for the current subframe | 140 int saved_scale_factors[2][MAX_BANDS]; ///< resampled and (previously) transmitted scale factor values |
141 int saved_scale_factors[MAX_BANDS]; ///< scale factors from a previous subframe | 141 int8_t scale_factor_idx; ///< index for the transmitted scale factor values (used for resampling) |
142 int* scale_factors; ///< pointer to the scale factor values used for decoding | |
142 uint8_t table_idx; ///< index in sf_offsets for the scale factor reference block | 143 uint8_t table_idx; ///< index in sf_offsets for the scale factor reference block |
143 float* coeffs; ///< pointer to the subframe decode buffer | 144 float* coeffs; ///< pointer to the subframe decode buffer |
144 DECLARE_ALIGNED_16(float, out[WMAPRO_BLOCK_MAX_SIZE + WMAPRO_BLOCK_MAX_SIZE / 2]); ///< output buffer | 145 DECLARE_ALIGNED_16(float, out[WMAPRO_BLOCK_MAX_SIZE + WMAPRO_BLOCK_MAX_SIZE / 2]); ///< output buffer |
145 } WMAProChannelCtx; | 146 } WMAProChannelCtx; |
146 | 147 |
858 */ | 859 */ |
859 | 860 |
860 for (i = 0; i < s->channels_for_cur_subframe; i++) { | 861 for (i = 0; i < s->channels_for_cur_subframe; i++) { |
861 int c = s->channel_indexes_for_cur_subframe[i]; | 862 int c = s->channel_indexes_for_cur_subframe[i]; |
862 int* sf; | 863 int* sf; |
863 int* sf_end = s->channel[c].scale_factors + s->num_bands; | 864 int* sf_end; |
865 s->channel[c].scale_factors = s->channel[c].saved_scale_factors[!s->channel[c].scale_factor_idx]; | |
866 sf_end = s->channel[c].scale_factors + s->num_bands; | |
864 | 867 |
865 /** resample scale factors for the new block size | 868 /** resample scale factors for the new block size |
866 * as the scale factors might need to be resampled several times | 869 * as the scale factors might need to be resampled several times |
867 * before some new values are transmitted, a backup of the last | 870 * before some new values are transmitted, a backup of the last |
868 * transmitted scale factors is kept in saved_scale_factors | 871 * transmitted scale factors is kept in saved_scale_factors |
870 if (s->channel[c].reuse_sf) { | 873 if (s->channel[c].reuse_sf) { |
871 const int8_t* sf_offsets = s->sf_offsets[s->table_idx][s->channel[c].table_idx]; | 874 const int8_t* sf_offsets = s->sf_offsets[s->table_idx][s->channel[c].table_idx]; |
872 int b; | 875 int b; |
873 for (b = 0; b < s->num_bands; b++) | 876 for (b = 0; b < s->num_bands; b++) |
874 s->channel[c].scale_factors[b] = | 877 s->channel[c].scale_factors[b] = |
875 s->channel[c].saved_scale_factors[*sf_offsets++]; | 878 s->channel[c].saved_scale_factors[s->channel[c].scale_factor_idx][*sf_offsets++]; |
876 } | 879 } |
877 | 880 |
878 if (!s->channel[c].cur_subframe || get_bits1(&s->gb)) { | 881 if (!s->channel[c].cur_subframe || get_bits1(&s->gb)) { |
879 | 882 |
880 if (!s->channel[c].reuse_sf) { | 883 if (!s->channel[c].reuse_sf) { |
917 return AVERROR_INVALIDDATA; | 920 return AVERROR_INVALIDDATA; |
918 } | 921 } |
919 s->channel[c].scale_factors[i] += (val ^ sign) - sign; | 922 s->channel[c].scale_factors[i] += (val ^ sign) - sign; |
920 } | 923 } |
921 } | 924 } |
922 | 925 /** swap buffers */ |
923 /** save transmitted scale factors so that they can be reused for | 926 s->channel[c].scale_factor_idx = !s->channel[c].scale_factor_idx; |
924 the next subframe */ | |
925 memcpy(s->channel[c].saved_scale_factors, | |
926 s->channel[c].scale_factors, s->num_bands * | |
927 sizeof(*s->channel[c].saved_scale_factors)); | |
928 s->channel[c].table_idx = s->table_idx; | 927 s->channel[c].table_idx = s->table_idx; |
929 s->channel[c].reuse_sf = 1; | 928 s->channel[c].reuse_sf = 1; |
930 } | 929 } |
931 | 930 |
932 /** calculate new scale factor maximum */ | 931 /** calculate new scale factor maximum */ |