Package de.maramuse.soundcomp.process

Examples of de.maramuse.soundcomp.process.Event


  // the sound generating object is not instantiated per note, as some instruments (cymbals, hihat) are
  // strictly monophonous, and the two hihat sounds even mutually exclusive.
  // therefore a "shell object" for each note acts as proxy to the singleton generator and handles timing
  // and mutual exclusion, whereas the singleton generators handle sound generation
  private Event createDrumNote(Drumnote note, double ts, double volume) {
  Event event;
  //boolean hihat_=false;
  double lvolume=volume*totalVolume;
  switch(note){
    case BASS_1:
    event=getBassDrum(0.7*lvolume, 0.6*lvolume);
    event.setFrequency(70);
    break;
    case BASS_2:
    event=getBassDrum(0.6*lvolume, 0.7*lvolume);
    event.setFrequency(77);
    break;
    case CRASH:
    event=getCrash(0.2*lvolume, 0.7*lvolume);
    break;
    case HIHAT_CLOSED:
    // if a hihat is hit in closed state, it is not permissible for
    // the hihat to still sound on as open. of course, this is an
    // extremely basic simulation - the process of closing the sounding
    // hihat is completely ignored.
    event=getHHClosed(0.5*lvolume, 0.5*lvolume);
    //hihat_=true;
    break;
    case HIHAT_OPEN:
    event=getHHOpen(0.5*lvolume, 0.5*lvolume);
    //hihat_=true;
    break;
    case RIDE:
    event=getRide(0.8*lvolume, 0.2*lvolume);
    break;
    default: // which case should that be?
    case SNARE:
    event=getSnare(0.45*lvolume, 0.55*lvolume);
    break;
    case TOM_HI:
    event=getTom(0.4*lvolume, 0.6*lvolume);
    event.setFrequency(130);
    break;
    case TOM_HIMID:
    event=getTom(0.5*lvolume, 0.5*lvolume);
    event.setFrequency(120);
    break;
    case TOM_LOMID:
    event=getTom(0.6*lvolume, 0.4*lvolume);
    event.setFrequency(110);
    break;
    case TOM_LO:
    event=getTom(0.7*lvolume, 0.3*lvolume);
    event.setFrequency(90);
    break;
  }
  event.setStarttime(ts);
  event.setPitch(Double.NaN);
  NoteGateOffEvent nge=new NoteGateOffEvent(event, ts+event.getDuration(), advancerRegistry);
  NoteBirthEvent nbe=new NoteBirthEvent(event, ts, advancerRegistry);
  NoteGateOnEvent ng1e=new NoteGateOnEvent(event, ts+1.01/globalParameters.getSampleRate(),
    advancerRegistry);
  NoteDeathEvent nde=new NoteDeathEvent(event, ts+event.getLivetime(), advancerRegistry);
  advancerRegistry.addEvent(nbe, event);
  advancerRegistry.addEvent(nge, event);
  advancerRegistry.addEvent(ng1e, event);
  advancerRegistry.addEvent(nde, event);
  return event;
View Full Code Here


  return note16/16.0/tempo;
  }

  private Event getSnare(double left, double right) {
  // create the snare drum from a sampled file
  Event snare=new Event();
  mul m3=new mul(), m4=new mul();
  InputFile ifsn=new InputFile("javasrc/de/maramuse/soundcomp/test/testfiles/sd.wav");
  snare.setAbstractName("snare");
  snare.setInstanceName("snare"+nameCount++);
  snare.setDuration(0.025);
  snare.setLivetime(1.25);
  snare.addElement(ifsn);
  try{
    m3.setSource(IN_IMAG.i, ifsn, OUT.i);
    m3.setSource(IN.i, ConstStream.c(left), OUT.i);
    m4.setSource(IN_IMAG.i, ifsn, OUT_IMAG.i);
    m4.setSource(IN.i, ConstStream.c(right), OUT.i);
  }catch(Exception ex){
    ex.printStackTrace();
  }
  snare.addElement(m3);
  snare.addElement(m4);
  snare.addMixerConnection(drums_L, m3, OUT.i);
  snare.addMixerConnection(drums_R, m4, OUT.i);
  return snare;
  }
View Full Code Here

  private Event getCrash(double left, double right) {
  // create the crash cymbal
  // TODO a crash cymbal, when hit multiple times, does not create overlaying sounds, the older sound
  // would need to be stopped similar to the hihat handling
  Event crash=new Event();
  InputFile ifsn=new InputFile("javasrc/de/maramuse/soundcomp/test/testfiles/crash.wav");
  crash.setDuration(0.025);
  crash.setLivetime(5.25);
  crash.addElement(ifsn);
  crash.setAbstractName("crash");
  crash.setInstanceName("crash"+nameCount++);
  return crash;
  }
