diff --git a/libcelt/celt.c b/libcelt/celt.c index 6a80aaa814aaa8d542f2256956680ed9645992d7..7e25e73294f34f500daae591747812aefb7e9e0f 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -650,10 +650,10 @@ static int alloc_trim_analysis(const CELTMode *m, const celt_norm *X, } #ifdef FIXED_POINT -int celt_encode_with_ec(CELTEncoder * restrict st, const celt_int16 * pcm, celt_int16 * optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc) +int celt_encode_with_ec(CELTEncoder * restrict st, const celt_int16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc) { #else -int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig * optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc) +int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc) { #endif int i, c, N; @@ -816,7 +816,11 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, c RESTORE_STACK; } - resynth = optional_resynthesis!=NULL; +#ifdef RESYNTH + resynth = 1; +#else + resynth = 0; +#endif if (st->complexity > 1 && LM>0) { @@ -1054,12 +1058,7 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, c st->prefilter_gain, gain1, st->mode->window, st->mode->overlap); } - /* De-emphasis and put everything back at the right place - in the synthesis history */ - if (optional_resynthesis != NULL) { - deemphasis(out_mem, optional_resynthesis, N, C, st->mode->preemph, st->preemph_memD); - - } + deemphasis(out_mem, (celt_word16*)pcm, N, C, st->mode->preemph, st->preemph_memD); } #endif @@ -1081,7 +1080,7 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, c #ifdef FIXED_POINT #ifndef DISABLE_FLOAT_API -int celt_encode_with_ec_float(CELTEncoder * restrict st, const float * pcm, float * optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc) +int celt_encode_with_ec_float(CELTEncoder * restrict st, const float * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc) { int j, ret, C, N, LM, M; VARDECL(celt_int16, in); @@ -1104,20 +1103,18 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const float * pcm, floa for (j=0;j<C*N;j++) in[j] = FLOAT2INT16(pcm[j]); - if (optional_resynthesis != NULL) { - ret=celt_encode_with_ec(st,in,in,frame_size,compressed,nbCompressedBytes, enc); - for (j=0;j<C*N;j++) - optional_resynthesis[j]=in[j]*(1.f/32768.f); - } else { - ret=celt_encode_with_ec(st,in,NULL,frame_size,compressed,nbCompressedBytes, enc); - } + ret=celt_encode_with_ec(st,in,frame_size,compressed,nbCompressedBytes, enc); +#ifdef RESYNTH + for (j=0;j<C*N;j++) + ((float*)pcm)[j]=in[j]*(1.f/32768.f); +#endif RESTORE_STACK; return ret; } #endif /*DISABLE_FLOAT_API*/ #else -int celt_encode_with_ec(CELTEncoder * restrict st, const celt_int16 * pcm, celt_int16 * optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc) +int celt_encode_with_ec(CELTEncoder * restrict st, const celt_int16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc) { int j, ret, C, N, LM, M; VARDECL(celt_sig, in); @@ -1140,13 +1137,11 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const celt_int16 * pcm, celt_ in[j] = SCALEOUT(pcm[j]); } - if (optional_resynthesis != NULL) { - ret = celt_encode_with_ec_float(st,in,in,frame_size,compressed,nbCompressedBytes, enc); - for (j=0;j<C*N;j++) - optional_resynthesis[j] = FLOAT2INT16(in[j]); - } else { - ret = celt_encode_with_ec_float(st,in,NULL,frame_size,compressed,nbCompressedBytes, enc); - } + ret = celt_encode_with_ec_float(st,in,frame_size,compressed,nbCompressedBytes, enc); +#ifdef RESYNTH + for (j=0;j<C*N;j++) + ((celt_int16*)pcm)[j] = FLOAT2INT16(in[j]); +#endif RESTORE_STACK; return ret; } @@ -1154,29 +1149,16 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const celt_int16 * pcm, celt_ int celt_encode(CELTEncoder * restrict st, const celt_int16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes) { - return celt_encode_with_ec(st, pcm, NULL, frame_size, compressed, nbCompressedBytes, NULL); + return celt_encode_with_ec(st, pcm, frame_size, compressed, nbCompressedBytes, NULL); } #ifndef DISABLE_FLOAT_API int celt_encode_float(CELTEncoder * restrict st, const float * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes) { - return celt_encode_with_ec_float(st, pcm, NULL, frame_size, compressed, nbCompressedBytes, NULL); + return celt_encode_with_ec_float(st, pcm, frame_size, compressed, nbCompressedBytes, NULL); } #endif /* DISABLE_FLOAT_API */ -int celt_encode_resynthesis(CELTEncoder * restrict st, const celt_int16 * pcm, celt_int16 * optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes) -{ - return celt_encode_with_ec(st, pcm, optional_resynthesis, frame_size, compressed, nbCompressedBytes, NULL); -} - -#ifndef DISABLE_FLOAT_API -int celt_encode_resynthesis_float(CELTEncoder * restrict st, const float * pcm, float * optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes) -{ - return celt_encode_with_ec_float(st, pcm, optional_resynthesis, frame_size, compressed, nbCompressedBytes, NULL); -} -#endif /* DISABLE_FLOAT_API */ - - int celt_encoder_ctl(CELTEncoder * restrict st, int request, ...) { va_list ap; diff --git a/libcelt/celt.h b/libcelt/celt.h index b747cabe55872be7686847d42ecc152893e42b9f..234f396d3f02d93adc3769066cf64c146ec69d6e 100644 --- a/libcelt/celt.h +++ b/libcelt/celt.h @@ -176,30 +176,6 @@ EXPORT CELTEncoder *celt_encoder_init(CELTEncoder *st, const CELTMode *mode, int */ EXPORT void celt_encoder_destroy(CELTEncoder *st); -/** Encodes a frame of audio. - @param st Encoder state - @param pcm PCM audio in float format, with a normal range of ±1.0. - * Samples with a range beyond ±1.0 are supported but will - * be clipped by decoders using the integer API and should - * only be used if it is known that the far end supports - * extended dynmaic range. There must be exactly - * frame_size samples per channel. - @param optional_resynthesis If not NULL, the encoder copies the audio signal that - * the decoder would decode. It is the same as calling the - * decoder on the compressed data, just faster. - * This may alias pcm. - @param compressed The compressed data is written here. This may not alias pcm or - * optional_synthesis. - @param nbCompressedBytes Maximum number of bytes to use for compressing the frame - * (can change from one frame to another) - @return Number of bytes written to "compressed". Will be the same as - * "nbCompressedBytes" unless the stream is VBR and will never be larger. - * If negative, an error has occurred (see error codes). It is IMPORTANT that - * the length returned be somehow transmitted to the decoder. Otherwise, no - * decoding is possible. -*/ -EXPORT int celt_encode_resynthesis_float(CELTEncoder *st, const float *pcm, float *optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes); - /** Encodes a frame of audio. @param st Encoder state @param pcm PCM audio in float format, with a normal range of ±1.0. @@ -220,26 +196,6 @@ EXPORT int celt_encode_resynthesis_float(CELTEncoder *st, const float *pcm, floa */ EXPORT int celt_encode_float(CELTEncoder *st, const float *pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes); -/** Encodes a frame of audio. - @param st Encoder state - @param pcm PCM audio in signed 16-bit format (native endian). There must be - * exactly frame_size samples per channel. - @param optional_resynthesis If not NULL, the encoder copies the audio signal that - * the decoder would decode. It is the same as calling the - * decoder on the compressed data, just faster. - * This may alias pcm. - @param compressed The compressed data is written here. This may not alias pcm or - * optional_synthesis. - @param nbCompressedBytes Maximum number of bytes to use for compressing the frame - * (can change from one frame to another) - @return Number of bytes written to "compressed". Will be the same as - * "nbCompressedBytes" unless the stream is VBR and will never be larger. - * If negative, an error has occurred (see error codes). It is IMPORTANT that - * the length returned be somehow transmitted to the decoder. Otherwise, no - * decoding is possible. - */ -EXPORT int celt_encode_resynthesis(CELTEncoder *st, const celt_int16 *pcm, celt_int16 *optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes); - /** Encodes a frame of audio. @param st Encoder state @param pcm PCM audio in signed 16-bit format (native endian). There must be diff --git a/libcelt/modes.h b/libcelt/modes.h index 826ab40053b90bf7b08c5c5019b9c0dfbb873f0b..87604360fb189963d5b63a29b84e232dc7271ae9 100644 --- a/libcelt/modes.h +++ b/libcelt/modes.h @@ -104,8 +104,8 @@ struct CELTMode { }; /* Prototypes for _ec versions of the encoder/decoder calls (not public) */ -int celt_encode_with_ec(CELTEncoder * restrict st, const celt_int16 * pcm, celt_int16 * optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc); -int celt_encode_with_ec_float(CELTEncoder * restrict st, const float * pcm, float * optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc); +int celt_encode_with_ec(CELTEncoder * restrict st, const celt_int16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc); +int celt_encode_with_ec_float(CELTEncoder * restrict st, const float * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc); int celt_decode_with_ec(CELTDecoder * restrict st, const unsigned char *data, int len, celt_int16 * restrict pcm, int frame_size, ec_dec *dec); int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *data, int len, float * restrict pcm, int frame_size, ec_dec *dec); #endif diff --git a/libcelt/testcelt.c b/libcelt/testcelt.c index 571350daa499650bba70b63dcf4aae57f086994b..6bfd0dd2e117507d5f36978ff09a858ef99ad16f 100644 --- a/libcelt/testcelt.c +++ b/libcelt/testcelt.c @@ -134,7 +134,7 @@ int main(int argc, char *argv[]) err = fread(in, sizeof(short), frame_size*channels, fin); if (feof(fin)) break; - len = celt_encode_resynthesis(enc, in, in, frame_size, data, bytes_per_packet); + len = celt_encode(enc, in, frame_size, data, bytes_per_packet); if (len <= 0) fprintf (stderr, "celt_encode() failed: %s\n", celt_strerror(len));