shithub: opus

Download patch

ref: c97b258c628ae6bd0e8e6229a8f398c980dfae77
parent: 5ad35bf3bf9eb64f8fc2d0d4a4799f4c21d013b8
author: Jean-Marc Valin <[email protected]>
date: Fri Jan 28 18:07:32 EST 2011

celt_encoder_create() now defaults to Opus standard mode

The old constructor is renamed celt_encoder_create_custom(). Same
for the decoder.

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -127,15 +127,28 @@
    return size;
 }
 
-CELTEncoder *celt_encoder_create(const CELTMode *mode, int channels, int *error)
+CELTEncoder *celt_encoder_create(int channels, int *error)
 {
+   CELTMode *mode = celt_mode_create(48000, 960, NULL);
    return celt_encoder_init(
          (CELTEncoder *)celt_alloc(celt_encoder_get_size(mode, channels)),
+         channels, error);
+}
+
+CELTEncoder *celt_encoder_create_custom(const CELTMode *mode, int channels, int *error)
+{
+   return celt_encoder_init_custom(
+         (CELTEncoder *)celt_alloc(celt_encoder_get_size(mode, channels)),
          mode, channels, error);
 }
 
-CELTEncoder *celt_encoder_init(CELTEncoder *st, const CELTMode *mode, int channels, int *error)
+CELTEncoder *celt_encoder_init(CELTEncoder *st, int channels, int *error)
 {
+   return celt_encoder_init_custom(st, celt_mode_create(48000, 960, NULL), channels, error);
+}
+
+CELTEncoder *celt_encoder_init_custom(CELTEncoder *st, const CELTMode *mode, int channels, int *error)
+{
    if (channels < 0 || channels > 2)
    {
       if (error)
@@ -1672,14 +1685,27 @@
    return size;
 }
 
-CELTDecoder *celt_decoder_create(const CELTMode *mode, int channels, int *error)
+CELTDecoder *celt_decoder_create(int channels, int *error)
 {
+   const CELTMode *mode = celt_mode_create(48000, 960, NULL);
    return celt_decoder_init(
          (CELTDecoder *)celt_alloc(celt_decoder_get_size(mode, channels)),
+         channels, error);
+}
+
+CELTDecoder *celt_decoder_create_custom(const CELTMode *mode, int channels, int *error)
+{
+   return celt_decoder_init_custom(
+         (CELTDecoder *)celt_alloc(celt_decoder_get_size(mode, channels)),
          mode, channels, error);
 }
 
-CELTDecoder *celt_decoder_init(CELTDecoder *st, const CELTMode *mode, int channels, int *error)
+CELTDecoder *celt_decoder_init(CELTDecoder *st, int channels, int *error)
+{
+   return celt_decoder_init_custom(st, celt_mode_create(48000, 960, NULL), channels, error);
+}
+
+CELTDecoder *celt_decoder_init_custom(CELTDecoder *st, const CELTMode *mode, int channels, int *error)
 {
    if (channels < 0 || channels > 2)
    {
--- a/libcelt/celt.h
+++ b/libcelt/celt.h
@@ -163,6 +163,14 @@
 
 /** Creates a new encoder state. Each stream needs its own encoder 
     state (can't be shared across simultaneous streams).
+ @param channels Number of channels
+ @param error Returns an error code
+ @return Newly created encoder state.
+*/
+EXPORT CELTEncoder *celt_encoder_create(int channels, int *error);
+
+/** Creates a new encoder state. Each stream needs its own encoder
+    state (can't be shared across simultaneous streams).
  @param mode Contains all the information about the characteristics of
  *  the stream (must be the same characteristics as used for the 
  *  decoder)
@@ -170,10 +178,12 @@
  @param error Returns an error code
  @return Newly created encoder state.
 */
-EXPORT CELTEncoder *celt_encoder_create(const CELTMode *mode, int channels, int *error);
+EXPORT CELTEncoder *celt_encoder_create_custom(const CELTMode *mode, int channels, int *error);
 
-EXPORT CELTEncoder *celt_encoder_init(CELTEncoder *st, const CELTMode *mode, int channels, int *error);
+EXPORT CELTEncoder *celt_encoder_init(CELTEncoder *st, int channels, int *error);
 
+EXPORT CELTEncoder *celt_encoder_init_custom(CELTEncoder *st, const CELTMode *mode, int channels, int *error);
+
 /** Destroys a an encoder state.
  @param st Encoder state to be destroyed
  */
@@ -235,9 +245,21 @@
  @param error Returns an error code
  @return Newly created decoder state.
  */
-EXPORT CELTDecoder *celt_decoder_create(const CELTMode *mode, int channels, int *error);
+EXPORT CELTDecoder *celt_decoder_create(int channels, int *error);
 
-EXPORT CELTDecoder *celt_decoder_init(CELTDecoder *st, const CELTMode *mode, int channels, int *error);
+/** Creates a new decoder state. Each stream needs its own decoder state (can't
+    be shared across simultaneous streams).
+ @param mode Contains all the information about the characteristics of the
+             stream (must be the same characteristics as used for the encoder)
+ @param channels Number of channels
+ @param error Returns an error code
+ @return Newly created decoder state.
+ */
+EXPORT CELTDecoder *celt_decoder_create_custom(const CELTMode *mode, int channels, int *error);
+
+EXPORT CELTDecoder *celt_decoder_init(CELTDecoder *st, int channels, int *error);
+
+EXPORT CELTDecoder *celt_decoder_init_custom(CELTDecoder *st, const CELTMode *mode, int channels, int *error);
 
 /** Destroys a a decoder state.
  @param st Decoder state to be destroyed
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -278,10 +278,16 @@
 
    for (i=0;i<TOTAL_MODES;i++)
    {
-      if (Fs == static_mode_list[i]->Fs &&
-          frame_size == static_mode_list[i]->shortMdctSize*static_mode_list[i]->nbShortMdcts)
+      int j;
+      for (j=0;j<4;j++)
       {
-         return (CELTMode*)static_mode_list[i];
+         if (Fs == static_mode_list[i]->Fs &&
+               (frame_size<<j) == static_mode_list[i]->shortMdctSize*static_mode_list[i]->nbShortMdcts)
+         {
+            if (error)
+               *error = CELT_OK;
+            return (CELTMode*)static_mode_list[i];
+         }
       }
    }
 #ifndef CUSTOM_MODES
--- a/libcelt/testcelt.c
+++ b/libcelt/testcelt.c
@@ -107,13 +107,13 @@
       return 1;
    }
    
-   enc = celt_encoder_create(mode, channels, &err);
+   enc = celt_encoder_create_custom(mode, channels, &err);
    if (err != 0)
    {
       fprintf(stderr, "Failed to create the encoder: %s\n", celt_strerror(err));
       return 1;
    }
-   dec = celt_decoder_create(mode, channels, &err);
+   dec = celt_decoder_create_custom(mode, channels, &err);
    if (err != 0)
    {
       fprintf(stderr, "Failed to create the decoder: %s\n", celt_strerror(err));
--- a/tests/tandem-test.c
+++ b/tests/tandem-test.c
@@ -85,12 +85,12 @@
         exit(1);
     }
 
-    dec = celt_decoder_create(mode, channels, &error);
+    dec = celt_decoder_create_custom(mode, channels, &error);
     if (error){
       fprintf(stderr, "Error: celt_decoder_create returned %s\n", celt_strerror(error));
       exit(1);
     }
-    enc = celt_encoder_create(mode, channels, &error);
+    enc = celt_encoder_create_custom(mode, channels, &error);
     if (error){
       fprintf(stderr, "Error: celt_encoder_create returned %s\n", celt_strerror(error));
       exit(1);
@@ -167,7 +167,11 @@
 
 int main(int argc, char *argv[])
 {
+#ifdef CUSTOM_MODES
     int sizes[8]={960,480,240,120,512,256,128,64};
+#else
+    int sizes[4]={960,480,240,120};
+#endif
     unsigned int seed;
     int ch, n;
 
@@ -184,6 +188,7 @@
     srand(seed);
     printf("CELT codec tests. Random seed: %u (%.4X)\n", seed, rand() % 65536);
 
+#ifdef CUSTOM_MODES
     for (n = 0; n < 8; n++) {
         for (ch = 1; ch <= 2; ch++) {
             async_tandem(48000, sizes[n], ch, 12000 * ch, 128000 * ch);
@@ -192,6 +197,12 @@
             async_tandem(16000, sizes[n], ch, 12000 * ch, 64000 * ch);
         }
     }
-
+#else
+    for (n = 0; n < 4; n++) {
+        for (ch = 1; ch <= 2; ch++) {
+            async_tandem(48000, sizes[n], ch, 12000 * ch, 128000 * ch);
+        }
+    }
+#endif
     return 0;
 }
--- a/tools/celtdec.c
+++ b/tools/celtdec.c
@@ -315,7 +315,7 @@
    
    *channels = header.nb_channels;
    *overlap=header.overlap;
-   st = celt_decoder_create(*mode, header.nb_channels, NULL);
+   st = celt_decoder_create_custom(*mode, header.nb_channels, NULL);
    if (!st)
    {
       fprintf (stderr, "Decoder initialization failed.\n");
--- a/tools/celtenc.c
+++ b/tools/celtenc.c
@@ -525,7 +525,7 @@
    }
 
    /*Initialize CELT encoder*/
-   st = celt_encoder_create(mode, chan, NULL);
+   st = celt_encoder_create_custom(mode, chan, NULL);
 
    if (!with_cbr)
    {