changeset 15020:3f80d5095f3e

usable downmixing for fixed point mode (take 2, previous patch reversed immediately on account of 1000l error :)
author rfelker
date Tue, 29 Mar 2005 18:14:24 +0000
parents bc17fdd4e2ef
children 0923dd27ddac
files libfaad2/output.c
diffstat 1 files changed, 48 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libfaad2/output.c	Tue Mar 29 17:59:08 2005 +0000
+++ b/libfaad2/output.c	Tue Mar 29 18:14:24 2005 +0000
@@ -463,7 +463,7 @@
     }
 }
 
-void* output_to_PCM(NeAACDecHandle hDecoder,
+void* output_to_PCM_sux(NeAACDecHandle hDecoder,
                     real_t **input, void *sample_buffer, uint8_t channels,
                     uint16_t frame_len, uint8_t format)
 {
@@ -554,4 +554,51 @@
     return sample_buffer;
 }
 
+void* output_to_PCM(NeAACDecHandle hDecoder,
+                    real_t **input, void *sample_buffer, uint8_t channels,
+                    uint16_t frame_len, uint8_t format)
+{
+    int ch;
+    int i;
+    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
+    real_t *ch0 = input[hDecoder->internal_channel[0]];
+    real_t *ch1 = input[hDecoder->internal_channel[1]];
+    real_t *ch2 = input[hDecoder->internal_channel[2]];
+    real_t *ch3 = input[hDecoder->internal_channel[3]];
+    real_t *ch4 = input[hDecoder->internal_channel[4]];
+
+    if (format != FAAD_FMT_16BIT)
+        return output_to_PCM_sux(hDecoder, input, sample_buffer, channels, frame_len, format);
+
+    if (hDecoder->downMatrix) {
+        for(i = 0; i < frame_len; i++)
+        {
+	    int32_t tmp;
+	    tmp = (ch1[i] + ((ch0[i]+ch3[i])<<1) + (ch0[i]+ch3[i]) + (1<<(REAL_BITS+2))) >> (REAL_BITS+3);
+	    if ((tmp+0x8000) & ~0xffff) tmp = ~(tmp>>31)-0x8000;
+            short_sample_buffer[0] = tmp;
+	    tmp = (ch2[i] + ((ch0[i]+ch4[i])<<1) + (ch0[i]+ch4[i]) + (1<<(REAL_BITS+2))) >> (REAL_BITS+3);
+	    if ((tmp+0x8000) & ~0xffff) tmp = ~(tmp>>31)-0x8000;
+            short_sample_buffer[1] = tmp;
+	    short_sample_buffer += channels;
+        }
+        return sample_buffer;
+    }
+
+    /* Copy output to a standard PCM buffer */
+    for(i = 0; i < frame_len; i++)
+    {
+        for (ch = 0; ch < channels; ch++)
+        {
+            int32_t tmp = input[ch][i];
+            tmp += (1 << (REAL_BITS-1));
+            tmp >>= REAL_BITS;
+	    if ((tmp+0x8000) & ~0xffff) tmp = ~(tmp>>31)-0x8000;
+            *(short_sample_buffer++) = tmp;
+        }
+    }
+
+    return sample_buffer;
+}
+
 #endif