[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
- To: alleg-developers@xxxxxxxxxx
- Subject: [AD] create_sample patch
- From: Chris <chris.kcat@xxxxxxxxxx>
- Date: Mon, 04 Jul 2005 15:30:00 -0700
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:user-agent:x-accept-language:mime-version:to:subject:content-type; b=QjZquNf5vD3qYGNjnteR+aycLKw+S7JsHcCyCU4vd+m3fEuOF08dEhPijADnf5wh9dZTpaR772TyMS1V79b1uKJwhdmW3il2U3qAoYzO8OhGL3xjdu1LifrAvUi4fW9FCza4nHAWE9/nQWS+zeq/rSe2YzkPnwpMoWSn1qZUgdI=
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;