23 #include <opus_multistream.h>
42 #define OPUS_HEAD_SIZE 19
47 int ret, channel_map = 0, gain_db = 0, nb_streams, nb_coupled;
48 uint8_t mapping_arr[8] = { 0, 1 }, *mapping;
64 if (nb_streams + nb_coupled != avc->
channels)
68 if (avc->
channels > 2 || channel_map) {
70 "No channel mapping for %d channels.\n", avc->
channels);
75 mapping = mapping_arr;
83 for (ch = 0; ch < avc->
channels; ch++)
84 mapping_arr[ch] = mapping[vorbis_offset[ch]];
85 mapping = mapping_arr;
89 nb_streams, nb_coupled,
98 ret = opus_multistream_decoder_ctl(opus->
dec, OPUS_SET_GAIN(gain_db));
104 double gain_lin = pow(10, gain_db / (20.0 * 256));
106 opus->
gain.
d = gain_lin;
108 opus->
gain.
i =
FFMIN(gain_lin * 65536, INT_MAX);
123 opus_multistream_decoder_destroy(opus->
dec);
127 #define MAX_FRAME_SIZE (960 * 6)
143 nb_samples = opus_multistream_decode(opus->
dec, pkt->
data, pkt->
size,
147 nb_samples = opus_multistream_decode_float(opus->
dec, pkt->
data, pkt->
size,
151 if (nb_samples < 0) {
153 opus_strerror(nb_samples));
157 #ifndef OPUS_SET_GAIN
161 float *pcm = (
float *)opus->
frame.
data[0];
162 for (; i > 0; i--, pcm++)
163 *pcm = av_clipf(*pcm * opus->
gain.
d, -1, 1);
165 int16_t *pcm = (int16_t *)opus->
frame.
data[0];
166 for (; i > 0; i--, pcm++)
167 *pcm = av_clip_int16(((int64_t)opus->
gain.
i * *pcm) >> 16);
182 opus_multistream_decoder_ctl(opus->
dec, OPUS_RESET_STATE);