gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Audio > GBC sound 1

#10829 - Daikath - Wed Sep 17, 2003 2:51 pm

I've tried to set the registers to play a GBC sound, sound 1 to be exact but when I play my emulator it won't let me hear anything.

I've set the hardware registers like this.

Code:

void soundplay(void)
{
REG_SOUND1CNT_L = 0x0074;
REG_SOUND1CNT_H = 0xCC07;
REG_SOUND1CNT_X = 0x05C0;
}

void AgbMain(void)
{
REG_SOUNDCNT_X = 0x80;
REG_SOUNDCNT_L = 0x1177;
REG_SOUNDCNT_H = 2;

while(1)
   {
   soundplay();
   }
}

_________________
?There are no stupid questions but there are a LOT of inquisitive idiots.?

#10840 - gb_feedback - Wed Sep 17, 2003 7:32 pm

Sorry to reply without looking up what the result would be.

But what if you just played it once, rather than every few us?
_________________
http://www.bookreader.co.uk/

#10851 - Daikath - Thu Sep 18, 2003 10:34 am

Did that and it didn;t work, still thanks for the effort though.
_________________
?There are no stupid questions but there are a LOT of inquisitive idiots.?

#10853 - gb_feedback - Thu Sep 18, 2003 1:21 pm

I once had something going with sound 1-4 before I started to use the digital output. I've lost my code, but I looked at the stuff on the web which I used to learn how to do it.

The most obvious thing that is different is that in the code I just looked at the note is played by:

stopping anything which is playing

NR51_REG &= 0xEE;

adjusting the settings for the next note

NR12_REG =
NR11_REG =
NR10_REG =
NR13_REG =
NR14_REG =

then starting the sound playing again

NR51_REG |= 0x11;

Of course this is GBC code; you have to map this onto the GBA names for the regs. But it certainly used to work for me. So my theory is that the note is played only when you do the NR51_REG |= 0x11;
This would correspond to the upper byte of SOUNDCNT_L

The code by the way comes from the excellent Ultima 3 for the Gameboy at http://home.nc.rr.com/sven/ultima3.html which contains the source code for a complete player.

EDIT: and of course you should still give the note time to play before you try it again...
_________________
http://www.bookreader.co.uk/

#10870 - Vortex - Thu Sep 18, 2003 7:28 pm

These are the functions I use to play sound for channels 1-2:

Code:

#define DUTY_CICLE_12 (0x0000)
#define DUTY_CICLE_25 (0x0040)
#define DUTY_CICLE_50 (0x0080)
#define DUTY_CICLE_75 (0x00C0)

void InitSound(void)
{
   // Turn on sound circuit
   REG_SOUNDCNT_X = 0x80;

   // Full volume, enable sound 1 & 2 to left and right
   REG_SOUNDCNT_L = 0x3377;

   // Overall output ratio - Full
   REG_SOUNDCNT_H = 2;
}

void PlaySoundChannel2(u8 duration, u16 frequency, u16 duty_cicle)
{
   REG_SOUND2CNT_L = 0xF000 | duty_cicle | duration;    // No Envelope
   REG_SOUND2CNT_H = 0xC000 | frequency;             // Timed mode
}

void PlayMelody( const u16* notes, u16 size )
{
   u16 i;

   for( i = 0; i < size; i++)
   {
      PlaySoundChannel2( 0xA0, notes[i], DUTY_CICLE_50 );

      // wait while the sound is playing
      while(REG_SOUNDCNT_X & 2)
      {
      }
   }
}



Hope that helps.