Strange Audio thing: sound sometimes doesn't play

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.
lesslucid
Prole
Posts: 20
Joined: Sun Mar 20, 2011 8:25 am

Strange Audio thing: sound sometimes doesn't play

Post by lesslucid »

I've been writing a simple pong game as a way of teaching myself how to use love, and I've run into something weird... I've set up a sound to play each time the ball hits either the player's bat or the enemy bat. However, despite using what is to my eye identical code, the sound does play when it hits the enemy bat, but it doesn't play when it hits the player's. I'll paste some code below - any idea what might be causing this?

Code: Select all

-- in the love.load function:
Blop = love.audio.newSource("blop.wav", "static")

-- in the updateBall() function:

	if collideCheck(Ball.x, Ball.y, Ball.width, Ball.height, Bat.x, Bat.y, Bat.width, Bat.height) == 1 then
		Ball.angle = bounceRight(Ball.angle)
		Ball.speed = Ball.speed + 1
		Ball.x = Ball.x + 1
		-- play a sound:
		love.audio.play(Blop)
		
		local bCentre = Ball.y + (Ball.height / 2)
		local tCentre = Bat.y + (Bat.height / 2)
		
		if bCentre < (tCentre - 5) then
			Ball.angle = Ball.angle - (math.random() / 3)
		elseif bCentre > (tCentre + 5) then 
			Ball.angle = Ball.angle + (math.random() / 3)
		end
		
	end
	
	if collideCheck(Ball.x, Ball.y, Ball.width, Ball.height, Foe.x, Foe.y, Foe.width, Foe.height) == 1 then
		Ball.angle = bounceLeft(Ball.angle)
		Ball.speed = Ball.speed + 1
		Ball.x = Ball.x - 1
		-- play a sound
		love.audio.play(Blop)
		
	end



User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Strange Audio thing: sound sometimes doesn't play

Post by Taehl »

Love's sound system currently sucks. Use TEsound to make up for it.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
Ensayia
Party member
Posts: 399
Joined: Sat Jun 12, 2010 7:57 pm

Re: Strange Audio thing: sound sometimes doesn't play

Post by Ensayia »

While the LOVE sound functions themselves are well documented, they act in very odd ways. Taehl and I wrote TEsound to get around this. Sound sources act more like channels than individual sounds and therefore you can't call from a source while it's playing unless you stop it first or create a duplicate sound in a new source and play it as well.

Solution? Just use the TEsound library that Taehl linked to. Seriously, it will keep you from beating your head against a wall for hours.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Strange Audio thing: sound sometimes doesn't play

Post by bartbes »

@Taehl: Just because it's hard for you to use it doesn't mean it sucks, please refrain from using language like that to describe love.

Anyway, the real deal is that sound sources act like real life sound sources, you don't expect one guitar to play two guitar tracks either, do you? Now you may be wondering why this is the case. Well, part of it is that sources are in 3d space, so you could place them in a marching band, if you were to feel that way.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Strange Audio thing: sound sometimes doesn't play

Post by BlackBulletIV »

So I guess what's wanted here is a Sound class, which everytime you want it to play, a new source will be created.
lesslucid
Prole
Posts: 20
Joined: Sun Mar 20, 2011 8:25 am

Re: Strange Audio thing: sound sometimes doesn't play

Post by lesslucid »

So, I made two sounds from the same wav file, called Blop and Blup. Each bat plays a different one, and now it works!

...but if I discover a need for a more complex sound system, I'll definitely check out TEsound. :)
lesslucid
Prole
Posts: 20
Joined: Sun Mar 20, 2011 8:25 am

Re: Strange Audio thing: sound sometimes doesn't play

Post by lesslucid »

BlackBulletIV wrote:So I guess what's wanted here is a Sound class, which everytime you want it to play, a new source will be created.
...also, this prompts me to ask a really dumb question: I read somewhere that Lua is not an object-oriented language, although it's possible to add an object system through a module or an extension or something. Is that something I should be doing?
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Strange Audio thing: sound sometimes doesn't play

Post by vrld »

lesslucid wrote:I read somewhere that Lua is not an object-oriented language, although it's possible to add an object system through a module or an extension or something. Is that something I should be doing?
If you don't feel a need for a class system, then no.
Just using tables is fine in most cases.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
Ensayia
Party member
Posts: 399
Joined: Sat Jun 12, 2010 7:57 pm

Re: Strange Audio thing: sound sometimes doesn't play

Post by Ensayia »

BlackBulletIV wrote:So I guess what's wanted here is a Sound class, which everytime you want it to play, a new source will be created.
That's pretty much what TEsound handles for you automatically.
bartbes wrote:@Taehl: Just because it's hard for you to use it doesn't mean it sucks, please refrain from using language like that to describe love.
It must be inherently difficult to use if newbies keep posting topics about how they don't understand it. You don't see topics of this nature about draw functions or print functions or anything like that nearly as often as the sound issues that keep popping up.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Strange Audio thing: sound sometimes doesn't play

Post by Taehl »

bartbes wrote:@Taehl: Just because it's hard for you to use it doesn't mean it sucks
It's not just hard for /me/ to use, as is evidenced by people making help threads about it almost weekly. Most people expect a sound to play when they love.audio.play it, not to wonder if a guitar could play two sounds at the same time (Which, for the record, makes no sense. Strumming multiple strings at the same time plays multiple notes at the same time, which is known as a "chord" and comprises a major part of music. Even if you pluck the same string twice, the second pluck doesn't get ignored - it starts the sound again (which would be a much better behavior for love.audio.play, failing a more complete solution)).
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 209 guests