12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748 |
- /*
- * SpanDSP - a series of DSP components for telephony
- *
- * modem_connect_tones_tests.c
- *
- * Written by Steve Underwood <steveu@coppice.org>
- *
- * Copyright (C) 2006 Steve Underwood
- *
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2, as
- * published by the Free Software Foundation.
- *
- * 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.
- */
- /*! \page modem_connect_tones_tests_page Modem connect tones tests
- \section modem_connect_tones_rx_tests_page_sec_1 What does it do?
- These tests...
- */
- #if defined(HAVE_CONFIG_H)
- #include "config.h"
- #endif
- #include <stdlib.h>
- #include <stdio.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <string.h>
- #include <sndfile.h>
- #include "spandsp.h"
- #include "spandsp-sim.h"
- #define SAMPLES_PER_CHUNK 160
- #define OUTPUT_FILE_NAME "modem_connect_tones.wav"
- #define MITEL_DIR "../test-data/mitel/"
- #define BELLCORE_DIR "../test-data/bellcore/"
- #define LEVEL_MAX -5
- #define LEVEL_MIN -48
- #define LEVEL_MIN_ACCEPT -43
- #define LEVEL_MIN_REJECT -44
- /* The 1100Hz tone is supposed to be within 38Hz, according to T.30. Allow another 8Hz for FDM, even though
- you rarely see that used today. */
- #define CED_FREQ_TOLERANCE (38 + 8)
- #define CED_FREQ_BLACKOUT (80)
- /* The 2100Hz tone is supposed to be within 15Hz, according to T.30. Allow another 8Hz for FDM, even though
- you rarely see that used today. */
- #define CNG_FREQ_TOLERANCE (15 + 8)
- #define CNG_FREQ_BLACKOUT (80)
- #define AM_FREQ_TOLERANCE (1)
- /* The 2225Hz tone is supposed to be within 15Hz. Allow another 8Hz for FDM, even though
- you rarely see that used today. */
- #define BELL_ANS_FREQ_TOLERANCE (15 + 8)
- #define BELL_ANS_FREQ_BLACKOUT (80)
- /* The 1300Hz tone is supposed to be within 15Hz, according to V.25. Allow another 8Hz for FDM, even though
- you rarely see that used today. */
- #define CALLING_TONE_FREQ_TOLERANCE (15 + 8)
- #define CALLING_TONE_FREQ_BLACKOUT (80)
- const char *bellcore_files[] =
- {
- MITEL_DIR "mitel-cm7291-talkoff.wav",
- BELLCORE_DIR "tr-tsy-00763-1.wav",
- BELLCORE_DIR "tr-tsy-00763-2.wav",
- BELLCORE_DIR "tr-tsy-00763-3.wav",
- BELLCORE_DIR "tr-tsy-00763-4.wav",
- BELLCORE_DIR "tr-tsy-00763-5.wav",
- BELLCORE_DIR "tr-tsy-00763-6.wav",
- ""
- };
- enum
- {
- PERFORM_TEST_1A = (1 << 1),
- PERFORM_TEST_1B = (1 << 2),
- PERFORM_TEST_1C = (1 << 3),
- PERFORM_TEST_1D = (1 << 4),
- PERFORM_TEST_1E = (1 << 5),
- PERFORM_TEST_1F = (1 << 6),
- PERFORM_TEST_1G = (1 << 7),
- PERFORM_TEST_2A = (1 << 8),
- PERFORM_TEST_2B = (1 << 9),
- PERFORM_TEST_2C = (1 << 10),
- PERFORM_TEST_2D = (1 << 11),
- PERFORM_TEST_2E = (1 << 12),
- PERFORM_TEST_2F = (1 << 13),
- PERFORM_TEST_2G = (1 << 14),
- PERFORM_TEST_3A = (1 << 15),
- PERFORM_TEST_3B = (1 << 16),
- PERFORM_TEST_3C = (1 << 17),
- PERFORM_TEST_3D = (1 << 18),
- PERFORM_TEST_3E = (1 << 19),
- PERFORM_TEST_3F = (1 << 20),
- PERFORM_TEST_3G = (1 << 21),
- PERFORM_TEST_4 = (1 << 22),
- PERFORM_TEST_5A = (1 << 23),
- PERFORM_TEST_5B = (1 << 24),
- PERFORM_TEST_6A = (1 << 25),
- PERFORM_TEST_6B = (1 << 26),
- PERFORM_TEST_7A = (1 << 27),
- PERFORM_TEST_7B = (1 << 28),
- PERFORM_TEST_8 = (1 << 29)
- };
- int preamble_count = 0;
- int preamble_on_at = -1;
- int preamble_off_at = -1;
- int hits = 0;
- int when = 0;
- static int preamble_get_bit(void *user_data)
- {
- static int bit_no = 0;
- int bit;
- /* Generate a section of HDLC flag octet preamble. Then generate some random
- bits, which should not look like preamble. */
- if (++preamble_count < 255)
- {
- bit = (bit_no < 2) ? 0 : 1;
- if (++bit_no >= 8)
- bit_no = 0;
- #if 0
- /* Inject some bad bits */
- if (rand()%15 == 0)
- return bit ^ 1;
- #endif
- }
- else
- {
- bit = rand() & 1;
- }
- return bit;
- }
- /*- End of function --------------------------------------------------------*/
- static void cng_detected(void *user_data, int tone, int level, int delay)
- {
- printf("%s (%d) declared at %fs, delay %d (%ddBm0)\n", modem_connect_tone_to_str(tone), tone, (float) when/SAMPLE_RATE, delay, level);
- if (tone == MODEM_CONNECT_TONES_FAX_CNG)
- hits++;
- }
- /*- End of function --------------------------------------------------------*/
- static void preamble_detected(void *user_data, int tone, int level, int delay)
- {
- printf("%s (%d) declared at bit %d (%ddBm0)\n", modem_connect_tone_to_str(tone), tone, preamble_count, level);
- if (tone == MODEM_CONNECT_TONES_FAX_PREAMBLE)
- preamble_on_at = preamble_count;
- else
- preamble_off_at = preamble_count;
- /*endif*/
- }
- /*- End of function --------------------------------------------------------*/
- static void ced_detected(void *user_data, int tone, int level, int delay)
- {
- printf("%s (%d) declared at %fs, delay %d (%ddBm0)\n", modem_connect_tone_to_str(tone), tone, (float) when/SAMPLE_RATE, delay, level);
- if (tone == MODEM_CONNECT_TONES_FAX_PREAMBLE
- ||
- tone == MODEM_CONNECT_TONES_ANS)
- {
- hits++;
- }
- }
- /*- End of function --------------------------------------------------------*/
- static void ans_pr_detected(void *user_data, int tone, int level, int delay)
- {
- printf("%s (%d) declared at %fs, delay %d (%ddBm0)\n", modem_connect_tone_to_str(tone), tone, (float) when/SAMPLE_RATE, delay, level);
- if (tone == MODEM_CONNECT_TONES_ANS_PR)
- hits++;
- }
- /*- End of function --------------------------------------------------------*/
- static void bell_ans_detected(void *user_data, int tone, int level, int delay)
- {
- printf("%s (%d) declared at %fs, delay %d (%ddBm0)\n", modem_connect_tone_to_str(tone), tone, (float) when/SAMPLE_RATE, delay, level);
- if (tone == MODEM_CONNECT_TONES_BELL_ANS)
- hits++;
- }
- /*- End of function --------------------------------------------------------*/
- static void calling_tone_detected(void *user_data, int tone, int level, int delay)
- {
- printf("%s (%d) declared at %fs, delay %d (%ddBm0)\n", modem_connect_tone_to_str(tone), tone, (float) when/SAMPLE_RATE, delay, level);
- if (tone == MODEM_CONNECT_TONES_CALLING_TONE)
- hits++;
- }
- /*- End of function --------------------------------------------------------*/
- int main(int argc, char *argv[])
- {
- int i;
- int j;
- int pitch;
- int depth;
- int level;
- int interval;
- int cycle;
- int16_t amp[8000];
- modem_connect_tones_rx_state_t cng_rx;
- modem_connect_tones_rx_state_t ced_rx;
- modem_connect_tones_rx_state_t ans_pr_rx;
- modem_connect_tones_tx_state_t modem_tone_tx;
- modem_connect_tones_rx_state_t calling_tone_rx;
- modem_connect_tones_rx_state_t bell_ans_rx;
- awgn_state_t chan_noise_source;
- SNDFILE *inhandle;
- SNDFILE *outhandle;
- int outframes;
- int frames;
- int samples;
- int hit;
- int level2;
- int max_level2;
- int tone_type;
- int test_list;
- int opt;
- bool false_hit;
- bool false_miss;
- char *decode_test_file;
- fsk_tx_state_t preamble_tx;
- test_list = 0;
- decode_test_file = NULL;
- while ((opt = getopt(argc, argv, "d:")) != -1)
- {
- switch (opt)
- {
- case 'd':
- decode_test_file = optarg;
- break;
- default:
- //usage();
- exit(2);
- break;
- }
- }
- argc -= optind;
- argv += optind;
- for (i = 0; i < argc; i++)
- {
- if (strcasecmp(argv[i], "1a") == 0)
- test_list |= PERFORM_TEST_1A;
- else if (strcasecmp(argv[i], "1b") == 0)
- test_list |= PERFORM_TEST_1B;
- else if (strcasecmp(argv[i], "1c") == 0)
- test_list |= PERFORM_TEST_1C;
- else if (strcasecmp(argv[i], "1d") == 0)
- test_list |= PERFORM_TEST_1D;
- else if (strcasecmp(argv[i], "1e") == 0)
- test_list |= PERFORM_TEST_1E;
- else if (strcasecmp(argv[i], "1f") == 0)
- test_list |= PERFORM_TEST_1F;
- else if (strcasecmp(argv[i], "1g") == 0)
- test_list |= PERFORM_TEST_1G;
- else if (strcasecmp(argv[i], "2a") == 0)
- test_list |= PERFORM_TEST_2A;
- else if (strcasecmp(argv[i], "2b") == 0)
- test_list |= PERFORM_TEST_2B;
- else if (strcasecmp(argv[i], "2c") == 0)
- test_list |= PERFORM_TEST_2C;
- else if (strcasecmp(argv[i], "2d") == 0)
- test_list |= PERFORM_TEST_2D;
- else if (strcasecmp(argv[i], "2e") == 0)
- test_list |= PERFORM_TEST_2E;
- else if (strcasecmp(argv[i], "2f") == 0)
- test_list |= PERFORM_TEST_2F;
- else if (strcasecmp(argv[i], "2g") == 0)
- test_list |= PERFORM_TEST_2G;
- else if (strcasecmp(argv[i], "3a") == 0)
- test_list |= PERFORM_TEST_3A;
- else if (strcasecmp(argv[i], "3b") == 0)
- test_list |= PERFORM_TEST_3B;
- else if (strcasecmp(argv[i], "3c") == 0)
- test_list |= PERFORM_TEST_3C;
- else if (strcasecmp(argv[i], "3d") == 0)
- test_list |= PERFORM_TEST_3D;
- else if (strcasecmp(argv[i], "3e") == 0)
- test_list |= PERFORM_TEST_3E;
- else if (strcasecmp(argv[i], "3f") == 0)
- test_list |= PERFORM_TEST_3F;
- else if (strcasecmp(argv[i], "3g") == 0)
- test_list |= PERFORM_TEST_3G;
- else if (strcasecmp(argv[i], "4") == 0)
- test_list |= PERFORM_TEST_4;
- else if (strcasecmp(argv[i], "5a") == 0)
- test_list |= PERFORM_TEST_5A;
- else if (strcasecmp(argv[i], "5b") == 0)
- test_list |= PERFORM_TEST_5B;
- else if (strcasecmp(argv[i], "6a") == 0)
- test_list |= PERFORM_TEST_6A;
- else if (strcasecmp(argv[i], "6b") == 0)
- test_list |= PERFORM_TEST_6B;
- else if (strcasecmp(argv[i], "7a") == 0)
- test_list |= PERFORM_TEST_7A;
- else if (strcasecmp(argv[i], "7b") == 0)
- test_list |= PERFORM_TEST_7B;
- else if (strcasecmp(argv[i], "8") == 0)
- test_list |= PERFORM_TEST_8;
- else
- {
- fprintf(stderr, "Unknown test '%s' specified\n", argv[i]);
- exit(2);
- }
- }
- if (decode_test_file == NULL && test_list == 0)
- test_list = 0xFFFFFFFF;
- if ((outhandle = sf_open_telephony_write(OUTPUT_FILE_NAME, 1)) == NULL)
- {
- fprintf(stderr, " Cannot create audio file '%s'\n", OUTPUT_FILE_NAME);
- exit(2);
- }
- if ((test_list & PERFORM_TEST_1A))
- {
- printf("Test 1a: CNG generation to a file\n");
- modem_connect_tones_tx_init(&modem_tone_tx, MODEM_CONNECT_TONES_FAX_CNG);
- for (i = 0; i < 20*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- outframes = sf_writef_short(outhandle, amp, samples);
- if (outframes != samples)
- {
- fprintf(stderr, " Error writing audio file\n");
- exit(2);
- }
- /*endif*/
- }
- /*endfor*/
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_1B))
- {
- printf("Test 1b: CED/ANS generation to a file\n");
- modem_connect_tones_tx_init(&modem_tone_tx, MODEM_CONNECT_TONES_FAX_CED);
- for (i = 0; i < 20*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- outframes = sf_writef_short(outhandle, amp, samples);
- if (outframes != samples)
- {
- fprintf(stderr, " Error writing audio file\n");
- exit(2);
- }
- /*endif*/
- }
- /*endfor*/
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_1C))
- {
- printf("Test 1c: ANSam (Modulated ANS) generation to a file\n");
- /* Some with modulation */
- modem_connect_tones_tx_init(&modem_tone_tx, MODEM_CONNECT_TONES_ANSAM);
- for (i = 0; i < 20*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- outframes = sf_writef_short(outhandle, amp, samples);
- if (outframes != samples)
- {
- fprintf(stderr, " Error writing audio file\n");
- exit(2);
- }
- /*endif*/
- }
- /*endfor*/
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_1D))
- {
- printf("Test 1d: ANS/ (EC-disable) generation to a file\n");
- /* Some without modulation, but with phase reversals */
- modem_connect_tones_tx_init(&modem_tone_tx, MODEM_CONNECT_TONES_ANS_PR);
- for (i = 0; i < 20*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- outframes = sf_writef_short(outhandle, amp, samples);
- if (outframes != samples)
- {
- fprintf(stderr, " Error writing audio file\n");
- exit(2);
- }
- /*endif*/
- }
- /*endfor*/
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_1E))
- {
- printf("Test 1e: ANSam/ (Modulated EC-disable) generation to a file\n");
- /* Some with modulation and phase reversals */
- modem_connect_tones_tx_init(&modem_tone_tx, MODEM_CONNECT_TONES_ANSAM_PR);
- for (i = 0; i < 20*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- outframes = sf_writef_short(outhandle, amp, samples);
- if (outframes != samples)
- {
- fprintf(stderr, " Error writing audio file\n");
- exit(2);
- }
- /*endif*/
- }
- /*endfor*/
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_1F))
- {
- printf("Test 1f: Bell answer tone generation to a file\n");
- modem_connect_tones_tx_init(&modem_tone_tx, MODEM_CONNECT_TONES_BELL_ANS);
- for (i = 0; i < 20*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- outframes = sf_writef_short(outhandle, amp, samples);
- if (outframes != samples)
- {
- fprintf(stderr, " Error writing audio file\n");
- exit(2);
- }
- /*endif*/
- }
- /*endfor*/
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_1G))
- {
- printf("Test 1g: Calling tone generation to a file\n");
- modem_connect_tones_tx_init(&modem_tone_tx, MODEM_CONNECT_TONES_CALLING_TONE);
- for (i = 0; i < 20*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- outframes = sf_writef_short(outhandle, amp, samples);
- if (outframes != samples)
- {
- fprintf(stderr, " Error writing audio file\n");
- exit(2);
- }
- /*endif*/
- }
- /*endfor*/
- }
- /*endif*/
- if (sf_close_telephony(outhandle))
- {
- printf(" Cannot close audio file '%s'\n", OUTPUT_FILE_NAME);
- exit(2);
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_2A))
- {
- printf("Test 2a: CNG detection with frequency\n");
- tone_type = MODEM_CONNECT_TONES_FAX_CNG;
- awgn_init_dbm0(&chan_noise_source, 7162534, -50.0f);
- false_hit = false;
- false_miss = false;
- for (pitch = 1100 - 500; pitch <= 1100 + 500; pitch++)
- {
- /* Use the transmitter to test the receiver */
- modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
- /* Fudge things for the test */
- modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
- modem_connect_tones_rx_init(&cng_rx, tone_type, NULL, NULL);
- level2 = 0;
- max_level2 = 0;
- for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- for (j = 0; j < samples; j++)
- {
- amp[j] += awgn(&chan_noise_source);
- level2 += ((abs(amp[j]) - level2) >> 5);
- if (level2 > max_level2)
- max_level2 = level2;
- }
- /*endfor*/
- modem_connect_tones_rx(&cng_rx, amp, samples);
- }
- /*endfor*/
- hit = modem_connect_tones_rx_get(&cng_rx);
- if (pitch < (1100 - CED_FREQ_BLACKOUT) || pitch > (1100 + CED_FREQ_BLACKOUT))
- {
- if (hit != MODEM_CONNECT_TONES_NONE)
- false_hit = true;
- /*endif*/
- }
- else if (pitch > (1100 - CED_FREQ_TOLERANCE) && pitch < (1100 + CED_FREQ_TOLERANCE))
- {
- if (hit != tone_type)
- false_miss = true;
- /*endif*/
- }
- /*endif*/
- if (hit != MODEM_CONNECT_TONES_NONE)
- printf("Detected at %5dHz %12" PRId32 " %12" PRId32 " %s (%d)\n", pitch, cng_rx.channel_level, cng_rx.notch_level, modem_connect_tone_to_str(hit), hit);
- /*endif*/
- }
- /*endfor*/
- if (false_hit || false_miss)
- {
- printf("Test failed.\n");
- exit(2);
- }
- /*endif*/
- printf("Test passed.\n");
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_2B))
- {
- printf("Test 2b: CED/ANS detection with frequency\n");
- awgn_init_dbm0(&chan_noise_source, 7162534, -50.0f);
- false_hit = false;
- false_miss = false;
- for (pitch = 2100 - 500; pitch < 2100 + 500; pitch++)
- {
- /* Use the transmitter to test the receiver */
- modem_connect_tones_tx_init(&modem_tone_tx, MODEM_CONNECT_TONES_ANS);
- /* Fudge things for the test */
- modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
- modem_connect_tones_rx_init(&ced_rx, MODEM_CONNECT_TONES_FAX_CED_OR_PREAMBLE, NULL, NULL);
- for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- for (j = 0; j < samples; j++)
- amp[j] += awgn(&chan_noise_source);
- /*endfor*/
- modem_connect_tones_rx(&ced_rx, amp, samples);
- }
- /*endfor*/
- hit = modem_connect_tones_rx_get(&ced_rx);
- if (pitch < (2100 - CNG_FREQ_BLACKOUT) || pitch > (2100 + CNG_FREQ_BLACKOUT))
- {
- if (hit != MODEM_CONNECT_TONES_NONE)
- false_hit = true;
- /*endif*/
- }
- else if (pitch > (2100 - CNG_FREQ_TOLERANCE) && pitch < (2100 + CNG_FREQ_TOLERANCE))
- {
- if (hit != MODEM_CONNECT_TONES_FAX_CED)
- false_miss = true;
- /*endif*/
- }
- /*endif*/
- if (hit != MODEM_CONNECT_TONES_NONE)
- printf("Detected at %5dHz %12" PRId32 " %12" PRId32 " %s (%d)\n", pitch, ced_rx.channel_level, ced_rx.notch_level, modem_connect_tone_to_str(hit), hit);
- /*endif*/
- }
- if (false_hit || false_miss)
- {
- printf("Test failed.\n");
- exit(2);
- }
- /*endif*/
- printf("Test passed.\n");
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_2C))
- {
- printf("Test 2c: ANSam detection with frequency\n");
- tone_type = MODEM_CONNECT_TONES_ANSAM;
- awgn_init_dbm0(&chan_noise_source, 7162534, -50.0f);
- false_hit = false;
- false_miss = false;
- for (pitch = 2100 - 100; pitch <= 2100 + 100; pitch++)
- {
- /* Use the transmitter to test the receiver */
- modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
- /* Fudge things for the test */
- modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
- modem_connect_tones_rx_init(&ans_pr_rx, tone_type, NULL, NULL);
- for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- for (j = 0; j < samples; j++)
- amp[j] += awgn(&chan_noise_source);
- /*endfor*/
- modem_connect_tones_rx(&ans_pr_rx, amp, samples);
- }
- /*endfor*/
- hit = modem_connect_tones_rx_get(&ans_pr_rx);
- if (pitch < (2100 - CNG_FREQ_BLACKOUT) || pitch > (2100 + CNG_FREQ_BLACKOUT))
- {
- if (hit != MODEM_CONNECT_TONES_NONE)
- false_hit = true;
- /*endif*/
- }
- else if (pitch > (2100 - CNG_FREQ_TOLERANCE) && pitch < (2100 + CNG_FREQ_TOLERANCE))
- {
- if (hit != tone_type)
- false_miss = true;
- /*endif*/
- }
- /*endif*/
- if (hit != MODEM_CONNECT_TONES_NONE)
- printf("Detected at %5dHz %12" PRId32 " %12" PRId32 " %s (%d)\n", pitch, ans_pr_rx.channel_level, ans_pr_rx.notch_level, modem_connect_tone_to_str(hit), hit);
- /*endif*/
- }
- /*endfor*/
- if (false_hit || false_miss)
- {
- printf("Test failed.\n");
- exit(2);
- }
- /*endif*/
- printf("Test passed.\n");
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_2D))
- {
- printf("Test 2d: ANS/ (EC-disable) detection with frequency\n");
- tone_type = MODEM_CONNECT_TONES_ANS_PR;
- awgn_init_dbm0(&chan_noise_source, 7162534, -50.0f);
- false_hit = false;
- false_miss = false;
- for (pitch = 2100 - 100; pitch <= 2100 + 100; pitch++)
- {
- /* Use the transmitter to test the receiver */
- modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
- /* Fudge things for the test */
- modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
- modem_connect_tones_rx_init(&ans_pr_rx, tone_type, NULL, NULL);
- for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- for (j = 0; j < samples; j++)
- amp[j] += awgn(&chan_noise_source);
- /*endfor*/
- modem_connect_tones_rx(&ans_pr_rx, amp, samples);
- }
- /*endfor*/
- hit = modem_connect_tones_rx_get(&ans_pr_rx);
- if (pitch < (2100 - CNG_FREQ_BLACKOUT) || pitch > (2100 + CNG_FREQ_BLACKOUT))
- {
- if (hit != MODEM_CONNECT_TONES_NONE)
- false_hit = true;
- /*endif*/
- }
- else if (pitch > (2100 - CNG_FREQ_TOLERANCE) && pitch < (2100 + CNG_FREQ_TOLERANCE))
- {
- if (hit != tone_type)
- false_miss = true;
- /*endif*/
- }
- /*endif*/
- if (hit != MODEM_CONNECT_TONES_NONE)
- printf("Detected at %5dHz %12" PRId32 " %12" PRId32 " %s (%d)\n", pitch, ans_pr_rx.channel_level, ans_pr_rx.notch_level, modem_connect_tone_to_str(hit), hit);
- /*endif*/
- }
- /*endfor*/
- if (false_hit || false_miss)
- {
- printf("Test failed.\n");
- exit(2);
- }
- /*endif*/
- printf("Test passed.\n");
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_2E))
- {
- printf("Test 2e: ANSam/ (Modulated EC-disable) detection with frequency\n");
- tone_type = MODEM_CONNECT_TONES_ANSAM_PR;
- awgn_init_dbm0(&chan_noise_source, 7162534, -50.0f);
- false_hit = false;
- false_miss = false;
- for (pitch = 2100 - 100; pitch <= 2100 + 100; pitch++)
- {
- /* Use the transmitter to test the receiver */
- modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
- /* Fudge things for the test */
- modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
- modem_connect_tones_rx_init(&ans_pr_rx, tone_type, NULL, NULL);
- for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- for (j = 0; j < samples; j++)
- amp[j] += awgn(&chan_noise_source);
- /*endfor*/
- modem_connect_tones_rx(&ans_pr_rx, amp, samples);
- }
- /*endfor*/
- hit = modem_connect_tones_rx_get(&ans_pr_rx);
- if (pitch < (2100 - CNG_FREQ_BLACKOUT) || pitch > (2100 + CNG_FREQ_BLACKOUT))
- {
- if (hit != MODEM_CONNECT_TONES_NONE)
- false_hit = true;
- /*endif*/
- }
- else if (pitch > (2100 - CNG_FREQ_TOLERANCE) && pitch < (2100 + CNG_FREQ_TOLERANCE))
- {
- if (hit != tone_type)
- false_miss = true;
- /*endif*/
- }
- /*endif*/
- if (hit != MODEM_CONNECT_TONES_NONE)
- printf("Detected at %5dHz %12" PRId32 " %12" PRId32 " %s (%d)\n", pitch, ans_pr_rx.channel_level, ans_pr_rx.notch_level, modem_connect_tone_to_str(hit), hit);
- /*endif*/
- }
- /*endfor*/
- if (false_hit || false_miss)
- {
- printf("Test failed.\n");
- exit(2);
- }
- /*endif*/
- printf("Test passed.\n");
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_2F))
- {
- printf("Test 2f: Bell answer tone detection with frequency\n");
- tone_type = MODEM_CONNECT_TONES_BELL_ANS;
- awgn_init_dbm0(&chan_noise_source, 7162534, -50.0f);
- false_hit = false;
- false_miss = false;
- for (pitch = 2225 - 500; pitch <= 2225 + 500; pitch++)
- {
- /* Use the transmitter to test the receiver */
- modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
- /* Fudge things for the test */
- modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
- modem_connect_tones_rx_init(&bell_ans_rx, tone_type, NULL, NULL);
- level2 = 0;
- max_level2 = 0;
- for (i = 0; i < 8000; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- for (j = 0; j < samples; j++)
- {
- amp[j] += awgn(&chan_noise_source);
- level2 += ((abs(amp[j]) - level2) >> 5);
- if (level2 > max_level2)
- max_level2 = level2;
- }
- /*endfor*/
- modem_connect_tones_rx(&bell_ans_rx, amp, samples);
- }
- /*endfor*/
- hit = modem_connect_tones_rx_get(&bell_ans_rx);
- if (pitch < (2225 - BELL_ANS_FREQ_BLACKOUT) || pitch > (2225 + BELL_ANS_FREQ_BLACKOUT))
- {
- if (hit != MODEM_CONNECT_TONES_NONE)
- false_hit = true;
- /*endif*/
- }
- else if (pitch > (2225 - BELL_ANS_FREQ_TOLERANCE) && pitch < (2225 + BELL_ANS_FREQ_TOLERANCE))
- {
- if (hit != tone_type)
- false_miss = true;
- /*endif*/
- }
- /*endif*/
- if (hit != MODEM_CONNECT_TONES_NONE)
- printf("Detected at %5dHz %12" PRId32 " %12" PRId32 " %s (%d)\n", pitch, bell_ans_rx.channel_level, bell_ans_rx.notch_level, modem_connect_tone_to_str(hit), hit);
- /*endif*/
- }
- /*endfor*/
- if (false_hit || false_miss)
- {
- printf("Test failed.\n");
- exit(2);
- }
- /*endif*/
- printf("Test passed.\n");
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_2G))
- {
- printf("Test 2g: Calling tone detection with frequency\n");
- tone_type = MODEM_CONNECT_TONES_CALLING_TONE;
- awgn_init_dbm0(&chan_noise_source, 7162534, -50.0f);
- false_hit = false;
- false_miss = false;
- for (pitch = 1300 - 500; pitch <= 1300 + 500; pitch++)
- {
- /* Use the transmitter to test the receiver */
- modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
- /* Fudge things for the test */
- modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
- modem_connect_tones_rx_init(&calling_tone_rx, tone_type, NULL, NULL);
- level2 = 0;
- max_level2 = 0;
- for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- for (j = 0; j < samples; j++)
- {
- amp[j] += awgn(&chan_noise_source);
- level2 += ((abs(amp[j]) - level2) >> 5);
- if (level2 > max_level2)
- max_level2 = level2;
- }
- /*endfor*/
- modem_connect_tones_rx(&calling_tone_rx, amp, samples);
- }
- /*endfor*/
- hit = modem_connect_tones_rx_get(&calling_tone_rx);
- if (pitch < (1300 - CALLING_TONE_FREQ_BLACKOUT) || pitch > (1300 + CALLING_TONE_FREQ_BLACKOUT))
- {
- if (hit != MODEM_CONNECT_TONES_NONE)
- false_hit = true;
- /*endif*/
- }
- else if (pitch > (1300 - CALLING_TONE_FREQ_TOLERANCE) && pitch < (1300 + CALLING_TONE_FREQ_TOLERANCE))
- {
- if (hit != tone_type)
- false_miss = true;
- /*endif*/
- }
- /*endif*/
- if (hit != MODEM_CONNECT_TONES_NONE)
- printf("Detected at %5dHz %12" PRId32 " %12" PRId32 " %s (%d)\n", pitch, calling_tone_rx.channel_level, calling_tone_rx.notch_level, modem_connect_tone_to_str(hit), hit);
- /*endif*/
- }
- /*endfor*/
- if (false_hit || false_miss)
- {
- printf("Test failed.\n");
- exit(2);
- }
- /*endif*/
- printf("Test passed.\n");
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_3A))
- {
- printf("Test 3a: CNG detection with level\n");
- tone_type = MODEM_CONNECT_TONES_FAX_CNG;
- awgn_init_dbm0(&chan_noise_source, 7162534, -60.0f);
- false_hit = false;
- false_miss = false;
- for (pitch = 1100 - CED_FREQ_TOLERANCE; pitch <= 1100 + CED_FREQ_TOLERANCE; pitch += 2*CED_FREQ_TOLERANCE)
- {
- for (level = LEVEL_MAX; level >= LEVEL_MIN; level--)
- {
- /* Use the transmitter to test the receiver */
- modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
- /* Fudge things for the test */
- modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
- modem_tone_tx.level = dds_scaling_dbm0(level);
- modem_connect_tones_rx_init(&cng_rx, tone_type, NULL, NULL);
- for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- for (j = 0; j < samples; j++)
- amp[j] += awgn(&chan_noise_source);
- /*endfor*/
- modem_connect_tones_rx(&cng_rx, amp, samples);
- }
- /*endfor*/
- hit = modem_connect_tones_rx_get(&cng_rx);
- if (level < LEVEL_MIN_REJECT)
- {
- if (hit != MODEM_CONNECT_TONES_NONE)
- false_hit = true;
- /*endif*/
- }
- else if (level > LEVEL_MIN_ACCEPT)
- {
- if (hit != tone_type)
- false_miss = true;
- /*endif*/
- }
- /*endif*/
- if (hit != MODEM_CONNECT_TONES_NONE)
- printf("Detected at %5dHz %4ddB %12" PRId32 " %12" PRId32 " %s (%d)\n", pitch, level, cng_rx.channel_level, cng_rx.notch_level, modem_connect_tone_to_str(hit), hit);
- /*endif*/
- }
- /*endfor*/
- }
- /*endfor*/
- if (false_hit || false_miss)
- {
- printf("Test failed.\n");
- exit(2);
- }
- /*endif*/
- printf("Test passed.\n");
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_3B))
- {
- printf("Test 3b: CED/ANS detection with level\n");
- tone_type = MODEM_CONNECT_TONES_ANS;
- awgn_init_dbm0(&chan_noise_source, 7162534, -60.0f);
- false_hit = false;
- false_miss = false;
- for (pitch = 2100 - CNG_FREQ_TOLERANCE; pitch <= 2100 + CNG_FREQ_TOLERANCE; pitch += 2*CNG_FREQ_TOLERANCE)
- {
- for (level = LEVEL_MAX; level >= LEVEL_MIN; level--)
- {
- /* Use the transmitter to test the receiver */
- modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
- /* Fudge things for the test */
- modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
- modem_tone_tx.level = dds_scaling_dbm0(level);
- modem_connect_tones_rx_init(&ced_rx, MODEM_CONNECT_TONES_FAX_CED_OR_PREAMBLE, NULL, NULL);
- for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- for (j = 0; j < samples; j++)
- amp[j] += awgn(&chan_noise_source);
- /*endfor*/
- modem_connect_tones_rx(&ced_rx, amp, samples);
- }
- /*endfor*/
- hit = modem_connect_tones_rx_get(&ced_rx);
- if (level < LEVEL_MIN_REJECT)
- {
- if (hit != MODEM_CONNECT_TONES_NONE)
- false_hit = true;
- /*endif*/
- }
- else if (level > LEVEL_MIN_ACCEPT)
- {
- if (hit != tone_type)
- false_miss = true;
- /*endif*/
- }
- /*endif*/
- if (hit != MODEM_CONNECT_TONES_NONE)
- printf("Detected at %5dHz %4ddB %12" PRId32 " %12" PRId32 " %s (%d)\n", pitch, level, ced_rx.channel_level, ced_rx.notch_level, modem_connect_tone_to_str(hit), hit);
- /*endif*/
- }
- /*endfor*/
- }
- /*endfor*/
- if (false_hit || false_miss)
- {
- printf("Test failed.\n");
- exit(2);
- }
- /*endif*/
- printf("Test passed.\n");
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_3C))
- {
- printf("Test 3c: ANSam detection with level\n");
- tone_type = MODEM_CONNECT_TONES_ANSAM;
- awgn_init_dbm0(&chan_noise_source, 7162534, -60.0f);
- false_hit = false;
- false_miss = false;
- for (pitch = 2100 - CNG_FREQ_TOLERANCE; pitch <= 2100 + CNG_FREQ_TOLERANCE; pitch += 2*CNG_FREQ_TOLERANCE)
- {
- //for (level = LEVEL_MAX; level >= LEVEL_MIN; level--)
- for (level = -26; level >= -26; level--)
- {
- /* Use the transmitter to test the receiver */
- modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
- /* Fudge things for the test */
- modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
- modem_tone_tx.level = dds_scaling_dbm0(level);
- modem_tone_tx.mod_level = modem_tone_tx.level*20/100;
- modem_connect_tones_rx_init(&ans_pr_rx, tone_type, NULL, NULL);
- for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- for (j = 0; j < samples; j++)
- amp[j] += awgn(&chan_noise_source);
- /*endfor*/
- modem_connect_tones_rx(&ans_pr_rx, amp, samples);
- }
- /*endfor*/
- hit = modem_connect_tones_rx_get(&ans_pr_rx);
- if (level < LEVEL_MIN_REJECT)
- {
- if (hit != MODEM_CONNECT_TONES_NONE)
- false_hit = true;
- /*endif*/
- }
- else if (level > LEVEL_MIN_ACCEPT)
- {
- if (hit != tone_type)
- false_miss = true;
- /*endif*/
- }
- /*endif*/
- if (hit != MODEM_CONNECT_TONES_NONE)
- printf("Detected at %5dHz %4ddB %12" PRId32 " %12" PRId32 " %s (%d)\n", pitch, level, ans_pr_rx.channel_level, ans_pr_rx.notch_level, modem_connect_tone_to_str(hit), hit);
- /*endif*/
- }
- /*endfor*/
- }
- /*endfor*/
- if (false_hit || false_miss)
- {
- printf("Test failed.\n");
- exit(2);
- }
- /*endif*/
- printf("Test passed.\n");
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_3D))
- {
- printf("Test 3d: ANS/ (EC-disable) detection with level\n");
- tone_type = MODEM_CONNECT_TONES_ANS_PR;
- awgn_init_dbm0(&chan_noise_source, 7162534, -60.0f);
- false_hit = false;
- false_miss = false;
- for (pitch = 2100 - CNG_FREQ_TOLERANCE; pitch <= 2100 + CNG_FREQ_TOLERANCE; pitch += 2*CNG_FREQ_TOLERANCE)
- {
- for (level = LEVEL_MAX; level >= LEVEL_MIN; level--)
- {
- /* Use the transmitter to test the receiver */
- modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
- /* Fudge things for the test */
- modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
- modem_tone_tx.level = dds_scaling_dbm0(level);
- modem_connect_tones_rx_init(&ans_pr_rx, tone_type, NULL, NULL);
- for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- for (j = 0; j < samples; j++)
- amp[j] += awgn(&chan_noise_source);
- /*endfor*/
- modem_connect_tones_rx(&ans_pr_rx, amp, samples);
- }
- /*endfor*/
- hit = modem_connect_tones_rx_get(&ans_pr_rx);
- if (level < LEVEL_MIN_REJECT)
- {
- if (hit != MODEM_CONNECT_TONES_NONE)
- false_hit = true;
- /*endif*/
- }
- else if (level > LEVEL_MIN_ACCEPT)
- {
- if (hit != tone_type)
- false_miss = true;
- /*endif*/
- }
- /*endif*/
- if (hit != MODEM_CONNECT_TONES_NONE)
- printf("Detected at %5dHz %4ddB %12" PRId32 " %12" PRId32 " %s (%d)\n", pitch, level, ans_pr_rx.channel_level, ans_pr_rx.notch_level, modem_connect_tone_to_str(hit), hit);
- /*endif*/
- }
- /*endfor*/
- }
- /*endfor*/
- if (false_hit || false_miss)
- {
- printf("Test failed.\n");
- exit(2);
- }
- /*endif*/
- printf("Test passed.\n");
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_3E))
- {
- printf("Test 3e: ANSam/ (Modulated EC-disable) detection with level\n");
- tone_type = MODEM_CONNECT_TONES_ANSAM_PR;
- awgn_init_dbm0(&chan_noise_source, 7162534, -60.0f);
- false_hit = false;
- false_miss = false;
- for (pitch = 2100 - CNG_FREQ_TOLERANCE; pitch <= 2100 + CNG_FREQ_TOLERANCE; pitch += 2*CNG_FREQ_TOLERANCE)
- {
- for (level = LEVEL_MAX; level >= LEVEL_MIN; level--)
- {
- /* Use the transmitter to test the receiver */
- modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
- /* Fudge things for the test */
- modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
- modem_tone_tx.level = dds_scaling_dbm0(level);
- modem_tone_tx.mod_level = modem_tone_tx.level*20/100;
- modem_connect_tones_rx_init(&ans_pr_rx, tone_type, NULL, NULL);
- for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- for (j = 0; j < samples; j++)
- amp[j] += awgn(&chan_noise_source);
- /*endfor*/
- modem_connect_tones_rx(&ans_pr_rx, amp, samples);
- }
- /*endfor*/
- hit = modem_connect_tones_rx_get(&ans_pr_rx);
- if (level < LEVEL_MIN_REJECT)
- {
- if (hit != MODEM_CONNECT_TONES_NONE)
- false_hit = true;
- /*endif*/
- }
- else if (level > LEVEL_MIN_ACCEPT)
- {
- if (hit != tone_type)
- false_miss = true;
- /*endif*/
- }
- /*endif*/
- if (hit != MODEM_CONNECT_TONES_NONE)
- printf("Detected at %5dHz %4ddB %12" PRId32 " %12" PRId32 " %s (%d)\n", pitch, level, ans_pr_rx.channel_level, ans_pr_rx.notch_level, modem_connect_tone_to_str(hit), hit);
- /*endif*/
- }
- /*endfor*/
- }
- /*endfor*/
- if (false_hit || false_miss)
- {
- printf("Test failed.\n");
- exit(2);
- }
- /*endif*/
- printf("Test passed.\n");
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_3F))
- {
- printf("Test 3f: Bell answer tone detection with level\n");
- tone_type = MODEM_CONNECT_TONES_BELL_ANS;
- awgn_init_dbm0(&chan_noise_source, 7162534, -60.0f);
- false_hit = false;
- false_miss = false;
- for (pitch = 2225 - BELL_ANS_FREQ_TOLERANCE; pitch <= 2225 + BELL_ANS_FREQ_TOLERANCE; pitch += 2*BELL_ANS_FREQ_TOLERANCE)
- {
- for (level = LEVEL_MAX; level >= LEVEL_MIN; level--)
- {
- /* Use the transmitter to test the receiver */
- modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
- /* Fudge things for the test */
- modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
- modem_tone_tx.level = dds_scaling_dbm0(level);
- modem_connect_tones_rx_init(&calling_tone_rx, tone_type, NULL, NULL);
- for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- for (j = 0; j < samples; j++)
- amp[j] += awgn(&chan_noise_source);
- /*endfor*/
- modem_connect_tones_rx(&calling_tone_rx, amp, samples);
- }
- /*endfor*/
- hit = modem_connect_tones_rx_get(&calling_tone_rx);
- if (level < LEVEL_MIN_REJECT)
- {
- if (hit != MODEM_CONNECT_TONES_NONE)
- false_hit = true;
- /*endif*/
- }
- else if (level > LEVEL_MIN_ACCEPT)
- {
- if (hit != tone_type)
- false_miss = true;
- /*endif*/
- }
- /*endif*/
- if (hit != MODEM_CONNECT_TONES_NONE)
- printf("Detected at %5dHz %4ddB %12" PRId32 " %12" PRId32 " %s (%d)\n", pitch, level, calling_tone_rx.channel_level, calling_tone_rx.notch_level, modem_connect_tone_to_str(hit), hit);
- /*endif*/
- }
- /*endfor*/
- }
- /*endfor*/
- if (false_hit || false_miss)
- {
- printf("Test failed.\n");
- exit(2);
- }
- /*endif*/
- printf("Test passed.\n");
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_3G))
- {
- printf("Test 3g: Calling tone detection with level\n");
- tone_type = MODEM_CONNECT_TONES_CALLING_TONE;
- awgn_init_dbm0(&chan_noise_source, 7162534, -60.0f);
- false_hit = false;
- false_miss = false;
- for (pitch = 1300 - CALLING_TONE_FREQ_TOLERANCE; pitch <= 1300 + CALLING_TONE_FREQ_TOLERANCE; pitch += 2*CALLING_TONE_FREQ_TOLERANCE)
- {
- for (level = LEVEL_MAX; level >= LEVEL_MIN; level--)
- {
- /* Use the transmitter to test the receiver */
- modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
- /* Fudge things for the test */
- modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
- modem_tone_tx.level = dds_scaling_dbm0(level);
- modem_connect_tones_rx_init(&calling_tone_rx, tone_type, NULL, NULL);
- for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- for (j = 0; j < samples; j++)
- amp[j] += awgn(&chan_noise_source);
- /*endfor*/
- modem_connect_tones_rx(&calling_tone_rx, amp, samples);
- }
- /*endfor*/
- hit = modem_connect_tones_rx_get(&calling_tone_rx);
- if (level < LEVEL_MIN_REJECT)
- {
- if (hit != MODEM_CONNECT_TONES_NONE)
- false_hit = true;
- /*endif*/
- }
- else if (level > LEVEL_MIN_ACCEPT)
- {
- if (hit != tone_type)
- false_miss = true;
- /*endif*/
- }
- /*endif*/
- if (hit != MODEM_CONNECT_TONES_NONE)
- printf("Detected at %5dHz %4ddB %12" PRId32 " %12" PRId32 " %s (%d)\n", pitch, level, calling_tone_rx.channel_level, calling_tone_rx.notch_level, modem_connect_tone_to_str(hit), hit);
- /*endif*/
- }
- /*endfor*/
- }
- /*endfor*/
- if (false_hit || false_miss)
- {
- printf("Test failed.\n");
- exit(2);
- }
- /*endif*/
- printf("Test passed.\n");
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_4))
- {
- printf("Test 4: CED detection, when stimulated with V.21 preamble\n");
- false_hit = false;
- false_miss = false;
- /* Send 255 bits of preamble (0.85s, the minimum specified preamble for T.30), and then
- some random bits. Check the preamble detector comes on, and goes off at reasonable times. */
- fsk_tx_init(&preamble_tx, &preset_fsk_specs[FSK_V21CH2], preamble_get_bit, NULL);
- modem_connect_tones_rx_init(&ced_rx, MODEM_CONNECT_TONES_FAX_CED_OR_PREAMBLE, preamble_detected, NULL);
- for (i = 0; i < 2*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = fsk_tx(&preamble_tx, amp, SAMPLES_PER_CHUNK);
- modem_connect_tones_rx(&ced_rx, amp, samples);
- }
- /*endfor*/
- for (i = 0; i < SAMPLE_RATE/10; i += SAMPLES_PER_CHUNK)
- {
- memset(amp, 0, sizeof(int16_t)*SAMPLES_PER_CHUNK);
- modem_connect_tones_rx(&ced_rx, amp, SAMPLES_PER_CHUNK);
- }
- /*endfor*/
- if (preamble_on_at < 40 || preamble_on_at > 50
- ||
- preamble_off_at < 580 || preamble_off_at > 620)
- {
- printf("Test failed.\n");
- exit(2);
- }
- /*endif*/
- printf("Test passed.\n");
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_5A))
- {
- printf("Test 5A: ANS and ANS/ detection with reversal interval\n");
- tone_type = MODEM_CONNECT_TONES_ANS_PR;
- awgn_init_dbm0(&chan_noise_source, 7162534, -60.0f);
- false_hit = false;
- false_miss = false;
- for (interval = 400; interval < 800; interval++)
- {
- printf("Reversal interval = %d\n", interval);
- /* Use the transmitter to test the receiver */
- modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
- modem_connect_tones_rx_init(&ans_pr_rx, tone_type, ans_pr_detected, NULL);
- hits = 0;
- for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- when = i;
- samples = SAMPLES_PER_CHUNK;
- for (j = 0; j < samples; j++)
- {
- if (--modem_tone_tx.hop_timer <= 0)
- {
- modem_tone_tx.hop_timer = ms_to_samples(interval);
- modem_tone_tx.tone_phase += 0x80000000;
- }
- /*endif*/
- amp[j] = dds_mod(&modem_tone_tx.tone_phase, modem_tone_tx.tone_phase_rate, modem_tone_tx.level, 0);
- }
- for (j = 0; j < samples; j++)
- amp[j] += awgn(&chan_noise_source);
- /*endfor*/
- modem_connect_tones_rx(&ans_pr_rx, amp, samples);
- }
- /*endfor*/
- if (interval < (450 - 25) || interval > (450 + 25))
- {
- if (hits != 0)
- false_hit = true;
- /*endif*/
- }
- else if (interval > (450 - 25) && interval < (450 + 25))
- {
- if (hits == 0)
- false_miss = true;
- /*endif*/
- }
- /*endif*/
- if (hits)
- printf("Detected at %5dHz %4ddB %dms %12" PRId32 " %12" PRId32 " %d\n", 2100, -11, interval, ans_pr_rx.channel_level, ans_pr_rx.notch_level, hits);
- /*endif*/
- }
- /*endfor*/
- if (false_hit || false_miss)
- {
- printf("Test failed.\n");
- exit(2);
- }
- /*endif*/
- printf("Test passed.\n");
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_5B))
- {
- printf("Test 5B: ANS and ANS/ detection with mixed reversal intervals\n");
- awgn_init_dbm0(&chan_noise_source, 7162534, -60.0f);
- tone_type = MODEM_CONNECT_TONES_ANS_PR;
- false_hit = false;
- false_miss = false;
- interval = 450;
- printf("Reversal interval = %d\n", interval);
- /* Use the transmitter to test the receiver */
- modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
- modem_connect_tones_rx_init(&ans_pr_rx, tone_type, ans_pr_detected, NULL);
- cycle = 0;
- hits = 0;
- for (i = 0; i < 60*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- when = i;
- samples = SAMPLES_PER_CHUNK;
- for (j = 0; j < samples; j++)
- {
- if (--modem_tone_tx.hop_timer <= 0)
- {
- if (++cycle == 10)
- interval = 1000;
- if (cycle == 20)
- interval = 450;
- modem_tone_tx.hop_timer = ms_to_samples(interval);
- modem_tone_tx.tone_phase += 0x80000000;
- }
- amp[j] = dds_mod(&modem_tone_tx.tone_phase, modem_tone_tx.tone_phase_rate, modem_tone_tx.level, 0);
- }
- /*endfor*/
- for (j = 0; j < samples; j++)
- amp[j] += awgn(&chan_noise_source);
- /*endfor*/
- modem_connect_tones_rx(&ans_pr_rx, amp, samples);
- /* TODO: Add test result detection logic. */
- }
- /*endfor*/
- if (false_hit || false_miss)
- {
- printf("Test failed.\n");
- exit(2);
- }
- /*endif*/
- printf("Test passed.\n");
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_6A))
- {
- printf("Test 6a: ANSam detection with AM pitch\n");
- tone_type = MODEM_CONNECT_TONES_ANSAM;
- awgn_init_dbm0(&chan_noise_source, 7162534, -50.0f);
- false_hit = false;
- false_miss = false;
- for (pitch = 5; pitch < 25; pitch++)
- {
- /* Use the transmitter to test the receiver */
- modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
- /* Fudge things for the test */
- modem_tone_tx.mod_phase_rate = dds_phase_rate(pitch);
- modem_connect_tones_rx_init(&ans_pr_rx, tone_type, NULL, NULL);
- for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- for (j = 0; j < samples; j++)
- amp[j] += awgn(&chan_noise_source);
- /*endfor*/
- modem_connect_tones_rx(&ans_pr_rx, amp, samples);
- }
- /*endfor*/
- hit = modem_connect_tones_rx_get(&ans_pr_rx);
- if (pitch < (15 - 10) || pitch > (15 + 10))
- {
- if (hit == tone_type)
- false_hit = true;
- /*endif*/
- }
- else if (pitch > (15 - AM_FREQ_TOLERANCE) && pitch < (15 + AM_FREQ_TOLERANCE))
- {
- if (hit != tone_type)
- false_miss = true;
- /*endif*/
- }
- /*endif*/
- if (hit != MODEM_CONNECT_TONES_NONE)
- printf("Detected at %5dHz %12" PRId32 " %12" PRId32 " %s (%d)\n", pitch, ans_pr_rx.channel_level, ans_pr_rx.notch_level, modem_connect_tone_to_str(hit), hit);
- /*endif*/
- }
- /*endfor*/
- if (false_hit || false_miss)
- {
- printf("Test failed.\n");
- exit(2);
- }
- /*endif*/
- printf("Test passed.\n");
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_6B))
- {
- printf("Test 6b: ANSam/ (Modulated EC-disable) detection with AM pitch\n");
- tone_type = MODEM_CONNECT_TONES_ANSAM_PR;
- awgn_init_dbm0(&chan_noise_source, 7162534, -50.0f);
- false_hit = false;
- false_miss = false;
- for (pitch = 5; pitch < 25; pitch++)
- {
- /* Use the transmitter to test the receiver */
- modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
- /* Fudge things for the test */
- modem_tone_tx.mod_phase_rate = dds_phase_rate(pitch);
- modem_connect_tones_rx_init(&ans_pr_rx, tone_type, NULL, NULL);
- for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- for (j = 0; j < samples; j++)
- amp[j] += awgn(&chan_noise_source);
- /*endfor*/
- modem_connect_tones_rx(&ans_pr_rx, amp, samples);
- }
- /*endfor*/
- hit = modem_connect_tones_rx_get(&ans_pr_rx);
- if (pitch < (15 - 10) || pitch > (15 + 10))
- {
- if (hit == tone_type)
- false_hit = true;
- /*endif*/
- }
- else if (pitch > (15 - AM_FREQ_TOLERANCE) && pitch < (15 + AM_FREQ_TOLERANCE))
- {
- if (hit != tone_type)
- false_miss = true;
- /*endif*/
- }
- /*endif*/
- if (hit != MODEM_CONNECT_TONES_NONE)
- printf("Detected at %5dHz %12" PRId32 " %12" PRId32 " %s (%d)\n", pitch, ans_pr_rx.channel_level, ans_pr_rx.notch_level, modem_connect_tone_to_str(hit), hit);
- /*endif*/
- }
- /*endfor*/
- if (false_hit || false_miss)
- {
- printf("Test failed.\n");
- exit(2);
- }
- /*endif*/
- printf("Test passed.\n");
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_7A))
- {
- printf("Test 7a: ANSam detection with AM depth\n");
- tone_type = MODEM_CONNECT_TONES_ANSAM;
- pitch = 2100;
- awgn_init_dbm0(&chan_noise_source, 7162534, -50.0f);
- false_hit = false;
- false_miss = false;
- for (depth = 0; depth < 40; depth++)
- {
- /* Use the transmitter to test the receiver */
- modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
- /* Fudge things for the test */
- modem_tone_tx.mod_level = modem_tone_tx.level*depth/100;
- modem_connect_tones_rx_init(&ans_pr_rx, tone_type, NULL, NULL);
- for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- for (j = 0; j < samples; j++)
- amp[j] += awgn(&chan_noise_source);
- /*endfor*/
- modem_connect_tones_rx(&ans_pr_rx, amp, samples);
- }
- /*endfor*/
- hit = modem_connect_tones_rx_get(&ans_pr_rx);
- if (depth < 10)
- {
- if (hit == tone_type)
- false_hit = true;
- /*endif*/
- }
- else if (depth > 15)
- {
- if (hit != tone_type)
- false_miss = true;
- /*endif*/
- }
- /*endif*/
- if (hit != MODEM_CONNECT_TONES_NONE)
- printf("Detected at %5dHz %12" PRId32 " %12" PRId32 " %s (%d)\n", pitch, ans_pr_rx.channel_level, ans_pr_rx.notch_level, modem_connect_tone_to_str(hit), hit);
- /*endif*/
- }
- /*endfor*/
- if (false_hit || false_miss)
- {
- printf("Test failed.\n");
- exit(2);
- }
- /*endif*/
- printf("Test passed.\n");
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_7B))
- {
- printf("Test 7b: ANSam/ (Modulated EC-disable) detection with AM depth\n");
- tone_type = MODEM_CONNECT_TONES_ANSAM_PR;
- pitch = 2100;
- awgn_init_dbm0(&chan_noise_source, 7162534, -50.0f);
- false_hit = false;
- false_miss = false;
- for (depth = 0; depth < 40; depth++)
- {
- /* Use the transmitter to test the receiver */
- modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
- /* Fudge things for the test */
- modem_tone_tx.mod_level = modem_tone_tx.level*depth/100;
- modem_connect_tones_rx_init(&ans_pr_rx, tone_type, NULL, NULL);
- for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
- {
- samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
- for (j = 0; j < samples; j++)
- amp[j] += awgn(&chan_noise_source);
- /*endfor*/
- modem_connect_tones_rx(&ans_pr_rx, amp, samples);
- }
- /*endfor*/
- hit = modem_connect_tones_rx_get(&ans_pr_rx);
- if (depth < 10)
- {
- if (hit == tone_type)
- false_hit = true;
- /*endif*/
- }
- else if (depth > 15)
- {
- if (hit != tone_type)
- false_miss = true;
- /*endif*/
- }
- /*endif*/
- if (hit != MODEM_CONNECT_TONES_NONE)
- printf("Detected at %5dHz %12" PRId32 " %12" PRId32 " %s (%d)\n", pitch, ans_pr_rx.channel_level, ans_pr_rx.notch_level, modem_connect_tone_to_str(hit), hit);
- /*endif*/
- }
- /*endfor*/
- if (false_hit || false_miss)
- {
- printf("Test failed.\n");
- exit(2);
- }
- /*endif*/
- printf("Test passed.\n");
- }
- /*endif*/
- if ((test_list & PERFORM_TEST_8))
- {
- /* Talk-off test */
- /* Here we use the BellCore and Mitel talk off test tapes, intended for DTMF
- detector testing. Presumably they should also have value here, but I am not
- sure. If those voice snippets were chosen to be tough on DTMF detectors, they
- might go easy on detectors looking for different pitches. However, the
- Mitel DTMF test tape is known (the hard way) to exercise 2280Hz tone
- detectors quite well. */
- printf("Test 8: Talk-off test\n");
- modem_connect_tones_rx_init(&cng_rx, MODEM_CONNECT_TONES_FAX_CNG, NULL, NULL);
- modem_connect_tones_rx_init(&ced_rx, MODEM_CONNECT_TONES_FAX_CED_OR_PREAMBLE, NULL, NULL);
- modem_connect_tones_rx_init(&ans_pr_rx, MODEM_CONNECT_TONES_ANS_PR, NULL, NULL);
- modem_connect_tones_rx_init(&bell_ans_rx, MODEM_CONNECT_TONES_BELL_ANS, NULL, NULL);
- modem_connect_tones_rx_init(&calling_tone_rx, MODEM_CONNECT_TONES_CALLING_TONE, NULL, NULL);
- for (j = 0; bellcore_files[j][0]; j++)
- {
- if ((inhandle = sf_open_telephony_read(bellcore_files[j], 1)) == NULL)
- {
- fprintf(stderr, " Cannot open speech file '%s'\n", bellcore_files[j]);
- exit (2);
- }
- /*endif*/
- when = 0;
- hits = 0;
- while ((frames = sf_readf_short(inhandle, amp, 8000)))
- {
- when++;
- modem_connect_tones_rx(&cng_rx, amp, frames);
- modem_connect_tones_rx(&ced_rx, amp, frames);
- modem_connect_tones_rx(&ans_pr_rx, amp, frames);
- modem_connect_tones_rx(&bell_ans_rx, amp, frames);
- modem_connect_tones_rx(&calling_tone_rx, amp, frames);
- if (modem_connect_tones_rx_get(&cng_rx) != MODEM_CONNECT_TONES_NONE)
- {
- /* This is not a true measure of hits, as there might be more
- than one in a block of data. However, since the only good
- result is no hits, this approximation is OK. */
- printf("Hit CNG at %ds\n", when);
- hits++;
- modem_connect_tones_rx_init(&cng_rx, MODEM_CONNECT_TONES_FAX_CNG, NULL, NULL);
- }
- /*endif*/
- if (modem_connect_tones_rx_get(&ced_rx) != MODEM_CONNECT_TONES_NONE)
- {
- printf("Hit CED at %ds\n", when);
- hits++;
- modem_connect_tones_rx_init(&ced_rx, MODEM_CONNECT_TONES_FAX_CED_OR_PREAMBLE, NULL, NULL);
- }
- /*endif*/
- if (modem_connect_tones_rx_get(&ans_pr_rx) != MODEM_CONNECT_TONES_NONE)
- {
- printf("Hit EC disable at %ds\n", when);
- hits++;
- modem_connect_tones_rx_init(&ans_pr_rx, MODEM_CONNECT_TONES_ANS_PR, NULL, NULL);
- }
- /*endif*/
- if (modem_connect_tones_rx_get(&bell_ans_rx) != MODEM_CONNECT_TONES_NONE)
- {
- printf("Hit calling tone at %ds\n", when);
- hits++;
- modem_connect_tones_rx_init(&bell_ans_rx, MODEM_CONNECT_TONES_BELL_ANS, NULL, NULL);
- }
- /*endif*/
- if (modem_connect_tones_rx_get(&calling_tone_rx) != MODEM_CONNECT_TONES_NONE)
- {
- printf("Hit calling tone at %ds\n", when);
- hits++;
- modem_connect_tones_rx_init(&calling_tone_rx, MODEM_CONNECT_TONES_CALLING_TONE, NULL, NULL);
- }
- /*endif*/
- }
- /*endwhile*/
- if (sf_close_telephony(inhandle))
- {
- fprintf(stderr, " Cannot close speech file '%s'\n", bellcore_files[j]);
- exit(2);
- }
- /*endif*/
- printf(" File %d gave %d false hits.\n", j + 1, hits);
- }
- /*endfor*/
- if (hits > 0)
- {
- printf("Test failed.\n");
- exit(2);
- }
- /*endif*/
- printf("Test passed.\n");
- }
- /*endif*/
- if (decode_test_file)
- {
- printf("Decode file '%s'\n", decode_test_file);
- modem_connect_tones_rx_init(&cng_rx, MODEM_CONNECT_TONES_FAX_CNG, cng_detected, NULL);
- modem_connect_tones_rx_init(&ced_rx, MODEM_CONNECT_TONES_FAX_CED_OR_PREAMBLE, ced_detected, NULL);
- modem_connect_tones_rx_init(&ans_pr_rx, MODEM_CONNECT_TONES_ANS_PR, ans_pr_detected, NULL);
- modem_connect_tones_rx_init(&bell_ans_rx, MODEM_CONNECT_TONES_BELL_ANS, bell_ans_detected, NULL);
- modem_connect_tones_rx_init(&calling_tone_rx, MODEM_CONNECT_TONES_CALLING_TONE, calling_tone_detected, NULL);
- hits = 0;
- if ((inhandle = sf_open_telephony_read(decode_test_file, 1)) == NULL)
- {
- fprintf(stderr, " Cannot open speech file '%s'\n", decode_test_file);
- exit (2);
- }
- /*endif*/
- when = 0;
- hits = 0;
- while ((frames = sf_readf_short(inhandle, amp, 8000)))
- {
- when++;
- modem_connect_tones_rx(&cng_rx, amp, frames);
- modem_connect_tones_rx(&ced_rx, amp, frames);
- modem_connect_tones_rx(&ans_pr_rx, amp, frames);
- modem_connect_tones_rx(&bell_ans_rx, amp, frames);
- modem_connect_tones_rx(&calling_tone_rx, amp, frames);
- }
- /*endwhile*/
- if (sf_close_telephony(inhandle))
- {
- fprintf(stderr, " Cannot close speech file '%s'\n", decode_test_file);
- exit(2);
- }
- /*endif*/
- printf(" File gave %d hits.\n", hits);
- }
- printf("Tests passed.\n");
- return 0;
- }
- /*- End of function --------------------------------------------------------*/
- /*- End of file ------------------------------------------------------------*/
|