awgn_tests_LDADD = $(LIBDIR) -lspandsp
bell_mf_rx_tests_SOURCES = bell_mf_rx_tests.c
-bell_mf_rx_tests_LDADD = $(LIBDIR) -lspandsp
+bell_mf_rx_tests_LDADD = -L$(top_builddir)/spandsp-sim -lspandsp-sim $(LIBDIR) -lspandsp
bell_mf_tx_tests_SOURCES = bell_mf_tx_tests.c
bell_mf_tx_tests_LDADD = -L$(top_builddir)/spandsp-sim -lspandsp-sim $(LIBDIR) -lspandsp
queue_tests_LDADD = $(LIBDIR) -lspandsp
r2_mf_rx_tests_SOURCES = r2_mf_rx_tests.c
-r2_mf_rx_tests_LDADD = $(LIBDIR) -lspandsp
+r2_mf_rx_tests_LDADD = -L$(top_builddir)/spandsp-sim -lspandsp-sim $(LIBDIR) -lspandsp
r2_mf_tx_tests_SOURCES = r2_mf_tx_tests.c
r2_mf_tx_tests_LDADD = -L$(top_builddir)/spandsp-sim -lspandsp-sim $(LIBDIR) -lspandsp
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
+#include <unistd.h>
#include <time.h>
#include <sndfile.h>
#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
#include "spandsp.h"
+#include "spandsp-sim.h"
/* Basic Bell MF specs:
*
#define MF_PAUSE (68*8)
#define MF_CYCLE (MF_DURATION + MF_PAUSE)
+#define SAMPLES_PER_CHUNK 160
+
/*!
MF tone descriptor for tests.
*/
bool callback_ok;
int callback_roll;
+codec_munge_state_t *munge = NULL;
+
+char *decode_test_file = NULL;
+
static void my_mf_gen_init(float low_fudge,
int low_level,
float high_fudge,
}
/*- End of function --------------------------------------------------------*/
-static void codec_munge(int16_t amp[], int len)
-{
- int i;
- uint8_t alaw;
-
- for (i = 0; i < len; i++)
- {
- alaw = linear_to_alaw (amp[i]);
- amp[i] = alaw_to_linear (alaw);
- }
-}
-/*- End of function --------------------------------------------------------*/
-
#define ALL_POSSIBLE_DIGITS "1234567890CA*B#"
static void digit_delivery(void *data, const char *digits, int len)
static int16_t amp[1000000];
-int main(int argc, char *argv[])
+static int test_tone_set(void)
{
- int duration;
int i;
int j;
int len;
int nminus;
float rrb;
float rcfo;
- time_t now;
bell_mf_rx_state_t *mf_state;
awgn_state_t noise_source;
- time(&now);
mf_state = bell_mf_rx_init(NULL, NULL, NULL);
/* Test 1: Mitel's test 1 isn't really a test. Its a calibration step,
for (i = 0; i < 10; i++)
{
len = my_mf_generate(amp, digit);
- codec_munge(amp, len);
+ codec_munge(munge, amp, len);
bell_mf_rx(mf_state, amp, len);
actual = bell_mf_rx_get(mf_state, buf, 128);
if (actual != 1 || buf[0] != digit[0])
{
my_mf_gen_init((float) i/1000.0, -17, 0.0, -17, 68, 68);
len = my_mf_generate(amp, digit);
- codec_munge(amp, len);
+ codec_munge(munge, amp, len);
bell_mf_rx(mf_state, amp, len);
nplus += bell_mf_rx_get(mf_state, buf, 128);
}
{
my_mf_gen_init((float) i/1000.0, -17, 0.0, -17, 68, 68);
len = my_mf_generate(amp, digit);
- codec_munge(amp, len);
+ codec_munge(munge, amp, len);
bell_mf_rx(mf_state, amp, len);
nminus += bell_mf_rx_get(mf_state, buf, 128);
}
{
my_mf_gen_init(0.0, -17, (float) i/1000.0, -17, 68, 68);
len = my_mf_generate(amp, digit);
- codec_munge(amp, len);
+ codec_munge(munge, amp, len);
bell_mf_rx(mf_state, amp, len);
nplus += bell_mf_rx_get(mf_state, buf, 128);
}
{
my_mf_gen_init(0.0, -17, (float) i/1000.0, -17, 68, 68);
len = my_mf_generate(amp, digit);
- codec_munge(amp, len);
+ codec_munge(munge, amp, len);
bell_mf_rx(mf_state, amp, len);
nminus += bell_mf_rx_get(mf_state, buf, 128);
}
my_mf_gen_init(0.0, -5, 0.0, i/10, 68, 68);
len = my_mf_generate(amp, digit);
- codec_munge(amp, len);
+ codec_munge(munge, amp, len);
bell_mf_rx(mf_state, amp, len);
nplus += bell_mf_rx_get(mf_state, buf, 128);
}
my_mf_gen_init(0.0, i/10, 0.0, -5, 68, 68);
len = my_mf_generate(amp, digit);
- codec_munge(amp, len);
+ codec_munge(munge, amp, len);
bell_mf_rx(mf_state, amp, len);
nminus += bell_mf_rx_get(mf_state, buf, 128);
}
for (j = 0; j < 100; j++)
{
len = my_mf_generate(amp, ALL_POSSIBLE_DIGITS);
- codec_munge(amp, len);
+ codec_munge(munge, amp, len);
bell_mf_rx(mf_state, amp, len);
if (bell_mf_rx_get(mf_state, buf, 128) != 15)
break;
for (j = 0; j < 500; j++)
{
len = my_mf_generate(amp, ALL_POSSIBLE_DIGITS);
- codec_munge(amp, len);
+ codec_munge(munge, amp, len);
bell_mf_rx(mf_state, amp, len);
if (bell_mf_rx_get(mf_state, buf, 128) != 15)
break;
len = my_mf_generate(amp, ALL_POSSIBLE_DIGITS);
for (sample = 0; sample < len; sample++)
amp[sample] = sat_add16(amp[sample], awgn(&noise_source));
- codec_munge(amp, len);
+ codec_munge(munge, amp, len);
bell_mf_rx(mf_state, amp, len);
if (bell_mf_rx_get(mf_state, buf, 128) != 15)
break;
}
bell_mf_rx_free(mf_state);
printf(" Passed\n");
+ return 0;
+}
+/*- End of function --------------------------------------------------------*/
+
+static void digit_delivery_decode(void *data, const char *digits, int len)
+{
+ int i;
+
+ if (data != (void *) 0x12345678)
+ {
+ return;
+ }
+ for (i = 0; i < len; i++)
+ {
+ printf("Digit '%c'\n", digits[i]);
+ }
+}
+/*- End of function --------------------------------------------------------*/
+
+static void decode_test(const char *test_file)
+{
+ int16_t amp[SAMPLES_PER_CHUNK];
+ SNDFILE *inhandle;
+ bell_mf_rx_state_t *mf_state;
+ int samples;
- duration = time (NULL) - now;
- printf("Tests passed in %ds\n", duration);
+ mf_state = bell_mf_rx_init(NULL, digit_delivery_decode, (void *) 0x12345678);
+
+ /* We will decode the audio from a file. */
+ if ((inhandle = sf_open_telephony_read(decode_test_file, 1)) == NULL)
+ {
+ fprintf(stderr, " Cannot open audio file '%s'\n", decode_test_file);
+ exit(2);
+ }
+
+ while ((samples = sf_readf_short(inhandle, amp, SAMPLES_PER_CHUNK)) > 0)
+ {
+ codec_munge(munge, amp, samples);
+ bell_mf_rx(mf_state, amp, samples);
+ }
+}
+/*- End of function --------------------------------------------------------*/
+
+int main(int argc, char *argv[])
+{
+ time_t now;
+ time_t duration;
+ decode_test_file = NULL;
+ int opt;
+
+ while ((opt = getopt(argc, argv, "d:")) != -1)
+ {
+ switch (opt)
+ {
+ case 'd':
+ decode_test_file = optarg;
+ break;
+ default:
+ //usage();
+ exit(2);
+ break;
+ }
+ }
+ munge = codec_munge_init(MUNGE_CODEC_ULAW, 0);
+ if (decode_test_file)
+ {
+ decode_test(decode_test_file);
+ }
+ else
+ {
+ now = time(NULL);
+ test_tone_set();
+ duration = time (NULL) - now;
+ printf("Tests passed in %lds\n", duration);
+ }
+ codec_munge_free(munge);
return 0;
}
/*- End of function --------------------------------------------------------*/
printf("0x%x ", msg[i]);
}
printf("\n");
- at_interpreter(&s->at_state, msg, len);
+ at_interpreter(&s->at_state, (const char *) msg, len);
}
/*- End of function --------------------------------------------------------*/
modem->stty = ttyname(modem->slave);
#else
#if defined(WIN32)
- modem->slot = 4 + next_id++; /* need work here we start at COM4 for now*/
+ modem->slot = 4 + next_id++; /* Need work here. We start at COM4 for now */
snprintf(modem->devlink, sizeof(modem->devlink), "COM%d", modem->slot);
modem->master = CreateFile(modem->devlink,
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
+#include <unistd.h>
#include <time.h>
#include <sndfile.h>
#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
#include "spandsp.h"
+#include "spandsp-sim.h"
/* R2 tone generation specs.
* Power: -11.5dBm +- 1dB
#define MF_PAUSE (68*8)
#define MF_CYCLE (MF_DURATION + MF_PAUSE)
+#define SAMPLES_PER_CHUNK 160
+
/*!
MF tone generator descriptor for tests.
*/
int callback_ok;
int callback_roll;
+codec_munge_state_t *munge = NULL;
+
+char *decode_test_file = NULL;
+
static void my_mf_gen_init(float low_fudge,
int low_level,
float high_fudge,
}
/*- End of function --------------------------------------------------------*/
-static void codec_munge(int16_t amp[], int len)
-{
- int i;
- uint8_t alaw;
-
- for (i = 0; i < len; i++)
- {
- alaw = linear_to_alaw (amp[i]);
- amp[i] = alaw_to_linear (alaw);
- }
-}
-/*- End of function --------------------------------------------------------*/
-
static void digit_delivery(void *data, int digit, int level, int delay)
{
char ch;
for (i = 0; i < 10; i++)
{
len = my_mf_generate(amp, digit);
- codec_munge (amp, len);
+ codec_munge(munge, amp, len);
r2_mf_rx(mf_state, amp, len);
actual = r2_mf_rx_get(mf_state);
if (actual != digit)
{
my_mf_gen_init((float) i/1000.0, -17, 0.0, -17, 68, fwd);
len = my_mf_generate(amp, digit);
- codec_munge(amp, len);
+ codec_munge(munge, amp, len);
r2_mf_rx(mf_state, amp, len);
if (r2_mf_rx_get(mf_state) == digit)
nplus++;
{
my_mf_gen_init((float) i/1000.0, -17, 0.0, -17, 68, fwd);
len = my_mf_generate(amp, digit);
- codec_munge(amp, len);
+ codec_munge(munge, amp, len);
r2_mf_rx(mf_state, amp, len);
if (r2_mf_rx_get(mf_state) == digit)
nminus++;
{
my_mf_gen_init(0.0, -17, (float) i/1000.0, -17, 68, fwd);
len = my_mf_generate(amp, digit);
- codec_munge(amp, len);
+ codec_munge(munge, amp, len);
r2_mf_rx(mf_state, amp, len);
if (r2_mf_rx_get(mf_state) == digit)
nplus++;
{
my_mf_gen_init(0.0, -17, (float) i/1000.0, -17, 68, fwd);
len = my_mf_generate(amp, digit);
- codec_munge(amp, len);
+ codec_munge(munge, amp, len);
r2_mf_rx(mf_state, amp, len);
if (r2_mf_rx_get(mf_state) == digit)
nminus++;
my_mf_gen_init(0.0, -5, 0.0, i/10, 68, fwd);
len = my_mf_generate(amp, digit);
- codec_munge (amp, len);
+ codec_munge(munge, amp, len);
r2_mf_rx(mf_state, amp, len);
if (r2_mf_rx_get(mf_state) == digit)
nplus++;
my_mf_gen_init(0.0, i/10, 0.0, -5, 68, fwd);
len = my_mf_generate(amp, digit);
- codec_munge(amp, len);
+ codec_munge(munge, amp, len);
r2_mf_rx(mf_state, amp, len);
if (r2_mf_rx_get(mf_state) == digit)
nminus++;
for (j = 0; j < 100; j++)
{
len = my_mf_generate(amp, digit);
- codec_munge(amp, len);
+ codec_munge(munge, amp, len);
r2_mf_rx(mf_state, amp, len);
if (r2_mf_rx_get(mf_state) != digit)
break;
for (j = 0; j < 500; j++)
{
len = my_mf_generate(amp, digit);
- codec_munge(amp, len);
+ codec_munge(munge, amp, len);
r2_mf_rx(mf_state, amp, len);
if (r2_mf_rx_get(mf_state) != digit)
break;
len = my_mf_generate(amp, digit);
for (sample = 0; sample < len; sample++)
amp[sample] = sat_add16(amp[sample], awgn(noise_source));
- codec_munge(amp, len);
+ codec_munge(munge, amp, len);
r2_mf_rx(mf_state, amp, len);
if (r2_mf_rx_get(mf_state) != digit)
break;
len = my_mf_generate(amp, digit);
for (sample = 0; sample < len; sample++)
amp[sample] = sat_add16(amp[sample], awgn(noise_source));
- codec_munge(amp, len);
+ codec_munge(munge, amp, len);
r2_mf_rx(mf_state, amp, len);
len = 160;
memset(amp, '\0', len*sizeof(int16_t));
for (sample = 0; sample < len; sample++)
amp[sample] = sat_add16(amp[sample], awgn(noise_source));
- codec_munge(amp, len);
+ codec_munge(munge, amp, len);
r2_mf_rx(mf_state, amp, len);
}
awgn_free(noise_source);
}
/*- End of function --------------------------------------------------------*/
+static void digit_delivery_fwd(void *data, int digit, int level, int delay)
+{
+ if (data != (void *) 0x12345678)
+ {
+ callback_ok = false;
+ return;
+ }
+ printf("FWD '%c' %d %d\n", (digit == 0) ? '-' : digit, level, delay);
+}
+/*- End of function --------------------------------------------------------*/
+
+static void digit_delivery_bwd(void *data, int digit, int level, int delay)
+{
+ if (data != (void *) 0x12345678)
+ {
+ callback_ok = false;
+ return;
+ }
+ printf("BWD '%c' %d %d\n", (digit == 0) ? '-' : digit, level, delay);
+}
+/*- End of function --------------------------------------------------------*/
+
+static void decode_test(const char *test_file)
+{
+ int16_t amp[SAMPLES_PER_CHUNK];
+ SNDFILE *inhandle;
+ r2_mf_rx_state_t *mf_fwd_state;
+ r2_mf_rx_state_t *mf_bwd_state;
+ int samples;
+
+ mf_fwd_state = r2_mf_rx_init(NULL, true, digit_delivery_fwd, (void *) 0x12345678);
+ mf_bwd_state = r2_mf_rx_init(NULL, false, digit_delivery_bwd, (void *) 0x12345678);
+
+ /* We will decode the audio from a file. */
+ if ((inhandle = sf_open_telephony_read(decode_test_file, 1)) == NULL)
+ {
+ fprintf(stderr, " Cannot open audio file '%s'\n", decode_test_file);
+ exit(2);
+ }
+
+ while ((samples = sf_readf_short(inhandle, amp, SAMPLES_PER_CHUNK)) > 0)
+ {
+ codec_munge(munge, amp, samples);
+ r2_mf_rx(mf_fwd_state, amp, samples);
+ r2_mf_rx(mf_bwd_state, amp, samples);
+ }
+}
+/*- End of function --------------------------------------------------------*/
+
int main(int argc, char *argv[])
{
time_t now;
time_t duration;
+ decode_test_file = NULL;
+ int opt;
- now = time(NULL);
- printf("R2 forward tones\n");
- test_a_tone_set(true);
- printf("R2 backward tones\n");
- test_a_tone_set(false);
- duration = time(NULL) - now;
- printf("Tests passed in %lds\n", duration);
+ while ((opt = getopt(argc, argv, "d:")) != -1)
+ {
+ switch (opt)
+ {
+ case 'd':
+ decode_test_file = optarg;
+ break;
+ default:
+ //usage();
+ exit(2);
+ break;
+ }
+ }
+ munge = codec_munge_init(MUNGE_CODEC_ALAW, 0);
+ if (decode_test_file)
+ {
+ decode_test(decode_test_file);
+ }
+ else
+ {
+ now = time(NULL);
+ printf("R2 forward tones\n");
+ test_a_tone_set(true);
+ printf("R2 backward tones\n");
+ test_a_tone_set(false);
+ duration = time(NULL) - now;
+ printf("Tests passed in %lds\n", duration);
+ }
+ codec_munge_free(munge);
return 0;
}
/*- End of function --------------------------------------------------------*/
int end_marks;
int res;
int compression;
+ int x_resolution;
+ int y_resolution;
int compression_step;
int min_row_bits;
int block_size;
int i;
int bit_error_rate;
int tests_failed;
+ int match_pos;
bool restart_pages;
bool add_page_headers;
bool overlay_page_headers;
tests_failed = 0;
compression = -1;
compression_step = 0;
+ x_resolution = -1;
+ y_resolution = -1;
add_page_headers = false;
overlay_page_headers = false;
restart_pages = false;
block_size = 1;
bit_error_rate = 0;
dump_as_xxx = false;
- while ((opt = getopt(argc, argv, "b:c:d:ehHri:m:t:x")) != -1)
+ while ((opt = getopt(argc, argv, "b:c:d:ehHrR:i:m:t:x")) != -1)
{
switch (opt)
{
case 'r':
restart_pages = true;
break;
+ case 'R':
+ if (strcmp(optarg, "standard") == 0)
+ {
+ y_resolution = T4_Y_RESOLUTION_STANDARD;
+ }
+ else if (strcmp(optarg, "fine") == 0)
+ {
+ y_resolution = T4_Y_RESOLUTION_FINE;
+ }
+ else if (strcmp(optarg, "superfine") == 0)
+ {
+ y_resolution = T4_Y_RESOLUTION_SUPERFINE;
+ }
+ break;
case 'i':
in_file_name = optarg;
break;
{
if (compression < 0)
compression = T4_COMPRESSION_T4_1D;
+ if (x_resolution < 0)
+ x_resolution = T4_X_RESOLUTION_R8;
+ if (y_resolution < 0)
+ y_resolution = T4_Y_RESOLUTION_STANDARD;
/* Receive end puts TIFF to a new file. We assume the receive width here. */
if ((receive_state = t4_rx_init(NULL, OUT_FILE_NAME, T4_COMPRESSION_T4_2D)) == NULL)
{
}
span_log_set_level(t4_rx_get_logging_state(receive_state), SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW);
t4_rx_set_rx_encoding(receive_state, compression);
- t4_rx_set_x_resolution(receive_state, T4_X_RESOLUTION_R8);
- //t4_rx_set_y_resolution(receive_state, T4_Y_RESOLUTION_FINE);
- t4_rx_set_y_resolution(receive_state, T4_Y_RESOLUTION_STANDARD);
+ t4_rx_set_x_resolution(receive_state, x_resolution);
+ t4_rx_set_y_resolution(receive_state, y_resolution);
t4_rx_set_image_width(receive_state, XSIZE);
t4_rx_start_page(receive_state);
}
end_of_page = t4_rx_put(receive_state, block, i);
}
- else if (sscanf(buf, "%*d:%*d:%*d.%*d T.38 Rx %d: IFP %x %x", &pkt_no, (unsigned int *) &bit, (unsigned int *) &bit) == 3)
+ else if (sscanf(buf, "%*d:%*d:%*d.%*d T.38 Rx %d: IFP %x %x %x %x %x %n", &pkt_no, (unsigned int *) &bit, (unsigned int *) &bit, (unsigned int *) &bit, (unsigned int *) &bit, (unsigned int *) &bit, &match_pos) == 6)
{
/* Useful for breaking up T.38 non-ECM logs */
if (pkt_no != last_pkt_no + 1)
last_pkt_no = pkt_no;
for (i = 0; i < 256; i++)
{
- if (sscanf(&buf[47 + 3*i], "%x", (unsigned int *) &bit) != 1)
+ if (sscanf(&buf[match_pos + 3*i], "%x", (unsigned int *) &bit) != 1)
break;
block[i] = bit_reverse8(bit);
}