Re: [linux-audio-dev] CDDA interface - How to convert to float? Any library?

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [linux-audio-dev] CDDA interface - How to convert to float? Any library?
From: Mark Rages (markrages_AT_mlug.missouri.edu)
Date: Sat Aug 10 2002 - 19:49:14 EEST


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


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : Sat Aug 10 2002 - 19:52:48 EEST