int16_t WebRtcOpus_Decode(OpusDecInst* inst, int16_t* encoded, int16_t encoded_bytes, int16_t* decoded, int16_t* audio_type) { /* Enough for 120 ms (the largest Opus packet size) of mono audio at 48 kHz * and resampler overlap. This will need to be enlarged for stereo decoding. */ int16_t buffer16[kWebRtcOpusMaxFrameSize]; int32_t buffer32[kWebRtcOpusMaxFrameSize + 7]; int decoded_samples; int blocks; int16_t output_samples; int i; /* If mono case, just do a regular call to the decoder. * If stereo, call to WebRtcOpus_Decode() gives left channel as output, and * calls to WebRtcOpus_Decode_slave() give right channel as output. * This is to make stereo work with the current setup of NetEQ, which * requires two calls to the decoder to produce stereo. */ /* Decode to a temporary buffer. */ decoded_samples = DecodeNative(inst->decoder_left, encoded, encoded_bytes, buffer16, audio_type); if (decoded_samples < 0) { return -1; } if (inst->channels == 2) { /* The parameter |decoded_samples| holds the number of samples pairs, in * case of stereo. Number of samples in |buffer16| equals |decoded_samples| * times 2. */ for (i = 0; i < decoded_samples; i++) { /* Take every second sample, starting at the first sample. This gives * the left channel. */ buffer16[i] = buffer16[i * 2]; } } /* Resample from 48 kHz to 32 kHz. */ for (i = 0; i < 7; i++) { buffer32[i] = inst->state_48_32_left[i]; inst->state_48_32_left[i] = buffer16[decoded_samples - 7 + i]; } for (i = 0; i < decoded_samples; i++) { buffer32[7 + i] = buffer16[i]; } /* Resampling 3 samples to 2. Function divides the input in |blocks| number * of 3-sample groups, and output is |blocks| number of 2-sample groups. * When this is removed, the compensation in WebRtcOpus_DurationEst should be * removed too. */ blocks = decoded_samples / 3; WebRtcSpl_Resample48khzTo32khz(buffer32, buffer32, blocks); output_samples = (int16_t) (blocks * 2); WebRtcSpl_VectorBitShiftW32ToW16(decoded, output_samples, buffer32, 15); return output_samples; }
int16_t WebRtcOpus_DecodeSlave(OpusDecInst* inst, int16_t* encoded, int16_t encoded_bytes, int16_t* decoded, int16_t* audio_type) { /* Enough for 120 ms (the largest Opus packet size) of mono audio at 48 kHz * and resampler overlap. This will need to be enlarged for stereo decoding. */ int16_t buffer16[kWebRtcOpusMaxFrameSize]; int32_t buffer32[kWebRtcOpusMaxFrameSize + 7]; int decoded_samples; int blocks; int16_t output_samples; int i; /* Decode to a temporary buffer. */ decoded_samples = DecodeNative(inst->decoder_right, encoded, encoded_bytes, buffer16, audio_type); if (decoded_samples < 0) { return -1; } if (inst->channels == 2) { /* The parameter |decoded_samples| holds the number of samples pairs, in * case of stereo. Number of samples in |buffer16| equals |decoded_samples| * times 2. */ for (i = 0; i < decoded_samples; i++) { /* Take every second sample, starting at the second sample. This gives * the right channel. */ buffer16[i] = buffer16[i * 2 + 1]; } } else { /* Decode slave should never be called for mono packets. */ return -1; } /* Resample from 48 kHz to 32 kHz. */ for (i = 0; i < 7; i++) { buffer32[i] = inst->state_48_32_right[i]; inst->state_48_32_right[i] = buffer16[decoded_samples - 7 + i]; } for (i = 0; i < decoded_samples; i++) { buffer32[7 + i] = buffer16[i]; } /* Resampling 3 samples to 2. Function divides the input in |blocks| number * of 3-sample groups, and output is |blocks| number of 2-sample groups. */ blocks = decoded_samples / 3; WebRtcSpl_Resample48khzTo32khz(buffer32, buffer32, blocks); output_samples = (int16_t) (blocks * 2); WebRtcSpl_VectorBitShiftW32ToW16(decoded, output_samples, buffer32, 15); return output_samples; }
int16_t WebRtcOpus_Decode(OpusDecInst* inst, int16_t* encoded, int16_t encoded_bytes, int16_t* decoded, int16_t* audio_type) { /* Enough for 120 ms (the largest Opus packet size) of mono audio at 48 kHz * and resampler overlap. This will need to be enlarged for stereo decoding. */ int16_t buffer16[kWebRtcOpusMaxFrameSize]; int32_t buffer32[kWebRtcOpusMaxFrameSize + 7]; int decoded_samples; int blocks; int16_t output_samples; int i; /* Decode to a temporary buffer. */ decoded_samples = DecodeNative(inst, encoded, encoded_bytes, buffer16, audio_type); if (decoded_samples < 0) { return -1; } /* Resample from 48 kHz to 32 kHz. */ for (i = 0; i < 7; i++) { buffer32[i] = inst->state_48_32[i]; inst->state_48_32[i] = buffer16[decoded_samples -7 + i]; } for (i = 0; i < decoded_samples; i++) { buffer32[7 + i] = buffer16[i]; } /* Resampling 3 samples to 2. Function divides the input in |blocks| number * of 3-sample groups, and output is |blocks| number of 2-sample groups. */ blocks = decoded_samples / 3; WebRtcSpl_Resample48khzTo32khz(buffer32, buffer32, blocks); output_samples = (int16_t) (blocks * 2); WebRtcSpl_VectorBitShiftW32ToW16(decoded, output_samples, buffer32, 15); return output_samples; }