shithub: opus

Download patch

ref: ec06c2ae404d21a7a34fb62ef6a2b3af5de4921d
parent: 977ee01670a9e5271ffeeddf5597583458002dfd
author: Jean-Marc Valin <jeanmarcv@google.com>
date: Wed Jun 12 10:43:51 EDT 2024

Cleanup Opus custom API

--- a/celt/celt_decoder.c
+++ b/celt/celt_decoder.c
@@ -1372,10 +1372,14 @@
 
 #ifdef CUSTOM_MODES
 
-#ifdef FIXED_POINT
-#ifdef ENABLE_RES24
+#if defined(FIXED_POINT) && !defined(ENABLE_RES24)
 int opus_custom_decode(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data, int len, opus_int16 * OPUS_RESTRICT pcm, int frame_size)
 {
+   return celt_decode_with_ec(st, data, len, pcm, frame_size, NULL, 0);
+}
+#else
+int opus_custom_decode(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data, int len, opus_int16 * OPUS_RESTRICT pcm, int frame_size)
+{
    int j, ret, C, N;
    VARDECL(opus_res, out);
    ALLOC_STACK;
@@ -1395,17 +1399,14 @@
    RESTORE_STACK;
    return ret;
 }
+#endif
 
+#if defined(FIXED_POINT) && defined(ENABLE_RES24)
 int opus_custom_decode24(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data, int len, opus_int32 * OPUS_RESTRICT pcm, int frame_size)
 {
    return celt_decode_with_ec(st, data, len, pcm, frame_size, NULL, 0);
 }
 #else
-int opus_custom_decode(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data, int len, opus_int16 * OPUS_RESTRICT pcm, int frame_size)
-{
-   return celt_decode_with_ec(st, data, len, pcm, frame_size, NULL, 0);
-}
-
 int opus_custom_decode24(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data, int len, opus_int32 * OPUS_RESTRICT pcm, int frame_size)
 {
    int j, ret, C, N;
@@ -1429,41 +1430,19 @@
 }
 #endif
 
+
 #ifndef DISABLE_FLOAT_API
-int opus_custom_decode_float(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data, int len, float * OPUS_RESTRICT pcm, int frame_size)
-{
-   int j, ret, C, N;
-   VARDECL(opus_res, out);
-   ALLOC_STACK;
 
-   if (pcm==NULL)
-      return OPUS_BAD_ARG;
-
-   C = st->channels;
-   N = frame_size;
-
-   ALLOC(out, C*N, opus_res);
-   ret=celt_decode_with_ec(st, data, len, out, frame_size, NULL, 0);
-   if (ret>0)
-      for (j=0;j<C*ret;j++)
-         pcm[j]=RES2FLOAT(out[j]);
-
-   RESTORE_STACK;
-   return ret;
-}
-#endif /* DISABLE_FLOAT_API */
-
-#else
-
+# if !defined(FIXED_POINT)
 int opus_custom_decode_float(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data, int len, float * OPUS_RESTRICT pcm, int frame_size)
 {
    return celt_decode_with_ec(st, data, len, pcm, frame_size, NULL, 0);
 }
-
-int opus_custom_decode(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data, int len, opus_int16 * OPUS_RESTRICT pcm, int frame_size)
+# else
+int opus_custom_decode_float(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data, int len, float * OPUS_RESTRICT pcm, int frame_size)
 {
    int j, ret, C, N;
-   VARDECL(celt_sig, out);
+   VARDECL(opus_res, out);
    ALLOC_STACK;
 
    if (pcm==NULL)
@@ -1471,41 +1450,20 @@
 
    C = st->channels;
    N = frame_size;
-   ALLOC(out, C*N, celt_sig);
 
+   ALLOC(out, C*N, opus_res);
    ret=celt_decode_with_ec(st, data, len, out, frame_size, NULL, 0);
-
    if (ret>0)
       for (j=0;j<C*ret;j++)
-         pcm[j] = RES2INT16(out[j]);
+         pcm[j]=RES2FLOAT(out[j]);
 
    RESTORE_STACK;
    return ret;
 }
+# endif
 
-int opus_custom_decode24(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data, int len, opus_int32 * OPUS_RESTRICT pcm, int frame_size)
-{
-   int j, ret, C, N;
-   VARDECL(celt_sig, out);
-   ALLOC_STACK;
-
-   if (pcm==NULL)
-      return OPUS_BAD_ARG;
-
-   C = st->channels;
-   N = frame_size;
-   ALLOC(out, C*N, celt_sig);
-
-   ret=celt_decode_with_ec(st, data, len, out, frame_size, NULL, 0);
-
-   if (ret>0)
-      for (j=0;j<C*ret;j++)
-         pcm[j] = RES2INT24(out[j]);
-
-   RESTORE_STACK;
-   return ret;
-}
 #endif
+
 #endif /* CUSTOM_MODES */
 
 int opus_custom_decoder_ctl(CELTDecoder * OPUS_RESTRICT st, int request, ...)
