memblock dword(1, 0) : `Audio format, 1 = PCM, other values indicate compression
memblock dword(1, 4) : `channels, 1=mono, 2=stereo
memblock dword(1, 8) : `sample rate Hz
memblock dword(1, 12) : `average data rate (for buffer estimation)
memblock dword(1, 16) : `chunk size in bytes
memblock dword(1, 20) : `sample size in bits (bitrate)
memblock dword(1, 24) : `always 0, i have no clue
byte 28 and up is the pcm data
format as dword
channels as dword
sampleRate as dword
adr as dword
chunkSize as dword
sampleSize as dword
dword7 as dword
format = 1
channels = 2
sampleRate = 22050
sampleSize = 16
chunkSize = (ceiling(sampleSize / 8.0))*channels
adr = sampleRate*chunkSize
dword7 = 0
rem length of audio in seconds
length = 1
rem number of samples
samples = length*sampleRate
rem size of memblock
size = samples*ceiling(sampleSize/8.0) + 28
make memblock 1, size
write memblock dword 1, 0, format
write memblock dword 1, 4, channels
write memblock dword 1, 8, sampleRate
write memblock dword 1, 12, adr
write memblock dword 1, 16, chunkSize
write memblock dword 1, 20, sampleSize
write memblock dword 1, 24, dword7
pos = 28
out as word
for i = 1 to samples
out = (pcm data value)
write memblock word 1, pos, out
inc pos, 2
next i
make sound from memblock 1,1
delete memblock 1
In the above example, I used a 16-bit audio file.
16-bit audio
Each sample is 2 bytes long, so the value is a "word".
Value range is -32768 to 32767 (signed 2^16)
8-bit audio
Each sample is 1 byte long.
Value range is 0-255 (unsigned 2^8)
I've only tested 16-bit, but the 8-bit info should be accurate.
sources:http://ccrma.stanford.edu/courses/422/projects/WaveFormat/
"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike