Wed Jan 8 2020 09:50:10

Asterisk developer's documentation


codec_speex.c File Reference

Translate between signed linear and Speex (Open Codec) More...

#include "asterisk.h"
#include <speex/speex.h>
#include "asterisk/translate.h"
#include "asterisk/module.h"
#include "asterisk/config.h"
#include "asterisk/utils.h"
#include "asterisk/slin.h"
#include "ex_speex.h"

Go to the source code of this file.

Data Structures

struct  speex_coder_pvt
 

Macros

#define BUFFER_SAMPLES   8000
 
#define SPEEX_SAMPLES   160
 
#define TYPE_HIGH   0x0
 
#define TYPE_LOW   0x1
 
#define TYPE_MASK   0x3
 
#define TYPE_SILENCE   0x2
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static int lin16tospeexwb_new (struct ast_trans_pvt *pvt)
 
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 More...
 
static struct ast_framelintospeex_frameout (struct ast_trans_pvt *pvt)
 convert work buffer and produce output frame More...
 
static int lintospeex_new (struct ast_trans_pvt *pvt)
 
static int load_module (void)
 
static int parse_config (int reload)
 
static int reload (void)
 
static int speex_decoder_construct (struct ast_trans_pvt *pvt, const SpeexMode *profile)
 
static int speex_encoder_construct (struct ast_trans_pvt *pvt, const SpeexMode *profile, int sampling_rate)
 
static void speextolin_destroy (struct ast_trans_pvt *arg)
 
static int speextolin_framein (struct ast_trans_pvt *pvt, struct ast_frame *f)
 convert and store into outbuf More...
 
static int speextolin_new (struct ast_trans_pvt *pvt)
 
static int speexwbtolin16_new (struct ast_trans_pvt *pvt)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Speex Coder/Decoder" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .reload = reload, }
 
static int abr = 0
 
static struct ast_module_infoast_module_info = &__mod_info
 
static int complexity = 2
 
static int dtx = 0
 
static int enhancement = 0
 
static struct ast_translator lin16tospeexwb
 
static struct ast_translator lintospeex
 
static int pp_agc = 0
 
static float pp_agc_level = 8000
 
static int pp_denoise = 0
 
static int pp_dereverb = 0
 
static float pp_dereverb_decay = 0.4
 
static float pp_dereverb_level = 0.3
 
static int pp_vad = 0
 
static int preproc = 0
 
static int quality = 3
 
static struct ast_translator speextolin
 
static struct ast_translator speexwbtolin16
 
static int vad = 0
 
static int vbr = 0
 
static float vbr_quality = 4
 

Detailed Description

Translate between signed linear and Speex (Open Codec)

Note
This work was motivated by Jeremy McNamara hacked to be configurable by anthm and bkw 9/28/2004
ExtRef:
The Speex library - http://www.speex.org

Definition in file codec_speex.c.

Macro Definition Documentation

#define BUFFER_SAMPLES   8000

Definition at line 81 of file codec_speex.c.

Referenced by speextolin_framein().

#define SPEEX_SAMPLES   160

Definition at line 82 of file codec_speex.c.

Referenced by speex16_sample(), and speex_sample().

#define TYPE_HIGH   0x0

Definition at line 77 of file codec_speex.c.

#define TYPE_LOW   0x1

Definition at line 78 of file codec_speex.c.

#define TYPE_MASK   0x3

Definition at line 79 of file codec_speex.c.

#define TYPE_SILENCE   0x2

Definition at line 76 of file codec_speex.c.

Function Documentation

static void __reg_module ( void  )
static

Definition at line 521 of file codec_speex.c.

static void __unreg_module ( void  )
static

Definition at line 521 of file codec_speex.c.

static int lin16tospeexwb_new ( struct ast_trans_pvt pvt)
static

Definition at line 147 of file codec_speex.c.

References speex_encoder_construct().

148 {
149  return speex_encoder_construct(pvt, &speex_wb_mode, 16000);
150 }
static int speex_encoder_construct(struct ast_trans_pvt *pvt, const SpeexMode *profile, int sampling_rate)
Definition: codec_speex.c:101
static void lintospeex_destroy ( struct ast_trans_pvt arg)
static

Definition at line 321 of file codec_speex.c.

References speex_coder_pvt::bits, ast_trans_pvt::pvt, and speex_coder_pvt::speex.

322 {
323  struct speex_coder_pvt *pvt = arg->pvt;
324 #ifdef _SPEEX_TYPES_H
325  if (preproc)
326  speex_preprocess_state_destroy(pvt->pp);
327 #endif
328  speex_encoder_destroy(pvt->speex);
329  speex_bits_destroy(&pvt->bits);
330 }
static int preproc
Definition: codec_speex.c:67
SpeexBits bits
Definition: codec_speex.c:90
void * pvt
Definition: translate.h:141
static int lintospeex_framein ( struct ast_trans_pvt pvt,
struct ast_frame f 
)
static

store input frame in work buffer

Definition at line 235 of file codec_speex.c.

References speex_coder_pvt::buf, ast_frame::data, ast_frame::datalen, ast_frame::ptr, ast_trans_pvt::pvt, ast_trans_pvt::samples, and ast_frame::samples.

236 {
237  struct speex_coder_pvt *tmp = pvt->pvt;
238 
239  /* XXX We should look at how old the rest of our stream is, and if it
240  is too old, then we should overwrite it entirely, otherwise we can
241  get artifacts of earlier talk that do not belong */
242  memcpy(tmp->buf + pvt->samples, f->data.ptr, f->datalen);
243  pvt->samples += f->samples;
244  return 0;
245 }
void * ptr
Definition: frame.h:160
int16_t buf[BUFFER_SAMPLES]
Definition: codec_speex.c:97
void * pvt
Definition: translate.h:141
int datalen
Definition: frame.h:148
union ast_frame::@172 data
int samples
Definition: frame.h:150
static struct ast_frame* lintospeex_frameout ( struct ast_trans_pvt pvt)
static

convert work buffer and produce output frame

Definition at line 248 of file codec_speex.c.

References AST_FRAME_CNG, ast_trans_frameout(), speex_coder_pvt::bits, speex_coder_pvt::buf, ast_translator::buf_size, ast_trans_pvt::c, dtx, ast_trans_pvt::f, speex_coder_pvt::framesize, ast_frame::frametype, ast_trans_pvt::outbuf, ast_trans_pvt::pvt, ast_trans_pvt::samples, ast_frame::samples, speex_coder_pvt::silent_state, speex_coder_pvt::speex, and ast_trans_pvt::t.

249 {
250  struct speex_coder_pvt *tmp = pvt->pvt;
251  int is_speech=1;
252  int datalen = 0; /* output bytes */
253  int samples = 0; /* output samples */
254 
255  /* We can't work on anything less than a frame in size */
256  if (pvt->samples < tmp->framesize)
257  return NULL;
258  speex_bits_reset(&tmp->bits);
259  while (pvt->samples >= tmp->framesize) {
260 #ifdef _SPEEX_TYPES_H
261  /* Preprocess audio */
262  if (preproc)
263  is_speech = speex_preprocess(tmp->pp, tmp->buf + samples, NULL);
264  /* Encode a frame of data */
265  if (is_speech) {
266  /* If DTX enabled speex_encode returns 0 during silence */
267  is_speech = speex_encode_int(tmp->speex, tmp->buf + samples, &tmp->bits) || !dtx;
268  } else {
269  /* 5 zeros interpreted by Speex as silence (submode 0) */
270  speex_bits_pack(&tmp->bits, 0, 5);
271  }
272 #else
273  {
274  float fbuf[1024];
275  int x;
276  /* Convert to floating point */
277  for (x = 0; x < tmp->framesize; x++)
278  fbuf[x] = tmp->buf[samples + x];
279  /* Encode a frame of data */
280  is_speech = speex_encode(tmp->speex, fbuf, &tmp->bits) || !dtx;
281  }
282 #endif
283  samples += tmp->framesize;
284  pvt->samples -= tmp->framesize;
285  }
286 
287  /* Move the data at the end of the buffer to the front */
288  if (pvt->samples)
289  memmove(tmp->buf, tmp->buf + samples, pvt->samples * 2);
290 
291  /* Use AST_FRAME_CNG to signify the start of any silence period */
292  if (is_speech) {
293  tmp->silent_state = 0;
294  } else {
295  if (tmp->silent_state) {
296  return NULL;
297  } else {
298  tmp->silent_state = 1;
299  speex_bits_reset(&tmp->bits);
300  memset(&pvt->f, 0, sizeof(pvt->f));
301  pvt->f.frametype = AST_FRAME_CNG;
302  pvt->f.samples = samples;
303  /* XXX what now ? format etc... */
304  }
305  }
306 
307  /* Terminate bit stream */
308  speex_bits_pack(&tmp->bits, 15, 5);
309  datalen = speex_bits_write(&tmp->bits, pvt->outbuf.c, pvt->t->buf_size);
310  return ast_trans_frameout(pvt, datalen, samples);
311 }
struct ast_frame * ast_trans_frameout(struct ast_trans_pvt *pvt, int datalen, int samples)
generic frameout function
Definition: translate.c:235
union ast_trans_pvt::@213 outbuf
static int preproc
Definition: codec_speex.c:67
SpeexBits bits
Definition: codec_speex.c:90
struct ast_frame f
Definition: translate.h:137
int16_t buf[BUFFER_SAMPLES]
Definition: codec_speex.c:97
void * pvt
Definition: translate.h:141
int buf_size
size of outbuf, in bytes. Mandatory. The wrapper code will also allocate an AST_FRIENDLY_OFFSET space...
Definition: translate.h:105
static int dtx
Definition: codec_speex.c:65
struct ast_translator * t
Definition: translate.h:136
enum ast_frame_type frametype
Definition: frame.h:144
int samples
Definition: frame.h:150
static int lintospeex_new ( struct ast_trans_pvt pvt)
static

Definition at line 142 of file codec_speex.c.

References speex_encoder_construct().

143 {
144  return speex_encoder_construct(pvt, &speex_nb_mode, 8000);
145 }
static int speex_encoder_construct(struct ast_trans_pvt *pvt, const SpeexMode *profile, int sampling_rate)
Definition: codec_speex.c:101
static int load_module ( void  )
static

Definition at line 502 of file codec_speex.c.

References AST_MODULE_LOAD_DECLINE, ast_register_translator, and parse_config().

503 {
504  int res = 0;
505 
506  if (parse_config(0))
508 
513 
514  return res;
515 }
static struct ast_translator lin16tospeexwb
Definition: codec_speex.c:374
static int parse_config(int reload)
Definition: codec_speex.c:388
#define ast_register_translator(t)
See __ast_register_translator()
Definition: translate.h:170
static struct ast_translator lintospeex
Definition: codec_speex.c:346
static struct ast_translator speexwbtolin16
Definition: codec_speex.c:360
static struct ast_translator speextolin
Definition: codec_speex.c:332
static int parse_config ( int  reload)
static

Definition at line 388 of file codec_speex.c.

References ast_config_destroy(), ast_config_load, ast_log(), ast_true(), ast_variable_browse(), ast_verb, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, CONFIG_STATUS_FILEUNCHANGED, LOG_ERROR, ast_variable::name, ast_variable::next, ast_variable::value, and var.

Referenced by load_module(), and reload().

