diff resample.c @ 64:5aa6292a1660 libavcodec

win32 fixes
author glantau
date Mon, 13 Aug 2001 21:48:05 +0000
parents 986e461dc072
children 3007abcbc510
line wrap: on
line diff
--- a/resample.c	Mon Aug 13 21:46:21 2001 +0000
+++ b/resample.c	Mon Aug 13 21:48:05 2001 +0000
@@ -16,14 +16,8 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
+#include "avcodec.h"
 #include <math.h>
-#include "avcodec.h"
-
-#define NDEBUG
-#include <assert.h>
 
 typedef struct {
     /* fractional resampling */
@@ -196,9 +190,11 @@
 
 static int mono_resample(ReSampleChannelContext *s, short *output, short *input, int nb_samples)
 {
-    short buf1[nb_samples];
+    short *buf1;
     short *buftmp;
 
+    buf1= (short*) malloc( nb_samples * sizeof(short) );
+
     /* first downsample by an integer factor with averaging filter */
     if (s->iratio > 1) {
         buftmp = buf1;
@@ -213,6 +209,7 @@
     } else {
         memcpy(output, buftmp, nb_samples * sizeof(short));
     }
+    free(buf1);
     return nb_samples;
 }
 
@@ -251,9 +248,10 @@
 int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples)
 {
     int i, nb_samples1;
-    short bufin[2][nb_samples];
-    short bufout[2][(int)(nb_samples * s->ratio) + 16]; /* make some zoom to avoid round pb */
+    short *bufin[2];
+    short *bufout[2];
     short *buftmp2[2], *buftmp3[2];
+    int lenout;
 
     if (s->input_channels == s->output_channels && s->ratio == 1.0) {
         /* nothing to do */
@@ -261,6 +259,15 @@
         return nb_samples;
     }
 
+    /* XXX: move those malloc to resample init code */
+    bufin[0]= (short*) malloc( nb_samples * sizeof(short) );
+    bufin[1]= (short*) malloc( nb_samples * sizeof(short) );
+    
+    /* make some zoom to avoid round pb */
+    lenout= (int)(nb_samples * s->ratio) + 16;
+    bufout[0]= (short*) malloc( lenout * sizeof(short) );
+    bufout[1]= (short*) malloc( lenout * sizeof(short) );
+
     if (s->input_channels == 2 &&
         s->output_channels == 1) {
         buftmp2[0] = bufin[0];
@@ -292,6 +299,11 @@
         stereo_mux(output, buftmp3[0], buftmp3[1], nb_samples1);
     }
 
+    free(bufin[0]);
+    free(bufin[1]);
+
+    free(bufout[0]);
+    free(bufout[1]);
     return nb_samples1;
 }