View Full Code Here

  private Event getRide(double left, double right) {
  // create the ride cymbal
  // TODO a ride cymbal is played in multiple, clearly distinct ways
  // TODO a ride cymbal, when hit multiple times, does not create simple overlaying sounds, the older sound
  // would need to be influenced on a second hit depending on what kind of hit occurs
  Event ride=new Event();
  InputFile ifsn=new InputFile("javasrc/de/maramuse/soundcomp/test/testfiles/ride.wav");
  ride.setDuration(0.025);
  ride.setLivetime(5.25);
  ride.addElement(ifsn);
  ride.setAbstractName("ride");
  ride.setInstanceName("ride"+nameCount++);
  return ride;
  }
View Full Code Here

  private Event getTom(double left, double right) {
  // create a tom.
  // a pitched percussive sound with decreasing pitch and harmonics that fade out
  // faster than the fundamental.
  Event tom=new Event();
  ProcessElement ev=new Envelope();
  ProcessElement m=new mul();
  ProcessElement m1=new mul();
  ProcessElement m2=new mul();
  ProcessElement p1=new plus();
  ProcessElement p2=new plus();
  ProcessElement st=new SawTooth();
  try{
    ev.setSource(SYNC.i, tom, GATE.i);
    ev.setSource(A.i, ConstStream.c(0.01), OUT.i);
    ev.setSource(D.i, ConstStream.c(1), OUT.i);
    ev.setSource(R.i, ConstStream.c(1), OUT.i);
    ev.setSource(S.i, ConstStream.c(0), OUT.i);
    m.setSource(IN_IMAG.i, ev, OUT.i);
    m.setSource(IN.i, st, OUT.i);
    m1.setSource(IN_IMAG.i, ev, OUT.i);
    m1.setSource(IN.i, ConstStream.c(20), OUT.i);
    p1.setSource(IN_IMAG.i, m1, OUT.i);
    p1.setSource(IN.i, ConstStream.c(150), OUT.i);
    st.setSource(FREQUENCY.i, p1, OUT.i);
    p2.setSource(IN_IMAG.i, m2, OUT.i);
    m2.setSource(IN.i, ConstStream.c(0.3), OUT.i);
    m2.setSource(IN_IMAG.i, ev, OUT.i);
    p2.setSource(IN.i, ConstStream.c(0.5), OUT.i);
    st.setSource(DUTYCYCLE.i, p2, OUT.i);
  }catch(UnknownConnectionException e){
    e.printStackTrace();
  }catch(TypeMismatchException e){
    e.printStackTrace();
  }
  tom.addElement(ev);
  tom.addElement(m);
  tom.addElement(m1);
  tom.addElement(m2);
  tom.addElement(p1);
  tom.addElement(p2);
  tom.addElement(st);
  tom.setAbstractName("tom");
  tom.setInstanceName("tom"+nameCount++);

  return tom;
  }
View Full Code Here

  return tom;
  }

  private Event getBassDrum(double left, double right) {
  Event bd=new Event();
  bd.setAbstractName("bass drum");
  bd.setInstanceName("bass drum"+nameCount++);
  bd.setDuration(0.1);
  bd.setLivetime(0.5);
  ProcessElement ev=new Envelope();
  ProcessElement m=new mul();
  ProcessElement m1=new mul();
  ProcessElement m2=new mul();
  ProcessElement p1=new plus();
  ProcessElement p2=new plus();
  ProcessElement st=new SawTooth();
  ProcessElement m3=new mul();
  ProcessElement m4=new mul();
  try{
    ev.setSource(SYNC.i, bd, GATE.i);
    ev.setSource(A.i, ConstStream.c(0.01), OUT.i);
    ev.setSource(D.i, ConstStream.c(0.7), OUT.i);
    ev.setSource(R.i, ConstStream.c(0.7), OUT.i);
    ev.setSource(S.i, ConstStream.c(0), OUT.i);
    m.setSource(IN_IMAG.i, ev, OUT.i);
    m.setSource(IN.i, st, OUT.i);
    m1.setSource(IN_IMAG.i, ev, OUT.i);
    m1.setSource(IN.i, ConstStream.c(20), OUT.i);
    p1.setSource(IN_IMAG.i, m1, OUT.i);
    p1.setSource(IN.i, ConstStream.c(50), OUT.i);
    st.setSource(FREQUENCY.i, p1, OUT.i);
    p2.setSource(IN_IMAG.i, m2, OUT.i);
    m2.setSource(IN.i, ConstStream.c(0.3), OUT.i);
    m2.setSource(IN_IMAG.i, ev, OUT.i);
    p2.setSource(IN.i, ConstStream.c(0.5), OUT.i);
    st.setSource(DUTYCYCLE.i, p2, OUT.i);
    bd.addElement(ev);
    bd.addElement(m);
    bd.addElement(m1);
    bd.addElement(m2);
    bd.addElement(p1);
    bd.addElement(p2);
    bd.addElement(st);
    bd.addElement(m3);
    bd.addElement(m4);
    m3.setSource(IN_IMAG.i, m, OUT.i);
    m3.setSource(IN.i, ConstStream.c(left), OUT.i);
    m4.setSource(IN_IMAG.i, m, OUT.i);
    m4.setSource(IN.i, ConstStream.c(right), OUT.i);
  }catch(UnknownConnectionException e){
    e.printStackTrace();
  }catch(TypeMismatchException e){
    e.printStackTrace();
  }
  bd.addMixerConnection(drums_L, m3, OUT.i);
  bd.addMixerConnection(drums_R, m4, OUT.i);
  return bd;
  }
