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);