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

« back to all changes in this revision

Viewing changes to lib/spandsp/tests/fsk_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: fsk_tests.c,v 1.23 2006/05/05 10:51:53 steveu Exp $
 
26
 * $Id: fsk_tests.c,v 1.25 2006/06/25 11:07:38 steveu Exp $
27
27
 */
28
28
 
29
29
/*! \page fsk_tests_page FSK modem tests
170
170
    int line_model_no;
171
171
    int modem_under_test_1;
172
172
    int modem_under_test_2;
 
173
    int log_audio;
173
174
 
174
175
    line_model_no = 0;
175
176
    decode_test_file = NULL;
176
177
    noise_sweep = FALSE;
177
178
    modem_under_test_1 = FSK_V21CH1;
178
179
    modem_under_test_2 = FSK_V21CH2;
 
180
    log_audio = FALSE;
179
181
    for (i = 1;  i < argc;  i++)
180
182
    {
181
183
        if (strcmp(argv[i], "-d") == 0)
203
205
            noise_sweep = TRUE;
204
206
            continue;
205
207
        }
 
208
        if (strcmp(argv[i], "-l") == 0)
 
209
        {
 
210
            log_audio = TRUE;
 
211
            continue;
 
212
        }
206
213
    }
207
 
    if ((filesetup = afNewFileSetup()) == AF_NULL_FILESETUP)
 
214
 
 
215
    filesetup = AF_NULL_FILESETUP;
 
216
    outhandle = AF_NULL_FILEHANDLE;
 
217
 
 
218
    if (log_audio)
208
219
    {
209
 
        fprintf(stderr, "    Failed to create file setup\n");
210
 
        exit(2);
 
220
        if ((filesetup = afNewFileSetup()) == AF_NULL_FILESETUP)
 
221
        {
 
222
            fprintf(stderr, "    Failed to create file setup\n");
 
223
            exit(2);
 
224
        }
 
225
        afInitSampleFormat(filesetup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16);
 
226
        afInitRate(filesetup, AF_DEFAULT_TRACK, (float) SAMPLE_RATE);
 
227
        afInitFileFormat(filesetup, AF_FILE_WAVE);
 
228
        afInitChannels(filesetup, AF_DEFAULT_TRACK, 2);
211
229
    }
212
 
    afInitSampleFormat(filesetup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16);
213
 
    afInitRate(filesetup, AF_DEFAULT_TRACK, (float) SAMPLE_RATE);
214
 
    afInitFileFormat(filesetup, AF_FILE_WAVE);
215
 
    afInitChannels(filesetup, AF_DEFAULT_TRACK, 2);
216
 
 
217
230
    noise_level = -200;
218
231
    bits_per_test = 0;
219
232
    inhandle = NULL;
224
237
            fprintf(stderr, "    Cannot open wave file '%s'\n", decode_test_file);
225
238
            exit(2);
226
239
        }
227
 
        fsk_rx_init(&caller_rx, &preset_fsk_specs[modem_under_test_1], TRUE, put_bit, NULL);
 
240
        fsk_rx_init(&caller_rx, &preset_fsk_specs[modem_under_test_1], TRUE, 0, put_bit, NULL);
228
241
        test_bps = preset_fsk_specs[modem_under_test_1].baud_rate;
229
242
    }
230
243
    else
233
246
        if (modem_under_test_1 >= 0)
234
247
        {
235
248
            fsk_tx_init(&caller_tx, &preset_fsk_specs[modem_under_test_1], (get_bit_func_t) bert_get_bit, &caller_bert);
236
 
            fsk_rx_init(&answerer_rx, &preset_fsk_specs[modem_under_test_1], TRUE, (put_bit_func_t) bert_put_bit, &answerer_bert);
 
249
            fsk_rx_init(&answerer_rx, &preset_fsk_specs[modem_under_test_1], TRUE, 0, (put_bit_func_t) bert_put_bit, &answerer_bert);
237
250
        }
238
251
        if (modem_under_test_2 >= 0)
239
252
        {
240
253
            fsk_tx_init(&answerer_tx, &preset_fsk_specs[modem_under_test_2], (get_bit_func_t) bert_get_bit, &answerer_bert);
241
 
            fsk_rx_init(&caller_rx, &preset_fsk_specs[modem_under_test_2], TRUE, (put_bit_func_t) bert_put_bit, &caller_bert);
 
254
            fsk_rx_init(&caller_rx, &preset_fsk_specs[modem_under_test_2], TRUE, 0, (put_bit_func_t) bert_put_bit, &caller_bert);
242
255
        }
243
256
        test_bps = preset_fsk_specs[modem_under_test_1].baud_rate;
244
257
 
255
268
            exit(2);
256
269
        }
257
270
    }
258
 
    if ((outhandle = afOpenFile(OUTPUT_FILE_NAME, "w", filesetup)) == AF_NULL_FILEHANDLE)
 
271
    if (log_audio)
259
272
    {
260
 
        fprintf(stderr, "    Cannot create wave file '%s'\n", OUTPUT_FILE_NAME);
261
 
        exit(2);
 
273
        if ((outhandle = afOpenFile(OUTPUT_FILE_NAME, "w", filesetup)) == AF_NULL_FILEHANDLE)
 
274
        {
 
275
            fprintf(stderr, "    Cannot create wave file '%s'\n", OUTPUT_FILE_NAME);
 
276
            exit(2);
 
277
        }
262
278
    }
263
279
 
264
280
    if (modem_under_test_1 >= 0)
312
328
            out_amp[2*i + 1] = answerer_model_amp[i];
313
329
        for (  ;  i < BLOCK_LEN;  i++)
314
330
            out_amp[2*i + 1] = 0;
315
 
 
316
 
        outframes = afWriteFrames(outhandle,
317
 
                                  AF_DEFAULT_TRACK,
318
 
                                  out_amp,
319
 
                                  BLOCK_LEN);
320
 
        if (outframes != BLOCK_LEN)
 
331
        
 
332
        if (log_audio)
321
333
        {
322
 
            fprintf(stderr, "    Error writing wave file\n");
323
 
            exit(2);
 
334
            outframes = afWriteFrames(outhandle,
 
335
                                      AF_DEFAULT_TRACK,
 
336
                                      out_amp,
 
337
                                      BLOCK_LEN);
 
338
            if (outframes != BLOCK_LEN)
 
339
            {
 
340
                fprintf(stderr, "    Error writing wave file\n");
 
341
                exit(2);
 
342
            }
324
343
        }
325
344
 
326
345
        if (samples < BLOCK_LEN)
357
376
 
358
377
            /* Put a little silence between the chunks in the file. */
