shithub: sox

Download patch

ref: 1b0c79606d4290497c491b576c4cf279065f01b6
parent: 8769e54f9acdbf65ef3b8dc57caaabc0bad19719
author: cbagwell <cbagwell>
date: Sun Nov 15 20:42:53 EST 2009

Optional support for opencore-amr libraries.

--- a/ChangeLog
+++ b/ChangeLog
@@ -31,6 +31,8 @@
 
   o Added new variants of sox_open to allow read/write from/to memory
     buffers (in POSIX 2008 environment); see example5.c.  (robs)
+  o amrnb and amrwb formats can optionally use opencore-amr libraries.
+    (cbagwell)
 
 File formats:
 
--- a/INSTALL
+++ b/INSTALL
@@ -18,7 +18,7 @@
 libraries, where to get them (if not from your OS distribution), and
 their licence types, is as follows:
 
-AMR-NB/WB         http://www.penguin.cz/~utx/amr        See library web page
+AMR-NB/WB         http://opencore-amr.sourceforge.net/  Apache
 AO                http://xiph.org/ao                    GPL
 ffmpeg            http://ffmpeg.mplayerhq.hu            LGPL
 FLAC              http://flac.sourceforge.net           BSD
--- a/configure.ac
+++ b/configure.ac
@@ -405,12 +405,25 @@
 
 
 
-AC_OPTIONAL_FORMAT(amrwb, AMRWB, [AC_CHECK_HEADER(amrwb/dec.h, [AC_CHECK_LIB(amrwb, D_IF_init, AMRWB_LIBS="$AMR_WB_LIBS -lamrwb",using_amrwb=no)], using_amrwb=no)])
+AC_OPTIONAL_FORMAT(amrwb, AMRWB, 
+		   [AC_CHECK_HEADERS(opencore-amrwb/dec_if.h,
+		    [AC_CHECK_LIB(opencore-amrwb, D_IF_init, 
+		     AMRNB_LIBS="$AMRWB_LIBS -lopencore-amrwb", using_amrwb=no)],
+		    [AC_CHECK_HEADERS(amrwb/dec.h, 
+		     [AC_CHECK_LIB(amrwb, D_IF_init, 
+		      AMRWB_LIBS="$AMRWB_LIBS -lamrwb",using_amrwb=no)], 
+		      using_amrwb=no)])])
 
 
 
-AC_OPTIONAL_FORMAT(amrnb, AMRNB, [AC_CHECK_HEADER(amrnb/sp_dec.h, [AC_CHECK_LIB(amrnb, Decoder_Interface_init, AMRNB_LIBS="$AMR_WB_LIBS -lamrnb",using_amrnb=no)], using_amrnb=no)])
-
+AC_OPTIONAL_FORMAT(amrnb, AMRNB, 
+		   [AC_CHECK_HEADERS(opencore-amrnb/interf_dec.h, 
+		    [AC_CHECK_LIB(opencore-amrnb, Decoder_Interface_init, 
+		     AMRNB_LIBS="$AMRNB_LIBS -lopencore-amrnb", using_amrnb=no)],
+		    [AC_CHECK_HEADER(amrnb/sp_dec.h, 
+		     [AC_CHECK_LIB(amrnb, Decoder_Interface_init, 
+		      AMRNB_LIBS="$AMRNB_LIBS -lamrnb", using_amrnb=no)], 
+		       using_amrnb=no)])])
 
 
 AC_OPTIONAL_FORMAT(wavpack, WAVPACK, [AC_CHECK_HEADER(wavpack/wavpack.h, [AC_CHECK_LIB(wavpack, WavpackGetSampleRate, WAVPACK_LIBS="$WAVPACK_LIBS -lwavpack",using_wavpack=no)], using_wavpack=no)])
--- a/src/amr-nb.c
+++ b/src/amr-nb.c
@@ -22,9 +22,13 @@
 
 #include "sox_i.h"
 
+#ifdef HAVE_OPENCORE_AMRNB_INTERF_DEC_H
+#include "opencore-amrnb/interf_dec.h"
+#else
 #include "amrnb/typedef.h"
 #include "amrnb/interf_dec.h"
 #include "amrnb/sp_dec.h"
+#endif
 #define Mode  _Mode
 #define MR102 _MR102
 #define MR122 _MR122
@@ -35,7 +39,11 @@
 #define MR74  _MR74
 #define MR795 _MR795
 #define MRDTX _MRDTX
+#ifdef HAVE_OPENCORE_AMRNB_INTERF_DEC_H
+#include "opencore-amrnb/interf_enc.h"
+#else
 #include "amrnb/interf_enc.h"
