예제 #1
0
 // -----------------------------------------------------------------
 //  Simulates a pluck by replace all the values in the queue with
 //  a value from -0.5 to 0.5
 // -----------------------------------------------------------------
 public void pluck() {
   Random rand = new Random();
   for (int i = 0; i < frequency; i++) {
     chord.dequeue();
     double randomNum = -0.5 + rand.nextDouble();
     chord.enqueue(randomNum);
   }
 }
예제 #2
0
 // -----------------------------------------------------------------
 //  Dequeues, takes the average of it and the sample, then multiplies
 //  by .944 to create an energy decay factor
 // -----------------------------------------------------------------
 public void tic() {
   try {
     double note = chord.dequeue();
     double newnote = ((note + chord.first()) * 0.994) / 2;
     chord.enqueue(newnote);
   } catch (NullPointerException exception) {
     System.out.println("Empty array");
   }
 }
예제 #3
0
 // -----------------------------------------------------------------
 //  Constructor takes a frequency to build around
 // -----------------------------------------------------------------
 public GuitarString(double frequency) {
   this.frequency = frequency;
   final int sampleRate = 44100;
   int capacity = (int) Math.round(44100 / frequency);
   chord = new BoundedQueue<Double>(capacity);
   for (int i = 0; i < capacity; i++) {
     chord.enqueue((double) 0);
   }
 }
예제 #4
0
 // -----------------------------------------------------------------
 //  Returns the first value in the queue
 // -----------------------------------------------------------------
 public double sample() {
   return chord.first();
 }