1 /* Copyright (c) 2010 Xiph.Org Foundation, Skype Limited
2 Written by Jean-Marc Valin and Koen Vos */
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
8 - Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
19 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include "opus_encoder.h"
40 #include "SKP_Silk_SDK_API.h"
42 /* Transition tables for the voice and audio modes. First column is the
43 middle (memoriless) threshold. The second column is the hysteresis
44 (difference with the middle) */
45 static const int voice_bandwidth_thresholds[10] = {
46 11500, 1500, /* NB<->MB */
47 14500, 1500, /* MB<->WB */
48 21000, 2000, /* WB<->SWB */
49 29000, 2000, /* SWB<->FB */
51 static const int audio_bandwidth_thresholds[10] = {
52 30000, 0, /* MB not allowed */
53 20000, 2000, /* MB<->WB */
54 26000, 2000, /* WB<->SWB */
55 33000, 2000, /* SWB<->FB */
58 /* Make sure everything's aligned to 4 bytes (this may need to be increased
59 on really weird architectures) */
60 static inline int align(int i)
65 int opus_encoder_get_size(int channels)
67 int silkEncSizeBytes, celtEncSizeBytes;
69 ret = SKP_Silk_SDK_Get_Encoder_Size( &silkEncSizeBytes );
72 silkEncSizeBytes = align(silkEncSizeBytes);
73 celtEncSizeBytes = celt_encoder_get_size(channels);
74 return align(sizeof(OpusEncoder))+silkEncSizeBytes+celtEncSizeBytes;
78 OpusEncoder *opus_encoder_init(OpusEncoder* st, int Fs, int channels)
81 CELTEncoder *celt_enc;
83 int ret, silkEncSizeBytes, celtEncSizeBytes;
85 memset(st, 0, sizeof(OpusEncoder));
86 /* Create SILK encoder */
87 ret = SKP_Silk_SDK_Get_Encoder_Size( &silkEncSizeBytes );
90 silkEncSizeBytes = align(silkEncSizeBytes);
91 celtEncSizeBytes = celt_encoder_get_size(channels);
92 st->silk_enc_offset = align(sizeof(OpusEncoder));
93 st->celt_enc_offset = st->silk_enc_offset+silkEncSizeBytes;
94 silk_enc = (char*)st+st->silk_enc_offset;
95 celt_enc = (CELTEncoder*)((char*)st+st->celt_enc_offset);
97 st->stream_channels = st->channels = channels;
101 ret = SKP_Silk_SDK_InitEncoder( silk_enc, &st->silk_mode );
105 /* default SILK parameters */
106 st->silk_mode.API_sampleRate = st->Fs;
107 st->silk_mode.nChannels = channels;
108 st->silk_mode.maxInternalSampleRate = 16000;
109 st->silk_mode.minInternalSampleRate = 8000;
110 st->silk_mode.payloadSize_ms = 20;
111 st->silk_mode.packetLossPercentage = 0;
112 st->silk_mode.useInBandFEC = 0;
113 st->silk_mode.useDTX = 0;
114 st->silk_mode.complexity = 10;
116 /* Create CELT encoder */
117 /* Initialize CELT encoder */
118 celt_encoder_init(celt_enc, Fs, channels, &err);
121 celt_encoder_ctl(celt_enc, CELT_SET_SIGNALLING(0));
123 st->mode = MODE_HYBRID;
124 st->bandwidth = BANDWIDTH_FULLBAND;
126 st->user_bitrate_bps = OPUS_BITRATE_AUTO;
127 st->bitrate_bps = 3000+Fs*channels;
128 st->user_mode = OPUS_MODE_AUTO;
129 st->user_bandwidth = BANDWIDTH_AUTO;
130 st->voice_ratio = 90;
133 st->encoder_buffer = st->Fs/100;
134 st->delay_compensation = st->Fs/400;
136 st->delay_compensation += 10;
143 OpusEncoder *opus_encoder_create(int Fs, int channels)
145 char *raw_state = malloc(opus_encoder_get_size(channels));
146 if (raw_state == NULL)
148 return opus_encoder_init((OpusEncoder*)raw_state, Fs, channels);
151 int opus_encode(OpusEncoder *st, const short *pcm, int frame_size,
152 unsigned char *data, int max_data_bytes)
155 CELTEncoder *celt_enc;
160 int framerate, period;
161 int silk_internal_bandwidth=-1;
166 int redundancy_bytes = 0;
167 int celt_to_silk = 0;
168 /* TODO: This is 60 only so we can handle 60ms speech/audio switching
169 it shouldn't bee too hard to reduce to 20 ms if needed */
170 short pcm_buf[3*960*2];
173 celt_int32 mono_rate;
175 silk_enc = (char*)st+st->silk_enc_offset;
176 celt_enc = (CELTEncoder*)((char*)st+st->celt_enc_offset);
178 if (st->user_bitrate_bps==OPUS_BITRATE_AUTO)
179 st->bitrate_bps = 60*st->Fs/frame_size + st->Fs*st->channels;
181 st->bitrate_bps = st->user_bitrate_bps;
183 /* Rete-dependent mono-stereo decision */
184 if (st->channels == 2)
186 celt_int32 decision_rate;
187 decision_rate = st->bitrate_bps + st->voice_ratio*st->voice_ratio;
188 /* Add some hysteresis */
189 if (st->stream_channels == 2)
190 decision_rate += 4000;
192 decision_rate -= 4000;
193 if (decision_rate>48000)
194 st->stream_channels = 2;
196 st->stream_channels = 1;
198 st->stream_channels = 1;
200 /* Equivalent bit-rate for mono */
201 mono_rate = st->bitrate_bps;
202 if (st->stream_channels==2)
203 mono_rate = (mono_rate+10000)/2;
204 /* Compensate for smaller frame sizes assuming an equivalent overhead
206 mono_rate -= 60*(st->Fs/frame_size - 50);
209 if (st->user_mode==OPUS_MODE_AUTO)
211 celt_int32 decision_rate;
212 /* SILK/CELT threshold is higher for voice than for music */
213 decision_rate = mono_rate - 3*st->voice_ratio*st->voice_ratio;
215 if (st->prev_mode == MODE_CELT_ONLY)
216 decision_rate += 4000;
217 else if (st->prev_mode>0)
218 decision_rate -= 4000;
219 if (decision_rate>24000)
220 st->mode = MODE_CELT_ONLY;
222 st->mode = MODE_SILK_ONLY;
223 } else if (st->user_mode==OPUS_MODE_VOICE)
225 st->mode = MODE_SILK_ONLY;
226 } else {/* OPUS_AUDIO_MODE */
227 st->mode = MODE_CELT_ONLY;
230 /* Automatic (rate-dependent) bandwidth selection */
231 if (st->mode == MODE_CELT_ONLY || st->first || st->silk_mode.allowBandwidthSwitch)
233 const int *bandwidth_thresholds;
234 int bandwidth = BANDWIDTH_FULLBAND;
236 bandwidth_thresholds = st->mode == MODE_CELT_ONLY ? audio_bandwidth_thresholds : voice_bandwidth_thresholds;
238 int threshold, hysteresis;
239 threshold = bandwidth_thresholds[2*(bandwidth-BANDWIDTH_MEDIUMBAND)];
240 hysteresis = bandwidth_thresholds[2*(bandwidth-BANDWIDTH_MEDIUMBAND)+1];
243 if (st->bandwidth >= bandwidth)
244 threshold -= hysteresis;
246 threshold += hysteresis;
248 if (mono_rate >= threshold)
250 } while (--bandwidth>BANDWIDTH_NARROWBAND);
251 st->bandwidth = bandwidth;
252 /* Prevents any transition to SWB/FB until the SILK layer has fully
253 switched to WB mode and turned the variable LP filter off */
254 if (st->mode != MODE_CELT_ONLY && !st->silk_mode.inWBmodeWithoutVariableLP && st->bandwidth > BANDWIDTH_WIDEBAND)
255 st->bandwidth = BANDWIDTH_WIDEBAND;
258 /* Prevents Opus from wasting bits on frequencies that are above
259 the Nyquist rate of the input signal */
260 if (st->Fs <= 24000 && st->bandwidth > BANDWIDTH_SUPERWIDEBAND)
261 st->bandwidth = BANDWIDTH_SUPERWIDEBAND;
262 if (st->Fs <= 16000 && st->bandwidth > BANDWIDTH_WIDEBAND)
263 st->bandwidth = BANDWIDTH_WIDEBAND;
264 if (st->Fs <= 12000 && st->bandwidth > BANDWIDTH_MEDIUMBAND)
265 st->bandwidth = BANDWIDTH_MEDIUMBAND;
266 if (st->Fs <= 8000 && st->bandwidth > BANDWIDTH_NARROWBAND)
267 st->bandwidth = BANDWIDTH_NARROWBAND;
269 if (st->user_bandwidth != BANDWIDTH_AUTO)
270 st->bandwidth = st->user_bandwidth;
272 /* Prevents nonsensical configurations, i.e. modes that don't exist */
273 if (frame_size < st->Fs/100 && st->mode != MODE_CELT_ONLY)
274 st->mode = MODE_CELT_ONLY;
275 if (frame_size > st->Fs/50 && st->mode != MODE_SILK_ONLY)
276 st->mode = MODE_SILK_ONLY;
277 if (st->mode == MODE_CELT_ONLY && st->bandwidth == BANDWIDTH_MEDIUMBAND)
278 st->bandwidth = BANDWIDTH_WIDEBAND;
279 if (st->mode == MODE_SILK_ONLY && st->bandwidth > BANDWIDTH_WIDEBAND)
280 st->mode = MODE_HYBRID;
281 if (st->mode == MODE_HYBRID && st->bandwidth <= BANDWIDTH_WIDEBAND)
282 st->mode = MODE_SILK_ONLY;
284 bytes_target = st->bitrate_bps * frame_size / (st->Fs * 8) - 1;
287 if (st->mode != MODE_CELT_ONLY && st->prev_mode == MODE_CELT_ONLY)
289 SKP_SILK_SDK_EncControlStruct dummy;
290 SKP_Silk_SDK_InitEncoder( silk_enc, &dummy);
293 if (st->prev_mode >0 &&
294 ((st->mode != MODE_CELT_ONLY && st->prev_mode == MODE_CELT_ONLY)
295 || (st->mode == MODE_CELT_ONLY && st->prev_mode != MODE_CELT_ONLY)))
298 celt_to_silk = (st->mode != MODE_CELT_ONLY);
301 /* Switch to SILK/hybrid if frame size is 10 ms or more*/
302 if (frame_size >= st->Fs/100)
304 st->mode = st->prev_mode;
312 ec_enc_init(&enc, data, max_data_bytes-1);
314 /* SILK processing */
315 if (st->mode != MODE_CELT_ONLY)
317 st->silk_mode.bitRate = st->bitrate_bps - 8*st->Fs/frame_size;
318 if( st->mode == MODE_HYBRID ) {
319 if( st->bandwidth == BANDWIDTH_SUPERWIDEBAND ) {
320 if( st->Fs == 100 * frame_size ) {
322 st->silk_mode.bitRate = ( ( st->silk_mode.bitRate + 2000 + st->use_vbr * 1000 ) * 2 ) / 3;
325 st->silk_mode.bitRate = ( ( st->silk_mode.bitRate + 1000 + st->use_vbr * 1000 ) * 2 ) / 3;
328 if( st->Fs == 100 * frame_size ) {
330 st->silk_mode.bitRate = ( st->silk_mode.bitRate + 8000 + st->use_vbr * 3000 ) / 2;
333 st->silk_mode.bitRate = ( st->silk_mode.bitRate + 9000 + st->use_vbr * 1000 ) / 2;
336 /* don't let SILK use more than 80% */
337 if( st->silk_mode.bitRate > ( st->bitrate_bps - 8*st->Fs/frame_size ) * 4/5 ) {
338 st->silk_mode.bitRate = ( st->bitrate_bps - 8*st->Fs/frame_size ) * 4/5;
342 st->silk_mode.payloadSize_ms = 1000 * frame_size / st->Fs;
343 if (st->bandwidth == BANDWIDTH_NARROWBAND) {
344 st->silk_mode.desiredInternalSampleRate = 8000;
345 } else if (st->bandwidth == BANDWIDTH_MEDIUMBAND) {
346 st->silk_mode.desiredInternalSampleRate = 12000;
348 SKP_assert( st->mode == MODE_HYBRID || st->bandwidth == BANDWIDTH_WIDEBAND );
349 st->silk_mode.desiredInternalSampleRate = 16000;
351 if( st->mode == MODE_HYBRID ) {
352 /* Don't allow bandwidth reduction at lowest bitrates in hybrid mode */
353 st->silk_mode.minInternalSampleRate = 16000;
355 st->silk_mode.minInternalSampleRate = 8000;
357 st->silk_mode.maxInternalSampleRate = 16000;
359 /* Call SILK encoder for the low band */
360 nBytes = max_data_bytes-1;
364 SKP_Silk_SDK_Encode( silk_enc, &st->silk_mode, st->delay_buffer, st->encoder_buffer, NULL, &zero, 1 );
367 ret = SKP_Silk_SDK_Encode( silk_enc, &st->silk_mode, pcm, frame_size, &enc, &nBytes, 0 );
369 fprintf (stderr, "SILK encode error: %d\n", ret);
374 /* Extract SILK internal bandwidth for signaling in first byte */
375 if( st->mode == MODE_SILK_ONLY ) {
376 if( st->silk_mode.internalSampleRate == 8000 ) {
377 silk_internal_bandwidth = BANDWIDTH_NARROWBAND;
378 } else if( st->silk_mode.internalSampleRate == 12000 ) {
379 silk_internal_bandwidth = BANDWIDTH_MEDIUMBAND;
380 } else if( st->silk_mode.internalSampleRate == 16000 ) {
381 silk_internal_bandwidth = BANDWIDTH_WIDEBAND;
384 SKP_assert( st->silk_mode.internalSampleRate == 16000 );
388 /* CELT processing */
392 switch(st->bandwidth)
394 case BANDWIDTH_NARROWBAND:
397 case BANDWIDTH_WIDEBAND:
400 case BANDWIDTH_SUPERWIDEBAND:
403 case BANDWIDTH_FULLBAND:
407 celt_encoder_ctl(celt_enc, CELT_SET_END_BAND(endband));
408 celt_encoder_ctl(celt_enc, CELT_SET_CHANNELS(st->stream_channels));
410 if (st->mode != MODE_SILK_ONLY)
412 celt_encoder_ctl(celt_enc, CELT_SET_VBR(0));
413 celt_encoder_ctl(celt_enc, CELT_SET_BITRATE(510000));
414 if (st->prev_mode == MODE_SILK_ONLY)
416 unsigned char dummy[10];
417 celt_encoder_ctl(celt_enc, CELT_RESET_STATE);
418 celt_encoder_ctl(celt_enc, CELT_SET_START_BAND(0));
419 celt_encoder_ctl(celt_enc, CELT_SET_PREDICTION(0));
420 /* TODO: This wastes CPU a bit compared to just prefilling the buffer */
421 celt_encode(celt_enc, &st->delay_buffer[(st->encoder_buffer-st->delay_compensation-st->Fs/400)*st->channels], st->Fs/400, dummy, 10);
423 celt_encoder_ctl(celt_enc, CELT_SET_PREDICTION(2));
426 if (st->mode == MODE_HYBRID)
430 len = (ec_tell(&enc)+7)>>3;
432 nb_compr_bytes = len + bytes_target - (st->silk_mode.bitRate * frame_size) / (8 * st->Fs);
434 /* check if SILK used up too much */
435 nb_compr_bytes = len > bytes_target ? len : bytes_target;
440 celt_encoder_ctl(celt_enc, CELT_SET_VBR(1));
441 celt_encoder_ctl(celt_enc, CELT_SET_VBR_CONSTRAINT(st->vbr_constraint));
442 celt_encoder_ctl(celt_enc, CELT_SET_BITRATE(st->bitrate_bps));
443 nb_compr_bytes = max_data_bytes-1;
445 nb_compr_bytes = bytes_target;
449 ec_enc_shrink(&enc, nb_compr_bytes);
454 for (i=0;i<IMIN(frame_size, st->delay_compensation)*st->channels;i++)
455 pcm_buf[i] = st->delay_buffer[(st->encoder_buffer-st->delay_compensation)*st->channels+i];
456 for (;i<frame_size*st->channels;i++)
457 pcm_buf[i] = pcm[i-st->delay_compensation*st->channels];
458 if (st->mode != MODE_CELT_ONLY)
460 /* Check if we have a redundant 0-8 kHz band */
461 ec_enc_bit_logp(&enc, redundancy, 12);
464 redundancy_bytes = st->stream_channels*st->bitrate_bps/1600;
465 ec_enc_bit_logp(&enc, celt_to_silk, 1);
466 if (st->mode == MODE_HYBRID)
467 ec_enc_uint(&enc, redundancy_bytes-2, 256);
472 if (st->mode == MODE_SILK_ONLY)
474 ret = (ec_tell(&enc)+7)>>3;
476 nb_compr_bytes = ret;
479 /* 5 ms redundant frame for CELT->SILK */
480 if (redundancy && celt_to_silk)
482 celt_encoder_ctl(celt_enc, CELT_SET_START_BAND(0));
483 celt_encoder_ctl(celt_enc, CELT_SET_VBR(0));
484 celt_encode(celt_enc, pcm_buf, st->Fs/200, data+nb_compr_bytes, redundancy_bytes);
485 celt_encoder_ctl(celt_enc, CELT_RESET_STATE);
488 celt_encoder_ctl(celt_enc, CELT_SET_START_BAND(start_band));
490 if (st->mode != MODE_SILK_ONLY)
492 /* Encode high band with CELT */
493 ret = celt_encode_with_ec(celt_enc, pcm_buf, frame_size, NULL, nb_compr_bytes, &enc);
496 /* 5 ms redundant frame for SILK->CELT */
497 if (redundancy && !celt_to_silk)
503 celt_encoder_ctl(celt_enc, CELT_RESET_STATE);
504 celt_encoder_ctl(celt_enc, CELT_SET_START_BAND(0));
505 celt_encoder_ctl(celt_enc, CELT_SET_PREDICTION(0));
507 /* TODO: We could speed up prefilling here */
508 celt_encode(celt_enc, pcm_buf+st->channels*(frame_size-N2-N4), N4, data+nb_compr_bytes, redundancy_bytes);
510 celt_encode(celt_enc, pcm_buf+st->channels*(frame_size-N2), N2, data+nb_compr_bytes, redundancy_bytes);
514 if (frame_size>st->encoder_buffer)
516 for (i=0;i<st->encoder_buffer*st->channels;i++)
517 st->delay_buffer[i] = pcm[(frame_size-st->encoder_buffer)*st->channels+i];
519 int tmp = st->encoder_buffer-frame_size;
520 for (i=0;i<tmp*st->channels;i++)
521 st->delay_buffer[i] = st->delay_buffer[i+frame_size*st->channels];
522 for (i=0;i<frame_size*st->channels;i++)
523 st->delay_buffer[tmp*st->channels+i] = pcm[i];
526 /* Signalling the mode in the first byte */
528 framerate = st->Fs/frame_size;
530 while (framerate < 400)
535 if (st->mode == MODE_SILK_ONLY)
537 data[0] = (silk_internal_bandwidth-BANDWIDTH_NARROWBAND)<<5;
538 data[0] |= (period-2)<<3;
539 } else if (st->mode == MODE_CELT_ONLY)
541 int tmp = st->bandwidth-BANDWIDTH_MEDIUMBAND;
546 data[0] |= period<<3;
550 data[0] |= (st->bandwidth-BANDWIDTH_SUPERWIDEBAND)<<4;
551 data[0] |= (period-2)<<3;
553 data[0] |= (st->stream_channels==2)<<2;
554 /*printf ("%x\n", (int)data[0]);*/
556 #if OPUS_TEST_RANGE_CODER_STATE
557 st->rangeFinal = enc.rng;
560 st->prev_mode = MODE_CELT_ONLY;
562 st->prev_mode = st->mode;
564 return ret+1+redundancy_bytes;
567 int opus_encoder_ctl(OpusEncoder *st, int request, ...)
569 CELTEncoder *celt_enc;
572 va_start(ap, request);
574 celt_enc = (CELTEncoder*)((char*)st+st->celt_enc_offset);
578 case OPUS_SET_MODE_REQUEST:
580 int value = va_arg(ap, int);
581 st->user_mode = value;
584 case OPUS_GET_MODE_REQUEST:
586 int *value = va_arg(ap, int*);
590 case OPUS_SET_BITRATE_REQUEST:
592 int value = va_arg(ap, int);
593 if (value != OPUS_BITRATE_AUTO)
597 else if (value <= 500)
600 st->user_bitrate_bps = value;
603 case OPUS_GET_BITRATE_REQUEST:
605 int *value = va_arg(ap, int*);
606 *value = st->bitrate_bps;
609 case OPUS_SET_BANDWIDTH_REQUEST:
611 int value = va_arg(ap, int);
612 if (value < BANDWIDTH_AUTO || value > BANDWIDTH_FULLBAND)
614 st->user_bandwidth = value;
615 if (st->user_bandwidth == BANDWIDTH_NARROWBAND) {
616 st->silk_mode.maxInternalSampleRate = 8000;
617 } else if (st->bandwidth == BANDWIDTH_MEDIUMBAND) {
618 st->silk_mode.maxInternalSampleRate = 12000;
620 st->silk_mode.maxInternalSampleRate = 16000;
624 case OPUS_GET_BANDWIDTH_REQUEST:
626 int *value = va_arg(ap, int*);
627 *value = st->bandwidth;
630 case OPUS_SET_DTX_FLAG_REQUEST:
632 int value = va_arg(ap, int);
633 st->silk_mode.useDTX = value;
636 case OPUS_GET_DTX_FLAG_REQUEST:
638 int *value = va_arg(ap, int*);
639 *value = st->silk_mode.useDTX;
642 case OPUS_SET_COMPLEXITY_REQUEST:
644 int value = va_arg(ap, int);
645 st->silk_mode.complexity = value;
646 celt_encoder_ctl(celt_enc, CELT_SET_COMPLEXITY(value));
649 case OPUS_GET_COMPLEXITY_REQUEST:
651 int *value = va_arg(ap, int*);
652 *value = st->silk_mode.complexity;
655 case OPUS_SET_INBAND_FEC_FLAG_REQUEST:
657 int value = va_arg(ap, int);
658 st->silk_mode.useInBandFEC = value;
661 case OPUS_GET_INBAND_FEC_FLAG_REQUEST:
663 int *value = va_arg(ap, int*);
664 *value = st->silk_mode.useInBandFEC;
667 case OPUS_SET_PACKET_LOSS_PERC_REQUEST:
669 int value = va_arg(ap, int);
670 if (value < 0 || value > 100)
672 st->silk_mode.packetLossPercentage = value;
673 celt_encoder_ctl(celt_enc, CELT_SET_LOSS_PERC(value));
676 case OPUS_GET_PACKET_LOSS_PERC_REQUEST:
678 int *value = va_arg(ap, int*);
679 *value = st->silk_mode.packetLossPercentage;
682 case OPUS_SET_VBR_FLAG_REQUEST:
684 int value = va_arg(ap, int);
686 st->silk_mode.useCBR = 1-value;
689 case OPUS_GET_VBR_FLAG_REQUEST:
691 int *value = va_arg(ap, int*);
692 *value = st->use_vbr;
695 case OPUS_SET_VOICE_RATIO_REQUEST:
697 int value = va_arg(ap, int);
698 if (value>100 || value<0)
700 st->voice_ratio = value;
703 case OPUS_GET_VOICE_RATIO_REQUEST:
705 int *value = va_arg(ap, int*);
706 *value = st->voice_ratio;
709 case OPUS_SET_VBR_CONSTRAINT_REQUEST:
711 int value = va_arg(ap, int);
712 st->vbr_constraint = value;
715 case OPUS_GET_VBR_CONSTRAINT_REQUEST:
717 int *value = va_arg(ap, int*);
718 *value = st->vbr_constraint;
722 fprintf(stderr, "unknown opus_encoder_ctl() request: %d", request);
732 void opus_encoder_destroy(OpusEncoder *st)
737 #if OPUS_TEST_RANGE_CODER_STATE
738 int opus_encoder_get_final_range(OpusEncoder *st)
740 return st->rangeFinal;