audio.loadSound()

Description:

Loads an entire file completely into memory and returns a reference to the audio data. Files that are loaded completely into memory may be reused/played/shared simultaneously on multiple channels so you only need to load one instance of the file. You should use this to load all your short sounds, especially ones you may play frequently. For best results, load all the sounds at the launch of your app or the start of a new level.

Syntax:

audio.loadSound( audiofileName [, baseDir ]  )

Example:

laserSound = audio.loadSound("laserBlast.wav")
explosionSound = audio.loadSound("explosion.mp3")

Parameters:

audiofileName
String: Specifies the name of the audio file you want to load. Supported file formats are determined by the platform you are running on.

baseDir
By default sound files are expected to be in the application resources directory. If the sound file is in the application documents directory, use system.DocumentsDirectory.

Returns:

A handle to a sound file.

Remarks:

Please note that you are responsible for unloading (cleaning up) any audio files you load with this API. Use the audio.dispose() API to clean up audio handles you are completely done with them and want to unload from memory to get back more RAM.

In many usage cases, you may want to use the audio file for the entire program in which case you do not need to worry about disposing of the resource.

Audio formats supported are determined by the platform you are running on. But note that the same formats are supported between audio.loadSound() and audio.loadStream().

Sound Formats
All platforms support 16-bit uncompressed .wav files.

iOS and Mac Simulator support .mp3, .caf, and .aac.

Windows Simulator supports .mp3 along with .wav.

As of build 269, Android now supports .mp3 and .ogg formats.

Supported on operating systems and platforms for build numbers shown:
  • Mac OS X:
    Build 2011.222
  • Windows:
    Build 2011.222
  • iOS:
    Build 2011.222
  • Android:
    Build 2011.222

Replies

maykelsb
User offline. Last seen 6 years 4 weeks ago. Offline
Joined: 5 Apr 2011

I had a bad time with MONO sounds, like sounds, not playing (although it was loaded and ok). So, if you have a problem like sounds not playing when they should, check if they are STEREO.

GenoBaby
User offline. Last seen 6 years 5 weeks ago. Offline
Joined: 11 Apr 2010

is there a way to tell if a sound is completely loaded?

ewing
User offline. Last seen 3 years 25 weeks ago. Offline
Alumni
Joined: 13 Jul 2010

If audio.loadSound doesn't return nil, it completely loaded.

theokieza
User offline. Last seen 4 years 50 weeks ago. Offline
Joined: 15 Mar 2012

Hi guys and girls,

As soon as I do adio.loadSound the cpu usage goes up and stays up on Android.

I'm not even playing it yet, just loading...

I idles at 0.1% to 0.8% but as soon as I load audio it goes up to 5% - 8%....

Any ideas?

Regards

T

ewing
User offline. Last seen 3 years 25 weeks ago. Offline
Alumni
Joined: 13 Jul 2010

That is an implementation detail but is expected. The audio system is completely shutdown until you make the first audio call. Then everything gets initialized. The audio subsystem runs on a background thread and is continuously processing to minimize latency. You will see CPU utilization even if no sound is playing, though the amount depends heavily on the OS and hardware.

zarzonis2
User offline. Last seen 8 years 25 weeks ago. Offline
Joined: 3 Apr 2011

Hi, i am new to programming. What exactly laserSound and explosionSound do?
Thank you in advance!

WauloK
User offline. Last seen 8 years 2 weeks ago. Offline
Joined: 21 Oct 2010

You can use them later in your app:

audio.play(laserSound)