aUCBLogo Demos and Tests / tinnitus
to tinnitus
starttime=timefine
rate=44100
size=rate*10
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 [-40 40]
gentones [60 40]
wavHeader'wavfilesize=maxsize*2
wavHeader'DataChunkSize=maxsize*2-wavHeaderSize
; pr wavHeader
setWriter wav
typeBin wavHeader
setWriter []
GC
(pr timefine-starttime [seconds])
playWave wav 1+8
(pr [playWave wav 1+8])
(pr [playWave [] 0])
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
phi=rSeqFloatArray 360*1/rate 360*l*length/rate l*length
setItems start+1 wav
(items start+1 start+l*length wav)
+Int16array ( (sin phi*f)-(sin phi*(f+6/l)) )*(Int16Max/8)
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
phi=rSeqFloatArray 360*1/rate 360*l*length/rate l*length
setItems start+1 wav
(items start+1 start+l*length wav)
+Int16array ( (sin phi*f )-(sin phi*(f +6/l))
+(sin phi*f2)-(sin phi*(f2+6/l))
+(sin phi*f3)-(sin phi*(f3+6/l))
+(sin phi*f4)-(sin phi*(f4+6/l)) )*(Int16Max/24)
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
phi=rSeqFloatArray 360*1/rate 360*l*length/rate l*length
setItems start+1 wav
(items start+1 start+l*length wav)
+Int16array ( (sin phi*f )-(sin phi*(f +6/l))
+(sin phi*f2)-(sin phi*(f2+6/l))
+(sin phi*f3)-(sin phi*(f3+6/l))
+(sin phi*f4)-(sin phi*(f4+6/l)) )*(Int16Max/24)
start=start+l*length
]
maxsize=max maxsize start
end