codec_speex.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2005, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@digium.com>
  7. *
  8. *
  9. * See http://www.asterisk.org for more information about
  10. * the Asterisk project. Please do not directly contact
  11. * any of the maintainers of this project for assistance;
  12. * the project provides a web site, mailing lists and IRC
  13. * channels for your use.
  14. *
  15. * This program is free software, distributed under the terms of
  16. * the GNU General Public License Version 2. See the LICENSE file
  17. * at the top of the source tree.
  18. */
  19. /*! \file
  20. *
  21. * \brief Translate between signed linear and Speex (Open Codec)
  22. *
  23. * http://www.speex.org
  24. * \note This work was motivated by Jeremy McNamara
  25. * hacked to be configurable by anthm and bkw 9/28/2004
  26. * \ingroup codecs
  27. */
  28. #include <fcntl.h>
  29. #include <stdlib.h>
  30. #include <unistd.h>
  31. #include <netinet/in.h>
  32. #include <string.h>
  33. #include <stdio.h>
  34. #include <speex.h>
  35. /* We require a post 1.1.8 version of Speex to enable preprocessing
  36. and better type handling */
  37. #ifdef _SPEEX_TYPES_H
  38. #include <speex/speex_preprocess.h>
  39. #endif
  40. static int quality = 3;
  41. static int complexity = 2;
  42. static int enhancement = 0;
  43. static int vad = 0;
  44. static int vbr = 0;
  45. static float vbr_quality = 4;
  46. static int abr = 0;
  47. static int dtx = 0;
  48. static int preproc = 0;
  49. static int pp_vad = 0;
  50. static int pp_agc = 0;
  51. static float pp_agc_level = 8000;
  52. static int pp_denoise = 0;
  53. static int pp_dereverb = 0;
  54. static float pp_dereverb_decay = 0.4;
  55. static float pp_dereverb_level = 0.3;
  56. #define TYPE_SILENCE 0x2
  57. #define TYPE_HIGH 0x0
  58. #define TYPE_LOW 0x1
  59. #define TYPE_MASK 0x3
  60. #include "asterisk.h"
  61. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  62. #include "asterisk/lock.h"
  63. #include "asterisk/translate.h"
  64. #include "asterisk/module.h"
  65. #include "asterisk/config.h"
  66. #include "asterisk/options.h"
  67. #include "asterisk/logger.h"
  68. #include "asterisk/channel.h"
  69. /* Sample frame data */
  70. #include "slin_speex_ex.h"
  71. #include "speex_slin_ex.h"
  72. AST_MUTEX_DEFINE_STATIC(localuser_lock);
  73. static int localusecnt=0;
  74. static char *tdesc = "Speex/PCM16 (signed linear) Codec Translator";
  75. struct ast_translator_pvt {
  76. void *speex;
  77. struct ast_frame f;
  78. SpeexBits bits;
  79. int framesize;
  80. /* Space to build offset */
  81. char offset[AST_FRIENDLY_OFFSET];
  82. #ifdef _SPEEX_TYPES_H
  83. SpeexPreprocessState *pp;
  84. /* Buffer for our outgoing frame */
  85. spx_int16_t outbuf[8000];
  86. /* Enough to store a full second */
  87. spx_int16_t buf[8000];
  88. #else
  89. short outbuf[8000];
  90. short buf[8000];
  91. #endif
  92. int tail;
  93. int silent_state;
  94. };
  95. #define speex_coder_pvt ast_translator_pvt
  96. static struct ast_translator_pvt *lintospeex_new(void)
  97. {
  98. struct speex_coder_pvt *tmp;
  99. tmp = malloc(sizeof(struct speex_coder_pvt));
  100. if (tmp) {
  101. if (!(tmp->speex = speex_encoder_init(&speex_nb_mode))) {
  102. free(tmp);
  103. tmp = NULL;
  104. } else {
  105. speex_bits_init(&tmp->bits);
  106. speex_bits_reset(&tmp->bits);
  107. speex_encoder_ctl(tmp->speex, SPEEX_GET_FRAME_SIZE, &tmp->framesize);
  108. speex_encoder_ctl(tmp->speex, SPEEX_SET_COMPLEXITY, &complexity);
  109. #ifdef _SPEEX_TYPES_H
  110. if (preproc) {
  111. tmp->pp = speex_preprocess_state_init(tmp->framesize, 8000);
  112. speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_VAD, &pp_vad);
  113. speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_AGC, &pp_agc);
  114. speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_AGC_LEVEL, &pp_agc_level);
  115. speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_DENOISE, &pp_denoise);
  116. speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_DEREVERB, &pp_dereverb);
  117. speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_DEREVERB_DECAY, &pp_dereverb_decay);
  118. speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &pp_dereverb_level);
  119. }
  120. #endif
  121. if (!abr && !vbr) {
  122. speex_encoder_ctl(tmp->speex, SPEEX_SET_QUALITY, &quality);
  123. if (vad)
  124. speex_encoder_ctl(tmp->speex, SPEEX_SET_VAD, &vad);
  125. }
  126. if (vbr) {
  127. speex_encoder_ctl(tmp->speex, SPEEX_SET_VBR, &vbr);
  128. speex_encoder_ctl(tmp->speex, SPEEX_SET_VBR_QUALITY, &vbr_quality);
  129. }
  130. if (abr) {
  131. speex_encoder_ctl(tmp->speex, SPEEX_SET_ABR, &abr);
  132. }
  133. if (dtx)
  134. speex_encoder_ctl(tmp->speex, SPEEX_SET_DTX, &dtx);
  135. tmp->tail = 0;
  136. tmp->silent_state = 0;
  137. }
  138. localusecnt++;
  139. }
  140. return tmp;
  141. }
  142. static struct ast_translator_pvt *speextolin_new(void)
  143. {
  144. struct speex_coder_pvt *tmp;
  145. tmp = malloc(sizeof(struct speex_coder_pvt));
  146. if (tmp) {
  147. if (!(tmp->speex = speex_decoder_init(&speex_nb_mode))) {
  148. free(tmp);
  149. tmp = NULL;
  150. } else {
  151. speex_bits_init(&tmp->bits);
  152. speex_decoder_ctl(tmp->speex, SPEEX_GET_FRAME_SIZE, &tmp->framesize);
  153. if (enhancement)
  154. speex_decoder_ctl(tmp->speex, SPEEX_SET_ENH, &enhancement);
  155. tmp->tail = 0;
  156. }
  157. localusecnt++;
  158. }
  159. return tmp;
  160. }
  161. static struct ast_frame *lintospeex_sample(void)
  162. {
  163. static struct ast_frame f;
  164. f.frametype = AST_FRAME_VOICE;
  165. f.subclass = AST_FORMAT_SLINEAR;
  166. f.datalen = sizeof(slin_speex_ex);
  167. /* Assume 8000 Hz */
  168. f.samples = sizeof(slin_speex_ex)/2;
  169. f.mallocd = 0;
  170. f.offset = 0;
  171. f.src = __PRETTY_FUNCTION__;
  172. f.data = slin_speex_ex;
  173. return &f;
  174. }
  175. static struct ast_frame *speextolin_sample(void)
  176. {
  177. static struct ast_frame f;
  178. f.frametype = AST_FRAME_VOICE;
  179. f.subclass = AST_FORMAT_SPEEX;
  180. f.datalen = sizeof(speex_slin_ex);
  181. /* All frames are 20 ms long */
  182. f.samples = 160;
  183. f.mallocd = 0;
  184. f.offset = 0;
  185. f.src = __PRETTY_FUNCTION__;
  186. f.data = speex_slin_ex;
  187. return &f;
  188. }
  189. static struct ast_frame *speextolin_frameout(struct ast_translator_pvt *tmp)
  190. {
  191. if (!tmp->tail)
  192. return NULL;
  193. /* Signed linear is no particular frame size, so just send whatever
  194. we have in the buffer in one lump sum */
  195. tmp->f.frametype = AST_FRAME_VOICE;
  196. tmp->f.subclass = AST_FORMAT_SLINEAR;
  197. tmp->f.datalen = tmp->tail * 2;
  198. /* Assume 8000 Hz */
  199. tmp->f.samples = tmp->tail;
  200. tmp->f.mallocd = 0;
  201. tmp->f.offset = AST_FRIENDLY_OFFSET;
  202. tmp->f.src = __PRETTY_FUNCTION__;
  203. tmp->f.data = tmp->buf;
  204. /* Reset tail pointer */
  205. tmp->tail = 0;
  206. return &tmp->f;
  207. }
  208. static int speextolin_framein(struct ast_translator_pvt *tmp, struct ast_frame *f)
  209. {
  210. /* Assuming there's space left, decode into the current buffer at
  211. the tail location. Read in as many frames as there are */
  212. int x;
  213. int res;
  214. #ifdef _SPEEX_TYPES_H
  215. spx_int16_t out[1024];
  216. #else
  217. float fout[1024];
  218. #endif
  219. if (f->datalen == 0) { /* Native PLC interpolation */
  220. if (tmp->tail + tmp->framesize > sizeof(tmp->buf) / 2) {
  221. ast_log(LOG_WARNING, "Out of buffer space\n");
  222. return -1;
  223. }
  224. #ifdef _SPEEX_TYPES_H
  225. speex_decode_int(tmp->speex, NULL, tmp->buf + tmp->tail);
  226. #else
  227. speex_decode(tmp->speex, NULL, fout);
  228. for (x=0;x<tmp->framesize;x++) {
  229. tmp->buf[tmp->tail + x] = fout[x];
  230. }
  231. #endif
  232. tmp->tail += tmp->framesize;
  233. return 0;
  234. }
  235. /* Read in bits */
  236. speex_bits_read_from(&tmp->bits, f->data, f->datalen);
  237. for(;;) {
  238. #ifdef _SPEEX_TYPES_H
  239. res = speex_decode_int(tmp->speex, &tmp->bits, out);
  240. #else
  241. res = speex_decode(tmp->speex, &tmp->bits, fout);
  242. #endif
  243. if (res < 0)
  244. break;
  245. if (tmp->tail + tmp->framesize < sizeof(tmp->buf) / 2) {
  246. for (x=0;x<tmp->framesize;x++) {
  247. #ifdef _SPEEX_TYPES_H
  248. tmp->buf[tmp->tail + x] = out[x];
  249. #else
  250. tmp->buf[tmp->tail + x] = fout[x];
  251. #endif
  252. }
  253. tmp->tail += tmp->framesize;
  254. } else {
  255. ast_log(LOG_WARNING, "Out of buffer space\n");
  256. return -1;
  257. }
  258. }
  259. return 0;
  260. }
  261. static int lintospeex_framein(struct ast_translator_pvt *tmp, struct ast_frame *f)
  262. {
  263. /* Just add the frames to our stream */
  264. /* XXX We should look at how old the rest of our stream is, and if it
  265. is too old, then we should overwrite it entirely, otherwise we can
  266. get artifacts of earlier talk that do not belong */
  267. if (tmp->tail + f->datalen/2 < sizeof(tmp->buf) / 2) {
  268. memcpy((tmp->buf + tmp->tail), f->data, f->datalen);
  269. tmp->tail += f->datalen/2;
  270. } else {
  271. ast_log(LOG_WARNING, "Out of buffer space\n");
  272. return -1;
  273. }
  274. return 0;
  275. }
  276. static struct ast_frame *lintospeex_frameout(struct ast_translator_pvt *tmp)
  277. {
  278. #ifndef _SPEEX_TYPES_H
  279. float fbuf[1024];
  280. int x;
  281. #endif
  282. int len;
  283. int y=0;
  284. int is_speech=1;
  285. /* We can't work on anything less than a frame in size */
  286. if (tmp->tail < tmp->framesize)
  287. return NULL;
  288. tmp->f.frametype = AST_FRAME_VOICE;
  289. tmp->f.subclass = AST_FORMAT_SPEEX;
  290. tmp->f.mallocd = 0;
  291. tmp->f.offset = AST_FRIENDLY_OFFSET;
  292. tmp->f.src = __PRETTY_FUNCTION__;
  293. tmp->f.data = tmp->outbuf;
  294. speex_bits_reset(&tmp->bits);
  295. while(tmp->tail >= tmp->framesize) {
  296. #ifdef _SPEEX_TYPES_H
  297. /* Preprocess audio */
  298. if(preproc)
  299. is_speech = speex_preprocess(tmp->pp, tmp->buf, NULL);
  300. /* Encode a frame of data */
  301. if (is_speech) {
  302. /* If DTX enabled speex_encode returns 0 during silence */
  303. is_speech = speex_encode_int(tmp->speex, tmp->buf, &tmp->bits) || !dtx;
  304. } else {
  305. /* 5 zeros interpreted by Speex as silence (submode 0) */
  306. speex_bits_pack(&tmp->bits, 0, 5);
  307. }
  308. #else
  309. /* Convert to floating point */
  310. for (x=0;x<tmp->framesize;x++)
  311. fbuf[x] = tmp->buf[x];
  312. /* Encode a frame of data */
  313. is_speech = speex_encode(tmp->speex, fbuf, &tmp->bits) || !dtx;
  314. #endif
  315. /* Assume 8000 Hz -- 20 ms */
  316. tmp->tail -= tmp->framesize;
  317. /* Move the data at the end of the buffer to the front */
  318. if (tmp->tail)
  319. memmove(tmp->buf, tmp->buf + tmp->framesize, tmp->tail * 2);
  320. y++;
  321. }
  322. /* Use AST_FRAME_CNG to signify the start of any silence period */
  323. if (!is_speech) {
  324. if (tmp->silent_state) {
  325. return NULL;
  326. } else {
  327. tmp->silent_state = 1;
  328. speex_bits_reset(&tmp->bits);
  329. tmp->f.frametype = AST_FRAME_CNG;
  330. }
  331. } else {
  332. tmp->silent_state = 0;
  333. }
  334. /* Terminate bit stream */
  335. speex_bits_pack(&tmp->bits, 15, 5);
  336. len = speex_bits_write(&tmp->bits, (char *)tmp->outbuf, sizeof(tmp->outbuf));
  337. tmp->f.datalen = len;
  338. tmp->f.samples = y * 160;
  339. #if 0
  340. {
  341. static int fd = -1;
  342. if (fd < 0) {
  343. fd = open("speex.raw", O_WRONLY|O_TRUNC|O_CREAT);
  344. if (fd > -1) {
  345. write(fd, tmp->f.data, tmp->f.datalen);
  346. close(fd);
  347. }
  348. }
  349. }
  350. #endif
  351. return &tmp->f;
  352. }
  353. static void speextolin_destroy(struct ast_translator_pvt *pvt)
  354. {
  355. speex_decoder_destroy(pvt->speex);
  356. speex_bits_destroy(&pvt->bits);
  357. free(pvt);
  358. localusecnt--;
  359. }
  360. static void lintospeex_destroy(struct ast_translator_pvt *pvt)
  361. {
  362. #ifdef _SPEEX_TYPES_H
  363. if (preproc)
  364. speex_preprocess_state_destroy(pvt->pp);
  365. #endif
  366. speex_encoder_destroy(pvt->speex);
  367. speex_bits_destroy(&pvt->bits);
  368. free(pvt);
  369. localusecnt--;
  370. }
  371. static struct ast_translator speextolin =
  372. { "speextolin",
  373. AST_FORMAT_SPEEX, AST_FORMAT_SLINEAR,
  374. speextolin_new,
  375. speextolin_framein,
  376. speextolin_frameout,
  377. speextolin_destroy,
  378. speextolin_sample
  379. };
  380. static struct ast_translator lintospeex =
  381. { "lintospeex",
  382. AST_FORMAT_SLINEAR, AST_FORMAT_SPEEX,
  383. lintospeex_new,
  384. lintospeex_framein,
  385. lintospeex_frameout,
  386. lintospeex_destroy,
  387. lintospeex_sample
  388. };
  389. static void parse_config(void)
  390. {
  391. struct ast_config *cfg;
  392. struct ast_variable *var;
  393. int res;
  394. float res_f;
  395. if ((cfg = ast_config_load("codecs.conf"))) {
  396. if ((var = ast_variable_browse(cfg, "speex"))) {
  397. while (var) {
  398. if (!strcasecmp(var->name, "quality")) {
  399. res = abs(atoi(var->value));
  400. if (res > -1 && res < 11) {
  401. if (option_verbose > 2)
  402. ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting Quality to %d\n",res);
  403. ast_mutex_lock(&localuser_lock);
  404. quality = res;
  405. ast_mutex_unlock(&localuser_lock);
  406. } else
  407. ast_log(LOG_ERROR,"Error Quality must be 0-10\n");
  408. } else if (!strcasecmp(var->name, "complexity")) {
  409. res = abs(atoi(var->value));
  410. if (res > -1 && res < 11) {
  411. if (option_verbose > 2)
  412. ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting Complexity to %d\n",res);
  413. ast_mutex_lock(&localuser_lock);
  414. complexity = res;
  415. ast_mutex_unlock(&localuser_lock);
  416. } else
  417. ast_log(LOG_ERROR,"Error! Complexity must be 0-10\n");
  418. } else if (!strcasecmp(var->name, "vbr_quality")) {
  419. if (sscanf(var->value, "%f", &res_f) == 1 && res_f >= 0 && res_f <= 10) {
  420. if (option_verbose > 2)
  421. ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting VBR Quality to %f\n",res_f);
  422. ast_mutex_lock(&localuser_lock);
  423. vbr_quality = res_f;
  424. ast_mutex_unlock(&localuser_lock);
  425. } else
  426. ast_log(LOG_ERROR,"Error! VBR Quality must be 0-10\n");
  427. } else if (!strcasecmp(var->name, "abr_quality")) {
  428. ast_log(LOG_ERROR,"Error! ABR Quality setting obsolete, set ABR to desired bitrate\n");
  429. } else if (!strcasecmp(var->name, "enhancement")) {
  430. ast_mutex_lock(&localuser_lock);
  431. enhancement = ast_true(var->value) ? 1 : 0;
  432. if (option_verbose > 2)
  433. ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Perceptual Enhancement Mode. [%s]\n",enhancement ? "on" : "off");
  434. ast_mutex_unlock(&localuser_lock);
  435. } else if (!strcasecmp(var->name, "vbr")) {
  436. ast_mutex_lock(&localuser_lock);
  437. vbr = ast_true(var->value) ? 1 : 0;
  438. if (option_verbose > 2)
  439. ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: VBR Mode. [%s]\n",vbr ? "on" : "off");
  440. ast_mutex_unlock(&localuser_lock);
  441. } else if (!strcasecmp(var->name, "abr")) {
  442. res = abs(atoi(var->value));
  443. if (res >= 0) {
  444. if (option_verbose > 2) {
  445. if (res > 0)
  446. ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting ABR target bitrate to %d\n",res);
  447. else
  448. ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Disabling ABR\n");
  449. }
  450. ast_mutex_lock(&localuser_lock);
  451. abr = res;
  452. ast_mutex_unlock(&localuser_lock);
  453. } else
  454. ast_log(LOG_ERROR,"Error! ABR target bitrate must be >= 0\n");
  455. } else if (!strcasecmp(var->name, "vad")) {
  456. ast_mutex_lock(&localuser_lock);
  457. vad = ast_true(var->value) ? 1 : 0;
  458. if (option_verbose > 2)
  459. ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: VAD Mode. [%s]\n",vad ? "on" : "off");
  460. ast_mutex_unlock(&localuser_lock);
  461. } else if (!strcasecmp(var->name, "dtx")) {
  462. ast_mutex_lock(&localuser_lock);
  463. dtx = ast_true(var->value) ? 1 : 0;
  464. if (option_verbose > 2)
  465. ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: DTX Mode. [%s]\n",dtx ? "on" : "off");
  466. ast_mutex_unlock(&localuser_lock);
  467. } else if (!strcasecmp(var->name, "preprocess")) {
  468. ast_mutex_lock(&localuser_lock);
  469. preproc = ast_true(var->value) ? 1 : 0;
  470. if (option_verbose > 2)
  471. ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Preprocessing. [%s]\n",preproc ? "on" : "off");
  472. ast_mutex_unlock(&localuser_lock);
  473. } else if (!strcasecmp(var->name, "pp_vad")) {
  474. ast_mutex_lock(&localuser_lock);
  475. pp_vad = ast_true(var->value) ? 1 : 0;
  476. if (option_verbose > 2)
  477. ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Preprocessor VAD. [%s]\n",pp_vad ? "on" : "off");
  478. ast_mutex_unlock(&localuser_lock);
  479. } else if (!strcasecmp(var->name, "pp_agc")) {
  480. ast_mutex_lock(&localuser_lock);
  481. pp_agc = ast_true(var->value) ? 1 : 0;
  482. if (option_verbose > 2)
  483. ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Preprocessor AGC. [%s]\n",pp_agc ? "on" : "off");
  484. ast_mutex_unlock(&localuser_lock);
  485. } else if (!strcasecmp(var->name, "pp_agc_level")) {
  486. if (sscanf(var->value, "%f", &res_f) == 1 && res_f >= 0) {
  487. if (option_verbose > 2)
  488. ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting preprocessor AGC Level to %f\n",res_f);
  489. ast_mutex_lock(&localuser_lock);
  490. pp_agc_level = res_f;
  491. ast_mutex_unlock(&localuser_lock);
  492. } else
  493. ast_log(LOG_ERROR,"Error! Preprocessor AGC Level must be >= 0\n");
  494. } else if (!strcasecmp(var->name, "pp_denoise")) {
  495. ast_mutex_lock(&localuser_lock);
  496. pp_denoise = ast_true(var->value) ? 1 : 0;
  497. if (option_verbose > 2)
  498. ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Preprocessor Denoise. [%s]\n",pp_denoise ? "on" : "off");
  499. ast_mutex_unlock(&localuser_lock);
  500. } else if (!strcasecmp(var->name, "pp_dereverb")) {
  501. ast_mutex_lock(&localuser_lock);
  502. pp_dereverb = ast_true(var->value) ? 1 : 0;
  503. if (option_verbose > 2)
  504. ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Preprocessor Dereverb. [%s]\n",pp_dereverb ? "on" : "off");
  505. ast_mutex_unlock(&localuser_lock);
  506. } else if (!strcasecmp(var->name, "pp_dereverb_decay")) {
  507. if (sscanf(var->value, "%f", &res_f) == 1 && res_f >= 0) {
  508. if (option_verbose > 2)
  509. ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting preprocessor Dereverb Decay to %f\n",res_f);
  510. ast_mutex_lock(&localuser_lock);
  511. pp_dereverb_decay = res_f;
  512. ast_mutex_unlock(&localuser_lock);
  513. } else
  514. ast_log(LOG_ERROR,"Error! Preprocessor Dereverb Decay must be >= 0\n");
  515. } else if (!strcasecmp(var->name, "pp_dereverb_level")) {
  516. if (sscanf(var->value, "%f", &res_f) == 1 && res_f >= 0) {
  517. if (option_verbose > 2)
  518. ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting preprocessor Dereverb Level to %f\n",res_f);
  519. ast_mutex_lock(&localuser_lock);
  520. pp_dereverb_level = res_f;
  521. ast_mutex_unlock(&localuser_lock);
  522. } else
  523. ast_log(LOG_ERROR,"Error! Preprocessor Dereverb Level must be >= 0\n");
  524. }
  525. var = var->next;
  526. }
  527. }
  528. ast_config_destroy(cfg);
  529. }
  530. }
  531. int reload(void)
  532. {
  533. parse_config();
  534. return 0;
  535. }
  536. int unload_module(void)
  537. {
  538. int res;
  539. ast_mutex_lock(&localuser_lock);
  540. res = ast_unregister_translator(&lintospeex);
  541. if (!res)
  542. res = ast_unregister_translator(&speextolin);
  543. if (localusecnt)
  544. res = -1;
  545. ast_mutex_unlock(&localuser_lock);
  546. return res;
  547. }
  548. int load_module(void)
  549. {
  550. int res;
  551. parse_config();
  552. res=ast_register_translator(&speextolin);
  553. if (!res)
  554. res=ast_register_translator(&lintospeex);
  555. else
  556. ast_unregister_translator(&speextolin);
  557. return res;
  558. }
  559. char *description(void)
  560. {
  561. return tdesc;
  562. }
  563. int usecount(void)
  564. {
  565. int res;
  566. STANDARD_USECOUNT(res);
  567. return res;
  568. }
  569. char *key()
  570. {
  571. return ASTERISK_GPL_KEY;
  572. }