tweaks to API for freedv integration, not tested yet
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 11 Jun 2015 02:34:32 +0000 (02:34 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 11 Jun 2015 02:34:32 +0000 (02:34 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2180 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/freedv_api.c
codec2-dev/src/freedv_api.h
codec2-dev/src/varicode.c
codec2-dev/src/varicode.h

index 921d2f0dc41a5bb6a1ec0e4ab5fbf15d1be7c220..1a21fb832118ed1fac45b1da3cab8064b6ce5857 100644 (file)
@@ -288,8 +288,8 @@ int freedv_nin(struct freedv *f) {
 
 int freedv_rx(struct freedv *f, short speech_out[], short demod_in[]) {
 
-float rxdata[FDMDV_MAX_SAMPLES_PER_FRAME];
-int i;
+    float rxdata[FDMDV_MAX_SAMPLES_PER_FRAME];
+    int i;
 
     for(i=0; i<f->nin; i++)
         rxdata[i] = (float)demod_in[i]/FDMDV_SCALE;
@@ -299,10 +299,23 @@ int i;
 }
 
 
-// float version
+// float input samples version
 
 int freedv_floatrx(struct freedv *f, short speech_out[], float demod_in[]) {
-    COMP                rx_fdm[FDMDV_MAX_SAMPLES_PER_FRAME];
+    COMP rx_fdm[FDMDV_MAX_SAMPLES_PER_FRAME];
+    int  i;
+
+    for(i=0; i<f->nin; i++) {
+        rx_fdm[i].real = demod_in[i];
+        rx_fdm[i].imag = 0;
+    }
+
+    return freedv_comprx(f, speech_out, rx_fdm);
+}
+
+// complex input samples version
+
+int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) {
     int                 bits_per_codec_frame, bytes_per_codec_frame, bits_per_fdmdv_frame;
     int                 reliable_sync_bit, i, j, bit, byte, nin_prev, nout;
     int                 recd_codeword, codeword1, data_flag_index, n_ascii;
@@ -313,13 +326,8 @@ int freedv_floatrx(struct freedv *f, short speech_out[], float demod_in[]) {
     bytes_per_codec_frame = (bits_per_codec_frame + 7) / 8;
     bits_per_fdmdv_frame  = fdmdv_bits_per_frame(f->fdmdv);
 
-    for(i=0; i<f->nin; i++) {
-        rx_fdm[i].real = demod_in[i];
-        rx_fdm[i].imag = 0;
-    }
-
     nin_prev = f->nin;
-    fdmdv_demod(f->fdmdv, f->fdmdv_bits, &reliable_sync_bit, rx_fdm, &f->nin);
+    fdmdv_demod(f->fdmdv, f->fdmdv_bits, &reliable_sync_bit, demod_in, &f->nin);
     fdmdv_get_demod_stats(f->fdmdv, &f->fdmdv_stats);
 
     if (f->fdmdv_stats.sync) {
@@ -405,10 +413,61 @@ int freedv_floatrx(struct freedv *f, short speech_out[], float demod_in[]) {
         /* if not in sync pass through analog samples */
         /* this lets us "hear" whats going on, e.g. during tuning */
         for(i=0; i<nin_prev; i++)
-            speech_out[i] = FDMDV_SCALE*demod_in[i];
+            speech_out[i] = FDMDV_SCALE*demod_in[i].real;
         nout = nin_prev;
     }
 
     return nout;
 }
 
+
+#ifdef TODO
+                if (g_testFrames) {
+                    int bit_errors, ntest_bits, test_frame_sync;
+
+                    // test frame processing, g_test_frame_sync will be asserted when we detect a
+                    // valid test frame.
+
+                    fdmdv_put_test_bits(g_pFDMDV, &test_frame_sync, g_error_pattern, &bit_errors, &ntest_bits, codec_bits);
+
+                    if (test_frame_sync == 1) {
+                        g_test_frame_sync_state = 1;
+                        g_test_frame_count = 0;
+                    }
+
+                    if (g_test_frame_sync_state) {
+                        if (g_test_frame_count == 0) {
+                            //printf("bit_errors: %d ntest_bits: %d\n", bit_errors, ntest_bits);
+                            g_total_bit_errors += bit_errors;
+                            g_total_bits       += ntest_bits;
+                            fifo_write(g_errorFifo, g_error_pattern, g_sz_error_pattern);
+                        }
+                        g_test_frame_count++;
+                        if (g_test_frame_count == 4)
+                            g_test_frame_count = 0;
+                    }
+
+                    fdmdv_put_test_bits(g_pFDMDV, &test_frame_sync, g_error_pattern, &bit_errors, &ntest_bits, &codec_bits[bits_per_fdmdv_frame]);
+
+                    if (test_frame_sync == 1) {
+                        g_test_frame_sync_state = 1;
+                        g_test_frame_count = 0;
+                    }
+
+                    if (g_test_frame_sync_state) {
+                        if (g_test_frame_count == 0) {
+                            //printf("bit_errors: %d ntest_bits: %d\n", bit_errors, ntest_bits);
+                            g_total_bit_errors += bit_errors;
+                            g_total_bits       += ntest_bits;
+                            fifo_write(g_errorFifo, g_error_pattern, g_sz_error_pattern);
+                        }
+                        g_test_frame_count++;
+                        if (g_test_frame_count == 4)
+                            g_test_frame_count = 0;
+                    }
+
+                    // silent audio
+
+                    for(i=0; i<2*N8; i++)
+                        output_buf[i] = 0;
+#endif
index 77a5e3d7957511df72201107d9a5afbeb903c721..1dbe867781f99acd9b6156a55d4d317f0b224673 100644 (file)
   along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
 
+#ifdef __cplusplus
+  extern "C" {
+#endif
+
 #ifndef __FREEDV__
 
 #define FREEDV_MODE_1600        0
+#define FREEDV_MODE_700         1
 #define FREEDV_NSAMPLES       320
 
 #include "varicode.h"
@@ -39,7 +44,7 @@
 struct freedv {
     int                  mode;
 
-    void                *codec2;
+    struct CODEC2       *codec2;
     struct FDMDV        *fdmdv;
     struct FDMDV_STATS   fdmdv_stats;
 
@@ -75,5 +80,10 @@ void freedv_tx(struct freedv *f, short mod_out[], short speech_in[]);
 int freedv_nin(struct freedv *f);
 int freedv_rx(struct freedv *f, short speech_out[], short demod_in[]);
 int freedv_floatrx(struct freedv *f, short speech_out[], float demod_in[]);
+int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]);
+
+#endif
 
+#ifdef __cplusplus
+}
 #endif
index 26de09a67acf561a43d57a67477a5965ceb17ed3..21f7cce1b98b01f959aebad61aaf39e74e285bd8 100644 (file)
@@ -168,6 +168,13 @@ void varicode_decode_init(struct VARICODE_DEC *dec_states, int code_num)
 }
 
 
+void varicode_set_code_num(struct VARICODE_DEC *dec_states, int code_num)
+{
+    assert((code_num == 1) || (code_num == 2));
+    dec_states->code_num = code_num;
+}
+
+
 /* Code 1 decode function, accepts one bit at a time */
 
 static int decode_one_bit(struct VARICODE_DEC *s, char *single_ascii, short varicode_in, int long_code)
index 4834a95c861f40d8b8427dea6992788c582d11c1..625d1e7ef5c106ac217f3c4afa8122412717375b 100644 (file)
@@ -43,6 +43,7 @@ struct VARICODE_DEC {
 int varicode_encode(short varicode_out[], char ascii_in[], int max_out, int n_in, int code_num);
 void varicode_decode_init(struct VARICODE_DEC *dec_states, int code_num);
 int varicode_decode(struct VARICODE_DEC *dec_states, char ascii_out[], short varicode_in[], int max_out, int n_in);
+void varicode_set_code_num(struct VARICODE_DEC *dec_states, int code_num);
 
 #ifdef __cplusplus
 }