Media Project Phase2: SILK 8khz-24khz, SLINEAR 8khz-192khz, SPEEX 32khz, hd audio...
[asterisk/asterisk.git] / funcs / func_speex.c
index 4b8b3a3..51cea99 100644 (file)
@@ -105,6 +105,7 @@ struct speex_direction_info {
 
 struct speex_info {
        struct ast_audiohook audiohook;
+       int lastrate;
        struct speex_direction_info *tx, *rx;
 };
 
@@ -163,12 +164,13 @@ static int speex_callback(struct ast_audiohook *audiohook, struct ast_channel *c
                return -1;
        }
 
-       if (sdi->samples != frame->samples) {
+       if ((sdi->samples != frame->samples) || (ast_format_rate(&frame->subclass.format) != si->lastrate)) {
+               si->lastrate = ast_format_rate(&frame->subclass.format);
                if (sdi->state) {
                        speex_preprocess_state_destroy(sdi->state);
                }
 
-               if (!(sdi->state = speex_preprocess_state_init((sdi->samples = frame->samples), 8000))) {
+               if (!(sdi->state = speex_preprocess_state_init((sdi->samples = frame->samples), si->lastrate))) {
                        return -1;
                }
 
@@ -212,9 +214,9 @@ static int speex_write(struct ast_channel *chan, const char *cmd, char *data, co
                        return 0;
                }
 
-               ast_audiohook_init(&si->audiohook, AST_AUDIOHOOK_TYPE_MANIPULATE, "speex");
+               ast_audiohook_init(&si->audiohook, AST_AUDIOHOOK_TYPE_MANIPULATE, "speex", AST_AUDIOHOOK_MANIPULATE_ALL_RATES);
                si->audiohook.manipulate_callback = speex_callback;
-
+               si->lastrate = 8000;
                is_new = 1;
        } else {
                ast_channel_unlock(chan);