+#endif
 
 static char const magic[] = "#!AMR\n";
 #define AMR_CODED_MAX       32                  /* max coded size */
--- a/src/amr-wb.c
+++ b/src/amr-wb.c
@@ -22,17 +22,26 @@
 
 #include "sox_i.h"
 
+#ifdef HAVE_OPENCORE_AMRWB_DEC_IF_H
+#include "opencore-amrwb/dec_if.h"
+#include "opencore-amrwb/if_rom.h"
+#define DISABLE_AMR_WB_ENCODE
+#else
 #include "amrwb/typedef.h"
 #include "amrwb/enc_if.h"
 #include "amrwb/dec_if.h"
 #include "amrwb/if_rom.h"
+#endif
 
 static char const magic[] = "#!AMR-WB\n";
-#define AMR_CODED_MAX       NB_SERIAL_MAX
+#define AMR_CODED_MAX       61 /* max serial size */
 #define AMR_ENCODING        SOX_ENCODING_AMR_WB
 #define AMR_FORMAT_FN       lsx_amr_wb_format_fn
-#define AMR_FRAME           L_FRAME16k
+#define AMR_FRAME           320 /* Frame size at 16kHz */
 #define AMR_MODE_MAX        8
 #define AMR_NAMES           "amr-wb", "awb"
 #define AMR_RATE            16000
+#ifdef HAVE_OPENCORE_AMRWB_DEC_IF_H
+static const unsigned block_size[16] = {18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1};
+#endif
 #include "amr.h"
--- a/src/amr.h
+++ b/src/amr.h
@@ -29,7 +29,7 @@
 {
   priv_t * p = (priv_t *)ft->priv;
   size_t n_1;
-  UWord8 coded[AMR_CODED_MAX];
+  uint8_t coded[AMR_CODED_MAX];
 
   if (lsx_readbuf(ft, &coded[0], (size_t)1) != 1)
     return AMR_FRAME;
@@ -40,17 +40,6 @@
   return 0;
 }
 
-static sox_bool encode_1_frame(sox_format_t * ft)
-{
-  priv_t * p = (priv_t *)ft->priv;
-  UWord8 coded[AMR_CODED_MAX];
-#include "amr1.h"
-  sox_bool result = lsx_writebuf(ft, coded, (size_t) (size_t) (unsigned)n) == (unsigned)n;
-  if (!result)
-    lsx_fail_errno(ft, errno, "write error");
-  return result;
-}
-
 static int startread(sox_format_t * ft)
 {
   priv_t * p = (priv_t *)ft->priv;
@@ -95,6 +84,10 @@
 
 static int startwrite(sox_format_t * ft)
 {
+#ifdef DISABLE_AMR_WB_ENCODE
+  lsx_fail_errno(ft, SOX_EOF, "SoX was compiled without AMR-WB encoding support.");
+  return SOX_EOF;
+#else
   priv_t * p = (priv_t *)ft->priv;
   if (ft->encoding.compression != HUGE_VAL) {
     p->mode = ft->encoding.compression;
@@ -109,8 +102,25 @@
   lsx_writes(ft, magic);
   p->pcm_index = 0;
   return SOX_SUCCESS;
+#endif
 }
 
+#ifndef DISABLE_AMR_WB_ENCODE
+static sox_bool encode_1_frame(sox_format_t * ft)
+{
+  priv_t * p = (priv_t *)ft->priv;
+  uint8_t coded[AMR_CODED_MAX];
+#include "amr1.h"
+  sox_bool result = lsx_writebuf(ft, coded, (size_t) (size_t) (unsigned)n) == (unsigned)n;
+  if (!result)
+    lsx_fail_errno(ft, errno, "write error");
+  return result;
+}
+#endif
+
+#ifdef DISABLE_AMR_WB_ENCODE
+#define write_samples NULL
+#else
 static size_t write_samples(sox_format_t * ft, const sox_sample_t * buf, size_t len)
 {
   priv_t * p = (priv_t *)ft->priv;
@@ -127,7 +137,11 @@
   }
   return done;
 }
+#endif
 
+#ifdef DISABLE_AMR_WB_ENCODE
+#define stopwrite NULL
+#else
 static int stopwrite(sox_format_t * ft)
 {
   priv_t * p = (priv_t *)ft->priv;
@@ -143,6 +157,7 @@
   E_IF_exit(p->state);
   return result;
 }
+#endif
 
 sox_format_handler_t const * AMR_FORMAT_FN(void);
 sox_format_handler_t const * AMR_FORMAT_FN(void)