Mercurial > hg > audiostuff
comparison spandsp-0.0.3/spandsp-0.0.3/tests/adsi_tests.c @ 5:f762bf195c4b
import spandsp-0.0.3
| author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
|---|---|
| date | Fri, 25 Jun 2010 16:00:21 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 4:26cd8f1ef0b1 | 5:f762bf195c4b |
|---|---|
| 1 /* | |
| 2 * SpanDSP - a series of DSP components for telephony | |
| 3 * | |
| 4 * adsi_tests.c - tests for analogue display service handling. | |
| 5 * | |
| 6 * Written by Steve Underwood <steveu@coppice.org> | |
| 7 * | |
| 8 * Copyright (C) 2003 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 * $Id: adsi_tests.c,v 1.28 2006/11/19 14:07:26 steveu Exp $ | |
| 26 */ | |
| 27 | |
| 28 /*! \page adsi_tests_page ADSI tests | |
| 29 \section adsi_tests_page_sec_1 What does it do? | |
| 30 These tests exercise the ADSI module, for all supported standards. A transmit | |
| 31 and a receive instance of the ADSI module are connected together. A quantity | |
| 32 of messages is passed between these instances, and checked for accuracy at | |
| 33 the receiver. Since the FSK modems used for this are exercised fully by other | |
| 34 tests, these tests do not include line modelling. | |
| 35 | |
| 36 \section adsi_tests_page_sec_2 How does it work? | |
| 37 */ | |
| 38 | |
| 39 #ifdef HAVE_CONFIG_H | |
| 40 #include "config.h" | |
| 41 #endif | |
| 42 | |
| 43 #include <inttypes.h> | |
| 44 #include <stdlib.h> | |
| 45 #include <stdio.h> | |
| 46 #include <string.h> | |
| 47 #include <strings.h> | |
| 48 #if defined(HAVE_TGMATH_H) | |
| 49 #include <tgmath.h> | |
| 50 #endif | |
| 51 #if defined(HAVE_MATH_H) | |
| 52 #include <math.h> | |
| 53 #endif | |
| 54 #include <assert.h> | |
| 55 #include <audiofile.h> | |
| 56 #include <tiffio.h> | |
| 57 | |
| 58 #include "spandsp.h" | |
| 59 | |
| 60 #define OUT_FILE_NAME "adsi.wav" | |
| 61 | |
| 62 #define BLOCK_LEN 160 | |
| 63 | |
| 64 char *decode_test_file = NULL; | |
| 65 | |
| 66 int errors = 0; | |
| 67 | |
| 68 adsi_rx_state_t rx_adsi; | |
| 69 adsi_tx_state_t tx_adsi; | |
| 70 | |
| 71 int current_standard = 0; | |
| 72 int good_message_received; | |
| 73 | |
| 74 int adsi_create_message(adsi_tx_state_t *s, uint8_t *msg); | |
| 75 | |
| 76 int adsi_create_message(adsi_tx_state_t *s, uint8_t *msg) | |
| 77 { | |
| 78 const char *t; | |
| 79 int len; | |
| 80 static int cycle = 0; | |
| 81 | |
| 82 len = 0; | |
| 83 switch (current_standard) | |
| 84 { | |
| 85 case ADSI_STANDARD_CLASS: | |
| 86 if (cycle > 3) | |
| 87 cycle = 0; | |
| 88 switch (cycle) | |
| 89 { | |
| 90 case 0: | |
| 91 len = adsi_add_field(s, msg, -1, CLASS_MDMF_CALLERID, NULL, 0); | |
| 92 /* Date and time as MMDDHHMM */ | |
| 93 len = adsi_add_field(s, msg, len, MCLASS_DATETIME, (uint8_t *) "10011750", 8); | |
| 94 len = adsi_add_field(s, msg, len, MCLASS_CALLER_NUMBER, (uint8_t *) "12345678", 8); | |
| 95 len = adsi_add_field(s, msg, len, MCLASS_DIALED_NUMBER, (uint8_t *) "87654321", 8); | |
| 96 len = adsi_add_field(s, msg, len, MCLASS_CALLER_NAME, (uint8_t *) "Chan Dai Man", 15); | |
| 97 break; | |
| 98 case 1: | |
| 99 len = adsi_add_field(s, msg, -1, CLASS_SDMF_MSG_WAITING, NULL, 0); | |
| 100 /* Active */ | |
| 101 len = adsi_add_field(s, msg, len, 0, (uint8_t *) "\x42", 1); | |
| 102 len = adsi_add_field(s, msg, len, 0, (uint8_t *) "\x42", 1); | |
| 103 len = adsi_add_field(s, msg, len, 0, (uint8_t *) "\x42", 1); | |
| 104 break; | |
| 105 case 2: | |
| 106 len = adsi_add_field(s, msg, -1, CLASS_SDMF_MSG_WAITING, NULL, 0); | |
| 107 /* Inactive */ | |
| 108 len = adsi_add_field(s, msg, len, 0, (uint8_t *) "\x6F", 1); | |
| 109 len = adsi_add_field(s, msg, len, 0, (uint8_t *) "\x6F", 1); | |
| 110 len = adsi_add_field(s, msg, len, 0, (uint8_t *) "\x6F", 1); | |
| 111 break; | |
| 112 case 3: | |
| 113 len = adsi_add_field(s, msg, -1, CLASS_SDMF_CALLERID, NULL, 0); | |
| 114 /* Date and time as MMDDHHMM */ | |
| 115 len = adsi_add_field(s, msg, len, 0, (uint8_t *) "10011750", 8); | |
| 116 len = adsi_add_field(s, msg, len, 0, (uint8_t *) "6095551212", 10); | |
| 117 break; | |
| 118 } | |
| 119 break; | |
| 120 case ADSI_STANDARD_CLIP: | |
| 121 if (cycle > 4) | |
| 122 cycle = 0; | |
| 123 switch (cycle) | |
| 124 { | |
| 125 case 0: | |
| 126 len = adsi_add_field(s, msg, -1, CLIP_MDMF_CALLERID, NULL, 0); | |
| 127 len = adsi_add_field(s, msg, len, CLIP_CALLTYPE, (uint8_t *) "\x81", 1); | |
| 128 /* Date and time as MMDDHHMM */ | |
| 129 len = adsi_add_field(s, msg, len, CLIP_DATETIME, (uint8_t *) "10011750", 8); | |
| 130 len = adsi_add_field(s, msg, len, CLIP_DIALED_NUMBER, (uint8_t *) "12345678", 8); | |
| 131 len = adsi_add_field(s, msg, len, CLIP_CALLER_NUMBER, (uint8_t *) "87654321", 8); | |
| 132 len = adsi_add_field(s, msg, len, CLIP_CALLER_NAME, (uint8_t *) "Chan Dai Man", 15); | |
| 133 break; | |
| 134 case 1: | |
| 135 len = adsi_add_field(s, msg, -1, CLIP_MDMF_MSG_WAITING, NULL, 0); | |
| 136 /* Inactive */ | |
| 137 len = adsi_add_field(s, msg, len, CLIP_VISUAL_INDICATOR, (uint8_t *) "\x00", 1); | |
| 138 break; | |
| 139 case 2: | |
| 140 len = adsi_add_field(s, msg, -1, CLIP_MDMF_MSG_WAITING, NULL, 0); | |
| 141 /* Active */ | |
| 142 len = adsi_add_field(s, msg, len, CLIP_VISUAL_INDICATOR, (uint8_t *) "\xFF", 1); | |
| 143 len = adsi_add_field(s, msg, len, CLIP_NUM_MSG, (uint8_t *) "\x05", 1); | |
| 144 break; | |
| 145 case 3: | |
| 146 len = adsi_add_field(s, msg, -1, CLIP_MDMF_SMS, NULL, 0); | |
| 147 /* Active */ | |
| 148 len = adsi_add_field(s, msg, len, CLIP_DISPLAY_INFO, (uint8_t *) "\x00" "ABC", 4); | |
| 149 break; | |
| 150 case 4: | |
| 151 len = adsi_add_field(s, msg, -1, CLIP_MDMF_CALLERID, NULL, 0); | |
| 152 len = adsi_add_field(s, msg, len, CLIP_NUM_MSG, (uint8_t *) "\x03", 1); | |
| 153 break; | |
| 154 } | |
| 155 break; | |
| 156 case ADSI_STANDARD_ACLIP: | |
| 157 if (cycle > 0) | |
| 158 cycle = 0; | |
| 159 switch (cycle) | |
| 160 { | |
| 161 case 0: | |
| 162 len = adsi_add_field(s, msg, -1, ACLIP_MDMF_CALLERID, NULL, 0); | |
| 163 /* Date and time as MMDDHHMM */ | |
| 164 len = adsi_add_field(s, msg, len, ACLIP_DATETIME, (uint8_t *) "10011750", 8); | |
| 165 len = adsi_add_field(s, msg, len, ACLIP_DIALED_NUMBER, (uint8_t *) "12345678", 8); | |
| 166 len = adsi_add_field(s, msg, len, ACLIP_CALLER_NUMBER, (uint8_t *) "87654321", 8); | |
| 167 len = adsi_add_field(s, msg, len, ACLIP_CALLER_NAME, (uint8_t *) "Chan Dai Man", 15); | |
| 168 break; | |
| 169 } | |
| 170 break; | |
| 171 case ADSI_STANDARD_JCLIP: | |
| 172 len = adsi_add_field(s, msg, -1, JCLIP_MDMF_CALLERID, NULL, 0); | |
| 173 len = adsi_add_field(s, msg, len, JCLIP_CALLER_NUMBER, (uint8_t *) "12345678", 8); | |
| 174 len = adsi_add_field(s, msg, len, JCLIP_CALLER_NUM_DES, (uint8_t *) "215", 3); | |
| 175 len = adsi_add_field(s, msg, len, JCLIP_DIALED_NUMBER, (uint8_t *) "87654321", 8); | |
| 176 len = adsi_add_field(s, msg, len, JCLIP_DIALED_NUM_DES, (uint8_t *) "215", 3); | |
| 177 break; | |
| 178 case ADSI_STANDARD_CLIP_DTMF: | |
| 179 len = adsi_add_field(s, msg, 0, CLIP_DTMF_CALLER_NUMBER, (uint8_t *) "12345678", 8); | |
| 180 break; | |
| 181 case ADSI_STANDARD_TDD: | |
| 182 t = "The quick Brown Fox Jumps Over The Lazy dog 0123456789!@#$%^&*()"; | |
| 183 len = adsi_add_field(s, msg, -1, 0, (uint8_t *) t, strlen(t)); | |
| 184 break; | |
| 185 } | |
| 186 cycle++; | |
| 187 return len; | |
| 188 } | |
| 189 /*- End of function --------------------------------------------------------*/ | |
| 190 | |
| 191 static void put_adsi_msg(void *user_data, const uint8_t *msg, int len) | |
| 192 { | |
| 193 int i; | |
| 194 int l; | |
| 195 uint8_t field_type; | |
| 196 const uint8_t *field_body; | |
| 197 int field_len; | |
| 198 int message_type; | |
| 199 uint8_t body[256]; | |
| 200 | |
| 201 printf("Good message received (%d bytes)\n", len); | |
| 202 good_message_received = TRUE; | |
| 203 for (i = 0; i < len; i++) | |
| 204 { | |
| 205 printf("%02x ", msg[i]); | |
| 206 if ((i & 0xf) == 0xf) | |
| 207 printf("\n"); | |
| 208 } | |
| 209 printf("\n"); | |
| 210 l = -1; | |
| 211 message_type = -1; | |
| 212 printf("Message breakdown\n"); | |
| 213 do | |
| 214 { | |
| 215 l = adsi_next_field(&rx_adsi, msg, len, l, &field_type, &field_body, &field_len); | |
| 216 if (l > 0) | |
| 217 { | |
| 218 if (field_body) | |
| 219 { | |
| 220 memcpy(body, field_body, field_len); | |
| 221 body[field_len] = '\0'; | |
| 222 printf("Field type 0x%x, len %d, '%s' - ", field_type, field_len, body); | |
| 223 switch (current_standard) | |
| 224 { | |
| 225 case ADSI_STANDARD_CLASS: | |
| 226 switch (message_type) | |
| 227 { | |
| 228 case CLASS_SDMF_CALLERID: | |
| 229 break; | |
| 230 case CLASS_MDMF_CALLERID: | |
| 231 switch (field_type) | |
| 232 { | |
| 233 case MCLASS_DATETIME: | |
| 234 printf("Date and time (MMDDHHMM)"); | |
| 235 break; | |
| 236 case MCLASS_CALLER_NUMBER: | |
| 237 printf("Caller's number"); | |
| 238 break; | |
| 239 case MCLASS_DIALED_NUMBER: | |
| 240 printf("Dialed number"); | |
| 241 break; | |
| 242 case MCLASS_ABSENCE1: | |
| 243 printf("Caller's number absent: 'O' or 'P'"); | |
| 244 break; | |
| 245 case MCLASS_REDIRECT: | |
| 246 printf("Call forward: universal ('0'), on busy ('1'), or on unanswered ('2')"); | |
| 247 break; | |
| 248 case MCLASS_QUALIFIER: | |
| 249 printf("Long distance: 'L'"); | |
| 250 break; | |
| 251 case MCLASS_CALLER_NAME: | |
| 252 printf("Caller's name"); | |
| 253 break; | |
| 254 case MCLASS_ABSENCE2: | |
| 255 printf("Caller's name absent: 'O' or 'P'"); | |
| 256 break; | |
| 257 } | |
| 258 break; | |
| 259 case CLASS_SDMF_MSG_WAITING: | |
| 260 break; | |
| 261 case CLASS_MDMF_MSG_WAITING: | |
| 262 switch (field_type) | |
| 263 { | |
| 264 case MCLASS_VISUAL_INDICATOR: | |
| 265 printf("Message waiting/not waiting"); | |
| 266 break; | |
| 267 } | |
| 268 break; | |
| 269 } | |
| 270 break; | |
| 271 case ADSI_STANDARD_CLIP: | |
| 272 switch (message_type) | |
| 273 { | |
| 274 case CLIP_MDMF_CALLERID: | |
| 275 case CLIP_MDMF_MSG_WAITING: | |
| 276 case CLIP_MDMF_CHARGE_INFO: | |
| 277 case CLIP_MDMF_SMS: | |
| 278 switch (field_type) | |
| 279 { | |
| 280 case CLIP_DATETIME: | |
| 281 printf("Date and time (MMDDHHMM)"); | |
| 282 break; | |
| 283 case CLIP_CALLER_NUMBER: | |
| 284 printf("Caller's number"); | |
| 285 break; | |
| 286 case CLIP_DIALED_NUMBER: | |
| 287 printf("Dialed number"); | |
| 288 break; | |
| 289 case CLIP_ABSENCE1: | |
| 290 printf("Caller's number absent"); | |
| 291 break; | |
| 292 case CLIP_CALLER_NAME: | |
| 293 printf("Caller's name"); | |
| 294 break; | |
| 295 case CLIP_ABSENCE2: | |
| 296 printf("Caller's name absent"); | |
| 297 break; | |
| 298 case CLIP_VISUAL_INDICATOR: | |
| 299 printf("Visual indicator"); | |
| 300 break; | |
| 301 case CLIP_MESSAGE_ID: | |
| 302 printf("Message ID"); | |
| 303 break; | |
| 304 case CLIP_CALLTYPE: | |
| 305 printf("Voice call, ring-back-when-free call, or msg waiting call"); | |
| 306 break; | |
| 307 case CLIP_NUM_MSG: | |
| 308 printf("Number of messages"); | |
| 309 break; | |
| 310 #if 0 | |
| 311 case CLIP_REDIR_NUMBER: | |
| 312 printf("Redirecting number"); | |
| 313 break; | |
| 314 #endif | |
| 315 case CLIP_CHARGE: | |
| 316 printf("Charge"); | |
| 317 break; | |
| 318 case CLIP_DURATION: | |
| 319 printf("Duration of the call"); | |
| 320 break; | |
| 321 case CLIP_ADD_CHARGE: | |
| 322 printf("Additional charge"); | |
| 323 break; | |
| 324 case CLIP_DISPLAY_INFO: | |
| 325 printf("Display information"); | |
| 326 break; | |
| 327 case CLIP_SERVICE_INFO: | |
| 328 printf("Service information"); | |
| 329 break; | |
| 330 } | |
| 331 break; | |
| 332 } | |
| 333 break; | |
| 334 case ADSI_STANDARD_ACLIP: | |
| 335 switch (message_type) | |
| 336 { | |
| 337 case ACLIP_SDMF_CALLERID: | |
| 338 break; | |
| 339 case ACLIP_MDMF_CALLERID: | |
| 340 switch (field_type) | |
| 341 { | |
| 342 case ACLIP_DATETIME: | |
| 343 printf("Date and time (MMDDHHMM)"); | |
| 344 break; | |
| 345 case ACLIP_CALLER_NUMBER: | |
| 346 printf("Caller's number"); | |
| 347 break; | |
| 348 case ACLIP_DIALED_NUMBER: | |
| 349 printf("Dialed number"); | |
| 350 break; | |
| 351 case ACLIP_ABSENCE1: | |
| 352 printf("Caller's number absent: 'O' or 'P'"); | |
| 353 break; | |
| 354 case ACLIP_REDIRECT: | |
| 355 printf("Call forward: universal, on busy, or on unanswered"); | |
| 356 break; | |
| 357 case ACLIP_QUALIFIER: | |
| 358 printf("Long distance call: 'L'"); | |
| 359 break; | |
| 360 case ACLIP_CALLER_NAME: | |
| 361 printf("Caller's name"); | |
| 362 break; | |
| 363 case ACLIP_ABSENCE2: | |
| 364 printf("Caller's name absent: 'O' or 'P'"); | |
| 365 break; | |
| 366 } | |
| 367 break; | |
| 368 } | |
| 369 break; | |
| 370 case ADSI_STANDARD_JCLIP: | |
| 371 switch (message_type) | |
| 372 { | |
| 373 case JCLIP_MDMF_CALLERID: | |
| 374 switch (field_type) | |
| 375 { | |
| 376 case JCLIP_CALLER_NUMBER: | |
| 377 printf("Caller's number"); | |
| 378 break; | |
| 379 case JCLIP_CALLER_NUM_DES: | |
| 380 printf("Caller's number data extension signal"); | |
| 381 break; | |
| 382 case JCLIP_DIALED_NUMBER: | |
| 383 printf("Dialed number"); | |
| 384 break; | |
| 385 case JCLIP_DIALED_NUM_DES: | |
| 386 printf("Dialed number data extension signal"); | |
| 387 break; | |
| 388 case JCLIP_ABSENCE: | |
| 389 printf("Caller's number absent: 'C', 'O', 'P' or 'S'"); | |
| 390 break; | |
| 391 } | |
| 392 break; | |
| 393 } | |
| 394 break; | |
| 395 case ADSI_STANDARD_CLIP_DTMF: | |
| 396 switch (message_type) | |
| 397 { | |
| 398 case CLIP_DTMF_CALLER_NUMBER: | |
| 399 printf("Caller's number"); | |
| 400 break; | |
| 401 case CLIP_DTMF_ABSENCE1: | |
| 402 printf("Caller's number absent: private (1), overseas (2) or not available (3)"); | |
| 403 break; | |
| 404 } | |
| 405 break; | |
| 406 case ADSI_STANDARD_TDD: | |
| 407 break; | |
| 408 } | |
| 409 } | |
| 410 else | |
| 411 { | |
| 412 printf("Message type 0x%x - ", field_type); | |
| 413 message_type = field_type; | |
| 414 switch (current_standard) | |
| 415 { | |
| 416 case ADSI_STANDARD_CLASS: | |
| 417 switch (message_type) | |
| 418 { | |
| 419 case CLASS_SDMF_CALLERID: | |
| 420 printf("Single data message caller ID"); | |
| 421 break; | |
| 422 case CLASS_MDMF_CALLERID: | |
| 423 printf("Multiple data message caller ID"); | |
| 424 break; | |
| 425 case CLASS_SDMF_MSG_WAITING: | |
| 426 printf("Single data message message waiting"); | |
| 427 break; | |
| 428 case CLASS_MDMF_MSG_WAITING: | |
| 429 printf("Multiple data message message waiting"); | |
| 430 break; | |
| 431 default: | |
| 432 printf("Unknown"); | |
| 433 break; | |
| 434 } | |
| 435 break; | |
| 436 case ADSI_STANDARD_CLIP: | |
| 437 switch (message_type) | |
| 438 { | |
| 439 case CLIP_MDMF_CALLERID: | |
| 440 printf("Multiple data message caller ID"); | |
| 441 break; | |
| 442 case CLIP_MDMF_MSG_WAITING: | |
| 443 printf("Multiple data message message waiting"); | |
| 444 break; | |
| 445 case CLIP_MDMF_CHARGE_INFO: | |
| 446 printf("Multiple data message charge info"); | |
| 447 break; | |
| 448 case CLIP_MDMF_SMS: | |
| 449 printf("Multiple data message SMS"); | |
| 450 break; | |
| 451 default: | |
| 452 printf("Unknown"); | |
| 453 break; | |
| 454 } | |
| 455 break; | |
| 456 case ADSI_STANDARD_ACLIP: | |
| 457 switch (message_type) | |
| 458 { | |
| 459 case ACLIP_SDMF_CALLERID: | |
| 460 printf("Single data message caller ID frame"); | |
| 461 break; | |
| 462 case ACLIP_MDMF_CALLERID: | |
| 463 printf("Multiple data message caller ID frame"); | |
| 464 break; | |
| 465 default: | |
| 466 printf("Unknown"); | |
| 467 break; | |
| 468 } | |
| 469 break; | |
| 470 case ADSI_STANDARD_JCLIP: | |
| 471 switch (message_type) | |
| 472 { | |
| 473 case JCLIP_MDMF_CALLERID: | |
| 474 printf("Multiple data message caller ID frame"); | |
| 475 break; | |
| 476 default: | |
| 477 printf("Unknown"); | |
| 478 break; | |
| 479 } | |
| 480 break; | |
| 481 case ADSI_STANDARD_CLIP_DTMF: | |
| 482 switch (message_type) | |
| 483 { | |
| 484 case CLIP_DTMF_CALLER_NUMBER: | |
| 485 printf("Caller's number"); | |
| 486 break; | |
| 487 case CLIP_DTMF_ABSENCE1: | |
| 488 printf("Caller's number absent"); | |
| 489 break; | |
| 490 default: | |
| 491 printf("Unknown"); | |
| 492 break; | |
| 493 } | |
| 494 break; | |
| 495 case ADSI_STANDARD_TDD: | |
| 496 printf("Unknown"); | |
| 497 break; | |
| 498 } | |
| 499 } | |
| 500 printf("\n"); | |
| 501 } | |
| 502 } | |
| 503 while (l > 0); | |
| 504 if (l < -1) | |
| 505 { | |
| 506 /* This message appears corrupt */ | |
| 507 printf("Bad message contents\n"); | |
| 508 exit(2); | |
| 509 } | |
| 510 printf("\n"); | |
| 511 } | |
| 512 /*- End of function --------------------------------------------------------*/ | |
| 513 | |
| 514 int main(int argc, char *argv[]) | |
| 515 { | |
| 516 int16_t amp[BLOCK_LEN]; | |
| 517 uint8_t adsi_msg[256 + 42]; | |
| 518 int adsi_msg_len; | |
| 519 AFfilehandle inhandle; | |
| 520 AFfilehandle outhandle; | |
| 521 AFfilesetup filesetup; | |
| 522 int outframes; | |
| 523 int len; | |
| 524 int i; | |
| 525 int j; | |
| 526 int push; | |
| 527 int log_audio; | |
| 528 | |
| 529 log_audio = FALSE; | |
| 530 decode_test_file = NULL; | |
| 531 current_standard = ADSI_STANDARD_CLASS; | |
| 532 for (i = 1; i < argc; i++) | |
| 533 { | |
| 534 if (strcmp(argv[i], "-d") == 0) | |
| 535 { | |
| 536 i++; | |
| 537 decode_test_file = argv[i]; | |
| 538 continue; | |
| 539 } | |
| 540 if (strcmp(argv[i], "-s") == 0) | |
| 541 { | |
| 542 i++; | |
| 543 if (strcasecmp("CLASS", argv[i]) == 0) | |
| 544 current_standard = ADSI_STANDARD_CLASS; | |
| 545 else if (strcasecmp("CLIP", argv[i]) == 0) | |
| 546 current_standard = ADSI_STANDARD_CLIP; | |
| 547 else if (strcasecmp("A-CLIP", argv[i]) == 0) | |
| 548 current_standard = ADSI_STANDARD_ACLIP; | |
| 549 else if (strcasecmp("J-CLIP", argv[i]) == 0) | |
| 550 current_standard = ADSI_STANDARD_JCLIP; | |
| 551 else if (strcasecmp("CLIP-DTMF", argv[i]) == 0) | |
| 552 current_standard = ADSI_STANDARD_CLIP_DTMF; | |
| 553 else if (strcasecmp("TDD", argv[i]) == 0) | |
| 554 current_standard = ADSI_STANDARD_TDD; | |
| 555 else | |
| 556 current_standard = atoi(argv[i]); | |
| 557 continue; | |
| 558 } | |
| 559 if (strcmp(argv[i], "-l") == 0) | |
| 560 { | |
| 561 log_audio = TRUE; | |
| 562 continue; | |
| 563 } | |
| 564 } | |
| 565 filesetup = AF_NULL_FILESETUP; | |
| 566 outhandle = AF_NULL_FILEHANDLE; | |
| 567 | |
| 568 #if 0 | |
| 569 /* This part tests internal static routines in the ADSI module. It can | |
| 570 only be run with a modified version of the ADSI module, which makes | |
| 571 the routines visible. */ | |
| 572 /* Check the character encode/decode cycle */ | |
| 573 current_standard = ADSI_STANDARD_TDD; | |
| 574 adsi_tx_init(&tx_adsi, ADSI_STANDARD_TDD); | |
| 575 adsi_rx_init(&rx_adsi, ADSI_STANDARD_TDD, put_adsi_msg, NULL); | |
| 576 s = "The quick Brown Fox Jumps Over The Lazy dog 0123456789!@#$%^&*()"; | |
| 577 while ((ch = *s++)) | |
| 578 { | |
| 579 xx = adsi_encode_baudot(&tx_adsi, ch); | |
| 580 if ((xx & 0x3E0)) | |
| 581 { | |
| 582 yy = adsi_decode_baudot(&rx_adsi, (xx >> 5) & 0x1F); | |
| 583 if (yy) | |
| 584 printf("%c", yy); | |
| 585 } | |
| 586 yy = adsi_decode_baudot(&rx_adsi, xx & 0x1F); | |
| 587 if (yy) | |
| 588 printf("%c", yy); | |
| 589 } | |
| 590 printf("\n"); | |
| 591 #endif | |
| 592 | |
| 593 if (decode_test_file) | |
| 594 { | |
| 595 /* We will decode the audio from a wave file. */ | |
| 596 if ((inhandle = afOpenFile(decode_test_file, "r", NULL)) == AF_NULL_FILEHANDLE) | |
| 597 { | |
| 598 fprintf(stderr, " Cannot open wave file '%s'\n", decode_test_file); | |
| 599 exit(2); | |
| 600 } | |
| 601 | |
| 602 adsi_rx_init(&rx_adsi, current_standard, put_adsi_msg, NULL); | |
| 603 span_log_set_level(&rx_adsi.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); | |
| 604 span_log_set_tag(&rx_adsi.logging, "ADSI"); | |
| 605 for (;;) | |
| 606 { | |
| 607 len = afReadFrames(inhandle, | |
| 608 AF_DEFAULT_TRACK, | |
| 609 amp, | |
| 610 BLOCK_LEN); | |
| 611 if (len == 0) | |
| 612 break; | |
| 613 adsi_rx(&rx_adsi, amp, len); | |
| 614 } | |
| 615 if (afCloseFile(inhandle) != 0) | |
| 616 { | |
| 617 fprintf(stderr, " Cannot close wave file '%s'\n", decode_test_file); | |
| 618 exit(2); | |
| 619 } | |
| 620 } | |
| 621 else | |
| 622 { | |
| 623 if (log_audio) | |
| 624 { | |
| 625 if ((filesetup = afNewFileSetup()) == AF_NULL_FILESETUP) | |
| 626 { | |
| 627 fprintf(stderr, " Failed to create file setup\n"); | |
| 628 exit(2); | |
| 629 } | |
| 630 afInitSampleFormat(filesetup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16); | |
| 631 afInitRate(filesetup, AF_DEFAULT_TRACK, (float) SAMPLE_RATE); | |
| 632 afInitFileFormat(filesetup, AF_FILE_WAVE); | |
| 633 afInitChannels(filesetup, AF_DEFAULT_TRACK, 1); | |
| 634 | |
| 635 if ((outhandle = afOpenFile(OUT_FILE_NAME, "w", filesetup)) == AF_NULL_FILEHANDLE) | |
| 636 { | |
| 637 fprintf(stderr, " Cannot create wave file '%s'\n", OUT_FILE_NAME); | |
| 638 exit(2); | |
| 639 } | |
| 640 } | |
| 641 /* Go through all the standards */ | |
| 642 /* This assumes standard 0 is NULL, and TDD is the last in the list */ | |
| 643 for (j = 1; j <= ADSI_STANDARD_TDD; j++) | |
| 644 { | |
| 645 printf("Testing %s\n", adsi_standard_to_str(j)); | |
| 646 current_standard = j; | |
| 647 adsi_tx_init(&tx_adsi, j); | |
| 648 adsi_rx_init(&rx_adsi, j, put_adsi_msg, NULL); | |
| 649 | |
| 650 /* Fake an OK condition for the first message test */ | |
| 651 good_message_received = TRUE; | |
| 652 push = 0; | |
| 653 for (i = 0; i < 100000; i++) | |
| 654 { | |
| 655 if (push == 0) | |
| 656 { | |
| 657 if ((len = adsi_tx(&tx_adsi, amp, BLOCK_LEN)) == 0) | |
| 658 push = 10; | |
| 659 } | |
| 660 else | |
| 661 { | |
| 662 len = 0; | |
| 663 /* Push a little silence through, to flush things out */ | |
| 664 if (--push == 0) | |
| 665 { | |
| 666 if (!good_message_received) | |
| 667 { | |
| 668 printf("No message received %s (%d)\n", adsi_standard_to_str(j), i); | |
| 669 exit(2); | |
| 670 } | |
| 671 good_message_received = FALSE; | |
| 672 adsi_msg_len = adsi_create_message(&tx_adsi, adsi_msg); | |
| 673 adsi_msg_len = adsi_put_message(&tx_adsi, adsi_msg, adsi_msg_len); | |
| 674 } | |
| 675 } | |
| 676 if (len < BLOCK_LEN) | |
| 677 { | |
| 678 memset(&[len], 0, sizeof(int16_t)*(BLOCK_LEN - len)); | |
| 679 len = BLOCK_LEN; | |
| 680 } | |
| 681 if (log_audio) | |
| 682 { | |
| 683 outframes = afWriteFrames(outhandle, | |
| 684 AF_DEFAULT_TRACK, | |
| 685 amp, | |
| 686 len); | |
| 687 if (outframes != len) | |
| 688 { | |
| 689 fprintf(stderr, " Error writing wave file\n"); | |
| 690 exit(2); | |
| 691 } | |
| 692 } | |
| 693 adsi_rx(&rx_adsi, amp, len); | |
| 694 } | |
| 695 } | |
| 696 if (log_audio) | |
| 697 { | |
| 698 if (afCloseFile(outhandle) != 0) | |
| 699 { | |
| 700 fprintf(stderr, " Cannot close wave file '%s'\n", OUT_FILE_NAME); | |
| 701 exit(2); | |
| 702 } | |
| 703 afFreeFileSetup(filesetup); | |
| 704 } | |
| 705 } | |
| 706 | |
| 707 printf("Tests passed.\n"); | |
| 708 return 0; | |
| 709 } | |
| 710 /*- End of function --------------------------------------------------------*/ | |
| 711 /*- End of file ------------------------------------------------------------*/ |
