Package de.maramuse.soundcomp.test

Source Code of de.maramuse.soundcomp.test.Test

package de.maramuse.soundcomp.test;

/*
* Copyright 2010 Jan Schmidt-Reinisch
*
* SoundComp - a sound processing library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; in version 2.1
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

/**
* A collection of JUnit test cases for the signal generation/manipulation parts.
* Each test case produces one or multiple output files.
* These can be verified by listening, or by viewing the output signal curves.
* The recommended way of verification is to load the files into audacity and look at the curves.
*
* The code here can also be taken as examples to what the parser created structures could do in the end.
*/
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import de.maramuse.soundcomp.effect.Flanger;
import de.maramuse.soundcomp.effect.FreqShift;
import de.maramuse.soundcomp.effect.TDHS;
import de.maramuse.soundcomp.files.FileFormats;
import de.maramuse.soundcomp.files.InputFile;
import de.maramuse.soundcomp.files.OutputFile;
import de.maramuse.soundcomp.filter.ParametricAllPass;
import de.maramuse.soundcomp.filter.PseudoHilbert;
import de.maramuse.soundcomp.filter.StateVariableFilter;
import de.maramuse.soundcomp.generator.*;
import de.maramuse.soundcomp.math.BasicMath;
import de.maramuse.soundcomp.math.exp;
import de.maramuse.soundcomp.math.mul;
import de.maramuse.soundcomp.process.*;
import de.maramuse.soundcomp.util.AdvancerRegistry;
import de.maramuse.soundcomp.util.ComplexTable;
import de.maramuse.soundcomp.util.GlobalParameters;
import de.maramuse.soundcomp.util.NativeObjects;
import junit.framework.TestCase;
import static de.maramuse.soundcomp.process.StandardParameters.*;

public class Test extends TestCase {

  private final static int fileBufferSize=8192;
  GlobalParameters globalParameters=new GlobalParameters(44100);

  /**
   * 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){
    fail(ex.getMessage());
  }
  }

  /**
   * Creates a frequency sweep signal pair, starting below audible range. One channel is phase shifted against the other
   * by 90 degrees. The result is saved in multiple file formats. - as 16 bit fixed PCM stream (original windows .wav
   * 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);
  }catch(Exception ex){
    fail(ex.getMessage());
  }
  }

  /**
   * 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);
  }catch(Exception ex){
    fail(ex.getMessage());
  }
  }

  /**
   * 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);
  }catch(Exception ex){
    fail(ex.getMessage());
  }
  }

  /**
   * 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);
    NativeObjects.unregisterNativeObject(time);
  }catch(Exception ex){
    fail(ex.getMessage());
  }
  }

  /**
   * 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());
  }
  }

  /**
   * 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);
    NativeObjects.unregisterNativeObject(tdhs2);
    NativeObjects.unregisterNativeObject(ws1);
    NativeObjects.unregisterNativeObject(ws2);
  }catch(Exception ex){
    fail(ex.getMessage());
  }
  }

  /**
   * Creates two test files with a small simple cosine melody. Employs the envelope generator for amplitudes. The
   * 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);
  }catch(Exception ex){
    fail(ex.getMessage());
  }
  }

  /**
   * 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);
    NativeObjects.unregisterNativeObject(si);
    NativeObjects.unregisterNativeObject(fmix);
    NativeObjects.unregisterNativeObject(fmix2);
    NativeObjects.unregisterNativeObject(fmul);
    NativeObjects.unregisterNativeObject(fmul2);
    NativeObjects.unregisterNativeObject(fmenv);
  }catch(Exception ex){
    fail(ex.getMessage());
  }
  }

  /**
   * 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 testTS9() {
  try{
    AdvancerRegistry advancerRegistry=new AdvancerRegistry();
    advancerRegistry.clear();
    globalParameters.setSampleRate(44100);
    ProcessElement pe=new InputFile("javasrc/de/maramuse/soundcomp/test/testfiles/hh-o.wav");
    advancerRegistry.registerAdvancer(pe);
    OutputFile ws=new OutputFile(1);
    advancerRegistry.registerAdvancer(ws);
    ws.setSource(0, pe, OUT.i);
    for(double time=0; time<1.5; time+=1/globalParameters.getSampleRate()){
    advancerRegistry.advanceAll();
    }
    File f=new File("hh-o.wav");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
    ws.setFormat(FileFormats.FMT_WAVE_S16);
    ws.write(fos);
    fos.close();
    advancerRegistry.unregisterAdvancer(pe);
    advancerRegistry.unregisterAdvancer(ws);
    NativeObjects.unregisterNativeObject(pe);
    NativeObjects.unregisterNativeObject(ws);
  }catch(Exception ex){
    fail(ex.getMessage());
  }
  }

  /**
   * Takes an existing file and applies the flanger to its first channel, writing a new stereo output file
   *
   * Succeeds immediately if the file is missing to not disturb automatized tests.
   */
  public void testTS10() {
  try{
    if(!new File("flanger-in.wav").exists())return;
    AdvancerRegistry advancerRegistry=new AdvancerRegistry();
    advancerRegistry.clear();
    globalParameters.setSampleRate(44100);
    ProcessElement in=new InputFile("flanger-in.wav");
    Flanger fl=new Flanger();
    mul _mul1=new mul(), _mul2=new mul();
    _mul1.setSource(IN.i, fl, OUT.i);
    _mul1.setSource(IN_IMAG.i, ConstStream.c(0.5), OUT.i);
    _mul2.setSource(IN.i, fl, OUT_IMAG.i);
    _mul2.setSource(IN_IMAG.i, ConstStream.c(0.5), OUT.i);
    OutputFile of=new OutputFile(2);
    advancerRegistry.registerAdvancer(of);
    advancerRegistry.registerAdvancer(fl);
    advancerRegistry.registerAdvancer(in);
    advancerRegistry.registerAdvancer(_mul1);
    advancerRegistry.registerAdvancer(_mul2);
    of.setSource(0, _mul1, OUT.i);
    of.setSource(-1, _mul2, OUT.i);
    fl.setSource(IN.i, in, OUT.i);
    fl.setSource(FREQUENCY.i, ConstStream.c(0.366), OUT.i);
    fl.setSource(DEPTH.i, ConstStream.c(0.0025), OUT.i);
    fl.setSource(MAXDELAY.i, ConstStream.c(0.0075), OUT.i);
    fl.setSource(DELAY.i, ConstStream.c(0.0033), OUT.i);
    for(double time=0; time==0||in.getValue(GATE.i)>0; time+=1/globalParameters.getSampleRate()){
    advancerRegistry.advanceAll();
    }
    File f=new File("flanger-out.wav");
    BufferedOutputStream fos=new BufferedOutputStream(new FileOutputStream(f), fileBufferSize);
    of.setFormat(FileFormats.FMT_WAVE_S16);
    of.write(fos);
    fos.close();
    advancerRegistry.unregisterAdvancer(in);
    advancerRegistry.unregisterAdvancer(of);
    advancerRegistry.unregisterAdvancer(_mul1);
    advancerRegistry.unregisterAdvancer(_mul2);
    advancerRegistry.unregisterAdvancer(fl);
    NativeObjects.unregisterNativeObject(in);
    NativeObjects.unregisterNativeObject(of);
    NativeObjects.unregisterNativeObject(_mul1);
    NativeObjects.unregisterNativeObject(_mul2);
    NativeObjects.unregisterNativeObject(fl);
   
  }catch(Exception ex){
    fail(ex.getMessage());
  }
  }
}
TOP

Related Classes of de.maramuse.soundcomp.test.Test

TOP
Copyright © 2018 www.massapi.com. 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.