View Full Code Here

  }

  private Event getHHOpen(double left, double right) {
  // create the open hihat from a sampled file
  synchronized(hihatsync){
    Event hihat_open=new Event();
    InputFile ifho=new InputFile("javasrc/de/maramuse/soundcomp/test/testfiles/hh-o.wav");
    hihat_open.setDuration(0.025);
    hihat_open.setLivetime(1.25);
    hihat_open.addElement(ifho);
    /*
     * we would have to disregister the open hihat when it is hit closed, but not at creation time, rather at run
     * time. if(hihat!=null){ hihat.die(); drums_L.disconnect(hihatcl); drums_R.disconnect(hihatcr); }
     */
    hihat_open.setAbstractName("hihat_open");
    hihat_open.setInstanceName("hihat_open"+nameCount++);
    return hihat_open;
  }
  }
View Full Code Here

  }

  private Event getHHClosed(double left, double right) {
  // create the closed hihat from a sampled file
  synchronized(hihatsync){
    Event hihat_closed=new Event();
    mul m3=new mul(), m4=new mul();
    InputFile ifhc=new InputFile("javasrc/de/maramuse/soundcomp/test/testfiles/hh-c.wav");
    ifhc.setAbstractName("ifhc");
    ifhc.setInstanceName("ifhc"+nameCount++);
    hihat_closed.setDuration(0.025);
    hihat_closed.setLivetime(0.5);
    /*
     * we would have to disregister the open hihat when it is hit closed, but not at creation time, rather at run
     * time. if(hihat!=null){ hihat.die(); drums_L.disconnect(hihatcl); drums_R.disconnect(hihatcr); }
     */
    hihat_closed.setAbstractName("hihat_closed");
    hihat_closed.setInstanceName("hihat_closed"+nameCount++);
    try{
    m3.setSource(IN_IMAG.i, ifhc, OUT.i);
    m3.setSource(IN.i, ConstStream.c(left), OUT.i);
    m4.setSource(IN_IMAG.i, ifhc, OUT.i);
    m4.setSource(IN.i, ConstStream.c(right), OUT.i);
    }catch(Exception ex){
    ex.printStackTrace();
    }
    hihat_closed.addElement(ifhc);
    hihat_closed.addElement(m3);
    hihat_closed.addElement(m4);
    hihat_closed.addMixerConnection(drums_L, m3, OUT.i);
    hihat_closed.addMixerConnection(drums_R, m4, OUT.i);
    return hihat_closed;
  }
  }
View Full Code Here

  // create one note instance for the solo instrument
  private Event createSoloNote(note n, double volume) {
  double effvol=volume;
  if(n.beats<1.0/8)
    effvol*=0.7;
  Event event=new Event();
  SawTooth st=new SawTooth();
  WhiteNoise pn=new WhiteNoise();
  mul noisevol=new mul();
  mul sawvol=new mul();
  Envelope noiseenv=new Envelope();
  Envelope sawenv=new Envelope();
  Sine dclfo1=new Sine();
  Sine dclfo2=new Sine();
  mul lfomul1=new mul(), lfomul2=new mul();
  mul lfomul1a=new mul(), lfomul2a=new mul();
  plus lfopl1=new plus(), lfopl2=new plus();
  Mixer out=new Mixer();
  try{
    lfomul1.setSource(IN_IMAG.i, ConstStream.c(n.frequency), OUT.i);
    lfomul1.setSource(IN.i, ConstStream.c(0.00033), OUT.i);
    dclfo1.setSource(FREQUENCY.i, lfomul1, OUT.i);
    lfomul1a.setSource(IN_IMAG.i, dclfo1, OUT.i);
    lfomul1a.setSource(IN.i, ConstStream.c(0.333), OUT.i);
    lfopl1.setSource(IN_IMAG.i, lfomul1a, OUT.i);
    lfopl1.setSource(IN.i, ConstStream.c(0.5), OUT.i);
    lfomul2.setSource(IN_IMAG.i, ConstStream.c(n.frequency), OUT.i);
    lfomul2.setSource(IN.i, ConstStream.c(0.00013), OUT.i);
    dclfo2.setSource(FREQUENCY.i, lfomul2, OUT.i);
    lfomul2a.setSource(IN_IMAG.i, dclfo2, OUT.i);
    lfomul2a.setSource(IN.i, ConstStream.c(0.133), OUT.i);
    lfopl2.setSource(IN_IMAG.i, lfomul2a, OUT.i);
    lfopl2.setSource(IN.i, lfopl1, OUT.i);
    st.setSource(FREQUENCY.i, ConstStream.c(n.frequency), OUT.i);
    st.setSource(DUTYCYCLE.i, lfopl2, OUT.i);
    out.setSource(-1, sawvol, OUT.i);
    out.setSource(-1, ConstStream.c(0.5*effvol), OUT.i);
    out.setSource(-2, noisevol, OUT.i);
    out.setSource(-2, ConstStream.c(0.4*effvol), OUT.i);
    sawvol.setSource(IN_IMAG.i, st, OUT.i);
    noisevol.setSource(IN_IMAG.i, pn, OUT.i);
    sawvol.setSource(IN.i, sawenv, OUT.i);
    noisevol.setSource(IN.i, noiseenv, OUT.i);
    noiseenv.setSource(SYNC.i, event, GATE.i);
    sawenv.setSource(SYNC.i, event, GATE.i);
    noiseenv.setSource(A.i, ConstStream.c(0.02), OUT.i);
    noiseenv.setSource(D.i, ConstStream.c(0.23), OUT.i);
    noiseenv.setSource(S.i, ConstStream.c(0.05), OUT.i);
    sawenv.setSource(A.i, ConstStream.c(0.02), OUT.i);
    sawenv.setSource(D.i, ConstStream.c(1), OUT.i);
    if(n.legato){
    sawenv.setSource(S.i, ConstStream.c(0.3), OUT.i);
    sawenv.setSource(R.i, ConstStream.c(1), OUT.i);
    noiseenv.setSource(R.i, ConstStream.c(1), OUT.i);
    }else{
    sawenv.setSource(S.i, ConstStream.c(0.2), OUT.i);
    sawenv.setSource(R.i, ConstStream.c(0.01), OUT.i);
    noiseenv.setSource(R.i, ConstStream.c(0.01), OUT.i);
    }
  }catch(UnknownConnectionException e){
    e.printStackTrace();
  }catch(TypeMismatchException e){
    e.printStackTrace();
  }
  double ts=getTimestamp(n.startbeat);
  event.setStarttime(ts);
  if(n.legato){
    event.setDuration(n.beats/16/tempo);
  }else{
    event.setDuration(Math.min(n.beats, 0.5)/16/tempo*0.6);
  }
  event.setLivetime(event.getDuration()+1);
  event.setFrequency(n.frequency);
  // System.out.println("solo note "+n.frequency+"Hz at "+ts+" for "+event.getDuration()+"/"+event.getLivetime()+"(beats:"+n.beats+","+tempo+")");
  event.setPitch(n.pitch);
  event.addElement(st);
  event.addElement(pn);
  event.addElement(noisevol);
  event.addElement(noiseenv);
  event.addElement(sawvol);
  event.addElement(sawenv);
  event.addElement(out);
  event.addElement(dclfo1);
  event.addElement(dclfo2);
  event.addElement(lfomul1);
  event.addElement(lfomul2);
  event.addElement(lfomul1a);
  event.addElement(lfomul2a);
  event.addElement(lfopl1);
  event.addElement(lfopl2);
  NoteGateOffEvent ng0e=new NoteGateOffEvent(event, ts+event.getDuration(), advancerRegistry);
  NoteBirthEvent nbe=new NoteBirthEvent(event, ts, advancerRegistry);
  NoteGateOnEvent ng1e=new NoteGateOnEvent(event, ts+1.01/globalParameters.getSampleRate(),
    advancerRegistry);
  NoteDeathEvent nde=new NoteDeathEvent(event, ts+event.getLivetime(), advancerRegistry);
  event.addMixerConnection(solo_L, out, OUT.i);
  event.addMixerConnection(solo_R, out, OUT.i);
  advancerRegistry.addEvent(nbe.getTimestamp(), nbe, event);
  advancerRegistry.addEvent(ng0e.getTimestamp(), ng0e, event);
  advancerRegistry.addEvent(ng1e.getTimestamp(), ng1e, event);
  advancerRegistry.addEvent(nde.getTimestamp(), nde, event);
  return event;
View Full Code Here

  }

  // create one note instance for the bass instrument
  private Event createBassNote(String note, double ts, double durationGate, double durationTotal,
                 double volume) {
  Event event=new Event();
  event.setAbstractName("bass");
  event.setInstanceName("bass"+nameCount++);
  event.setStarttime(ts);
  event.setDuration(durationGate);
  event.setLivetime(durationTotal);
  event.setFrequency(scale.getValueFor(note));
  event.setPitch(scale.getPitch(note));
  SawTooth st=new SawTooth();
  st.setAbstractName("bass-st");
  st.setInstanceName("bass-st"+nameCount++);
  Envelope filterEnv=new Envelope();
  Envelope volumeEnv=new Envelope();
  StateVariableFilter svf=new StateVariableFilter();
  mul mfilfreq=new mul(), mfilfreq2=new mul();
  plus pfilfreq=new plus();
  mul mout=new mul();
  mul mvol=new mul();
  try{
    filterEnv.setSource(SYNC.i, event, GATE.i);
    filterEnv.setSource(A.i, ConstStream.c(0.2), OUT.i);
    filterEnv.setSource(D.i, ConstStream.c(0.4), OUT.i);
    filterEnv.setSource(R.i, ConstStream.c(0.4), 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.1), OUT.i);
    volumeEnv.setSource(D.i, ConstStream.c(0.3), OUT.i);
    volumeEnv.setSource(R.i, ConstStream.c(0.3), OUT.i);
    volumeEnv.setSource(S.i, ConstStream.c(0.3), OUT.i);
    st.setSource(FREQUENCY.i, event, FREQUENCY.i);
    svf.setSource(IN.i, st, OUT.i);
    mfilfreq.setSource(IN.i, filterEnv, OUT.i);
    mfilfreq.setSource(IN_IMAG.i, ConstStream.c(4), OUT.i);
    mfilfreq2.setSource(IN.i, mfilfreq, OUT.i);
    mfilfreq2.setSource(IN_IMAG.i, event, FREQUENCY.i);
    pfilfreq.setSource(IN_IMAG.i, mfilfreq2, OUT.i);
    pfilfreq.setSource(IN.i, event, FREQUENCY.i);
    svf.setSource(FREQUENCY.i, pfilfreq, OUT.i);
    svf.setSource(Q.i, ConstStream.c(0.9), OUT.i);
    mout.setSource(IN_IMAG.i, volumeEnv, OUT.i);
    mout.setSource(IN.i, mvol, OUT.i);
    mvol.setSource(IN_IMAG.i, svf, LP.i);
    mvol.setSource(IN.i, ConstStream.c(volume), OUT.i);
  }catch(UnknownConnectionException e){
    e.printStackTrace();
  }catch(TypeMismatchException e){
    e.printStackTrace();
  }
  event.addElement(st);
  event.addElement(filterEnv);
  event.addElement(volumeEnv);
  event.addElement(mout);
  event.addElement(mvol);
  event.addElement(svf);
  event.addElement(pfilfreq);
  event.addElement(mfilfreq);
  event.addElement(mfilfreq2);
  NoteGateOffEvent nge=new NoteGateOffEvent(event, ts+event.getDuration(), advancerRegistry);
  NoteBirthEvent nbe=new NoteBirthEvent(event, ts, advancerRegistry);
  NoteGateOnEvent ng1e=new NoteGateOnEvent(event, ts+1.01/globalParameters.getSampleRate(),
    advancerRegistry);
  NoteDeathEvent nde=new NoteDeathEvent(event, ts+event.getLivetime(), advancerRegistry);
  event.addMixerConnection(bass_L, mout, OUT.i);
  event.addMixerConnection(bass_R, mout, OUT.i);
  advancerRegistry.addEvent(nbe.getTimestamp(), nbe, event);
  advancerRegistry.addEvent(nge.getTimestamp(), nge, event);
  advancerRegistry.addEvent(ng1e.getTimestamp(), ng1e, event);
  advancerRegistry.addEvent(nde.getTimestamp(), nde, event);
  return event;
View Full Code Here

TOP

Related Classes of de.maramuse.soundcomp.process.Event

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.