2012-12-19 09:30:18 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* *
|
|
|
|
* Project 64 - A Nintendo 64 emulator. *
|
|
|
|
* http://www.pj64-emu.com/ *
|
|
|
|
* Copyright (C) 2012 Project64. All rights reserved. *
|
|
|
|
* *
|
|
|
|
* License: *
|
|
|
|
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
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
|
|
|
{
|
|
|
|
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;
|
2012-11-29 11:23:35 +00:00
|
|
|
m_CountsPerByte = g_System->AiCountPerBytes(); // should be calculated ... see below, instead allow from user settings
|
2010-06-29 02:11:22 +00:00
|
|
|
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
|
|
|
{
|
2012-11-13 05:06:46 +00:00
|
|
|
WriteTraceF(TraceAudio,__FUNCTION__ ": Start (m_SecondBuff = %d)",m_SecondBuff);
|
2012-11-17 02:31:46 +00:00
|
|
|
DWORD TimeLeft = g_SystemTimer->GetTimer(CSystemTimer::AiTimer), Res = 0;
|
2010-06-14 21:14:58 +00:00
|
|
|
if (TimeLeft > 0)
|
2010-05-22 04:47:15 +00:00
|
|
|
{
|
2012-11-13 05:06:46 +00:00
|
|
|
Res = (TimeLeft / m_CountsPerByte) + m_SecondBuff;
|
2010-05-22 04:47:15 +00:00
|
|
|
}
|
2012-11-13 05:06:46 +00:00
|
|
|
WriteTraceF(TraceAudio,__FUNCTION__ ": Done (res = %d, TimeLeft = %d)",Res, TimeLeft);
|
|
|
|
return Res;
|
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
|
|
|
{
|
2012-11-13 05:06:46 +00:00
|
|
|
WriteTraceF(TraceAudio,__FUNCTION__ ": m_Status = %X",m_Status);
|
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
|
|
|
{
|
2012-11-17 02:18:14 +00:00
|
|
|
WriteTraceF(TraceAudio,__FUNCTION__ ": Start (g_Reg->AI_LEN_REG = %d)",g_Reg->AI_LEN_REG);
|
|
|
|
if (g_Reg->AI_LEN_REG != 0)
|
2010-06-14 21:14:58 +00:00
|
|
|
{
|
2012-11-17 02:18:14 +00:00
|
|
|
if (g_Reg->AI_LEN_REG >= 0x20000)
|
2012-11-02 23:27:19 +00:00
|
|
|
{
|
2012-11-17 02:18:14 +00:00
|
|
|
WriteTraceF(TraceAudio,__FUNCTION__ ": *** Ignoring Write, To Large (%X)",g_Reg->AI_LEN_REG);
|
2010-07-05 11:29:46 +00:00
|
|
|
} else {
|
2012-11-06 10:23:47 +00:00
|
|
|
m_Status |= 0x80000000;
|
2012-11-17 02:31:46 +00:00
|
|
|
if (g_SystemTimer->GetTimer(CSystemTimer::AiTimer) == 0)
|
2012-11-06 08:09:56 +00:00
|
|
|
{
|
2012-11-13 05:06:46 +00:00
|
|
|
if (m_SecondBuff)
|
|
|
|
{
|
2012-11-17 00:58:31 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__,__LINE__);
|
2012-11-13 05:06:46 +00:00
|
|
|
}
|
2012-11-17 02:18:14 +00:00
|
|
|
WriteTraceF(TraceAudio,__FUNCTION__ ": Set Timer AI_LEN_REG: %d m_CountsPerByte: %d",g_Reg->AI_LEN_REG,m_CountsPerByte);
|
2012-11-17 02:31:46 +00:00
|
|
|
g_SystemTimer->SetTimer(CSystemTimer::AiTimer,g_Reg->AI_LEN_REG * m_CountsPerByte,false);
|
2012-11-06 08:09:56 +00:00
|
|
|
} else {
|
2012-11-17 02:18:14 +00:00
|
|
|
WriteTraceF(TraceAudio,__FUNCTION__ ": Increasing Second Buffer (m_SecondBuff %d Increase: %d)",m_SecondBuff,g_Reg->AI_LEN_REG);
|
|
|
|
m_SecondBuff += g_Reg->AI_LEN_REG;
|
2012-11-06 08:09:56 +00:00
|
|
|
}
|
2012-11-02 23:27:19 +00:00
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
} else {
|
2012-11-13 05:06:46 +00:00
|
|
|
WriteTraceF(TraceAudio,__FUNCTION__ ": *** Reset Timer to 0");
|
2012-11-17 02:31:46 +00:00
|
|
|
g_SystemTimer->StopTimer(CSystemTimer::AiTimer);
|
2010-07-05 11:29:46 +00:00
|
|
|
m_SecondBuff = 0;
|
|
|
|
m_Status = 0;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
2010-07-05 11:29:46 +00:00
|
|
|
|
2012-11-17 02:20:21 +00:00
|
|
|
if (g_Plugins->Audio()->LenChanged != NULL)
|
2010-06-14 21:14:58 +00:00
|
|
|
{
|
2012-11-17 02:20:21 +00:00
|
|
|
g_Plugins->Audio()->LenChanged();
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
2012-11-13 05:06:46 +00:00
|
|
|
WriteTraceF(TraceAudio,__FUNCTION__ ": Done");
|
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
|
|
|
{
|
2012-11-13 05:06:46 +00:00
|
|
|
WriteTraceF(TraceAudio,__FUNCTION__ ": Start (m_SecondBuff = %d)",m_SecondBuff);
|
2012-11-06 10:23:47 +00:00
|
|
|
if (m_SecondBuff != 0)
|
2012-11-02 23:27:19 +00:00
|
|
|
{
|
2012-11-17 02:31:46 +00:00
|
|
|
g_SystemTimer->SetTimer(CSystemTimer::AiTimer,m_SecondBuff * m_CountsPerByte,false);
|
2012-11-06 10:23:47 +00:00
|
|
|
m_SecondBuff = 0;
|
|
|
|
} else {
|
2012-11-17 02:18:14 +00:00
|
|
|
g_Reg->MI_INTR_REG |= MI_INTR_AI;
|
|
|
|
g_Reg->CheckInterrupts();
|
2012-11-06 10:23:47 +00:00
|
|
|
m_Status &= 0x7FFFFFFF;
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
2012-11-13 05:06:46 +00:00
|
|
|
WriteTraceF(TraceAudio,__FUNCTION__ ": Done",m_SecondBuff);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2012-10-06 04:09:17 +00:00
|
|
|
void CAudio::SetViIntr ( DWORD /*VI_INTR_TIME*/ )
|
2010-06-14 21:14:58 +00:00
|
|
|
{
|
2012-10-06 04:09:17 +00:00
|
|
|
/*
|
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;
|
|
|
|
}
|
2012-10-06 04:09:17 +00:00
|
|
|
*/
|
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)
|
|
|
|
{
|
2012-11-17 02:18:14 +00:00
|
|
|
WriteTraceF(TraceAudio,__FUNCTION__ "(Dacrate: %X System: %d): AI_BITRATE_REG = %X",Dacrate,System,g_Reg->AI_BITRATE_REG);
|
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;
|
2011-01-04 09:10:28 +00:00
|
|
|
m_BytesPerSecond = 194532;
|
|
|
|
m_BytesPerSecond = 128024;
|
2010-06-29 02:11:22 +00:00
|
|
|
|
|
|
|
if (System == SYSTEM_PAL) {
|
2010-10-29 03:20:25 +00:00
|
|
|
m_FramesPerSecond = 50;
|
2010-06-29 02:11:22 +00:00
|
|
|
} else {
|
2010-10-29 03:20:25 +00:00
|
|
|
m_FramesPerSecond = 60;
|
2010-06-29 02:11:22 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
|