Mercurial > mm7
changeset 2507:6dcc6e8dd041
.
author | Ritor1 |
---|---|
date | Thu, 25 Sep 2014 10:40:16 +0600 |
parents | 9b96a51011fb |
children | 491f0babd563 |
files | Media/Audio/AudioCD.cpp Media/Audio/AudioCD.h |
diffstat | 2 files changed, 0 insertions(+), 155 deletions(-) [+] |
line wrap: on
line diff
--- a/Media/Audio/AudioCD.cpp Thu Sep 25 10:39:49 2014 +0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,119 +0,0 @@ -#define _CRTDBG_MAP_ALLOC -#include <stdlib.h> -#include <crtdbg.h> -#define _CRT_SECURE_NO_WARNINGS - -#include <string> -#include "AudioCD.h" -#include "Engine/mm7_data.h" -#include "Engine/Log.h" -//#include "OSAPI.h" -#include <sstream> -//char в wchar_t -bool char2wchar_t(char *str1, wchar_t *str2) -{ - std::wstringstream st; - st << str1; - return !(st >> str2).fail(); -}; -class CDaudio *CD_Audio; - -void CDaudio::CDRomOpen(bool bOpenDrive, char *drive) -{ - DWORD flags; - MCIERROR err; - wchar_t *wStr = new wchar_t; - - char2wchar_t(drive,wStr); - open.lpstrDeviceType = (LPCWSTR)(DWORD)MCI_DEVTYPE_CD_AUDIO; - open.lpstrElementName = (LPCWSTR)wStr; - - flags = MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID; - - if (!mciSendCommand(0, MCI_OPEN, flags, (DWORD) &open)) - { - // The device opened successfully; get the device ID. - MCI_STATUS_PARMS mciStatusParms; - mciStatusParms.dwItem = MCI_STATUS_READY; - if (mciSendCommand(open.wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD)&mciStatusParms)) - { - Log::Warning(L"CD device is not ready"); - return; - } - // Set the time format to minute/second/frame (MSF) format. - mciSetParms.dwTimeFormat = MCI_FORMAT_TMSF; - flags = MCI_SET_TIME_FORMAT; - if ( mciSendCommand(open.wDeviceID, MCI_SET, flags, (DWORD)&mciSetParms)) - { - mciSendCommand(open.wDeviceID, MCI_CLOSE, 0, NULL); - Log::Warning(L"audio time format error"); - return; - } - // Get the number of tracks; - // limit to number that can be displayed (20). - mciStatusParms.dwItem = MCI_STATUS_NUMBER_OF_TRACKS; - if (mciSendCommand(open.wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD)&mciStatusParms)) - { - Log::Warning(L"No audio tracks"); - return; - } - CD_Audio->number_of_tracks = mciStatusParms.dwReturn;//количество треков - - for ( unsigned int i = 0; i < CD_Audio->number_of_tracks; i++) - { - mciStatusParms.dwTrack = i + 1; - mciStatusParms.dwItem = MCI_STATUS_LENGTH; - if ( mciSendCommand(open.wDeviceID, MCI_STATUS, MCI_STATUS_ITEM + MCI_TRACK, (DWORD)&mciStatusParms)) - { - Log::Warning(L"audio track is corrupt"); - return; - } - CD_Audio->tracks[i].track_length = mciStatusParms.dwReturn;//длина трека - - // For each track, get and save the starting location - mciStatusParms.dwItem = MCI_STATUS_POSITION; - if ( mciSendCommand(open.wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK, (DWORD)(LPVOID) &mciStatusParms)) - { - mciSendCommand(open.wDeviceID, MCI_CLOSE, 0, NULL); - return; - } - CD_Audio->tracks[i].position = mciStatusParms.dwReturn; - - mciStatusParms.dwItem = MCI_CDA_STATUS_TYPE_TRACK; - mciSendCommand(open.wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK, (DWORD)&mciStatusParms); - CD_Audio->tracks[i].track_type = mciStatusParms.dwReturn;// MCI_CDA_TRACK_AUDIO = 1088, MCI_CDA_TRACK_OTHER = 1089 - - CD_Audio->tracks[i].playing_time_minute = MCI_MSF_MINUTE(CD_Audio->tracks[i].track_length); - CD_Audio->tracks[i].playing_time_second = MCI_MSF_SECOND(CD_Audio->tracks[i].track_length); - - } - - /* - MCI_PLAY_PARMS playParams; - MCIDEVICEID devID = open.wDeviceID; - playParams.dwCallback = 0; - playParams.dwFrom = 0; - playParams.dwTo = 0; - err = mciSendCommand(devID, MCI_PLAY, (DWORD)MCI_WAIT, (DWORD)(LPVOID)&playParams ); - if ( err ) - __debugbreak();*/ - } -} - -void CDaudio::CDAudioPlay(int TrackID) -{ - DWORD flags; - - - - //DWORD lengthTrack = LengthTrack(TrackID); - mciPlayParms.dwFrom = MCI_MAKE_TMSF(TrackID, 0, 0, 0); - // mciPlayParms.dwTo = MCI_MAKE_TMSF(TrackID, CD_Audio->tracks[TrackID].playing_time_minute, - //CD_Audio->tracks[TrackID].playing_time_second, 0); - flags = MCI_FROM;// | MCI_TO; - if (mciSendCommand(open.wDeviceID, MCI_PLAY, flags, (DWORD)&mciPlayParms)) - { - Log::Warning(L"audio track is corrupt"); - return; - } -} \ No newline at end of file
--- a/Media/Audio/AudioCD.h Thu Sep 25 10:39:49 2014 +0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -#define WIN32_LEAN_AND_MEAN -#include <windows.h> - -#include <MMSystem.h> -//#pragma comment(lib, "winmm.lib") -struct CDAudioTrack -{ - int track_length; - int track_type; - int playing_time_minute; - int playing_time_second; - int position; -}; - -class CDaudio -{ - private: - MCI_OPEN_PARMS open; - MCI_SET_PARMS mciSetParms; - MCI_PLAY_PARMS mciPlayParms; - int number_of_tracks; - CDAudioTrack tracks[20]; - - public: - - CDaudio() - { - ZeroMemory(&open, sizeof(open)); - number_of_tracks = 0; - memset(&tracks, 0, sizeof(CDAudioTrack) * 20); - } - - void CDRomOpen(bool bOpenDrive, char *drive); - void CDAudioPlay(int TrackID); -}; -extern class CDaudio *CD_Audio; \ No newline at end of file