Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.LinkedList;
- import java.util.Queue;
- /**
- * Implements your code here.
- * Change comments
- * @Author Your Name
- * @Date
- */
- public class KPGuitarString implements GuitarString{
- private Queue<Double> ringBuffer;
- // private RingBuffer ring;
- private int strlen;
- private int time;
- private static final int SAMPLE = 44100;
- private static final double ENERGY = .996;
- public KPGuitarString(double frequency)
- {
- time = 0;
- int length = (int) Math.ceil(SAMPLE / frequency);
- strlen = length;
- //ring = new RingBuffer(length);
- ringBuffer = new LinkedList<>();
- for (int i = 0; i < length; i++) {
- ringBuffer.add(0.0);
- }
- // while(!ring.isFull())
- // ring.enqueue(0);
- }
- public KPGuitarString(double[] init)
- {
- time = 0;
- ringBuffer = (Queue<Double>) new RingBuffer(init.length);
- for(int i = 0; i < init.length; i++)
- {
- // ring.enqueue(init[i]);
- ringBuffer.add(init[i]);
- }
- }
- /**
- * Implement your code here
- * Change comments
- */
- @Override
- public void pluck(){
- for(int i = 0; i < strlen; i++)
- {
- double rnd = Math.random() - 0.5;
- // ring.enqueue(rnd);
- ringBuffer.add(rnd);
- }
- }
- /**
- * Implement your code here
- * Change comments
- */
- @Override
- public void tic(){
- // double first = ring.dequeue();
- double first = ringBuffer.remove();
- double second = sample();
- ringBuffer.add(ENERGY * (first + second) / 2 );
- time++;
- }
- /**
- * Implement your code here
- * Change comments
- */
- @Override
- public double sample()
- {
- return ringBuffer.peek();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement