aUCBLogo Demos and Tests / makewav3
to makewav3
rate=44100
size=rate/2
wavHeaderType=(list
[ChunkID Word RIFF]
[wavfilesize Int]
[RIFFtype Word 4] ;the last item is the string length
[formatChunkID Word fmt\ ]
[formatChunkSize Int 16]
[compressionCode Int16 1]
[NumberOfChannels Int16 1]
(list "SampleRate "Int rate)
(list "BytesPerSecond "Int rate*2)
[BlockAlign Int16 2]
[BitsPerSample Int16 16]
[DataChunkID word data]
(list "DataChunkSize "Int size*2)
)
wavHeader=struct wavHeaderType
wavHeaderSize=SizeOf wavHeader
wavHeaderSizeHalf=int wavHeaderSize/2
wavsize=wavHeaderSize+size*2
wavHeader'RIFFtype=[WAVE] ;example for setting a string
wavHeader'wavfilesize=wavsize
pr wavHeader
wav=Int16Array int wavsize/2
setWriter wav
typeBin wavHeader
setWriter []
; setReader wav
; wh=readStructBin wavHeaderType
; pr wh
; setReader []
k=-43
dk=1
(pr [+ - changes speed, ESC exits])
running=true
while [running]
[ f=440*2^(k/12)
pr f
if f > 20000 [dk=-dk]
if f < 20 [dk=-dk]
while [Key?]
[ c=readChar
if (rawASCII c)==27 [running=false]
if c=="+ [dk=dk+1]
if c=="- [dk=dk-1]
]
k=k+dk
repeat size
[ phi=360*repcount/rate
i=repCount+wavHeaderSizeHalf
wav.i=Int16 16383*( (sin (f)*phi)
- (sin (f+2)*phi) )
]
playWave wav 1
GC
waitms 200
]
ignore readChar
playWave [] 0
end