This is a program that plays stuff through the sound channels, then uses the GBA timers to calculate exact times for the waveform to be okay before starting a new sound at a lower volume.
It sounds significantly different on hardware compared to VBA-M.
The sound played is just repeating E notes, but it waits for the exact timing necessary to begin another note with no impact from the "reset" bit.
On hardware it sounds smooth. On VBA-M, it sounds clicky/noisy/metalic.
Â
Code: Select all
//get_wavelength(4);
void test2()
{
REG_IME=0;
REG_TM2CNT_H=0;
REG_TM2CNT_L=0;
REG_TM2CNT_H=0xC1; //256KiHz timer
REG_SOUNDCNT_X=0x80;
REG_SOUNDCNT_L=0xFF77;
int period = 0x673; //E-note after middle C
int target_time;
int last_time=0;
int num_tones=6;
int volume=15;
int real_period=2048-period;
do
{
target_time=last_time+real_period*2*num_tones;
target_time&=0xFFFF;
while (1)
{
if (REG_TM2CNT_L==target_time-1)
{
break;
}
}
REG_SOUND1CNT_H = 0x80 + (volume<<12);
REG_SOUND1CNT_X = 0x8000 + period;
last_time=target_time;
volume--;
if (volume==0) volume=15;
} while (1);
}