359
378
            memset(out_amp, 0, sizeof(out_amp));
360
 
            for (i = 0;  i < 200;  i++)
 
379
            if (log_audio)
361
380
            {
362
 
                outframes = afWriteFrames(outhandle,
363
 
                                          AF_DEFAULT_TRACK,
364
 
                                          out_amp,
365
 
                                          BLOCK_LEN);
 
381
                for (i = 0;  i < 200;  i++)
 
382
                {
 
383
                    outframes = afWriteFrames(outhandle,
 
384
                                              AF_DEFAULT_TRACK,
 
385
                                              out_amp,
 
386
                                              BLOCK_LEN);
 
387
                }
366
388
            }
367
389
            if (modem_under_test_1 >= 0)
368
390
            {
369
391
                fsk_tx_init(&caller_tx, &preset_fsk_specs[modem_under_test_1], (get_bit_func_t) bert_get_bit, &caller_bert);
370
 
                fsk_rx_init(&answerer_rx, &preset_fsk_specs[modem_under_test_1], TRUE, (put_bit_func_t) bert_put_bit, &answerer_bert);
 
392
                fsk_rx_init(&answerer_rx, &preset_fsk_specs[modem_under_test_1], TRUE, 0, (put_bit_func_t) bert_put_bit, &answerer_bert);
371
393
            }
372
394
            if (modem_under_test_2 >= 0)
373
395
            {
374
396
                fsk_tx_init(&answerer_tx, &preset_fsk_specs[modem_under_test_2], (get_bit_func_t) bert_get_bit, &answerer_bert);
375
 
                fsk_rx_init(&caller_rx, &preset_fsk_specs[modem_under_test_2], TRUE, (put_bit_func_t) bert_put_bit, &caller_bert);
 
397
                fsk_rx_init(&caller_rx, &preset_fsk_specs[modem_under_test_2], TRUE, 0, (put_bit_func_t) bert_put_bit, &caller_bert);
376
398
            }
377
399
            noise_level++;
378
400
            if ((model = both_ways_line_model_init(line_model_no, noise_level, line_model_no, noise_level)) == NULL)
387
409
        }
388
410
    }
389
411
 
390
 
    if (afCloseFile(outhandle) != 0)
 
412
    if (log_audio)
391
413
    {
392
 
        fprintf(stderr, "    Cannot close wave file '%s'\n", OUTPUT_FILE_NAME);
393
 
        exit(2);
 
414
        if (afCloseFile(outhandle) != 0)
 
415
        {
 
416
            fprintf(stderr, "    Cannot close wave file '%s'\n", OUTPUT_FILE_NAME);
 
417
            exit(2);
 
418
        }
 
419
        afFreeFileSetup(filesetup);
394
420
    }
395
421
    if (decode_test_file)
396
422
    {
404
430
    {
405
431
        printf("Tests passed.\n");
406
432
    }
407
 
    afFreeFileSetup(filesetup);
408
433
    return  0;
409
434
}
410
435
/*- End of function --------------------------------------------------------*/