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 
  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);
 
  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);
 
 
  214    spx_int16_t fout[1024];
 
  229            dst[pvt->
samples + x] = (int16_t)fout[x];
 
  241        res = speex_decode_int(tmp->
speex, &tmp->
bits, fout);
 
  243        res = speex_decode(tmp->
speex, &tmp->
bits, fout);
 
  252            dst[pvt->
samples + x] = (int16_t)fout[x];
 
 
  284        speex_bits_reset(&tmp->
bits);
 
  296            speex_bits_pack(&tmp->
bits, 0, 5);
 
  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);
 
 
  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")) {
 
  598            res = 
abs(atoi(
var->value));
 
  599            if (res > -1 && res < 11) {
 
  600                ast_verb(5, 
"CODEC SPEEX: Setting Quality to %d\n",res);
 
  604        } 
else if (!strcasecmp(
var->name, 
"complexity")) {
 
  605            res = 
abs(atoi(
var->value));
 
  606            if (res > -1 && res < 11) {
 
  607                ast_verb(5, 
"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(5, 
"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(5, 
"CODEC SPEEX: Perceptual Enhancement Mode. [%s]\n",
enhancement ? 
"on" : 
"off");
 
  622        } 
else if (!strcasecmp(
var->name, 
"vbr")) {
 
  624            ast_verb(5, 
"CODEC SPEEX: VBR Mode. [%s]\n",
vbr ? 
"on" : 
"off");
 
  625        } 
else if (!strcasecmp(
var->name, 
"abr")) {
 
  626            res = 
abs(atoi(
var->value));
 
  629                    ast_verb(5, 
"CODEC SPEEX: Setting ABR target bitrate to %d\n",res);
 
  631                    ast_verb(5, 
"CODEC SPEEX: Disabling ABR\n");
 
  635        } 
else if (!strcasecmp(
var->name, 
"vad")) {
 
  637            ast_verb(5, 
"CODEC SPEEX: VAD Mode. [%s]\n",
vad ? 
"on" : 
"off");
 
  638        } 
else if (!strcasecmp(
var->name, 
"dtx")) {
 
  640            ast_verb(5, 
"CODEC SPEEX: DTX Mode. [%s]\n",
dtx ? 
"on" : 
"off");
 
  641        } 
else if (!strcasecmp(
var->name, 
"preprocess")) {
 
  643            ast_verb(5, 
"CODEC SPEEX: Preprocessing. [%s]\n",
preproc ? 
"on" : 
"off");
 
  644        } 
else if (!strcasecmp(
var->name, 
"pp_vad")) {
 
  646            ast_verb(5, 
"CODEC SPEEX: Preprocessor VAD. [%s]\n",
pp_vad ? 
"on" : 
"off");
 
  647        } 
else if (!strcasecmp(
var->name, 
"pp_agc")) {
 
  649            ast_verb(5, 
"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(5, 
"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(5, 
"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(5, 
"CODEC SPEEX: Setting preprocessor Dereverb Level to %f\n",res_f);
 
  674        } 
else if (!strcasecmp(
var->name, 
"experimental_rtcp_feedback")) {
 
 
struct sla_ringing_trunk * last
Asterisk main include file. File version handling, generic pbx functions.
static struct ast_translator speextolin
static struct ast_translator speexuwbtolin32
static int speexuwbtolin32_new(struct ast_trans_pvt *pvt)
static struct ast_translator speexwbtolin16
static struct ast_translator lintospeex
static float pp_agc_level
static int speextolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
convert and store into outbuf
static int speex_encoder_construct(struct ast_trans_pvt *pvt, const SpeexMode *profile, int sampling_rate)
static int speextolin_new(struct ast_trans_pvt *pvt)
static int lintospeex_new(struct ast_trans_pvt *pvt)
static int lin32tospeexuwb_new(struct ast_trans_pvt *pvt)
static void lintospeex_feedback(struct ast_trans_pvt *pvt, struct ast_frame *feedback)
handle incoming RTCP feedback and possibly edit encoder settings
static int speexwbtolin16_new(struct ast_trans_pvt *pvt)
static struct ast_frame * lintospeex_frameout(struct ast_trans_pvt *pvt)
convert work buffer and produce output frame
static void lintospeex_destroy(struct ast_trans_pvt *arg)
static int lintospeex_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
store input frame in work buffer
static void speextolin_destroy(struct ast_trans_pvt *arg)
static int load_module(void)
static struct ast_translator lin32tospeexuwb
static float pp_dereverb_level
static int lin16tospeexwb_new(struct ast_trans_pvt *pvt)
static int unload_module(void)
static int speex_decoder_construct(struct ast_trans_pvt *pvt, const SpeexMode *profile)
static struct ast_translator lin16tospeexwb
static float pp_dereverb_decay
static struct ast_frame * speex16_sample(void)
static struct ast_frame * speex_sample(void)
Configuration File Parser.
#define ast_config_load(filename, flags)
Load a config file.
#define CONFIG_STATUS_FILEMISSING
#define CONFIG_STATUS_FILEUNCHANGED
#define CONFIG_STATUS_FILEINVALID
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
@ CONFIG_FLAG_FILEUNCHANGED
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Asterisk internal frame definitions.
#define ast_frisolate(fr)
Makes a frame independent of any static storage.
#define ast_debug(level,...)
Log a DEBUG message.
#define ast_verb(level,...)
A set of macros to manage forward-linked lists.
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Asterisk module definitions.
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
@ AST_MODULE_SUPPORT_CORE
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
static int parse_config(void)
parse the configuration file
Pluggable RTP Architecture.
static struct ast_frame * slin8_sample(void)
static struct ast_frame * slin16_sample(void)
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Structure used to handle boolean flags.
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
enum ast_frame_type frametype
union ast_frame::@239 data
A report block within a SR/RR report.
struct ast_rtp_rtcp_report_block::@291 lost_count
An object that represents data sent during a SR/RR RTCP report.
unsigned short reception_report_count
struct ast_rtp_rtcp_report_block * report_block[0]
Default structure for translators, with the basic fields and buffers, all allocated as part of the sa...
union ast_trans_pvt::@308 outbuf
struct ast_translator * t
int datalen
actual space used in outbuf
Descriptor of a translator.
int buf_size
size of outbuf, in bytes. Mandatory. The wrapper code will also allocate an AST_FRIENDLY_OFFSET space...
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
int16_t buf[BUFFER_SAMPLES]
Support for translation of data formats. translate.c.
#define ast_register_translator(t)
See __ast_register_translator()
int ast_unregister_translator(struct ast_translator *t)
Unregister a translator Unregisters the given translator.
struct ast_frame * ast_trans_frameout(struct ast_trans_pvt *pvt, int datalen, int samples)
generic frameout function