52 #if !defined(INT16_MAX)
53 #define INT16_MAX (32767)
54 #define INT16_MIN (-32767-1)
58 #define ATTENUATION_INCREMENT 0.0025
60 #define ms_to_samples(t) (((t)*DEFAULT_SAMPLE_RATE)/1000)
62 static inline int16_t fsaturate(
double damp)
68 return (int16_t) rint(damp);
71 static void save_history(
plc_state_t *s, int16_t *buf,
int len)
108 static int __inline__ amdf_pitch(
int min_pitch,
int max_pitch, int16_t amp[],
int len)
118 for (i = max_pitch; i <= min_pitch; i++) {
120 for (j = 0; j < len; j++)
121 acc += abs(amp[i + j] - amp[j]);
148 pitch_overlap = s->
pitch >> 2;
149 if (pitch_overlap > len)
154 new_step = 1.0/pitch_overlap;
155 old_step = new_step*gain;
156 new_weight = new_step;
157 old_weight = (1.0 - new_step)*gain;
158 for (i = 0; i < pitch_overlap; i++) {
162 new_weight += new_step;
163 old_weight -= old_step;
164 if (old_weight < 0.0)
169 save_history(s, amp, len);
190 normalise_history(s);
193 pitch_overlap = s->
pitch >> 2;
197 for (i = 0; i < s->
pitch - pitch_overlap; i++)
200 new_step = 1.0/pitch_overlap;
201 new_weight = new_step;
202 for ( ; i < s->
pitch; i++) {
204 new_weight += new_step;
213 new_step = 1.0 / pitch_overlap;
215 new_weight = new_step;
216 old_weight = 1.0 - new_step;
217 for (i = 0; i < pitch_overlap; i++) {
219 new_weight += new_step;
220 old_weight -= old_step;
221 if (old_weight < 0.0)
229 for ( ; gain > 0.0 && i < len; i++) {
231 gain -= ATTENUATION_INCREMENT;
235 for ( ; i < len; i++)
238 save_history(s, amp, len);
246 memset(s, 0,
sizeof(*s));
252 static int reload_module(
void)
258 if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
262 for (var = ast_variable_browse(cfg,
"plc"); var; var = var->
next) {
263 if (!strcasecmp(var->
name,
"genericplc")) {
265 }
else if (!strcasecmp(var->
name,
"genericplc_on_equal_codecs")) {
274 if (!ast_opt_generic_plc) {
281 static int load_module(
void)
288 static int unload_module(
void)
293 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER,
"PLC",
294 .support_level = AST_MODULE_SUPPORT_CORE,
296 .unload = unload_module,
297 .reload = reload_module,
299 .requires =
"extconfig",
struct ast_variable * next
Asterisk main include file. File version handling, generic pbx functions.
int16_t history[PLC_HISTORY_LEN]
Structure for variables, used for configurations and for channel variables.
int plc_rx(plc_state_t *s, int16_t amp[], int len)
Process a block of received audio samples.
int plc_fillin(plc_state_t *s, int16_t amp[], int len)
Fill-in a block of missing audio samples.
Configuration File Parser.
#define ast_config_load(filename, flags)
Load a config file.
plc_state_t * plc_init(plc_state_t *s)
Process a block of received V.29 modem audio samples.
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".
Structure used to handle boolean flags.
SpanDSP - a series of DSP components for telephony.
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
float pitchbuf[PLC_PITCH_MIN]