2008-09-18 03:15:49 +00:00
|
|
|
/*
|
|
|
|
* Project 64 - A Nintendo 64 emulator.
|
|
|
|
*
|
|
|
|
* (c) Copyright 2001 zilmar (zilmar@emulation64.com) and
|
|
|
|
* Jabo (jabo@emulation64.com).
|
|
|
|
*
|
|
|
|
* pj64 homepage: www.pj64.net
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify and distribute Project64 in both binary and
|
|
|
|
* source form, for non-commercial purposes, is hereby granted without fee,
|
|
|
|
* providing that this license information and copyright notice appear with
|
|
|
|
* all copies and any derived work.
|
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied
|
|
|
|
* warranty. In no event shall the authors be held liable for any damages
|
|
|
|
* arising from the use of this software.
|
|
|
|
*
|
|
|
|
* Project64 is freeware for PERSONAL USE only. Commercial users should
|
|
|
|
* seek permission of the copyright holders first. Commercial use includes
|
|
|
|
* charging money for Project64 or software derived from Project64.
|
|
|
|
*
|
|
|
|
* The copyright holders request that bug fixes and improvements to the code
|
|
|
|
* should be forwarded to them so if they want them.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <windows.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "..\..\N64 System.h"
|
|
|
|
|
|
|
|
|
|
|
|
// ****************** Testing Audio Stuff *****************
|
2010-05-22 04:47:15 +00:00
|
|
|
CAudio::CAudio (void)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
ResetAudioSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
// I seem to be getting clicking when I set CF to 1 and VSyncTiming to 789000
|
|
|
|
void CAudio::ResetAudioSettings (void)
|
|
|
|
{
|
2010-05-22 04:47:15 +00:00
|
|
|
//float CAudio::VSyncTiming = 789000.0f; // 500000
|
|
|
|
////const float VSyncTiming = 760000.0f;
|
|
|
|
m_FramesPerSecond = 60.0f;
|
|
|
|
m_BytesPerSecond = 0;
|
|
|
|
m_Length = 0;
|
|
|
|
m_Status = 0;
|
|
|
|
m_CountsPerByte = 0;
|
|
|
|
m_SecondBuff = 0;
|
|
|
|
m_CurrentCount = 0;
|
|
|
|
m_CurrentLength = 0;
|
|
|
|
m_IntScheduled = 0;
|
|
|
|
m_VSyncTiming = 789000.0f;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2010-05-22 04:47:15 +00:00
|
|
|
void CAudio::AiCallBack ()
|
|
|
|
{
|
|
|
|
if (m_SecondBuff != 0) {
|
|
|
|
m_IntScheduled = (DWORD)((double)m_SecondBuff * m_CountsPerByte);
|
|
|
|
_Reg->ChangeTimerFixed(AiTimer, m_IntScheduled);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
2010-05-22 04:47:15 +00:00
|
|
|
m_CurrentCount = _Reg->COUNT_REGISTER;
|
|
|
|
m_CurrentLength = m_SecondBuff;
|
|
|
|
m_SecondBuff = 0;
|
|
|
|
m_Status &= 0x7FFFFFFF;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2010-05-22 04:47:15 +00:00
|
|
|
DWORD CAudio::AiGetLength (void)
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
double AiCounts;
|
|
|
|
// static DWORD LengthReadHack = 0;
|
|
|
|
// if ((COUNT_REGISTER - LengthReadHack) < 0x20) {
|
|
|
|
// // This is a Spin Lock... ;-/
|
|
|
|
// //COUNT_REGISTER += (DWORD)(CountsPerByte*0.5); // Lets speed up the CPU to the next Event
|
|
|
|
// //CurrentLength = 0;
|
|
|
|
// COUNT_REGISTER+=0xA; // This hack is necessary... but what is a good value??
|
|
|
|
// }
|
|
|
|
// LengthReadHack = COUNT_REGISTER;
|
2010-05-22 04:47:15 +00:00
|
|
|
AiCounts = m_CountsPerByte * m_CurrentLength;
|
|
|
|
AiCounts = AiCounts - (double)(_Reg->COUNT_REGISTER - m_CurrentCount);
|
2008-09-18 03:15:49 +00:00
|
|
|
if (AiCounts < 0)
|
2010-05-22 04:47:15 +00:00
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
return 0;
|
2010-05-22 04:47:15 +00:00
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
// return 0;
|
2010-05-22 04:47:15 +00:00
|
|
|
return (DWORD)(AiCounts / m_CountsPerByte);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2010-05-22 04:47:15 +00:00
|
|
|
DWORD CAudio::AiGetStatus (void)
|
|
|
|
{
|
|
|
|
return m_Status;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2010-05-22 04:47:15 +00:00
|
|
|
void CAudio::AiSetLength (void)
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
// Set Status to FULL for a few COUNT cycles
|
2010-05-22 04:47:15 +00:00
|
|
|
if (m_CurrentLength == 0) {
|
|
|
|
m_CurrentLength = _Reg->AI_LEN_REG;
|
|
|
|
m_CurrentCount = _Reg->COUNT_REGISTER;
|
|
|
|
m_IntScheduled = (DWORD)((double)_Reg->AI_LEN_REG * m_CountsPerByte);
|
|
|
|
_Reg->ChangeTimerFixed(AiTimer, m_IntScheduled);
|
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-05-22 04:47:15 +00:00
|
|
|
void CAudio::UpdateAudioTimer (DWORD CountsPerFrame)
|
|
|
|
{
|
|
|
|
double CountsPerSecond = (DWORD)((double)CountsPerFrame * m_FramesPerSecond); // This will only work with NTSC... VSyncTiming...
|
|
|
|
m_CountsPerByte = CountsPerSecond / (double)m_BytesPerSecond;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CAudio::AiSetFrequency (DWORD Dacrate, DWORD System) {
|
|
|
|
double CountsPerSecond;
|
|
|
|
switch (System) {
|
2010-05-22 04:47:15 +00:00
|
|
|
case SYSTEM_NTSC: m_BytesPerSecond = 48681812 / (Dacrate + 1); break;
|
|
|
|
case SYSTEM_PAL: m_BytesPerSecond = 49656530 / (Dacrate + 1); break;
|
|
|
|
case SYSTEM_MPAL: m_BytesPerSecond = 48628316 / (Dacrate + 1); break;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
if (System == SYSTEM_PAL) {
|
2010-05-22 04:47:15 +00:00
|
|
|
m_FramesPerSecond = 50.0;
|
2008-09-18 03:15:49 +00:00
|
|
|
} else {
|
2010-05-22 04:47:15 +00:00
|
|
|
m_FramesPerSecond = 60.0;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
2010-05-22 04:47:15 +00:00
|
|
|
m_BytesPerSecond = (m_BytesPerSecond * 4); // This makes it Bytes Per Second...
|
|
|
|
CountsPerSecond = (double)(((double)m_VSyncTiming) * (double)60.0); // This will only work with NTSC... VSyncTiming...
|
|
|
|
m_CountsPerByte = (double)CountsPerSecond / (double)m_BytesPerSecond;
|
|
|
|
m_SecondBuff = m_Status = m_CurrentLength = 0;
|
2008-09-18 03:15:49 +00:00
|
|
|
//CountsPerByte /= CountPerOp;
|
|
|
|
}
|