added experimental support for stealing bits
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sun, 25 Nov 2012 20:46:33 +0000 (20:46 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sun, 25 Nov 2012 20:46:33 +0000 (20:46 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1067 01035d8c-6547-0410-b346-abe4f91aad63

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

index f1517a60c2d2dea7afd5a21690413b3551d2c331..db5c5ee36631c1de5284683685e8dab5bd5a3d2a 100644 (file)
@@ -659,7 +659,7 @@ void codec2_decode_1400(struct CODEC2 *c2, short speech[], const unsigned char *
        frames */
 
     model[0].voiced = unpack(bits, &nbit, 1);
-
+    
     model[1].voiced = unpack(bits, &nbit, 1);
     WoE_index = unpack(bits, &nbit, WO_E_BITS);
     decode_WoE(&model[1], &e[1], c2->xq_dec, WoE_index);
@@ -1005,7 +1005,7 @@ void ear_protection(float in_out[], int n) {
     }
 }
 
-int CODEC2_WIN32SUPPORT codec2_set_lpc_post_filter(struct CODEC2 *c2, int enable, int bass_boost, float beta, float gamma)
+void CODEC2_WIN32SUPPORT codec2_set_lpc_post_filter(struct CODEC2 *c2, int enable, int bass_boost, float beta, float gamma)
 {
     assert((beta >= 0.0) && (beta <= 1.0));
     assert((gamma >= 0.0) && (gamma <= 1.0));
@@ -1015,3 +1015,45 @@ int CODEC2_WIN32SUPPORT codec2_set_lpc_post_filter(struct CODEC2 *c2, int enable
     c2->gamma = gamma;
 }
 
+/* 
+   Allows optional stealing of one of the voicing bits for use as a
+   spare bit, only 1400 bit/s supported for now.  Experimental method
+   of sending voice/data frames for FreeDV.
+*/
+
+int CODEC2_WIN32SUPPORT codec2_get_spare_bit_index(struct CODEC2 *c2)
+{
+    assert(c2 != NULL);
+
+    if (c2->mode != CODEC2_MODE_1400)
+        return -1;
+    
+    return 10; // bit 10 (11th bit) is v2 (third voicing bit)
+}
+
+/*
+   Reconstructs the spare voicing bit.  Note works on unpacked bits
+   for convenience.
+*/
+
+int CODEC2_WIN32SUPPORT codec2_rebuild_spare_bit(struct CODEC2 *c2, int unpacked_bits[])
+{
+    int v0,v1,v3;
+
+    assert(c2 != NULL);
+
+    if (c2->mode != CODEC2_MODE_1400)
+        return -1;
+
+    v0 = unpacked_bits[0];
+    v1 = unpacked_bits[1];
+    v3 = unpacked_bits[11];
+
+    /* if either adjacent frame is voiced, make this one voiced */
+
+    unpacked_bits[10] = (v1 || v3);  
+
+    return 0;
+}
+
+
index b97fc0dfa1234e17c7ed431094ffe5361cf7065e..8baa307eb620df81fdcf4064363ae87430de9b3d 100644 (file)
@@ -59,7 +59,10 @@ void CODEC2_WIN32SUPPORT codec2_encode(struct CODEC2 *codec2_state, unsigned cha
 void CODEC2_WIN32SUPPORT codec2_decode(struct CODEC2 *codec2_state, short speech_out[], const unsigned char *bits);
 int  CODEC2_WIN32SUPPORT codec2_samples_per_frame(struct CODEC2 *codec2_state);
 int  CODEC2_WIN32SUPPORT codec2_bits_per_frame(struct CODEC2 *codec2_state);
-int  CODEC2_WIN32SUPPORT codec2_set_lpc_post_filter(struct CODEC2 *codec2_state, int enable, int bass_boost, float beta, float gamma);
+
+void CODEC2_WIN32SUPPORT codec2_set_lpc_post_filter(struct CODEC2 *codec2_state, int enable, int bass_boost, float beta, float gamma);
+int  CODEC2_WIN32SUPPORT codec2_get_spare_bit_index(struct CODEC2 *codec2_state);
+int  CODEC2_WIN32SUPPORT codec2_rebuild_spare_bit(struct CODEC2 *codec2_state, int unpacked_bits[]);
 
 #endif