389 {
390  struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
391  struct ast_config *cfg = ast_config_load("codecs.conf", config_flags);
392  struct ast_variable *var;
393  int res;
394  float res_f;
395 
397  return 0;
398 
399  for (var = ast_variable_browse(cfg, "speex"); var; var = var->next) {
400  if (!strcasecmp(var->name, "quality")) {
401  res = abs(atoi(var->value));
402  if (res > -1 && res < 11) {
403  ast_verb(3, "CODEC SPEEX: Setting Quality to %d\n",res);
404  quality = res;
405  } else
406  ast_log(LOG_ERROR,"Error Quality must be 0-10\n");
407  } else if (!strcasecmp(var->name, "complexity")) {
408  res = abs(atoi(var->value));
409  if (res > -1 && res < 11) {
410  ast_verb(3, "CODEC SPEEX: Setting Complexity to %d\n",res);
411  complexity = res;
412  } else
413  ast_log(LOG_ERROR,"Error! Complexity must be 0-10\n");
414  } else if (!strcasecmp(var->name, "vbr_quality")) {
415  if (sscanf(var->value, "%30f", &res_f) == 1 && res_f >= 0 && res_f <= 10) {
416  ast_verb(3, "CODEC SPEEX: Setting VBR Quality to %f\n",res_f);
417  vbr_quality = res_f;
418  } else
419  ast_log(LOG_ERROR,"Error! VBR Quality must be 0-10\n");
420  } else if (!strcasecmp(var->name, "abr_quality")) {
421  ast_log(LOG_ERROR,"Error! ABR Quality setting obsolete, set ABR to desired bitrate\n");
422  } else if (!strcasecmp(var->name, "enhancement")) {
423  enhancement = ast_true(var->value) ? 1 : 0;
424  ast_verb(3, "CODEC SPEEX: Perceptual Enhancement Mode. [%s]\n",enhancement ? "on" : "off");
425  } else if (!strcasecmp(var->name, "vbr")) {
426  vbr = ast_true(var->value) ? 1 : 0;
427  ast_verb(3, "CODEC SPEEX: VBR Mode. [%s]\n",vbr ? "on" : "off");
428  } else if (!strcasecmp(var->name, "abr")) {
429  res = abs(atoi(var->value));
430  if (res >= 0) {
431  if (res > 0)
432  ast_verb(3, "CODEC SPEEX: Setting ABR target bitrate to %d\n",res);
433  else
434  ast_verb(3, "CODEC SPEEX: Disabling ABR\n");
435  abr = res;
436  } else
437  ast_log(LOG_ERROR,"Error! ABR target bitrate must be >= 0\n");
438  } else if (!strcasecmp(var->name, "vad")) {
439  vad = ast_true(var->value) ? 1 : 0;
440  ast_verb(3, "CODEC SPEEX: VAD Mode. [%s]\n",vad ? "on" : "off");
441  } else if (!strcasecmp(var->name, "dtx")) {
442  dtx = ast_true(var->value) ? 1 : 0;
443  ast_verb(3, "CODEC SPEEX: DTX Mode. [%s]\n",dtx ? "on" : "off");
444  } else if (!strcasecmp(var->name, "preprocess")) {
445  preproc = ast_true(var->value) ? 1 : 0;
446  ast_verb(3, "CODEC SPEEX: Preprocessing. [%s]\n",preproc ? "on" : "off");
447  } else if (!strcasecmp(var->name, "pp_vad")) {
448  pp_vad = ast_true(var->value) ? 1 : 0;
449  ast_verb(3, "CODEC SPEEX: Preprocessor VAD. [%s]\n",pp_vad ? "on" : "off");
450  } else if (!strcasecmp(var->name, "pp_agc")) {
451  pp_agc = ast_true(var->value) ? 1 : 0;
452  ast_verb(3, "CODEC SPEEX: Preprocessor AGC. [%s]\n",pp_agc ? "on" : "off");
453  } else if (!strcasecmp(var->name, "pp_agc_level")) {
454  if (sscanf(var->value, "%30f", &res_f) == 1 && res_f >= 0) {
455  ast_verb(3, "CODEC SPEEX: Setting preprocessor AGC Level to %f\n",res_f);
456  pp_agc_level = res_f;
457  } else
458  ast_log(LOG_ERROR,"Error! Preprocessor AGC Level must be >= 0\n");
459  } else if (!strcasecmp(var->name, "pp_denoise")) {
460  pp_denoise = ast_true(var->value) ? 1 : 0;
461  ast_verb(3, "CODEC SPEEX: Preprocessor Denoise. [%s]\n",pp_denoise ? "on" : "off");
462  } else if (!strcasecmp(var->name, "pp_dereverb")) {
463  pp_dereverb = ast_true(var->value) ? 1 : 0;
464  ast_verb(3, "CODEC SPEEX: Preprocessor Dereverb. [%s]\n",pp_dereverb ? "on" : "off");
465  } else if (!strcasecmp(var->name, "pp_dereverb_decay")) {
466  if (sscanf(var->value, "%30f", &res_f) == 1 && res_f >= 0) {
467  ast_verb(3, "CODEC SPEEX: Setting preprocessor Dereverb Decay to %f\n",res_f);
468  pp_dereverb_decay = res_f;
469  } else
470  ast_log(LOG_ERROR,"Error! Preprocessor Dereverb Decay must be >= 0\n");
471  } else if (!strcasecmp(var->name, "pp_dereverb_level")) {
472  if (sscanf(var->value, "%30f", &res_f) == 1 && res_f >= 0) {
473  ast_verb(3, "CODEC SPEEX: Setting preprocessor Dereverb Level to %f\n",res_f);
474  pp_dereverb_level = res_f;
475  } else
476  ast_log(LOG_ERROR,"Error! Preprocessor Dereverb Level must be >= 0\n");
477  }
478  }
479  ast_config_destroy(cfg);
480  return 0;
481 }
static float pp_dereverb_decay
Definition: codec_speex.c:73
static int quality
Definition: codec_speex.c:58
static int preproc
Definition: codec_speex.c:67
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
Definition: config.c:597
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
#define var
Definition: ast_expr2f.c:606
#define ast_verb(level,...)
Definition: logger.h:243
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: config.c:1037
static int reload(void)
Definition: codec_speex.c:483
static int complexity
Definition: codec_speex.c:59
#define CONFIG_STATUS_FILEMISSING
Definition: config.h:50
const char * value
Definition: config.h:79
static float pp_dereverb_level
Definition: codec_speex.c:74
#define ast_config_load(filename, flags)
Load a config file.
Definition: config.h:170
const char * name
Definition: config.h:77
static int vbr
Definition: codec_speex.c:62
static int pp_vad
Definition: codec_speex.c:68
static int pp_dereverb
Definition: codec_speex.c:72
#define LOG_ERROR
Definition: logger.h:155
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is &quot;true&quot;. This function checks to see whether a string passed to it is an indication of an &quot;true&quot; value. It checks to see if the string is &quot;yes&quot;, &quot;true&quot;, &quot;y&quot;, &quot;t&quot;, &quot;on&quot; or &quot;1&quot;.
Definition: utils.c:1533
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static int vad
Definition: codec_speex.c:61
static int dtx
Definition: codec_speex.c:65
static int pp_denoise
Definition: codec_speex.c:71
Structure used to handle boolean flags.
Definition: utils.h:200
static int enhancement
Definition: codec_speex.c:60
static float vbr_quality
Definition: codec_speex.c:63
struct ast_variable * next
Definition: config.h:82
#define CONFIG_STATUS_FILEINVALID
Definition: config.h:52
static float pp_agc_level
Definition: codec_speex.c:70
static int abr
Definition: codec_speex.c:64
#define CONFIG_STATUS_FILEUNCHANGED
Definition: config.h:51
static int pp_agc
Definition: codec_speex.c:69
static int reload ( void  )
static

