* trigger signals are created by a PWM generator. The pitches are generated by the well tempered scale for the first,
* and a custom scale for the second file.
*/
@SuppressWarnings("hiding")
public void testTS7() { // envelope generator
AdvancerRegistry advancerRegistry=new AdvancerRegistry();
try{
advancerRegistry.clear();
globalParameters.setSampleRate(44100);
ProcessElement cos=new Cosine();
ProcessElement env1=new Envelope();
advancerRegistry.registerAdvancer(cos);
advancerRegistry.registerAdvancer(env1);
Time time=new Time();
Mixer mix=new Mixer();
PWM gate=new PWM();
advancerRegistry.registerAdvancer(mix);
advancerRegistry.registerAdvancer(time);
advancerRegistry.registerAdvancer(env1);
advancerRegistry.registerAdvancer(cos);
advancerRegistry.registerAdvancer(gate);
Scale s=new WellTemperedScale();
ConstStream note_A=new ConstStream(s.getValueFor("A"));
ConstStream note_e=new ConstStream(s.getValueFor("e"));
ConstStream note_csharp=new ConstStream(s.getValueFor("c#"));
ConstStream notes[]=new ConstStream[]{note_A, note_e, note_csharp};
ConstStream beats=ConstStream.c(1); // 60 bpm in beats per second
ConstStream A=new ConstStream(0.13);
ConstStream D=new ConstStream(1.25);
ConstStream S=new ConstStream(0.25);
ConstStream R=new ConstStream(2.55);
try{
mix.setSource(-1, cos, StandardParameters.OUT.i);
mix.setSource(-1, env1, StandardParameters.OUT.i);
gate.setSource(StandardParameters.FREQUENCY.i, beats, StandardParameters.OUT.i);
gate.setSource(StandardParameters.DUTYCYCLE.i, new ConstStream(0.5),
StandardParameters.OUT.i);
cos.setSource(StandardParameters.FREQUENCY.i, note_A, StandardParameters.OUT.i);
env1.setSource(StandardParameters.A.i, A, StandardParameters.OUT.i);
env1.setSource(StandardParameters.D.i, D, StandardParameters.OUT.i);
env1.setSource(StandardParameters.S.i, S, StandardParameters.OUT.i);
env1.setSource(StandardParameters.R.i, R, StandardParameters.OUT.i);
env1.setSource(StandardParameters.SYNC.i, gate, StandardParameters.OUT.i);
}catch(Exception te){
fail(te.getMessage());
}
OutputFile ws1=new OutputFile(2);
mul m1=new mul();
mul m2=new mul();
ws1.setSource(0, m1, OUT.i);
ws1.setSource(-1, m2, OUT.i);
m1.setSource(IN_IMAG.i, ConstStream.c(0.5), OUT.i);
m2.setSource(IN_IMAG.i, ConstStream.c(0.5), OUT.i);
m1.setSource(IN.i, mix, OUT.i);
m2.setSource(IN.i, gate, OUT.i);
advancerRegistry.registerAdvancer(ws1);
double lastVal=0;
int lastIndex=0;
for(double t=0; t<10.5; t+=1/globalParameters.getSampleRate()){
advancerRegistry.advanceAll();
// ws1.getChannel(0).add(0.5*mix.getValue(StandardParameters.OUT.i));
// ws1.getChannel(1).add(0.5*gate.getValue(StandardParameters.OUT.i));
double newVal=gate.getValue(StandardParameters.OUT.i);
if(lastVal<1&&newVal>0){
cos.setSource(StandardParameters.FREQUENCY.i, notes[lastIndex], StandardParameters.OUT.i);
lastIndex=(lastIndex+1)%notes.length;
}
lastVal=gate.getValue(StandardParameters.OUT.i);
}
try{
File f=new File("env1test.wav");
BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
ws1.setFormat(FileFormats.FMT_WAVE_S16);
ws1.write(fos);
fos.close();
}catch(IOException ex){
fail(ex.getMessage());
}
s=new CustomScale();
s.put("note1", 320, 1, 2, null);
s.put("note2", 400, 2, 3, 1);
s.put("note3", 480, 3, null, 2);
note_A=new ConstStream(s.getValueFor("note1"));
note_e=new ConstStream(s.getValueFor("note2"));
note_csharp=new ConstStream(s.getValueFor("note3"));
notes=new ConstStream[]{note_A, note_e, note_csharp};
beats=new ConstStream(1.5); // 60 bpm in beats per second
A=new ConstStream(0.13);
D=new ConstStream(1.25);
S=new ConstStream(0.25);
R=new ConstStream(2.55);
try{
mix.setSource(-1, cos, StandardParameters.OUT.i);
mix.setSource(-1, env1, StandardParameters.OUT.i);
gate.setSource(StandardParameters.FREQUENCY.i, beats, StandardParameters.OUT.i);
gate.setSource(StandardParameters.DUTYCYCLE.i, ConstStream.c(0.5), StandardParameters.OUT.i);
cos.setSource(StandardParameters.FREQUENCY.i, note_A, StandardParameters.OUT.i);
env1.setSource(StandardParameters.A.i, A, StandardParameters.OUT.i);
env1.setSource(StandardParameters.D.i, D, StandardParameters.OUT.i);
env1.setSource(StandardParameters.S.i, S, StandardParameters.OUT.i);
env1.setSource(StandardParameters.R.i, R, StandardParameters.OUT.i);
env1.setSource(StandardParameters.SYNC.i, gate, StandardParameters.OUT.i);
}catch(Exception te){
fail(te.getMessage());
}
NativeObjects.unregisterNativeObject(ws1);
ws1=new OutputFile(2);
ws1.setSource(0, m1, OUT.i);
ws1.setSource(-1, m2, OUT.i);
m1.setSource(IN_IMAG.i, ConstStream.c(0.5), OUT.i);
m2.setSource(IN_IMAG.i, ConstStream.c(0.5), OUT.i);
m1.setSource(IN.i, mix, OUT.i);
m2.setSource(IN.i, gate, OUT.i);
advancerRegistry.registerAdvancer(ws1);
lastVal=0;
lastIndex=0;
for(double t=0; t<10.5; t+=1/globalParameters.getSampleRate()){
advancerRegistry.advanceAll();
// ws1.getChannel(0).add(0.5*mix.getValue(StandardParameters.OUT.i));
// ws1.getChannel(1).add(0.5*gate.getValue(StandardParameters.OUT.i));
double newVal=gate.getValue(StandardParameters.OUT.i);
if(lastVal<1&&newVal>0){
cos.setSource(StandardParameters.FREQUENCY.i, notes[lastIndex], StandardParameters.OUT.i);
lastIndex=(lastIndex+1)%notes.length;
}
lastVal=gate.getValue(StandardParameters.OUT.i);
}
try{
File f=new File("scale1test.wav");
BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
ws1.setFormat(FileFormats.FMT_WAVE_S16);
ws1.write(fos);
fos.close();
}catch(IOException ex){
fail(ex.getMessage());
}
advancerRegistry.unregisterAdvancer(cos);
advancerRegistry.unregisterAdvancer(mix);
advancerRegistry.unregisterAdvancer(env1);
advancerRegistry.unregisterAdvancer(time);
advancerRegistry.unregisterAdvancer(gate);
advancerRegistry.clear();
NativeObjects.unregisterNativeObject(cos);
NativeObjects.unregisterNativeObject(mix);
NativeObjects.unregisterNativeObject(time);
NativeObjects.unregisterNativeObject(ws1);
NativeObjects.unregisterNativeObject(gate);