2010-05-23 10:05:41 +00:00
|
|
|
#include "stdafx.h"
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2010-05-22 04:47:15 +00:00
|
|
|
CAudio::CAudio (void)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
Reset();
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2010-06-14 21:14:58 +00:00
|
|
|
CAudio::~CAudio (void)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-06-14 21:14:58 +00:00
|
|
|
void CAudio::Reset ( void )
|
2010-05-22 04:47:15 +00:00
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
m_CurrentLength = 0;
|
2010-05-22 04:47:15 +00:00
|
|
|
m_SecondBuff = 0;
|
2010-06-14 21:14:58 +00:00
|
|
|
m_Status = 0;
|
2010-06-30 21:35:44 +00:00
|
|
|
m_BytesPerSecond = 0;
|
2010-06-29 02:11:22 +00:00
|
|
|
m_CountsPerByte = 500; // should be calculated ... see below
|
|
|
|
m_FramesPerSecond = 60;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2010-06-14 21:14:58 +00:00
|
|
|
DWORD CAudio::GetLength ( void )
|
2010-05-22 04:47:15 +00:00
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
DWORD TimeLeft = _SystemTimer->GetTimer(CSystemTimer::AiTimer);
|
2010-06-30 21:35:44 +00:00
|
|
|
WriteTraceF(TraceError,"CAudio::GetLength: TimeLeft = %d m_CountsPerByte = %d BytesLeft = %d",TimeLeft,(int)m_CountsPerByte, (int)(TimeLeft / m_CountsPerByte));
|
2010-06-14 21:14:58 +00:00
|
|
|
if (TimeLeft > 0)
|
2010-05-22 04:47:15 +00:00
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
return TimeLeft / m_CountsPerByte;
|
2010-05-22 04:47:15 +00:00
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
return 0;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2010-06-14 21:14:58 +00:00
|
|
|
DWORD CAudio::GetStatus ( void )
|
2010-05-22 04:47:15 +00:00
|
|
|
{
|
|
|
|
return m_Status;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2010-06-14 21:14:58 +00:00
|
|
|
void CAudio::LenChanged ( void )
|
2010-05-22 04:47:15 +00:00
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
if (_Reg->AI_LEN_REG == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-30 21:35:44 +00:00
|
|
|
WriteTraceF(TraceError,"CAudio::LenChanged: m_CurrentLength = %d AI_LEN_REG = %d m_CountsPerByte = %d",m_CurrentLength,_Reg->AI_LEN_REG,(int)m_CountsPerByte);
|
2010-05-22 04:47:15 +00:00
|
|
|
if (m_CurrentLength == 0) {
|
|
|
|
m_CurrentLength = _Reg->AI_LEN_REG;
|
2010-06-14 21:14:58 +00:00
|
|
|
_SystemTimer->SetTimer(CSystemTimer::AiTimer,m_CurrentLength * m_CountsPerByte,false);
|
2008-09-18 03:15:49 +00:00
|
|
|
} else {
|
2010-05-22 04:47:15 +00:00
|
|
|
m_SecondBuff = _Reg->AI_LEN_REG;
|
|
|
|
m_Status |= 0x80000000;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
if (_Plugins->Audio()->LenChanged != NULL)
|
|
|
|
{
|
|
|
|
_Plugins->Audio()->LenChanged();
|
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2010-06-14 21:14:58 +00:00
|
|
|
void CAudio::TimerDone ( void )
|
2010-05-22 04:47:15 +00:00
|
|
|
{
|
2010-06-30 21:35:44 +00:00
|
|
|
WriteTraceF(TraceError,"CAudio::TimerDone: m_SecondBuff = %d",m_SecondBuff);
|
|
|
|
|
|
|
|
_Reg->MI_INTR_REG |= MI_INTR_AI;
|
|
|
|
_Reg->CheckInterrupts();
|
|
|
|
|
2010-06-14 21:14:58 +00:00
|
|
|
if (m_SecondBuff != 0) {
|
2010-06-30 21:35:44 +00:00
|
|
|
_SystemTimer->SetTimer(CSystemTimer::AiTimer,m_SecondBuff * m_CountsPerByte,false);
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
|
|
|
m_CurrentLength = m_SecondBuff;
|
|
|
|
m_SecondBuff = 0;
|
|
|
|
m_Status &= 0x7FFFFFFF;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2010-06-14 21:14:58 +00:00
|
|
|
void CAudio::SetViIntr ( DWORD VI_INTR_TIME )
|
|
|
|
{
|
2010-06-30 21:35:44 +00:00
|
|
|
WriteTraceF(TraceError,"CAudio::SetViIntr: VI_INTR_TIME = %d",VI_INTR_TIME);
|
|
|
|
|
2010-06-29 02:11:22 +00:00
|
|
|
double CountsPerSecond = (DWORD)((double)VI_INTR_TIME * m_FramesPerSecond);
|
2010-06-30 21:35:44 +00:00
|
|
|
if (m_BytesPerSecond != 0)
|
|
|
|
{
|
|
|
|
//m_CountsPerByte = (double)CountsPerSecond / (double)m_BytesPerSecond;
|
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
|
|
|
|
|
2010-06-29 02:11:22 +00:00
|
|
|
void CAudio::SetFrequency (DWORD Dacrate, DWORD System)
|
|
|
|
{
|
2010-06-30 21:35:44 +00:00
|
|
|
WriteTraceF(TraceError,"CAudio::SetFrequency: Dacrate = %d System = %d",Dacrate,System);
|
|
|
|
|
2010-06-29 02:11:22 +00:00
|
|
|
DWORD Frequency;
|
|
|
|
|
|
|
|
switch (System) {
|
|
|
|
case SYSTEM_PAL: Frequency = 49656530 / (Dacrate + 1); break;
|
|
|
|
case SYSTEM_MPAL: Frequency = 48628316 / (Dacrate + 1); break;
|
|
|
|
default: Frequency = 48681812 / (Dacrate + 1); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//nBlockAlign = 16 / 8 * 2;
|
|
|
|
m_BytesPerSecond = Frequency * 4;
|
|
|
|
|
|
|
|
if (System == SYSTEM_PAL) {
|
|
|
|
m_FramesPerSecond = 50.0;
|
|
|
|
} else {
|
|
|
|
m_FramesPerSecond = 60.0;
|
|
|
|
}
|
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
|