shithub: aacdec

Download patch

ref: 2b65b584656d94459a29da0ebfef673e5c5d9ca1
parent: a0ba9ba615f9ad5429bb2d50add1e7bdb42fa55f
author: menno <menno>
date: Wed Apr 2 15:07:46 EST 2003

library can now output 64 bit doubles

--- a/common/mp4v2/libmp4v2_cb.dsp
+++ b/common/mp4v2/libmp4v2_cb.dsp
@@ -42,7 +42,7 @@
 # PROP Target_Dir ""
 MTL=midl.exe
 # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
-# ADD CPP /nologo /MT /W3 /GX /O2 /I ".\\" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "USE_FILE_CALLBACKS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I ".\\" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "USE_FILE_CALLBACKS" /YX /FD /c
 # ADD BASE RSC /l 0x413 /d "NDEBUG"
 # ADD RSC /l 0x413 /d "NDEBUG"
 BSC32=bscmake.exe
--- a/frontend/main.c
+++ b/frontend/main.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: main.c,v 1.29 2003/03/05 14:24:50 menno Exp $
+** $Id: main.c,v 1.30 2003/04/02 20:07:44 menno Exp $
 **/
 
 #ifdef _WIN32
@@ -135,10 +135,11 @@
     fprintf(stderr, "        2:  24 bit PCM data.\n");
     fprintf(stderr, "        3:  32 bit PCM data.\n");
     fprintf(stderr, "        4:  32 bit floating point data.\n");
-    fprintf(stderr, "        5:  16 bit PCM data (dithered).\n");
-    fprintf(stderr, "        6:  16 bit PCM data (dithered with LIGHT noise shaping).\n");
-    fprintf(stderr, "        7:  16 bit PCM data (dithered with MEDIUM noise shaping).\n");
-    fprintf(stderr, "        8:  16 bit PCM data (dithered with HEAVY noise shaping).\n");
+    fprintf(stderr, "        5:  64 bit floating point data.\n");
+    fprintf(stderr, "        6:  16 bit PCM data (dithered).\n");
+    fprintf(stderr, "        7:  16 bit PCM data (dithered with LIGHT noise shaping).\n");
+    fprintf(stderr, "        8:  16 bit PCM data (dithered with MEDIUM noise shaping).\n");
+    fprintf(stderr, "        9:  16 bit PCM data (dithered with HEAVY noise shaping).\n");
     fprintf(stderr, " -s X  Force the samplerate to X (for RAW files).\n");
     fprintf(stderr, " -l X  Set object type. Supported object types:\n");
     fprintf(stderr, "        0:  Main object type.\n");
@@ -583,7 +584,7 @@
                     outputFormat = FAAD_FMT_16BIT; /* just use default */
                 } else {
                     outputFormat = atoi(dr);
-                    if ((outputFormat < 1) || (outputFormat > 8))
+                    if ((outputFormat < 1) || (outputFormat > 9))
                         showHelp = 1;
                 }
             }
--- a/include/faad.h
+++ b/include/faad.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: faad.h,v 1.20 2003/03/05 14:24:52 menno Exp $
+** $Id: faad.h,v 1.21 2003/04/02 20:07:45 menno Exp $
 **/
 
 #ifndef __AACDEC_H__
@@ -55,15 +55,16 @@
 #define ADTS       2
 
 /* library output formats */
-#define FAAD_FMT_16BIT 1
-#define FAAD_FMT_24BIT 2
-#define FAAD_FMT_32BIT 3
-#define FAAD_FMT_FLOAT 4
-#define FAAD_FMT_16BIT_DITHER 5
-#define FAAD_FMT_16BIT_L_SHAPE 6
-#define FAAD_FMT_16BIT_M_SHAPE 7
-#define FAAD_FMT_16BIT_H_SHAPE 8
-
+#define FAAD_FMT_16BIT  1
+#define FAAD_FMT_24BIT  2
+#define FAAD_FMT_32BIT  3
+#define FAAD_FMT_FLOAT  4
+#define FAAD_FMT_DOUBLE 5
+#define FAAD_FMT_16BIT_DITHER  6
+#define FAAD_FMT_16BIT_L_SHAPE 7
+#define FAAD_FMT_16BIT_M_SHAPE 8
+#define FAAD_FMT_16BIT_H_SHAPE 9
+    
 /* Capabilities */
 #define LC_DEC_CAP            (1<<0)
 #define MAIN_DEC_CAP          (1<<1)
