| 142 | } |
| 143 | |
| 144 | static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], int total_gain){ |
| 145 | int v, bsize, ch, coef_nb_bits, parse_exponents; |
| 146 | float mdct_norm; |
| 147 | int nb_coefs[MAX_CHANNELS]; |
| 148 | static const int fixed_exp[25]={20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20}; |
| 149 | |
| 150 | //FIXME remove duplication relative to decoder |
| 151 | if (s->use_variable_block_len) { |
| 152 | assert(0); //FIXME not implemented |
| 153 | }else{ |
| 154 | /* fixed block len */ |
| 155 | s->next_block_len_bits = s->frame_len_bits; |
| 156 | s->prev_block_len_bits = s->frame_len_bits; |
| 157 | s->block_len_bits = s->frame_len_bits; |
| 158 | } |
| 159 | |
| 160 | s->block_len = 1 << s->block_len_bits; |
| 161 | // assert((s->block_pos + s->block_len) <= s->frame_len); |
| 162 | bsize = s->frame_len_bits - s->block_len_bits; |
| 163 | |
| 164 | //FIXME factor |
| 165 | v = s->coefs_end[bsize] - s->coefs_start; |
| 166 | for(ch = 0; ch < s->nb_channels; ch++) |
| 167 | nb_coefs[ch] = v; |
| 168 | { |
| 169 | int n4 = s->block_len / 2; |
| 170 | mdct_norm = 1.0 / (float)n4; |
| 171 | if (s->version == 1) { |
| 172 | mdct_norm *= sqrt(n4); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | if (s->nb_channels == 2) { |
| 177 | put_bits(&s->pb, 1, s->ms_stereo= 1); |
| 178 | } |
| 179 | |
| 180 | for(ch = 0; ch < s->nb_channels; ch++) { |
| 181 | s->channel_coded[ch] = 1; //FIXME only set channel_coded when needed, instead of always |
| 182 | if (s->channel_coded[ch]) { |
| 183 | init_exp(s, ch, fixed_exp); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | for(ch = 0; ch < s->nb_channels; ch++) { |
| 188 | if (s->channel_coded[ch]) { |
| 189 | WMACoef *coefs1; |
| 190 | float *coefs, *exponents, mult; |
| 191 | int i, n; |
| 192 | |
| 193 | coefs1 = s->coefs1[ch]; |
| 194 | exponents = s->exponents[ch]; |
| 195 | mult = pow(10, total_gain * 0.05) / s->max_exponent[ch]; |
| 196 | mult *= mdct_norm; |
| 197 | coefs = src_coefs[ch]; |
| 198 | if (s->use_noise_coding && 0) { |
| 199 | assert(0); //FIXME not implemented |
| 200 | } else { |
| 201 | coefs += s->coefs_start; |
no test coverage detected