How to make sounds?

Understanding the language, error messages, etc.

How to make sounds?

Postby yawn » Wed Dec 07, 2016 3:57 pm

Sorry for the harsh title but it sounded like an attention grabber...

I have read the wiki sound page multiple times and remain with no idea how to make sounds. Forum searches have yielded no useful results, I have found some examples but none with explanatory comments.

Would someone be kind enough to provide a small tutorial about how to create sounds?
yawn
 
Posts: 32
Joined: Tue Dec 23, 2014 1:54 pm

Re: How to make sounds?

Postby STUDIOCRAFTapps » Wed Dec 07, 2016 10:21 pm

It's pretty simple, first, you need to create and get sound data. Use http://www.yodasvideoarcade.com/gamebuino.php%20FX-SYNTH. Mess around with this "game". When you're done and happy with the sound, save the sound. How to save the sound? Use this for example:
Code: Select all
const int soundfx[8][8] = {
  {1,27,90,2,7,7,3,7}, //jump <
  {1,27,112,1,1,1,6,4}, // walljump <
  {0,27,57,1,1,1,6,4}, // unlockdoor <
  {0,9,57,1,6,8,7,8}, // land
  {0,46,57,1,0,18,7,47}, // getkey <
  {0,38,79,3,6,7,7,20}, // finish <
  {0,30,68,3,0,0,7,5}, // click <
  {0,30,55,1,7,0,7,15} //death <
};

All your sound will be saved this way. In FX-SYNTH, you can see the numbers, write them in the array this way: WAVEFORM, PITCH, PMD, PMT, VMD, VMT, VOL, LENGTH. If you want to play a sound, use this function
Code: Select all
void sfx(int fxno, int channel) {
  gb.sound.command(0, soundfx[fxno][6], 0, channel); // set volume
  gb.sound.command(1, soundfx[fxno][0], 0, channel); // set waveform
  gb.sound.command(2, soundfx[fxno][5], -soundfx[fxno][4], channel); // set volume slide
  gb.sound.command(3, soundfx[fxno][3], soundfx[fxno][2] - 58, channel); // set pitch slide
  gb.sound.playNote(soundfx[fxno][1], soundfx[fxno][7], channel); // play note
  //WAVEFORM, PITCH, PMD, PMT, VMD, VMT, VOL, LENGTH
}


and call it this way:
Code: Select all
sfx(/*The id of the sound, for exemple "jump" is 0, land is 3...*/, /*The channel need to be in the range of 0 to  3, if you haven't modify setting.c to change the NUM_CHANNEL, you can use only the first channel (0)*/);


'Hope it will work, if you don't understand something I have said (I normally speak french), please ask it.
User avatar
STUDIOCRAFTapps
 
Posts: 86
Joined: Sun Oct 02, 2016 11:58 pm
Location: Deep in the web

Re: How to make sounds?

Postby yawn » Thu Dec 08, 2016 8:16 am

Thanks Studiocraft Apps,

I should have mentionned I have seen this technique and was about to try implementing sounds when I saw a forum post by rodot saying this method was not recommended. I would like to do it the proper way, and why not add music to my games but I simply don't get it. :(
yawn
 
Posts: 32
Joined: Tue Dec 23, 2014 1:54 pm

Re: How to make sounds?

Postby STUDIOCRAFTapps » Thu Dec 08, 2016 5:16 pm

The way i show you is present almost 1/3 of all the game. I've checked the Super-Crate-Buino's (a game by rodot) code and I've discovered this:

