I have been battling for days/weeks now to try and find out how to extract a track from an audio cd and dump it into a raw file. I did it but its not doing it correctly. Its for a cource project that I'm doing at university. My project is finished but for an extra 10% I have to write a CD dumper.
When I run it through my RAW-audio-file player, all I hear is high pitched garbage sound. I know that my player works because I used a raw file created by cdda2wav and it worked 100%!
So I have a few questions:
* What are the sampling rate, channels, and bits that I can expect when I call the "ioctl(cd, CDROMREADRAW, &msf);" function?
* What mode should I use to read data from a track?
cdrom.h gives me the following (from what I know):
* What should I do to the data read from the CD-Rom to be in the AFMT_S16_BE format? I have tried all the formats to play my raw audio but none works.
Sorry for all the questions but I really can't find anything on the web about this. I hope some of you can help me.
Here is my code for dumping the audio:
struct track_info *tr;
struct cdrom_msf msf;
int total_frames; //How many (CD_FRAME_SIZE) frames are going to be needed to read in a whole track.
//Now we have obtain the necessary information
//about the track we wish to retrieve and work
//out how many FRAMES are going to be needed
//to write out that track to the RAW file.
tr = getTracksInfo();
total_frames = tr[track_index].end_min * CD_SECS * CD_FRAMES + tr[track_index].end_sec * CD_SECS + tr[track_index].end_frame;
total_frames -= tr[track_index].offset_min * CD_SECS * CD_FRAMES + tr[track_index].offset_sec * CD_SECS + tr[track_index].offset_frame;
msf.cdmsf_min0 = tr[track_index].offset_min;
msf.cdmsf_sec0 = tr[track_index].offset_sec;
msf.cdmsf_frame0 = tr[track_index].offset_frame;
progress_total = total_frames / 20;
progress_cur = progress_total;
//Start reading in and writing out frames
for(i = 0; i < total_frames; ++i)
readData(&msf, buffer, CD_FRAMESIZE_RAW);
fwrite(buffer, sizeof(char) * CD_FRAMESIZE_RAW, 1, fp);
if(progress_cur >= progress_total)
progress_cur = 0;
printf("%.2f%% complete...\n", i / (float)total_frames * 100.0f);
if(msf.cdmsf_frame0 >= CD_FRAMES)
msf.cdmsf_frame0 = 0;
if(msf.cdmsf_sec0 > CD_SECS)
msf.cdmsf_sec0 = 0;
void readData(struct cdrom_msf *msf, char *buffer, int frame_size)
ioctl(cd, CDROMREADRAW, &msf);
memcpy(buffer, msf, sizeof(char) * frame_size);
int len_min; //You'd be interrested in the len_* fields!
BOOL music_track; //If false, it has to be a data track