Definition at line 483 of file codec_speex.c.

References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and parse_config().

484 {
485  if (parse_config(1))
488 }
static int parse_config(int reload)
Definition: codec_speex.c:388
static int speex_decoder_construct ( struct ast_trans_pvt pvt,
const SpeexMode *  profile 
)
static

Definition at line 152 of file codec_speex.c.

References speex_coder_pvt::bits, speex_coder_pvt::framesize, ast_trans_pvt::pvt, and speex_coder_pvt::speex.

Referenced by speextolin_new(), and speexwbtolin16_new().

153 {
154  struct speex_coder_pvt *tmp = pvt->pvt;
155 
156  if (!(tmp->speex = speex_decoder_init(profile)))
157  return -1;
158 
159  speex_bits_init(&tmp->bits);
160  speex_decoder_ctl(tmp->speex, SPEEX_GET_FRAME_SIZE, &tmp->framesize);
161  if (enhancement)
162  speex_decoder_ctl(tmp->speex, SPEEX_SET_ENH, &enhancement);
163 
164  return 0;
165 }
SpeexBits bits
Definition: codec_speex.c:90
void * pvt
Definition: translate.h:141
static int enhancement
Definition: codec_speex.c:60
static int speex_encoder_construct ( struct ast_trans_pvt pvt,
const SpeexMode *  profile,
int  sampling_rate 
)
static

