Mercurial > hg > audiostuff
comparison spandsp-0.0.6pre17/tests/swept_tone_tests.c @ 4:26cd8f1ef0b1
import spandsp-0.0.6pre17
| author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
|---|---|
| date | Fri, 25 Jun 2010 15:50:58 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 3:c6c5a16ce2f2 | 4:26cd8f1ef0b1 |
|---|---|
| 1 /* | |
| 2 * SpanDSP - a series of DSP components for telephony | |
| 3 * | |
| 4 * swept_tone_tests.c | |
| 5 * | |
| 6 * Written by Steve Underwood <steveu@coppice.org> | |
| 7 * | |
| 8 * Copyright (C) 2009 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: swept_tone_tests.c,v 1.2 2009/09/22 13:28:18 steveu Exp $ | |
| 26 */ | |
| 27 | |
| 28 /*! \file */ | |
| 29 | |
| 30 #if defined(HAVE_CONFIG_H) | |
| 31 #include "config.h" | |
| 32 #endif | |
| 33 | |
| 34 #include <stdlib.h> | |
| 35 #include <stdio.h> | |
| 36 #include <fcntl.h> | |
| 37 #include <memory.h> | |
| 38 #include <sndfile.h> | |
| 39 | |
| 40 #include "spandsp.h" | |
| 41 #include "spandsp-sim.h" | |
| 42 | |
| 43 #define OUTPUT_FILE_NAME "swept_tone.wav" | |
| 44 | |
| 45 #define BLOCK_LEN 160 | |
| 46 | |
| 47 int main(int argc, char *argv[]) | |
| 48 { | |
| 49 int i; | |
| 50 int j; | |
| 51 int outframes; | |
| 52 int len; | |
| 53 SNDFILE *outhandle; | |
| 54 power_meter_t meter; | |
| 55 swept_tone_state_t *s; | |
| 56 int16_t buf[BLOCK_LEN]; | |
| 57 | |
| 58 power_meter_init(&meter, 10); | |
| 59 | |
| 60 if ((outhandle = sf_open_telephony_write(OUTPUT_FILE_NAME, 1)) == NULL) | |
| 61 { | |
| 62 fprintf(stderr, " Cannot create audio file '%s'\n", OUTPUT_FILE_NAME); | |
| 63 exit(2); | |
| 64 } | |
| 65 | |
| 66 printf("Test with swept tone.\n"); | |
| 67 s = swept_tone_init(NULL, 200.0f, 3900.0f, -10.0f, 60*SAMPLE_RATE, 1); | |
| 68 for (j = 0; j < 60*SAMPLE_RATE; j += BLOCK_LEN) | |
| 69 { | |
| 70 len = swept_tone(s, buf, BLOCK_LEN); | |
| 71 for (i = 0; i < len; i++) | |
| 72 power_meter_update(&meter, buf[i]); | |
| 73 outframes = sf_writef_short(outhandle, buf, len); | |
| 74 if (outframes != len) | |
| 75 { | |
| 76 fprintf(stderr, " Error writing audio file\n"); | |
| 77 exit(2); | |
| 78 } | |
| 79 #if 0 | |
| 80 printf("Current freq %.1fHz, Level is %fdBOv/%fdBm0\n", | |
| 81 swept_tone_current_frequency(s), | |
| 82 power_meter_current_dbov(&meter), | |
| 83 power_meter_current_dbm0(&meter)); | |
| 84 #else | |
| 85 printf("%.1f %f\n", | |
| 86 swept_tone_current_frequency(s), | |
| 87 power_meter_current_dbm0(&meter)); | |
| 88 #endif | |
| 89 } | |
| 90 | |
| 91 if (sf_close(outhandle) != 0) | |
| 92 { | |
| 93 fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_FILE_NAME); | |
| 94 exit(2); | |
| 95 } | |
| 96 | |
| 97 printf("Tests passed.\n"); | |
| 98 return 0; | |
| 99 } | |
| 100 /*- End of function --------------------------------------------------------*/ | |
| 101 /*- End of file ------------------------------------------------------------*/ |
