Posted: 22nd Mar 2003 17:42
Update: I was getting a crash from certain 16-bit samples on the line

v = 0x8000 - memblock word(block, startpos)

It cleared up when I changed the line

if startpos > endpos then exitfunction

to

if startpos => endpos
line lastx,lasty,right,centerline
exitfunction
endif

There's probably a better way to do this, but that's what worked for my not-terribly-critical application. Without the "line lastx,lasty,right,centerline", the sample stops before it hits the end of its box.
Posted: 22nd Mar 2003 22:03
I use some useful code Van-B used in VSD tracker, it's really easy
Posted: 23rd Mar 2003 21:50
That's really good!

Keep up the good work,

maby you can do some effects in 2D/3D, that would be nice to see.

Cheers.
Posted: 29th Mar 2003 0:11
Ok, I've updated the function. The coding is a bit more efficent in places and also should be a little more stable than before (fingers crossed). I think the samples now draw the right way up, not that is critical.

Also I've added an extra draw mode, bar, which draws the sound more complete than lines or dots, well, I think it looks better

+ Code Snippet
function DrawMonoSnd(left,top,right,bottom,block,startpercent#,endpercent#,bckcol,wavcol,drawmode)
  ` function for drawing standard 8 and 16 bit WAV mono sounds

  ` left, top, right, bottom = boxed area to draw sound
  ` block = number of memblock containing sound
  ` startpercent# = where to draw from in sound data
  ` endpercent# = where to draw to in sound data
  ` bckcol = background color
  ` wavcol = wav color
  ` drawmode = 0 for dot, 1 for line, 2 for bars

  width# = (right - left) + 1  :  height# = (bottom - top) + 1
  centerline = top + (height#/2)  :  vscale# = height# / 256.0

  ` draw background and set wav color
  ink bckcol,0 : box left,top,right,bottom
  ink wavcol,0

  ` exit now if there is no memblock
  if memblock exist(block) = 0 then exitfunction

  ` check for 8 or 16 bit sounds
  bps = memblock dword(block,0)
  frq = memblock dword(block,4)
  bs = (bps / frq) / 8

  ` exit now if sound is neither 8 or 16 bit
  if (bs <> 1) and (bs <> 2) then exitfunction

  ` check percent parameters
  if startpercent# = endpercent#
    startpercent# = 0.0 : endpercent# = 100.0
  else
    if startpercent# > endpercent#
      t# = startpercent#
      startpercent# = endpercent#
      endpercent# = t#
    endif
  endif

  if startpercent# < 0.0 then startpercent# = 0.0
  if endpercent# > 100.0 then endpercent# = 100.0

  ` get byte positions from startpercent and endpercent
  sndsize = get memblock size(block) - 12
  startpos = (sndsize / 100.0) * startpercent#
  endpos = (sndsize / 100.0) * endpercent#
  drawrange = (endpos - startpos) + 1

 ` if sound is 16 bit then startpos and endpos must be even
  if bs = 2
    if (startpos mod 2) then inc startpos,1
    if (endpos mod 2) then dec endpos,1
  endif

  inc startpos, 12 : inc endpos, 12
  x# = left
  xd# = (width#-2) / (drawrange / bs)

  ` draw sound
  for pos = startpos to (endpos-1) step bs
    if bs = 1
      v = 128 - memblock byte(block, pos)
    else
      v = memblock word(block, pos) - 32768
      if v > 0 then v = 32768 - v else v = -32768 - v
      v = v / 256
    endif

    sx = int(x#)
    sy = centerline + (v * vscale#)

    select drawmode

      case 2
        if pos > startpos
          if sy < centerline
            box lastsx,sy,sx+1,centerline+1
          else
            box lastsx,centerline,sx+1,sy+1
          endif
        endif
        lastsx = sx
      endcase

      case 1
        if sx <> lastsx
          if pos > startpos then line lastsx,lastsy,sx,sy
          lastsx = sx : lastsy = sy
        endif
      endcase

      case default
        if sx <> lastsx
          box sx,sy,sx+1,sy+1
          lastsx = sx
        endif
      endcase

    endselect

    x# = x# + xd#
  next pos

endfunction



...and a small demo showing the new draw mode.

+ Code Snippet
sync on : sync rate 40

load sound "your_sound.wav",1
make memblock from sound 1,1

ink rgb(255,255,255),0 : text 10,0,"Dot"
DrawMonoSnd(10,16,630,144,1,0,100,rgb(128,128,128),rgb(255,255,0),0)
ink rgb(255,255,255),0 : text 10,148,"Line"
DrawMonoSnd(10,164,630,292,1,0,100,rgb(128,128,128),rgb(255,255,0),1)
ink rgb(255,255,255),0 : text 10,296,"Bar"
DrawMonoSnd(10,312,630,440,1,0,100,rgb(128,128,128),rgb(255,255,0),2)

` This double sync thing for Patch 4 is ugly :(
sync : sync

wait key
delete memblock 1
delete sound 1
end
Posted: 29th Mar 2003 6:06
Excellent -- the samples that were giving it a problem earlier are now loading without complaint. And they are right way up.

I like the new bar draw mode, but I'm staying with line mode for Lip Sync Lab just because I'm used to it.
Posted: 4th Apr 2003 7:34
Stereo Samples have two waveforms(one for each channel) so maybe there's a way to check for that?