84 #include <speex/speex.h>
85 #include <speex/speex_header.h>
86 #include <speex/speex_stereo.h>
114 const char *mode_str =
"unknown";
118 case SPEEX_MODEID_NB: mode_str =
"narrowband";
break;
119 case SPEEX_MODEID_WB: mode_str =
"wideband";
break;
120 case SPEEX_MODEID_UWB: mode_str =
"ultra-wideband";
break;
148 const SpeexMode *
mode;
156 "mono are supported\n", avctx->
channels);
162 case 8000: mode = &speex_nb_mode;
break;
163 case 16000: mode = &speex_wb_mode;
break;
164 case 32000: mode = &speex_uwb_mode;
break;
167 "Resample to 8, 16, or 32 kHz.\n", avctx->
sample_rate);
193 speex_encoder_ctl(s->
enc_state, SPEEX_SET_ABR,
195 speex_encoder_ctl(s->
enc_state, SPEEX_GET_ABR,
198 speex_encoder_ctl(s->
enc_state, SPEEX_SET_BITRATE,
200 speex_encoder_ctl(s->
enc_state, SPEEX_GET_BITRATE,
205 speex_encoder_ctl(s->
enc_state, SPEEX_SET_QUALITY,
207 speex_encoder_ctl(s->
enc_state, SPEEX_GET_BITRATE,
217 speex_encoder_ctl(s->
enc_state, SPEEX_SET_VAD, &s->
vad);
221 speex_encoder_ctl(s->
enc_state, SPEEX_SET_DTX, &s->
dtx);
229 speex_encoder_ctl(s->
enc_state, SPEEX_SET_COMPLEXITY, &complexity);
231 speex_encoder_ctl(s->
enc_state, SPEEX_GET_COMPLEXITY, &complexity);
239 speex_encoder_ctl(s->
enc_state, SPEEX_GET_LOOKAHEAD, &avctx->
delay);
245 header_data = speex_header_to_packet(&s->
header, &header_size);
250 speex_header_free(header_data);
257 memcpy(avctx->
extradata, header_data, header_size);
259 speex_header_free(header_data);
262 speex_bits_init(&s->
bits);
272 int16_t *samples = frame ? (int16_t *)frame->
data[0] : NULL;
278 speex_encode_stereo_int(samples, s->
header.frame_size, &s->
bits);
289 speex_bits_pack(&s->
bits, 15, 5);
300 speex_bits_reset(&s->
bits);
317 speex_bits_destroy(&s->
bits);
326 #define OFFSET(x) offsetof(LibSpeexEncContext, x)
327 #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
330 {
"cbr_quality",
"Set quality value (0 to 10) for CBR",
OFFSET(cbr_quality),
AV_OPT_TYPE_INT, { .i64 = 8 }, 0, 10,
AE },
331 {
"frames_per_packet",
"Number of frames to encode in each packet",
OFFSET(frames_per_packet),
AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 8,
AE },
346 {
"compression_level",
"3" },
364 .supported_samplerates = (
const int[]){ 8000, 16000, 32000, 0 },