2006-02-24 04:48:15 +00:00
|
|
|
#include "i_musicinterns.h"
|
|
|
|
#include "i_cd.h"
|
2014-06-25 11:25:36 +00:00
|
|
|
#include "files.h"
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-08-03 03:54:48 +00:00
|
|
|
void CDSong::Play (bool looping, int subsong)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
m_Status = STATE_Stopped;
|
|
|
|
m_Looping = looping;
|
|
|
|
if (m_Track != 0 ? CD_Play (m_Track, looping) : CD_PlayCD (looping))
|
|
|
|
{
|
|
|
|
m_Status = STATE_Playing;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDSong::Pause ()
|
|
|
|
{
|
|
|
|
if (m_Status == STATE_Playing)
|
|
|
|
{
|
|
|
|
CD_Pause ();
|
|
|
|
m_Status = STATE_Paused;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDSong::Resume ()
|
|
|
|
{
|
|
|
|
if (m_Status == STATE_Paused)
|
|
|
|
{
|
|
|
|
if (CD_Resume ())
|
|
|
|
m_Status = STATE_Playing;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDSong::Stop ()
|
|
|
|
{
|
|
|
|
if (m_Status != STATE_Stopped)
|
|
|
|
{
|
|
|
|
m_Status = STATE_Stopped;
|
|
|
|
CD_Stop ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CDSong::~CDSong ()
|
|
|
|
{
|
|
|
|
Stop ();
|
|
|
|
m_Inited = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CDSong::CDSong (int track, int id)
|
|
|
|
{
|
|
|
|
bool success;
|
|
|
|
|
|
|
|
m_Inited = false;
|
|
|
|
|
|
|
|
if (id != 0)
|
|
|
|
{
|
|
|
|
success = CD_InitID (id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
success = CD_Init ();
|
|
|
|
}
|
|
|
|
|
2008-06-25 22:16:04 +00:00
|
|
|
if (success && (track == 0 || CD_CheckTrack (track)))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
m_Inited = true;
|
|
|
|
m_Track = track;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CDSong::IsPlaying ()
|
|
|
|
{
|
|
|
|
if (m_Status == STATE_Playing)
|
|
|
|
{
|
|
|
|
if (CD_GetMode () != CDMode_Play)
|
|
|
|
{
|
|
|
|
Stop ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m_Status != STATE_Stopped;
|
|
|
|
}
|
|
|
|
|
2014-06-25 11:25:36 +00:00
|
|
|
CDDAFile::CDDAFile (std::auto_ptr<FileReader> reader)
|
2006-02-24 04:48:15 +00:00
|
|
|
: CDSong ()
|
|
|
|
{
|
|
|
|
DWORD chunk;
|
|
|
|
WORD track;
|
|
|
|
DWORD discid;
|
2014-06-25 11:25:36 +00:00
|
|
|
long endpos = reader->Tell() + reader->GetLength() - 8;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
// I_RegisterSong already identified this as a CDDA file, so we
|
|
|
|
// just need to check the contents we're interested in.
|
2014-06-25 11:25:36 +00:00
|
|
|
reader->Seek(12, SEEK_CUR);
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2014-06-25 11:25:36 +00:00
|
|
|
while (reader->Tell() < endpos)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2014-06-25 11:25:36 +00:00
|
|
|
reader->Read(&chunk, 4);
|
2006-02-24 04:48:15 +00:00
|
|
|
if (chunk != (('f')|(('m')<<8)|(('t')<<16)|((' ')<<24)))
|
|
|
|
{
|
2014-06-25 11:25:36 +00:00
|
|
|
reader->Read(&chunk, 4);
|
|
|
|
reader->Seek(chunk, SEEK_CUR);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-06-25 11:25:36 +00:00
|
|
|
reader->Seek(6, SEEK_CUR);
|
|
|
|
reader->Read(&track, 2);
|
|
|
|
reader->Read(&discid, 4);
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (CD_InitID (discid) && CD_CheckTrack (track))
|
|
|
|
{
|
|
|
|
m_Inited = true;
|
|
|
|
m_Track = track;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|