Package de.maramuse.soundcomp.util

Examples of de.maramuse.soundcomp.util.AdvancerRegistry


   * test does not apparently fail, but the resulting file is still questionable
   * because the 6581 code is yet incomplete.
   */
  public void testSID() {
  try{
    AdvancerRegistry advancerRegistry=new AdvancerRegistry();
    advancerRegistry.clear();
    globalParameters.setSampleRate(44100);
    OutputFile ws=new OutputFile(1);
    int waveform=0;
    double freq=0.01;
    double lasttime=0;
    boolean gate=false;
    ProcessElement sid=new SID6581();
    // set any parameters you like. SID6581 treats unset parameters as 0.
    // you may edit this template to test any features of the SID6581.
    sid.setSource(VOL.i, ConstStream.c(0.8), OUT.i);
    sid.setSource(SQUA1.i, ConstStream.c(1), OUT.i);
    sid.setSource(DUTYCYCLE1.i, ConstStream.c(.75), OUT.i);
    sid.setSource(RING1.i, ConstStream.c(1), OUT.i);
    sid.setSource(SYNC1.i, ConstStream.c(1), OUT.i);
    sid.setSource(A1.i, ConstStream.c(5/15.0), OUT.i);
    sid.setSource(D1.i, ConstStream.c(8/15.0), OUT.i);
    sid.setSource(S1.i, ConstStream.c(9/15.0), OUT.i);
    sid.setSource(R1.i, ConstStream.c(3/15.0), OUT.i);
    ProcessElement m=new mul();
    // multiply the output with 0.05 to reduce signal volume, OutputFile expects abs(signal)<1
    m.setSource(IN_IMAG.i, ConstStream.c(0.95), OUT.i);
    m.setSource(IN.i, sid, OUT.i);
    advancerRegistry.registerAdvancer(ws);
    ws.setSource(0, m, OUT.i);
    advancerRegistry.registerAdvancer(sid);
    for(double time=0; time<10; time+=1/globalParameters.getSampleRate()){
    if(time>lasttime){
      gate=!gate;
      sid.setSource(GATE1.i, ConstStream.c(gate), OUT.i);
      lasttime+=0.3;
      if(gate){
        waveform++;
        waveform%=3;
        sid.setSource(SQUA1.i, ConstStream.c(waveform==0), OUT.i);
        sid.setSource(TRIA1.i, ConstStream.c(waveform==1), OUT.i);
        sid.setSource(SAWT1.i, ConstStream.c(waveform==2), OUT.i);
      freq*=Math.exp(Math.log(2)/12d);
      sid.setSource(StandardParameters.FREQUENCY1.i, new ConstStream(freq), StandardParameters.OUT.i);
      sid.setSource(StandardParameters.FREQUENCY3.i, new ConstStream(freq/2), StandardParameters.OUT.i);
      }
    }
    advancerRegistry.advanceAll();
    }
    try{
    File f=new File("SID6581test.wav");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), 4096);
    ws.setFormat(FileFormats.FMT_WAVE_S16);
    ws.write(fos);
    fos.close();
    }catch(IOException ex){
    fail(ex.getMessage());
    }
    advancerRegistry.unregisterAdvancer(ws);
    advancerRegistry.unregisterAdvancer(sid);
    NativeObjects.unregisterNativeObject(ws);
    NativeObjects.unregisterNativeObject(sid);
  }catch(Exception ex){
    fail(ex.getMessage());
  }
View Full Code Here


   * Creates a sawtooth signal and a "duty cycle modulated cosine", both with constant pitch "a2" (880Hz). Both signals
   * are subject to a 50Hz sync with a varying sync phase.
   */
  public void testTS1() {
  try{
    AdvancerRegistry advancerRegistry=new AdvancerRegistry();
    advancerRegistry.clear();
    globalParameters.setSampleRate(44100);
    ProcessElement pe=new SawTooth();
    ProcessElement sync=new PWM();
    ProcessElement syncphase=new UnitySawTooth();
    sync.setSource(DUTYCYCLE.i, ConstStream.c(0.0015), OUT.i);
    sync.setSource(FREQUENCY.i, ConstStream.c(50), OUT.i);
    syncphase.setSource(FREQUENCY.i, ConstStream.c(1), OUT.i);
    advancerRegistry.registerAdvancer(pe);
    WellTemperedScale sc=new WellTemperedScale();
    NamedSource freq=ConstStream.c(sc.getValueFor("a2"));
    try{
    pe.setSource(FREQUENCY.i, freq, OUT.i);
    pe.setSource(SYNC.i, sync, OUT.i);
    pe.setSource(SYNCPHASE.i, syncphase, OUT.i);
    }catch(Exception te){
    fail(te.getMessage());
    }
    OutputFile ws=new OutputFile(1);
    ProcessElement m=new mul();
    m.setSource(IN_IMAG.i, pe, OUT.i);
    m.setSource(IN.i, ConstStream.c(0.9995), OUT.i);
    advancerRegistry.registerAdvancer(ws);
    advancerRegistry.registerAdvancer(sync);
    advancerRegistry.registerAdvancer(syncphase);
    ws.setSource(0, m, OUT.i);
    advancerRegistry.registerAdvancer(m);
    for(double time=0; time<10; time+=1/globalParameters.getSampleRate()){
    advancerRegistry.advanceAll();
    }
    try{
    File f=new File("880HzSyncSaw.wav");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
    ws.setFormat(FileFormats.FMT_WAVE_S16);
    ws.write(fos);
    fos.close();
    }catch(IOException ex){
    fail(ex.getMessage());
    }
    advancerRegistry.unregisterAdvancer(pe);
    advancerRegistry.unregisterAdvancer(ws);
    advancerRegistry.unregisterAdvancer(m);
    NativeObjects.unregisterNativeObject(pe);
    NativeObjects.unregisterNativeObject(ws);
    NativeObjects.unregisterNativeObject(m);
    pe=new Cosine();
    advancerRegistry.registerAdvancer(pe);
    ws=new OutputFile(1);
    advancerRegistry.registerAdvancer(ws);
    m.setSource(IN_IMAG.i, pe, OUT.i);
    m.setSource(IN.i, ConstStream.c(0.5), OUT.i);
    ws.setSource(0, m, OUT.i);
    try{
    pe.setSource(FREQUENCY.i, freq, OUT.i);
    }catch(Exception te){
    fail(te.getMessage());
    }
    for(double time=0; time<10; time+=1/globalParameters.getSampleRate()){
    advancerRegistry.advanceAll();
    }
    try{
    File f=new File("880HzSine.wav");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
    ws.setFormat(FileFormats.FMT_WAVE_S16);
    ws.write(fos);
    fos.close();
    }catch(IOException ex){
    fail(ex.getMessage());
    }
    advancerRegistry.unregisterAdvancer(pe);
    NativeObjects.unregisterNativeObject(pe);
    NativeObjects.unregisterNativeObject(ws);
    pe=new Cosine();
    ProcessElement pe2=new Cosine();
    ProcessElement mix=new Mixer();
    advancerRegistry.registerAdvancer(pe2);
    advancerRegistry.registerAdvancer(pe);
    advancerRegistry.registerAdvancer(mix);
    mix.setSource(-1, pe2, StandardParameters.OUT.i);
    mix.setSource(-1, new ConstStream(0.5), StandardParameters.OUT.i);
    mix.setSource(-2, new ConstStream(0.5), StandardParameters.OUT.i);
    ws=new OutputFile(1);
    advancerRegistry.registerAdvancer(ws);
    try{
    pe2.setSource(StandardParameters.FREQUENCY.i, new ConstStream(1), StandardParameters.OUT.i);
    pe.setSource(StandardParameters.FREQUENCY.i, freq, StandardParameters.OUT.i);
    pe.setSource(StandardParameters.DUTYCYCLE.i, mix, StandardParameters.OUT.i);
    m.setSource(StandardParameters.IN_IMAG.i, pe, StandardParameters.OUT.i);
    m.setSource(StandardParameters.IN.i, new ConstStream(0.5), StandardParameters.OUT.i);
    ws.setSource(0, m, OUT.i);
    }catch(Exception te){
    fail(te.getMessage());
    }
    for(double time=0; time<10; time+=1/globalParameters.getSampleRate()){
    advancerRegistry.advanceAll();
    }
    try{
    File f=new File("880HzSineMod.wav");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
    ws.setFormat(FileFormats.FMT_WAVE_S16);
    ws.write(fos);
    fos.close();
    }catch(IOException ex){
    fail(ex.getMessage());
    }
    advancerRegistry.clear();
    NativeObjects.unregisterNativeObject(pe);
    NativeObjects.unregisterNativeObject(ws);
    NativeObjects.unregisterNativeObject(pe2);
    NativeObjects.unregisterNativeObject(mix);
  }catch(Exception ex){
View Full Code Here

   * format) - as 8 bit fixed PCM stream (original windows .wav format) - as 32 bit floating point stream - as 64 bit
   * floating point stream and in other supported file formats.
   */
  public void testTS2() {
  try{
    AdvancerRegistry advancerRegistry=new AdvancerRegistry();
    advancerRegistry.clear();
    globalParameters.setSampleRate(44100);
    ProcessElement cos=new Cosine();
    ProcessElement hi=new PseudoHilbert();
    advancerRegistry.registerAdvancer(cos);
    advancerRegistry.registerAdvancer(hi);
    Time time=new Time(null);
    Mixer mix=new Mixer();
    advancerRegistry.registerAdvancer(mix);
    // ConstStream cs1=new ConstStream(Math.log(10));
    advancerRegistry.registerAdvancer(time);
    BasicMath _exp=new exp();
    advancerRegistry.registerAdvancer(_exp);
    NamedSource cs=new ConstStream(Math.log(10));
    try{
    _exp.setSource(StandardParameters.IN.i, mix, StandardParameters.OUT.i);
    mix.setSource(-2, cs, StandardParameters.OUT.i);
    mix.setSource(-1, cs, StandardParameters.OUT.i);
    mix.setSource(-1, time, StandardParameters.OUT.i);
    cos.setSource(StandardParameters.FREQUENCY.i, _exp, StandardParameters.OUT.i);
    hi.setSource(StandardParameters.IN.i, cos, StandardParameters.OUT.i);
    }catch(Exception te){
    fail(te.getMessage());
    }
    OutputFile ws=new OutputFile(2);
    mul m1=new mul();
    mul m2=new mul();
    ws.setSource(0, m1, OUT.i);
    ws.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, hi, OUT.i);
    m2.setSource(IN.i, hi, OUT_IMAG.i);
    advancerRegistry.registerAdvancer(ws);
    for(double t=0; t<3; t+=1/globalParameters.getSampleRate()){
    advancerRegistry.advanceAll();
    // ws.getChannel(0).add(0.5*hi.getValue(StandardParameters.OUT.i));
    // ws.getChannel(1).add(0.5*hi.getValue(StandardParameters.OUT_IMAG.i));
    }
    try{
    File f=new File("hilbertsweep_u8.wav");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
    ws.setFormat(FileFormats.FMT_WAVE_U8);
    ws.write(fos);
    fos.close();
    }catch(IOException ex){
    fail(ex.getMessage());
    }
    try{
    File f=new File("hilbertsweep_i16.wav");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
    ws.setFormat(FileFormats.FMT_WAVE_S16);
    ws.write(fos);
    fos.close();
    }catch(IOException ex){
    fail(ex.getMessage());
    }
    try{
    File f=new File("hilbertsweep_d.wav");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
    ws.setFormat(FileFormats.FMT_WAVE_DOUBLE);
    ws.write(fos);
    fos.close();
    }catch(IOException ex){
    fail(ex.getMessage());
    }
    try{
    File f=new File("hilbertsweep_i32.wav");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
    ws.setFormat(FileFormats.FMT_WAVE_S32);
    ws.write(fos);
    fos.close();
    }catch(IOException ex){
    fail(ex.getMessage());
    }
    try{
    File f=new File("hilbertsweep_i24.wav");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
    ws.setFormat(FileFormats.FMT_WAVE_S24);
    ws.write(fos);
    fos.close();
    }catch(IOException ex){
    fail(ex.getMessage());
    }
    try{
    File f=new File("hilbertsweep_b.wav");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
    ws.setFormat(FileFormats.FMT_WAVE_U8);
    ws.write(fos);
    fos.close();
    }catch(IOException ex){
    fail(ex.getMessage());
    }
    try{
    File f=new File("hilbertsweep_f.wav");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
    ws.setFormat(FileFormats.FMT_WAVE_FLOAT);
    ws.write(fos);
    fos.close();
    }catch(IOException ex){
    fail(ex.getMessage());
    }
    try{
    File f=new File("hilbertsweep_m16.ape");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
    ws.setFormat(FileFormats.FMT_MONKEY_16);
    ws.write(fos);
    fos.close();
    }catch(IOException ex){
    fail(ex.getMessage());
    }
    try{
    File f=new File("hilbertsweep_m24.ape");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
    ws.setFormat(FileFormats.FMT_MONKEY_24);
    ws.write(fos);
    fos.close();
    }catch(IOException ex){
    fail(ex.getMessage());
    }
    try{
    File f=new File("hilbertsweep_m8.ape");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
    ws.setFormat(FileFormats.FMT_MONKEY_8);
    ws.write(fos);
    fos.close();
    }catch(IOException ex){
    fail(ex.getMessage());
    }
    try{
    File f=new File("hilbertsweep_f16.flac");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
    ws.setFormat(FileFormats.FMT_FLAC_RAW_16);
    ws.write(fos);
    fos.close();
    }catch(IOException ex){
    fail(ex.getMessage());
    }
    try{
    File f=new File("hilbertsweep_f16.ogg");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
    ws.setFormat(FileFormats.FMT_FLAC_OGG_16);
    ws.write(fos);
    fos.close();
    }catch(IOException ex){
    fail(ex.getMessage());
    }
    advancerRegistry.unregisterAdvancer(cos);
    advancerRegistry.unregisterAdvancer(hi);
    advancerRegistry.unregisterAdvancer(time);
    advancerRegistry.clear();
    NativeObjects.unregisterNativeObject(cos);
    NativeObjects.unregisterNativeObject(ws);
    NativeObjects.unregisterNativeObject(hi);
    NativeObjects.unregisterNativeObject(mix);
    NativeObjects.unregisterNativeObject(time);
View Full Code Here

   * Creates a frequency sweep cosine signal, starting below audible range. One channel is filtered by a parametric all
   * pass, then superposed.
   */
  public void testTS3a() {
  try{
    AdvancerRegistry advancerRegistry=new AdvancerRegistry();
    advancerRegistry.clear();
    globalParameters.setSampleRate(44100);
    ProcessElement cos=new Cosine();
    ProcessElement all=new ParametricAllPass();
    advancerRegistry.registerAdvancer(cos);
    advancerRegistry.registerAdvancer(all);
    Time time=new Time();
    Mixer mix=new Mixer();
    advancerRegistry.registerAdvancer(mix);
    advancerRegistry.registerAdvancer(time);
    BasicMath _exp=new exp();
    advancerRegistry.registerAdvancer(_exp);
    NamedSource cs=new ConstStream(Math.log(10));
    ConstStream cs2=new ConstStream(100);
    ConstStream cs3=new ConstStream(0.9);
    try{
    _exp.setSource(StandardParameters.IN.i, mix, StandardParameters.OUT.i);
    mix.setSource(-2, cs, StandardParameters.OUT.i);
    mix.setSource(-1, cs, StandardParameters.OUT.i);
    mix.setSource(-1, time, StandardParameters.OUT.i);
    cos.setSource(StandardParameters.FREQUENCY.i, _exp, StandardParameters.OUT.i);
    all.setSource(StandardParameters.IN.i, cos, StandardParameters.OUT.i);
    all.setSource(StandardParameters.FREQUENCY.i, cs2, StandardParameters.OUT.i);
    all.setSource(StandardParameters.Q.i, cs3, StandardParameters.OUT.i);
    }catch(Exception te){
    fail(te.getMessage());
    }
    OutputFile ws=new OutputFile(2);
    mul m1=new mul();
    mul m2=new mul();
    mul m3=new mul();
    // Mixer mix2=new Mixer();
    // mix2.setSource(-1, m1, OUT.i);
    // mix2.setSource(-1, new ConstStream(-0.6), OUT.i);
    // AdvancerRegistry.registerAdvancer(mix2);
    // mix2.setSource(-2, m2, OUT.i);
    // mix2.setSource(-2, new ConstStream(-0.3), OUT.i);
    m3.setSource(IN_IMAG.i, /* _exp */new ConstStream(10000d), OUT.i);
    m3.setSource(IN.i, new ConstStream(1d/10001d), OUT.i);
    ws.setSource(0, m1, OUT.i);
    ws.setSource(-1, m2, OUT.i);
    m2.setSource(IN_IMAG.i, ConstStream.c(0.3), OUT.i);
    m1.setSource(IN_IMAG.i, ConstStream.c(0.3), OUT.i);
    m1.setSource(IN.i, all, OUT.i);
    m2.setSource(IN.i, cos, OUT.i);
    advancerRegistry.registerAdvancer(ws);
    for(double t=0; t<3; t+=1/globalParameters.getSampleRate()){
    advancerRegistry.advanceAll();
    }
    try{
    File f=new File("allpasssweep.wav");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
    ws.setFormat(FileFormats.FMT_WAVE_S16);
    ws.write(fos);
    fos.close();
    }catch(IOException ex){
    fail(ex.getMessage());
    }
    advancerRegistry.unregisterAdvancer(cos);
    advancerRegistry.unregisterAdvancer(all);
    advancerRegistry.unregisterAdvancer(time);
    advancerRegistry.clear();
    NativeObjects.unregisterNativeObject(cos);
    NativeObjects.unregisterNativeObject(ws);
    NativeObjects.unregisterNativeObject(all);
    NativeObjects.unregisterNativeObject(mix);
    NativeObjects.unregisterNativeObject(time);
View Full Code Here

   * Creates a frequency sweep cosine signal, starting below audible range. One channel is frequency shifted against the
   * other by 30 Hz.
   */
  public void testTS3b() {
  try{
    AdvancerRegistry advancerRegistry=new AdvancerRegistry();
    advancerRegistry.clear();
    globalParameters.setSampleRate(44100);
    ProcessElement cos=new Cosine();
    ProcessElement fs=new FreqShift();
    advancerRegistry.registerAdvancer(cos);
    advancerRegistry.registerAdvancer(fs);
    Time time=new Time();
    Mixer mix=new Mixer();
    advancerRegistry.registerAdvancer(mix);
    advancerRegistry.registerAdvancer(time);
    BasicMath _exp=new exp();
    advancerRegistry.registerAdvancer(_exp);
    NamedSource cs=new ConstStream(Math.log(10));
    ConstStream cs2=new ConstStream(30);
    try{
    _exp.setSource(StandardParameters.IN.i, mix, StandardParameters.OUT.i);
    mix.setSource(-2, cs, StandardParameters.OUT.i);
    mix.setSource(-1, cs, StandardParameters.OUT.i);
    mix.setSource(-1, time, StandardParameters.OUT.i);
    cos.setSource(StandardParameters.FREQUENCY.i, _exp, StandardParameters.OUT.i);
    fs.setSource(StandardParameters.IN.i, cos, StandardParameters.OUT.i);
    fs.setSource(StandardParameters.FREQUENCY.i, cs2, StandardParameters.OUT.i);
    }catch(Exception te){
    fail(te.getMessage());
    }
    OutputFile ws=new OutputFile(2);
    mul m1=new mul();
    mul m2=new mul();
    ws.setSource(0, m1, OUT.i);
    ws.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, fs, OUT.i);
    m2.setSource(IN.i, fs, OUT_IMAG.i);
    advancerRegistry.registerAdvancer(ws);
    for(double t=0; t<3; t+=1/globalParameters.getSampleRate()){
    advancerRegistry.advanceAll();
    }
    try{
    File f=new File("shiftsweep.wav");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
    ws.setFormat(FileFormats.FMT_WAVE_S16);
    ws.write(fos);
    fos.close();
    }catch(IOException ex){
    fail(ex.getMessage());
    }
    advancerRegistry.unregisterAdvancer(cos);
    advancerRegistry.unregisterAdvancer(fs);
    advancerRegistry.unregisterAdvancer(time);
    advancerRegistry.clear();
    NativeObjects.unregisterNativeObject(cos);
    NativeObjects.unregisterNativeObject(ws);
    NativeObjects.unregisterNativeObject(fs);
    NativeObjects.unregisterNativeObject(mix);
    NativeObjects.unregisterNativeObject(time);
View Full Code Here

  /**
   * Test the frequency response of the state variable filter. A file is written with a SVF lowpass filtered frequency
   * sweep cosine signal on one channel, and an envelope signal extracted with WindowedMaximum on the other channel.
   */
  public void testTS4() {
  AdvancerRegistry advancerRegistry=new AdvancerRegistry();
  try{
    advancerRegistry.clear();
    globalParameters.setSampleRate(44100);
    ProcessElement cos=new Cosine();
    ProcessElement svf=new StateVariableFilter();
    advancerRegistry.registerAdvancer(cos);
    advancerRegistry.registerAdvancer(svf);
    Time time=new Time();
    Mixer mix=new Mixer();
    advancerRegistry.registerAdvancer(mix);
    advancerRegistry.registerAdvancer(time);
    BasicMath _exp=new exp();
    advancerRegistry.registerAdvancer(_exp);
    NamedSource cs=new ConstStream(Math.log(10));
    ConstStream cs2=new ConstStream(300); // edge freq
    ConstStream cs3=new ConstStream(4); // Q
    WindowedMaximum wm=new WindowedMaximum();
    ConstStream sz=new ConstStream(.1);
    advancerRegistry.registerAdvancer(wm);
    try{
    _exp.setSource(StandardParameters.IN.i, mix, StandardParameters.OUT.i);
    mix.setSource(-2, cs, StandardParameters.OUT.i);
    mix.setSource(-1, cs, StandardParameters.OUT.i);
    mix.setSource(-1, time, StandardParameters.OUT.i);
    cos.setSource(StandardParameters.FREQUENCY.i, _exp, StandardParameters.OUT.i);
    svf.setSource(StandardParameters.IN.i, cos, StandardParameters.OUT.i);
    svf.setSource(StandardParameters.FREQUENCY.i, cs2, StandardParameters.OUT.i);
    svf.setSource(StandardParameters.Q.i, cs3, StandardParameters.OUT.i);
    wm.setSource(StandardParameters.IN.i, svf, StandardParameters.LP.i);
    wm.setSource(StandardParameters.WINDOWSIZE.i, sz, StandardParameters.OUT.i);
    }catch(Exception te){
    fail(te.getMessage());
    }
    OutputFile ws=new OutputFile(2);
    mul m1=new mul();
    mul m2=new mul();
    ws.setSource(0, m1, OUT.i);
    ws.setSource(-1, m2, OUT.i);
    m1.setSource(IN_IMAG.i, ConstStream.c(0.125), OUT.i);
    m2.setSource(IN_IMAG.i, ConstStream.c(0.125), OUT.i);
    m1.setSource(IN.i, svf, LP.i);
    m2.setSource(IN.i, wm, OUT.i);
    advancerRegistry.registerAdvancer(ws);
    for(double t=0; t<3; t+=1/globalParameters.getSampleRate()){
    advancerRegistry.advanceAll();
    }
    try{
    File f=new File("svf.wav");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
    ws.setFormat(FileFormats.FMT_WAVE_S16);
    ws.write(fos);
    fos.close();
    }catch(IOException ex){
    fail(ex.getMessage());
    }
    advancerRegistry.unregisterAdvancer(cos);
    advancerRegistry.unregisterAdvancer(svf);
    advancerRegistry.unregisterAdvancer(wm);
    advancerRegistry.unregisterAdvancer(ws);
    advancerRegistry.unregisterAdvancer(time);
    advancerRegistry.clear();
    NativeObjects.unregisterNativeObject(cos);
    NativeObjects.unregisterNativeObject(ws);
    NativeObjects.unregisterNativeObject(wm);
    NativeObjects.unregisterNativeObject(svf);
    NativeObjects.unregisterNativeObject(mix);
View Full Code Here

  /**
   * Creates a file with white noise on one and pink noise on the other channel.
   */
  public void testTS5() {
  AdvancerRegistry advancerRegistry=new AdvancerRegistry();
  try{
    advancerRegistry.clear();
    globalParameters.setSampleRate(44100);
    ProcessElement white=new WhiteNoise();
    ProcessElement pink=new PinkNoise();
    advancerRegistry.registerAdvancer(white);
    advancerRegistry.registerAdvancer(pink);
    OutputFile ws=new OutputFile(2);
    mul m1=new mul();
    mul m2=new mul();
    ws.setSource(0, m1, OUT.i);
    ws.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, white, OUT.i);
    m2.setSource(IN.i, pink, OUT.i);
    advancerRegistry.registerAdvancer(ws);
    for(double t=0; t<3; t+=1/globalParameters.getSampleRate()){
    advancerRegistry.advanceAll();
    }
    try{
    File f=new File("noise.wav");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
    ws.setFormat(FileFormats.FMT_WAVE_S16);
    ws.write(fos);
    fos.close();
    }catch(IOException ex){
    fail(ex.getMessage());
    }
    advancerRegistry.unregisterAdvancer(pink);
    advancerRegistry.unregisterAdvancer(white);
    advancerRegistry.clear();
    NativeObjects.unregisterNativeObject(pink);
    NativeObjects.unregisterNativeObject(white);
    NativeObjects.unregisterNativeObject(ws);
  }catch(Exception ex){
    fail(ex.getMessage());
View Full Code Here

  /**
   * Create two frequency sweep files, the first contains a 20% TDHS uppitched version on the second channel, the second
   * file does the same with TDHS downpitching.
   */
  public void testTS6() { // tests TDHS up- and downpitching
  AdvancerRegistry advancerRegistry=new AdvancerRegistry();
  try{
    advancerRegistry.clear();
    globalParameters.setSampleRate(44100);
    ProcessElement cos=new Cosine();
    ProcessElement tdhs1=new TDHS();
    ProcessElement tdhs2=new TDHS();
    advancerRegistry.registerAdvancer(cos);
    advancerRegistry.registerAdvancer(tdhs1);
    advancerRegistry.registerAdvancer(tdhs2);
    Time time=new Time();
    Mixer mix=new Mixer();
    advancerRegistry.registerAdvancer(mix);
    advancerRegistry.registerAdvancer(time);
    BasicMath _exp=new exp();
    advancerRegistry.registerAdvancer(_exp);
    NamedSource cs=new ConstStream(Math.log(10));
    ConstStream cs1=new ConstStream(1.2);
    ConstStream cs2=new ConstStream(0.8);
    try{
    _exp.setSource(StandardParameters.IN.i, mix, StandardParameters.OUT.i);
    mix.setSource(-2, cs, StandardParameters.OUT.i);
    mix.setSource(-1, cs, StandardParameters.OUT.i);
    mix.setSource(-1, time, StandardParameters.OUT.i);
    cos.setSource(StandardParameters.FREQUENCY.i, _exp, StandardParameters.OUT.i);
    tdhs1.setSource(StandardParameters.IN.i, cos, StandardParameters.OUT.i);
    tdhs1.setSource(StandardParameters.FACTOR.i, cs1, StandardParameters.OUT.i);
    tdhs2.setSource(StandardParameters.IN.i, cos, StandardParameters.OUT.i);
    tdhs2.setSource(StandardParameters.FACTOR.i, cs2, 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.125), OUT.i);
    m2.setSource(IN_IMAG.i, ConstStream.c(0.125), OUT.i);
    m1.setSource(IN.i, tdhs1, OUT.i);
    m2.setSource(IN.i, cos, OUT.i);
    advancerRegistry.registerAdvancer(ws1);
    OutputFile ws2=new OutputFile(2);
    mul m3=new mul();
    mul m4=new mul();
    ws2.setSource(0, m3, OUT.i);
    ws2.setSource(-1, m4, OUT.i);
    m3.setSource(IN_IMAG.i, ConstStream.c(0.125), OUT.i);
    m4.setSource(IN_IMAG.i, ConstStream.c(0.125), OUT.i);
    m3.setSource(IN.i, tdhs2, OUT.i);
    m4.setSource(IN.i, cos, OUT.i);
    advancerRegistry.registerAdvancer(ws2);
    for(double t=0; t<3; t+=1/globalParameters.getSampleRate()){
    advancerRegistry.advanceAll();
    }
    try{
    File f=new File("tdhssweep1.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());
    }
    try{
    File f=new File("tdhssweep2.wav");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
    ws2.setFormat(FileFormats.FMT_WAVE_S16);
    ws2.write(fos);
    fos.close();
    }catch(IOException ex){
    fail(ex.getMessage());
    }
    advancerRegistry.unregisterAdvancer(cos);
    advancerRegistry.unregisterAdvancer(tdhs1);
    advancerRegistry.unregisterAdvancer(tdhs2);
    advancerRegistry.unregisterAdvancer(time);
    advancerRegistry.clear();
    NativeObjects.unregisterNativeObject(cos);
    NativeObjects.unregisterNativeObject(mix);
    NativeObjects.unregisterNativeObject(_exp);
    NativeObjects.unregisterNativeObject(time);
    NativeObjects.unregisterNativeObject(tdhs1);
View Full Code Here

   * 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);
View Full Code Here

   * Creates a test file with a small simple melody. Employs the envelope generator for amplitudes. The trigger signals
   * are created by a PWM generator. The pitches employ the well tempered scale, and are modulated in addition.
   */
  @SuppressWarnings("hiding")
  public void testTS8() { // envelope generator
  AdvancerRegistry advancerRegistry=new AdvancerRegistry();
  try{
    advancerRegistry.clear();
    globalParameters.setSampleRate(44100);
    ProcessElement env1=new Envelope();
    advancerRegistry.registerAdvancer(env1);
    Time time=new Time(null);
    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;
    for(; time.getValue(StandardParameters.OUT.i)<10.5;){
    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){
      fmul.setSource(StandardParameters.IN.i, notes[lastIndex], StandardParameters.OUT.i);
      lastIndex=(lastIndex+1)%notes.length;
    }
    lastVal=gate.getValue(StandardParameters.OUT.i);
    }
    try{
    File f=new File("cwtest.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(cw);
    advancerRegistry.unregisterAdvancer(mix);
    advancerRegistry.unregisterAdvancer(env1);
    advancerRegistry.unregisterAdvancer(time);
    advancerRegistry.unregisterAdvancer(gate);
    advancerRegistry.unregisterAdvancer(si);
    advancerRegistry.unregisterAdvancer(fmix);
    advancerRegistry.unregisterAdvancer(fmix2);
    advancerRegistry.unregisterAdvancer(fmul);
    advancerRegistry.unregisterAdvancer(fmul2);
    advancerRegistry.unregisterAdvancer(fmenv);
    advancerRegistry.clear();
    // NativeObjects.unregisterNativeObject(cw);
    NativeObjects.unregisterNativeObject(mix);
    NativeObjects.unregisterNativeObject(time);
    NativeObjects.unregisterNativeObject(ws1);
    NativeObjects.unregisterNativeObject(gate);
View Full Code Here

TOP

Related Classes of de.maramuse.soundcomp.util.AdvancerRegistry

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.