Definition at line 101 of file codec_speex.c.

References speex_coder_pvt::bits, speex_coder_pvt::framesize, ast_trans_pvt::pvt, speex_coder_pvt::silent_state, and speex_coder_pvt::speex.

Referenced by lin16tospeexwb_new(), and lintospeex_new().

102 {
103  struct speex_coder_pvt *tmp = pvt->pvt;
104 
105  if (!(tmp->speex = speex_encoder_init(profile)))
106  return -1;
107 
108  speex_bits_init(&tmp->bits);
109  speex_bits_reset(&tmp->bits);
110  speex_encoder_ctl(tmp->speex, SPEEX_GET_FRAME_SIZE, &tmp->framesize);
111  speex_encoder_ctl(tmp->speex, SPEEX_SET_COMPLEXITY, &complexity);
112 #ifdef _SPEEX_TYPES_H
113  if (preproc) {
114  tmp->pp = speex_preprocess_state_init(tmp->framesize, sampling_rate);
115  speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_VAD, &pp_vad);
116  speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_AGC, &pp_agc);
117  speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_AGC_LEVEL, &pp_agc_level);
118  speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_DENOISE, &pp_denoise);
119  speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_DEREVERB, &pp_dereverb);
120  speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_DEREVERB_DECAY, &pp_dereverb_decay);
121  speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &pp_dereverb_level);
122  }
123 #endif
124  if (!abr && !vbr) {
125  speex_encoder_ctl(tmp->speex, SPEEX_SET_QUALITY, &quality);
126  if (vad)
127  speex_encoder_ctl(tmp->speex, SPEEX_SET_VAD, &vad);
128  }
129  if (vbr) {
130  speex_encoder_ctl(tmp->speex, SPEEX_SET_VBR, &vbr);
131  speex_encoder_ctl(tmp->speex, SPEEX_SET_VBR_QUALITY, &vbr_quality);
132  }
133  if (abr)
134  speex_encoder_ctl(tmp->speex, SPEEX_SET_ABR, &abr);
135  if (dtx)
136  speex_encoder_ctl(tmp->speex, SPEEX_SET_DTX, &dtx);
137  tmp->silent_state = 0;
138 
139  return 0;
140 }
static float pp_dereverb_decay
Definition: codec_speex.c:73
static int quality
Definition: codec_speex.c:58
static int preproc
Definition: codec_speex.c:67
SpeexBits bits
Definition: codec_speex.c:90
void * pvt
Definition: translate.h:141
static int complexity
Definition: codec_speex.c:59
static float pp_dereverb_level
Definition: codec_speex.c:74
static int vbr
Definition: codec_speex.c:62
static int pp_vad
Definition: codec_speex.c:68
static int pp_dereverb
Definition: codec_speex.c:72
static int vad
Definition: codec_speex.c:61
static int dtx
Definition: codec_speex.c:65
static int pp_denoise
Definition: codec_speex.c:71
static float vbr_quality
Definition: codec_speex.c:63
static float pp_agc_level
Definition: codec_speex.c:70
static int abr
Definition: codec_speex.c:64
static int pp_agc
Definition: codec_speex.c:69
static void speextolin_destroy ( struct ast_trans_pvt arg)
static

