Like a thousand other people I've started playing around with V2.
In particular, the memblock commands.
This is creating a memblock from a sound file.
Playing a wav from position and playing a wav from the start.
Plus a graphical display of the wav.
Hope you like it.
(The wav file I've included is mono ... This graph example only works on mono)
` draw wav and play sound from start or position
`
gosub set_resolution
`
gosub load_sound_music
`
gosub memblock_and_wav_data
`
gosub draw_wav
`
setprintsize(14)
`
do
`
gosub print_wav_info
`
gosub play_sound_from_start
`
gosub play_sound_from_position
`
sync()
loop
`
`-------------------------------- pre loop subs -----------------------------
set_resolution:
width#=640 : height=480
setvirtualresolution(width#,height)
return
`
`
load_sound_music:
loadsound(1,"wav1.wav")
loadmusic(1,"wav1.wav")
return
`
`
memblock_and_wav_data:
creatememblockfromsound(1,1)
`
channels = GetMemblockShort( 1, 0 )
bits_per_sample = GetMemblockShort( 1, 2 )
samples_per_second# = GetMemblockInt( 1, 4 )
frames_in_sound_data# = GetMemblockInt( 1, 8 )
bytes_of_sound_data = frames_in_sound_data#*(bits_per_sample/8)*channels
sound_length_in_seconds# = frames_in_sound_data#/samples_per_second#
scale# = bytes_of_sound_data/bits_per_sample
return
`
`
draw_wav:
z=1
for t = 13 to bytes_of_sound_data - 13 step bits_per_sample
z = z * -1
y = GetMemblockByte( 1, t ) * z
drawline(x#,(y*2)+300,x#,(y*2)+301,255,0,0)
x# = x# + width#/scale#
render()
next t
`
getimage(1,0,0,width#,height)
clearscreen()
createsprite(1,1)
return
`
`----------------------------------- looped subs ----------------------------
print_wav_info:
print("channels " + str(channels))
print("bits per sample " + str(bits_per_sample))
print("samples per second " + str(samples_per_second#))
print("frames in sound data " + str(frames_in_sound_data#))
print("bytes of sound data " + str(bytes_of_sound_data))
print("sound length in seconds " + str(sound_length_in_seconds#))
print("")
print("mouse right click to play the sound from start")
print("mouse left click to play the sound from position")
print("")
if seek=0 then print("time " + str(b#))
if seek=1 then print("time " + str(c#))
return
`
`
play_sound_from_start:
if GetRawMouseRightPressed() =1 : playmusic(1) : sx#=0 : resettimer() : a#=timer() : sy=200 : seek=0 : endif
if getmusicplaying()=1 and seek=0
drawline(sx#,sy,sx#,sy+200,2,2,255)
b# = timer()-a#
sx# = b# * (width#/sound_length_in_seconds#)
endif
return
`
`
play_sound_from_position:
if GetRawMouseleftPressed() =1 : playmusic(1) : sx#=getpointerx() : resettimer() : a#=timer() : sy=200
b# = sx#/(width#/sound_length_in_seconds#)
SeekMusic( b#, 1 )
seek=1
endif
if getmusicplaying()=1 and seek=1
c# = b# + timer()-a#
drawline(sx#,sy,sx#,sy+200,2,2,255)
sx# = c# * (width#/sound_length_in_seconds#)
endif
return
regards,
miki.
in the end