23 #include <opus_multistream.h>
41 #define OPUS_HEAD_SIZE 19
46 int ret, channel_map = 0, gain_db = 0, nb_streams, nb_coupled;
47 uint8_t mapping_arr[8] = { 0, 1 }, *mapping;
63 if (nb_streams + nb_coupled != avc->
channels)
67 if (avc->
channels > 2 || channel_map) {
69 "No channel mapping for %d channels.\n", avc->
channels);
74 mapping = mapping_arr;
82 for (ch = 0; ch < avc->
channels; ch++)
83 mapping_arr[ch] = mapping[vorbis_offset[ch]];
84 mapping = mapping_arr;
88 nb_streams, nb_coupled,
97 ret = opus_multistream_decoder_ctl(opus->
dec, OPUS_SET_GAIN(gain_db));
103 double gain_lin = pow(10, gain_db / (20.0 * 256));
105 opus->
gain.
d = gain_lin;
107 opus->
gain.
i =
FFMIN(gain_lin * 65536, INT_MAX);
121 opus_multistream_decoder_destroy(opus->
dec);
125 #define MAX_FRAME_SIZE (960 * 6)
142 nb_samples = opus_multistream_decode(opus->
dec, pkt->
data, pkt->
size,
143 (opus_int16 *)frame->
data[0],
146 nb_samples = opus_multistream_decode_float(opus->
dec, pkt->
data, pkt->
size,
147 (
float *)frame->
data[0],
150 if (nb_samples < 0) {
152 opus_strerror(nb_samples));
156 #ifndef OPUS_SET_GAIN
160 float *pcm = (
float *)frame->
data[0];
161 for (; i > 0; i--, pcm++)
162 *pcm = av_clipf(*pcm * opus->
gain.
d, -1, 1);
164 int16_t *pcm = (int16_t *)frame->
data[0];
165 for (; i > 0; i--, pcm++)
166 *pcm = av_clip_int16(((int64_t)opus->
gain.
i * *pcm) >> 16);
181 opus_multistream_decoder_ctl(opus->
dec, OPUS_RESET_STATE);