First version of in-band signalling and user callbacks
authorjmvalin <jmvalin@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Wed, 2 Oct 2002 22:49:30 +0000 (22:49 +0000)
committerjmvalin <jmvalin@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Wed, 2 Oct 2002 22:49:30 +0000 (22:49 +0000)
git-svn-id: http://svn.xiph.org/trunk/speex@3969 0101bb08-14d6-0310-b084-bc0e0c8e3800

libspeex/nb_celp.c
libspeex/nb_celp.h
libspeex/speex_callbacks.c
libspeex/speex_callbacks.h

index 6ae4d2d..232584d 100644 (file)
@@ -31,6 +31,7 @@
 #include "speex_bits.h"
 #include "vbr.h"
 #include "misc.h"
+#include "speex_callbacks.h"
 
 extern int training_weight;
 #ifndef M_PI
@@ -756,6 +757,13 @@ void *nb_decoder_init(SpeexMode *m)
    st->pi_gain = speex_alloc(st->nbSubframes*sizeof(float));
    st->last_pitch = 40;
    st->count_lost=0;
+
+
+   st->user_callback.func = &speex_default_user_handler;
+   st->user_callback.data = NULL;
+   for (i=0;i<16;i++)
+      st->speex_callbacks[i].func = NULL;
+
    return st;
 }
 
@@ -865,11 +873,18 @@ int nb_decode(void *state, SpeexBits *bits, float *out)
    m = speex_bits_peek_unsigned(bits, 5);
    if (m==15)
    {
+      speex_bits_unpack_unsigned(bits, 5);
       return -1;
    } else if (m==14)
    {
-      int req_size = speex_bits_unpack_unsigned(bits, 6);
-      speex_bits_advance(bits, 8*req_size);
+      int ret = speex_inband_handler(bits, st->speex_callbacks, state);
+      if (ret)
+         return ret;
+   } else if (m==13)
+   {
+      int ret = st->user_callback.func(bits, state, st->user_callback.data);
+      if (ret)
+         return ret;
    } else if (m>7)
    {
       return -2;
index 6ef5ded..80405f6 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "modes.h"
 #include "speex_bits.h"
+#include "speex_callbacks.h"
 #include "vbr.h"
 
 /**Structure representing the full state of the narrowband encoder*/
@@ -127,6 +128,10 @@ typedef struct DecState {
    SpeexSubmode **submodes; /**< Sub-mode data */
    int    submodeID;      /**< Activated sub-mode */
    int    lpc_enh_enabled; /**< 1 when LPC enhancer is on, 0 otherwise */
+
+   SpeexCallback speex_callbacks[SPEEX_MAX_CALLBACKS];
+
+   SpeexCallback user_callback;
 } DecState;
 
 /** Initializes encoder state*/
index fa2fab8..dc0cf61 100644 (file)
 
 #include "speex_callbacks.h"
 
-int speex_inband_handler(void *state, void *data)
+int speex_inband_handler(SpeexBits *bits, SpeexCallback *callback_list, void *state)
 {
+   int id;
+   SpeexCallback *callback;
+
+   id=speex_bits_unpack_unsigned(bits, 4);
+   callback = callback_list+id;
+
+   if (callback->func)
+   {
+      return callback->func(bits, state, callback->data);
+   } else
+   {
+      int adv;
+      if (id<4)
+         adv = 4;
+      else if (id<8)
+         adv = 8;
+      else if (id<12)
+         adv = 16;
+      else if (id<14)
+         adv = 32;
+      else 
+         adv = 64;
+      speex_bits_advance(bits, adv);
+   }
+   return 0;
+}
+
+int speex_std_mode_request_handler(SpeexBits *bits, void *state, void *data)
+{
+   return 0;
 }
 
-int speex_std_mode_request_handler(void *state, void *data)
+int speex_std_high_mode_request_handler(SpeexBits *bits, void *state, void *data)
 {
+   return 0;
 }
 
-int speex_std_high_mode_request_handler(void *state, void *data)
+int speex_std_vbr_quality_request_handler(SpeexBits *bits, void *state, void *data)
 {
+   return 0;
 }
 
-int speex_std_char_handler(void *state, void *data)
+
+int speex_std_char_handler(SpeexBits *bits, void *state, void *data)
+{
+   return 0;
+}
+
+
+
+int speex_default_user_handler(SpeexBits *bits, void *state, void *data)
 {
+   int req_size = speex_bits_unpack_unsigned(bits, 6);
+   speex_bits_advance(bits, 5+8*req_size);
+   return 0;
 }
index c161b6e..3a3dc5b 100644 (file)
 extern "C" {
 #endif
 
+#define SPEEX_MAX_CALLBACKS 16
+
+
 #define SPEEX_INBAND_MODE_REQUEST        0
 #define SPEEX_INBAND_HIGH_MODE_REQUEST   1
 #define SPEEX_INBAND_CHAR                2
 
 
-typedef int (*speex_callback_func)(void *state, void *data);
+typedef int (*speex_callback_func)(SpeexBits *bits, void *state, void *data);
 
 typedef struct SpeexCallback {
    int callback_id;
@@ -42,13 +45,16 @@ typedef struct SpeexCallback {
    void *data;
 } SpeexCallback;
 
-int speex_inband_handler(void *state, void *data);
+int speex_inband_handler(SpeexBits *bits, SpeexCallback *callback_list, void *state);
+
+int speex_std_mode_request_handler(SpeexBits *bits, void *state, void *data);
+
+int speex_std_high_mode_request_handler(SpeexBits *bits, void *state, void *data);
 
-int speex_std_mode_request_handler(void *state, void *data);
+int speex_std_char_handler(SpeexBits *bits, void *state, void *data);
 
-int speex_std_high_mode_request_handler(void *state, void *data);
 
-int speex_std_char_handler(void *state, void *data);
+int speex_default_user_handler(SpeexBits *bits, void *state, void *data);
 
 #ifdef __cplusplus
 }