--- a/celt/celt_encoder.c
+++ b/celt/celt_encoder.c
@@ -2544,10 +2544,14 @@
 
 #ifdef CUSTOM_MODES
 
-#ifdef FIXED_POINT
-#ifdef ENABLE_RES24
+#if defined(FIXED_POINT) && !defined(ENABLE_RES24)
 int opus_custom_encode(CELTEncoder * OPUS_RESTRICT st, const opus_int16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes)
 {
+   return celt_encode_with_ec(st, pcm, frame_size, compressed, nbCompressedBytes, NULL);
+}
+#else
+int opus_custom_encode(CELTEncoder * OPUS_RESTRICT st, const opus_int16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes)
+{
    int j, ret, C, N;
    VARDECL(opus_res, in);
    ALLOC_STACK;
@@ -2570,17 +2574,15 @@
    RESTORE_STACK;
    return ret;
 }
+#endif
 
+
+#if defined(FIXED_POINT) && defined(ENABLE_RES24)
 int opus_custom_encode24(CELTEncoder * OPUS_RESTRICT st, const opus_int32 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes)
 {
    return celt_encode_with_ec(st, pcm, frame_size, compressed, nbCompressedBytes, NULL);
 }
 #else
-int opus_custom_encode(CELTEncoder * OPUS_RESTRICT st, const opus_int16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes)
-{
-   return celt_encode_with_ec(st, pcm, frame_size, compressed, nbCompressedBytes, NULL);
-}
-
 int opus_custom_encode24(CELTEncoder * OPUS_RESTRICT st, const opus_int32 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes)
 {
    int j, ret, C, N;
@@ -2600,7 +2602,7 @@
    ret=celt_encode_with_ec(st,in,frame_size,compressed,nbCompressedBytes, NULL);
 #ifdef RESYNTH
    for (j=0;j<C*N;j++)
-      ((float*)pcm)[j]=RES2INT24(in[j]);
+      ((opus_int32*)pcm)[j]=RES2INT24(in[j]);
 #endif
    RESTORE_STACK;
    return ret;
@@ -2607,9 +2609,17 @@
 }
 #endif
 
+
 #ifndef DISABLE_FLOAT_API
+
+# if !defined(FIXED_POINT)
 int opus_custom_encode_float(CELTEncoder * OPUS_RESTRICT st, const float * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes)
 {
+   return celt_encode_with_ec(st, pcm, frame_size, compressed, nbCompressedBytes, NULL);
+}
+# else
+int opus_custom_encode_float(CELTEncoder * OPUS_RESTRICT st, const float * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes)
+{
    int j, ret, C, N;
    VARDECL(opus_res, in);
    ALLOC_STACK;
@@ -2632,63 +2642,7 @@
    RESTORE_STACK;
    return ret;
 }
-#endif /* DISABLE_FLOAT_API */
-#else
-
-int opus_custom_encode(CELTEncoder * OPUS_RESTRICT st, const opus_int16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes)
-{
-   int j, ret, C, N;
-   VARDECL(celt_sig, in);
-   ALLOC_STACK;
-
-   if (pcm==NULL)
-      return OPUS_BAD_ARG;
-
-   C=st->channels;
-   N=frame_size;
-   ALLOC(in, C*N, celt_sig);
-   for (j=0;j<C*N;j++) {
-     in[j] = INT16TORES(pcm[j]);
-   }
-
-   ret = celt_encode_with_ec(st,in,frame_size,compressed,nbCompressedBytes, NULL);
-#ifdef RESYNTH
-   for (j=0;j<C*N;j++)
-      ((opus_int16*)pcm)[j] = FLOAT2INT16(in[j]);
-#endif
-   RESTORE_STACK;
-   return ret;
-}
-
-int opus_custom_encode24(CELTEncoder * OPUS_RESTRICT st, const opus_int32 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes)
-{
-   int j, ret, C, N;
-   VARDECL(celt_sig, in);
-   ALLOC_STACK;
-
-   if (pcm==NULL)
-      return OPUS_BAD_ARG;
-
-   C=st->channels;
-   N=frame_size;
-   ALLOC(in, C*N, celt_sig);
-   for (j=0;j<C*N;j++) {
-     in[j] = INT24TORES(pcm[j]);
-   }
-
-   ret = celt_encode_with_ec(st,in,frame_size,compressed,nbCompressedBytes, NULL);
-#ifdef RESYNTH
-   for (j=0;j<C*N;j++)
-      ((opus_int32*)pcm)[j] = RES2INT24(in[j]);
-#endif
-   RESTORE_STACK;
-   return ret;
-}
-
-int opus_custom_encode_float(CELTEncoder * OPUS_RESTRICT st, const float * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes)
-{
-   return celt_encode_with_ec(st, pcm, frame_size, compressed, nbCompressedBytes, NULL);
-}
+# endif
 
 #endif
 
--