Skip to content

Instantly share code, notes, and snippets.

@Frithir
Last active April 13, 2024 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Frithir/08a21ae5cc763cda3127d5f74a068e51 to your computer and use it in GitHub Desktop.
Save Frithir/08a21ae5cc763cda3127d5f74a068e51 to your computer and use it in GitHub Desktop.
Sonic pi phone
DIAL_TONES = {
:uk => [350, 450],
:us => [350, 440],
:eu => [425],
:jp => [400]
}
DTMF_TONES = {
'1' => [697, 1209],
'2' => [697, 1336],
'3' => [697, 1477],
'4' => [770, 1209],
'5' => [770, 1336],
'6' => [770, 1477],
'7' => [852, 1209],
'8' => [852, 1336],
'9' => [852, 1477],
'*' => [941, 1209],
'0' => [941, 1336],
'#' => [941, 1477],
'A' => [697, 1477],
'B' => [770, 1477],
'C' => [852, 1477],
'D' => [941, 1477],
}
define :pulses do |freqs, periods|
on = true
periods.each do |t|
if on
freqs.each do |freq|
synth :sine, note: hz_to_midi(freq), sustain: t, release: 0
end
end
sleep t
on = not(on)
end
end
define :dialtone do |tone=:uk, periods=[2]|
tone = DIAL_TONES[tone]
pulses(tone, periods)
end
define :dtmf do |digit, length=0.15, pause=0.15|
tone = DTMF_TONES[digit.to_s.upcase]
pulses(tone, [length, pause]) if tone
end
define :ringring do |rings=1|
pulses([400, 450], [0.4, 0.2, 0.4, 2] * rings)
end
define :phone do |number|
with_fx :distortion, distort: 0.3, mix: 0.3 do
noise = synth :pnoise, amp: 0.03, sustain: 15
dialtone(:uk)
number.split('').each do |n|
dtmf(n)
end
sleep 1
ringring(3)
#control noise, amp: 0
end
end
phone '0421 834 000'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment