| Re: [AD] Bug with WAV loader on latest WIP |
[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]
> The latest WIP has this code in load_wav:
>
> for (i=0; i<len*channels; i++) {
> if ((s = pack_igetw(f)) == EOF) {
> destroy_sample(spl);
> spl = NULL;
> break;
> }
> ((signed short *)spl->data)[i] = s^0x8000;
> }
>
> However, EOF is -1, which is 0xFFFF and is a valid sample for a 16-bit
> wave file to have in it. Since the return value of pack_igetw is being
> cast to short to be placed into s, there is no distinction between the
> sample 0xFFFF and the error code -1.
> This is causing load_wav to fail on some perfectly valid wave files.
Oops! My bad. I didn't see that 's' was a 'signed short', which is a
non-sense since pack_igetw() returns an 'int'.
> I propose the following fix:
>
> int in;
> for (i=0; i<len*channels; i++) {
> if ((in = pack_igetw(f)) == EOF) {
> destroy_sample(spl);
> spl = NULL;
> break;
> }
> s = in;
> ((signed short *)spl->data)[i] = s^0x8000;
> }
>
> which reads from the file initially into a 32-bit integer, so that the
> 0xFFFF sample value will be accurately stored as 65535, completely
> distinct from -1, the fail value.
Fine with me. I'm going to apply the slighly modified patch that is
attached. Could you confirm that it fixes your problem too ?
--
Eric BotcazouAttachment:
sound.diff
Description: Binary data
| Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |