42 #include <speex/speex.h> 48 #include <speex/speex_preprocess.h> 81 #define TYPE_SILENCE 0x2 86 #define BUFFER_SAMPLES 8000 87 #define SPEEX_SAMPLES 160 103 #ifdef _SPEEX_TYPES_H 104 SpeexPreprocessState *pp;
115 if (!(tmp->
speex = speex_encoder_init(profile)))
118 speex_bits_init(&tmp->
bits);
119 speex_bits_reset(&tmp->
bits);
120 speex_encoder_ctl(tmp->
speex, SPEEX_GET_FRAME_SIZE, &tmp->
framesize);
122 #ifdef _SPEEX_TYPES_H 124 tmp->pp = speex_preprocess_state_init(tmp->
framesize, sampling_rate);
125 speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_VAD, &
pp_vad);
126 speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_AGC, &
pp_agc);
127 speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_AGC_LEVEL, &
pp_agc_level);
128 speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_DENOISE, &
pp_denoise);
129 speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_DEREVERB, &
pp_dereverb);
130 speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_DEREVERB_DECAY, &
pp_dereverb_decay);
131 speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &
pp_dereverb_level);
135 speex_encoder_ctl(tmp->
speex, SPEEX_SET_QUALITY, &
quality);
137 speex_encoder_ctl(tmp->
speex, SPEEX_SET_VAD, &
vad);
140 speex_encoder_ctl(tmp->
speex, SPEEX_SET_VBR, &
vbr);
144 speex_encoder_ctl(tmp->
speex, SPEEX_SET_ABR, &
abr);
146 speex_encoder_ctl(tmp->
speex, SPEEX_SET_DTX, &
dtx);
176 if (!(tmp->
speex = speex_decoder_init(profile)))
179 speex_bits_init(&tmp->
bits);
180 speex_decoder_ctl(tmp->
speex, SPEEX_GET_FRAME_SIZE, &tmp->
framesize);
213 #ifdef _SPEEX_TYPES_H 214 spx_int16_t fout[1024];
224 #ifdef _SPEEX_TYPES_H 240 #ifdef _SPEEX_TYPES_H 241 res = speex_decode_int(tmp->
speex, &tmp->
bits, fout);
243 res = speex_decode(tmp->
speex, &tmp->
bits, fout);
284 speex_bits_reset(&tmp->
bits);
286 #ifdef _SPEEX_TYPES_H 289 is_speech = speex_preprocess(tmp->pp, tmp->
buf + samples,
NULL);
293 is_speech = speex_encode_int(tmp->
speex, tmp->
buf + samples, &tmp->
bits) || !
dtx;
296 speex_bits_pack(&tmp->
bits, 0, 5);
304 fbuf[x] = tmp->
buf[samples + x];
306 is_speech = speex_encode(tmp->
speex, fbuf, &tmp->
bits) || !
dtx;
318 speex_bits_pack(&tmp->
bits, 15, 5);
390 percent = (fraction_lost*100)/256;
393 ast_debug(3,
"Fraction lost changed: %d --> %d percent loss\n", fraction_lost, percent);
395 speex_encoder_ctl(tmp->
speex, SPEEX_GET_BITRATE, &bitrate);
396 ast_debug(3,
"Current bitrate: %d\n", bitrate);
402 }
else if (percent < 20) {
405 }
else if (percent < 30) {
418 speex_encoder_ctl(tmp->
speex, SPEEX_SET_VBR_QUALITY, &vbr_q);
420 speex_encoder_ctl(tmp->
speex, SPEEX_SET_QUALITY, &q);
431 speex_decoder_destroy(pvt->
speex);
432 speex_bits_destroy(&pvt->
bits);
438 #ifdef _SPEEX_TYPES_H 440 speex_preprocess_state_destroy(pvt->pp);
442 speex_encoder_destroy(pvt->
speex);
443 speex_bits_destroy(&pvt->
bits);
447 .
name =
"speextolin",
470 .
name =
"lintospeex",
494 .
name =
"speexwbtolin16",
498 .sample_rate = 16000,
503 .sample_rate = 16000,
517 .
name =
"lin16tospeexwb",
521 .sample_rate = 16000,
526 .sample_rate = 16000,
541 .
name =
"speexuwbtolin32",
545 .sample_rate = 32000,
550 .sample_rate = 32000,
563 .
name =
"lin32tospeexuwb",
567 .sample_rate = 32000,
572 .sample_rate = 32000,
597 if (!strcasecmp(var->
name,
"quality")) {
599 if (res > -1 && res < 11) {
600 ast_verb(3,
"CODEC SPEEX: Setting Quality to %d\n",res);
604 }
else if (!strcasecmp(var->
name,
"complexity")) {
606 if (res > -1 && res < 11) {
607 ast_verb(3,
"CODEC SPEEX: Setting Complexity to %d\n",res);
611 }
else if (!strcasecmp(var->
name,
"vbr_quality")) {
612 if (sscanf(var->
value,
"%30f", &res_f) == 1 && res_f >= 0 && res_f <= 10) {
613 ast_verb(3,
"CODEC SPEEX: Setting VBR Quality to %f\n",res_f);
617 }
else if (!strcasecmp(var->
name,
"abr_quality")) {
618 ast_log(
LOG_ERROR,
"Error! ABR Quality setting obsolete, set ABR to desired bitrate\n");
619 }
else if (!strcasecmp(var->
name,
"enhancement")) {
621 ast_verb(3,
"CODEC SPEEX: Perceptual Enhancement Mode. [%s]\n",
enhancement ?
"on" :
"off");
622 }
else if (!strcasecmp(var->
name,
"vbr")) {
624 ast_verb(3,
"CODEC SPEEX: VBR Mode. [%s]\n",
vbr ?
"on" :
"off");
625 }
else if (!strcasecmp(var->
name,
"abr")) {
629 ast_verb(3,
"CODEC SPEEX: Setting ABR target bitrate to %d\n",res);
631 ast_verb(3,
"CODEC SPEEX: Disabling ABR\n");
635 }
else if (!strcasecmp(var->
name,
"vad")) {
637 ast_verb(3,
"CODEC SPEEX: VAD Mode. [%s]\n",
vad ?
"on" :
"off");
638 }
else if (!strcasecmp(var->
name,
"dtx")) {
640 ast_verb(3,
"CODEC SPEEX: DTX Mode. [%s]\n",
dtx ?
"on" :
"off");
641 }
else if (!strcasecmp(var->
name,
"preprocess")) {
643 ast_verb(3,
"CODEC SPEEX: Preprocessing. [%s]\n",
preproc ?
"on" :
"off");
644 }
else if (!strcasecmp(var->
name,
"pp_vad")) {
646 ast_verb(3,
"CODEC SPEEX: Preprocessor VAD. [%s]\n",
pp_vad ?
"on" :
"off");
647 }
else if (!strcasecmp(var->
name,
"pp_agc")) {
649 ast_verb(3,
"CODEC SPEEX: Preprocessor AGC. [%s]\n",
pp_agc ?
"on" :
"off");
650 }
else if (!strcasecmp(var->
name,
"pp_agc_level")) {
651 if (sscanf(var->
value,
"%30f", &res_f) == 1 && res_f >= 0) {
652 ast_verb(3,
"CODEC SPEEX: Setting preprocessor AGC Level to %f\n",res_f);
656 }
else if (!strcasecmp(var->
name,
"pp_denoise")) {
659 }
else if (!strcasecmp(var->
name,
"pp_dereverb")) {
662 }
else if (!strcasecmp(var->
name,
"pp_dereverb_decay")) {
663 if (sscanf(var->
value,
"%30f", &res_f) == 1 && res_f >= 0) {
664 ast_verb(3,
"CODEC SPEEX: Setting preprocessor Dereverb Decay to %f\n",res_f);
668 }
else if (!strcasecmp(var->
name,
"pp_dereverb_level")) {
669 if (sscanf(var->
value,
"%30f", &res_f) == 1 && res_f >= 0) {
670 ast_verb(3,
"CODEC SPEEX: Setting preprocessor Dereverb Level to %f\n",res_f);
674 }
else if (!strcasecmp(var->
name,
"experimental_rtcp_feedback")) {
struct ast_variable * next
static int speexwbtolin16_new(struct ast_trans_pvt *pvt)
struct ast_frame * ast_trans_frameout(struct ast_trans_pvt *pvt, int datalen, int samples)
generic frameout function
int datalen
actual space used in outbuf
static float pp_dereverb_decay
An object that represents data sent during a SR/RR RTCP report.
static void lintospeex_destroy(struct ast_trans_pvt *arg)
Asterisk main include file. File version handling, generic pbx functions.
Descriptor of a translator.
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
static struct ast_translator lin16tospeexwb
Support for translation of data formats. translate.c.
static int speex_decoder_construct(struct ast_trans_pvt *pvt, const SpeexMode *profile)
#define CONFIG_STATUS_FILEINVALID
static int lin16tospeexwb_new(struct ast_trans_pvt *pvt)
Structure for variables, used for configurations and for channel variables.
unsigned short reception_report_count
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
static struct ast_frame * lintospeex_frameout(struct ast_trans_pvt *pvt)
convert work buffer and produce output frame
struct ast_rtp_rtcp_report_block * report_block[0]
static int lintospeex_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
store input frame in work buffer
A report block within a SR/RR report.
static struct ast_translator lin32tospeexuwb
int16_t buf[BUFFER_SAMPLES]
static int load_module(void)
static void speextolin_destroy(struct ast_trans_pvt *arg)
static struct ast_frame * slin8_sample(void)
static int speexuwbtolin32_new(struct ast_trans_pvt *pvt)
static int parse_config(int reload)
static int lin32tospeexuwb_new(struct ast_trans_pvt *pvt)
#define ast_verb(level,...)
static void lintospeex_feedback(struct ast_trans_pvt *pvt, struct ast_frame *feedback)
handle incoming RTCP feedback and possibly edit encoder settings
struct ast_frame_subclass subclass
static struct ast_frame * slin16_sample(void)
Configuration File Parser.
#define ast_debug(level,...)
Log a DEBUG message.
#define ast_config_load(filename, flags)
Load a config file.
static float pp_dereverb_level
static int speextolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
convert and store into outbuf
struct sla_ringing_trunk * last
#define ast_register_translator(t)
See __ast_register_translator()
Asterisk internal frame definitions.
void ast_config_destroy(struct ast_config *config)
Destroys a config.
int ast_unregister_translator(struct ast_translator *t)
Unregister a translator Unregisters the given tranlator.
A set of macros to manage forward-linked lists.
static int speextolin_new(struct ast_trans_pvt *pvt)
int buf_size
size of outbuf, in bytes. Mandatory. The wrapper code will also allocate an AST_FRIENDLY_OFFSET space...
static struct ast_frame * speex_sample(void)
#define CONFIG_STATUS_FILEUNCHANGED
static struct ast_translator speexuwbtolin32
union ast_trans_pvt::@327 outbuf
static int unload_module(void)
static struct ast_translator lintospeex
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Default structure for translators, with the basic fields and buffers, all allocated as part of the sa...
static struct ast_translator speexwbtolin16
static int speex_encoder_construct(struct ast_trans_pvt *pvt, const SpeexMode *profile, int sampling_rate)
static struct ast_frame * speex16_sample(void)
Module has failed to load, may be in an inconsistent state.
#define ast_frisolate(fr)
Makes a frame independent of any static storage.
static int lintospeex_new(struct ast_trans_pvt *pvt)
Structure used to handle boolean flags.
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
#define CONFIG_STATUS_FILEMISSING
Data structure associated with a single frame of data.
struct ast_translator * t
union ast_frame::@263 data
enum ast_frame_type frametype
static float pp_agc_level
static struct ast_translator speextolin
#define ASTERISK_GPL_KEY
The text the key() function should return.
Pluggable RTP Architecture.
Asterisk module definitions.
struct ast_rtp_rtcp_report_block::@314 lost_count