[AD] create_sample patch

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


While playing with create_sample, I wondered if it cleared the data to silence or if I had to do it myself. The docs didn't mention whether it does or not, but in the source it appeared to set it to 0. However, since Allegro's samples use unsigned data, this is obviously wrong.

This patch properly sets the sample data to 0x80 and 0x8000 for 8-bit and 16-bit respectively. Perhaps someone should also modify the docs to mention that the sample is cleared to silence as well.
Index: src/sound.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/sound.c,v
retrieving revision 1.25
diff -u -r1.25 sound.c
--- src/sound.c	28 Apr 2005 08:53:37 -0000	1.25
+++ src/sound.c	4 Jul 2005 22:24:02 -0000
@@ -1077,7 +1077,14 @@
       return NULL;
    }
 
-   memset(spl->data, 0, len * ((bits==8) ? 1 : sizeof(short)) * ((stereo) ? 2 : 1));
+   if (bits == 16) {
+      int i;
+      for (i=0; i<(len*((stereo) ? 2 : 1)); ++i)
+	 ((short*)spl->data)[i] = 0x8000;
+   }
+   else {
+      memset(spl->data, 0x80, len * ((stereo) ? 2 : 1));
+   }
 
    lock_sample(spl);
    return spl;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/