Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue with audio
Hi, I have an issue when playing a wav file for the first time in a game loop.
When I do this for the first time, the screen freezes for a second. The freezing does not repeat when the sound is subsequently played.
I can work around this easily enough by playng the wav file once at zero volume before the game loop starts (uncommenting line 8 in the attached file), but I'm curious to know what, if anything, I am doing wrong? 
I have tried it using a wav file from farmer_man, but get the same result, so no issue with the wav file.

Edit - I have just looked at Farmer_man again, and it looks to me as though the same issue shows up there when the first wav file is played in the game?

.zip   audio (Size: 346.82 KB / Downloads: 3)

'Open a window
set window "Audio_test",640,480
'enable double buffering
set redraw off
t = clock()
test_sound = loadsound("10point.wav")
player = [x:50,y:200,x_inc:2]
'play sound test_sound,0.0
'clear the screen
set color 255,255,255
set color 0,0,0
'draw a rect
set color 255,0,0
draw rect player.x,player.y,32,32,1
player.x = player.x + player.x_inc
if player.x < 0 or player.x > 608 then player.x_inc = - player.x_inc

text_here(250,150,"PRESS SPACE BAR TO PLAY SOUND")
if keydown(KEY_SPACE) then play sound test_sound,0.9

'copy back buffer to the screen
'cap FPS to 60
fwait 60
until mousebutton(0)

function text_here(x,y,text)
    set color 0,0,0
    set caret x,y
    center text
Interesting. Ran via Wine, on Linux, I get the same result. Short pause for the first time, then ok after that...
May your journey be free of incident.
Live long and prosper.
Sorry about that. I was initializing the audio stuff a bit late. It's been fixed in the version I just uploaded.

Forum Jump:

Users browsing this thread: 1 Guest(s)