--- a/libfaad/decoder.c
+++ b/libfaad/decoder.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: decoder.c,v 1.53 2003/03/05 14:24:53 menno Exp $
+** $Id: decoder.c,v 1.54 2003/04/02 20:07:45 menno Exp $
 **/
 
 #include "common.h"
@@ -225,8 +225,8 @@
         return -1;
 
 #ifndef FIXED_POINT
-    if (hDecoder->config.outputFormat >= 5)
-        Init_Dither(16, hDecoder->config.outputFormat - 5);
+    if (hDecoder->config.outputFormat >= FAAD_FMT_DITHER_LOWEST)
+        Init_Dither(16, hDecoder->config.outputFormat - FAAD_FMT_DITHER_LOWEST);
 #endif
 
     return bits;
@@ -288,8 +288,8 @@
 #endif
 
 #ifndef FIXED_POINT
-    if (hDecoder->config.outputFormat >= 5)
-        Init_Dither(16, hDecoder->config.outputFormat - 5);
+    if (hDecoder->config.outputFormat >= FAAD_FMT_DITHER_LOWEST)
+        Init_Dither(16, hDecoder->config.outputFormat - FAAD_FMT_DITHER_LOWEST);
 #endif
 
     return 0;
@@ -314,8 +314,8 @@
     hDecoder->fb = filter_bank_init(hDecoder->frameLength);
 
 #ifndef FIXED_POINT
-    if (hDecoder->config.outputFormat >= 5)
-        Init_Dither(16, hDecoder->config.outputFormat - 5);
+    if (hDecoder->config.outputFormat >= FAAD_FMT_DITHER_LOWEST)
+        Init_Dither(16, hDecoder->config.outputFormat - FAAD_FMT_DITHER_LOWEST);
 #endif
 
     return 0;
@@ -481,7 +481,12 @@
     }
 
     if (hDecoder->sample_buffer == NULL)
-        hDecoder->sample_buffer = malloc(frame_len*channels*sizeof(real_t));
+    {
+        if (hDecoder->config.outputFormat == FAAD_FMT_DOUBLE)
+            hDecoder->sample_buffer = malloc(frame_len*channels*sizeof(double));
+        else
+            hDecoder->sample_buffer = malloc(frame_len*channels*sizeof(real_t));
+    }
 
     sample_buffer = hDecoder->sample_buffer;
 
--- a/libfaad/decoder.h
+++ b/libfaad/decoder.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: decoder.h,v 1.21 2003/03/05 14:24:55 menno Exp $
+** $Id: decoder.h,v 1.22 2003/04/02 20:07:46 menno Exp $
 **/
 
 #ifndef __DECODER_H__
@@ -45,14 +45,18 @@
 #include "ic_predict.h"
 
 
-#define FAAD_FMT_16BIT 1
-#define FAAD_FMT_24BIT 2
-#define FAAD_FMT_32BIT 3
-#define FAAD_FMT_FLOAT 4
-#define FAAD_FMT_16BIT_DITHER 5
-#define FAAD_FMT_16BIT_L_SHAPE 6
-#define FAAD_FMT_16BIT_M_SHAPE 7
-#define FAAD_FMT_16BIT_H_SHAPE 8
+/* library output formats */
+#define FAAD_FMT_16BIT  1
+#define FAAD_FMT_24BIT  2
+#define FAAD_FMT_32BIT  3
+#define FAAD_FMT_FLOAT  4
+#define FAAD_FMT_DOUBLE 5
+#define FAAD_FMT_16BIT_DITHER  6
+#define FAAD_FMT_16BIT_L_SHAPE 7
+#define FAAD_FMT_16BIT_M_SHAPE 8
+#define FAAD_FMT_16BIT_H_SHAPE 9
+
+#define FAAD_FMT_DITHER_LOWEST FAAD_FMT_16BIT_DITHER
 
 #define LC_DEC_CAP            (1<<0)
 #define MAIN_DEC_CAP          (1<<1)
