aUCBLogo Demos and Tests / makewav4
to makewav4
starttime=timefine
rate=44100
size=rate*22
wavHeaderType=(list
[ChunkID Word RIFF]
[wavfilesize Int]
[RIFFtype Word WAVE] ;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]
[DataChunkSize Int]
)
wavHeader=struct wavHeaderType
wavHeaderSize=SizeOf wavHeader
wavHeaderSizeHalf=int wavHeaderSize/2
wavsize=wavHeaderSize+size*2
wav=Int16Array int wavsize/2
; setReader wav
; wh=readStructBin wavHeaderType
; pr wh
; setReader []
start0=wavHeaderSizeHalf
maxsize=0
length=int rate/6
gentones [2 2 5 2 7 4 7 4 7 4 7 2 5 2 7 2 9 1 7 4 -100 4
2 2 5 2 7 4 5 4 2 4 2 2 0 1 2 6 -100 6
2 2 5 2 7 4 5 4 0 4 0 2 -2 2 0 2 2 1 0 4 -100 4
2 2 5 2 7 4 5 4 0 4 0 2 -2 1 0 6 -100 6]
start=start0
moll [-26 2 -27 2 -29 4 -29 4 -29 4 -29 2 -22 2 -29 2 -22 1 -29 4 -100 4
-29 2 -26 2 -22 4 -22 4 -22 4 -22 2 -24 1 -22 6 -100 6]
dur [-26 2 -27 2 -31 8 -31 8 -31 2 -31 1 -31 4 -100 4
-19 2 -22 2 -24 4 -24 4 -24 4 -24 2 -19 1 -24 6 -100 6]
wavHeader'wavfilesize=maxsize*2
wavHeader'DataChunkSize=maxsize*2-wavHeaderSize
; pr wavHeader
setWriter wav
typeBin wavHeader
setWriter []
(pr timefine-starttime [seconds])
playWave wav 1
(pr [playWave wav 1+8])
ignore readChar
playWave [] 0
end
to gentones tlist
start=start0
while [and not empty? tlist not Key?]
[ t=first tlist
tlist=bf tlist
f=440*2^(t/12)
l=first tlist
tlist=bf tlist
repeat l*length
[ phi=360*repcount/rate
i=repCount+start
wav.i=(wav.i)+Int16 Int16Max/8*( (sin f*phi)
- (sin (f+6/l)*phi) )
]
start=start+l*length
]
maxsize=max maxsize start
end
to moll tlist
while [and not empty? tlist not Key?]
[ t=first tlist
tlist=bf tlist
f=440*2^(t/12)
f2=440*2^((t+7)/12)
f3=440*2^((t+12)/12)
f4=440*2^((t+15)/12)
l=first tlist
tlist=bf tlist
repeat l*length
[ phi=360*repcount/rate
i=repCount+start
wav.i=(wav.i)+Int16 Int16Max/24*(
(sin (f )*phi) - (sin (f +6/l)*phi)
+(sin (f2)*phi) - (sin (f2+6/l)*phi)
+(sin (f3)*phi) - (sin (f3+6/l)*phi)
+(sin (f4)*phi) - (sin (f4+6/l)*phi) )
]
start=start+l*length
]
maxsize=max maxsize start
end
to dur tlist
while [and not empty? tlist not Key?]
[ t=first tlist
tlist=bf tlist
f=440*2^(t/12)
f2=440*2^((t+7)/12)
f3=440*2^((t+12)/12)
f4=440*2^((t+16)/12)
l=first tlist
tlist=bf tlist
repeat l*length
[ phi=360*repcount/rate
i=repCount+start
wav.i=(wav.i)+Int16 Int16Max/24*(
(sin (f )*phi) - (sin (f +6/l)*phi)
+(sin (f2)*phi) - (sin (f2+6/l)*phi)
+(sin (f3)*phi) - (sin (f3+6/l)*phi)
+(sin (f4)*phi) - (sin (f4+6/l)*phi) )
]
start=start+l*length
]
maxsize=max maxsize start
end