提交 32f70174 authored 作者: Steve Underwood's avatar Steve Underwood

Tweaks to spandsp tests

上级 62f21d8d
/*
* SpanDSP - a series of DSP components for telephony
*
* fax_tests.c
* fax_tests.c - Tests for the audio and T.38 FAX modules.
*
* Written by Steve Underwood <steveu@coppice.org>
*
* Copyright (C) 2003 Steve Underwood
* Copyright (C) 2005, 2006, 2009, 2010 Steve Underwood
*
* All rights reserved.
*
......@@ -23,6 +23,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*! \file */
/*! \page fax_tests_page FAX tests
\section fax_tests_page_sec_1 What does it do?
\section fax_tests_page_sec_2 How does it work?
......@@ -33,11 +35,16 @@
#endif
#include <stdlib.h>
#include <inttypes.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <sndfile.h>
#if !defined(_WIN32)
#include <unistd.h>
#endif
//#if defined(WITH_SPANDSP_INTERNALS)
#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
......@@ -206,6 +213,7 @@ int main(int argc, char *argv[])
time_t end_time;
int scan_line_time;
char *page_header_info;
char *page_header_tz;
int opt;
t30_state_t *t30;
logging_state_t *logging;
......@@ -218,6 +226,7 @@ int main(int argc, char *argv[])
use_tep = FALSE;
polled_mode = FALSE;
page_header_info = NULL;
page_header_tz = NULL;
reverse_flow = FALSE;
use_transmit_on_idle = TRUE;
use_receiver_not_ready = FALSE;
......@@ -226,7 +235,7 @@ int main(int argc, char *argv[])
noise_level = -99;
scan_line_time = 0;
supported_modems = T30_SUPPORT_V27TER | T30_SUPPORT_V29 | T30_SUPPORT_V17;
while ((opt = getopt(argc, argv, "ehH:i:I:lm:n:prRs:S:tTw:")) != -1)
while ((opt = getopt(argc, argv, "ehH:i:I:lm:n:prRs:S:tTw:z:")) != -1)
{
switch (opt)
{
......@@ -278,6 +287,9 @@ int main(int argc, char *argv[])
case 'w':
t30_state_to_wreck = atoi(optarg);
break;
case 'z':
page_header_tz = optarg;
break;
default:
//usage();
exit(2);
......@@ -335,6 +347,8 @@ int main(int argc, char *argv[])
t30_set_tx_polled_sub_address(t30, "Polled sub-address");
t30_set_tx_selective_polling_address(t30, "Selective polling address");
t30_set_tx_page_header_info(t30, page_header_info);
if (page_header_tz)
t30_set_tx_page_header_tz(t30, page_header_tz);
t30_set_tx_nsf(t30, (const uint8_t *) "\x50\x00\x00\x00Spandsp\x00", 12);
t30_set_ecm_capability(t30, use_ecm);
t30_set_supported_t30_features(t30,
......
......@@ -18,8 +18,8 @@
run_fax_test()
{
rm -f fax_tests_1.tif
echo -i ${FILE} ${OPTS}
./fax_tests -i ${FILE} ${OPTS} >xyzzy 2>xyzzy2
echo ./fax_tests ${OPTS} -i ${FILE}
./fax_tests ${OPTS} -i ${FILE} >xyzzy 2>xyzzy2
RETVAL=$?
if [ $RETVAL != 0 ]
then
......
......@@ -131,8 +131,8 @@ int main(int argc, char *argv[])
int16_t noise_sound[8830];
int16_t silence_sound[8192];
int i;
int outframes;
int voiced_length;
int randy;
double f;
double pk;
double ms;
......@@ -155,6 +155,18 @@ int main(int argc, char *argv[])
}
printf("Generate C1\n");
/* The sequence is
48.62ms of voiced sound from table C.1 of G.168
200.0ms of pseudo-noise
101.38ms of silence
The above is then repeated phase inverted.
The voice comes straight from C.1, repeated enough times to
fill out the 48.62ms period - i.e. 16 copies of the sequence.
The pseudo noise section is random numbers filtered by the spectral
pattern in Figure C.2 */
/* The set of C1 voice samples is ready for use in the output file. */
voiced_length = sizeof(css_c1)/sizeof(css_c1[0]);
for (i = 0; i < voiced_length; i++)
......@@ -208,13 +220,12 @@ int main(int argc, char *argv[])
#else
scale = 0.0;
#endif
randy = ((rand() >> 10) & 0x1) ? 1.0 : -1.0;
#if defined(HAVE_FFTW3_H)
in[i][0] = ((rand() >> 10) & 0x1) ? 1.0 : -1.0;
in[i][0] *= pow(10.0, scale/20.0)*35.0; //305360
in[i][0] = randy*pow(10.0, scale/20.0)*35.0;
in[8192 - i][0] = -in[i][0];
#else
in[i].re = ((rand() >> 10) & 0x1) ? 1.0 : -1.0;
in[i].re *= pow(10.0, scale/20.0)*35.0; //305360
in[i].re = randy*pow(10.0, scale/20.0)*35.0;
in[8192 - i].re = -in[i].re;
#endif
}
......@@ -233,38 +244,34 @@ int main(int argc, char *argv[])
}
pk = peak(noise_sound, 8192);
ms = rms(noise_sound, 8192);
printf("Noise level = %.2fdB, crest factor = %.2fdB\n", rms_to_dbm0(ms), rms_to_db(pk/ms));
printf("Filtered noise level = %.2fdB, crest factor = %.2fdB\n", rms_to_dbm0(ms), rms_to_db(pk/ms));
for (i = 0; i < 8192; i++)
silence_sound[i] = 0.0;
for (i = 0; i < 16; i++)
outframes = sf_writef_short(filehandle, voiced_sound, voiced_length);
sf_writef_short(filehandle, voiced_sound, voiced_length);
printf("%d samples of voice\n", 16*voiced_length);
outframes = sf_writef_short(filehandle, noise_sound, 8192);
outframes = sf_writef_short(filehandle, noise_sound, C1_NOISE_SAMPLES - 8192);
sf_writef_short(filehandle, noise_sound, 8192);
sf_writef_short(filehandle, noise_sound, C1_NOISE_SAMPLES - 8192);
printf("%d samples of noise\n", C1_NOISE_SAMPLES);
outframes = sf_writef_short(filehandle, silence_sound, C1_SILENCE_SAMPLES);
sf_writef_short(filehandle, silence_sound, C1_SILENCE_SAMPLES);
printf("%d samples of silence\n", C1_SILENCE_SAMPLES);
/* Now phase invert the C1 set of voice samples. */
/* Now phase invert the C1 set of samples. */
voiced_length = sizeof(css_c1)/sizeof(css_c1[0]);
for (i = 0; i < voiced_length; i++)
voiced_sound[i] = -css_c1[i];
pk = peak(voiced_sound, voiced_length);
ms = rms(voiced_sound, voiced_length);
printf("Voiced level = %.2fdB, crest factor = %.2fdB\n", rms_to_dbm0(ms), rms_to_db(pk/ms));
for (i = 0; i < 8192; i++)
noise_sound[i] = -noise_sound[i];
for (i = 0; i < 16; i++)
outframes = sf_writef_short(filehandle, voiced_sound, voiced_length);
sf_writef_short(filehandle, voiced_sound, voiced_length);
printf("%d samples of voice\n", 16*voiced_length);
outframes = sf_writef_short(filehandle, noise_sound, 8192);
outframes = sf_writef_short(filehandle, noise_sound, C1_NOISE_SAMPLES - 8192);
sf_writef_short(filehandle, noise_sound, 8192);
sf_writef_short(filehandle, noise_sound, C1_NOISE_SAMPLES - 8192);
printf("%d samples of noise\n", C1_NOISE_SAMPLES);
outframes = sf_writef_short(filehandle, silence_sound, C1_SILENCE_SAMPLES);
sf_writef_short(filehandle, silence_sound, C1_SILENCE_SAMPLES);
printf("%d samples of silence\n", C1_SILENCE_SAMPLES);
if (sf_close(filehandle))
......@@ -287,6 +294,21 @@ int main(int argc, char *argv[])
}
printf("Generate C3\n");
/* The sequence is
72.69ms of voiced sound from table C.3 of G.168
200.0ms of pseudo-noise
127.31ms of silence
The above is then repeated phase inverted.
The voice comes straight from C.3, repeated enough times to
fill out the 72.69ms period - i.e. 14 copies of the sequence.
The pseudo noise section is AWGN filtered by the spectral
pattern in Figure C.2. Since AWGN has the quality of being its
own Fourier transform, we can use an approach like the one above
for the C1 signal, using AWGN samples instead of randomly alternating
ones and zeros. */
/* Take the supplied set of C3 voice samples. */
voiced_length = (sizeof(css_c3)/sizeof(css_c3[0]));
for (i = 0; i < voiced_length; i++)
......@@ -300,37 +322,102 @@ int main(int argc, char *argv[])
noise_sound[i] = awgn(&noise_source);
pk = peak(noise_sound, 8192);
ms = rms(noise_sound, 8192);
printf("Noise level = %.2fdB, crest factor = %.2fdB\n", rms_to_dbm0(ms), rms_to_db(pk/ms));
printf("Unfiltered noise level = %.2fdB, crest factor = %.2fdB\n", rms_to_dbm0(ms), rms_to_db(pk/ms));
/* Now filter them */
#if defined(HAVE_FFTW3_H)
p = fftw_plan_dft_1d(8192, in, out, FFTW_BACKWARD, FFTW_ESTIMATE);
#else
p = fftw_create_plan(8192, FFTW_BACKWARD, FFTW_ESTIMATE);
#endif
for (i = 0; i < 8192; i++)
{
#if defined(HAVE_FFTW3_H)
in[i][0] = 0.0;
in[i][1] = 0.0;
#else
in[i].re = 0.0;
in[i].im = 0.0;
#endif
}
for (i = 1; i <= 3715; i++)
{
f = FAST_SAMPLE_RATE*i/8192.0;
#if 1
if (f < 50.0)
scale = -60.0;
else if (f < 100.0)
scale = scaling(f, 50.0, 100.0, -25.8, -12.8);
else if (f < 200.0)
scale = scaling(f, 100.0, 200.0, -12.8, 17.4);
else if (f < 215.0)
scale = scaling(f, 200.0, 215.0, 17.4, 17.8);
else if (f < 500.0)
scale = scaling(f, 215.0, 500.0, 17.8, 12.2);
else if (f < 1000.0)
scale = scaling(f, 500.0, 1000.0, 12.2, 7.2);
else if (f < 2850.0)
scale = scaling(f, 1000.0, 2850.0, 7.2, 0.0);
else if (f < 3600.0)
scale = scaling(f, 2850.0, 3600.0, 0.0, -2.0);
else if (f < 3660.0)
scale = scaling(f, 3600.0, 3660.0, -2.0, -20.0);
else if (f < 3680.0)
scale = scaling(f, 3600.0, 3680.0, -20.0, -30.0);
else
scale = -60.0;
#else
scale = 0.0;
#endif
#if defined(HAVE_FFTW3_H)
in[i][0] = noise_sound[i]*pow(10.0, scale/20.0)*0.0106;
in[8192 - i][0] = -in[i][0];
#else
in[i].re = noise_sound[i]*pow(10.0, scale/20.0)*0.0106;
in[8192 - i].re = -in[i].re;
#endif
}
#if defined(HAVE_FFTW3_H)
fftw_execute(p);
#else
fftw_one(p, in, out);
#endif
for (i = 0; i < 8192; i++)
{
#if defined(HAVE_FFTW3_H)
noise_sound[i] = out[i][1];
#else
noise_sound[i] = out[i].im;
#endif
}
pk = peak(noise_sound, 8192);
ms = rms(noise_sound, 8192);
printf("Filtered noise level = %.2fdB, crest factor = %.2fdB\n", rms_to_dbm0(ms), rms_to_db(pk/ms));
for (i = 0; i < 14; i++)
outframes = sf_writef_short(filehandle, voiced_sound, voiced_length);
sf_writef_short(filehandle, voiced_sound, voiced_length);
printf("%d samples of voice\n", 14*voiced_length);
outframes = sf_writef_short(filehandle, noise_sound, 8192);
outframes = sf_writef_short(filehandle, noise_sound, C3_NOISE_SAMPLES - 8192);
sf_writef_short(filehandle, noise_sound, 8192);
sf_writef_short(filehandle, noise_sound, C3_NOISE_SAMPLES - 8192);
printf("%d samples of noise\n", C3_NOISE_SAMPLES);
outframes = sf_writef_short(filehandle, silence_sound, C3_SILENCE_SAMPLES);
sf_writef_short(filehandle, silence_sound, C3_SILENCE_SAMPLES);
printf("%d samples of silence\n", C3_SILENCE_SAMPLES);
/* Now phase invert the set of voice samples. */
/* Now phase invert the C3 set of samples. */
voiced_length = (sizeof(css_c3)/sizeof(css_c3[0]));
for (i = 0; i < voiced_length; i++)
voiced_sound[i] = -css_c3[i];
pk = peak(voiced_sound, voiced_length);
ms = rms(voiced_sound, voiced_length);
printf("Voiced level = %.2fdB, crest factor = %.2fdB\n", rms_to_dbm0(ms), rms_to_db(pk/ms));
/* Now phase invert the set of noise samples. */
for (i = 0; i < 8192; i++)
noise_sound[i] = -noise_sound[i];
for (i = 0; i < 14; i++)
outframes = sf_writef_short(filehandle, voiced_sound, voiced_length);
printf("%d samples of voice\n", 14*i);
outframes = sf_writef_short(filehandle, noise_sound, 8192);
outframes = sf_writef_short(filehandle, noise_sound, C3_NOISE_SAMPLES - 8192);
sf_writef_short(filehandle, voiced_sound, voiced_length);
printf("%d samples of voice\n", 14*voiced_length);
sf_writef_short(filehandle, noise_sound, 8192);
sf_writef_short(filehandle, noise_sound, C3_NOISE_SAMPLES - 8192);
printf("%d samples of noise\n", C3_NOISE_SAMPLES);
outframes = sf_writef_short(filehandle, silence_sound, C3_SILENCE_SAMPLES);
sf_writef_short(filehandle, silence_sound, C3_SILENCE_SAMPLES);
printf("%d samples of silence\n", C3_SILENCE_SAMPLES);
if (sf_close(filehandle))
......
......@@ -334,6 +334,15 @@ then
fi
echo lpc10_tests completed OK
./math_fixed_tests >$STDOUT_DEST 2>$STDERR_DEST
RETVAL=$?
if [ $RETVAL != 0 ]
then
echo math_fixed_tests failed!
exit $RETVAL
fi
echo math_fixed_tests completed OK
./modem_echo_tests >$STDOUT_DEST 2>$STDERR_DEST
RETVAL=$?
if [ $RETVAL != 0 ]
......
......@@ -311,6 +311,7 @@ int main(int argc, char *argv[])
const char *in_file_name;
const char *decode_file_name;
const char *page_header_tz;
tz_t tz;
int opt;
int i;
int bit_error_rate;
......@@ -678,7 +679,10 @@ int main(int argc, char *argv[])
else
t4_tx_set_header_info(&send_state, NULL);
if (page_header_tz && page_header_tz[0])
t4_tx_set_header_tz(&send_state, page_header_tz);
{
if (tz_init(&tz, page_header_tz))
t4_tx_set_header_tz(&send_state, &tz);
}
//t4_tx_set_header_overlays_image(&send_state, overlay_page_headers);
if (restart_pages && (sends & 1))
{
......
......@@ -82,7 +82,7 @@ int main(int argc, char *argv[])
printf("Generated %d samples\n", len);
if (len <= 0)
break;
outframes = sf_writef_short(outhandle, amp, len);
sf_writef_short(outhandle, amp, len);
}
/* Try a different tone pair */
......@@ -104,7 +104,7 @@ int main(int argc, char *argv[])
printf("Generated %d samples\n", len);
if (len <= 0)
break;
outframes = sf_writef_short(outhandle, amp, len);
sf_writef_short(outhandle, amp, len);
}
/* Try a different tone pair */
......@@ -126,7 +126,7 @@ int main(int argc, char *argv[])
printf("Generated %d samples\n", len);
if (len <= 0)
break;
outframes = sf_writef_short(outhandle, amp, len);
sf_writef_short(outhandle, amp, len);
}
/* Try a single tone */
......@@ -148,7 +148,7 @@ int main(int argc, char *argv[])
printf("Generated %d samples\n", len);
if (len <= 0)
break;
outframes = sf_writef_short(outhandle, amp, len);
sf_writef_short(outhandle, amp, len);
}
/* Try a single non-repeating tone */
......@@ -170,7 +170,7 @@ int main(int argc, char *argv[])
printf("Generated %d samples\n", len);
if (len <= 0)
break;
outframes = sf_writef_short(outhandle, amp, len);
sf_writef_short(outhandle, amp, len);
}
/* Try a single non-repeating tone at 0dBm0 */
......@@ -192,7 +192,7 @@ int main(int argc, char *argv[])
printf("Generated %d samples\n", len);
if (len <= 0)
break;
outframes = sf_writef_short(outhandle, amp, len);
sf_writef_short(outhandle, amp, len);
}
/* Try an AM modulated tone at a modest modulation level (25%) */
......@@ -214,7 +214,7 @@ int main(int argc, char *argv[])
printf("Generated %d samples\n", len);
if (len <= 0)
break;
outframes = sf_writef_short(outhandle, amp, len);
sf_writef_short(outhandle, amp, len);
}
/* Try an AM modulated tone at maximum modulation level (100%) */
......@@ -236,7 +236,7 @@ int main(int argc, char *argv[])
printf("Generated %d samples\n", len);
if (len <= 0)
break;
outframes = sf_writef_short(outhandle, amp, len);
sf_writef_short(outhandle, amp, len);
}
if (sf_close_telephony(outhandle))
......
差异被折叠。
......@@ -119,17 +119,17 @@ static void reporter(void *user_data, int reason, bert_results_t *results)
static void v17_rx_status(void *user_data, int status)
{
v17_rx_state_t *rx;
v17_rx_state_t *s;
int i;
int len;
complexf_t *coeffs;
printf("V.17 rx status is %s (%d)\n", signal_status_to_str(status), status);
rx = (v17_rx_state_t *) user_data;
s = (v17_rx_state_t *) user_data;
switch (status)
{
case SIG_STATUS_TRAINING_SUCCEEDED:
len = v17_rx_equalizer_state(rx, &coeffs);
len = v17_rx_equalizer_state(s, &coeffs);
printf("Equalizer:\n");
for (i = 0; i < len; i++)
printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i]));
......@@ -140,15 +140,12 @@ static void v17_rx_status(void *user_data, int status)
static void v17putbit(void *user_data, int bit)
{
v17_rx_state_t *rx;
if (bit < 0)
{
v17_rx_status(user_data, bit);
return;
}
rx = (v17_rx_state_t *) user_data;
if (decode_test_file)
printf("Rx bit %d - %d\n", rx_bits++, bit);
else
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论