FBA The Creator
http://www.fbacreator.com/fbaforum/

Latency / delay in playing sounds
http://www.fbacreator.com/fbaforum/viewtopic.php?f=5&t=214
Page 1 of 1

Author:  kryptech [ Mon Aug 31, 2009 3:22 pm ]
Post subject:  Latency / delay in playing sounds

This is my first post here, so I'd like to give a huge thanks to the FBA Team! :D

I've made a very simple drum kit for my HTC Touch Pro Pocket PC. My idea is to tap on the different drums on the screen to play the matching sounds. It works snappy on Windows XP Pro but the Pocket PC version has too much latency or delay between the tap and the sound. It is high enough that the application really is unusable.

I've used 8 bit mono WAV files. I've tried running the program after a restart with all extra running programs (e.g. Manila) closed but it doesn't make any noticeable difference. Does anyone have suggestions on how to tune and optimize this so that the application will respond very quickly? Here is the code:

Code:
local background = loadimage("Image.png")
local hat = loadsound("Hat_8b_mono.wav")
local kick = loadsound("Kick_8b_mono.wav")
local snare = loadsound("Snare_8b_mono.wav")

function onmainloop()
  if getnumiterations() < 1 then -- First loop
    drawimage(background, 0, 0) -- Draw background image, with drum pictures and close button
  end

  -- Handle mousedown
  if mousedown() == 1 then
    if mousex() >= screenwidth() - 30 and mousey() >= 0 and mousex() <= screenwidth() and mousey() <= 29 then -- Clicked close button area
      quit() -- Close application
    elseif mousex() >= 18 and mousey() >= 158 and mousex() <= 250 and mousey() <= 275 then -- Clicked hat area
      playsound(hat) -- Play hat sound clip
    elseif mousex() >= 227 and mousey() >= 295 and mousex() <= 427 and mousey() <= 464 then -- Clicked kick area
      playsound(kick) -- Play kick sound clip
    elseif mousex() >= 440 and mousey() >= 173 and mousex() <= 629 and mousey() <= 346 then -- Clicked snare area
      playsound(snare) -- Play snare sound clip
    end
  end
end

Author:  evilmaio [ Tue Sep 01, 2009 8:33 am ]
Post subject:  Re: Latency / delay in playing sounds

You could try moving your input logic inside mouse events instead of gameloop

Author:  kryptech [ Fri Sep 04, 2009 1:50 pm ]
Post subject:  Re: Latency / delay in playing sounds

Thanks for the reply! Since my original post I've tried a couple variations. Is this what you meant?

Code:
local background = loadimage("Image.png")
local hat = loadsound("Hat_8b_mono.wav")
local kick = loadsound("Kick_8b_mono.wav")
local snare = loadsound("Snare_8b_mono.wav")

function onmainloop()
  if getnumiterations() < 1 then -- First loop
    drawimage(background, 0, 0) -- Draw background
  end
end

function onstylusdown(x, y)
  if x >= screenwidth() - 30 and y >= 0 and x <= screenwidth() and y <= 29 then -- Clicked in close button area
    quit() -- Close application
  elseif x >= 18 and y >= 158 and x <= 250 and y <= 275 then -- Clicked in hat area
    playsound(hat) -- Play hat sound clip
  elseif x >= 227 and y>= 295 and x <= 427 and y<= 464 then -- Clicked in kick area
    playsound(kick) -- Play kick sound clip
  elseif x >= 440 and y >= 173 and x <= 629 and y <= 346 then -- Clicked in snare area
    playsound(snare) -- Play snare sound clip
  end
end


This performs with the same delay between the tap and playback. I tried using print() to output which drum had been hit and it appears to update very quickly, without the delay that is apparent with playsound(). So I tend to think the delay is due to the sound, not the input. But I'd have to test further to confirm that.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/