To store:
Code: Select all
const uint16_t player_damage_sound[] PROGMEM = {0x0045, 0x564, 0x0000};
const uint16_t revolver_sound[] PROGMEM = {0x0045, 0x7049, 0x17C, 0x784D, 0x42C, 0x0000};
const uint16_t grenade_sound[] PROGMEM = {0x0045, 0x012C, 0x0000};
const uint16_t machiegun_sound[] PROGMEM = {0x0045, 0x140, 0x8141, 0x7849, 0x788D, 0x52C, 0x0000};
const uint16_t rocket_sound[] PROGMEM = {0x8045, 0x8001, 0x8889, 0x3C5C, 0x0000};
const uint16_t blast_sound[] PROGMEM = {0x0045, 0x7849, 0x784D, 0xA28, 0x0000};
const uint16_t power_up_sound[] PROGMEM = {0x0005, 0x140, 0x150, 0x15C, 0x170, 0x180, 0x16C, 0x154, 0x160, 0x174, 0x184, 0x14C, 0x15C, 0x168, 0x17C, 0x18C, 0x0000};
const uint16_t enemy_death_sound[] PROGMEM = {0x0045, 0x184, 0x0000};
const uint16_t jump_sound[] PROGMEM = {0x0005, 0x7049, 0x884D, 0x354, 0x0000};
const uint16_t enemy_felt_sound[] PROGMEM = {0x8005, 0x8001, 0x8849, 0xF20, 0x0000};
const uint16_t shotgun_sound[] PROGMEM = {0x0045, 0x7049, 0x334, 0x0000};
const uint16_t laser_sound[] PROGMEM = {0x0005, 0x784D, 0x7849, 0x670, 0x0000};
const unsigned int club_sound[] PROGMEM = {0x8005, 0x784D, 0x7849, 0x318, 0x0000};


and to play:

Code: Select all
gb.playPattern(jumpSound, 1/*I don't know what i does...*/)


I don't understand how it work but it may help you...
User avatar
STUDIOCRAFTapps
 
Posts: 86
Joined: Sun Oct 02, 2016 11:58 pm
Location: Deep in the web

Re: How to make sounds?

Postby yawn » Thu Dec 08, 2016 6:04 pm

Thanks, I might give it a try after all...
yawn
 
Posts: 32
Joined: Tue Dec 23, 2014 1:54 pm

Re: How to make sounds?

Postby Sorunome » Thu Dec 08, 2016 9:17 pm

As you (STUDIOCRAFTapps) said you didn't know what the one in gb.playPattern does:

the first parameter it takes is the song file its playing, the other one is to which channel to output, valid numbers are 0-3. This way you can play up to four of those pattern things at the same time!

EDIT: If you use a lot of channels you'll probably should increase NUM_CHANNELS in settings.c to be the number you need :)
User avatar
Sorunome
 
Posts: 629
Joined: Sun Mar 01, 2015 1:58 pm

Re: How to make sounds?

Postby yawn » Tue Dec 13, 2016 7:37 pm

I'll have to understand how to make music though, I'm more a chiptune composer than a coder :) My next game will have to feature some music
https://soundcloud.com/user-241462608/longroqd
yawn
 
Posts: 32
Joined: Tue Dec 23, 2014 1:54 pm

Re: How to make sounds?

Postby erico » Tue Dec 13, 2016 10:04 pm

You a module man? :D

You should check FreddyWild tracker then...
viewtopic.php?f=12&t=3435
User avatar
erico
 
Posts: 671
Joined: Thu Mar 27, 2014 9:29 pm
Location: Brazil

Re: How to make sounds?

Postby yawn » Wed Dec 14, 2016 8:57 am

erico wrote:You a module man? :D

You should check FreddyWild tracker then...
viewtopic.php?f=12&t=3435

Thanks, already downloaded it but unfortunately it won't install on my machine (maybe because I'm on win XP) :(
yawn
 
Posts: 32
Joined: Tue Dec 23, 2014 1:54 pm

Re: How to make sounds?

Postby STUDIOCRAFTapps » Thu Dec 15, 2016 12:11 am

yawn wrote:I'll have to understand how to make music though, I'm more a chiptune composer than a coder :) My next game will have to feature some music
https://soundcloud.com/user-241462608/longroqd


With what did-you make that cool music, i'm working on a cool 3d game and i want to make my own music and GarageBand is very bad for that.
User avatar
STUDIOCRAFTapps
 
Posts: 86
Joined: Sun Oct 02, 2016 11:58 pm
Location: Deep in the web

Next

Return to Programming Questions

Who is online

Users browsing this forum: No registered users and 13 guests

cron