Definition at line 313 of file codec_speex.c.

References speex_coder_pvt::bits, ast_trans_pvt::pvt, and speex_coder_pvt::speex.

314 {
315  struct speex_coder_pvt *pvt = arg->pvt;
316 
317  speex_decoder_destroy(pvt->speex);
318  speex_bits_destroy(&pvt->bits);
319 }
SpeexBits bits
Definition: codec_speex.c:90
void * pvt
Definition: translate.h:141
static int speextolin_framein ( struct ast_trans_pvt pvt,
struct ast_frame f 
)
static

convert and store into outbuf

Definition at line 178 of file codec_speex.c.

References ast_log(), speex_coder_pvt::bits, BUFFER_SAMPLES, ast_frame::data, ast_trans_pvt::datalen, ast_frame::datalen, speex_coder_pvt::framesize, ast_trans_pvt::i16, LOG_WARNING, ast_trans_pvt::outbuf, ast_frame::ptr, ast_trans_pvt::pvt, ast_trans_pvt::samples, and speex_coder_pvt::speex.

179 {
180  struct speex_coder_pvt *tmp = pvt->pvt;
181 
182  /* Assuming there's space left, decode into the current buffer at
183  the tail location. Read in as many frames as there are */
184  int x;
185  int res;
186  int16_t *dst = pvt->outbuf.i16;
187  /* XXX fout is a temporary buffer, may have different types */
188 #ifdef _SPEEX_TYPES_H
189  spx_int16_t fout[1024];
190 #else
191  float fout[1024];
192 #endif
193 
194  if (f->datalen == 0) { /* Native PLC interpolation */
195  if (pvt->samples + tmp->framesize > BUFFER_SAMPLES) {
196  ast_log(LOG_WARNING, "Out of buffer space\n");
197  return -1;
198  }
199 #ifdef _SPEEX_TYPES_H
200  speex_decode_int(tmp->speex, NULL, dst + pvt->samples);
201 #else
202  speex_decode(tmp->speex, NULL, fout);
203  for (x=0;x<tmp->framesize;x++) {
204  dst[pvt->samples + x] = (int16_t)fout[x];
205  }
206 #endif
207  pvt->samples += tmp->framesize;
208  pvt->datalen += 2 * tmp->framesize; /* 2 bytes/sample */
209  return 0;
210  }
211 
212  /* Read in bits */
213  speex_bits_read_from(&tmp->bits, f->data.ptr, f->datalen);
214  for (;;) {
215 #ifdef _SPEEX_TYPES_H
216  res = speex_decode_int(tmp->speex, &tmp->bits, fout);
217 #else
218  res = speex_decode(tmp->speex, &tmp->bits, fout);
219 #endif
220  if (res < 0)
221  break;
222  if (pvt->samples + tmp->framesize > BUFFER_SAMPLES) {
223  ast_log(LOG_WARNING, "Out of buffer space\n");
224  return -1;
225  }
226  for (x = 0 ; x < tmp->framesize; x++)
227  dst[pvt->samples + x] = (int16_t)fout[x];
228  pvt->samples += tmp->framesize;
229  pvt->datalen += 2 * tmp->framesize; /* 2 bytes/sample */
230  }
231  return 0;
232 }
int datalen
actual space used in outbuf
Definition: translate.h:140
union ast_trans_pvt::@213 outbuf
SpeexBits bits
Definition: codec_speex.c:90
void * ptr
Definition: frame.h:160
#define LOG_WARNING
Definition: logger.h:144
void * pvt
Definition: translate.h:141
int16_t * i16
Definition: translate.h:145
int datalen
Definition: frame.h:148
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define BUFFER_SAMPLES
Definition: codec_speex.c:81
union ast_frame::@172 data
static int speextolin_new ( struct ast_trans_pvt pvt)
static

