i think i know now where is the problem.
Its in the programmable timer.
Im doing the following:
im sampling at 81 cpu cc per sample. This is more or less 1789772.5 / 22050. Im using 22Khz.
I was using a method that maybe was not correct at all for emulating th ptiimer behavor:
Vars:
cPTimer is the counter itself
nPtimer is the 11 bit value loaded trough $400A and $400B (this is done when these registers are written)
Code:
ClockInPtimer(int cpuCycles)
{
cPtimer -= cpuCycles
if (cPtimer <= 0)
{
cPtimer += nPtimer + 1;
ClockInStepGenerator();
}
i changed that so i have a func that calls ClockInPTimer(int nChannel);
where nChannel is the channel i want to clock the p timer.
Code:
//first function: these calls the ClockInPTimer;
ClockPTimers(int cpuCycles)
{
int i;
for (i =0; i < Cycles; i++)
{
ClockInPtimer(0); //SQUARE 1
ClockInPtimer(1); //SQUARE 2
ClockInPtimer(2); //TRIANGLE
ClockInPtimer(3); //NOISE
}
}
//second function (wich is called by ClockPTimers())
ClockInPTimer(int nChannel)
{
if (cPtimer == 0)
{
cPtimer = nPtimer + 1;
swich (nChannel)
{
case 0: case 1: ClockInDutyCycle(nChannel) break; //SQUARES
case 2: ClockInStepGenerator(); //TRIANGLE
case 3: ClockInRandomGenerator(); //NOISE
}
else // is it convinient to put this else here?
cPtimer--;
}
The second method is better, more accurate and i only can hear a very high frequency but i still hear it
.
Do you know what can be wrong?