/* dsp_dtmf.c David Rowe Sep 5 2006 This file provides an interface between Steve Underwood's DTMF test software and the Asterisk DSP code. Allows sophisicated unit testing of Asterisk dsp.c signal processing functions. */ /* Copyright (C) 2006 David Rowe This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include #include #include /* Asterisk DTMF detector functions */ #include /* spandsp DTMF detector interface */ /* dummy variables and stubs to enable dsp.c to link OK */ unsigned char __ast_lin2a[8192]; short __ast_alaw[256]; unsigned char __ast_lin2mu[16384]; short __ast_mulaw[256]; void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) { } int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f) { return 0; } void ast_frfree(struct ast_frame *fr) { } char *ast_getformatname(int format) { return "dummy"; } void ast_register_file_version(const char *file, const char *version) { } void ast_unregister_file_version(const char *file) { } static struct ast_dsp *dsp; static int digits; static char digbuf[128]; dtmf_rx_state_t *dtmf_rx_init( dtmf_rx_state_t *s, void (*callback)(void *user_data, const char *digits, int len), void *user_data ) { dsp = ast_dsp_new(); ast_dsp_set_features(dsp, DSP_FEATURE_DTMF_DETECT); digits = 0; *digbuf = 0; } void dtmf_rx_parms(dtmf_rx_state_t *s, int filter_dialtone, int twist, int reverse_twist) { } int dtmf_rx(dtmf_rx_state_t *s, const int16_t *amp, int samples) { struct ast_frame af_in; struct ast_frame *af_out; int n; af_in.subclass = AST_FORMAT_SLINEAR; af_in.frametype = AST_FRAME_VOICE; af_in.data = (char*)amp; af_in.datalen = samples*2; af_out = ast_dsp_process(NULL, dsp, &af_in); if (af_out->frametype == AST_FRAME_DTMF) { digbuf[digits++] = af_out->subclass; } } int dtmf_get(dtmf_rx_state_t *s, char *buf, int max) { int dig = digits; memcpy(buf, digbuf, digits); digits = 0; *digbuf = 0; return dig; }