shithub: opus

Download patch

ref: d56c610cac85d571f1504ea48420fd3dcfa1b2d5
parent: e949b720495fa9d11fdb189ffe38a7e115c1c426
author: Jean-Marc Valin <[email protected]>
date: Fri May 7 16:30:22 EDT 2010

API change: optional resynthesis

The main encode call no longer takes a pointer for the optional resynthesis.
It's now done with a call to celt_encode_resynthesis().

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -544,10 +544,10 @@
 
 
 #ifdef FIXED_POINT
-int celt_encode(CELTEncoder * restrict st, const celt_int16 * pcm, celt_int16 * optional_synthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes)
+int celt_encode_resynthesis(CELTEncoder * restrict st, const celt_int16 * pcm, celt_int16 * optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes)
 {
 #else
-int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig * optional_synthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes)
+int celt_encode_resynthesis_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig * optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes)
 {
 #endif
    int i, c, N, NN, N4;
@@ -631,7 +631,7 @@
    transient_shift = 0;
    isTransient = 0;
 
-   resynth = st->pitch_available>0 || optional_synthesis!=NULL;
+   resynth = st->pitch_available>0 || optional_resynthesis!=NULL;
 
    if (M > 1 && transient_analysis(in, N+st->overlap, C, &transient_time, &transient_shift, &st->frame_max))
    {
@@ -910,8 +910,8 @@
 
       /* De-emphasis and put everything back at the right place 
          in the synthesis history */
-      if (optional_synthesis != NULL) {
-         deemphasis(st->out_mem, optional_synthesis, N, C, preemph, st->preemph_memD);
+      if (optional_resynthesis != NULL) {
+         deemphasis(st->out_mem, optional_resynthesis, N, C, preemph, st->preemph_memD);
 
       }
    }
@@ -924,7 +924,7 @@
 
 #ifdef FIXED_POINT
 #ifndef DISABLE_FLOAT_API
-int celt_encode_float(CELTEncoder * restrict st, const float * pcm, float * optional_synthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes)
+int celt_encode_resynthesis_float(CELTEncoder * restrict st, const float * pcm, float * optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes)
 {
    int j, ret, C, N, LM, M;
    VARDECL(celt_int16, in);
@@ -954,11 +954,11 @@
      in[j] = FLOAT2INT16(pcm[j]);
 
    if (optional_synthesis != NULL) {
-     ret=celt_encode(st,in,in,frame_size,compressed,nbCompressedBytes);
+     ret=celt_encode_resynthesis(st,in,in,frame_size,compressed,nbCompressedBytes);
       for (j=0;j<C*N;j++)
          optional_synthesis[j]=in[j]*(1/32768.);
    } else {
-     ret=celt_encode(st,in,NULL,frame_size,compressed,nbCompressedBytes);
+     ret=celt_encode_resynthesis(st,in,NULL,frame_size,compressed,nbCompressedBytes);
    }
    RESTORE_STACK;
    return ret;
@@ -966,7 +966,7 @@
 }
 #endif /*DISABLE_FLOAT_API*/
 #else
-int celt_encode(CELTEncoder * restrict st, const celt_int16 * pcm, celt_int16 * optional_synthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes)
+int celt_encode_resynthesis(CELTEncoder * restrict st, const celt_int16 * pcm, celt_int16 * optional_resynthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes)
 {
    int j, ret, C, N, LM, M;
    VARDECL(celt_sig, in);
@@ -995,17 +995,27 @@
      in[j] = SCALEOUT(pcm[j]);
    }
 
-   if (optional_synthesis != NULL) {
-      ret = celt_encode_float(st,in,in,frame_size,compressed,nbCompressedBytes);
+   if (optional_resynthesis != NULL) {
+      ret = celt_encode_resynthesis_float(st,in,in,frame_size,compressed,nbCompressedBytes);
       for (j=0;j<C*N;j++)
-         optional_synthesis[j] = FLOAT2INT16(in[j]);
+         optional_resynthesis[j] = FLOAT2INT16(in[j]);
    } else {
-      ret = celt_encode_float(st,in,NULL,frame_size,compressed,nbCompressedBytes);
+      ret = celt_encode_resynthesis_float(st,in,NULL,frame_size,compressed,nbCompressedBytes);
    }
    RESTORE_STACK;
    return ret;
 }
 #endif
+
+int celt_encode(CELTEncoder * restrict st, const celt_int16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes)
+{
+   return celt_encode_resynthesis(st, pcm, NULL, frame_size, compressed, nbCompressedBytes);
+}
+
+int celt_encode_float(CELTEncoder * restrict st, const float * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes)
+{
+   return celt_encode_resynthesis_float(st, pcm, NULL, frame_size, compressed, nbCompressedBytes);
+}
 
 int celt_encoder_ctl(CELTEncoder * restrict st, int request, ...)
 {
--- a/libcelt/celt.h
+++ b/libcelt/celt.h
@@ -175,7 +175,7 @@
  *          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_synthesis If not NULL, the encoder copies the audio signal that
+ @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. 
@@ -189,13 +189,33 @@
  *       the length returned be somehow transmitted to the decoder. Otherwise, no
  *       decoding is possible.
 */
-EXPORT int celt_encode_float(CELTEncoder *st, const float *pcm, float *optional_synthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes);
+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.
+ *          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 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_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_synthesis If not NULL, the encoder copies the audio signal that
+ @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. 
@@ -209,7 +229,23 @@
  *       the length returned be somehow transmitted to the decoder. Otherwise, no
  *       decoding is possible.
  */
-EXPORT int celt_encode(CELTEncoder *st, const celt_int16 *pcm, celt_int16 *optional_synthesis, int frame_size, unsigned char *compressed, int nbCompressedBytes);
+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
+ *          exactly frame_size samples per channel.
+ @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(CELTEncoder *st, const celt_int16 *pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes);
 
 /** Query and set encoder parameters 
  @param st Encoder state
--- a/libcelt/testcelt.c
+++ b/libcelt/testcelt.c
@@ -133,7 +133,7 @@
       err = fread(in, sizeof(short), frame_size*channels, fin);
       if (feof(fin))
          break;
-      len = celt_encode(enc, in, in, frame_size, data, bytes_per_packet);
+      len = celt_encode_resynthesis(enc, in, in, frame_size, data, bytes_per_packet);
       if (len <= 0)
       {
          fprintf (stderr, "celt_encode() returned %d\n", len);
--- a/tests/tandem-test.c
+++ b/tests/tandem-test.c
@@ -99,7 +99,7 @@
             for (j = channels; j < frame_size * channels - 1; j++)
                 pcm[j] = ((rand() % 4096) - 2048) + .9 * pcm[j - channels];
 
-            ret = celt_encode(enc, pcm, NULL, frame_size, data, bytes_per_frame);
+            ret = celt_encode(enc, pcm, frame_size, data, bytes_per_frame);
             if (ret != bytes_per_frame) {
                 fprintf(stderr, "Error: during init celt_encode returned %d\n", ret);
                 exit(1);
@@ -123,7 +123,7 @@
             for (j = 0; j < channels; j++)
                 pcm[j] = carry[j];
 
-            ret = celt_encode(enc, pcm, NULL, frame_size, data, bytes_per_frame);
+            ret = celt_encode(enc, pcm, frame_size, data, bytes_per_frame);
             if (ret != bytes_per_frame) {
                 fprintf(stderr, "Error: at %d bytes_per_frame celt_encode returned %d\n",
                         bytes_per_frame, ret);
--- a/tools/celtenc.c
+++ b/tools/celtenc.c
@@ -664,7 +664,7 @@
       id++;
       /*Encode current frame*/
 
-      nbBytes = celt_encode(st, input, NULL, frame_size, bits, bytes_per_packet);
+      nbBytes = celt_encode(st, input, frame_size, bits, bytes_per_packet);
       if (nbBytes<0)
       {
          fprintf(stderr, "Got error %d while encoding. Aborting.\n", nbBytes);