Skip to content

Instantly share code, notes, and snippets.

@nbqx
Created May 10, 2011 14:00
Show Gist options
  • Save nbqx/964517 to your computer and use it in GitHub Desktop.
Save nbqx/964517 to your computer and use it in GitHub Desktop.
import com.softsynth.jsyn.*
//groovy script for phone call
class DualToneMultiFrequency{
def num
def buf
SineOscillator high
SineOscillator low
AddUnit mixer
LineOut out
public DualToneMultiFrequency(String str){
Synth.startEngine(0)
num = str.toList()
high = new SineOscillator()
low = new SineOscillator()
mixer = new AddUnit()
out = new LineOut()
buf = num.collect{x-> dtmfMatrix[x]}
}
def exec = {
high.output.connect(0,mixer.inputA,0)
low.output.connect(mixer.inputB)
mixer.output.connect(0,out.input,0)
mixer.output.connect(0,out.input,1)
high.start()
low.start()
mixer.start()
buf.each{
dial(it)
}
out.stop()
Synth.stopEngine()
}
def dial = {x->
high.with{
frequency.set(x.higher)
amplitude.set(0.5)
}
low.with{
frequency.set(x.lower)
amplitude.set(0.5)
}
out.start()
Synth.sleepForTicks(80)
out.stop()
Synth.sleepForTicks(60)
}
def dtmfMatrix = [
"1":[higher:1209, lower:697],
"2":[higher:1336, lower:697],
"3":[higher:1477, lower:697],
"4":[higher:1209, lower:770],
"5":[higher:1336, lower:770],
"6":[higher:1477, lower:770],
"7":[higher:1209, lower:852],
"8":[higher:1336, lower:852],
"9":[higher:1477, lower:852],
"*":[higher:1209, lower:941],
"0":[higher:1336, lower:941],
"#":[higher:1477, lower:941],
"A":[higher:1633, lower:697],
"B":[higher:1633, lower:770],
"C":[higher:1633, lower:852],
"D":[higher:1633, lower:941]
]
}
def dtmf = new DualToneMultiFrequency("117")
dtmf.exec()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment