def pluck(string): """ Pluck the given guitar string by replacing the buffer with white noise. """ ring_buffer.dequeue(string) ring_buffer.enqueue(string, random.randrange(-0.5, 0.5))
def pluck(string): """ Pluck the given guitar string by replacing the buffer with white noise. """ for i in range(len(string[0])): v = random.uniform(-0.5, 0.5) ring_buffer.enqueue(string, v)
def tic(string): """ Advance the simulation one time step on the given guitar string by applying the Karplus-Strong update. """ a = ring_buffer.dequeue(string) b = ring_buffer.peek(string) ring_buffer.enqueue(string, 0.996 * 0.5 * (a + b))
def pluck(string): """ Pluck the given guitar string by replacing the buffer with white noise. """ string_size = ring_buffer.size(string) for i in range(0, string_size): ring_buffer.dequeue(string) ring_buffer.enqueue(string, random.uniform(-0.5, 0.5))
def pluck(string): """ Pluck the given guitar string by replacing the buffer with white noise. """ ring_buffer.dequeue(string) random_entry = random.uniform(-0.5, 0.5) print(random_entry) ring_buffer.enqueue(string, random_entry)
def tic(string): """ Advance the simulation one time step on the given guitar string by applying the Karplus-Strong update. """ x1 = ring_buffer.dequeue(string) x2 = ring_buffer.peek(string) x3 = 0.5 * (x1 + x2) * 0.996 ring_buffer.enqueue(string, x3)
def pluck(string): """ Pluck the given guitar string by replacing the buffer with white noise. Replace each value (dequeue followed by enqueue) in the given ring buffer with a random number from the interval [-0.5, 0.5]. """ ring_buffer.dequeue(string) r = random.uniform(-0.5, 0.5) ring_buffer.enqueue(string, r)
def pluck(string): """ Pluck the given guitar string by replacing the buffer with white noise. """ # All elements in ring buffer replaced with random float. for v in range(ring_buffer.capacity(string)): v = random.uniform(-0.5, 0.5) ring_buffer.dequeue(string) ring_buffer.enqueue(string, v)
def create_from_samples(init): """ Create and return a guitar string whose size and initial values are given by the list init. """ n = len(init) rb = ring_buffer.create(n) for v in init: ring_buffer.enqueue(rb, v) return rb
def tic(string): """ Advance the simulation one time step on the given guitar string by applying the Karplus-Strong update. Dequeue a value a in the given ring buffer and peek at the next value b. Enqueue the value 0.996 * 0.5 * (a+b) into the ring buffer. """ a = ring_buffer.dequeue(string) b = ring_buffer.peek(string) ring_buffer.enqueue(string, 0.996 * 0.5 * (a + b))
def create_from_samples(init): """ Create and return a guitar string whose size and initial values are given by the list init. Populate the ring buffer with values from init. Return the ring buffer. """ capacity = len(init) rb = ring_buffer.create(capacity) for i in init: ring_buffer.enqueue(rb, i) return rb
def create(frequency): """ Create and return a guitar string of the given frequency, using a sampling rate given by SPS. A guitar string is represented as a ring buffer of of capacity N (SPS divided by frequency, rounded up to the nearest integer), with all values initialized to 0.0. """ N = int(math.ceil(SPS / frequency)) rb = ring_buffer.create(N) for i in range(N): ring_buffer.enqueue(rb, 0.0) return rb
def create_from_samples(init): """ Create and return a guitar string whose size and initial values are given by the list init. """ # create a sample ring buffer # use for loop and make it equal to init samp_rg = ring_buffer.create(len(init)) for v in init: ring_buffer.enqueue(samp_rg, v) return samp_rg
def tic(string): """ Advance the simulation one time step on the given guitar string by applying the Karplus-Strong update. """ # set x with removed value of the ring buffer. x = ring_buffer.dequeue(string) # set y without removing value of rg. y = ring_buffer.peek(string) # set z as with Karplus-Strong update. # invoke enqueue with string and z z = 0.996 * 0.5 * (x + y) ring_buffer.enqueue(string, z)
def create(frequency): """ Create and return a guitar string of the given frequency, using a sampling rate given by SPS. A guitar string is represented as a ring buffer of of capacity N (SPS divided by frequency, rounded up to the nearest integer), with all values initialized to 0.0. """ # calculating N then rouned up. N = int(math.ceil(SPS / frequncy)) # create a guitar string by using ring buffer. string = ring_buffer.create(N) # use for loop for enqeue N. for v in range(N): ring_buffer.enqueue(string, 0.0) # return string return string