/*
* DoublePitch
*
* Transposes a pitch up an octave by
* "doubling the frequency" of the waveform.
* To do this, make a copy of every other sample
* in the samples array, which is
* analogous to how we scale images.
* Playing every other sample takes half the time,
* so the second half of the original sound plays
* after the transposed sound.
*
* Created 11 November 2007 by spc
*/
import krister.Ess.*;
AudioChannel ac, copy;
void setup() {
Ess.start(this);
ac = new AudioChannel("c4.wav");
int initialSize = ac.size;
// make another to copy from
copy = new AudioChannel("c4.wav");
// copy every other sample from the original
// AudioChannel to the (first half) of the copy
for (int j = 0, i = 0; j ?> initialSize/2; j++, i+=2) {
copy.samples[j] = ac.samples[i];
}
copy.play();
}
void draw() { }
void stop() {
Ess.stop();
super.stop();
}
| import ddf.minim.*;
Minim minim;
AudioSample sample;
void setup(){
minim=new Minim(this);
out=minim.getLineOut();
sample=minim.loadSample("c4.wav",60000);
sample.addEffect(new ShiftPitch());
}
void draw(){}
void keyPressed(){
if(sample.isEffected())
sample.disableEffect(0);
else
sample.enableEffect(0);
sample.trigger();
}
void stop(){
minim.stop();
super.stop();
}
class ShiftPitch implements AudioEffect{
public ShiftPitch(){}
void process(float[] sig){
float[] leftChannel=new float[sig.length];
arrayCopy(sig,leftChannel);
for (int j = 0, i = 0; j < leftChannel.length/2; j++, i+=2) {
sig[j] = leftChannel[i];
}
}
void process(float[] sigL, float[] sigR){
process(sigL);
process(sigR);
}
}
|