Package de.maramuse.soundcomp.generator

Examples of de.maramuse.soundcomp.generator.PWM


  event.setStarttime(ts);
  event.setDuration(durationGate);
  event.setLivetime(durationTotal);
  event.setFrequency(scale.getValueFor(note));
  event.setPitch(scale.getPitch(note));
  PWM pwm=new PWM();
  pwm.setAbstractName("pad-pw");
  pwm.setInstanceName("pad-pw"+nameCount++);
  Envelope filterEnv=new Envelope();
  Sine lfo=new Sine();
  Envelope volumeEnv=new Envelope();
  StateVariableFilter svf=new StateVariableFilter();
  StateVariableFilter hp=new StateVariableFilter();
  mul mfilfreq=new mul(), mfilfreq2=new mul();
  plus pfilfreq=new plus();
  mul mout=new mul();
  mul lfof=new mul();
  mul mvol=new mul();
  mul dmul=new mul();
  mul dmul2=new mul();
  plus dpl=new plus();
  plus dpl2=new plus();
  try{
    lfof.setSource(IN_IMAG.i, event, FREQUENCY.i);
    lfof.setSource(IN.i, ConstStream.c(0.005), OUT.i);
    lfo.setSource(FREQUENCY.i, lfof, OUT.i);
    hp.setSource(FREQUENCY.i, ConstStream.c(20), OUT.i);
    hp.setSource(IN.i, pwm, OUT.i);
    filterEnv.setSource(SYNC.i, event, GATE.i);
    filterEnv.setSource(A.i, ConstStream.c(0.4), OUT.i);
    filterEnv.setSource(D.i, ConstStream.c(0.7), OUT.i);
    filterEnv.setSource(R.i, ConstStream.c(0.7), OUT.i);
    filterEnv.setSource(S.i, ConstStream.c(0), OUT.i);
    volumeEnv.setSource(SYNC.i, event, GATE.i);
    volumeEnv.setSource(A.i, ConstStream.c(0.4), OUT.i);
    volumeEnv.setSource(D.i, ConstStream.c(1.1), OUT.i);
    volumeEnv.setSource(R.i, ConstStream.c(1.1), OUT.i);
    volumeEnv.setSource(S.i, ConstStream.c(0.8), OUT.i);
    pwm.setSource(FREQUENCY.i, event, FREQUENCY.i);
    dmul.setSource(IN_IMAG.i, filterEnv, OUT.i);
    dmul.setSource(IN.i, ConstStream.c(0.4), OUT.i);
    dpl.setSource(IN_IMAG.i, dmul, OUT.i);
    dpl.setSource(IN.i, ConstStream.c(0.5), OUT.i);
    pwm.setSource(DUTYCYCLE.i, dpl2, OUT.i);
    dpl2.setSource(IN.i, dpl, OUT.i);
    dpl2.setSource(IN_IMAG.i, dmul2, OUT.i);
    dmul2.setSource(IN_IMAG.i, lfo, OUT.i);
    dmul2.setSource(IN.i, ConstStream.c(0.2), OUT.i);
    svf.setSource(IN.i, hp, HP.i);
View Full Code Here


    globalParameters.setSampleRate(44100);
    ProcessElement env1=new Envelope();
    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(gate);
    Scale s=new WellTemperedScale();
    ConstStream[] notes=new ConstStream[]{
    new ConstStream(s.getValueFor("c#")),
    new ConstStream(s.getValueFor("e")),
    new ConstStream(s.getValueFor("A")),
    };
    ConstStream beats=new ConstStream(1); // 60 bpm in beats per second
    ConstStream A=new ConstStream(0.13);
    ConstStream D=new ConstStream(1.25);
    ConstStream S=ConstStream.c(0.25);
    ConstStream R=new ConstStream(2.55);
    ConstStream A2=new ConstStream(0.05);
    ConstStream D2=new ConstStream(2.25);
    ConstStream S2=ConstStream.c(0.25);
    ConstStream R2=new ConstStream(1.55);
    ComplexTable<Double> ct=new ComplexTable<Double>();
    ct.put(0.0, 0);
    ct.put(0.25, 1);
    ct.put(1.0, 0);
    ct.put(1.25, -1);
    ct.put(2.0, 0);
    // ct.finish();
    ProcessElement si=new Sine();
    Mixer fmix=new Mixer();
    mul fmul=new mul();
    mul fmul2=new mul();
    Mixer fmix2=new Mixer();
    Envelope fmenv=new Envelope();
    CustomWaveform ts=new CustomWaveform();

    ts.setTable(ct);
    ProcessElement cw=new CustomWave();
    advancerRegistry.registerAdvancer(cw);
    advancerRegistry.registerAdvancer(si);
    advancerRegistry.registerAdvancer(mix);
    advancerRegistry.registerAdvancer(fmix);
    advancerRegistry.registerAdvancer(fmix2);
    advancerRegistry.registerAdvancer(fmul2);
    advancerRegistry.registerAdvancer(fmenv);
    advancerRegistry.registerAdvancer(fmul);
    advancerRegistry.registerAdvancer(env1);
    try{
    mix.setSource(-1, cw, 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);
    cw.setSource(StandardParameters.FREQUENCY.i, fmix2, StandardParameters.OUT.i);
    cw.setSource(StandardParameters.TABLE.i, ts, StandardParameters.TABLE.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);
    fmenv.setSource(StandardParameters.A.i, A2, StandardParameters.OUT.i);
    fmenv.setSource(StandardParameters.D.i, D2, StandardParameters.OUT.i);
    fmenv.setSource(StandardParameters.S.i, S2, StandardParameters.OUT.i);
    fmenv.setSource(StandardParameters.R.i, R2, StandardParameters.OUT.i);
    fmenv.setSource(StandardParameters.SYNC.i, gate, StandardParameters.OUT.i);
    si.setSource(StandardParameters.FREQUENCY.i, fmix, StandardParameters.OUT.i);
    fmix.setSource(-1, fmenv, StandardParameters.OUT.i);
    fmix.setSource(-1, new ConstStream(-10), StandardParameters.OUT.i);
    fmix.setSource(-2, new ConstStream(10), StandardParameters.OUT.i);
    fmix2.setSource(-1, si, StandardParameters.OUT.i);
    fmix2.setSource(-1, fmenv, StandardParameters.OUT.i);
    fmix2.setSource(-1, new ConstStream(12), StandardParameters.OUT.i);
    fmul.setSource(StandardParameters.IN.i, new ConstStream(s.getValueFor("A")),
      StandardParameters.OUT.i);
    fmul.setSource(StandardParameters.IN_IMAG.i, new ConstStream(1), StandardParameters.OUT.i);
    fmix2.setSource(-2, fmul, 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;
    int sampleCounter=0;
    long starttime=System.currentTimeMillis();
    //for(; time.getValue(StandardParameters.OUT.i)<10.5;){ // as long as we're testing the file buffering in emulation, we must take the time
    for(; time.getValue(StandardParameters.OUT.i)<1.0;){ // as long as we're testing coding in emulation, we don't need full buffers
    advancerRegistry.advanceAll();
    sampleCounter++;
    // 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){
      fmul.setSource(StandardParameters.IN.i, notes[lastIndex], StandardParameters.OUT.i);
      lastIndex=(lastIndex+1)%notes.length;
    }
    lastVal=gate.getValue(StandardParameters.OUT.i);
    if((sampleCounter%1000)==0)
      System.out.println("calculated "+sampleCounter+" samples in "+(System.currentTimeMillis()-starttime)/1000+" seconds");
    }
    try{
    File f=new File("monkeytest.wav");
View Full Code Here

TOP

Related Classes of de.maramuse.soundcomp.generator.PWM

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.