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.

Beginners > Simple Beep Sound

#60975 - Tomik - Wed Nov 16, 2005 12:22 pm

Hi,

I want to create a simple beep. I will use it if "the player found something". its my first thing with sound so i will start with this !
It should look like
Code:
if(findGOLD) beep(1);

have an idea? or help where i can learn the beeping sound ??

Thomas

#61045 - tepples - Thu Nov 17, 2005 2:05 am

AGBTTY has code to make a simple beep sound using a tone generator.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#61108 - Tomik - Thu Nov 17, 2005 9:51 am

is that what you ment:
Code:
static int agbtty_beep(void)
{
  SQR1CTRL = 0xd140;
  SQR1FREQ = 1917 | FREQ_HOLD | FREQ_RESET;
  return 0;
}

#61131 - headspin - Thu Nov 17, 2005 4:36 pm

You could also try and use something like ToneGen to create the noise you want and then just export it as a wav sample.
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game

#61142 - Tomik - Thu Nov 17, 2005 5:21 pm

yeah ... i have got my tone !! very nice ... but how can i put that in my game ??

beep beep, thomas

#61158 - thegamefreak0134 - Thu Nov 17, 2005 6:30 pm

Well, if it's a .wav file, you have many options. (1) use someone else's sound engine to play the sound. All of them are very nice, and all of them are at least a little tedious to set up the first time. (2) write your own sound generator. Since you only need one sound to play, basically all you have to do is fill the buffer with your sound data untill the sound is done. DekuTree64 has written a nice tutorial that wolks you through doing this, and the sound you need is covered in just the first few chapters. Unfortunately, I can't remember the link for that. Could someone please provide? Thx.
_________________
What if the hokey-pokey really is what it's all about?

[url=http:/www.darknovagames.com/index.php?action=recruit&clanid=1]Support Zeta on DarkNova![/url]

#61254 - Tomik - Fri Nov 18, 2005 2:08 pm

yes, can someone provide.
I like version (1) ;)
I just need the source for play only one sound ! (.wav)
can someone give me the complete source for that please ...

thanks, thomas

#61404 - Tomik - Sat Nov 19, 2005 8:58 pm

someone there, who can help me ??

#61425 - ghost Leinad - Sun Nov 20, 2005 1:09 am

yep, i can help you, but not now :S

i have a function using the channel sound 1 which makes a simple beep sound, in fact a happy sound, and another for a sad sound (this is how i called it)...

im not in my computer now, so i can't show you, but is very easy

you just need two functions

Code:

void initializeschannel1();

void playsound1();
void playsound2();

int main()
{
   initializeschannel1();
   if(smt)
   {
       playsound1();
   }
   else
   {
      playsound2();
   }
   return(0);
}

well, with a simple code like that (more or less) you can play a beep sound in your game, let me provide you with the code and registers used...for tomorrow, sorry...:S:S:S i just saw your post.

ah BTW, the sounds channels are very easy to use and implement, direct sound is hard for me still...

smell ya later[/code]
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#61536 - Tomik - Mon Nov 21, 2005 9:01 am

@gohst leinad: did you forget me ;)

#61615 - ghost Leinad - Tue Nov 22, 2005 1:50 am

Code:
/*******canal uno**********/
void Inicia_Sonido1()
{
//Play a sound on channel 1
//turn on sound circuit

REG_SOUNDCNT_X = 0x80;

//full volume, enable sound 1 to left and right

REG_SOUNDCNT_L=0x1177;

// Overall output ratio - Full

REG_SOUNDCNT_H = 2;
}

u16 note;
u16 delta,u,sweepshifts=2,sweepdir=1,sweeptime=0,cur=6;
u16 envinit=0xf, envdir=0, envsteptime=7,waveduty=2,soundlength=1;
u16 loopmode=1,sfreq=0x700,resamp=1;

void Sonido_Triste()
{
   REG_SOUND1CNT_L=(sweeptime<<4)+(sweepdir<<3)+sweepshifts;
   REG_SOUND1CNT_H=(envinit<<12)+(envdir<<11)+(envsteptime<<8)+(waveduty<<6)+soundlength;
   REG_SOUND1CNT_X=SOUND1INIT+(loopmode<<14)+sfreq-0x300;
}

void Sonido_Feliz()
{
   REG_SOUND1CNT_L=(sweeptime<<4)+(sweepdir<<3)+sweepshifts;
   REG_SOUND1CNT_H=(envinit<<12)+(envdir<<11)+(envsteptime<<8)+(waveduty<<6)+soundlength;
   REG_SOUND1CNT_X=SOUND1INIT+(loopmode<<14)+sfreq;

}

int main()
{
   Inicia_Sonido1();
   while(1)
   {
      if(keyDown(KEY_A))
      {
         Sonido_Triste();
      }
      if(keyDown(KEY_B))
      {
         Sonido_Feliz();
      }
   return(0);   
}


there it is...i hope you like it :D...sorry the delay, read my quote, you'll find the cause
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#61649 - Tomik - Tue Nov 22, 2005 9:09 am

that looks very good, I will try it !
Otherwise I am still searching for a code like this :

Code:

if(something is detected)
{
 play my wav
}


isnt there something very easy, short, simple code ?
Can someone help me with that ?

Thanks, Thomas (germany)

#61695 - tepples - Tue Nov 22, 2005 7:47 pm

If you want to play a wav then you're beyond simple beeps.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#61722 - headspin - Tue Nov 22, 2005 9:37 pm

tepples wrote:
If you want to play a wav then you're beyond simple beeps.


Well your not if you wav file is a beep. Your better off getting code to play wav's which is much more usefull than a tone generator or whatever.
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game

#61749 - ghost Leinad - Wed Nov 23, 2005 2:11 am

I really recommend you to start with the sound channels within the GBA, because they are so much easy to understand. belogic has a very nice tutorial. and the demos are amazing, they let you try everything about all the sounds channels :D, try to find that.

Maybe I make a library with this sounds, or maybe somebody has a library with the sounds channels all the way through.

direct sound is like black magic for me, but I'm starting to undestand.
maybe beeps using direct sound is not very hard, because when the song is done, is done, you don't need to refill your FIFO and to play the noise all over again, as in background music...mmmm interesting...I will try that...:D

somebody knows a good tone generator???
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#61777 - Tomik - Wed Nov 23, 2005 9:36 am

headspin wrote:
tepples wrote:
If you want to play a wav then you're beyond simple beeps.


Well your not if you wav file is a beep. Your better off getting code to play wav's which is much more usefull than a tone generator or whatever.


My wav is a beep. Do you have a code where I can implement my wav ?

I NEED A TONE GENERATOR !! Can someone give that to me ?

Thomas

#61784 - tepples - Wed Nov 23, 2005 2:29 pm

There are tone generators built into the GBA hardware.

To use the tone generators built into the GBA hardware, read about how to use them at The Audio Advance.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#61785 - Tomik - Wed Nov 23, 2005 2:38 pm

so you dont have a working tone generator ??

Thomas

#61798 - ScottLininger - Wed Nov 23, 2005 5:53 pm

Tomik wrote:
so you dont have a working tone generator ??


Uh...

Tepples wrote:
There are tone generators built into the GBA hardware.


So we *all* have a working tone generator.

The code that Ghost Leinad posted above is an example of using the hardware for this.

-Scott

#61857 - Tomik - Thu Nov 24, 2005 8:47 am

..couldn?t give me yours ... i know it was much work, but if it is working fine .... that would be hours for me ....

thanks a lot, thomas

#61915 - ghost Leinad - Fri Nov 25, 2005 2:59 am

well, well, do I have to make a job for you??? jajaja...Ok, do not worry, we'll work it out...

I don't know either how to embed a direct "beep"sound (.wav) in my files, but im trying to discover (But now, I'm lacking of the sound)...I will try my theory tonight, and if it works, I will post it tomorrow.

Code:


//pseudocode

initialize_directsound();
load_sound();

if(smt)
{
      playsound(); //and stop playing soung due ending or IRQ
}


Ok, I have to study for my DDB test for tomorrow too, so farewell for now :D:D
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#61976 - ghost Leinad - Sat Nov 26, 2005 3:15 am

finally!!!

after trying for two hours, I finally managed to make a directsound function that plays the sound and when the sample is over stops...(the stop part was the tricky one)

so, let me share my knowledge..

here's the main, you just call the functions
Code:

