Difference between revisions of "Article Tutorials/Intro to sounds"

From GiderosMobile
 
Line 1: Line 1:
 
__TOC__
 
__TOC__
Now that we can display images and text on the screen, you’ll be wanting to make noise!<br>
+
Now that we can display images and text on the screen, you’ll be wanting to make noise!
  
First, we’ll start with just sound effects.<br>
+
First, we’ll start with just sound effects.
  
Download all audio for this tutorial from: Gideros Mobile Tutorial Audio file (2.4Mb)<br>
+
Download all audio for this tutorial from: Gideros Mobile Tutorial Audio file (2.4Mb)
  
<s>The easiest and cheapest way to get cool sound effects for your application is to use the funky BFXR which you can download from here:<br>
+
The easiest and cheapest way to get cool sound effects for your application is to use the funky BFXR which you can download here: http://www.bfxr.net/ or [https://github.com/plicatibu/gideros_external_tutorials/tree/master/bluebilby.com_2013-04-18_gideros-mobile-tutorial-playing-music-and-sound-effects here].
  
http://www.bfxr.net/</s> ('''Note''': This site is offline but you can get its software for Windows and for Mac [https://github.com/plicatibu/gideros_external_tutorials/tree/master/bluebilby.com_2013-04-18_gideros-mobile-tutorial-playing-music-and-sound-effects here].)<br><br>
+
This is a free-to-use and download application which lets you create sound effects and export the wav files of your effects for using in your application (if you download the standalone version, you will need to install Adobe Air, but it’s worth it).
  
This is a free-to-use and download application which lets you create sound effects and export the wav files of your effects for using in your application.<br>
+
[[File:Jason-Oakley-Playing-Music-And-Sound-Effects-bfxr.png|thumb|center]]
  
If you download the standalone version, you will need to install Adobe Air, but it’s worth it.<br><br>
+
Click on the buttons until you find an effect you like and use Export Wav to save it into your Gideros Studio Project folder.
  
[[File:Jason-Oakley-Playing-Music-And-Sound-Effects-bfxr.png|thumb|center]]<br>
+
Create a new Project and add a new main.lua file to it. Use Add Existing Files to add your wav sound (eg laser.wav).
 
 
Click on the buttons until you find an effect you like and use Export Wav to save it into your Gideros Studio Project folder.<br>
 
 
 
Create a new Project and add a new main.lua file to it. Use Add Existing Files to add your wav sound (eg laser.wav).<br>
 
 
 
Type this into the main.lua file:<br>
 
  
 +
Type this into the main.lua file:
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
local laserfx = Sound.new("laser.wav")
 
local laserfx = Sound.new("laser.wav")
 
laserfx:play()
 
laserfx:play()
</syntaxhighlight><br>
+
</syntaxhighlight>
 
 
This creates an object called “laserfx” and loads the laser.wav file into it. The next line plays your sound effect. Pretty simple, huh?<br>
 
  
Every game needs a funky tune in the background, so lets add in a tune. There’s plenty of free mp3s on the internet, so go grab your own and add it to the Project.<br>
+
This creates an object called “laserfx” and loads the laser.wav file into it. The next line plays your sound effect. Pretty simple, huh?
 
 
I grabbed a free tune from No Soap Radio (www.nosoapradio.us). They have a lot of game tunes, all totally free – even for commercial use!<br>
 
  
 +
Every game needs a funky tune in the background, so lets add in a tune. There’s plenty of free mp3s on the internet, so go grab your own and add it to the Project.
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
local gametune = Sound.new("DST-AngryMod.mp3")
 
local gametune = Sound.new("DST-AngryMod.mp3")
 
gametune:play()
 
gametune:play()
</syntaxhighlight><br>
+
</syntaxhighlight>
 
 
Now, if you launch your application you will hear the sound playing. Awesome!<br>
 
The ‘play’ parameter has two options:<br>
 
 
 
• StartPosition<br>
 
• Loops<br>
 
  
You can start your tune partway through the song by specifying the StartPosition option. <s>You can tell the tune how many times to loop (play over again) by specifying the Loops option.</s><br>
+
Now, if you launch your application you will hear the sound playing. Awesome!
  
Eg.<br>
+
The ‘play’ parameter has two options:
 +
* StartPosition
 +
* Loops
  
 +