--- a/libfaad/output.c
+++ b/libfaad/output.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: output.c,v 1.14 2002/11/28 18:48:30 menno Exp $
+** $Id: output.c,v 1.15 2003/04/02 20:07:46 menno Exp $
 **/
 
 #include "common.h"
@@ -53,6 +53,7 @@
     int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
     int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
     float32_t *float_sample_buffer = (float32_t*)sample_buffer;
+    double    *double_sample_buffer = (double*)sample_buffer;
 
     /* Copy output to a standard PCM buffer */
     switch (format)
@@ -144,6 +145,19 @@
                 else if (input[ch][i] < -(1<<15))
                     input[ch][i] = -(1<<15);
                 float_sample_buffer[(i*channels)+ch] = input[ch][i]*FLOAT_SCALE;
+            }
+        }
+        break;
+    case FAAD_FMT_DOUBLE:
+        for (ch = 0; ch < channels; ch++)
+        {
+            for(i = 0; i < frame_len; i++)
+            {
+                if (input[ch][i] > (1<<15)-1)
+                    input[ch][i] = (1<<15)-1;
+                else if (input[ch][i] < -(1<<15))
+                    input[ch][i] = -(1<<15);
+                double_sample_buffer[(i*channels)+ch] = (double)input[ch][i]*FLOAT_SCALE;
             }
         }
         break;
--- a/plugins/foo_mp4/foo_mp4.cpp
+++ b/plugins/foo_mp4/foo_mp4.cpp
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: foo_mp4.cpp,v 1.14 2003/02/09 20:42:50 menno Exp $
+** $Id: foo_mp4.cpp,v 1.15 2003/04/02 20:07:46 menno Exp $
 **/
 
 #include <mp4.h>
@@ -38,6 +38,7 @@
         unsigned __int8 *buffer;
         unsigned __int32 buffer_size;
         unsigned __int8 channels;
+        unsigned __int32 samplerate;
         faacDecConfigurationPtr config;
 
         m_reader = r;
@@ -46,7 +47,7 @@
         if (!hDecoder) return 0;
 
         config = faacDecGetCurrentConfiguration(hDecoder);
-        config->outputFormat = FAAD_FMT_FLOAT;
+        config->outputFormat = FAAD_FMT_DOUBLE;
         faacDecSetConfiguration(hDecoder, config);
 
         hFile = MP4ReadCb(0, open_cb, close_cb, read_cb, write_cb,
@@ -62,7 +63,7 @@
         if (!buffer) return 0;
 
         int rc = faacDecInit2(hDecoder, (unsigned char*)buffer, buffer_size,
-            (unsigned long*)&m_samplerate, (unsigned char*)&channels);
+            (unsigned long*)&samplerate, (unsigned char*)&channels);
         if (buffer) free(buffer);
         if (rc < 0) return 0;
 
@@ -78,7 +79,7 @@
             (double)(__int64)MP4GetTrackIntegerProperty(hFile,
             track, "mdia.minf.stbl.stsd.mp4a.esds.decConfigDescr.avgBitrate")) + 0.5);
         info->info_set_int("channels", (__int64)channels);
-        info->info_set_int("samplerate", (__int64)m_samplerate);
+        info->info_set_int("samplerate", (__int64)samplerate);
 
         ReadMP4Tag(info);
 
@@ -127,10 +128,10 @@
         if (frameInfo.error || (sampleId > numSamples))
             return 0;
 
-        chunk->data = (float*)sample_buffer;
+        chunk->data = (audio_sample*)sample_buffer;
         chunk->samples = frameInfo.samples/frameInfo.channels;
         chunk->nch = frameInfo.channels;
-        chunk->srate = m_samplerate;
+        chunk->srate = frameInfo.samplerate;
 
         return 1;
     }
@@ -147,7 +148,6 @@
         if (track < 1) return 0;
 
         MP4TagDelete(hFile, track);
-//        MP4TagCreate(hFile, track);
 
         /* replay gain writing */
         const char *p = NULL;
@@ -203,8 +203,6 @@
     MP4FileHandle hFile;
     MP4SampleId sampleId, numSamples;
     MP4TrackId track;
-
-    unsigned __int32 m_samplerate;
 
     faacDecHandle hDecoder;