Can't TEsound.playLooping
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Can't TEsound.playLooping
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:
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
Re: Can't TEsound.playLooping
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.
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.
Re: Can't TEsound.playLooping
But I DID define music in sound.lua:
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
musicL = love.sound.newDecoder("sounds/music.mp3", 4 * 1024 * 1024)
music = love.sound.newSoundData(musicL)
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
Re: Can't TEsound.playLooping
I think this might do what you want it to:
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:
- "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...
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.
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:
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:
And then in love.load...
Now it uses around 23 MB, and loads faster too!
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
- "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)
Code: Select all
music = love.sound.newSoundData(musicL)
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")
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.
Code: Select all
function love.load()
-- Everything else.
love.audio.play(music) -- Alternatively, music:play()
end
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Can't TEsound.playLooping
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: 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.
It is decoding the entire mp3, considering it's probably huge, this takes a while.Santos wrote:But... this seems to be really really slow, or something is causing LOVE to not respond? Can someone explain what's going on here?Code: Select all
music = love.sound.newSoundData("sounds/music.mp3")
Re: Can't TEsound.playLooping
But externally, it seems the only uses for Decoders are...
In regards to the SoundData taking a long time, why is this slow/unresponsive:
and also this:
but this is not?
- 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.
In regards to the SoundData taking a long time, why is this slow/unresponsive:
Code: Select all
music = love.sound.newSoundData("sounds/music.mp3")
Code: Select all
musicL = love.sound.newDecoder("sounds/music.mp3")
music = love.sound.newSoundData(musicL)
Code: Select all
musicL = love.sound.newDecoder("sounds/music.mp3", 4 * 1024 * 1024)
music = love.sound.newSoundData(musicL)
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Can't TEsound.playLooping
There is no difference between internal and external.Santos wrote:But externally,
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.Santos wrote: In regards to the SoundData taking a long time, why is this slow/unresponsive:
[...]
and also this:
[...]
but this is not?
Also, I'd like to note the first two are directly equivalent.
Re: Can't TEsound.playLooping
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?
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?
Re: Can't TEsound.playLooping
Thanks for clearing so much stuff out for me! You're really helping out
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
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
Last edited by bartbes on Wed Apr 24, 2013 5:07 pm, edited 1 time in total.
Reason: Merged
Reason: Merged
Code: Select all
while game.engine == "LÖVE2D" do
game.awesome = true
community.helpful = true
end
Who is online
Users browsing this forum: ChocolateLoxtl and 2 guests