int main()
{
   inicio();
   Inicia_Sonido();
   TurnDirectSoundOn();
   
   while(1)
   {
      if(keyDown(KEY_START))   //everytime you press the KEY_START the sound plays again from the begining
      {
         t2++;
         if(t2<2)
         {
            TurnDirectSoundOn();
         }
      }   
      else
      {
         t2=0;
      }
      
      InterruptProcess();   //check for interruptions.
      vsync();
   }
   return(0);
}


same as channel 1, you have to enable the sound, (You should make a macro for this bit to bit register)

Code:
void Inicia_Sonido()
{
   //prende el sonido en el gba
   REG_SOUNDCNT_X = 0x80;
}


the interrupt process, you call this to stop playing the sound lol, this was very hard to figure it out!

Code:
void InterruptProcess(void)
{
   if(REG_IF==0x10)      //flag de interrupcion del timer 0
   {
      REG_TM0CNT_H=0; //disable timer 0
      REG_DMA1CNT_H=0; //stop DMA   ;detiene el sonido
      REG_IF |= REG_IF;//limpia las interrupciones
   }
}


finally, you have to set all this registers, look for the memory addres if you don't know it
.
Code:
//para inicializar el direct sound
void TurnDirectSoundOn()
{
   SetDirectSound(OUTPUTSOUND(3) | DIRECTSOUNDA | SOUNDARIGHT | SOUNDALEFT | SOUNDARESET );
   REG_SOUNDCNT_X=0x0080; //turn sound chip on

   //Formula for playback frequency is: 0xFFFF-round(cpuFreq/playbackFreq) 65536-(16777216)
   REG_TM0CNT_L=0xFBE8;      //16khz playback freq
   REG_TM0CNT_H=0x0080;       //enable timer0

   REG_DMA1SAD=(unsigned long)sample;//(unsigned long)_binary_lo1234_pcm_start; //dma1 source
   REG_DMA1DAD=0x040000a0;    //write to FIFO A address
   REG_DMA1CNT_H=0xB640;      //dma control: DMA enabled+ start on FIFO+32bit+repeat+increment source&dest
               //repite el sonido hasta que el registro sea cero.
   REG_TM1CNT_L = 0xffff-0x3EA0;
   REG_TM1CNT_H = TIMER_CASCADE | TIMER_INTERRUPT | TIMER_ENABLE;

   REG_IE=0x10;          //enable interruption request (irq) for timer 1
}


I will upload my code, in just a while, because you have to have the sample.wav.

you need the TectronikWave tool, to be able to change your .wav into a C array. You cand find it in the tools section on this web.
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#61977 - ghost Leinad - Sat Nov 26, 2005 3:29 am

you can download the sample in my page...very lame web BTW

http://www.angelfire.com/ab8/leinadcharm

or type or copy and paste the next url in your browser...

http://www.angelfire.com/ab8/leinadcharm/dsss.rar

I can't direct link my example...maybe you could borrow me a URL to upload my archives. :P:P:P
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#61978 - ghost Leinad - Sat Nov 26, 2005 3:51 am

how the heck do I make a quote??? :S:S:S jajaja

well this part

REG_TM1CNT_L = 0xffff-0x3EA0; the formule is 0xffff- SampleLenght

it took me hours to discover where was the samplelenght!!! jajaja...well...the sound is 1 second long!!! one second!! and the number of samples is 16032, for one second!!!

how is supposed to keep a track of sounds with more samples...lets say, a two second sample is (acoording to my example) 32064 samples long, a 4 second, 64128, this still fits in the timer...but what happen with a 5 second sample???

Maybe you can explain me...
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#61981 - tepples - Sat Nov 26, 2005 5:12 am

ghost Leinad wrote:
it took me hours to discover where was the samplelenght!!! jajaja...well...the sound is 1 second long!!! one second!! and the number of samples is 16032, for one second!!!

how is supposed to keep a track of sounds with more samples...lets say, a two second sample is (acoording to my example) 32064 samples long, a 4 second, 64128, this still fits in the timer...but what happen with a 5 second sample???

Usually by the time you have a real need for 5 second samples, you've written a mixer. Until then, you can cascade the sample-counting timer into a second timer or break the sample into pieces.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#62226 - Tomik - Mon Nov 28, 2005 2:53 pm

THIS WORKS ..... THANKS EVERBODY FOR HELP !!

Code:

ZENSUR