aUCBLogo Demos and Tests / makewav_sines
to makewav_sines
rate=44100
ntones=13
size=Int rate*ntones/8
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 []
ssize=Int size/ntones-1
phi=0
t=0
t0=0
dt=1/rate
k=wavHeaderSizeHalf+1
for [i 0 ntones-1]
[ f=440*2^(i/12)
for [j 0 ssize]
[ t=t+dt
phi=phi+f*(t-t0)
t0=t
wav.k=Int16 30000*(sin 360*phi)
k=k+1
]
]
; drawPlot
playWave wav 0
end
to drawPlot
WindowMode
hideTurtle
clearScreen
PenUp
setXY -400 0
PenDown
setXY rseqfa -400 400 Int wavsize/2 FloatArray wav
updateGraph
end