Audio Looping(again :I )?

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
Eamonn
Party member
Posts: 550
Joined: Sat May 04, 2013 1:29 pm
Location: Ireland

Audio Looping(again :I )?

Post by Eamonn »

I asked this a while ago, but got no help on the subject. I'm working on a game called 'Mr. BallGuy', and I have a soundtrack playing during gameplay. This works well, but the audio does not loop. Here is a sample piece of code from the game:

Code: Select all

function love.load()
    song = love.audio.newSource('/songs/song.mp3')
    song:setLooping(true)
end

function love.update(dt)
    song:play()
end
This causes 2 problems:
1) The audio plays twice as fast
2) The audio doesn't loop

When I asked this before, the only reply said it was all right when it obviously isn't. The audio does not loop and I cannot for the life of me figure out why! If you know, please help! Is it another bug (like the audio crashing bug) in LÖVE 0.8.0?

Thanks! Any help is appreciated!
"In those quiet moments, you come into my mind" - Liam Reilly
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: Audio Looping(again :I )?

Post by MadByte »

Try converting the mp3 to ogg. I guess löve has problems with the mp3 format sometimes.
edit: also I'm not sure if there is a problem with calling the :play() method everytime in the update loop.
User avatar
Eamonn
Party member
Posts: 550
Joined: Sat May 04, 2013 1:29 pm
Location: Ireland

Re: Audio Looping(again :I )?

Post by Eamonn »

MadByte wrote:Try converting the mp3 to ogg. I guess löve has problems with the mp3 format sometimes.
edit: also I'm not sure if there is a problem with calling the :play() method everytime in the update loop.
I've tried converting the mp3 to an ogg but no luck :(

Thanks for the reply none the less :D
"In those quiet moments, you come into my mind" - Liam Reilly
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: Audio Looping(again :I )?

Post by MadByte »

Good, so for me exactly the same code you use work on my computer. ( using a .ogg )
If your music file is fine I really had no clue why this shouldn't work.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Audio Looping(again :I )?

Post by Boolsheet »

LÖVE 0.7.2 had problems with mp3. This has been fixed.

The mp3 format requires special metadata to mark the exact sample where the audio ends. If there isn't, you may hear a click at the end of the track, but this should not stop it from looping.

Yes, you should not call play that often. Only call it if you mean to change the playing state or OpenAL (the library LÖVE uses for audio) throws a weird, unexpected error and LÖVE 0.8.0 goes into a long loop. This has been fixed for the next version.

Can you upload an example? It works as expected with my files.
Shallow indentations.
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: Audio Looping(again :I )?

Post by MadByte »

I tested it again and I've found following:
I have a .ogg file with a short sound ( ~1,5esc ). I used this code:

Code: Select all

function love.load()
    song = love.audio.newSource('song.ogg')
    song:setLooping(true)
end

function love.update(dt)
    song:play()	
end
After ~ 15 loops the sound stopped. But when calling the Play() method just once like this :

Code: Select all

function love.load()
    song = love.audio.newSource('song.ogg')
    song:setLooping(true)
    song:play()
end
Then the problem does not occur. I guess there is some kind of overflow while calling the play() method to often.
So you should try to call play() just once when you want to change the music state ( as boolsheet said ).
You could do so in the love.load or alternatively in the update i.e in a if loop which is only called once when the game starts.
User avatar
Eamonn
Party member
Posts: 550
Joined: Sat May 04, 2013 1:29 pm
Location: Ireland

Re: Audio Looping(again :I )?

Post by Eamonn »

MadByte wrote:I tested it again and I've found following:
I have a .ogg file with a short sound ( ~1,5esc ). I used this code:

Code: Select all

function love.load()
    song = love.audio.newSource('song.ogg')
    song:setLooping(true)
end

function love.update(dt)
    song:play()	
end
After ~ 15 loops the sound stopped. But when calling the Play() method just once like this :

Code: Select all

function love.load()
    song = love.audio.newSource('song.ogg')
    song:setLooping(true)
    song:play()
end
Then the problem does not occur. I guess there is some kind of overflow while calling the play() method to often.
So you should try to call play() just once when you want to change the music state ( as boolsheet said ).
You could do so in the love.load or alternatively in the update i.e in a if loop which is only called once when the game starts.
This problem WOULD fix the issue, but the song HAS TO PLAY DURING GAMEPLAY and not the start menu. BTW I got it working! I called it like 10 other times in love.update() :P
"In those quiet moments, you come into my mind" - Liam Reilly
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Audio Looping(again :I )?

Post by Robin »

Eamonn wrote:This problem WOULD fix the issue, but the song HAS TO PLAY DURING GAMEPLAY and not the start menu.
Then you call song:play() when the game proper starts, instead of in love.load(). You know, right next to state = "game" or whatever you use.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests