graphics and sound jerky

BlitzMax Forums/BlitzMax Programming/graphics and sound jerky

I'm a Blitz3D user that's recently bought BlitzMax. I tried to convert one of my old programs over to BlitzMax and found that the conversion has both the graphics and sound jerky while the BlitzBasic version is smooth.
I have both versions on my site with graphics and audio.

http://www.tomtoad.com/BlitzStuff/tiggerbb.zip
http://www.tomtoad.com/BlitzStuff/tiggerbmx.zip

[ETA] Strange, I just recompiled the program, unmodified, and now it runs just fine, although there's some tearing in the graphics. [/ETA]
[ETA2] Well, it seems to be working ok now. I fixed the tearing by using HARDSYNC in the graphics. As far as the jerkiness, I have no clue what was causing it, but I seem to have no problems now.[/ETA2]

Here is the code for the two diffeent versions.
BlitzBasic version
Graphics 640,480,32,0
SetBuffer BackBuffer()

tiggerleft = LoadImage("tigger-left.bmp")
MaskImage tiggerleft,90,255,49

tiggerright = LoadImage("tigger-right.bmp")
MaskImage tiggerright,90,255,49
background = LoadImage("forest.jpg")

song = LoadSound("tigger.ogg")
LoopSound song
PlaySound song

tiggercurrent = tiggerright

Color 255,0,0
time = MilliSecs()
acc# = .0032
push# = -.5
friction# = .1

velocity# = -1.3
xv# = 284.0
xd# = .3
y# = 293.0


While Not KeyDown(1)
timepass = MilliSecs()
delta# = timepass - time
time = timepass

finalspeed# = velocity# + acc# * delta#
distance# = (velocity# + finalspeed#)/2.0 * delta#

If y# + distance# > 293.0
 totaldistance# = 293.0 - y#
 totaltime# = (Sqr((2.0*velocity#)^2 + 8.0 * acc# * totaldistance#)-2.0*velocity#)/(2.0*acc#)
 finaltime# = delta# - totaltime#
 totalvelocity# = -(velocity# + acc# * totaltime#)
 finalspeed# = totalvelocity# + acc# * finaltime#
 distance# = ((totalvelocity# + finalspeed#)/2.0) * finaltime#
 y# = 293.0
End If
y# = y# + distance#

xv# = xv# + xd# * delta#
If xv# >= 534.0
  xv# = 1068.0 - xv#
  xd# = - xd#
  tiggercurrent = tiggerleft
Else If xv# < 0
 xv# = -xv#
 xd# = -xd#
 tiggercurrent = tiggerright
End If
 
DrawBlock background,0,0
DrawImage tiggercurrent,xv#,y#

velocity# = finalspeed#

Flip
Wend

WaitKey()

and BlitzMax version
Graphics 640,480,32
SetMaskColor(90,255,49)
tiggerleft:TImage = LoadImage("tigger-left.bmp")
tiggerright:TImage = LoadImage("tigger-right.bmp")
background:TImage = LoadImage("forest.jpg")

song:TSound = LoadSound("tigger.ogg")
channel:TChannel = PlaySound(song)

tiggercurrent:TImage = tiggerright

time = MilliSecs()
acc# = .0032
push# = -.5
friction# = .1

velocity# = -1.3
xv# = 284.0
xd# = .3
y# = 293.0


While Not KeyDown(KEY_ESCAPE)
timepass = MilliSecs()
delta# = timepass - time
time = timepass

finalspeed# = velocity# + acc# * delta#
distance# = (velocity# + finalspeed#)/2.0 * delta#

If y# + distance# > 293.0
 totaldistance# = 293.0 - y#
 totaltime# = (Sqr((2.0*velocity#)^2 + 8.0 * acc# * totaldistance#)-2.0*velocity#)/(2.0*acc#)
 finaltime# = delta# - totaltime#
 totalvelocity# = -(velocity# + acc# * totaltime#)
 finalspeed# = totalvelocity# + acc# * finaltime#
 distance# = ((totalvelocity# + finalspeed#)/2.0) * finaltime#
 y# = 293.0
End If
y# = y# + distance#

xv# = xv# + xd# * delta#
If xv# >= 534.0
  xv# = 1068.0 - xv#
  xd# = - xd#
  tiggercurrent = tiggerleft
Else If xv# < 0
 xv# = -xv#
 xd# = -xd#
 tiggercurrent = tiggerright
End If
SetBlend(SOLIDBLEND) 
DrawImage(background,0,0)
SetBlend(MASKBLEND)
DrawImage(tiggercurrent,xv#,y#)

velocity# = finalspeed#

If Not ChannelPlaying(channel) Then channel = PlaySound(song)

 Flip
Wend



I've tried using FlushMem before the Flip, but it didn't make any difference.

You need the flushmem anyway.
I don't get any sound issues but, if it's crackling, then there's an ongoing bug HERE
I changed the graphics to...
graphics 640,480,32,0
which made things look better although they didn't seem bad to begin with. I do get a few jerky movements, after about 30-40 seconds, lasting a couple of seconds but I put that down to being connected to the internet. I'll signoff and check whether it still occurs.

<edit> OK, the same jerky movement is there for about 2 seconds after 30 seconds but never seems to repeat (listened to Tigger bouncey, trouncey flounceying about 4 times).
In fact, I get the same jerky movement at the same time in B3D.
2700+, 9800Pro, WinXP XP2 with 1G RAM.

This is weird. I recompiled and executed the program again and again and still had problems, then all of a sudden, without any additional changes, everything runs fine. There must've been some CPU hogging task running in the background I guess. I did notice that I'll need to put a HidMouse in there :)

The jerky problem can be caused by having your video driver set to ignore vsync. I think it happens even if you specify HARDSYNC. That could explain why it come and goes. Maybe.