Performance tips

When creating good quality audios for your games, refer to the helpful notes mentioned here.

It is best to preload the files you regularly use on startup of your application. While loadStream() is generally fast, loadSound() may take a while since it must load and decode the entire file the instant it needs to be used. Generally, you don't want to be calling loadSound() in the parts of your application that users expect it to be running smoothly when events occur, such as during game play.

In the config.lua file, you may specify a field called audioPlayFrequency:

This tells the OpenAL system what sample rate to mix and playback at. For best results, set this no higher than you actually need. So if you never need better than 22,050 Hz playback, set this to 22,050. It produces quality speech recordings or middle-quality recordings of music. If you really do need high quality, then set this to 44,100 to produce audio CD type of quality at playback.

It is best to have all your audio files encoded at the same frequency when you have this set. The supported values are 11,025, 22,050, and 44,100.

For highly compressed formats, such as MP3 and AAC, AAC is the better option. AAC is the official successor to the MP3 by the MPEG Group. MP3 has patent and royalty issues that you may need to concern yourself with, if you distribute anything yourself. You might need to consult your lawyers for guidance. When AAC was ratified, it was agreed there would be no royalties required for distribution. If you prefer to use AAC over MP3, here's a tutorial on how to convert an MP3 to AAC or any file format of your preference at http://support.apple.com/kb/ht1550.

Ogg Vorbis is a royalty-free and patent-free format. However, this is not supported on iOS devices.

Q1. What is the proper way of clearing audio files from the memory?

Q2. How many channels of audio can be played simultaneously in an application?

Q3. How do you make your audio file loop infinitely?