[xiph-commits] r3596 - libfishsound/trunk/src/examples

conrad at svn.annodex.net conrad at svn.annodex.net
Mon May 5 01:32:01 PDT 2008


Author: conrad
Date: 2008-05-05 01:32:01 -0700 (Mon, 05 May 2008)
New Revision: 3596

Modified:
   libfishsound/trunk/src/examples/fishsound-decenc.c
Log:
fix use of unintialized fsinfo in fishsound-decenc example


Modified: libfishsound/trunk/src/examples/fishsound-decenc.c
===================================================================
--- libfishsound/trunk/src/examples/fishsound-decenc.c	2008-05-05 08:31:56 UTC (rev 3595)
+++ libfishsound/trunk/src/examples/fishsound-decenc.c	2008-05-05 08:32:01 UTC (rev 3596)
@@ -48,6 +48,7 @@
   FishSound * encoder;
   int format;
   int interleave;
+  int blocksize;
   int channels;
   float ** pcm;
   int begun;
@@ -108,6 +109,16 @@
     fish_sound_set_interleave (ed->encoder, ed->interleave);
     fish_sound_set_encoded_callback (ed->encoder, encoded, ed);
 
+    ed->channels = fsinfo.channels;
+    if (ed->interleave) {
+      ed->pcm = (float **) malloc (sizeof (float) * ed->channels * ed->blocksize);
+    } else {
+      ed->pcm = (float **) malloc (sizeof (float *) * ed->channels);
+      for (i = 0; i < ed->channels; i++) {
+        ed->pcm[i] = (float *) malloc (sizeof (float) * ed->blocksize);
+      }
+    }
+
     ed->begun = 1;
   }
 
@@ -132,7 +143,6 @@
 	       int interleave, int blocksize)
 {
   FS_DecEnc * ed;
-  FishSoundInfo fsinfo;
   int i;
 
   if (infilename == NULL || outfilename == NULL) return NULL;
@@ -155,19 +165,15 @@
   fish_sound_set_decoded_float_ilv (ed->decoder, decoded, ed);
 
   ed->format = format;
+  ed->interleave = interleave;
+  ed->blocksize = blocksize;
   ed->begun = 0;
   ed->b_o_s = 1;
-  ed->channels = fsinfo.channels; /* FIXME: fsinfo is unitialized! */
-  ed->interleave = interleave;
 
-  if (interleave) {
-    ed->pcm = (float **) malloc (sizeof (float) * ed->channels * blocksize);
-  } else {
-    ed->pcm = (float **) malloc (sizeof (float *) * ed->channels);
-    for (i = 0; i < ed->channels; i++) {
-      ed->pcm[i] = (float *) malloc (sizeof (float) * blocksize);
-    }
-  }
+  /* Delay the setting of channels and allocation of PCM buffers until
+   * the number of channels is known from decoding the headers */
+  ed->channels = 0;
+  ed->pcm = NULL;
 
   ed->frames_in = 0;
   ed->frames_out = 0;



More information about the commits mailing list