Joshy
Code: Select all
type QSFChunk
as string*4 ID
as ulong Size
end type
function readBE16(byref p as ubyte ptr,byref nBytes as uinteger) as ushort
if nBytes<2 then
print "error: readBE16() out of memory !"
beep:sleep:end 1
end if
dim as ulong ret
dim as ubyte ptr p8=cptr(ubyte ptr,@ret)
for i as integer = 0 to 1
p8[1-i]= p[i]
next
p+=2:nBytes-=2
return ret
end function
function readBE32(byref p as ubyte ptr,byref nBytes as uinteger) as ulong
if nBytes<4 then
print "error: readBE32() out of memory !"
beep:sleep:end 1
end if
dim as ulong ret
dim as ubyte ptr p8=cptr(ubyte ptr,@ret)
for i as integer = 0 to 3
p8[3-i]= p[i]
next
p+=4:nBytes-=4
return ret
end function
function readChunkID(byref p as ubyte ptr,byref nBytes as uinteger) as string
if nBytes<4 then
print "error: readChunkID() out of memory !"
beep:sleep:end 1
end if
dim as string ret
for i as integer = 0 to 3
ret &= chr(p[i])
next
p+=4:nBytes-=4
return ret
end function
function readChunk(byref p as ubyte ptr,byref nBytes as uinteger) as QSFChunk
if nBytes<8 then
print "error: readChunk() out of memory !"
beep:sleep:end 1
end if
dim as QSFChunk ret
ret.ID = readChunkID(p,nBytes)
ret.size = readBE32(p,nBytes)
return ret
end function
'const fileName = "guitarra.QSF"
'const fileName = "SMPL000.QSF"
'const fileName = "SMPL001.QSF"
'const fileName = "SMPL002.QSF"
const fileName = "SMPLL002.QSL"
var hFile = FreeFile()
if open(fileName,for binary,access read,as hFile) then
print "error: can't read: '" & fileName & "' !"
beep:sleep:end 1
end if
dim as uinteger nBytes = lof(hFile)
print "file size: " & nBytes
dim as ubyte ptr fileBuffer=allocate(nBytes)
get #hFile,,*fileBuffer,nBytes
close hFile
dim as ushort U16
dim as ulong U32
var p=fileBuffer
var chunk = readChunk(p,nBytes)
print chunk.id,chunk.size,nBytes
U16=readBE16(p,nBytes)
print U16,hex(U16)
U16=readBE16(p,nBytes)
print U16,hex(U16)
U16=readBE16(p,nBytes)
print U16,hex(U16)
chunk = readChunk(p,nBytes)
print chunk.ID,chunk.Size,nBytes
U32=readBE32(p,nBytes)
print U32,hex(U32)
U32=readBE32(p,nBytes)
print U32,hex(U32)
print "done ..."
if fileBuffer then deallocate fileBuffer
sleep