modem_connect_tones_tests.c 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748
  1. /*
  2. * SpanDSP - a series of DSP components for telephony
  3. *
  4. * modem_connect_tones_tests.c
  5. *
  6. * Written by Steve Underwood <steveu@coppice.org>
  7. *
  8. * Copyright (C) 2006 Steve Underwood
  9. *
  10. * All rights reserved.
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2, as
  14. * published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. /*! \page modem_connect_tones_tests_page Modem connect tones tests
  26. \section modem_connect_tones_rx_tests_page_sec_1 What does it do?
  27. These tests...
  28. */
  29. #if defined(HAVE_CONFIG_H)
  30. #include "config.h"
  31. #endif
  32. #include <stdlib.h>
  33. #include <stdio.h>
  34. #include <fcntl.h>
  35. #include <unistd.h>
  36. #include <string.h>
  37. #include <sndfile.h>
  38. #include "spandsp.h"
  39. #include "spandsp-sim.h"
  40. #define SAMPLES_PER_CHUNK 160
  41. #define OUTPUT_FILE_NAME "modem_connect_tones.wav"
  42. #define MITEL_DIR "../test-data/mitel/"
  43. #define BELLCORE_DIR "../test-data/bellcore/"
  44. #define LEVEL_MAX -5
  45. #define LEVEL_MIN -48
  46. #define LEVEL_MIN_ACCEPT -43
  47. #define LEVEL_MIN_REJECT -44
  48. /* The 1100Hz tone is supposed to be within 38Hz, according to T.30. Allow another 8Hz for FDM, even though
  49. you rarely see that used today. */
  50. #define CED_FREQ_TOLERANCE (38 + 8)
  51. #define CED_FREQ_BLACKOUT (80)
  52. /* The 2100Hz tone is supposed to be within 15Hz, according to T.30. Allow another 8Hz for FDM, even though
  53. you rarely see that used today. */
  54. #define CNG_FREQ_TOLERANCE (15 + 8)
  55. #define CNG_FREQ_BLACKOUT (80)
  56. #define AM_FREQ_TOLERANCE (1)
  57. /* The 2225Hz tone is supposed to be within 15Hz. Allow another 8Hz for FDM, even though
  58. you rarely see that used today. */
  59. #define BELL_ANS_FREQ_TOLERANCE (15 + 8)
  60. #define BELL_ANS_FREQ_BLACKOUT (80)
  61. /* The 1300Hz tone is supposed to be within 15Hz, according to V.25. Allow another 8Hz for FDM, even though
  62. you rarely see that used today. */
  63. #define CALLING_TONE_FREQ_TOLERANCE (15 + 8)
  64. #define CALLING_TONE_FREQ_BLACKOUT (80)
  65. const char *bellcore_files[] =
  66. {
  67. MITEL_DIR "mitel-cm7291-talkoff.wav",
  68. BELLCORE_DIR "tr-tsy-00763-1.wav",
  69. BELLCORE_DIR "tr-tsy-00763-2.wav",
  70. BELLCORE_DIR "tr-tsy-00763-3.wav",
  71. BELLCORE_DIR "tr-tsy-00763-4.wav",
  72. BELLCORE_DIR "tr-tsy-00763-5.wav",
  73. BELLCORE_DIR "tr-tsy-00763-6.wav",
  74. ""
  75. };
  76. enum
  77. {
  78. PERFORM_TEST_1A = (1 << 1),
  79. PERFORM_TEST_1B = (1 << 2),
  80. PERFORM_TEST_1C = (1 << 3),
  81. PERFORM_TEST_1D = (1 << 4),
  82. PERFORM_TEST_1E = (1 << 5),
  83. PERFORM_TEST_1F = (1 << 6),
  84. PERFORM_TEST_1G = (1 << 7),
  85. PERFORM_TEST_2A = (1 << 8),
  86. PERFORM_TEST_2B = (1 << 9),
  87. PERFORM_TEST_2C = (1 << 10),
  88. PERFORM_TEST_2D = (1 << 11),
  89. PERFORM_TEST_2E = (1 << 12),
  90. PERFORM_TEST_2F = (1 << 13),
  91. PERFORM_TEST_2G = (1 << 14),
  92. PERFORM_TEST_3A = (1 << 15),
  93. PERFORM_TEST_3B = (1 << 16),
  94. PERFORM_TEST_3C = (1 << 17),
  95. PERFORM_TEST_3D = (1 << 18),
  96. PERFORM_TEST_3E = (1 << 19),
  97. PERFORM_TEST_3F = (1 << 20),
  98. PERFORM_TEST_3G = (1 << 21),
  99. PERFORM_TEST_4 = (1 << 22),
  100. PERFORM_TEST_5A = (1 << 23),
  101. PERFORM_TEST_5B = (1 << 24),
  102. PERFORM_TEST_6A = (1 << 25),
  103. PERFORM_TEST_6B = (1 << 26),
  104. PERFORM_TEST_7A = (1 << 27),
  105. PERFORM_TEST_7B = (1 << 28),
  106. PERFORM_TEST_8 = (1 << 29)
  107. };
  108. int preamble_count = 0;
  109. int preamble_on_at = -1;
  110. int preamble_off_at = -1;
  111. int hits = 0;
  112. int when = 0;
  113. static int preamble_get_bit(void *user_data)
  114. {
  115. static int bit_no = 0;
  116. int bit;
  117. /* Generate a section of HDLC flag octet preamble. Then generate some random
  118. bits, which should not look like preamble. */
  119. if (++preamble_count < 255)
  120. {
  121. bit = (bit_no < 2) ? 0 : 1;
  122. if (++bit_no >= 8)
  123. bit_no = 0;
  124. #if 0
  125. /* Inject some bad bits */
  126. if (rand()%15 == 0)
  127. return bit ^ 1;
  128. #endif
  129. }
  130. else
  131. {
  132. bit = rand() & 1;
  133. }
  134. return bit;
  135. }
  136. /*- End of function --------------------------------------------------------*/
  137. static void cng_detected(void *user_data, int tone, int level, int delay)
  138. {
  139. printf("%s (%d) declared at %fs, delay %d (%ddBm0)\n", modem_connect_tone_to_str(tone), tone, (float) when/SAMPLE_RATE, delay, level);
  140. if (tone == MODEM_CONNECT_TONES_FAX_CNG)
  141. hits++;
  142. }
  143. /*- End of function --------------------------------------------------------*/
  144. static void preamble_detected(void *user_data, int tone, int level, int delay)
  145. {
  146. printf("%s (%d) declared at bit %d (%ddBm0)\n", modem_connect_tone_to_str(tone), tone, preamble_count, level);
  147. if (tone == MODEM_CONNECT_TONES_FAX_PREAMBLE)
  148. preamble_on_at = preamble_count;
  149. else
  150. preamble_off_at = preamble_count;
  151. /*endif*/
  152. }
  153. /*- End of function --------------------------------------------------------*/
  154. static void ced_detected(void *user_data, int tone, int level, int delay)
  155. {
  156. printf("%s (%d) declared at %fs, delay %d (%ddBm0)\n", modem_connect_tone_to_str(tone), tone, (float) when/SAMPLE_RATE, delay, level);
  157. if (tone == MODEM_CONNECT_TONES_FAX_PREAMBLE
  158. ||
  159. tone == MODEM_CONNECT_TONES_ANS)
  160. {
  161. hits++;
  162. }
  163. }
  164. /*- End of function --------------------------------------------------------*/
  165. static void ans_pr_detected(void *user_data, int tone, int level, int delay)
  166. {
  167. printf("%s (%d) declared at %fs, delay %d (%ddBm0)\n", modem_connect_tone_to_str(tone), tone, (float) when/SAMPLE_RATE, delay, level);
  168. if (tone == MODEM_CONNECT_TONES_ANS_PR)
  169. hits++;
  170. }
  171. /*- End of function --------------------------------------------------------*/
  172. static void bell_ans_detected(void *user_data, int tone, int level, int delay)
  173. {
  174. printf("%s (%d) declared at %fs, delay %d (%ddBm0)\n", modem_connect_tone_to_str(tone), tone, (float) when/SAMPLE_RATE, delay, level);
  175. if (tone == MODEM_CONNECT_TONES_BELL_ANS)
  176. hits++;
  177. }
  178. /*- End of function --------------------------------------------------------*/
  179. static void calling_tone_detected(void *user_data, int tone, int level, int delay)
  180. {
  181. printf("%s (%d) declared at %fs, delay %d (%ddBm0)\n", modem_connect_tone_to_str(tone), tone, (float) when/SAMPLE_RATE, delay, level);
  182. if (tone == MODEM_CONNECT_TONES_CALLING_TONE)
  183. hits++;
  184. }
  185. /*- End of function --------------------------------------------------------*/
  186. int main(int argc, char *argv[])
  187. {
  188. int i;
  189. int j;
  190. int pitch;
  191. int depth;
  192. int level;
  193. int interval;
  194. int cycle;
  195. int16_t amp[8000];
  196. modem_connect_tones_rx_state_t cng_rx;
  197. modem_connect_tones_rx_state_t ced_rx;
  198. modem_connect_tones_rx_state_t ans_pr_rx;
  199. modem_connect_tones_tx_state_t modem_tone_tx;
  200. modem_connect_tones_rx_state_t calling_tone_rx;
  201. modem_connect_tones_rx_state_t bell_ans_rx;
  202. awgn_state_t chan_noise_source;
  203. SNDFILE *inhandle;
  204. SNDFILE *outhandle;
  205. int outframes;
  206. int frames;
  207. int samples;
  208. int hit;
  209. int level2;
  210. int max_level2;
  211. int tone_type;
  212. int test_list;
  213. int opt;
  214. bool false_hit;
  215. bool false_miss;
  216. char *decode_test_file;
  217. fsk_tx_state_t preamble_tx;
  218. test_list = 0;
  219. decode_test_file = NULL;
  220. while ((opt = getopt(argc, argv, "d:")) != -1)
  221. {
  222. switch (opt)
  223. {
  224. case 'd':
  225. decode_test_file = optarg;
  226. break;
  227. default:
  228. //usage();
  229. exit(2);
  230. break;
  231. }
  232. }
  233. argc -= optind;
  234. argv += optind;
  235. for (i = 0; i < argc; i++)
  236. {
  237. if (strcasecmp(argv[i], "1a") == 0)
  238. test_list |= PERFORM_TEST_1A;
  239. else if (strcasecmp(argv[i], "1b") == 0)
  240. test_list |= PERFORM_TEST_1B;
  241. else if (strcasecmp(argv[i], "1c") == 0)
  242. test_list |= PERFORM_TEST_1C;
  243. else if (strcasecmp(argv[i], "1d") == 0)
  244. test_list |= PERFORM_TEST_1D;
  245. else if (strcasecmp(argv[i], "1e") == 0)
  246. test_list |= PERFORM_TEST_1E;
  247. else if (strcasecmp(argv[i], "1f") == 0)
  248. test_list |= PERFORM_TEST_1F;
  249. else if (strcasecmp(argv[i], "1g") == 0)
  250. test_list |= PERFORM_TEST_1G;
  251. else if (strcasecmp(argv[i], "2a") == 0)
  252. test_list |= PERFORM_TEST_2A;
  253. else if (strcasecmp(argv[i], "2b") == 0)
  254. test_list |= PERFORM_TEST_2B;
  255. else if (strcasecmp(argv[i], "2c") == 0)
  256. test_list |= PERFORM_TEST_2C;
  257. else if (strcasecmp(argv[i], "2d") == 0)
  258. test_list |= PERFORM_TEST_2D;
  259. else if (strcasecmp(argv[i], "2e") == 0)
  260. test_list |= PERFORM_TEST_2E;
  261. else if (strcasecmp(argv[i], "2f") == 0)
  262. test_list |= PERFORM_TEST_2F;
  263. else if (strcasecmp(argv[i], "2g") == 0)
  264. test_list |= PERFORM_TEST_2G;
  265. else if (strcasecmp(argv[i], "3a") == 0)
  266. test_list |= PERFORM_TEST_3A;
  267. else if (strcasecmp(argv[i], "3b") == 0)
  268. test_list |= PERFORM_TEST_3B;
  269. else if (strcasecmp(argv[i], "3c") == 0)
  270. test_list |= PERFORM_TEST_3C;
  271. else if (strcasecmp(argv[i], "3d") == 0)
  272. test_list |= PERFORM_TEST_3D;
  273. else if (strcasecmp(argv[i], "3e") == 0)
  274. test_list |= PERFORM_TEST_3E;
  275. else if (strcasecmp(argv[i], "3f") == 0)
  276. test_list |= PERFORM_TEST_3F;
  277. else if (strcasecmp(argv[i], "3g") == 0)
  278. test_list |= PERFORM_TEST_3G;
  279. else if (strcasecmp(argv[i], "4") == 0)
  280. test_list |= PERFORM_TEST_4;
  281. else if (strcasecmp(argv[i], "5a") == 0)
  282. test_list |= PERFORM_TEST_5A;
  283. else if (strcasecmp(argv[i], "5b") == 0)
  284. test_list |= PERFORM_TEST_5B;
  285. else if (strcasecmp(argv[i], "6a") == 0)
  286. test_list |= PERFORM_TEST_6A;
  287. else if (strcasecmp(argv[i], "6b") == 0)
  288. test_list |= PERFORM_TEST_6B;
  289. else if (strcasecmp(argv[i], "7a") == 0)
  290. test_list |= PERFORM_TEST_7A;
  291. else if (strcasecmp(argv[i], "7b") == 0)
  292. test_list |= PERFORM_TEST_7B;
  293. else if (strcasecmp(argv[i], "8") == 0)
  294. test_list |= PERFORM_TEST_8;
  295. else
  296. {
  297. fprintf(stderr, "Unknown test '%s' specified\n", argv[i]);
  298. exit(2);
  299. }
  300. }
  301. if (decode_test_file == NULL && test_list == 0)
  302. test_list = 0xFFFFFFFF;
  303. if ((outhandle = sf_open_telephony_write(OUTPUT_FILE_NAME, 1)) == NULL)
  304. {
  305. fprintf(stderr, " Cannot create audio file '%s'\n", OUTPUT_FILE_NAME);
  306. exit(2);
  307. }
  308. if ((test_list & PERFORM_TEST_1A))
  309. {
  310. printf("Test 1a: CNG generation to a file\n");
  311. modem_connect_tones_tx_init(&modem_tone_tx, MODEM_CONNECT_TONES_FAX_CNG);
  312. for (i = 0; i < 20*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  313. {
  314. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  315. outframes = sf_writef_short(outhandle, amp, samples);
  316. if (outframes != samples)
  317. {
  318. fprintf(stderr, " Error writing audio file\n");
  319. exit(2);
  320. }
  321. /*endif*/
  322. }
  323. /*endfor*/
  324. }
  325. /*endif*/
  326. if ((test_list & PERFORM_TEST_1B))
  327. {
  328. printf("Test 1b: CED/ANS generation to a file\n");
  329. modem_connect_tones_tx_init(&modem_tone_tx, MODEM_CONNECT_TONES_FAX_CED);
  330. for (i = 0; i < 20*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  331. {
  332. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  333. outframes = sf_writef_short(outhandle, amp, samples);
  334. if (outframes != samples)
  335. {
  336. fprintf(stderr, " Error writing audio file\n");
  337. exit(2);
  338. }
  339. /*endif*/
  340. }
  341. /*endfor*/
  342. }
  343. /*endif*/
  344. if ((test_list & PERFORM_TEST_1C))
  345. {
  346. printf("Test 1c: ANSam (Modulated ANS) generation to a file\n");
  347. /* Some with modulation */
  348. modem_connect_tones_tx_init(&modem_tone_tx, MODEM_CONNECT_TONES_ANSAM);
  349. for (i = 0; i < 20*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  350. {
  351. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  352. outframes = sf_writef_short(outhandle, amp, samples);
  353. if (outframes != samples)
  354. {
  355. fprintf(stderr, " Error writing audio file\n");
  356. exit(2);
  357. }
  358. /*endif*/
  359. }
  360. /*endfor*/
  361. }
  362. /*endif*/
  363. if ((test_list & PERFORM_TEST_1D))
  364. {
  365. printf("Test 1d: ANS/ (EC-disable) generation to a file\n");
  366. /* Some without modulation, but with phase reversals */
  367. modem_connect_tones_tx_init(&modem_tone_tx, MODEM_CONNECT_TONES_ANS_PR);
  368. for (i = 0; i < 20*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  369. {
  370. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  371. outframes = sf_writef_short(outhandle, amp, samples);
  372. if (outframes != samples)
  373. {
  374. fprintf(stderr, " Error writing audio file\n");
  375. exit(2);
  376. }
  377. /*endif*/
  378. }
  379. /*endfor*/
  380. }
  381. /*endif*/
  382. if ((test_list & PERFORM_TEST_1E))
  383. {
  384. printf("Test 1e: ANSam/ (Modulated EC-disable) generation to a file\n");
  385. /* Some with modulation and phase reversals */
  386. modem_connect_tones_tx_init(&modem_tone_tx, MODEM_CONNECT_TONES_ANSAM_PR);
  387. for (i = 0; i < 20*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  388. {
  389. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  390. outframes = sf_writef_short(outhandle, amp, samples);
  391. if (outframes != samples)
  392. {
  393. fprintf(stderr, " Error writing audio file\n");
  394. exit(2);
  395. }
  396. /*endif*/
  397. }
  398. /*endfor*/
  399. }
  400. /*endif*/
  401. if ((test_list & PERFORM_TEST_1F))
  402. {
  403. printf("Test 1f: Bell answer tone generation to a file\n");
  404. modem_connect_tones_tx_init(&modem_tone_tx, MODEM_CONNECT_TONES_BELL_ANS);
  405. for (i = 0; i < 20*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  406. {
  407. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  408. outframes = sf_writef_short(outhandle, amp, samples);
  409. if (outframes != samples)
  410. {
  411. fprintf(stderr, " Error writing audio file\n");
  412. exit(2);
  413. }
  414. /*endif*/
  415. }
  416. /*endfor*/
  417. }
  418. /*endif*/
  419. if ((test_list & PERFORM_TEST_1G))
  420. {
  421. printf("Test 1g: Calling tone generation to a file\n");
  422. modem_connect_tones_tx_init(&modem_tone_tx, MODEM_CONNECT_TONES_CALLING_TONE);
  423. for (i = 0; i < 20*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  424. {
  425. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  426. outframes = sf_writef_short(outhandle, amp, samples);
  427. if (outframes != samples)
  428. {
  429. fprintf(stderr, " Error writing audio file\n");
  430. exit(2);
  431. }
  432. /*endif*/
  433. }
  434. /*endfor*/
  435. }
  436. /*endif*/
  437. if (sf_close_telephony(outhandle))
  438. {
  439. printf(" Cannot close audio file '%s'\n", OUTPUT_FILE_NAME);
  440. exit(2);
  441. }
  442. /*endif*/
  443. if ((test_list & PERFORM_TEST_2A))
  444. {
  445. printf("Test 2a: CNG detection with frequency\n");
  446. tone_type = MODEM_CONNECT_TONES_FAX_CNG;
  447. awgn_init_dbm0(&chan_noise_source, 7162534, -50.0f);
  448. false_hit = false;
  449. false_miss = false;
  450. for (pitch = 1100 - 500; pitch <= 1100 + 500; pitch++)
  451. {
  452. /* Use the transmitter to test the receiver */
  453. modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
  454. /* Fudge things for the test */
  455. modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
  456. modem_connect_tones_rx_init(&cng_rx, tone_type, NULL, NULL);
  457. level2 = 0;
  458. max_level2 = 0;
  459. for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  460. {
  461. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  462. for (j = 0; j < samples; j++)
  463. {
  464. amp[j] += awgn(&chan_noise_source);
  465. level2 += ((abs(amp[j]) - level2) >> 5);
  466. if (level2 > max_level2)
  467. max_level2 = level2;
  468. }
  469. /*endfor*/
  470. modem_connect_tones_rx(&cng_rx, amp, samples);
  471. }
  472. /*endfor*/
  473. hit = modem_connect_tones_rx_get(&cng_rx);
  474. if (pitch < (1100 - CED_FREQ_BLACKOUT) || pitch > (1100 + CED_FREQ_BLACKOUT))
  475. {
  476. if (hit != MODEM_CONNECT_TONES_NONE)
  477. false_hit = true;
  478. /*endif*/
  479. }
  480. else if (pitch > (1100 - CED_FREQ_TOLERANCE) && pitch < (1100 + CED_FREQ_TOLERANCE))
  481. {
  482. if (hit != tone_type)
  483. false_miss = true;
  484. /*endif*/
  485. }
  486. /*endif*/
  487. if (hit != MODEM_CONNECT_TONES_NONE)
  488. 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);
  489. /*endif*/
  490. }
  491. /*endfor*/
  492. if (false_hit || false_miss)
  493. {
  494. printf("Test failed.\n");
  495. exit(2);
  496. }
  497. /*endif*/
  498. printf("Test passed.\n");
  499. }
  500. /*endif*/
  501. if ((test_list & PERFORM_TEST_2B))
  502. {
  503. printf("Test 2b: CED/ANS detection with frequency\n");
  504. awgn_init_dbm0(&chan_noise_source, 7162534, -50.0f);
  505. false_hit = false;
  506. false_miss = false;
  507. for (pitch = 2100 - 500; pitch < 2100 + 500; pitch++)
  508. {
  509. /* Use the transmitter to test the receiver */
  510. modem_connect_tones_tx_init(&modem_tone_tx, MODEM_CONNECT_TONES_ANS);
  511. /* Fudge things for the test */
  512. modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
  513. modem_connect_tones_rx_init(&ced_rx, MODEM_CONNECT_TONES_FAX_CED_OR_PREAMBLE, NULL, NULL);
  514. for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  515. {
  516. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  517. for (j = 0; j < samples; j++)
  518. amp[j] += awgn(&chan_noise_source);
  519. /*endfor*/
  520. modem_connect_tones_rx(&ced_rx, amp, samples);
  521. }
  522. /*endfor*/
  523. hit = modem_connect_tones_rx_get(&ced_rx);
  524. if (pitch < (2100 - CNG_FREQ_BLACKOUT) || pitch > (2100 + CNG_FREQ_BLACKOUT))
  525. {
  526. if (hit != MODEM_CONNECT_TONES_NONE)
  527. false_hit = true;
  528. /*endif*/
  529. }
  530. else if (pitch > (2100 - CNG_FREQ_TOLERANCE) && pitch < (2100 + CNG_FREQ_TOLERANCE))
  531. {
  532. if (hit != MODEM_CONNECT_TONES_FAX_CED)
  533. false_miss = true;
  534. /*endif*/
  535. }
  536. /*endif*/
  537. if (hit != MODEM_CONNECT_TONES_NONE)
  538. 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);
  539. /*endif*/
  540. }
  541. if (false_hit || false_miss)
  542. {
  543. printf("Test failed.\n");
  544. exit(2);
  545. }
  546. /*endif*/
  547. printf("Test passed.\n");
  548. }
  549. /*endif*/
  550. if ((test_list & PERFORM_TEST_2C))
  551. {
  552. printf("Test 2c: ANSam detection with frequency\n");
  553. tone_type = MODEM_CONNECT_TONES_ANSAM;
  554. awgn_init_dbm0(&chan_noise_source, 7162534, -50.0f);
  555. false_hit = false;
  556. false_miss = false;
  557. for (pitch = 2100 - 100; pitch <= 2100 + 100; pitch++)
  558. {
  559. /* Use the transmitter to test the receiver */
  560. modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
  561. /* Fudge things for the test */
  562. modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
  563. modem_connect_tones_rx_init(&ans_pr_rx, tone_type, NULL, NULL);
  564. for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  565. {
  566. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  567. for (j = 0; j < samples; j++)
  568. amp[j] += awgn(&chan_noise_source);
  569. /*endfor*/
  570. modem_connect_tones_rx(&ans_pr_rx, amp, samples);
  571. }
  572. /*endfor*/
  573. hit = modem_connect_tones_rx_get(&ans_pr_rx);
  574. if (pitch < (2100 - CNG_FREQ_BLACKOUT) || pitch > (2100 + CNG_FREQ_BLACKOUT))
  575. {
  576. if (hit != MODEM_CONNECT_TONES_NONE)
  577. false_hit = true;
  578. /*endif*/
  579. }
  580. else if (pitch > (2100 - CNG_FREQ_TOLERANCE) && pitch < (2100 + CNG_FREQ_TOLERANCE))
  581. {
  582. if (hit != tone_type)
  583. false_miss = true;
  584. /*endif*/
  585. }
  586. /*endif*/
  587. if (hit != MODEM_CONNECT_TONES_NONE)
  588. 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);
  589. /*endif*/
  590. }
  591. /*endfor*/
  592. if (false_hit || false_miss)
  593. {
  594. printf("Test failed.\n");
  595. exit(2);
  596. }
  597. /*endif*/
  598. printf("Test passed.\n");
  599. }
  600. /*endif*/
  601. if ((test_list & PERFORM_TEST_2D))
  602. {
  603. printf("Test 2d: ANS/ (EC-disable) detection with frequency\n");
  604. tone_type = MODEM_CONNECT_TONES_ANS_PR;
  605. awgn_init_dbm0(&chan_noise_source, 7162534, -50.0f);
  606. false_hit = false;
  607. false_miss = false;
  608. for (pitch = 2100 - 100; pitch <= 2100 + 100; pitch++)
  609. {
  610. /* Use the transmitter to test the receiver */
  611. modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
  612. /* Fudge things for the test */
  613. modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
  614. modem_connect_tones_rx_init(&ans_pr_rx, tone_type, NULL, NULL);
  615. for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  616. {
  617. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  618. for (j = 0; j < samples; j++)
  619. amp[j] += awgn(&chan_noise_source);
  620. /*endfor*/
  621. modem_connect_tones_rx(&ans_pr_rx, amp, samples);
  622. }
  623. /*endfor*/
  624. hit = modem_connect_tones_rx_get(&ans_pr_rx);
  625. if (pitch < (2100 - CNG_FREQ_BLACKOUT) || pitch > (2100 + CNG_FREQ_BLACKOUT))
  626. {
  627. if (hit != MODEM_CONNECT_TONES_NONE)
  628. false_hit = true;
  629. /*endif*/
  630. }
  631. else if (pitch > (2100 - CNG_FREQ_TOLERANCE) && pitch < (2100 + CNG_FREQ_TOLERANCE))
  632. {
  633. if (hit != tone_type)
  634. false_miss = true;
  635. /*endif*/
  636. }
  637. /*endif*/
  638. if (hit != MODEM_CONNECT_TONES_NONE)
  639. 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);
  640. /*endif*/
  641. }
  642. /*endfor*/
  643. if (false_hit || false_miss)
  644. {
  645. printf("Test failed.\n");
  646. exit(2);
  647. }
  648. /*endif*/
  649. printf("Test passed.\n");
  650. }
  651. /*endif*/
  652. if ((test_list & PERFORM_TEST_2E))
  653. {
  654. printf("Test 2e: ANSam/ (Modulated EC-disable) detection with frequency\n");
  655. tone_type = MODEM_CONNECT_TONES_ANSAM_PR;
  656. awgn_init_dbm0(&chan_noise_source, 7162534, -50.0f);
  657. false_hit = false;
  658. false_miss = false;
  659. for (pitch = 2100 - 100; pitch <= 2100 + 100; pitch++)
  660. {
  661. /* Use the transmitter to test the receiver */
  662. modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
  663. /* Fudge things for the test */
  664. modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
  665. modem_connect_tones_rx_init(&ans_pr_rx, tone_type, NULL, NULL);
  666. for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  667. {
  668. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  669. for (j = 0; j < samples; j++)
  670. amp[j] += awgn(&chan_noise_source);
  671. /*endfor*/
  672. modem_connect_tones_rx(&ans_pr_rx, amp, samples);
  673. }
  674. /*endfor*/
  675. hit = modem_connect_tones_rx_get(&ans_pr_rx);
  676. if (pitch < (2100 - CNG_FREQ_BLACKOUT) || pitch > (2100 + CNG_FREQ_BLACKOUT))
  677. {
  678. if (hit != MODEM_CONNECT_TONES_NONE)
  679. false_hit = true;
  680. /*endif*/
  681. }
  682. else if (pitch > (2100 - CNG_FREQ_TOLERANCE) && pitch < (2100 + CNG_FREQ_TOLERANCE))
  683. {
  684. if (hit != tone_type)
  685. false_miss = true;
  686. /*endif*/
  687. }
  688. /*endif*/
  689. if (hit != MODEM_CONNECT_TONES_NONE)
  690. 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);
  691. /*endif*/
  692. }
  693. /*endfor*/
  694. if (false_hit || false_miss)
  695. {
  696. printf("Test failed.\n");
  697. exit(2);
  698. }
  699. /*endif*/
  700. printf("Test passed.\n");
  701. }
  702. /*endif*/
  703. if ((test_list & PERFORM_TEST_2F))
  704. {
  705. printf("Test 2f: Bell answer tone detection with frequency\n");
  706. tone_type = MODEM_CONNECT_TONES_BELL_ANS;
  707. awgn_init_dbm0(&chan_noise_source, 7162534, -50.0f);
  708. false_hit = false;
  709. false_miss = false;
  710. for (pitch = 2225 - 500; pitch <= 2225 + 500; pitch++)
  711. {
  712. /* Use the transmitter to test the receiver */
  713. modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
  714. /* Fudge things for the test */
  715. modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
  716. modem_connect_tones_rx_init(&bell_ans_rx, tone_type, NULL, NULL);
  717. level2 = 0;
  718. max_level2 = 0;
  719. for (i = 0; i < 8000; i += SAMPLES_PER_CHUNK)
  720. {
  721. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  722. for (j = 0; j < samples; j++)
  723. {
  724. amp[j] += awgn(&chan_noise_source);
  725. level2 += ((abs(amp[j]) - level2) >> 5);
  726. if (level2 > max_level2)
  727. max_level2 = level2;
  728. }
  729. /*endfor*/
  730. modem_connect_tones_rx(&bell_ans_rx, amp, samples);
  731. }
  732. /*endfor*/
  733. hit = modem_connect_tones_rx_get(&bell_ans_rx);
  734. if (pitch < (2225 - BELL_ANS_FREQ_BLACKOUT) || pitch > (2225 + BELL_ANS_FREQ_BLACKOUT))
  735. {
  736. if (hit != MODEM_CONNECT_TONES_NONE)
  737. false_hit = true;
  738. /*endif*/
  739. }
  740. else if (pitch > (2225 - BELL_ANS_FREQ_TOLERANCE) && pitch < (2225 + BELL_ANS_FREQ_TOLERANCE))
  741. {
  742. if (hit != tone_type)
  743. false_miss = true;
  744. /*endif*/
  745. }
  746. /*endif*/
  747. if (hit != MODEM_CONNECT_TONES_NONE)
  748. 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);
  749. /*endif*/
  750. }
  751. /*endfor*/
  752. if (false_hit || false_miss)
  753. {
  754. printf("Test failed.\n");
  755. exit(2);
  756. }
  757. /*endif*/
  758. printf("Test passed.\n");
  759. }
  760. /*endif*/
  761. if ((test_list & PERFORM_TEST_2G))
  762. {
  763. printf("Test 2g: Calling tone detection with frequency\n");
  764. tone_type = MODEM_CONNECT_TONES_CALLING_TONE;
  765. awgn_init_dbm0(&chan_noise_source, 7162534, -50.0f);
  766. false_hit = false;
  767. false_miss = false;
  768. for (pitch = 1300 - 500; pitch <= 1300 + 500; pitch++)
  769. {
  770. /* Use the transmitter to test the receiver */
  771. modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
  772. /* Fudge things for the test */
  773. modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
  774. modem_connect_tones_rx_init(&calling_tone_rx, tone_type, NULL, NULL);
  775. level2 = 0;
  776. max_level2 = 0;
  777. for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  778. {
  779. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  780. for (j = 0; j < samples; j++)
  781. {
  782. amp[j] += awgn(&chan_noise_source);
  783. level2 += ((abs(amp[j]) - level2) >> 5);
  784. if (level2 > max_level2)
  785. max_level2 = level2;
  786. }
  787. /*endfor*/
  788. modem_connect_tones_rx(&calling_tone_rx, amp, samples);
  789. }
  790. /*endfor*/
  791. hit = modem_connect_tones_rx_get(&calling_tone_rx);
  792. if (pitch < (1300 - CALLING_TONE_FREQ_BLACKOUT) || pitch > (1300 + CALLING_TONE_FREQ_BLACKOUT))
  793. {
  794. if (hit != MODEM_CONNECT_TONES_NONE)
  795. false_hit = true;
  796. /*endif*/
  797. }
  798. else if (pitch > (1300 - CALLING_TONE_FREQ_TOLERANCE) && pitch < (1300 + CALLING_TONE_FREQ_TOLERANCE))
  799. {
  800. if (hit != tone_type)
  801. false_miss = true;
  802. /*endif*/
  803. }
  804. /*endif*/
  805. if (hit != MODEM_CONNECT_TONES_NONE)
  806. 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);
  807. /*endif*/
  808. }
  809. /*endfor*/
  810. if (false_hit || false_miss)
  811. {
  812. printf("Test failed.\n");
  813. exit(2);
  814. }
  815. /*endif*/
  816. printf("Test passed.\n");
  817. }
  818. /*endif*/
  819. if ((test_list & PERFORM_TEST_3A))
  820. {
  821. printf("Test 3a: CNG detection with level\n");
  822. tone_type = MODEM_CONNECT_TONES_FAX_CNG;
  823. awgn_init_dbm0(&chan_noise_source, 7162534, -60.0f);
  824. false_hit = false;
  825. false_miss = false;
  826. for (pitch = 1100 - CED_FREQ_TOLERANCE; pitch <= 1100 + CED_FREQ_TOLERANCE; pitch += 2*CED_FREQ_TOLERANCE)
  827. {
  828. for (level = LEVEL_MAX; level >= LEVEL_MIN; level--)
  829. {
  830. /* Use the transmitter to test the receiver */
  831. modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
  832. /* Fudge things for the test */
  833. modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
  834. modem_tone_tx.level = dds_scaling_dbm0(level);
  835. modem_connect_tones_rx_init(&cng_rx, tone_type, NULL, NULL);
  836. for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  837. {
  838. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  839. for (j = 0; j < samples; j++)
  840. amp[j] += awgn(&chan_noise_source);
  841. /*endfor*/
  842. modem_connect_tones_rx(&cng_rx, amp, samples);
  843. }
  844. /*endfor*/
  845. hit = modem_connect_tones_rx_get(&cng_rx);
  846. if (level < LEVEL_MIN_REJECT)
  847. {
  848. if (hit != MODEM_CONNECT_TONES_NONE)
  849. false_hit = true;
  850. /*endif*/
  851. }
  852. else if (level > LEVEL_MIN_ACCEPT)
  853. {
  854. if (hit != tone_type)
  855. false_miss = true;
  856. /*endif*/
  857. }
  858. /*endif*/
  859. if (hit != MODEM_CONNECT_TONES_NONE)
  860. 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);
  861. /*endif*/
  862. }
  863. /*endfor*/
  864. }
  865. /*endfor*/
  866. if (false_hit || false_miss)
  867. {
  868. printf("Test failed.\n");
  869. exit(2);
  870. }
  871. /*endif*/
  872. printf("Test passed.\n");
  873. }
  874. /*endif*/
  875. if ((test_list & PERFORM_TEST_3B))
  876. {
  877. printf("Test 3b: CED/ANS detection with level\n");
  878. tone_type = MODEM_CONNECT_TONES_ANS;
  879. awgn_init_dbm0(&chan_noise_source, 7162534, -60.0f);
  880. false_hit = false;
  881. false_miss = false;
  882. for (pitch = 2100 - CNG_FREQ_TOLERANCE; pitch <= 2100 + CNG_FREQ_TOLERANCE; pitch += 2*CNG_FREQ_TOLERANCE)
  883. {
  884. for (level = LEVEL_MAX; level >= LEVEL_MIN; level--)
  885. {
  886. /* Use the transmitter to test the receiver */
  887. modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
  888. /* Fudge things for the test */
  889. modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
  890. modem_tone_tx.level = dds_scaling_dbm0(level);
  891. modem_connect_tones_rx_init(&ced_rx, MODEM_CONNECT_TONES_FAX_CED_OR_PREAMBLE, NULL, NULL);
  892. for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  893. {
  894. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  895. for (j = 0; j < samples; j++)
  896. amp[j] += awgn(&chan_noise_source);
  897. /*endfor*/
  898. modem_connect_tones_rx(&ced_rx, amp, samples);
  899. }
  900. /*endfor*/
  901. hit = modem_connect_tones_rx_get(&ced_rx);
  902. if (level < LEVEL_MIN_REJECT)
  903. {
  904. if (hit != MODEM_CONNECT_TONES_NONE)
  905. false_hit = true;
  906. /*endif*/
  907. }
  908. else if (level > LEVEL_MIN_ACCEPT)
  909. {
  910. if (hit != tone_type)
  911. false_miss = true;
  912. /*endif*/
  913. }
  914. /*endif*/
  915. if (hit != MODEM_CONNECT_TONES_NONE)
  916. 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);
  917. /*endif*/
  918. }
  919. /*endfor*/
  920. }
  921. /*endfor*/
  922. if (false_hit || false_miss)
  923. {
  924. printf("Test failed.\n");
  925. exit(2);
  926. }
  927. /*endif*/
  928. printf("Test passed.\n");
  929. }
  930. /*endif*/
  931. if ((test_list & PERFORM_TEST_3C))
  932. {
  933. printf("Test 3c: ANSam detection with level\n");
  934. tone_type = MODEM_CONNECT_TONES_ANSAM;
  935. awgn_init_dbm0(&chan_noise_source, 7162534, -60.0f);
  936. false_hit = false;
  937. false_miss = false;
  938. for (pitch = 2100 - CNG_FREQ_TOLERANCE; pitch <= 2100 + CNG_FREQ_TOLERANCE; pitch += 2*CNG_FREQ_TOLERANCE)
  939. {
  940. //for (level = LEVEL_MAX; level >= LEVEL_MIN; level--)
  941. for (level = -26; level >= -26; level--)
  942. {
  943. /* Use the transmitter to test the receiver */
  944. modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
  945. /* Fudge things for the test */
  946. modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
  947. modem_tone_tx.level = dds_scaling_dbm0(level);
  948. modem_tone_tx.mod_level = modem_tone_tx.level*20/100;
  949. modem_connect_tones_rx_init(&ans_pr_rx, tone_type, NULL, NULL);
  950. for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  951. {
  952. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  953. for (j = 0; j < samples; j++)
  954. amp[j] += awgn(&chan_noise_source);
  955. /*endfor*/
  956. modem_connect_tones_rx(&ans_pr_rx, amp, samples);
  957. }
  958. /*endfor*/
  959. hit = modem_connect_tones_rx_get(&ans_pr_rx);
  960. if (level < LEVEL_MIN_REJECT)
  961. {
  962. if (hit != MODEM_CONNECT_TONES_NONE)
  963. false_hit = true;
  964. /*endif*/
  965. }
  966. else if (level > LEVEL_MIN_ACCEPT)
  967. {
  968. if (hit != tone_type)
  969. false_miss = true;
  970. /*endif*/
  971. }
  972. /*endif*/
  973. if (hit != MODEM_CONNECT_TONES_NONE)
  974. 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);
  975. /*endif*/
  976. }
  977. /*endfor*/
  978. }
  979. /*endfor*/
  980. if (false_hit || false_miss)
  981. {
  982. printf("Test failed.\n");
  983. exit(2);
  984. }
  985. /*endif*/
  986. printf("Test passed.\n");
  987. }
  988. /*endif*/
  989. if ((test_list & PERFORM_TEST_3D))
  990. {
  991. printf("Test 3d: ANS/ (EC-disable) detection with level\n");
  992. tone_type = MODEM_CONNECT_TONES_ANS_PR;
  993. awgn_init_dbm0(&chan_noise_source, 7162534, -60.0f);
  994. false_hit = false;
  995. false_miss = false;
  996. for (pitch = 2100 - CNG_FREQ_TOLERANCE; pitch <= 2100 + CNG_FREQ_TOLERANCE; pitch += 2*CNG_FREQ_TOLERANCE)
  997. {
  998. for (level = LEVEL_MAX; level >= LEVEL_MIN; level--)
  999. {
  1000. /* Use the transmitter to test the receiver */
  1001. modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
  1002. /* Fudge things for the test */
  1003. modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
  1004. modem_tone_tx.level = dds_scaling_dbm0(level);
  1005. modem_connect_tones_rx_init(&ans_pr_rx, tone_type, NULL, NULL);
  1006. for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  1007. {
  1008. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  1009. for (j = 0; j < samples; j++)
  1010. amp[j] += awgn(&chan_noise_source);
  1011. /*endfor*/
  1012. modem_connect_tones_rx(&ans_pr_rx, amp, samples);
  1013. }
  1014. /*endfor*/
  1015. hit = modem_connect_tones_rx_get(&ans_pr_rx);
  1016. if (level < LEVEL_MIN_REJECT)
  1017. {
  1018. if (hit != MODEM_CONNECT_TONES_NONE)
  1019. false_hit = true;
  1020. /*endif*/
  1021. }
  1022. else if (level > LEVEL_MIN_ACCEPT)
  1023. {
  1024. if (hit != tone_type)
  1025. false_miss = true;
  1026. /*endif*/
  1027. }
  1028. /*endif*/
  1029. if (hit != MODEM_CONNECT_TONES_NONE)
  1030. 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);
  1031. /*endif*/
  1032. }
  1033. /*endfor*/
  1034. }
  1035. /*endfor*/
  1036. if (false_hit || false_miss)
  1037. {
  1038. printf("Test failed.\n");
  1039. exit(2);
  1040. }
  1041. /*endif*/
  1042. printf("Test passed.\n");
  1043. }
  1044. /*endif*/
  1045. if ((test_list & PERFORM_TEST_3E))
  1046. {
  1047. printf("Test 3e: ANSam/ (Modulated EC-disable) detection with level\n");
  1048. tone_type = MODEM_CONNECT_TONES_ANSAM_PR;
  1049. awgn_init_dbm0(&chan_noise_source, 7162534, -60.0f);
  1050. false_hit = false;
  1051. false_miss = false;
  1052. for (pitch = 2100 - CNG_FREQ_TOLERANCE; pitch <= 2100 + CNG_FREQ_TOLERANCE; pitch += 2*CNG_FREQ_TOLERANCE)
  1053. {
  1054. for (level = LEVEL_MAX; level >= LEVEL_MIN; level--)
  1055. {
  1056. /* Use the transmitter to test the receiver */
  1057. modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
  1058. /* Fudge things for the test */
  1059. modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
  1060. modem_tone_tx.level = dds_scaling_dbm0(level);
  1061. modem_tone_tx.mod_level = modem_tone_tx.level*20/100;
  1062. modem_connect_tones_rx_init(&ans_pr_rx, tone_type, NULL, NULL);
  1063. for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  1064. {
  1065. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  1066. for (j = 0; j < samples; j++)
  1067. amp[j] += awgn(&chan_noise_source);
  1068. /*endfor*/
  1069. modem_connect_tones_rx(&ans_pr_rx, amp, samples);
  1070. }
  1071. /*endfor*/
  1072. hit = modem_connect_tones_rx_get(&ans_pr_rx);
  1073. if (level < LEVEL_MIN_REJECT)
  1074. {
  1075. if (hit != MODEM_CONNECT_TONES_NONE)
  1076. false_hit = true;
  1077. /*endif*/
  1078. }
  1079. else if (level > LEVEL_MIN_ACCEPT)
  1080. {
  1081. if (hit != tone_type)
  1082. false_miss = true;
  1083. /*endif*/
  1084. }
  1085. /*endif*/
  1086. if (hit != MODEM_CONNECT_TONES_NONE)
  1087. 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);
  1088. /*endif*/
  1089. }
  1090. /*endfor*/
  1091. }
  1092. /*endfor*/
  1093. if (false_hit || false_miss)
  1094. {
  1095. printf("Test failed.\n");
  1096. exit(2);
  1097. }
  1098. /*endif*/
  1099. printf("Test passed.\n");
  1100. }
  1101. /*endif*/
  1102. if ((test_list & PERFORM_TEST_3F))
  1103. {
  1104. printf("Test 3f: Bell answer tone detection with level\n");
  1105. tone_type = MODEM_CONNECT_TONES_BELL_ANS;
  1106. awgn_init_dbm0(&chan_noise_source, 7162534, -60.0f);
  1107. false_hit = false;
  1108. false_miss = false;
  1109. for (pitch = 2225 - BELL_ANS_FREQ_TOLERANCE; pitch <= 2225 + BELL_ANS_FREQ_TOLERANCE; pitch += 2*BELL_ANS_FREQ_TOLERANCE)
  1110. {
  1111. for (level = LEVEL_MAX; level >= LEVEL_MIN; level--)
  1112. {
  1113. /* Use the transmitter to test the receiver */
  1114. modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
  1115. /* Fudge things for the test */
  1116. modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
  1117. modem_tone_tx.level = dds_scaling_dbm0(level);
  1118. modem_connect_tones_rx_init(&calling_tone_rx, tone_type, NULL, NULL);
  1119. for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  1120. {
  1121. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  1122. for (j = 0; j < samples; j++)
  1123. amp[j] += awgn(&chan_noise_source);
  1124. /*endfor*/
  1125. modem_connect_tones_rx(&calling_tone_rx, amp, samples);
  1126. }
  1127. /*endfor*/
  1128. hit = modem_connect_tones_rx_get(&calling_tone_rx);
  1129. if (level < LEVEL_MIN_REJECT)
  1130. {
  1131. if (hit != MODEM_CONNECT_TONES_NONE)
  1132. false_hit = true;
  1133. /*endif*/
  1134. }
  1135. else if (level > LEVEL_MIN_ACCEPT)
  1136. {
  1137. if (hit != tone_type)
  1138. false_miss = true;
  1139. /*endif*/
  1140. }
  1141. /*endif*/
  1142. if (hit != MODEM_CONNECT_TONES_NONE)
  1143. 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);
  1144. /*endif*/
  1145. }
  1146. /*endfor*/
  1147. }
  1148. /*endfor*/
  1149. if (false_hit || false_miss)
  1150. {
  1151. printf("Test failed.\n");
  1152. exit(2);
  1153. }
  1154. /*endif*/
  1155. printf("Test passed.\n");
  1156. }
  1157. /*endif*/
  1158. if ((test_list & PERFORM_TEST_3G))
  1159. {
  1160. printf("Test 3g: Calling tone detection with level\n");
  1161. tone_type = MODEM_CONNECT_TONES_CALLING_TONE;
  1162. awgn_init_dbm0(&chan_noise_source, 7162534, -60.0f);
  1163. false_hit = false;
  1164. false_miss = false;
  1165. for (pitch = 1300 - CALLING_TONE_FREQ_TOLERANCE; pitch <= 1300 + CALLING_TONE_FREQ_TOLERANCE; pitch += 2*CALLING_TONE_FREQ_TOLERANCE)
  1166. {
  1167. for (level = LEVEL_MAX; level >= LEVEL_MIN; level--)
  1168. {
  1169. /* Use the transmitter to test the receiver */
  1170. modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
  1171. /* Fudge things for the test */
  1172. modem_tone_tx.tone_phase_rate = dds_phase_rate(pitch);
  1173. modem_tone_tx.level = dds_scaling_dbm0(level);
  1174. modem_connect_tones_rx_init(&calling_tone_rx, tone_type, NULL, NULL);
  1175. for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  1176. {
  1177. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  1178. for (j = 0; j < samples; j++)
  1179. amp[j] += awgn(&chan_noise_source);
  1180. /*endfor*/
  1181. modem_connect_tones_rx(&calling_tone_rx, amp, samples);
  1182. }
  1183. /*endfor*/
  1184. hit = modem_connect_tones_rx_get(&calling_tone_rx);
  1185. if (level < LEVEL_MIN_REJECT)
  1186. {
  1187. if (hit != MODEM_CONNECT_TONES_NONE)
  1188. false_hit = true;
  1189. /*endif*/
  1190. }
  1191. else if (level > LEVEL_MIN_ACCEPT)
  1192. {
  1193. if (hit != tone_type)
  1194. false_miss = true;
  1195. /*endif*/
  1196. }
  1197. /*endif*/
  1198. if (hit != MODEM_CONNECT_TONES_NONE)
  1199. 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);
  1200. /*endif*/
  1201. }
  1202. /*endfor*/
  1203. }
  1204. /*endfor*/
  1205. if (false_hit || false_miss)
  1206. {
  1207. printf("Test failed.\n");
  1208. exit(2);
  1209. }
  1210. /*endif*/
  1211. printf("Test passed.\n");
  1212. }
  1213. /*endif*/
  1214. if ((test_list & PERFORM_TEST_4))
  1215. {
  1216. printf("Test 4: CED detection, when stimulated with V.21 preamble\n");
  1217. false_hit = false;
  1218. false_miss = false;
  1219. /* Send 255 bits of preamble (0.85s, the minimum specified preamble for T.30), and then
  1220. some random bits. Check the preamble detector comes on, and goes off at reasonable times. */
  1221. fsk_tx_init(&preamble_tx, &preset_fsk_specs[FSK_V21CH2], preamble_get_bit, NULL);
  1222. modem_connect_tones_rx_init(&ced_rx, MODEM_CONNECT_TONES_FAX_CED_OR_PREAMBLE, preamble_detected, NULL);
  1223. for (i = 0; i < 2*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  1224. {
  1225. samples = fsk_tx(&preamble_tx, amp, SAMPLES_PER_CHUNK);
  1226. modem_connect_tones_rx(&ced_rx, amp, samples);
  1227. }
  1228. /*endfor*/
  1229. for (i = 0; i < SAMPLE_RATE/10; i += SAMPLES_PER_CHUNK)
  1230. {
  1231. memset(amp, 0, sizeof(int16_t)*SAMPLES_PER_CHUNK);
  1232. modem_connect_tones_rx(&ced_rx, amp, SAMPLES_PER_CHUNK);
  1233. }
  1234. /*endfor*/
  1235. if (preamble_on_at < 40 || preamble_on_at > 50
  1236. ||
  1237. preamble_off_at < 580 || preamble_off_at > 620)
  1238. {
  1239. printf("Test failed.\n");
  1240. exit(2);
  1241. }
  1242. /*endif*/
  1243. printf("Test passed.\n");
  1244. }
  1245. /*endif*/
  1246. if ((test_list & PERFORM_TEST_5A))
  1247. {
  1248. printf("Test 5A: ANS and ANS/ detection with reversal interval\n");
  1249. tone_type = MODEM_CONNECT_TONES_ANS_PR;
  1250. awgn_init_dbm0(&chan_noise_source, 7162534, -60.0f);
  1251. false_hit = false;
  1252. false_miss = false;
  1253. for (interval = 400; interval < 800; interval++)
  1254. {
  1255. printf("Reversal interval = %d\n", interval);
  1256. /* Use the transmitter to test the receiver */
  1257. modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
  1258. modem_connect_tones_rx_init(&ans_pr_rx, tone_type, ans_pr_detected, NULL);
  1259. hits = 0;
  1260. for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  1261. {
  1262. when = i;
  1263. samples = SAMPLES_PER_CHUNK;
  1264. for (j = 0; j < samples; j++)
  1265. {
  1266. if (--modem_tone_tx.hop_timer <= 0)
  1267. {
  1268. modem_tone_tx.hop_timer = ms_to_samples(interval);
  1269. modem_tone_tx.tone_phase += 0x80000000;
  1270. }
  1271. /*endif*/
  1272. amp[j] = dds_mod(&modem_tone_tx.tone_phase, modem_tone_tx.tone_phase_rate, modem_tone_tx.level, 0);
  1273. }
  1274. for (j = 0; j < samples; j++)
  1275. amp[j] += awgn(&chan_noise_source);
  1276. /*endfor*/
  1277. modem_connect_tones_rx(&ans_pr_rx, amp, samples);
  1278. }
  1279. /*endfor*/
  1280. if (interval < (450 - 25) || interval > (450 + 25))
  1281. {
  1282. if (hits != 0)
  1283. false_hit = true;
  1284. /*endif*/
  1285. }
  1286. else if (interval > (450 - 25) && interval < (450 + 25))
  1287. {
  1288. if (hits == 0)
  1289. false_miss = true;
  1290. /*endif*/
  1291. }
  1292. /*endif*/
  1293. if (hits)
  1294. 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);
  1295. /*endif*/
  1296. }
  1297. /*endfor*/
  1298. if (false_hit || false_miss)
  1299. {
  1300. printf("Test failed.\n");
  1301. exit(2);
  1302. }
  1303. /*endif*/
  1304. printf("Test passed.\n");
  1305. }
  1306. /*endif*/
  1307. if ((test_list & PERFORM_TEST_5B))
  1308. {
  1309. printf("Test 5B: ANS and ANS/ detection with mixed reversal intervals\n");
  1310. awgn_init_dbm0(&chan_noise_source, 7162534, -60.0f);
  1311. tone_type = MODEM_CONNECT_TONES_ANS_PR;
  1312. false_hit = false;
  1313. false_miss = false;
  1314. interval = 450;
  1315. printf("Reversal interval = %d\n", interval);
  1316. /* Use the transmitter to test the receiver */
  1317. modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
  1318. modem_connect_tones_rx_init(&ans_pr_rx, tone_type, ans_pr_detected, NULL);
  1319. cycle = 0;
  1320. hits = 0;
  1321. for (i = 0; i < 60*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  1322. {
  1323. when = i;
  1324. samples = SAMPLES_PER_CHUNK;
  1325. for (j = 0; j < samples; j++)
  1326. {
  1327. if (--modem_tone_tx.hop_timer <= 0)
  1328. {
  1329. if (++cycle == 10)
  1330. interval = 1000;
  1331. if (cycle == 20)
  1332. interval = 450;
  1333. modem_tone_tx.hop_timer = ms_to_samples(interval);
  1334. modem_tone_tx.tone_phase += 0x80000000;
  1335. }
  1336. amp[j] = dds_mod(&modem_tone_tx.tone_phase, modem_tone_tx.tone_phase_rate, modem_tone_tx.level, 0);
  1337. }
  1338. /*endfor*/
  1339. for (j = 0; j < samples; j++)
  1340. amp[j] += awgn(&chan_noise_source);
  1341. /*endfor*/
  1342. modem_connect_tones_rx(&ans_pr_rx, amp, samples);
  1343. /* TODO: Add test result detection logic. */
  1344. }
  1345. /*endfor*/
  1346. if (false_hit || false_miss)
  1347. {
  1348. printf("Test failed.\n");
  1349. exit(2);
  1350. }
  1351. /*endif*/
  1352. printf("Test passed.\n");
  1353. }
  1354. /*endif*/
  1355. if ((test_list & PERFORM_TEST_6A))
  1356. {
  1357. printf("Test 6a: ANSam detection with AM pitch\n");
  1358. tone_type = MODEM_CONNECT_TONES_ANSAM;
  1359. awgn_init_dbm0(&chan_noise_source, 7162534, -50.0f);
  1360. false_hit = false;
  1361. false_miss = false;
  1362. for (pitch = 5; pitch < 25; pitch++)
  1363. {
  1364. /* Use the transmitter to test the receiver */
  1365. modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
  1366. /* Fudge things for the test */
  1367. modem_tone_tx.mod_phase_rate = dds_phase_rate(pitch);
  1368. modem_connect_tones_rx_init(&ans_pr_rx, tone_type, NULL, NULL);
  1369. for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  1370. {
  1371. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  1372. for (j = 0; j < samples; j++)
  1373. amp[j] += awgn(&chan_noise_source);
  1374. /*endfor*/
  1375. modem_connect_tones_rx(&ans_pr_rx, amp, samples);
  1376. }
  1377. /*endfor*/
  1378. hit = modem_connect_tones_rx_get(&ans_pr_rx);
  1379. if (pitch < (15 - 10) || pitch > (15 + 10))
  1380. {
  1381. if (hit == tone_type)
  1382. false_hit = true;
  1383. /*endif*/
  1384. }
  1385. else if (pitch > (15 - AM_FREQ_TOLERANCE) && pitch < (15 + AM_FREQ_TOLERANCE))
  1386. {
  1387. if (hit != tone_type)
  1388. false_miss = true;
  1389. /*endif*/
  1390. }
  1391. /*endif*/
  1392. if (hit != MODEM_CONNECT_TONES_NONE)
  1393. 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);
  1394. /*endif*/
  1395. }
  1396. /*endfor*/
  1397. if (false_hit || false_miss)
  1398. {
  1399. printf("Test failed.\n");
  1400. exit(2);
  1401. }
  1402. /*endif*/
  1403. printf("Test passed.\n");
  1404. }
  1405. /*endif*/
  1406. if ((test_list & PERFORM_TEST_6B))
  1407. {
  1408. printf("Test 6b: ANSam/ (Modulated EC-disable) detection with AM pitch\n");
  1409. tone_type = MODEM_CONNECT_TONES_ANSAM_PR;
  1410. awgn_init_dbm0(&chan_noise_source, 7162534, -50.0f);
  1411. false_hit = false;
  1412. false_miss = false;
  1413. for (pitch = 5; pitch < 25; pitch++)
  1414. {
  1415. /* Use the transmitter to test the receiver */
  1416. modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
  1417. /* Fudge things for the test */
  1418. modem_tone_tx.mod_phase_rate = dds_phase_rate(pitch);
  1419. modem_connect_tones_rx_init(&ans_pr_rx, tone_type, NULL, NULL);
  1420. for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  1421. {
  1422. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  1423. for (j = 0; j < samples; j++)
  1424. amp[j] += awgn(&chan_noise_source);
  1425. /*endfor*/
  1426. modem_connect_tones_rx(&ans_pr_rx, amp, samples);
  1427. }
  1428. /*endfor*/
  1429. hit = modem_connect_tones_rx_get(&ans_pr_rx);
  1430. if (pitch < (15 - 10) || pitch > (15 + 10))
  1431. {
  1432. if (hit == tone_type)
  1433. false_hit = true;
  1434. /*endif*/
  1435. }
  1436. else if (pitch > (15 - AM_FREQ_TOLERANCE) && pitch < (15 + AM_FREQ_TOLERANCE))
  1437. {
  1438. if (hit != tone_type)
  1439. false_miss = true;
  1440. /*endif*/
  1441. }
  1442. /*endif*/
  1443. if (hit != MODEM_CONNECT_TONES_NONE)
  1444. 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);
  1445. /*endif*/
  1446. }
  1447. /*endfor*/
  1448. if (false_hit || false_miss)
  1449. {
  1450. printf("Test failed.\n");
  1451. exit(2);
  1452. }
  1453. /*endif*/
  1454. printf("Test passed.\n");
  1455. }
  1456. /*endif*/
  1457. if ((test_list & PERFORM_TEST_7A))
  1458. {
  1459. printf("Test 7a: ANSam detection with AM depth\n");
  1460. tone_type = MODEM_CONNECT_TONES_ANSAM;
  1461. pitch = 2100;
  1462. awgn_init_dbm0(&chan_noise_source, 7162534, -50.0f);
  1463. false_hit = false;
  1464. false_miss = false;
  1465. for (depth = 0; depth < 40; depth++)
  1466. {
  1467. /* Use the transmitter to test the receiver */
  1468. modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
  1469. /* Fudge things for the test */
  1470. modem_tone_tx.mod_level = modem_tone_tx.level*depth/100;
  1471. modem_connect_tones_rx_init(&ans_pr_rx, tone_type, NULL, NULL);
  1472. for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  1473. {
  1474. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  1475. for (j = 0; j < samples; j++)
  1476. amp[j] += awgn(&chan_noise_source);
  1477. /*endfor*/
  1478. modem_connect_tones_rx(&ans_pr_rx, amp, samples);
  1479. }
  1480. /*endfor*/
  1481. hit = modem_connect_tones_rx_get(&ans_pr_rx);
  1482. if (depth < 10)
  1483. {
  1484. if (hit == tone_type)
  1485. false_hit = true;
  1486. /*endif*/
  1487. }
  1488. else if (depth > 15)
  1489. {
  1490. if (hit != tone_type)
  1491. false_miss = true;
  1492. /*endif*/
  1493. }
  1494. /*endif*/
  1495. if (hit != MODEM_CONNECT_TONES_NONE)
  1496. 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);
  1497. /*endif*/
  1498. }
  1499. /*endfor*/
  1500. if (false_hit || false_miss)
  1501. {
  1502. printf("Test failed.\n");
  1503. exit(2);
  1504. }
  1505. /*endif*/
  1506. printf("Test passed.\n");
  1507. }
  1508. /*endif*/
  1509. if ((test_list & PERFORM_TEST_7B))
  1510. {
  1511. printf("Test 7b: ANSam/ (Modulated EC-disable) detection with AM depth\n");
  1512. tone_type = MODEM_CONNECT_TONES_ANSAM_PR;
  1513. pitch = 2100;
  1514. awgn_init_dbm0(&chan_noise_source, 7162534, -50.0f);
  1515. false_hit = false;
  1516. false_miss = false;
  1517. for (depth = 0; depth < 40; depth++)
  1518. {
  1519. /* Use the transmitter to test the receiver */
  1520. modem_connect_tones_tx_init(&modem_tone_tx, tone_type);
  1521. /* Fudge things for the test */
  1522. modem_tone_tx.mod_level = modem_tone_tx.level*depth/100;
  1523. modem_connect_tones_rx_init(&ans_pr_rx, tone_type, NULL, NULL);
  1524. for (i = 0; i < 10*SAMPLE_RATE; i += SAMPLES_PER_CHUNK)
  1525. {
  1526. samples = modem_connect_tones_tx(&modem_tone_tx, amp, SAMPLES_PER_CHUNK);
  1527. for (j = 0; j < samples; j++)
  1528. amp[j] += awgn(&chan_noise_source);
  1529. /*endfor*/
  1530. modem_connect_tones_rx(&ans_pr_rx, amp, samples);
  1531. }
  1532. /*endfor*/
  1533. hit = modem_connect_tones_rx_get(&ans_pr_rx);
  1534. if (depth < 10)
  1535. {
  1536. if (hit == tone_type)
  1537. false_hit = true;
  1538. /*endif*/
  1539. }
  1540. else if (depth > 15)
  1541. {
  1542. if (hit != tone_type)
  1543. false_miss = true;
  1544. /*endif*/
  1545. }
  1546. /*endif*/
  1547. if (hit != MODEM_CONNECT_TONES_NONE)
  1548. 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);
  1549. /*endif*/
  1550. }
  1551. /*endfor*/
  1552. if (false_hit || false_miss)
  1553. {
  1554. printf("Test failed.\n");
  1555. exit(2);
  1556. }
  1557. /*endif*/
  1558. printf("Test passed.\n");
  1559. }
  1560. /*endif*/
  1561. if ((test_list & PERFORM_TEST_8))
  1562. {
  1563. /* Talk-off test */
  1564. /* Here we use the BellCore and Mitel talk off test tapes, intended for DTMF
  1565. detector testing. Presumably they should also have value here, but I am not
  1566. sure. If those voice snippets were chosen to be tough on DTMF detectors, they
  1567. might go easy on detectors looking for different pitches. However, the
  1568. Mitel DTMF test tape is known (the hard way) to exercise 2280Hz tone
  1569. detectors quite well. */
  1570. printf("Test 8: Talk-off test\n");
  1571. modem_connect_tones_rx_init(&cng_rx, MODEM_CONNECT_TONES_FAX_CNG, NULL, NULL);
  1572. modem_connect_tones_rx_init(&ced_rx, MODEM_CONNECT_TONES_FAX_CED_OR_PREAMBLE, NULL, NULL);
  1573. modem_connect_tones_rx_init(&ans_pr_rx, MODEM_CONNECT_TONES_ANS_PR, NULL, NULL);
  1574. modem_connect_tones_rx_init(&bell_ans_rx, MODEM_CONNECT_TONES_BELL_ANS, NULL, NULL);
  1575. modem_connect_tones_rx_init(&calling_tone_rx, MODEM_CONNECT_TONES_CALLING_TONE, NULL, NULL);
  1576. for (j = 0; bellcore_files[j][0]; j++)
  1577. {
  1578. if ((inhandle = sf_open_telephony_read(bellcore_files[j], 1)) == NULL)
  1579. {
  1580. fprintf(stderr, " Cannot open speech file '%s'\n", bellcore_files[j]);
  1581. exit (2);
  1582. }
  1583. /*endif*/
  1584. when = 0;
  1585. hits = 0;
  1586. while ((frames = sf_readf_short(inhandle, amp, 8000)))
  1587. {
  1588. when++;
  1589. modem_connect_tones_rx(&cng_rx, amp, frames);
  1590. modem_connect_tones_rx(&ced_rx, amp, frames);
  1591. modem_connect_tones_rx(&ans_pr_rx, amp, frames);
  1592. modem_connect_tones_rx(&bell_ans_rx, amp, frames);
  1593. modem_connect_tones_rx(&calling_tone_rx, amp, frames);
  1594. if (modem_connect_tones_rx_get(&cng_rx) != MODEM_CONNECT_TONES_NONE)
  1595. {
  1596. /* This is not a true measure of hits, as there might be more
  1597. than one in a block of data. However, since the only good
  1598. result is no hits, this approximation is OK. */
  1599. printf("Hit CNG at %ds\n", when);
  1600. hits++;
  1601. modem_connect_tones_rx_init(&cng_rx, MODEM_CONNECT_TONES_FAX_CNG, NULL, NULL);
  1602. }
  1603. /*endif*/
  1604. if (modem_connect_tones_rx_get(&ced_rx) != MODEM_CONNECT_TONES_NONE)
  1605. {
  1606. printf("Hit CED at %ds\n", when);
  1607. hits++;
  1608. modem_connect_tones_rx_init(&ced_rx, MODEM_CONNECT_TONES_FAX_CED_OR_PREAMBLE, NULL, NULL);
  1609. }
  1610. /*endif*/
  1611. if (modem_connect_tones_rx_get(&ans_pr_rx) != MODEM_CONNECT_TONES_NONE)
  1612. {
  1613. printf("Hit EC disable at %ds\n", when);
  1614. hits++;
  1615. modem_connect_tones_rx_init(&ans_pr_rx, MODEM_CONNECT_TONES_ANS_PR, NULL, NULL);
  1616. }
  1617. /*endif*/
  1618. if (modem_connect_tones_rx_get(&bell_ans_rx) != MODEM_CONNECT_TONES_NONE)
  1619. {
  1620. printf("Hit calling tone at %ds\n", when);
  1621. hits++;
  1622. modem_connect_tones_rx_init(&bell_ans_rx, MODEM_CONNECT_TONES_BELL_ANS, NULL, NULL);
  1623. }
  1624. /*endif*/
  1625. if (modem_connect_tones_rx_get(&calling_tone_rx) != MODEM_CONNECT_TONES_NONE)
  1626. {
  1627. printf("Hit calling tone at %ds\n", when);
  1628. hits++;
  1629. modem_connect_tones_rx_init(&calling_tone_rx, MODEM_CONNECT_TONES_CALLING_TONE, NULL, NULL);
  1630. }
  1631. /*endif*/
  1632. }
  1633. /*endwhile*/
  1634. if (sf_close_telephony(inhandle))
  1635. {
  1636. fprintf(stderr, " Cannot close speech file '%s'\n", bellcore_files[j]);
  1637. exit(2);
  1638. }
  1639. /*endif*/
  1640. printf(" File %d gave %d false hits.\n", j + 1, hits);
  1641. }
  1642. /*endfor*/
  1643. if (hits > 0)
  1644. {
  1645. printf("Test failed.\n");
  1646. exit(2);
  1647. }
  1648. /*endif*/
  1649. printf("Test passed.\n");
  1650. }
  1651. /*endif*/
  1652. if (decode_test_file)
  1653. {
  1654. printf("Decode file '%s'\n", decode_test_file);
  1655. modem_connect_tones_rx_init(&cng_rx, MODEM_CONNECT_TONES_FAX_CNG, cng_detected, NULL);
  1656. modem_connect_tones_rx_init(&ced_rx, MODEM_CONNECT_TONES_FAX_CED_OR_PREAMBLE, ced_detected, NULL);
  1657. modem_connect_tones_rx_init(&ans_pr_rx, MODEM_CONNECT_TONES_ANS_PR, ans_pr_detected, NULL);
  1658. modem_connect_tones_rx_init(&bell_ans_rx, MODEM_CONNECT_TONES_BELL_ANS, bell_ans_detected, NULL);
  1659. modem_connect_tones_rx_init(&calling_tone_rx, MODEM_CONNECT_TONES_CALLING_TONE, calling_tone_detected, NULL);
  1660. hits = 0;
  1661. if ((inhandle = sf_open_telephony_read(decode_test_file, 1)) == NULL)
  1662. {
  1663. fprintf(stderr, " Cannot open speech file '%s'\n", decode_test_file);
  1664. exit (2);
  1665. }
  1666. /*endif*/
  1667. when = 0;
  1668. hits = 0;
  1669. while ((frames = sf_readf_short(inhandle, amp, 8000)))
  1670. {
  1671. when++;
  1672. modem_connect_tones_rx(&cng_rx, amp, frames);
  1673. modem_connect_tones_rx(&ced_rx, amp, frames);
  1674. modem_connect_tones_rx(&ans_pr_rx, amp, frames);
  1675. modem_connect_tones_rx(&bell_ans_rx, amp, frames);
  1676. modem_connect_tones_rx(&calling_tone_rx, amp, frames);
  1677. }
  1678. /*endwhile*/
  1679. if (sf_close_telephony(inhandle))
  1680. {
  1681. fprintf(stderr, " Cannot close speech file '%s'\n", decode_test_file);
  1682. exit(2);
  1683. }
  1684. /*endif*/
  1685. printf(" File gave %d hits.\n", hits);
  1686. }
  1687. printf("Tests passed.\n");
  1688. return 0;
  1689. }
  1690. /*- End of function --------------------------------------------------------*/
  1691. /*- End of file ------------------------------------------------------------*/