Sound.constructor(file, [nodecoding], [nopitch], [nospatial]) constructor
The Sound constructor returns a Sound instance representing a binary sample data loaded from a file.
Parameters
file
A File or a filename as a string
representing the file to load the sound from.
[nodecoding]
A boolean
value that prevent decoding of the binary sample when set to true
.The sound will be decoded later (with a risk of performance hit). If set to false
(the default value), the binary sample will be decoded during load time.
[nopitch]
A boolean
value that prevent using pitching/doppler effect on the sound when set to true
(provides better optimization). If set to false
(the default value), pitching and doppler effect will be available for this sound.
[nospatial]
A boolean
value that prevent to use spatialization on the sound when set to true
(provides better optimization). If set to false
(the default value), spatialization will be available for this sound.
The audio module support the following file types :
- WAV (Waveform Audio file format)
*.wav
- MP3 (Moving Picture Experts Group Layer 3)
*.mp3
- FLAC (Free Lossless Audio Codec)
*.flac
- OGG VORBIS
*.ogg
Example
local audio = require "audio"
local sound = audio.Sound("music.mp3")
sound:play()
-- play sound for 5sec and exit
sleep(5000)