Definition at line 167 of file codec_speex.c.

References speex_decoder_construct().

168 {
169  return speex_decoder_construct(pvt, &speex_nb_mode);
170 }
static int speex_decoder_construct(struct ast_trans_pvt *pvt, const SpeexMode *profile)
Definition: codec_speex.c:152
static int speexwbtolin16_new ( struct ast_trans_pvt pvt)
static

Definition at line 172 of file codec_speex.c.

References speex_decoder_construct().

173 {
174  return speex_decoder_construct(pvt, &speex_wb_mode);
175 }
static int speex_decoder_construct(struct ast_trans_pvt *pvt, const SpeexMode *profile)
Definition: codec_speex.c:152
static int unload_module ( void  )
static

Definition at line 490 of file codec_speex.c.

References ast_unregister_translator().

491 {
492  int res = 0;
493 
498 
499  return res;
500 }
static struct ast_translator lin16tospeexwb
Definition: codec_speex.c:374
int ast_unregister_translator(struct ast_translator *t)
Unregister a translator Unregisters the given tranlator.
Definition: translate.c:942
static struct ast_translator lintospeex
Definition: codec_speex.c:346
static struct ast_translator speexwbtolin16
Definition: codec_speex.c:360
static struct ast_translator speextolin
Definition: codec_speex.c:332

Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Speex Coder/Decoder" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .reload = reload, }
static

Definition at line 521 of file codec_speex.c.

int abr = 0
static

Definition at line 64 of file codec_speex.c.

Definition at line 521 of file codec_speex.c.

int complexity = 2
static

Definition at line 59 of file codec_speex.c.

int dtx = 0
static

Definition at line 65 of file codec_speex.c.

Referenced by lintospeex_frameout().

int enhancement = 0
static

Definition at line 60 of file codec_speex.c.

struct ast_translator lin16tospeexwb
static

Definition at line 374 of file codec_speex.c.

struct ast_translator lintospeex
static

Definition at line 346 of file codec_speex.c.

int pp_agc = 0
static

Definition at line 69 of file codec_speex.c.

float pp_agc_level = 8000
static

Definition at line 70 of file codec_speex.c.

int pp_denoise = 0
static

Definition at line 71 of file codec_speex.c.

int pp_dereverb = 0
static

Definition at line 72 of file codec_speex.c.

float pp_dereverb_decay = 0.4
static

Definition at line 73 of file codec_speex.c.

float pp_dereverb_level = 0.3
static

Definition at line 74 of file codec_speex.c.

int pp_vad = 0
static

Definition at line 68 of file codec_speex.c.

int preproc = 0
static

Definition at line 67 of file codec_speex.c.

int quality = 3
static

Definition at line 58 of file codec_speex.c.

Referenced by ast_rtp_instance_set_stats_vars(), handle_request_bye(), and sip_hangup().

struct ast_translator speextolin
static

Definition at line 332 of file codec_speex.c.

struct ast_translator speexwbtolin16
static

Definition at line 360 of file codec_speex.c.

int vad = 0
static

Definition at line 61 of file codec_speex.c.

int vbr = 0
static

Definition at line 62 of file codec_speex.c.

float vbr_quality = 4
static

Definition at line 63 of file codec_speex.c.