Page 1 of 1

Directional sounds not working

Posted: Sat Apr 08, 2023 10:26 pm
by BurrickSlayer
Hi all,

has anyone got directional sounds working in LÖVE?

Positional sounds work just fine for me, but when I try to restrict the audible area of a sound with Source:setDirection and Source:setCone, these functions do not seem to have any effect.

I created the following test script where a directional sound circles the position of the listener. The sound should only be audible when the listener enters the sound's cone, but this does not happen. The sound always plays with its full volume instead.

Code: Select all

local DISTANCE = 200
local source
local angle = 0

function love.load()
  local cx, cy = love.graphics.getDimensions()
  love.audio.setPosition(cx / 2, cy / 2, 0)

  source = love.audio.newSource("qubodup-edev.ogg", "static")
  source:setVolume(0.2)
  source:setLooping(true)
  source:setAttenuationDistances(300, 700)
  source:setDirection(1, 0, 0)
  source:setCone(math.rad(10), math.rad(20), 0)
  source:play()
end

function love.update(dt)
  local cx, cy = love.graphics.getDimensions()
  angle = angle + dt
  source:setPosition(
    math.cos(angle) * DISTANCE + cx / 2,
    math.sin(angle) * DISTANCE + cy / 2
  )
end

function love.draw()
  love.graphics.setColor(1, 1, 0)
  local x, y = source:getPosition()
  love.graphics.circle("fill", x, y, 20)
end
Am I doing anything wrong here?

Thanks and happy easter!

Re: Directional sounds not working

Posted: Sun Apr 09, 2023 2:27 pm
by pgimeno
Works for me. Maybe a problem with your sound driver or OpenAL library?

Re: Directional sounds not working

Posted: Tue Apr 11, 2023 11:34 pm
by BurrickSlayer
Thank you for trying this out!

Interesting, I wonder if it might be related to macOS which has some version of OpenAL pre-installed. I will try this on another Mac system and see if it works there.