Home | History | Annotate | Download | only in sbc

Lines Matching full:frame

53 /* This structure contains an unpacked SBC frame.
82 /* raw integer subband samples in the frame */
159 * Takes a pointer to the frame in question, a pointer to the bits array and
162 static void sbc_calculate_bits(const struct sbc_frame *frame, int (*bits)[8])
164 uint8_t sf = frame->frequency;
166 if (frame->mode == MONO || frame->mode == DUAL_CHANNEL) {
170 for (ch = 0; ch < frame->channels; ch++) {
172 if (frame->allocation == SNR) {
173 for (sb = 0; sb < frame->subbands; sb++) {
174 bitneed[ch][sb] = frame->scale_factor[ch][sb];
179 for (sb = 0; sb < frame->subbands; sb++) {
180 if (frame->scale_factor[ch][sb] == 0)
183 if (frame->subbands == 4)
184 loudness = frame->scale_factor[ch][sb] - sbc_offset4[sf][sb];
186 loudness = frame->scale_factor[ch][sb] - sbc_offset8[sf][sb];
204 for (sb = 0; sb < frame->subbands; sb++) {
210 } while (bitcount + slicecount < frame->bitpool);
212 if (bitcount + slicecount == frame->bitpool) {
217 for (sb = 0; sb < frame->subbands; sb++) {
227 for (sb = 0; bitcount < frame->bitpool && sb < frame->subbands; sb++) {
231 } else if ((bitneed[ch][sb] == bitslice + 1) && (frame->bitpool > bitcount + 1)) {
237 for (sb = 0; bitcount < frame->bitpool && sb < frame->subbands; sb++) {
246 } else if (frame->mode == STEREO || frame->mode == JOINT_STEREO) {
251 if (frame->allocation == SNR) {
253 for (sb = 0; sb < frame->subbands; sb++) {
254 bitneed[ch][sb] = frame->scale_factor[ch][sb];
261 for (sb = 0; sb < frame->subbands; sb++) {
262 if (frame->scale_factor[ch][sb] == 0)
265 if (frame->subbands == 4)
266 loudness = frame->scale_factor[ch][sb] - sbc_offset4[sf][sb];
268 loudness = frame->scale_factor[ch][sb] - sbc_offset8[sf][sb];
288 for (sb = 0; sb < frame->subbands; sb++) {
295 } while (bitcount + slicecount < frame->bitpool);
297 if (bitcount + slicecount == frame->bitpool) {
303 for (sb = 0; sb < frame->subbands; sb++) {
316 while (bitcount < frame->bitpool) {
320 } else if ((bitneed[ch][sb] == bitslice + 1) && (frame->bitpool > bitcount + 1)) {
327 if (sb >= frame->subbands) break;
334 while (bitcount < frame->bitpool) {
342 if (sb >= frame->subbands) break;
352 * Unpacks a SBC frame at the beginning of the stream in data,
353 * which has at most len bytes into frame.
354 * Returns the length in bytes of the packed frame, or a negative
362 static int sbc_unpack_frame(const uint8_t *data, struct sbc_frame *frame,
384 frame->frequency = (data[1] >> 6) & 0x03;
386 frame->block_mode = (data[1] >> 4) & 0x03;
387 switch (frame->block_mode) {
389 frame->blocks = 4;
392 frame->blocks = 8;
395 frame->blocks = 12;
398 frame->blocks = 16;
402 frame->mode = (data[1] >> 2) & 0x03;
403 switch (frame->mode) {
405 frame->channels = 1;
410 frame->channels = 2;
414 frame->allocation = (data[1] >> 1) & 0x01;
416 frame->subband_mode = (data[1] & 0x01);
417 frame->subbands = frame->subband_mode ? 8 : 4;
419 frame->bitpool = data[2];
421 if ((frame->mode == MONO || frame->mode == DUAL_CHANNEL) &&
422 frame->bitpool > 16 * frame->subbands)
425 if ((frame->mode == STEREO || frame->mode == JOINT_STEREO) &&
426 frame->bitpool > 32 * frame->subbands)
437 if (frame->mode == JOINT_STEREO) {
438 if (len * 8 < consumed + frame->subbands)
441 frame->joint = 0x00;
442 for (sb = 0; sb < frame->subbands - 1; sb++)
443 frame->joint |= ((data[4] >> (7 - sb)) & 0x01) << sb;
444 if (frame->subbands == 4)
449 consumed += frame->subbands;
450 crc_pos += frame->subbands;
453 if (len * 8 < consumed + (4 * frame->subbands * frame->channels))
456 for (ch = 0; ch < frame->channels; ch++) {
457 for (sb = 0; sb < frame->subbands; sb++) {
459 frame->scale_factor[ch][sb] =
462 frame->scale_factor[ch][sb] << (4 - (crc_pos & 0x7));
472 sbc_calculate_bits(frame, bits);
474 for (ch = 0; ch < frame->channels; ch++) {
475 for (sb = 0; sb < frame->subbands; sb++)
479 for (blk = 0; blk < frame->blocks; blk++) {
480 for (ch = 0; ch < frame->channels; ch++) {
481 for (sb = 0; sb < frame->subbands; sb++) {
494 frame->sb_sample[blk][ch][sb] =
495 (((audio_sample << 1) | 1) << frame->scale_factor[ch][sb]) /
496 levels[ch][sb] - (1 << frame->scale_factor[ch][sb]);
498 frame->sb_sample[blk][ch][sb] = 0;
503 if (frame->mode == JOINT_STEREO) {
504 for (blk = 0; blk < frame->blocks; blk++) {
505 for (sb = 0; sb < frame->subbands; sb++) {
506 if (frame->joint & (0x01 << sb)) {
507 temp = frame->sb_sample[blk][0][sb] +
508 frame->sb_sample[blk][1][sb];
509 frame->sb_sample[blk][1][sb] =
510 frame->sb_sample[blk][0][sb] -
511 frame->sb_sample[blk][1][sb];
512 frame->sb_sample[blk][0][sb] = temp;
525 const struct sbc_frame *frame)
530 state->subbands = frame->subbands;
533 for (i = 0; i < frame->subbands * 2; i++)
548 struct sbc_frame *frame, int ch, int blk)
564 MULA(synmatrix4[i][0], frame->sb_sample[blk][ch][0],
565 MULA(synmatrix4[i][1], frame->sb_sample[blk][ch][1],
566 MULA(synmatrix4[i][2], frame->sb_sample[blk][ch][2],
567 MUL (synmatrix4[i][3], frame->sb_sample[blk][ch][3])))));
575 frame->pcm_sample[ch][blk * 4 + i] = sbc_clip16(SCALE4_STAGED1(
590 struct sbc_frame *frame, int ch, int blk)
606 MULA(synmatrix8[i][0], frame->sb_sample[blk][ch][0],
607 MULA(synmatrix8[i][1], frame->sb_sample[blk][ch][1],
608 MULA(synmatrix8[i][2], frame->sb_sample[blk][ch][2],
609 MULA(synmatrix8[i][3], frame->sb_sample[blk][ch][3],
610 MULA(synmatrix8[i][4], frame->sb_sample[blk][ch][4],
611 frame->sb_sample[blk][ch][5],
612 MULA(synmatrix8[i][6], frame->sb_sample[blk][ch][6],
613 MUL( synmatrix8[i][7], frame->sb_sample[blk][ch][7])))))))));
621 frame->pcm_sample[ch][blk * 8 + i] = sbc_clip16(SCALE8_STAGED1(
636 struct sbc_frame *frame)
640 switch (frame->subbands) {
642 for (ch = 0; ch < frame->channels; ch++) {
643 for (blk = 0; blk < frame->blocks; blk++)
644 sbc_synthesize_four(state, frame, ch, blk);
646 return frame->blocks * 4;
649 for (ch = 0; ch < frame->channels; ch++) {
650 for (blk = 0; blk < frame->blocks; blk++)
651 sbc_synthesize_eight(state, frame, ch, blk);
653 return frame->blocks * 8;
661 struct sbc_frame *frame)
666 switch (frame->subbands) {
668 for (ch = 0; ch < frame->channels; ch++) {
670 frame->blocks * 4];
671 for (blk = 0; blk < frame->blocks; blk += 4) {
674 frame->sb_sample_f[blk][ch],
675 frame->sb_sample_f[blk + 1][ch] -
676 frame->sb_sample_f[blk][ch]);
680 return frame->blocks * 4;
683 for (ch = 0; ch < frame->channels; ch++) {
685 frame->blocks * 8];
686 for (blk = 0; blk < frame->blocks; blk += 4) {
689 frame->sb_sample_f[blk][ch],
690 frame->sb_sample_f[blk + 1][ch] -
691 frame->sb_sample_f[blk][ch]);
695 return frame->blocks * 8;
731 * Packs the SBC frame from frame into the memory at data. At most len
733 * error code will be returned. Returns the length of the packed frame
746 struct sbc_frame *frame, size_t len,
767 data[1] = (frame->frequency & 0x03) << 6;
769 data[1] |= (frame->block_mode & 0x03) << 4;
771 data[1] |= (frame->mode & 0x03) << 2;
773 data[1] |= (frame->allocation & 0x01) << 1;
787 data[2] = frame->bitpool;
789 if ((frame->mode == MONO || frame->mode == DUAL_CHANNEL) &&
790 frame->bitpool > frame_subbands << 4)
793 if ((frame->mode == STEREO || frame->mode == JOINT_STEREO) &&
794 frame->bitpool > frame_subbands << 5)
803 if (frame->mode == JOINT_STEREO) {
804 /* like frame->sb_sample but joint stereo */
811 frame->joint = 0;
819 for (blk = 0; blk < frame->blocks; blk++) {
823 ASR(frame->sb_sample_f[blk][0][sb], 1) +
824 ASR(frame->sb_sample_f[blk][1][sb], 1);
826 ASR(frame->sb_sample_f[blk][0][sb], 1) -
827 ASR(frame->sb_sample_f[blk][1][sb], 1);
843 if ((frame->scale_factor[0][sb] +
844 frame->scale_factor[1][sb]) >
849 frame->joint |= 1 << sb;
850 frame->scale_factor[0][sb] = scale_factor_j[0];
851 frame->scale_factor[1][sb] = scale_factor_j[1];
852 for (blk = 0; blk < frame->blocks; blk++) {
853 frame->sb_sample_f[blk][0][sb] =
855 frame->sb_sample_f[blk][1][sb] =
870 frame->scale_factor[ch][sb] & 0x0F, 4);
872 crc_header[crc_pos >> 3] |= frame->scale_factor[ch][sb] & 0x0F;
883 sbc_calculate_bits(frame, bits);
888 (32 - (frame->scale_factor[ch][sb] +
891 (frame->scale_factor[ch][sb] +
896 for (blk = 0; blk < frame->blocks; blk++) {
905 frame->sb_sample_f[blk][ch][sb])) >> 32;
918 static int sbc_pack_frame(uint8_t *data, struct sbc_frame *frame, size_t len)
920 if (frame->subbands == 4) {
921 if (frame->channels == 1)
922 return sbc_pack_frame_internal(data, frame, len, 4, 1);
924 return sbc_pack_frame_internal(data, frame, len, 4, 2);
926 if (frame->channels == 1)
927 return sbc_pack_frame_internal(data, frame, len, 8, 1);
929 return sbc_pack_frame_internal(data, frame, len, 8, 2);
934 const struct sbc_frame *frame)
937 state->position = (SBC_X_BUFFER_SIZE - frame->subbands * 9) & ~7;
944 struct SBC_ALIGNED sbc_frame frame;
1003 framelen = sbc_unpack_frame(input, &priv->frame, input_len);
1006 sbc_decoder_init(&priv->dec_state, &priv->frame);
1009 sbc->frequency = priv->frame.frequency;
1010 sbc->mode = priv->frame.mode;
1011 sbc->subbands = priv->frame.subband_mode;
1012 sbc->blocks = priv->frame.block_mode;
1013 sbc->allocation = priv->frame.allocation;
1014 sbc->bitpool = priv->frame.bitpool;
1016 priv->frame.codesize = sbc_get_codesize(sbc);
1017 priv->frame.length = framelen;
1029 samples = sbc_synthesize_audio(&priv->dec_state, &priv->frame);
1033 if (output_len < (size_t) (samples * priv->frame.channels * 2))
1034 samples = output_len / (priv->frame.channels * 2);
1037 for (ch = 0; ch < priv->frame.channels; ch++) {
1039 s = priv->frame.pcm_sample[ch][i];
1052 *written = samples * priv->frame.channels * 2;
1075 priv->frame.frequency = sbc->frequency;
1076 priv->frame.mode = sbc->mode;
1077 priv->frame.channels = sbc->mode == SBC_MODE_MONO ? 1 : 2;
1078 priv->frame.allocation = sbc->allocation;
1079 priv->frame.subband_mode = sbc->subbands;
1080 priv->frame.subbands = sbc->subbands ? 8 : 4;
1081 priv->frame.block_mode = sbc->blocks;
1082 priv->frame.blocks = 4 + (sbc->blocks * 4);
1083 priv->frame.bitpool = sbc->bitpool;
1084 priv->frame.codesize = sbc_get_codesize(sbc);
1085 priv->frame.length = sbc_get_frame_length(sbc);
1087 sbc_encoder_init(&priv->enc_state, &priv->frame);
1091 /* input must be large enough to encode a complete frame */
1092 if (input_len < priv->frame.codesize)
1095 /* output must be large enough to receive the encoded frame */
1096 if (!output || output_len < priv->frame.length)
1100 if (priv->frame.subbands == 8) {
1118 priv->enc_state.X, priv->frame.subbands * priv->frame.blocks,
1119 priv->frame.channels);
1121 samples = sbc_analyze_audio(&priv->enc_state, &priv->frame);
1124 priv->frame.sb_sample_f, priv->frame.scale_factor,
1125 priv->frame.blocks, priv->frame.channels, priv->frame.subbands);
1127 framelen = sbc_pack_frame(output, &priv->frame, output_len);
1132 return samples * priv->frame.channels * 2;
1154 return priv->frame.length;
1183 subbands = priv->frame.subbands;
1184 blocks = priv->frame.blocks;
1221 subbands = priv->frame.subbands;
1222 blocks = priv->frame.blocks;
1223 channels = priv->frame.channels;