ref: 454d1d0c21a28d899865aa4ae1eafec60be66197
parent: a8734e0fd90c652dcf731cd51aadb00015bc92e0
author: John Ridges <[email protected]>
date: Thu May 21 18:38:39 EDT 2009
This code does a very naive reset of the state. It is possible (even likely) that I'm resetting more than is necessary, but I would have to know a lot more about how CELT works to determine that.
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -866,6 +866,23 @@
st->VBR_rate = ((value<<7)+(st->VBR_rate>>1))/st->VBR_rate;
}
break;
+ case CELT_RESET_STATE:
+ {
+ const CELTMode *mode = st->mode;
+ int C = mode->nbChannels;
+
+ if (st->pitch_available > 0) st->pitch_available = 1;
+
+ CELT_MEMSET(st->in_mem, 0, st->overlap*C);
+ CELT_MEMSET(st->out_mem, 0, (MAX_PERIOD+st->overlap)*C);
+
+ CELT_MEMSET(st->oldBandE, 0, C*mode->nbEBands);
+
+ CELT_MEMSET(st->preemph_memE, 0, C);
+ CELT_MEMSET(st->preemph_memD, 0, C);
+ st->delayedIntra = 1;
+ }
+ break;
default:
goto bad_request;
}
@@ -1220,3 +1237,37 @@
return ret;
}
#endif
+
+int celt_decoder_ctl(CELTDecoder * restrict st, int request, ...)
+{
+ va_list ap;
+ va_start(ap, request);
+ switch (request)
+ {
+ case CELT_RESET_STATE:
+ {
+ const CELTMode *mode = st->mode;
+ int C = mode->nbChannels;
+
+ CELT_MEMSET(st->decode_mem, 0, (DECODE_BUFFER_SIZE+st->overlap)*C);
+ CELT_MEMSET(st->oldBandE, 0, C*mode->nbEBands);
+
+ CELT_MEMSET(st->preemph_memD, 0, C);
+
+ st->last_pitch_index = 0;
+ }
+ break;
+ default:
+ goto bad_request;
+ }
+ va_end(ap);
+ return CELT_OK;
+#if 0 /* Put this back in if you ever need "bad_arg" */
+bad_arg:
+ va_end(ap);
+ return CELT_BAD_ARG;
+#endif
+bad_request:
+ va_end(ap);
+ return CELT_UNIMPLEMENTED;
+}
--- a/libcelt/celt.h
+++ b/libcelt/celt.h
@@ -77,6 +77,9 @@
#define CELT_SET_VBR_RATE_REQUEST 6
/** Set the target VBR rate in bits per second (int); 0=CBR (default) */
#define CELT_SET_VBR_RATE(x) CELT_SET_VBR_RATE_REQUEST, _celt_check_int(x)
+/** Reset the encoder/decoder memories to zero*/
+#define CELT_RESET_STATE_REQUEST 8
+#define CELT_RESET_STATE CELT_RESET_STATE_REQUEST
/** GET the frame size used in the current mode */
#define CELT_GET_FRAME_SIZE 1000
@@ -237,6 +240,15 @@
@return Error code.
*/
EXPORT int celt_decode(CELTDecoder *st, const unsigned char *data, int len, celt_int16_t *pcm);
+
+/** Query and set decoder parameters
+ @param st Decoder state
+ @param request Parameter to change or query
+ @param value Pointer to a 32-bit int value
+ @return Error code
+ */
+EXPORT int celt_decoder_ctl(CELTDecoder * st, int request, ...);
+
/* @} */