I think this might do what you want it to:
Code: Select all
function love.load()
-- Everything else.
TEsound.play(music)
end
Now, about sound in LOVE...
Please note that I don't really know what I'm talking about, so please correct me someone if this isn't correct!
Also, this is all from the perspective of how LOVE is used, not how LOVE works internally. For more in-depth and authorative descriptions, check out this thread:
viewtopic.php?f=4&t=7749
First, a couple of concepts to understand:
Audio can be encoded or unencoded. For example, an MP3 or Ogg file is encoded, it's compressed, it's like it's "zipped". Unencoded audio is "unzipped", like a WAV file, all of the information is just there and doesn't need to be "decoded".
There are three sound-related types:
- Sources
- SoundData
- Decoders
Sources are audio which can be played. love.audio.newSource creates new Sources, and you can load files as either "static" or "stream"ing.
- "stream" will load the audio file into memory, and then when it's played decode it piece by piece. - "static" will decode the audio and save that into memory. Because the audio file has been decompressed, it will take up more memory, however it will be less processor intensive to play the sound, because it doesn't need to be decoded on the fly.
SoundData is unencoded audio, which can be edited (you might want to synthesise a sound, or edit a sound in some way). You can then create a Source from the SoundData. Because the SoundData is unencoded, the Source you make will be "static". You can create multiple Sources from the same SoundData and it will use the same data in memory, which might be useful for creating many Sources for a single sound.
Decoders are encoded audio, plus the size of each piece if it were to be played piece-by-piece in a streaming Source. So if the default size of each piece it decodes isn't what you want for some reason (perhaps for performance issues?), then you could create a Decoder, and then create a streaming Source from it.
(With my current level of understanding, I don't think Decoders make much sense to have in the API for people who use LOVE. If the only useful thing they do is to set the buffer size for streaming Sources, why not have that as an argument when creating Sources?)
So...
Code: Select all
musicL = love.sound.newDecoder("sounds/music.mp3", 4 * 1024 * 1024)
This loads music.mp3 into memory, it leaves it encoded, and it sets a buffer size for if it were to be used for a streaming Source.
Code: Select all
music = love.sound.newSoundData(musicL)
This creates a SoundData object from the Decoder. SoundData is unencoded, so music.mp3 is decompressed, "unzipped".
Until just now, I thought the Decoder was actually pointless, seeing as though it's been decoded into memory by the SoundData and not streamed, and I thought you could write something like this instead:
Code: Select all
music = love.sound.newSoundData("sounds/music.mp3")
But... this seems to be really really slow, or something is causing LOVE to not respond? Can someone explain what's going on here?
I suspect that TEsound then creates a new Source from this SoundData every time you tell TEsound to play it. The SoundData isn't duplicated in memory, however SoundData is unencoded, and takes up more memory than encoded audio. Try running your game and check out the memory usage with Task Manager or the equivalent on your operating system. For me, it uses around 84 MB!
I'd suggest loading it as a "stream"ing Source instead:
Code: Select all
music = love.sound.newSource("sounds/music.mp3", "stream")
music:setLooping(true) -- If you want it to loop.
And then in love.load...
Code: Select all
function love.load()
-- Everything else.
love.audio.play(music) -- Alternatively, music:play()
end
Now it uses around 23 MB, and loads faster too!