Skip to content

Commit

Permalink
GBA Sound test: add surround
Browse files Browse the repository at this point in the history
same 25/75 setup as GB port
  • Loading branch information
pinobatch committed Mar 10, 2024
1 parent b661c8a commit f056d29
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
9 changes: 9 additions & 0 deletions gba/src/helppages.txt
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ moving in high speed.
1000 Hz left
1000 Hz right
1000 Hz (pulse)
1000 Hz (surround)
Hiss noise
Buzz noise
G major (PCM)
Expand Down Expand Up @@ -521,6 +522,14 @@ or buzz (127 steps).
The G chord is synthesized
in real-time using the
Karplus/Strong algorithm.
----
Surround is played 180
degrees out of phase and
should be silent on the
mono internal speaker.
Matrix surround decoders
such as Dolby Pro Logic
send it to the rear.

== Audio sync ==

Expand Down
28 changes: 24 additions & 4 deletions gba/src/soundtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ static void wait24() {
BG_COLORS[6] = RGB5(31, 31, 31);
}

static void reinitAudio(void) {
REG_SOUNDCNT_X = 0x0000; // 00: reset
REG_SOUNDCNT_X = 0x0080; // 80: run
REG_SOUNDBIAS = 0xC200; // 4200: 65.5 kHz PWM (for PCM); C200: 262 kHz PWM (for PSG)
REG_SOUNDCNT_H = 0x0B06; // xBxx: PCM A centered from timer 0; PSG/PCM full mix
}

static void beepTri(const unsigned char *wave, unsigned int period) {
REG_SOUND3CNT_L = 0; // unlock waveram
dmaCopy(wave, (void *)WAVE_RAM, 16);
Expand Down Expand Up @@ -113,6 +120,21 @@ static void beepPulse(void) {
REG_SOUND1CNT_X = 0x8000; // note cut
}

static void beepSurround(void) {
reinitAudio();
REG_SOUNDCNT_L = 0xD277;
REG_SOUND1CNT_L = 0x08; // no sweep
REG_SOUND1CNT_H = 0xA040; // 2/3 volume, 25% duty
REG_SOUND2CNT_L = 0xA0C0; // 2/3 volume, 75% duty
REG_SOUND1CNT_X = (2048 - 131) + 0x8000; // pitch
REG_SOUND2CNT_H = (2048 - 131) + 0x8000; // pitch
wait24();
REG_SOUND1CNT_H = 0;
REG_SOUND1CNT_X = 0x8000; // note cut
REG_SOUND2CNT_L = 0;
REG_SOUND2CNT_H = 0x8000; // note cut
}

static void beepHiss(void) {
REG_SOUND4CNT_L = 0xA000; // 2/3 volume
REG_SOUND4CNT_H = 0x8024; // divider
Expand Down Expand Up @@ -228,15 +250,13 @@ static const activity_func sound_test_handlers[] = {
beep1kL,
beep1kR,
beepPulse,
beepSurround,
beepHiss,
beepBuzz,
beepPCM,
};
void activity_sound_test() {
REG_SOUNDCNT_X = 0x0080; // 00: reset; 80: run
REG_SOUNDBIAS = 0xC200; // 4200: 65.5 kHz PWM (for PCM); C200: 262 kHz PWM (for PSG)
REG_SOUNDCNT_H = 0x0B06; // xBxx: PCM A centered from timer 0; PSG/PCM full mix

reinitAudio();
while (1) {
REG_SOUNDCNT_L = 0xFF77; // reset PSG vol/pan
helpscreen(DOC_MENU, KEY_A|KEY_START|KEY_B|KEY_UP|KEY_DOWN|KEY_LEFT|KEY_RIGHT);
Expand Down

0 comments on commit f056d29

Please sign in to comment.