Sound_FX and Patterns

Creations

JulienGio

5 years ago

This tutorial explains how to make and use sound patterns and sound_FXs to implement in your games

Overview

A sound pattern is composed of a series of sound_FXs that are played in a sequence. Each sound_FX has 7 parameters that affect how it sounds:

  • Type: Either SQUARE or NOISE, determines the waveform
  • Continue_flag: Set to 0 if this is the last sound_FX in the sound. Otherwise 1.
  • Volume start: Volume (amplitude) at the start of the sound_FX
  • Volume sweep: Volume (amplitude) variation over time (negative values dim volume over time, positive values amplify)
  • Period sweep: Period variation over time (negative values shrink the period over time, positive values extend)
  • Period start: Period at the start of the sound_FX
  • Length: Duration of the sound_FX.

I recommend using Valden's GSFX tool to quickly make sounds ;)


Implementing sound patterns in code

A sound pattern is an array of sound_FX. To implement a sound pattern in code, you need to create an array containing the sequence of sound_FXs like so:

const Gamebuino_Meta::Sound_FX mySfx[] = {
  {uint8_t Type, 
   uint8_t Continue_flag, 
   uint8_t Volume start, 
   int8_t Volume sweep, 
   int8_t Period Sweep, 
   uint8_t Period Start, 
   uint8_t Length},  // 1st sound
  {...},  // 2nd sound
};

Type can be Gamebuino_Meta::Sound_FX_Wave::NOISE or Gamebuino_Meta::Sound_FX_Wave::SQUARE.

If Continue_flag is set to 0, then the pattern stops at this sound_FX. Always set the last sound_FX's continue_flag to 0.

Volume start and volume sweep determine the amplitude of the wave during the sound_FX. Using a high start volume with a negative sweep will make the sound fade out. You could also have a low starting volume and a positive sweep to make the sound fade in.

Period sweep and Period start are similar except they affect the period. Just in case for those who may not know this, but the period is directly tied to the inverse of the frequency. So a high period corresponds to a low frequency and vice-versa.

Lastly, the length is how long the sound lasts. In milliseconds, the sound will last 20 times the value you put for length. So a length of 40 will make your sound_FX last for 800ms (or 0.8s).


Here is an example of a pattern composed of 3 sound_FXs: one noise and two square.

const Gamebuino_Meta::Sound_FX mySfx[] = {
    {Gamebuino_Meta::Sound_FX_Wave::NOISE,1,100,2,5,96,3},
    {Gamebuino_Meta::Sound_FX_Wave::SQUARE,1,100,10,0,126,10},
    {Gamebuino_Meta::Sound_FX_Wave::SQUARE,0,120,-6,0,84,10},
};

Then, play your pattern by calling the gb.sound.fx() (reference here) function whenever you want:

// Play the FX
gb.sound.fx(mySfx);

Note: you cannot play multiple sound_FX / patterns at the same time. Well, you could, but because there is only one sound_FX audio channel, playing a sound when another is still playing will cut the older sound midway through.

View full creation

jicehel

NEW 5 years ago

Just a question to how convert old data from the gamebuino to the new sound fx of the meta.

If i had that on Gamebuino: 

gb.sound.command(0,5,0,0);           // to set the volume

gb.sound.command(1,0,0,0);           // to set the wave form

gb.sound.command(2,4,-3,0);           // to set the volume slide

gb.sound.command(0,12,-58,0);           // to set the pitch

gb.sound.playNote(0,8);


or this one:

gb.sound.command(0,5,0,0);           // to set the volume

gb.sound.command(1,0,0,0);           // to set the wave form

gb.sound.command(2,4,-4,0);           // to set the volume slide

gb.sound.command(0,8,-39,0);           // to set the pitch

gb.sound.playNote(12,6);


Could you say me how i could convert it in new format.

For the first example, does is be correct to init it with:

Sound_FX mySfx[] = { {Gamebuino_Meta::Sound_FX_Wave::SQUARE,0,100,88,5,96,8},

=> I have let parameters 5,96, because it was in example but no idea of what i had to put here, sorry. 

I thought it was easy to understand, it's can be good using the tools but i need a little more informations to understand how to convert sound from Gamebuino to Meta, or just say me how to set important parameters and let some 'by default' if you think that it's could be too hard for me to understand.


Thanks already for informations


Aurélien Rodot

5 years ago

You can't really convert, it's better to start again from scratch because the new system doesn't have much in common. But it does many new things ?

Aurélien Rodot

NEW 5 years ago

jicehel jicehel

You can't really convert, it's better to start again from scratch because the new system doesn't have much in common. But it does many new things ?

jicehel

NEW 5 years ago

yes, yes.. So i'll have to use the tool to create new sounds. It's great for new code, but it's could be cool to be able to have the basis of the conversion from the sounds of old gamebuino games to 'port' them to the META to keep the 'spirit' of the source game.

 

Sorunome

NEW 5 years ago

If you are only using the square waves and no pitch sliding effects, you can still play back that pattern with gb.sound.play

makerSquirrel

NEW 5 years ago

I think the information of this tutorial is essential to understand how to use gb.sound.fx(). Is there a possibility to attach essential links to the reference?

Sorunome

5 years ago

It is already linked in gb.sound.fx!

Sorunome

NEW 5 years ago

makerSquirrel makerSquirrel

It is already linked in gb.sound.fx!

makerSquirrel

NEW 5 years ago

yop, I saw that lateron, sorry. I mentioned that in the other thread...

Sorunome

5 years ago

It's OK, don't worry!

Sorunome

NEW 5 years ago

makerSquirrel makerSquirrel

It's OK, don't worry!

T0mmy2005

NEW 5 years ago

i need help it diddnt let me uload the code

Sorunome

5 years ago

Perhaps try to make a new topic with your issue and more details on what isn't working? Code not uploading doesn't sound like it is specific to this

Sorunome

NEW 5 years ago

T0mmy2005 T0mmy2005

Perhaps try to make a new topic with your issue and more details on what isn't working? Code not uploading doesn't sound like it is specific to this