Grain.java (940B)
1 package be.tarsos.dsp.granulator; 2 3 /** 4 * The nested class Grain. Stores information about the start time, current position, age, and grain size of the grain. 5 */ 6 class Grain{ 7 8 /** The position in millseconds. */ 9 double position; 10 11 /** The age of the grain in milliseconds. */ 12 double age; 13 14 /** The grain size of the grain. Fixed at instantiation. */ 15 double grainSize; 16 17 boolean active; 18 19 /** 20 * Sets the given Grain to start immediately. 21 * 22 * @param g 23 * the g 24 * @param time 25 * the time 26 */ 27 void reset(double grainSize,double randomness,double position,double timeStretchFactor,double pitchShiftFactor){ 28 double randomTimeDiff = (Math.random() > 0.5 ? +1 : -1) * grainSize * randomness; 29 double actualGrainSize = (grainSize + randomTimeDiff) * 1.0/timeStretchFactor + 1; 30 this.position = position - actualGrainSize; 31 this.age = 0f; 32 this.grainSize = actualGrainSize; 33 this.active =true; 34 } 35 }