Getting Disc Information

Once you get a CD device handle, call CDROM_IOCTL_DISC_INFO to get the table of contents for the disc. The table of contents (TOC) is contained in the Q-channel data on the lead-in track. It provides the starting and ending track numbers and the starting address of the lead-out track. The starting and ending track numbers are binary values, not binary-coded decimals. Read and cache TOC information when you initialize the drive, so that when CDROM_IOCTL_DISC_INFO is called, the application will not interrupt play to get this information. The first and last track numbers do not include the lead-in and lead-out tracks of the session.

After getting the disc TOC, call the CDROM_IOCTL_TRACK_INFO function to find out the track starting address and control information. This function takes a binary track number in the range specified by the first and last track number for the disc. It returns the Red Book address for the starting point and control information for the track. The Red Book address, one of two formats used to specify an address, specifies the data location in minutes, seconds, and frames (MSF). The other address format is the High Sierra Specification format, which displays data as a logical block address.

Note MSF contains 75 frames per second. To convert address data from one format to the other, use the following formula:

Sector = (((Minute*60) + Second)*75) + Frame

The control information for the track is contained in the four most significant bits of the control information byte. The following table shows the bit field definitions.

Bit
Definition
0–3 Automatic dialog replacement (ADR) information
4 0 No pre-emphasis on audio channels
1 Pre-emphasis on audio channels
5 0 Digital copy prohibited
1 Digital copy enabled
6 0 Audio track
1 Data track
7 0 Two audio channels
1 Four audio channels

Pre-emphasis, increases the magnitude of the higher signal frequencies, improving the signal-to-noise ratio. De-emphasis resets the signal magnitude. When verifying track information, if pre-emphasis is specified, you can turn it off by calling AAM_EQPreset and setting AAM_FLAG_DEEMPHASIS.

The following code example shows how to use CDROM_IOCTL_DISC_INFO and CDROM_IOCTL_TRACK_INFO to obtain information about a CD player.

BOOL cdGetDiskInfo( void)
{
    DWORD                           RetDataLen;
    WORD                            wTrackIdx;
    CDROM_TRACKINFO         TrackInfo;

    g_DiskValid = FALSE;              // Assume no disc information.

    g_DiscInfo.Reserved = 0;
    g_DiscInfo.ReqSession = 0xff;     // Do you want the last session?

    if (DeviceIoControl(g_hDev,       // Obtains the disc TOC
            CDROM_IOCTL_DISC_INFO,
            &g_DiscInfo, 
            sizeof(g_DiscInfo),
            NULL, 0,
            &RetDataLen, NULL) == FALSE)
    {
         return( FALSE);
    } 
   
    g_nTracks = (WORD)g_DiscInfo.LastTrack + 1 - g_DiscInfo.FirstTrack;
    
    for( wTrackIdx = 0; wTrackIdx < g_nTracks; wTrackIdx++)
    {               
        TrackInfo.TrackNumber = g_DiscInfo.FirstTrack + wTrackIdx;

        if (DeviceIoControl(g_hDev,
                CDROM_IOCTL_TRACK_INFO, // Obtains the track starting
                                        // address and control
                                        // information
                &TrackInfo, 
                sizeof(TrackInfo),
                NULL, 0,
                &RetDataLen, NULL) == FALSE)
    {    
        return( FALSE);
        } 
        
        g_Tracks[wTrackIdx].ti_msfaddr = TrackInfo.TrackAddr;
        g_Tracks[wTrackIdx].ti_ctl = TrackInfo.TrackControl;
    }
    g_DiskValid = TRUE;     // Assume no disc information.
    return(TRUE);
}