sound = love.audio.newSource("pling.wav", "static") -- the "static" tells LÖVE to load the file into memory, good for short sound effects music = love.audio.newSource("techno.ogg") -- if "static" is omitted, LÖVE will stream the file from disk, good for longer music tracks love.audio.play(sound) love.audio.play(music)
LÖVE supports a lot of audio formats, thanks to the love.sound module, which handles all the decoding. Supported formats include:
- and just about every tracker format you can think of - XM, MIDI, MOD, and over twenty others.
(Note, however, that Ogg seems to be the only format which plays back without any problems.)
Static vs. Streaming
Keep in mind that, if you pass
love.audio.newSource "static" as a second argument, the sound file will be expanded into memory, so if you load a 5MB compressed .ogg file that way, it would consume ~50MB RAM when fully decompressed. Consider not using "static" in such cases.
If you omit the "static", the audio will be streamed from the file as it's played, something that saves a lot of memory when you're dealing with massive files.
To pause, stop, change volume, looping, pitch, etc., simply call the relevant method of a Source.
src1 = love.audio.newSource("bang.wav", "static") src2 = love.audio.newSource("bgm.mp3") src1:setVolume(0.9) -- 90% of ordinary volume src1:setPitch(0.5) -- one octave lower src2:setVolume(0.7) love.audio.play(src1) love.audio.play(src2)
Further details can be found in the Source documentation.
- TEsound - A sound manager which makes it easier to use sound effects and music
- Minimalist Sound Manager - A snippet that makes usage of love.audio easier and automatically manages sources
Tiếng Việt –