void channel_read_adsi_channel(uc_t *uc, int chan, void *user_data, uint8_t *buf, int len) { int i; int xlen; int16_t pcm_buf[1024]; char *s; int outframes; for (i = 0; i < len; i++) pcm_buf[i] = alaw_to_linear(buf[i]); /*endfor*/ outframes = afWriteFrames(rxhandle, AF_DEFAULT_TRACK, pcm_buf, len); if (outframes != len) { printf("Failed to write %d samples\n", len); exit(2); } dtmf_rx(&chan_stuff[chan].dtmf_state, pcm_buf, len); xlen = dtmf_rx_get(&chan_stuff[chan].dtmf_state, chan_stuff[chan].dtmf + chan_stuff[chan].dtmf_ptr, 100 - chan_stuff[chan].dtmf_ptr); if (xlen > 0) { s = chan_stuff[chan].dtmf + chan_stuff[chan].dtmf_ptr; while (*s) { if (*s == '#') { uc_set_channel_read_callback(uc, 0, NULL, 0); uc_set_channel_write_callback(uc, 0, NULL, 0); if (uc_call_control(uc, UC_OP_DROPCALL, chan_stuff[chan].crn, (void *) UC_CAUSE_NORMAL_CLEARING)) printf ("A Drop Call failed\n"); /*endif*/ break; } /*endif*/ s++; } /*endwhile*/ printf("Got '%s'\n", chan_stuff[chan].dtmf); chan_stuff[chan].dtmf_ptr += xlen; } /*endif*/ adsi_rx(&(chan_stuff[chan].adsi_rx), pcm_buf, len); }
void channel_read_fax_channel(uc_t *uc, int chan, void *user_data, uint8_t *buf, int len) { int i; int xlen; char *s; int outframes; #if 0 outframes = afWriteFrames(rxhandle, AF_DEFAULT_TRACK, buf, len >> 1); if (outframes != len) { printf("Failed to write %d samples\n", len); exit(2); } #endif dtmf_rx(&chan_stuff[chan].dtmf_state, (int16_t *) buf, len); xlen = dtmf_rx_get(&chan_stuff[chan].dtmf_state, chan_stuff[chan].dtmf + chan_stuff[chan].dtmf_ptr, 100 - chan_stuff[chan].dtmf_ptr); if (xlen > 0) { s = chan_stuff[chan].dtmf + chan_stuff[chan].dtmf_ptr; while (*s) { if (*s == '#') { uc_set_channel_read_callback(uc, 0, NULL, 0); uc_set_channel_write_callback(uc, 0, NULL, 0); if (uc_call_control(uc, UC_OP_DROPCALL, chan_stuff[chan].crn, (void *) UC_CAUSE_NORMAL_CLEARING)) printf ("A Drop Call failed\n"); /*endif*/ break; } /*endif*/ s++; } /*endwhile*/ printf("Got '%s'\n", chan_stuff[chan].dtmf); chan_stuff[chan].dtmf_ptr += xlen; } /*endif*/ t30_rx(&(chan_stuff[chan].fax), (int16_t *) buf, len); }
void SpanDtmfProbe() { std::string dtmfCode = "*1234567890#ABCD"; iDSP::DtmfGeneratorProfile prof; prof.Level = 0; prof.DurationMs = 80; // 70 мало prof.PauseMs = 40; // 50 20-мало iDSP::DtmfGenerator gen; gen.Add(dtmfCode); // Init: digits_rx_callback_t callback = 0;//EvDigitDetected; void* pUserData = 0; dtmf_rx_state_t state; dtmf_rx_state_t* pState = &state; dtmf_rx_init(pState, callback, pUserData); // Adjust detector: bool rej350_440 = false; int fwTwist = 8; //8 Db максимальная разница уровней частот в комбинации int revTwist = 8; //-4 Db ? int threshold = -26; //Db минимальный уровень сигнала dtmf_rx_parms(pState, rej350_440, fwTwist, revTwist, threshold); while (gen.RestSampleCount() != 0) { int16_t sample = gen.NextSample(); dtmf_rx(pState, &sample, 1); } const int CMaxSymbols = 100; char dtmfCodeRx[CMaxSymbols]; int size = dtmf_rx_get(pState, dtmfCodeRx, CMaxSymbols); TUT_ASSERT(size == dtmfCode.size()); dtmfCodeRx[size] = '\0'; TUT_ASSERT(dtmfCode == dtmfCodeRx); // delete pState; //dtmf_rx_free(pState); //pState = 0; }
int main(int argc, char *argv[]) { int rc = 0; short readbuf[160]; char digitsbuf[255]; int fd = open(argv[1], O_RDONLY); #if defined(BELL_DETECTOR) bell_mf_rx_state_t *rxstate = NULL; if (!(rxstate = bell_mf_rx_init(rxstate, NULL, NULL))) { fprintf(stderr, "bell_mf_rx_init\n"); return -1; } #elif defined(MF_DETECTOR_FWD) r2_mf_rx_state_t *rxstate = NULL; if (!(rxstate = r2_mf_rx_init(rxstate, 1, NULL, NULL))) { fprintf(stderr, "r2_mf_rx_init fwd\n"); return -1; } #elif defined(MF_DETECTOR_BWD) r2_mf_rx_state_t *rxstate = NULL; if (!(rxstate = r2_mf_rx_init(rxstate, 0, NULL, NULL))) { fprintf(stderr, "r2_mf_rx_init backward\n"); return -1; } #elif defined(DTMF_DETECTOR) dtmf_rx_state_t *rxstate = NULL; if (!(rxstate = dtmf_rx_init(rxstate, NULL, NULL))) { fprintf(stderr, "dtmf_rx_init\n"); return -1; } #else #error "define detector type!" #endif if (fd == -1) { perror("fopen"); return -1; } while (1) { rc = read(fd, readbuf, sizeof(readbuf)/sizeof(readbuf[0])); if (rc < 0) { perror("read"); break; } if (!rc) { break; } #if defined(BELL_DETECTOR) rc = bell_mf_rx(rxstate, readbuf, rc/2); if (rc != 0) { fprintf(stderr, "Unprocessed samples: %d\n", rc); break; } digitsbuf[0] = '\0'; rc = bell_mf_rx_get(rxstate, digitsbuf, sizeof(digitsbuf)-1); if (rc > 0) { printf("Rx digits: %s\n", digitsbuf); } #elif defined(MF_DETECTOR_FWD) || defined(MF_DETECTOR_BWD) rc = r2_mf_rx(rxstate, readbuf, rc/2); if (rc != 0) { fprintf(stderr, "Unprocessed samples: %d\n", rc); break; } rc = r2_mf_rx_get(rxstate); if (rc > 0) { printf("Rx digit: %c\n", rc); } #elif defined(DTMF_DETECTOR) rc = dtmf_rx(rxstate, readbuf, rc/2); if (rc != 0) { fprintf(stderr, "Unprocessed samples: %d\n", rc); break; } digitsbuf[0] = '\0'; rc = dtmf_rx_get(rxstate, digitsbuf, sizeof(digitsbuf)-1); if (rc > 0) { printf("Rx digit: %s\n", digitsbuf); } #else #error "define detector type!" #endif } #if defined(BELL_DETECTOR) bell_mf_rx_free(rxstate); #elif defined(MF_DETECTOR_FWD) || defined(MF_DETECTOR_BWD) r2_mf_rx_free(rxstate); #elif defined(DTMF_DETECTOR) dtmf_rx_free(rxstate); #endif close(fd); return 0; }
static GstFlowReturn gst_dtmf_detect_transform_ip (GstBaseTransform * trans, GstBuffer * buf) { GstDtmfDetect *self = GST_DTMF_DETECT (trans); gint dtmf_count; gchar dtmfbuf[MAX_DTMF_DIGITS] = ""; gint i; GstMapInfo map; if (GST_BUFFER_IS_DISCONT (buf)) gst_dtmf_detect_state_reset (self); if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_GAP)) return GST_FLOW_OK; gst_buffer_map (buf, &map, GST_MAP_READ); dtmf_rx (self->dtmf_state, (gint16 *) map.data, map.size / 2); dtmf_count = dtmf_rx_get (self->dtmf_state, dtmfbuf, MAX_DTMF_DIGITS); if (dtmf_count) GST_DEBUG_OBJECT (self, "Got %d DTMF events: %s", dtmf_count, dtmfbuf); else GST_LOG_OBJECT (self, "Got no DTMF events"); gst_buffer_unmap (buf, &map); for (i = 0; i < dtmf_count; i++) { GstMessage *dtmf_message = NULL; GstStructure *structure; gint dtmf_payload_event; GST_DEBUG_OBJECT (self, "Got DTMF event %c", dtmfbuf[i]); switch (dtmfbuf[i]) { case '0': dtmf_payload_event = 0; break; case '1': dtmf_payload_event = 1; break; case '2': dtmf_payload_event = 2; break; case '3': dtmf_payload_event = 3; break; case '4': dtmf_payload_event = 4; break; case '5': dtmf_payload_event = 5; break; case '6': dtmf_payload_event = 6; break; case '7': dtmf_payload_event = 7; break; case '8': dtmf_payload_event = 8; break; case '9': dtmf_payload_event = 9; break; case '*': dtmf_payload_event = 10; break; case '#': dtmf_payload_event = 11; break; case 'A': dtmf_payload_event = 12; break; case 'B': dtmf_payload_event = 13; break; case 'C': dtmf_payload_event = 14; break; case 'D': dtmf_payload_event = 15; break; default: continue; } structure = gst_structure_new ("dtmf-event", "type", G_TYPE_INT, 1, "number", G_TYPE_INT, dtmf_payload_event, "method", G_TYPE_INT, 2, NULL); dtmf_message = gst_message_new_element (GST_OBJECT (self), structure); gst_element_post_message (GST_ELEMENT (self), dtmf_message); } return GST_FLOW_OK; }