In :
# Not the best version, just a first-off at this:
# By Keith O'Hara, Bard College

# Based on nifty guitar demo:
# http://introcs.cs.princeton.edu/java/assignments/guitar.html
# This assignment was developed by Andrew Appel, Jeff Bernstein,
# Maia Ginsburg, Ken Steiglitz, Ge Wang, and Kevin Wayne.

import wave
import math
import struct
import random
from collections import deque

def pluck(freq1=220, freq2=330): #A3, E4
sampling_rate = 44100
channels = 2
bytes_per_sample = 2
amplitude = 2**(8*bytes_per_sample) / 2

buffer1_size = sampling_rate // freq1
buffer2_size = sampling_rate // freq2

w = wave.open("out.wav", 'w')
w.setnchannels(channels)
w.setsampwidth(bytes_per_sample)
w.setframerate(sampling_rate)
w.setnframes(sampling_rate * bytes_per_sample)

buf1 = deque([random.uniform(-.5, .5) for x in range(buffer1_size)])
buf2 = deque([random.uniform(-.5, .5) for x in range(buffer2_size)])
gain = .994

for i in range(int(amplitude * 1.5)):
v1 = gain * .5*(buf1 + buf1)
buf1.popleft()
buf1.append(v1)
v2 = gain * .5*(buf2 + buf2)
buf2.popleft()
buf2.append(v2)
v = v1 + v2
w.writeframes(struct.pack('h', int(v*amplitude)))
w.writeframes(struct.pack('h', int(v*amplitude)))
w.close()

In :
pluck()
calico.display(calico.Audio("out.wav"))

In :
freq1 = calico.IntSliderWidget(description="Freq1", min=100, max=2000)

In :
freq2 = calico.IntSliderWidget(description="Freq2", min=100, max=2000)

In :
[calico.display(f) for f in [freq1, freq2]]

Out:
[None, None]
In :
pluck(freq1.value, freq2.value)

In :
calico.Audio("out.wav")

Out:
In [ ]: