5 + * Asterisk -- A telephony toolkit for Linux.
7 + * Trivial application to receive a TIFF FAX file
9 + * Copyright (C) 2003, Steve Underwood
11 + * Steve Underwood <steveu@coppice.org>
13 + * This program is free software, distributed under the terms of
14 + * the GNU General Public License
18 + <depend>spandsp</depend>
21 +#include "asterisk.h"
23 +ASTERISK_FILE_VERSION(__FILE__, "$Revision:$")
28 +#include <inttypes.h>
35 +#include "asterisk/lock.h"
36 +#include "asterisk/file.h"
37 +#include "asterisk/logger.h"
38 +#include "asterisk/channel.h"
39 +#include "asterisk/pbx.h"
40 +#include "asterisk/module.h"
41 +#include "asterisk/translate.h"
42 +#include "asterisk/dsp.h"
43 +#include "asterisk/manager.h"
45 +static char *app = "RxFAX";
47 +static char *synopsis = "Receive a FAX to a file";
49 +static char *descrip =
50 +" RxFAX(filename[|caller][|debug]): Receives a FAX from the channel into the\n"
51 +"given filename. If the file exists it will be overwritten. The file\n"
52 +"should be in TIFF/F format.\n"
53 +"The \"caller\" option makes the application behave as a calling machine,\n"
54 +"rather than the answering machine. The default behaviour is to behave as\n"
55 +"an answering machine.\n"
56 +"Uses LOCALSTATIONID to identify itself to the remote end.\n"
57 +" LOCALHEADERINFO to generate a header line on each page.\n"
58 +"Sets REMOTESTATIONID to the sender CSID.\n"
59 +" FAXPAGES to the number of pages received.\n"
60 +" FAXBITRATE to the transmition rate.\n"
61 +" FAXRESOLUTION to the resolution.\n"
62 +"Returns -1 when the user hangs up.\n"
63 +"Returns 0 otherwise.\n";
65 +#define MAX_BLOCK_SIZE 240
67 +static void span_message(int level, const char *msg)
71 + if (level == SPAN_LOG_WARNING)
72 + ast_level = __LOG_WARNING;
73 + else if (level == SPAN_LOG_WARNING)
74 + ast_level = __LOG_WARNING;
76 + ast_level = __LOG_DEBUG;
77 + ast_log(ast_level, __FILE__, __LINE__, __PRETTY_FUNCTION__, msg);
79 +/*- End of function --------------------------------------------------------*/
81 +static void t30_flush(t30_state_t *s, int which)
85 +/*- End of function --------------------------------------------------------*/
87 +static void phase_e_handler(t30_state_t *s, void *user_data, int result)
89 + struct ast_channel *chan;
91 + char local_ident[21];
95 + chan = (struct ast_channel *) user_data;
96 + if (result == T30_ERR_OK)
98 + t30_get_transfer_statistics(s, &t);
99 + t30_get_far_ident(s, far_ident);
100 + t30_get_local_ident(s, local_ident);
101 + ast_log(LOG_DEBUG, "==============================================================================\n");
102 + ast_log(LOG_DEBUG, "Fax successfully received.\n");
103 + ast_log(LOG_DEBUG, "Remote station id: %s\n", far_ident);
104 + ast_log(LOG_DEBUG, "Local station id: %s\n", local_ident);
105 + ast_log(LOG_DEBUG, "Pages transferred: %i\n", t.pages_transferred);
106 + ast_log(LOG_DEBUG, "Image resolution: %i x %i\n", t.x_resolution, t.y_resolution);
107 + ast_log(LOG_DEBUG, "Transfer Rate: %i\n", t.bit_rate);
108 + ast_log(LOG_DEBUG, "==============================================================================\n");
109 + manager_event(EVENT_FLAG_CALL,
110 + "FaxReceived", "Channel: %s\nExten: %s\nCallerID: %s\nRemoteStationID: %s\nLocalStationID: %s\nPagesTransferred: %i\nResolution: %i\nTransferRate: %i\nFileName: %s\n",
113 + (chan->cid.cid_num) ? chan->cid.cid_num : "",
116 + t.pages_transferred,
120 + pbx_builtin_setvar_helper(chan, "REMOTESTATIONID", far_ident);
121 + snprintf(buf, sizeof(buf), "%i", t.pages_transferred);
122 + pbx_builtin_setvar_helper(chan, "FAXPAGES", buf);
123 + snprintf(buf, sizeof(buf), "%i", t.y_resolution);
124 + pbx_builtin_setvar_helper(chan, "FAXRESOLUTION", buf);
125 + snprintf(buf, sizeof(buf), "%i", t.bit_rate);
126 + pbx_builtin_setvar_helper(chan, "FAXBITRATE", buf);
130 + ast_log(LOG_DEBUG, "==============================================================================\n");
131 + ast_log(LOG_DEBUG, "Fax receive not successful - result (%d) %s.\n", result, t30_completion_code_to_str(result));
132 + ast_log(LOG_DEBUG, "==============================================================================\n");
135 +/*- End of function --------------------------------------------------------*/
137 +static void phase_d_handler(t30_state_t *s, void *user_data, int result)
139 + struct ast_channel *chan;
142 + chan = (struct ast_channel *) user_data;
145 + t30_get_transfer_statistics(s, &t);
146 + ast_log(LOG_DEBUG, "==============================================================================\n");
147 + ast_log(LOG_DEBUG, "Pages transferred: %i\n", t.pages_transferred);
148 + ast_log(LOG_DEBUG, "Image size: %i x %i\n", t.width, t.length);
149 + ast_log(LOG_DEBUG, "Image resolution %i x %i\n", t.x_resolution, t.y_resolution);
150 + ast_log(LOG_DEBUG, "Transfer Rate: %i\n", t.bit_rate);
151 + ast_log(LOG_DEBUG, "Bad rows %i\n", t.bad_rows);
152 + ast_log(LOG_DEBUG, "Longest bad row run %i\n", t.longest_bad_row_run);
153 + ast_log(LOG_DEBUG, "Compression type %i\n", t.encoding);
154 + ast_log(LOG_DEBUG, "Image size (bytes) %i\n", t.image_size);
155 + ast_log(LOG_DEBUG, "==============================================================================\n");
158 +/*- End of function --------------------------------------------------------*/
160 +static int rxfax_exec(struct ast_channel *chan, void *data)
163 + char template_file[256];
164 + char target_file[256];
177 + struct ast_module_user *u;
178 + struct ast_frame *inf = NULL;
179 + struct ast_frame outf;
181 + int original_read_fmt;
182 + int original_write_fmt;
184 + uint8_t __buf[sizeof(uint16_t)*MAX_BLOCK_SIZE + 2*AST_FRIENDLY_OFFSET];
185 + uint8_t *buf = __buf + AST_FRIENDLY_OFFSET;
189 + ast_log(LOG_WARNING, "Fax receive channel is NULL. Giving up.\n");
193 + span_set_message_handler(span_message);
195 + /* The next few lines of code parse out the filename and header from the input string */
198 + /* No data implies no filename or anything is present */
199 + ast_log(LOG_WARNING, "Rxfax requires an argument (filename)\n");
203 + calling_party = FALSE;
205 + target_file[0] = '\0';
207 + for (option = 0, v = s = data; v; option++, s++)
210 + v = strchr(s, '|');
211 + s = (v) ? v : s + strlen(s);
212 + strncpy((char *) buf, t, s - t);
216 + /* The first option is always the file name */
220 + strncpy(target_file, t, len);
221 + target_file[len] = '\0';
222 + /* Allow the use of %d in the file name for a wild card of sorts, to
223 + create a new file with the specified name scheme */
224 + if ((x = strchr(target_file, '%')) && x[1] == 'd')
226 + strcpy(template_file, target_file);
230 + snprintf(target_file, 256, template_file, 1);
233 + while (ast_fileexists(target_file, "", chan->language) != -1);
236 + else if (strncmp("caller", t, s - t) == 0)
238 + calling_party = TRUE;
240 + else if (strncmp("debug", t, s - t) == 0)
248 + u = ast_module_user_add(chan);
250 + if (chan->_state != AST_STATE_UP)
252 + /* Shouldn't need this, but checking to see if channel is already answered
253 + * Theoretically asterisk should already have answered before running the app */
254 + res = ast_answer(chan);
259 + original_read_fmt = chan->readformat;
260 + if (original_read_fmt != AST_FORMAT_SLINEAR)
262 + res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
265 + ast_log(LOG_WARNING, "Unable to set to linear read mode, giving up\n");
269 + original_write_fmt = chan->writeformat;
270 + if (original_write_fmt != AST_FORMAT_SLINEAR)
272 + res = ast_set_write_format(chan, AST_FORMAT_SLINEAR);
275 + ast_log(LOG_WARNING, "Unable to set to linear write mode, giving up\n");
276 + res = ast_set_read_format(chan, original_read_fmt);
278 + ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", chan->name);
282 + fax_init(&fax, calling_party);
284 + fax.logging.level = SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW;
285 + x = pbx_builtin_getvar_helper(chan, "LOCALSTATIONID");
287 + t30_set_local_ident(&fax.t30_state, x);
288 + x = pbx_builtin_getvar_helper(chan, "LOCALHEADERINFO");
290 + t30_set_header_info(&fax.t30_state, x);
291 + t30_set_rx_file(&fax.t30_state, target_file, -1);
292 + //t30_set_phase_b_handler(&fax.t30_state, phase_b_handler, chan);
293 + t30_set_phase_d_handler(&fax.t30_state, phase_d_handler, chan);
294 + t30_set_phase_e_handler(&fax.t30_state, phase_e_handler, chan);
295 + t30_set_ecm_capability(&fax.t30_state, TRUE);
296 + t30_set_supported_compressions(&fax.t30_state, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION);
297 + while (ast_waitfor(chan, -1) > -1)
299 + inf = ast_read(chan);
305 + if (inf->frametype == AST_FRAME_VOICE)
307 + if (fax_rx(&fax, inf->data, inf->samples))
309 + samples = (inf->samples <= MAX_BLOCK_SIZE) ? inf->samples : MAX_BLOCK_SIZE;
310 + len = fax_tx(&fax, (int16_t *) &buf[AST_FRIENDLY_OFFSET], samples);
313 + memset(&outf, 0, sizeof(outf));
314 + outf.frametype = AST_FRAME_VOICE;
315 + outf.subclass = AST_FORMAT_SLINEAR;
316 + outf.datalen = len*sizeof(int16_t);
317 + outf.samples = len;
318 + outf.data = &buf[AST_FRIENDLY_OFFSET];
319 + outf.offset = AST_FRIENDLY_OFFSET;
320 + outf.src = "RxFAX";
321 + if (ast_write(chan, &outf) < 0)
323 + ast_log(LOG_WARNING, "Unable to write frame to channel; %s\n", strerror(errno));
332 + ast_log(LOG_DEBUG, "Got hangup\n");
335 + if (original_read_fmt != AST_FORMAT_SLINEAR)
337 + res = ast_set_read_format(chan, original_read_fmt);
339 + ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", chan->name);
341 + if (original_write_fmt != AST_FORMAT_SLINEAR)
343 + res = ast_set_write_format(chan, original_write_fmt);
345 + ast_log(LOG_WARNING, "Unable to restore write format on '%s'\n", chan->name);
347 + t30_terminate(&fax.t30_state);
351 + ast_log(LOG_WARNING, "Could not answer channel '%s'\n", chan->name);
353 + ast_module_user_remove(u);
356 +/*- End of function --------------------------------------------------------*/
358 +static int unload_module(void)
362 + ast_module_user_hangup_all();
364 + res = ast_unregister_application(app);
369 +/*- End of function --------------------------------------------------------*/
371 +static int load_module(void)
373 + return ast_register_application(app, rxfax_exec, synopsis, descrip);
375 +/*- End of function --------------------------------------------------------*/
377 +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Trivial FAX Receive Application");
379 +/*- End of file ------------------------------------------------------------*/
381 +++ b/apps/app_txfax.c
384 + * Asterisk -- A telephony toolkit for Linux.
386 + * Trivial application to send a TIFF file as a FAX
388 + * Copyright (C) 2003, Steve Underwood
390 + * Steve Underwood <steveu@coppice.org>
392 + * This program is free software, distributed under the terms of
393 + * the GNU General Public License
397 + <depend>spandsp</depend>
400 +#include "asterisk.h"
402 +ASTERISK_FILE_VERSION(__FILE__, "$Revision:$")
407 +#include <inttypes.h>
408 +#include <pthread.h>
412 +#include <spandsp.h>
414 +#include "asterisk/lock.h"
415 +#include "asterisk/file.h"
416 +#include "asterisk/logger.h"
417 +#include "asterisk/channel.h"
418 +#include "asterisk/pbx.h"
419 +#include "asterisk/module.h"
420 +#include "asterisk/translate.h"
422 +static char *app = "TxFAX";
424 +static char *synopsis = "Send a FAX file";
426 +static char *descrip =
427 +" TxFAX(filename[|caller][|debug]): Send a given TIFF file to the channel as a FAX.\n"
428 +"The \"caller\" option makes the application behave as a calling machine,\n"
429 +"rather than the answering machine. The default behaviour is to behave as\n"
430 +"an answering machine.\n"
431 +"Uses LOCALSTATIONID to identify itself to the remote end.\n"
432 +" LOCALHEADERINFO to generate a header line on each page.\n"
433 +"Sets REMOTESTATIONID to the receiver CSID.\n"
434 +"Returns -1 when the user hangs up, or if the file does not exist.\n"
435 +"Returns 0 otherwise.\n";
437 +#define MAX_BLOCK_SIZE 240
439 +static void span_message(int level, const char *msg)
443 + if (level == SPAN_LOG_WARNING)
444 + ast_level = __LOG_WARNING;
445 + else if (level == SPAN_LOG_WARNING)
446 + ast_level = __LOG_WARNING;
448 + ast_level = __LOG_DEBUG;
449 + ast_log(ast_level, __FILE__, __LINE__, __PRETTY_FUNCTION__, msg);
451 +/*- End of function --------------------------------------------------------*/
454 +static void t30_flush(t30_state_t *s, int which)
458 +/*- End of function --------------------------------------------------------*/
461 +static void phase_e_handler(t30_state_t *s, void *user_data, int result)
463 + struct ast_channel *chan;
464 + char far_ident[21];
466 + chan = (struct ast_channel *) user_data;
467 + if (result == T30_ERR_OK)
469 + t30_get_far_ident(s, far_ident);
470 + pbx_builtin_setvar_helper(chan, "REMOTESTATIONID", far_ident);
474 + ast_log(LOG_DEBUG, "==============================================================================\n");
475 + ast_log(LOG_DEBUG, "Fax send not successful - result (%d) %s.\n", result, t30_completion_code_to_str(result));
476 + ast_log(LOG_DEBUG, "==============================================================================\n");
479 +/*- End of function --------------------------------------------------------*/
481 +static int txfax_exec(struct ast_channel *chan, void *data)
484 + char source_file[256];
496 + struct ast_module_user *u;
497 + struct ast_frame *inf = NULL;
498 + struct ast_frame outf;
500 + int original_read_fmt;
501 + int original_write_fmt;
503 + uint8_t __buf[sizeof(uint16_t)*MAX_BLOCK_SIZE + 2*AST_FRIENDLY_OFFSET];
504 + uint8_t *buf = __buf + AST_FRIENDLY_OFFSET;
508 + ast_log(LOG_WARNING, "Fax transmit channel is NULL. Giving up.\n");
512 + span_set_message_handler(span_message);
514 + /* The next few lines of code parse out the filename and header from the input string */
517 + /* No data implies no filename or anything is present */
518 + ast_log(LOG_WARNING, "Txfax requires an argument (filename)\n");
522 + calling_party = FALSE;
524 + source_file[0] = '\0';
526 + for (option = 0, v = s = data; v; option++, s++)
529 + v = strchr(s, '|');
530 + s = (v) ? v : s + strlen(s);
531 + strncpy((char *) buf, t, s - t);
535 + /* The first option is always the file name */
539 + strncpy(source_file, t, len);
540 + source_file[len] = '\0';
542 + else if (strncmp("caller", t, s - t) == 0)
544 + calling_party = TRUE;
546 + else if (strncmp("debug", t, s - t) == 0)
554 + u = ast_module_user_add(chan);
556 + if (chan->_state != AST_STATE_UP)
558 + /* Shouldn't need this, but checking to see if channel is already answered
559 + * Theoretically asterisk should already have answered before running the app */
560 + res = ast_answer(chan);
565 + original_read_fmt = chan->readformat;
566 + if (original_read_fmt != AST_FORMAT_SLINEAR)
568 + res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
571 + ast_log(LOG_WARNING, "Unable to set to linear read mode, giving up\n");
575 + original_write_fmt = chan->writeformat;
576 + if (original_write_fmt != AST_FORMAT_SLINEAR)
578 + res = ast_set_write_format(chan, AST_FORMAT_SLINEAR);
581 + ast_log(LOG_WARNING, "Unable to set to linear write mode, giving up\n");
582 + res = ast_set_read_format(chan, original_read_fmt);
584 + ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", chan->name);
588 + fax_init(&fax, calling_party);
590 + fax.logging.level = SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW;
592 + x = pbx_builtin_getvar_helper(chan, "LOCALSTATIONID");
594 + t30_set_local_ident(&fax.t30_state, x);
595 + x = pbx_builtin_getvar_helper(chan, "LOCALHEADERINFO");
597 + t30_set_header_info(&fax.t30_state, x);
598 + t30_set_tx_file(&fax.t30_state, source_file, -1, -1);
599 + //t30_set_phase_b_handler(&fax.t30_state, phase_b_handler, chan);
600 + //t30_set_phase_d_handler(&fax.t30_state, phase_d_handler, chan);
601 + t30_set_phase_e_handler(&fax.t30_state, phase_e_handler, chan);
602 + t30_set_ecm_capability(&fax.t30_state, TRUE);
603 + t30_set_supported_compressions(&fax.t30_state, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION);
604 + while (ast_waitfor(chan, -1) > -1)
606 + inf = ast_read(chan);
612 + if (inf->frametype == AST_FRAME_VOICE)
614 + if (fax_rx(&fax, inf->data, inf->samples))
616 + samples = (inf->samples <= MAX_BLOCK_SIZE) ? inf->samples : MAX_BLOCK_SIZE;
617 + len = fax_tx(&fax, (int16_t *) &buf[AST_FRIENDLY_OFFSET], samples);
620 + memset(&outf, 0, sizeof(outf));
621 + outf.frametype = AST_FRAME_VOICE;
622 + outf.subclass = AST_FORMAT_SLINEAR;
623 + outf.datalen = len*sizeof(int16_t);
624 + outf.samples = len;
625 + outf.data = &buf[AST_FRIENDLY_OFFSET];
626 + outf.offset = AST_FRIENDLY_OFFSET;
627 + if (ast_write(chan, &outf) < 0)
629 + ast_log(LOG_WARNING, "Unable to write frame to channel; %s\n", strerror(errno));
638 + ast_log(LOG_DEBUG, "Got hangup\n");
641 + if (original_read_fmt != AST_FORMAT_SLINEAR)
643 + res = ast_set_read_format(chan, original_read_fmt);
645 + ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", chan->name);
647 + if (original_write_fmt != AST_FORMAT_SLINEAR)
649 + res = ast_set_write_format(chan, original_write_fmt);
651 + ast_log(LOG_WARNING, "Unable to restore write format on '%s'\n", chan->name);
653 + t30_terminate(&fax.t30_state);
657 + ast_log(LOG_WARNING, "Could not answer channel '%s'\n", chan->name);
659 + ast_module_user_remove(u);
662 +/*- End of function --------------------------------------------------------*/
664 +static int unload_module(void)
668 + ast_module_user_hangup_all();
670 + res = ast_unregister_application(app);
675 +/*- End of function --------------------------------------------------------*/
677 +static int load_module(void)
679 + return ast_register_application(app, txfax_exec, synopsis, descrip);
681 +/*- End of function --------------------------------------------------------*/
683 +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Trivial FAX Transmit Application");
685 +/*- End of file ------------------------------------------------------------*/
686 --- a/build_tools/menuselect-deps.in
687 +++ b/build_tools/menuselect-deps.in
688 @@ -23,6 +23,7 @@ PGSQL=@PBX_PGSQL@
692 +SPANDSP=@PBX_SPANDSP@
694 SPEEXDSP=@PBX_SPEEXDSP@
695 SPEEX_PREPROCESS=@PBX_SPEEX_PREPROCESS@
698 @@ -205,6 +205,7 @@ AST_EXT_LIB_SETUP([PRI], [ISDN PRI], [pr
699 AST_EXT_LIB_SETUP([PWLIB], [PWlib], [pwlib])
700 AST_EXT_LIB_SETUP([OPENH323], [OpenH323], [h323])
701 AST_EXT_LIB_SETUP([RADIUS], [Radius Client], [radius])
702 +AST_EXT_LIB_SETUP([SPANDSP], [spandsp Library], [spandsp])
703 AST_EXT_LIB_SETUP([SPEEX], [Speex], [speex])
704 AST_EXT_LIB_SETUP([SPEEXDSP], [Speexdsp], [speexdsp])
705 AST_EXT_LIB_SETUP([SQLITE], [SQLite], [sqlite])
706 @@ -1359,6 +1360,8 @@ fi
708 AST_EXT_LIB_CHECK([RADIUS], [radiusclient-ng], [rc_read_config], [radiusclient-ng.h])
710 +AST_EXT_LIB_CHECK([SPANDSP], [spandsp], [fax_init], [spandsp.h], [-ltiff -ljpeg -lz])
712 AST_EXT_LIB_CHECK([SPEEX], [speex], [speex_encode], [speex/speex.h], [-lm])
714 # See if the main speex library contains the preprocess functions
715 --- a/include/asterisk/plc.h
716 +++ b/include/asterisk/plc.h
719 - * \brief SpanDSP - a series of DSP components for telephony
721 + * SpanDSP - a series of DSP components for telephony
725 - * \author Steve Underwood <steveu@coppice.org>
726 + * Written by Steve Underwood <steveu@coppice.org>
728 * Copyright (C) 2004 Steve Underwood
730 * All rights reserved.
732 * This program is free software; you can redistribute it and/or modify
733 - * it under the terms of the GNU General Public License as published by
734 - * the Free Software Foundation; either version 2 of the License, or
735 - * (at your option) any later version.
736 + * it under the terms of the GNU General Public License version 2, as
737 + * published by the Free Software Foundation.
739 * This program is distributed in the hope that it will be useful,
740 * but WITHOUT ANY WARRANTY; without even the implied warranty of
742 * along with this program; if not, write to the Free Software
743 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
745 - * This version may be optionally licenced under the GNU LGPL licence.
747 - * A license has been granted to Digium (via disclaimer) for the use of
749 + * $Id: plc.h,v 1.15 2007/04/08 08:16:18 steveu Exp $
754 -#if !defined(_PLC_H_)
758 -#include <sys/int_types.h>
760 -#if defined(__OpenBSD__) || defined( __FreeBSD__)
761 -#include <inttypes.h>
766 +#if !defined(_SPANDSP_PLC_H_)
767 +#define _SPANDSP_PLC_H_
769 /*! \page plc_page Packet loss concealment
770 \section plc_page_sec_1 What does it do?
771 -The packet loss concealment module provides a suitable synthetic fill-in signal,
772 -to minimise the audible effect of lost packets in VoIP applications. It is not
773 -tied to any particular codec, and could be used with almost any codec which does not
774 +The packet loss concealment module provides a synthetic fill-in signal, to minimise
775 +the audible effect of lost packets in VoIP applications. It is not tied to any
776 +particular codec, and could be used with almost any codec which does not
777 specify its own procedure for packet loss concealment.
779 -Where a codec specific concealment procedure exists, the algorithm is usually built
780 +Where a codec specific concealment procedure exists, that algorithm is usually built
781 around knowledge of the characteristics of the particular codec. It will, therefore,
782 generally give better results for that particular codec than this generic concealer will.
784 +The PLC code implements an algorithm similar to the one described in Appendix 1 of G.711.
785 +However, the G.711 algorithm is optimised for 10ms packets. Few people use such small
786 +packets. 20ms is a much more common value, and longer packets are also quite common. The
787 +algorithm has been adjusted with this in mind. Also, the G.711 approach causes an
788 +algorithmic delay, and requires significant buffer manipulation when there is no packet
789 +loss. The algorithm used here avoids this. It causes no delay, and achieves comparable
790 +quality with normal speech.
792 +Note that both this algorithm, and the one in G.711 are optimised for speech. For most kinds
793 +of music a much slower decay on bursts of lost packets give better results.
795 \section plc_page_sec_2 How does it work?
796 While good packets are being received, the plc_rx() routine keeps a record of the trailing
797 section of the known speech signal. If a packet is missed, plc_fillin() is called to produce
798 @@ -83,7 +81,7 @@ are needed to obtain smooth pleasant sou
799 correct steadily fall. Therefore, the volume of the synthesized signal is made to decay
800 linearly, such that after 50ms of missing audio it is reduced to silence.
802 -- When real speech resumes, an extra 1/4 pitch period of sythetic speech is blended with the
803 +- When real speech resumes, an extra 1/4 pitch period of synthetic speech is blended with the
804 start of the real speech. If the erasure is small, this smoothes the transition. If the erasure
805 is long, and the synthetic signal has faded to zero, the blending softens the start up of the
806 real signal, avoiding a kind of "click" or "pop" effect that might occur with a sudden onset.
807 @@ -110,6 +108,9 @@ That's it!
808 the pitch assessment. */
809 #define PLC_HISTORY_LEN (CORRELATION_SPAN + PLC_PITCH_MIN)
812 + The generic packet loss concealer context.
816 /*! Consecutive erased samples */
817 @@ -127,12 +128,13 @@ typedef struct
823 +#if defined(__cplusplus)
828 -/*! Process a block of received audio samples.
829 - \brief Process a block of received audio samples.
830 +/*! Process a block of received audio samples for PLC.
831 + \brief Process a block of received audio samples for PLC.
832 \param s The packet loss concealer context.
833 \param amp The audio sample buffer.
834 \param len The number of samples in the buffer.
835 @@ -147,13 +149,18 @@ int plc_rx(plc_state_t *s, int16_t amp[]
836 \return The number of samples synthesized. */
837 int plc_fillin(plc_state_t *s, int16_t amp[], int len);
839 -/*! Process a block of received V.29 modem audio samples.
840 - \brief Process a block of received V.29 modem audio samples.
841 +/*! Initialise a packet loss concealer context.
842 + \brief Initialise a PLC context.
843 \param s The packet loss concealer context.
844 - \return A pointer to the he packet loss concealer context. */
845 + \return A pointer to the the packet loss concealer context. */
846 plc_state_t *plc_init(plc_state_t *s);
849 +/*! Free a packet loss concealer context.
850 + \param s The packet loss concealer context.
851 + \return 0 for OK. */
852 +int plc_release(plc_state_t *s);
854 +#if defined(__cplusplus)
860 @@ -141,6 +141,9 @@ PWLIB_LIB=@PWLIB_LIB@
861 RADIUS_INCLUDE=@RADIUS_INCLUDE@
862 RADIUS_LIB=@RADIUS_LIB@
864 +SPANDSP_INCLUDE=@SPANDSP_INCLUDE@
865 +SPANDSP_LIB=@SPANDSP_LIB@
867 SPEEX_INCLUDE=@SPEEX_INCLUDE@
868 SPEEX_LIB=@SPEEX_LIB@