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

> On Fri, Aug 09, 2002 at 06:18:44PM -0700, Martin Wolters wrote:
> >  I am trying to read out data from a CDDA and convert it into float (on
> > Linux x86). The data from the CD is returned in an unsigned char buffer.
> > That code looks something like this:
> >
> > int cd_read_audio(int cdrom_fd, int lba, int num, unsigned char *buf)
> > {
> >    struct cdrom_read_audio ra;
> >    ra.addr.lba = lba;
> >    ra.addr_format = CDROM_LBA;
> >    ra.nframes = num;
> >    ra.buf = buf;
> >   ioctl(cdrom_fd, CDROMREADAUDIO, &ra);
> > }
> >
> > I tried using something like the following to convert the data:
> >
> > float samples[samplesInBuffer];
> > for(i=0;i<samplesInBuffer;i++) {
> >    int value = (buf[1] << 8) + (buf[0] << 16);
> >    sample[i] = ((float)(value/256))*scalefactor;
> >    buf += 2;
> > }
> >
> > I would expect left/right audio interleaved, but that doesn't sound like
> > regular audio at all. Any ideas? Or even better: Are you aware of any
> > library such as portaudio or libsndfile that will do that for me? (Looks
> > like libcdaudio doesn't actually touch the audio data but only controls
> > the CD drive. Correct?)
> >
> > -M
>
> libparanoia?
>
> http://www.xiph.org/paranoia
>
> What's going on with that project? The web page has been stagnant for
> two years.
>
> 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
>
> Regards,
> Mark

Reply via email to