From 8bda12f8bd6d1f779125dc39feefa019a8574dd8 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Sat, 12 Dec 2015 02:21:41 +0000 Subject: [PATCH] echoing back tx OK git-svn-id: https://svn.code.sf.net/p/freetel/code@2520 01035d8c-6547-0410-b346-abe4f91aad63 --- freebeacon/freebeacon.c | 85 +++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/freebeacon/freebeacon.c b/freebeacon/freebeacon.c index 581e23a6..0614f177 100644 --- a/freebeacon/freebeacon.c +++ b/freebeacon/freebeacon.c @@ -23,6 +23,7 @@ [ ] writing to wave files [ ] basic SM1000 version + has audio interfaces + [ ] test mode to tx straight away then end Building: @@ -49,10 +50,8 @@ #include "freedv_api.h" #define MAX_CHAR 80 -#define FS 8000 // 8 kHz sampling rate used for modem -#define SAMPLE_RATE 48000 // 48 kHz sampling rate rec. as we can trust accuracy of sound card -#define N8 160 // processing buffer size at 8 kHz -#define N48 (N8*SAMPLE_RATE/FS) // processing buffer size at 48 kHz +#define FS8 8000 // codec audio sample rate fixed at 8 kHz +#define FS48 48000 // 48 kHz sampling rate rec. as we can trust accuracy of sound card #define SYNC_FRAMES 50 // frames of valid rx /* globals used to communicate with async events */ @@ -97,13 +96,11 @@ int resample(SRC_STATE *src, ) { SRC_DATA src_data; - float input[N48*4]; - float output[N48*4]; + float input[length_input_short]; + float output[length_output_short]; int ret; assert(src != NULL); - assert(length_input_short <= N48*4); - assert(length_output_short <= N48*4); src_short_to_float_array(input_short, input, length_input_short); @@ -113,6 +110,7 @@ int resample(SRC_STATE *src, src_data.output_frames = length_output_short; src_data.end_of_input = 0; src_data.src_ratio = (float)output_sample_rate/input_sample_rate; + //printf("%d %d src_ratio: %f \n", length_input_short, length_output_short, src_data.src_ratio); ret = src_process(src, &src_data); assert(ret == 0); @@ -237,9 +235,6 @@ int main(int argc, char *argv[]) { const PaDeviceInfo *deviceInfo = NULL; PaStream *stream = NULL; PaError err; - short stereo_short[2*N48]; - short in48k_short[N48], out48k_short[N48]; - short in8k_short[N48]; int numDevices, nBufs, n8k, i, j, src_error, inputChannels, nin, devNum; int outputChannels; int state, next_state; @@ -255,6 +250,8 @@ int main(int argc, char *argv[]) { FILE *ftmp; unsigned int sync_counter; + /* debug raw file */ + ftmp = fopen("t.raw", "wb"); assert(ftmp != NULL); @@ -323,10 +320,22 @@ int main(int argc, char *argv[]) { /* Open Sound Device and start processing --------------------------------------------------------------*/ f = freedv_open(FREEDV_MODE_1600); assert(f != NULL); - assert(freedv_get_modem_sample_rate(f) == FS); /* just in case modem FS every changes */ + int fsm = freedv_get_modem_sample_rate(f); /* modem sample rate */ + int n8m = freedv_get_n_nom_modem_samples(f); /* nominal modem sample buffer size at fsm sample rate */ + int n48 = n8m*FS48/fsm; /* nominal modem sample buffer size at 48kHz */ + + printf("fsm: %d n8m: %d n48: %d\n", fsm, n8m, n48); + + short stereo[2*n48]; /* stereo I/O buffer from port audio */ + short rx48k[n48], tx48k[n48]; /* signals at 48 kHz */ + short rxfsm[n48]; /* rx signal at modem sample rate */ + freedv_set_callback_txt(f, callbackNextRxChar, callbackNextTxChar, NULL); - fifo = fifo_create(N48); assert(fifo != NULL); + fifo = fifo_create(4*n8m); assert(fifo != NULL); /* fifo to smooth out variation in demod nin */ + + /* states for sample rate converters */ + rxsrc = src_new(SRC_SINC_FASTEST, 1, &src_error); assert(rxsrc != NULL); txsrc = src_new(SRC_SINC_FASTEST, 1, &src_error); assert(txsrc != NULL); playsrc = src_new(SRC_SINC_FASTEST, 1, &src_error); assert(playsrc != NULL); @@ -372,7 +381,7 @@ int main(int argc, char *argv[]) { &stream, &inputParameters, &outputParameters, - SAMPLE_RATE, + FS48, 0, /* let the driver decide */ paClipOff, NULL, /* no callback, use blocking API */ @@ -407,27 +416,29 @@ int main(int argc, char *argv[]) { /* Read samples, resample to modem sample rate */ - Pa_ReadStream(stream, stereo_short, N48); + Pa_ReadStream(stream, stereo, n48); if (inputChannels == 2) { - for(j=0; j