MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / parse_x96_subframe_audio

Function parse_x96_subframe_audio

libavcodec/dca_core.c:1161–1267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1159}
1160
1161static int parse_x96_subframe_audio(DCACoreDecoder *s, int sf, int xch_base, int *sub_pos)
1162{
1163 int n, ssf, ch, band, ofs;
1164
1165 // Check number of subband samples in this subframe
1166 int nsamples = s->nsubsubframes[sf] * DCA_SUBBAND_SAMPLES;
1167 if (*sub_pos + nsamples > s->npcmblocks) {
1168 av_log(s->avctx, AV_LOG_ERROR, "Subband sample buffer overflow\n");
1169 return AVERROR_INVALIDDATA;
1170 }
1171
1172 if (get_bits_left(&s->gb) < 0)
1173 return AVERROR_INVALIDDATA;
1174
1175 // VQ encoded or unallocated subbands
1176 for (ch = xch_base; ch < s->x96_nchannels; ch++) {
1177 for (band = s->x96_subband_start; band < s->nsubbands[ch]; band++) {
1178 // Get the sample pointer and scale factor
1179 int32_t *samples = s->x96_subband_samples[ch][band] + *sub_pos;
1180 int32_t scale = s->scale_factors[ch][band >> 1][band & 1];
1181
1182 switch (s->bit_allocation[ch][band]) {
1183 case 0: // No bits allocated for subband
1184 if (scale <= 1)
1185 memset(samples, 0, nsamples * sizeof(int32_t));
1186 else for (n = 0; n < nsamples; n++)
1187 // Generate scaled random samples
1188 samples[n] = mul31(rand_x96(s), scale);
1189 break;
1190
1191 case 1: // VQ encoded subband
1192 for (ssf = 0; ssf < (s->nsubsubframes[sf] + 1) / 2; ssf++) {
1193 // Extract the VQ address from the bit stream and look up
1194 // the VQ code book for up to 16 subband samples
1195 const int8_t *vq_samples = ff_dca_high_freq_vq[get_bits(&s->gb, 10)];
1196 // Scale and take the samples
1197 for (n = 0; n < FFMIN(nsamples - ssf * 16, 16); n++)
1198 *samples++ = clip23(vq_samples[n] * scale + (1 << 3) >> 4);
1199 }
1200 break;
1201 }
1202 }
1203 }
1204
1205 // Audio data
1206 for (ssf = 0, ofs = *sub_pos; ssf < s->nsubsubframes[sf]; ssf++) {
1207 for (ch = xch_base; ch < s->x96_nchannels; ch++) {
1208 if (get_bits_left(&s->gb) < 0)
1209 return AVERROR_INVALIDDATA;
1210
1211 for (band = s->x96_subband_start; band < s->nsubbands[ch]; band++) {
1212 int ret, abits = s->bit_allocation[ch][band] - 1;
1213 int32_t audio[DCA_SUBBAND_SAMPLES], step_size, scale;
1214
1215 // Not VQ encoded or unallocated subbands
1216 if (abits < 1)
1217 continue;
1218

Callers 1

parse_x96_frame_dataFunction · 0.85

Calls 9

av_logFunction · 0.85
get_bits_leftFunction · 0.85
mul31Function · 0.85
rand_x96Function · 0.85
clip23Function · 0.85
extract_audioFunction · 0.85
ff_dca_core_dequantizeFunction · 0.85
inverse_adpcmFunction · 0.85
get_bitsFunction · 0.70

Tested by

no test coverage detected