{
return g_realloc (ptr, size);
}
+
static inline void
speex_free (void *ptr)
{
}
/* Do the new part */
- ptr = in + st->in_stride * (last_sample - N + 1 + j);
- for (; j < N; j++) {
- sum += MULT16_16 (*ptr, st->sinc_table[samp_frac_num * st->filt_len + j]);
- ptr += st->in_stride;
+ if (in != NULL) {
+ ptr = in + st->in_stride * (last_sample - N + 1 + j);
+ for (; j < N; j++) {
+ sum +=
+ MULT16_16 (*ptr, st->sinc_table[samp_frac_num * st->filt_len + j]);
+ ptr += st->in_stride;
+ }
}
*out = PSHR32 (sum, 15);
}
/* Do the new part */
- ptr = in + st->in_stride * (last_sample - N + 1 + j);
- for (; j < N; j++) {
- sum +=
- MULT16_16 (*ptr,
- (double) st->sinc_table[samp_frac_num * st->filt_len + j]);
- ptr += st->in_stride;
+ if (in != NULL) {
+ ptr = in + st->in_stride * (last_sample - N + 1 + j);
+ for (; j < N; j++) {
+ sum +=
+ MULT16_16 (*ptr,
+ (double) st->sinc_table[samp_frac_num * st->filt_len + j]);
+ ptr += st->in_stride;
+ }
}
*out = sum;
MULT16_16 (curr_mem,
st->sinc_table[4 + (j + 1) * st->oversample - offset + 1]);
}
- ptr = in + st->in_stride * (last_sample - N + 1 + j);
- /* Do the new part */
- for (; j < N; j++) {
- spx_word16_t curr_in = *ptr;
- ptr += st->in_stride;
- accum[0] +=
- MULT16_16 (curr_in,
- st->sinc_table[4 + (j + 1) * st->oversample - offset - 2]);
- accum[1] +=
- MULT16_16 (curr_in,
- st->sinc_table[4 + (j + 1) * st->oversample - offset - 1]);
- accum[2] +=
- MULT16_16 (curr_in,
- st->sinc_table[4 + (j + 1) * st->oversample - offset]);
- accum[3] +=
- MULT16_16 (curr_in,
- st->sinc_table[4 + (j + 1) * st->oversample - offset + 1]);
+ if (in != NULL) {
+ ptr = in + st->in_stride * (last_sample - N + 1 + j);
+ /* Do the new part */
+ for (; j < N; j++) {
+ spx_word16_t curr_in = *ptr;
+
+ ptr += st->in_stride;
+ accum[0] +=
+ MULT16_16 (curr_in,
+ st->sinc_table[4 + (j + 1) * st->oversample - offset - 2]);
+ accum[1] +=
+ MULT16_16 (curr_in,
+ st->sinc_table[4 + (j + 1) * st->oversample - offset - 1]);
+ accum[2] +=
+ MULT16_16 (curr_in,
+ st->sinc_table[4 + (j + 1) * st->oversample - offset]);
+ accum[3] +=
+ MULT16_16 (curr_in,
+ st->sinc_table[4 + (j + 1) * st->oversample - offset + 1]);
+ }
}
cubic_coef (frac, interp);
sum =
MULT16_16 (curr_mem,
st->sinc_table[4 + (j + 1) * st->oversample - offset + 1]);
}
- ptr = in + st->in_stride * (last_sample - N + 1 + j);
- /* Do the new part */
- for (; j < N; j++) {
- double curr_in = *ptr;
-
- ptr += st->in_stride;
- accum[0] +=
- MULT16_16 (curr_in,
- st->sinc_table[4 + (j + 1) * st->oversample - offset - 2]);
- accum[1] +=
- MULT16_16 (curr_in,
- st->sinc_table[4 + (j + 1) * st->oversample - offset - 1]);
- accum[2] +=
- MULT16_16 (curr_in,
- st->sinc_table[4 + (j + 1) * st->oversample - offset]);
- accum[3] +=
- MULT16_16 (curr_in,
- st->sinc_table[4 + (j + 1) * st->oversample - offset + 1]);
+ if (in != NULL) {
+ ptr = in + st->in_stride * (last_sample - N + 1 + j);
+ /* Do the new part */
+ for (; j < N; j++) {
+ double curr_in = *ptr;
+
+ ptr += st->in_stride;
+ accum[0] +=
+ MULT16_16 (curr_in,
+ st->sinc_table[4 + (j + 1) * st->oversample - offset - 2]);
+ accum[1] +=
+ MULT16_16 (curr_in,
+ st->sinc_table[4 + (j + 1) * st->oversample - offset - 1]);
+ accum[2] +=
+ MULT16_16 (curr_in,
+ st->sinc_table[4 + (j + 1) * st->oversample - offset]);
+ accum[3] +=
+ MULT16_16 (curr_in,
+ st->sinc_table[4 + (j + 1) * st->oversample - offset + 1]);
+ }
}
cubic_coef (frac, interp);
sum =
for (j = 0; j < N - 1 - (spx_int32_t) * in_len; j++)
mem[j] = mem[j + *in_len];
- for (; j < N - 1; j++)
- mem[j] = in[st->in_stride * (j + *in_len - N + 1)];
-
+ if (in != NULL) {
+ for (; j < N - 1; j++)
+ mem[j] = in[st->in_stride * (j + *in_len - N + 1)];
+ } else {
+ for (; j < N - 1; j++)
+ mem[j] = 0;
+ }
return RESAMPLER_ERR_SUCCESS;
}
ALLOC(y, *out_len, spx_word16_t); */
istride_save = st->in_stride;
ostride_save = st->out_stride;
- for (i = 0; i < *in_len; i++)
- x[i] = WORD2INT (in[i * st->in_stride]);
- st->in_stride = st->out_stride = 1;
- speex_resampler_process_native (st, channel_index, x, in_len, y, out_len);
+ if (in != NULL) {
+ for (i = 0; i < *in_len; i++)
+ x[i] = WORD2INT (in[i * st->in_stride]);
+ st->in_stride = st->out_stride = 1;
+ speex_resampler_process_native (st, channel_index, x, in_len, y, out_len);
+ } else {
+ st->in_stride = st->out_stride = 1;
+ speex_resampler_process_native (st, channel_index, NULL, in_len, y,
+ out_len);
+ }
st->in_stride = istride_save;
st->out_stride = ostride_save;
for (i = 0; i < *out_len; i++)
ichunk = FIXED_STACK_ALLOC;
if (ochunk > FIXED_STACK_ALLOC)
ochunk = FIXED_STACK_ALLOC;
- for (i = 0; i < ichunk; i++)
- x[i] = WORD2INT (in[i * st->in_stride]);
- st->in_stride = st->out_stride = 1;
- speex_resampler_process_native (st, channel_index, x, &ichunk, y, &ochunk);
+ if (in != NULL) {
+ for (i = 0; i < ichunk; i++)
+ x[i] = WORD2INT (in[i * st->in_stride]);
+ st->in_stride = st->out_stride = 1;
+ speex_resampler_process_native (st, channel_index, x, &ichunk, y,
+ &ochunk);
+ } else {
+ st->in_stride = st->out_stride = 1;
+ speex_resampler_process_native (st, channel_index, NULL, &ichunk, y,
+ &ochunk);
+ }
st->in_stride = istride_save;
st->out_stride = ostride_save;
for (i = 0; i < ochunk; i++)
ALLOC(y, *out_len, spx_word16_t); */
istride_save = st->in_stride;
ostride_save = st->out_stride;
- for (i = 0; i < *in_len; i++)
- x[i] = in[i * st->in_stride];
- st->in_stride = st->out_stride = 1;
- speex_resampler_process_native (st, channel_index, x, in_len, y, out_len);
+ if (in != NULL) {
+ for (i = 0; i < *in_len; i++)
+ x[i] = in[i * st->in_stride];
+ st->in_stride = st->out_stride = 1;
+ speex_resampler_process_native (st, channel_index, x, in_len, y, out_len);
+ } else {
+ st->in_stride = st->out_stride = 1;
+ speex_resampler_process_native (st, channel_index, NULL, in_len, y,
+ out_len);
+ }
st->in_stride = istride_save;
st->out_stride = ostride_save;
for (i = 0; i < *out_len; i++)
ichunk = FIXED_STACK_ALLOC;
if (ochunk > FIXED_STACK_ALLOC)
ochunk = FIXED_STACK_ALLOC;
- for (i = 0; i < ichunk; i++)
- x[i] = in[i * st->in_stride];
- st->in_stride = st->out_stride = 1;
- speex_resampler_process_native (st, channel_index, x, &ichunk, y, &ochunk);
+ if (in != NULL) {
+ for (i = 0; i < ichunk; i++)
+ x[i] = in[i * st->in_stride];
+ st->in_stride = st->out_stride = 1;
+ speex_resampler_process_native (st, channel_index, x, &ichunk, y,
+ &ochunk);
+ } else {
+ st->in_stride = st->out_stride = 1;
+ speex_resampler_process_native (st, channel_index, NULL, &ichunk, y,
+ &ochunk);
+ }
st->in_stride = istride_save;
st->out_stride = ostride_save;
for (i = 0; i < ochunk; i++)
st->in_stride = st->out_stride = st->nb_channels;
for (i = 0; i < st->nb_channels; i++) {
*out_len = bak_len;
- speex_resampler_process_float (st, i, in + i, in_len, out + i, out_len);
+ if (in != NULL)
+ speex_resampler_process_float (st, i, in + i, in_len, out + i, out_len);
+ else
+ speex_resampler_process_float (st, i, NULL, in_len, out + i, out_len);
}
st->in_stride = istride_save;
st->out_stride = ostride_save;
st->in_stride = st->out_stride = st->nb_channels;
for (i = 0; i < st->nb_channels; i++) {
*out_len = bak_len;
- speex_resampler_process_int (st, i, in + i, in_len, out + i, out_len);
+ if (in != NULL)
+ speex_resampler_process_int (st, i, in + i, in_len, out + i, out_len);
+ else
+ speex_resampler_process_int (st, i, NULL, in_len, out + i, out_len);
}
st->in_stride = istride_save;
st->out_stride = ostride_save;
}
int
-speex_resampler_get_latency (SpeexResamplerState * st)
+speex_resampler_get_input_latency (SpeexResamplerState * st)
{
return st->filt_len / 2;
}
int
-speex_resampler_drain_float (SpeexResamplerState * st,
- spx_uint32_t channel_index, float *out, spx_uint32_t * out_len)
+speex_resampler_get_output_latency (SpeexResamplerState * st)
{
- spx_uint32_t in_len;
- int ret;
- float *in;
-
- in_len = speex_resampler_get_latency (st);
-
- in = speex_alloc (sizeof (float) * in_len);
- *out_len =
- MIN (in_len * st->den_rate + (st->num_rate >> 1) / st->num_rate,
- *out_len);
-
- ret =
- speex_resampler_process_float (st, channel_index, in, &in_len, out,
- out_len);
-
- speex_free (in);
-
- speex_resampler_reset_mem (st);
-
- return ret;
-}
-
-int
-speex_resampler_drain_int (SpeexResamplerState * st,
- spx_uint32_t channel_index, spx_int16_t * out, spx_uint32_t * out_len)
-{
- spx_uint32_t in_len;
- int ret;
- spx_int16_t *in;
-
- in_len = speex_resampler_get_latency (st);
-
- in = speex_alloc (sizeof (spx_int16_t) * in_len);
- *out_len =
- MIN (in_len * st->den_rate + (st->num_rate >> 1) / st->num_rate,
- *out_len);
-
- ret =
- speex_resampler_process_int (st, channel_index, in, &in_len, out,
- out_len);
-
- speex_free (in);
-
- speex_resampler_reset_mem (st);
-
- return ret;
-}
-
-int
-speex_resampler_drain_interleaved_float (SpeexResamplerState * st,
- float *out, spx_uint32_t * out_len)
-{
- spx_uint32_t i;
- int istride_save, ostride_save;
- spx_uint32_t bak_len;
- spx_uint32_t in_len;
- float *in;
-
- in_len = speex_resampler_get_latency (st);
-
- in = speex_alloc (sizeof (float) * in_len);
- *out_len =
- MIN (in_len * st->den_rate + (st->num_rate >> 1) / st->num_rate,
- *out_len);
- bak_len = *out_len;
-
- istride_save = st->in_stride;
- ostride_save = st->out_stride;
- st->in_stride = 1;
- st->out_stride = st->nb_channels;
- for (i = 0; i < st->nb_channels; i++) {
- *out_len = bak_len;
- speex_resampler_process_float (st, i, in, &in_len, out + i, out_len);
- }
- st->in_stride = istride_save;
- st->out_stride = ostride_save;
-
- speex_free (in);
-
- speex_resampler_reset_mem (st);
-
- return RESAMPLER_ERR_SUCCESS;
-}
-
-int
-speex_resampler_drain_interleaved_int (SpeexResamplerState * st,
- spx_int16_t * out, spx_uint32_t * out_len)
-{
- spx_uint32_t i;
- int istride_save, ostride_save;
- spx_uint32_t bak_len;
- spx_uint32_t in_len;
- spx_int16_t *in;
-
- in_len = speex_resampler_get_latency (st);
-
- in = speex_alloc (sizeof (spx_int16_t) * in_len);
- *out_len =
- MIN (in_len * st->den_rate + (st->num_rate >> 1) / st->num_rate,
- *out_len);
- bak_len = *out_len;
-
- istride_save = st->in_stride;
- ostride_save = st->out_stride;
- st->in_stride = 1;
- st->out_stride = st->nb_channels;
- for (i = 0; i < st->nb_channels; i++) {
- *out_len = bak_len;
- speex_resampler_process_int (st, i, in, &in_len, out + i, out_len);
- }
- st->in_stride = istride_save;
- st->out_stride = ostride_save;
-
- speex_free (in);
-
- speex_resampler_reset_mem (st);
-
- return RESAMPLER_ERR_SUCCESS;
+ return ((st->filt_len / 2) * st->den_rate +
+ (st->num_rate >> 1)) / st->num_rate;
}
int
#define speex_resampler_get_input_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_stride)
#define speex_resampler_set_output_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_set_output_stride)
#define speex_resampler_get_output_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_get_output_stride)
-#define speex_resampler_get_latency CAT_PREFIX(RANDOM_PREFIX,_resampler_get_latency)
-#define speex_resampler_drain_float CAT_PREFIX(RANDOM_PREFIX,_resampler_drain_float)
-#define speex_resampler_drain_int CAT_PREFIX(RANDOM_PREFIX,_resampler_drain_int)
-#define speex_resampler_drain_interleaved_float CAT_PREFIX(RANDOM_PREFIX,_resampler_drain_interleaved_float)
-#define speex_resampler_drain_interleaved_int CAT_PREFIX(RANDOM_PREFIX,_resampler_drain_interleaved_int)
+#define speex_resampler_get_input_latency CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_latency)
+#define speex_resampler_get_output_latency CAT_PREFIX(RANDOM_PREFIX,_resampler_get_output_latency)
#define speex_resampler_skip_zeros CAT_PREFIX(RANDOM_PREFIX,_resampler_skip_zeros)
#define speex_resampler_reset_mem CAT_PREFIX(RANDOM_PREFIX,_resampler_reset_mem)
#define speex_resampler_strerror CAT_PREFIX(RANDOM_PREFIX,_resampler_strerror)
/** Get the input stride.
* @param st Resampler state
- * @param stride Input stride
+ * @param stride Input stride copied
*/
void speex_resampler_get_input_stride(SpeexResamplerState *st,
spx_uint32_t *stride);
spx_uint32_t stride);
/** Get the output stride.
- * @param st Resampler state
+ * @param st Resampler state copied
* @param stride Output stride
*/
void speex_resampler_get_output_stride(SpeexResamplerState *st,
/** Get the latency in input samples introduced by the resampler.
* @param st Resampler state
*/
-int speex_resampler_get_latency(SpeexResamplerState *st);
+int speex_resampler_get_input_latency(SpeexResamplerState *st);
-/**
- * Outputs the remaining samples into a float array.
- * @param st Resampler state
- * @param channel_index Index of the channel to process for the multi-channel
- * base (0 otherwise)
- * of samples processed
- * @param out Output buffer
- * @param out_len Size of the output buffer. Returns the number of samples written
- */
-int speex_resampler_drain_float(SpeexResamplerState *st,
- spx_uint32_t channel_index,
- float *out,
- spx_uint32_t *out_len);
-/**
- * Outputs the remaining samples into an int array.
- * @param st Resampler state
- * @param channel_index Index of the channel to process for the multi-channel
- * base (0 otherwise)
- * of samples processed
- * @param out Output buffer
- * @param out_len Size of the output buffer. Returns the number of samples written
- */
-int speex_resampler_drain_int(SpeexResamplerState *st,
- spx_uint32_t channel_index,
- spx_int16_t *out,
- spx_uint32_t *out_len);
-/**
- * Outputs the remaining samples into a float array.
- * @param st Resampler state
- * @param channel_index Index of the channel to process for the multi-channel
- * base (0 otherwise)
- * of samples processed
- * @param out Output buffer
- * @param out_len Size of the output buffer. Returns the number of samples written
- */
-int speex_resampler_drain_interleaved_float(SpeexResamplerState *st,
- float *out,
- spx_uint32_t *out_len);
-/**
- * Outputs the remaining samples into an int array.
+/** Get the latency in output samples introduced by the resampler.
* @param st Resampler state
- * @param channel_index Index of the channel to process for the multi-channel
- * base (0 otherwise)
- * of samples processed
- * @param out Output buffer
- * @param out_len Size of the output buffer. Returns the number of samples written
*/
-int speex_resampler_drain_interleaved_int(SpeexResamplerState *st,
- spx_int16_t *out,
- spx_uint32_t *out_len);
+int speex_resampler_get_output_latency(SpeexResamplerState *st);
/** Make sure that the first samples to go out of the resamplers don't have
* leading zeros. This is only useful before starting to use a newly created