Can't TEsound.playLooping

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Rafer45
Prole
Posts: 12
Joined: Wed Apr 10, 2013 3:22 pm

Can't TEsound.playLooping

Post by Rafer45 »

So I'm using Sockmunkeedev's tutorials to learn the ropes on LÖVE2D [youtube]http://www.youtube.com/watch?v=P5TfKHj6H5Q[/youtube]
In the wiki, it sort of explains TEsound.playLooping, but I don't seem to be able to make it work
I didn't find any other posts asking about this problem :I If there is one, link me to it so I erase this post.
My code:

Code: Select all

while game.engine == "LÖVE2D" do
	game.awesome = true
	community.helpful = true
end
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Can't TEsound.playLooping

Post by Plu »

There seem to be two problems. The reason you can't hear anything is because you're not calling the function playMusic which is supposed to play the music, at least not as far as I can see.

The second problem is going to be that if you do call the function, it'll try to read a variable called 'music' which doesn't exist, so it will crash.

Try changing the word music in that function to the filename of the song you want to open, and then call the function when the player clicks the start button. That should fix it.
User avatar
Rafer45
Prole
Posts: 12
Joined: Wed Apr 10, 2013 3:22 pm

Re: Can't TEsound.playLooping

Post by Rafer45 »

But I DID define music in sound.lua:

Code: Select all

musicL = love.sound.newDecoder("sounds/music.mp3", 4 * 1024 * 1024)

music = love.sound.newSoundData(musicL)
However, I don't even know what that code means (I know, baad idea).
So, could you also help me with the concept? I really don't find the wiki's explanation to be clear :I

Code: Select all

while game.engine == "LÖVE2D" do
	game.awesome = true
	community.helpful = true
end
Santos
Party member
Posts: 384
Joined: Sat Oct 22, 2011 7:37 am

Re: Can't TEsound.playLooping

Post by Santos »

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! ^^
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Can't TEsound.playLooping

Post by bartbes »

Santos wrote: 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.
Decoders are just what does the decoding, this means they are internally used when creating SoundData (all at once) or when using streaming Sources (one buffer-size at a time).
Santos wrote:

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? ^^
It is decoding the entire mp3, considering it's probably huge, this takes a while.
Santos
Party member
Posts: 384
Joined: Sat Oct 22, 2011 7:37 am

Re: Can't TEsound.playLooping

Post by Santos »

But externally, it seems the only uses for Decoders are...
  • Adjusting the buffer size for streaming Sources. (and somehow maybe SoundData, given what happens when what is described below happens?)
  • Getting the bits per sample, sample rate, and number of channels of an audio file without decoding the whole thing into memory via SoundData.
Are there any other external uses?

In regards to the SoundData taking a long time, why is this slow/unresponsive:

Code: Select all

music = love.sound.newSoundData("sounds/music.mp3")
and also this:

Code: Select all

musicL = love.sound.newDecoder("sounds/music.mp3")
music = love.sound.newSoundData(musicL)
but this is not?

Code: Select all

musicL = love.sound.newDecoder("sounds/music.mp3", 4 * 1024 * 1024)
music = love.sound.newSoundData(musicL)
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Can't TEsound.playLooping

Post by bartbes »

Santos wrote:But externally,
There is no difference between internal and external.
Santos wrote: In regards to the SoundData taking a long time, why is this slow/unresponsive:
[...]
and also this:
[...]
but this is not?
Because there's fewer allocations, basically it's the benefits of scale. That said, it's wasteful memory-wise and SoundData is not meant to contain things longer than a short effect.
Also, I'd like to note the first two are directly equivalent.
Santos
Party member
Posts: 384
Joined: Sat Oct 22, 2011 7:37 am

Re: Can't TEsound.playLooping

Post by Santos »

Aaah, so the buffer-size is used when decoding in the form of streaming and in the form of putting-into-memory?

I'm wondering if SoundData could have a larger default buffer size? What I posted wasn't a very good example because it's a music file and SoundData is meant for holding smaller sounds, but even in the case of smaller sounds, would a larger default buffer size be faster?
User avatar
Rafer45
Prole
Posts: 12
Joined: Wed Apr 10, 2013 3:22 pm

Re: Can't TEsound.playLooping

Post by Rafer45 »

Thanks for clearing so much stuff out for me! You're really helping out :nyu:
So,if my current code is inefficient for music, what should I do?
And, on a sidenote, would it be acceptable if I had my sources in a separate .txt file inthe game's .zip file?
Thanks for the help :ultrahappy:
Last edited by bartbes on Wed Apr 24, 2013 5:07 pm, edited 1 time in total.
Reason: Merged

Code: Select all

while game.engine == "LÖVE2D" do
	game.awesome = true
	community.helpful = true
end
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 1 guest