Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Extract computation-intensive loops before refactoring the stateful p…

…art of the plugin to ruby.
  • Loading branch information...
commit 527a262b409e4b740f3c4ba0f9f185a1c541b9e3 1 parent 41a2b26
@thbar authored
Showing with 26 additions and 18 deletions.
  1. +26 −18 plugins/HybridSynth/HybridSynthTools.java
View
44 plugins/HybridSynth/HybridSynthTools.java
@@ -29,6 +29,29 @@ public void note_off() {
this.noteIsOn = false;
}
+ public void zeroFill(float[][] outputs, int count) {
+ float[] output0 = outputs[0];
+ float[] output1 = outputs[1];
+ for(int i = 0; i < count; i++) {
+ output0[i] = 0;
+ output1[i] = 0;
+ }
+ }
+
+ public void computeWave(float[][] outputs, float[] wave1, float[] wave2, int mask, int start, float freq1, float freq2, float vol, float volume1, float volume2) {
+ float[] output0 = outputs[0];
+ float[] output1 = outputs[1];
+ for (int i = start, j=output0.length; i < j; i++) {
+ // this is all very raw, there is no means of interpolation,
+ // and we will certainly get aliasing due to non-bandlimited
+ // waveforms. don't use this for serious projects...
+ output0[i] = wave1[(int)phase1 & mask] * volume1 * vol;
+ output1[i] = wave2[(int)phase2 & mask] * volume2 * vol;
+ this.phase1 += freq1;
+ this.phase2 += freq2;
+ }
+ }
+
public void processReplacing(
float[][] inputs, float[][] outputs, int sampleFrames,
float volume,
@@ -54,31 +77,16 @@ public void processReplacing(
this.currentDelta -= sampleFrames;
return;
}
- for(int i = 0; i < this.currentDelta; i++) { //zero delta frames
- out1[i] = 0;
- out2[i] = 0;
- }
+ zeroFill(outputs, this.currentDelta);
start = this.currentDelta;
sampleFrames -= this.currentDelta;
this.currentDelta = 0;
}
- for (int i = start, j=out1.length; i < j; i++) {
- // this is all very raw, there is no means of interpolation,
- // and we will certainly get aliasing due to non-bandlimited
- // waveforms. don't use this for serious projects...
- out1[i] = wave1[(int)phase1 & mask] * volume1 * vol;
- out2[i] = wave2[(int)phase2 & mask] * volume2 * vol;
- this.phase1 += freq1;
- this.phase2 += freq2;
- }
+ computeWave(outputs, wave1, wave2, mask, start, freq1, freq2, vol, volume1, volume);
}
else {
- //note off
- for (int i=0; i<outputs[0].length; i++){
- outputs[0][i] = 0;
- outputs[1][i] = 0;
- }
+ zeroFill(outputs, outputs[0].length); //note off
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.