分类: C/C++
2008-08-01 17:00:52
HANDLE m_hDevice; CString FileName=”F:”; m_hDevice =CreateFile("\\\\.\\" FileName, // 文件名路径 GENERIC_READ, // 读写方式 FILE_SHARE_READ | FILE_SHARE_WRITE, // 共享方式 NULL, // 默认的安全描述符 OPEN_EXISTING, // 创建方式 0, // 不需设置文件属性 NULL); // 不需参照模板文件3、读取CD参数
BOOL DeviceIoControl( HANDLE hDevice, // 设备句柄 DWORD dwIoControlCode, // 控制码 LPVOID lpInBuffer, // 输入数据缓冲区指针 DWORD nInBufferSize, // 输入数据缓冲区长度 LPVOID lpOutBuffer, // 输出数据缓冲区指针 DWORD nOutBufferSize, // 输出数据缓冲区长度 LPDWORD lpBytesReturned, // 输出数据实际长度单元长度 LPOVERLAPPED lpOverlapped // 重叠操作结构指针 );
BOOL bResult; DWORD dwOutBytes; CDROM_TOC CdromTOC; //曲目信息结构,详细请看MSDN bResult=DeviceIoControl(m_hDevice, IOCTL_CDROM_READ_TOC,NULL,0, &CdromTOC, sizeof(CdromTOC), &dwOutBytes, (LPOVERLAPPED)NULL);5、获取曲目始点
DWORD CCdToWavDlg::GetStartSector(int track) { return (CdromTOC.TrackData[track-1].Address[1]*60*75 CdromTOC.TrackData[track-1].Address[2]*75 CdromTOC.TrackData[track-1].Address[3])-150; }6、获取曲目终点
DWORD CCdToWavDlg::GetEndSector(int track) { return (CdromTOC.TrackData[track].Address[1]*60*75 CdromTOC.TrackData[track].Address[2]*75 CdromTOC.TrackData[track].Address[3])-151; }7、读取曲目信息
BOOL CCdToWavDlg::ReadSector(int sector,BYTE Buffer[], int NumSectors) { DWORD dwOutBytes; RAW_READ_INFO rri; //结构详细请看MSDN rri.TrackMode =(TRACK_MODE_TYPE)2; rri.SectorCount = (DWORD)NumSectors; rri.DiskOffset =(DWORD64)(sector*CB_CDROMSECTOR); if (DeviceIoControl(m_hDevice,IOCTL_CDROM_RAW_READ, &rri, sizeof(rri), Buffer, (DWORD)NumSectors*CB_AUDIO,&dwOutBytes, (LPOVERLAPPED)NULL)) return true; return false; }8、 文件生成
标志符(RIFF) |
数据大小 |
格式类型("WAVE") |
"fmt" |
Sizeof(WAVEFORMATEX) |
WAVEFORMATEX |
"data" |
声音数据大小 |
声音数据 |