Does anyone have a capx which plays sounds at 0db once?

Get help using Construct 2

Post » Sun Aug 31, 2014 6:33 pm

Hey guys,

I'd like to add a feature to my piano app which plays every key (note) once and 0db (silent) and then, once that is complete, turns up the volume again and make the app ready for use.

Does anyone happen to have a capx which has these features already implemented?

I've read a tutorial on how to play sounds with functions but it doesn't look like a solution that is ideal for my situation.

Even if someone could post just how to play one sound and change the volume would be enough for me to learn from.

Thanks,

V :)
B
14
S
4
Posts: 190
Reputation: 1,735

Post » Thu Sep 04, 2014 1:26 pm

Hey vancouver :)

To play a sound at an inaudible volume (essentially silent), you'll probably want to use something like -60 dB or lower. Decibels (dB) are logarithmic units of volume, so "0 dB" is actually full volume, (100% original sound volume).

Decibels are kind of a weird scale. And to make things weirder, computers use the dB scale differently than the way it's used to describe the loudness of sounds in the real world.


Computer dB
When dealing with computer audio, most programs use the convention that a sound's original (100%) volume is "0 dB", no matter what the sound is. Could be crinkling paper, could be a jackhammer, but on a computer 0 dB means play this sound file at 100% of whatever volume it was recorded at.

Decibel scale
When you *add* to a sound's dB level, you *scale* its power level up.
When you *subtract* from a sound's dB level, you *scale* its power level down.

(I say "power" rather than "loudness" because the human perception of audio signal power has its own non-linear issues.)

Adding +10 dB to a 0 dB sound gives you the original sound power times 10.
Adding +20 dB to a 0 dB sound gives you the original sound times 10, and then times another 10, for a total of times 100.
Adding +30 dB to a sound yields 10 x 10 x 10, or 1000 times more power.
And -30 db scales it down by 1000, making it 1/1000th the original power.

So, playing a sound at -60 dB is playing it at 1/1,000,000th its normal volume, which is going to be silent enough. :)

For more confusion, here's the wiki page for Decibels ... http://en.wikipedia.org/wiki/Decibel


Preload sounds
All that said, if you're looking to play all the sounds once to force them to preload, so that there's no delay the first time a user tries to play a note, then there's good news.

As of one of the recent updates to Construct 2, a "Preload sounds" option was added to the project properties in the "Configuration Settings" section. This will automatically preload all sounds (not including sounds in the "music" folder).


Playing all sounds once
If you need to play every sound once, you could create an event "Start of layout", with an action "Play sound" at -60 db for each sound.

Or, if your sound files are named with a fixed name followed by a number (e.g. "note00", "note01" , "note02", etc) then you could create a loop using the action "play sound by name", using the name [ "note" & zeropad( loopindex , 2 ) ].

The zeropad() function will convert a number to a string with a fixed number of digits, such that leading zeros are used when the converted number isn't large enough to fill the fixed digit amount. e.g. zeropad( 77 , 5 ) = "00077"


Hope that helps. Sorry for the long explanation of the dB scale. :)
B
27
S
18
G
8
Posts: 327
Reputation: 6,154

Post » Fri Sep 05, 2014 2:27 am

@fishholite
Thank you for shedding light on this issue.
I will implement your suggestion(s) which will provide a better user experience.

Safari, Chrome and FF seem to work fine but IE still waits for that first touch per piano key.

I'm sure that your reply will be useful for many of us,

Thank you so much for providing it,

V
B
14
S
4
Posts: 190
Reputation: 1,735

Post » Fri Sep 05, 2014 2:43 am

No problem. Glad I could help. :)
B
27
S
18
G
8
Posts: 327
Reputation: 6,154


Return to How do I....?

Who is online

Users browsing this forum: tarek2 and 19 guests