On Sat, Aug 10, 2002 at 04:05:40PM -0700, Martin Wolters wrote:
> On Saturday 10 August 2002 09:49, Mark Rages wrote:
> > Anyhow, try something like this:
> >
> > u16 *u16_buffer = (u16 *)buf;
> > float sample[samplesInBuffer]
> >
> > for (i=0; i<samplesInBuffer; i++)
> >    sample[i]=u16_buffer[i]; // implicit conversion to float
> 
> Well, that doesn't seem to work for me. If I use "s16" instead, it sounds a 
> little more like music (I actually can recognize a song). But it's far from 
> being undistored. I am wondering, if a byte-swap might be required and how to 
> do that. 
> 
> -M
> 
> PS.: I assume "u16" is equivalent to "__u16" as defined in <linux/types.h>, 
> correct? I now use the following lines:
> #include <linux/types.h>
> #define s16 __s16
> #define u16 __u16
> 

Ahh, I forgot CDDA is signed.

Yes, I meant the u16 in the general sense that you picked up on.

Well, you can try a byte-swap like this:

#include <string.h> // for swab()
#include <asm/byteorder.h> // for __LITTLE_ENDIAN macro

float sample[samplesInBuffer]; 

#ifdef __LITTLE_ENDIAN
        s16 s16_buffer[samplesInBuffer];
        swab(buf, s16_buffer, samplesInBuffer*sizeof(s16));
#else
        s16 *s16buffer = (s16 *)buf;
#endif

for (i=0; i<samplesInBuffer; i++)
    sample[i]=s16_buffer[i]; // implicit conversion to float

Regards,
Mark

Reply via email to