~ubuntu-branches/ubuntu/saucy/iaxmodem/saucy

« back to all changes in this revision

Viewing changes to lib/spandsp/tests/v27ter_tests.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien BLACHE
  • Date: 2006-10-28 10:54:55 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20061028105455-qdnaih9tmq0uc29w
Tags: 0.1.15~dfsg-1
* New upstream release.
* debian/rules:
  + Use new ~dfsg versionning scheme.
  + Do not remove config.* in get-orig-source.
* debian/patches/11_build_configure-stamp.dpatch:
  + Updated.
* debian/iaxmodem.init:
  + Added LSB header.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 * along with this program; if not, write to the Free Software
24
24
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25
25
 *
26
 
 * $Id: v27ter_tests.c,v 1.55 2006/05/14 08:34:19 steveu Exp $
 
26
 * $Id: v27ter_tests.c,v 1.60 2006/08/22 13:17:56 steveu Exp $
27
27
 */
28
28
 
29
29
/*! \page v27ter_tests_page V.27ter modem tests
59
59
#include <stdio.h>
60
60
#include <fcntl.h>
61
61
#include <string.h>
62
 
#include <math.h>
 
62
#include <tgmath.h>
63
63
#include <assert.h>
64
64
#include <audiofile.h>
65
65
#include <tiffio.h>
68
68
#include "line_model.h"
69
69
#if defined(ENABLE_GUI)
70
70
#include "modem_monitor.h"
 
71
#include "line_model_monitor.h"
71
72
#endif
72
73
 
73
74
#define BLOCK_LEN       160
255
256
    int outframes;
256
257
    int samples;
257
258
    int i;
 
259
    int tep;
258
260
    int test_bps;
259
 
    int tep;
260
261
    int noise_level;
261
262
    int signal_level;
262
263
    int bits_per_test;
263
264
    int line_model_no;
264
265
    int block;
 
266
    int log_audio;
265
267
 
266
268
    test_bps = 4800;
267
269
    tep = FALSE;
268
270
    line_model_no = 0;
269
271
    decode_test_file = NULL;
 
272
    use_gui = FALSE;
270
273
    noise_level = -70;
271
274
    signal_level = -13;
272
275
    bits_per_test = 50000;
 
276
    log_audio = FALSE;
273
277
    for (i = 1;  i < argc;  i++)
274
278
    {
275
279
        if (strcmp(argv[i], "-b") == 0)
292
296
            use_gui = TRUE;
293
297
            continue;
294
298
        }
 
299
        if (strcmp(argv[i], "-l") == 0)
 
300
        {
 
301
            log_audio = TRUE;
 
302
            continue;
 
303
        }
295
304
        if (strcmp(argv[i], "-m") == 0)
296
305
        {
297
306
            line_model_no = atoi(argv[++i]);
317
326
            exit(2);
318
327
        }
319
328
    }
320
 
    if ((filesetup = afNewFileSetup()) == AF_NULL_FILESETUP)
 
329
    filesetup = AF_NULL_FILESETUP;
 
330
    if (log_audio)
321
331
    {
322
 
        fprintf(stderr, "    Failed to create file setup\n");
323
 
        exit(2);
 
332
        if ((filesetup = afNewFileSetup()) == AF_NULL_FILESETUP)
 
333
        {
 
334
            fprintf(stderr, "    Failed to create file setup\n");
 
335
            exit(2);
 
336
        }
 
337
        afInitSampleFormat(filesetup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16);
 
338
        afInitRate(filesetup, AF_DEFAULT_TRACK, (float) SAMPLE_RATE);
 
339
        afInitFileFormat(filesetup, AF_FILE_WAVE);
 
340
        afInitChannels(filesetup, AF_DEFAULT_TRACK, 1);
 
341
        if ((outhandle = afOpenFile(OUT_FILE_NAME, "w", filesetup)) == AF_NULL_FILEHANDLE)
 
342
        {
 
343
            fprintf(stderr, "    Cannot create wave file '%s'\n", OUT_FILE_NAME);
 
344
            exit(2);
 
345
        }
324
346
    }
325
 
    afInitSampleFormat(filesetup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16);
326
 
    afInitRate(filesetup, AF_DEFAULT_TRACK, (float) SAMPLE_RATE);
327
 
    afInitFileFormat(filesetup, AF_FILE_WAVE);
328
 
    afInitChannels(filesetup, AF_DEFAULT_TRACK, 1);
329
347
 
330
348
    inhandle = NULL;
331
349
    outhandle = NULL;
341
359
    else
342
360
    {
343
361
        /* We will generate V.27ter audio, and add some noise to it. */
344
 
        if ((outhandle = afOpenFile(OUT_FILE_NAME, "w", filesetup)) == AF_NULL_FILEHANDLE)
345
 
        {
346
 
            fprintf(stderr, "    Cannot create wave file '%s'\n", OUT_FILE_NAME);
347
 
            exit(2);
348
 
        }
349
 
 
350
362
        v27ter_tx_init(&tx, test_bps, tep, v27tergetbit, NULL);
351
363
        v27ter_tx_power(&tx, signal_level);
352
364
        /* Move the carrier off a bit */
364
376
 
365
377
    v27ter_rx_init(&rx, test_bps, v27terputbit, NULL);
366
378
    v27ter_rx_set_qam_report_handler(&rx, qam_report, (void *) &rx);
367
 
    rx.logging.level = SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW;
368
 
    rx.logging.tag = "V.27ter rx";
 
379
    span_log_set_level(&rx.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW);
 
380
    span_log_set_tag(&rx.logging, "V.27ter-rx");
369
381
 
370
382
#if defined(ENABLE_GUI)
371
383
    if (use_gui)
 
384
    {
372
385
        qam_monitor = qam_monitor_init(2.0, NULL);
 
386
        start_line_model_monitor(129);
 
387
        line_model_monitor_line_model_update(line_model->near_filter, line_model->near_filter_len);
 
388
    }
373
389
#endif
374
390
 
375
391
    memset(&latest_results, 0, sizeof(latest_results));
376
 
    for (block = 0; ;  block++)
 
392
    for (block = 0;  ;  block++)
377
393
    {
378
394
        if (decode_test_file)
379
395
        {
437
453
                }
438
454
            }
439
455
 
440
 
            outframes = afWriteFrames(outhandle,
441
 
                                      AF_DEFAULT_TRACK,
442
 
                                      gen_amp,
443
 
                                      samples);
444
 
            if (outframes != samples)
 
456
            if (log_audio)
445
457
            {
446
 
                fprintf(stderr, "    Error writing wave file\n");
447
 
                exit(2);
 
458
                outframes = afWriteFrames(outhandle,
 
459
                                          AF_DEFAULT_TRACK,
 
460
                                          gen_amp,
 
461
                                          samples);
 
462
                if (outframes != samples)
 
463
                {
 
464
                    fprintf(stderr, "    Error writing wave file\n");
 
465
                    exit(2);
 
466
                }
448
467
            }
449
468
            one_way_line_model(line_model, amp, gen_amp, samples);
450
469
        }
 
470
#if defined(ENABLE_GUI)
 
471
        if (use_gui)
 
472
            line_model_monitor_line_spectrum_update(amp, samples);
 
473
#endif
451
474
        v27ter_rx(&rx, amp, samples);
452
475
        if (decode_test_file == NULL  &&  block%500 == 0)
453
476
            printf("Noise level is %d\n", noise_level);
465
488
        fprintf(stderr, "At completion:\n");
466
489
        fprintf(stderr, "Final result %ddBm0, %d bits, %d bad bits, %d resyncs\n", signal_level, bert_results.total_bits, bert_results.bad_bits, bert_results.resyncs);
467
490
        fprintf(stderr, "Last report  %ddBm0, %d bits, %d bad bits, %d resyncs\n", signal_level, latest_results.total_bits, latest_results.bad_bits, latest_results.resyncs);
468
 
        if (afCloseFile(outhandle))
469
 
        {
470
 
            fprintf(stderr, "    Cannot close wave file '%s'\n", OUT_FILE_NAME);
471
 
            exit(2);
472
 
        }
473
491
        one_way_line_model_release(line_model);
474
492
        if (signal_level > -38)
475
493
        {
479
497
 
480
498
        printf("Tests passed.\n");
481
499
    }
482
 
    afFreeFileSetup(filesetup);
 
500
    if (log_audio)
 
501
    {
 
502
        if (afCloseFile(outhandle))
 
503
        {
 
504
            fprintf(stderr, "    Cannot close wave file '%s'\n", OUT_FILE_NAME);
 
505
            exit(2);
 
506
        }
 
507
        afFreeFileSetup(filesetup);
 
508
    }
483
509
    return  0;
484
510
}
485
511
/*- End of function --------------------------------------------------------*/