You can start your tune partway through the song by specifying the StartPosition option. You can tell the tune how many times to loop (play over again) by specifying the Loops option. Eg.
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
local gametune = Sound.new("DST-AngryMod.mp3")
 
local gametune = Sound.new("DST-AngryMod.mp3")
 
gametune:play(100)
 
gametune:play(100)
</syntaxhighlight><br>
+
</syntaxhighlight>
 
 
If you want to play the song repeating forever, use this:<br>
 
  
 +
If you want to play the song repeating forever, use this:
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
gametune:play(0, true)
 
gametune:play(0, true)
</syntaxhighlight><br>
+
</syntaxhighlight>
 
 
Set the volume of your tune or sound effect:<br>
 
  
 +
Set the volume of your tune or sound effect:
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
sndChannel:setVolume(0.5)
 
sndChannel:setVolume(0.5)
</syntaxhighlight><br>
+
</syntaxhighlight>
 
 
“0.5” is at half volume. You can set your volume anywhere from 0 to 1.<br>
 
  
Stop your tune from playing:<br>
+
“0.5” is at half volume. You can set your volume anywhere from 0 to 1.
  
 +
Stop your tune from playing:
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
Soundchannel=gametune:play(0,true)
 
Soundchannel=gametune:play(0,true)
 
Soundchannel:stop()
 
Soundchannel:stop()
</syntaxhighlight><br>
+
</syntaxhighlight>
 
 
To unload and free up memory when you’re finished with your tune, use:<br>
 
  
 +
To unload and free up memory when you’re finished with your tune, use:
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
gametune = nil
 
gametune = nil
</syntaxhighlight><br><br><br>
+
</syntaxhighlight>
 +
 
  
 
  '''Note: This tutorial was written by [http://bluebilby.com/author/waulokadmin/ Jason Oakley] and was originally available here: http://bluebilby.com/2013/04/18/gideros-mobile-tutorial-playing-music-and-sound-effects/'''
 
  '''Note: This tutorial was written by [http://bluebilby.com/author/waulokadmin/ Jason Oakley] and was originally available here: http://bluebilby.com/2013/04/18/gideros-mobile-tutorial-playing-music-and-sound-effects/'''

Latest revision as of 11:18, 26 August 2024

Now that we can display images and text on the screen, you’ll be wanting to make noise!

First, we’ll start with just sound effects.

Download all audio for this tutorial from: Gideros Mobile Tutorial Audio file (2.4Mb)

The easiest and cheapest way to get cool sound effects for your application is to use the funky BFXR which you can download here: http://www.bfxr.net/ or here.

This is a free-to-use and download application which lets you create sound effects and export the wav files of your effects for using in your application (if you download the standalone version, you will need to install Adobe Air, but it’s worth it).

Jason-Oakley-Playing-Music-And-Sound-Effects-bfxr.png

Click on the buttons until you find an effect you like and use Export Wav to save it into your Gideros Studio Project folder.

Create a new Project and add a new main.lua file to it. Use Add Existing Files to add your wav sound (eg laser.wav).

Type this into the main.lua file:

local laserfx = Sound.new("laser.wav")
laserfx:play()

This creates an object called “laserfx” and loads the laser.wav file into it. The next line plays your sound effect. Pretty simple, huh?

Every game needs a funky tune in the background, so lets add in a tune. There’s plenty of free mp3s on the internet, so go grab your own and add it to the Project.

local gametune = Sound.new("DST-AngryMod.mp3")
gametune:play()

Now, if you launch your application you will hear the sound playing. Awesome!

The ‘play’ parameter has two options:

  • StartPosition
  • Loops

You can start your tune partway through the song by specifying the StartPosition option. You can tell the tune how many times to loop (play over again) by specifying the Loops option. Eg.

local gametune = Sound.new("DST-AngryMod.mp3")
gametune:play(100)

If you want to play the song repeating forever, use this:

gametune:play(0, true)

Set the volume of your tune or sound effect:

sndChannel:setVolume(0.5)

“0.5” is at half volume. You can set your volume anywhere from 0 to 1.

Stop your tune from playing:

Soundchannel=gametune:play(0,true)
Soundchannel:stop()

To unload and free up memory when you’re finished with your tune, use:

gametune = nil


Note: This tutorial was written by Jason Oakley and was originally available here: http://bluebilby.com/2013/04/18/gideros-mobile-tutorial-playing-music-and-sound-effects/


Written Tutorials