Skip to content

Commit

Permalink
Refactoring to support the new API based around the AudioEvent object.
Browse files Browse the repository at this point in the history
  • Loading branch information
JorenSix committed Feb 22, 2012
1 parent dd4ba95 commit 91bfc59
Show file tree
Hide file tree
Showing 40 changed files with 398 additions and 1,899 deletions.
4 changes: 3 additions & 1 deletion build/build_examples.bash
Expand Up @@ -14,4 +14,6 @@ ant -q -f goertzel_algorithm.xml

ant -q -f time_stretch.xml

ant -q -f spectrogram.xml
ant -q -f spectrogram.xml

ant -q -f delay_effect.xml
26 changes: 26 additions & 0 deletions build/delay_effect.xml
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="create_run_jar" name="Create Runnable Time Stretch Jar">
<target name="create_run_jar">
<jar destfile="Delay.jar" filesetmanifest="mergewithoutmain">
<manifest>
<attribute name="Main-Class" value="be.hogent.tarsos.dsp.example.Delay"/>
<attribute name="Class-Path" value="."/>
</manifest>

<!-- exclude wav and test files -->
<fileset dir="../bin">
<exclude name="**/*.wav"/>
<exclude name="**/test/**"/>
</fileset>

<!-- include source files -->
<fileset dir="../src">
<include name="**/*.java"/>
</fileset>
<fileset dir="../examples">
<exclude name="**/*.wav"/>
<include name="**/*.java"/>
</fileset>
</jar>
</target>
</project>
Expand Up @@ -23,20 +23,20 @@
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import be.hogent.tarsos.dsp.NewAudioDispatcher;
import be.hogent.tarsos.dsp.NewAudioPlayer;
import be.hogent.tarsos.dsp.NewDelayEffect;
import be.hogent.tarsos.dsp.NewGainProcessor;
import be.hogent.tarsos.dsp.AudioDispatcher;
import be.hogent.tarsos.dsp.AudioPlayer;
import be.hogent.tarsos.dsp.DelayEffect;
import be.hogent.tarsos.dsp.GainProcessor;

public class DelayEffectExample extends JFrame {
public class Delay extends JFrame {

/**
*
*/
private static final long serialVersionUID = -5020248948695915733L;
private NewAudioDispatcher dispatcher;
private NewDelayEffect delayEffect;
private NewGainProcessor inputGain;
private AudioDispatcher dispatcher;
private DelayEffect delayEffect;
private GainProcessor inputGain;

private int defaultInputGain = 100;//%
private int defaultDelay = 200;//ms
Expand All @@ -58,7 +58,7 @@ public void propertyChange(PropertyChangeEvent arg0) {
};


public DelayEffectExample() {
public Delay() {
this.setLayout(new BorderLayout());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Delay Effect Example");
Expand Down Expand Up @@ -159,15 +159,15 @@ private void setNewMixer(Mixer mixer) throws LineUnavailableException,
final AudioInputStream stream = new AudioInputStream(line);

// create a new dispatcher
dispatcher = new NewAudioDispatcher(stream, bufferSize, overlap);
dispatcher = new AudioDispatcher(stream, bufferSize, overlap);

delayEffect = new NewDelayEffect(defaultDelay/1000.0,defaultDecay/100.0,sampleRate);
inputGain = new NewGainProcessor(defaultInputGain/100.0);
delayEffect = new DelayEffect(defaultDelay/1000.0,defaultDecay/100.0,sampleRate);
inputGain = new GainProcessor(defaultInputGain/100.0);

//add processors
dispatcher.addAudioProcessor(inputGain);
dispatcher.addAudioProcessor(delayEffect);
dispatcher.addAudioProcessor(new NewAudioPlayer(format));
dispatcher.addAudioProcessor(new AudioPlayer(format));

// run the dispatcher (on a new thread).
new Thread(dispatcher, "Audio dispatching").start();
Expand All @@ -183,7 +183,7 @@ public void run() {
} catch (Exception e) {
//ignore failure to set default look en feel;
}
JFrame frame = new DelayEffectExample();
JFrame frame = new Delay();
frame.pack();
frame.setVisible(true);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/be/hogent/tarsos/dsp/example/GoertzelDTMF.java
Expand Up @@ -33,8 +33,8 @@
import javax.swing.border.TitledBorder;

import be.hogent.tarsos.dsp.AudioDispatcher;
import be.hogent.tarsos.dsp.AudioPlayer;
import be.hogent.tarsos.dsp.AudioProcessor;
import be.hogent.tarsos.dsp.BlockingAudioPlayer;
import be.hogent.tarsos.dsp.pitch.DTMF;
import be.hogent.tarsos.dsp.pitch.Goertzel;
import be.hogent.tarsos.dsp.pitch.Goertzel.FrequenciesDetectedHandler;
Expand Down Expand Up @@ -187,7 +187,7 @@ public void process(char character) throws UnsupportedAudioFileException, LineUn
final AudioInputStream inputStream = new AudioInputStream(bais, format,floatBuffer.length);
final AudioDispatcher dispatcher = new AudioDispatcher(inputStream, stepSize, 0);
dispatcher.addAudioProcessor(goertzelAudioProcessor);
dispatcher.addAudioProcessor(new BlockingAudioPlayer(format, stepSize, 0));
dispatcher.addAudioProcessor(new AudioPlayer(format));
new Thread(dispatcher).start();

}
Expand Down
Expand Up @@ -231,7 +231,7 @@ private void setNewMixer(Mixer mixer) throws LineUnavailableException,

// add a processor, handle percussion event.
dispatcher.addAudioProcessor(new PercussionOnsetDetector(sampleRate,
bufferSize, overlap, this,sensitivity,threshold));
bufferSize, this,sensitivity,threshold));

// run the dispatcher (on a new thread).
new Thread(dispatcher,"Audio dispatching").start();
Expand Down
10 changes: 4 additions & 6 deletions examples/be/hogent/tarsos/dsp/example/PitchDetector.java
Expand Up @@ -32,8 +32,7 @@
import javax.swing.UIManager;

import be.hogent.tarsos.dsp.AudioDispatcher;
import be.hogent.tarsos.dsp.BlockingAudioPlayer;
import be.hogent.tarsos.dsp.FloatConverter;
import be.hogent.tarsos.dsp.AudioPlayer;
import be.hogent.tarsos.dsp.pitch.PitchProcessor;
import be.hogent.tarsos.dsp.pitch.PitchProcessor.DetectedPitchHandler;
import be.hogent.tarsos.dsp.pitch.PitchProcessor.PitchEstimationAlgorithm;
Expand Down Expand Up @@ -111,10 +110,9 @@ private void setNewMixer(Mixer mixer) throws LineUnavailableException,
dispatcher = new AudioDispatcher(stream, bufferSize,
overlap);

// add a processor, handle percussion event.
dispatcher.addAudioProcessor(new PitchProcessor(PitchEstimationAlgorithm.YIN, sampleRate, bufferSize, overlap, 0, this));
dispatcher.addAudioProcessor(new FloatConverter(format));
dispatcher.addAudioProcessor(new BlockingAudioPlayer(format, bufferSize, overlap));
// add a processor
dispatcher.addAudioProcessor(new PitchProcessor(PitchEstimationAlgorithm.YIN, sampleRate, bufferSize, 0, this));
dispatcher.addAudioProcessor(new AudioPlayer(format));


// run the dispatcher (on a new thread).
Expand Down
7 changes: 7 additions & 0 deletions examples/be/hogent/tarsos/dsp/example/Player.java
@@ -0,0 +1,7 @@
package be.hogent.tarsos.dsp.example;

import javax.swing.JFrame;

public class Player extends JFrame {

}
17 changes: 6 additions & 11 deletions examples/be/hogent/tarsos/dsp/example/SoundDetector.java
Expand Up @@ -40,8 +40,8 @@
import javax.swing.event.ChangeListener;

import be.hogent.tarsos.dsp.AudioDispatcher;
import be.hogent.tarsos.dsp.AudioEvent;
import be.hogent.tarsos.dsp.AudioProcessor;
import be.hogent.tarsos.dsp.ContinuingSilenceDetector;
import be.hogent.tarsos.dsp.SilenceDetector;

public class SoundDetector extends JFrame implements AudioProcessor {
Expand All @@ -58,7 +58,7 @@ public class SoundDetector extends JFrame implements AudioProcessor {
AudioDispatcher dispatcher;
Mixer currentMixer;
private final GaphPanel graphPanel;
ContinuingSilenceDetector silenceDetector;
SilenceDetector silenceDetector;


public SoundDetector() {
Expand Down Expand Up @@ -256,7 +256,7 @@ private void setNewMixer(Mixer mixer) throws LineUnavailableException,
overlap);

// add a processor, handle percussion event.
silenceDetector = new ContinuingSilenceDetector(threshold);
silenceDetector = new SilenceDetector(threshold,false);
dispatcher.addAudioProcessor(silenceDetector);
dispatcher.addAudioProcessor(this);

Expand All @@ -278,14 +278,7 @@ public void run() {
}

@Override
public boolean processFull(float[] audioFloatBuffer, byte[] audioByteBuffer) {
handleSound();
return true;
}

@Override
public boolean processOverlapping(float[] audioFloatBuffer,
byte[] audioByteBuffer) {
public boolean process(AudioEvent audioEvent) {
handleSound();
return true;
}
Expand All @@ -302,4 +295,6 @@ public void processingFinished() {

}



}
25 changes: 9 additions & 16 deletions examples/be/hogent/tarsos/dsp/example/Spectrogram.java
Expand Up @@ -35,8 +35,9 @@
import javax.swing.border.TitledBorder;

import be.hogent.tarsos.dsp.AudioDispatcher;
import be.hogent.tarsos.dsp.AudioEvent;
import be.hogent.tarsos.dsp.AudioProcessor;
import be.hogent.tarsos.dsp.BlockingAudioPlayer;
import be.hogent.tarsos.dsp.AudioPlayer;
import be.hogent.tarsos.dsp.pitch.PitchProcessor;
import be.hogent.tarsos.dsp.pitch.PitchProcessor.DetectedPitchHandler;
import be.hogent.tarsos.dsp.pitch.PitchProcessor.PitchEstimationAlgorithm;
Expand Down Expand Up @@ -143,7 +144,7 @@ private void setNewMixer(Mixer mixer) throws LineUnavailableException, Unsupport
File audioFile = new File(fileName);
dispatcher = AudioDispatcher.fromFile(audioFile, bufferSize, overlap);
AudioFormat format = AudioSystem.getAudioFileFormat(audioFile).getFormat();
dispatcher.addAudioProcessor(new BlockingAudioPlayer(format, bufferSize, overlap));
dispatcher.addAudioProcessor(new AudioPlayer(format));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand All @@ -154,7 +155,7 @@ private void setNewMixer(Mixer mixer) throws LineUnavailableException, Unsupport


// add a processor, handle pitch event.
dispatcher.addAudioProcessor(new PitchProcessor(algo, sampleRate, bufferSize, overlap, 0, this));
dispatcher.addAudioProcessor(new PitchProcessor(algo, sampleRate, bufferSize, 0, this));
dispatcher.addAudioProcessor(fftProcessor);


Expand All @@ -167,29 +168,21 @@ private void setNewMixer(Mixer mixer) throws LineUnavailableException, Unsupport

FFT fft = new FFT(bufferSize);
float[] amplitudes = new float[bufferSize/2];


@Override
public boolean processFull(float[] audioFloatBuffer,
byte[] audioByteBuffer) {
processOverlapping(audioFloatBuffer,audioByteBuffer);
return true;
public void processingFinished() {
// TODO Auto-generated method stub
}

@Override
public boolean processOverlapping(float[] audioFloatBuffer,
byte[] audioByteBuffer) {
public boolean process(AudioEvent audioEvent) {
float[] audioFloatBuffer = audioEvent.getFloatBuffer();
float[] transformbuffer = new float[bufferSize*2];
System.arraycopy(audioFloatBuffer, 0, transformbuffer, 0, audioFloatBuffer.length);
fft.forwardTransform(transformbuffer);
fft.modulus(transformbuffer, amplitudes);
panel.drawFFT(pitch, amplitudes,fft);
return true;
}

@Override
public void processingFinished() {
// TODO Auto-generated method stub
return false;
}

};
Expand Down
28 changes: 14 additions & 14 deletions examples/be/hogent/tarsos/dsp/example/TimeStretch.java
Expand Up @@ -37,11 +37,11 @@
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import be.hogent.tarsos.dsp.NewAudioDispatcher;
import be.hogent.tarsos.dsp.NewAudioPlayer;
import be.hogent.tarsos.dsp.NewGainProcessor;
import be.hogent.tarsos.dsp.NewWaveformSimilarityBasedOverlapAdd;
import be.hogent.tarsos.dsp.NewWaveformSimilarityBasedOverlapAdd.Parameters;
import be.hogent.tarsos.dsp.AudioDispatcher;
import be.hogent.tarsos.dsp.AudioPlayer;
import be.hogent.tarsos.dsp.GainProcessor;
import be.hogent.tarsos.dsp.WaveformSimilarityBasedOverlapAdd;
import be.hogent.tarsos.dsp.WaveformSimilarityBasedOverlapAdd.Parameters;

public class TimeStretch extends JFrame{

Expand All @@ -52,10 +52,10 @@ public class TimeStretch extends JFrame{

private JFileChooser fileChooser;

private NewAudioDispatcher dispatcher;
private NewWaveformSimilarityBasedOverlapAdd wsola;
private NewGainProcessor gain;
private NewAudioPlayer audioPlayer;
private AudioDispatcher dispatcher;
private WaveformSimilarityBasedOverlapAdd wsola;
private GainProcessor gain;
private AudioPlayer audioPlayer;

private final JSlider tempoSlider;
private final JSlider gainSlider;
Expand Down Expand Up @@ -175,11 +175,11 @@ private void startFile(File inputFile){
try {
format = AudioSystem.getAudioFileFormat(inputFile).getFormat();

gain = new NewGainProcessor(1.0);
audioPlayer = new NewAudioPlayer(format);
gain = new GainProcessor(1.0);
audioPlayer = new AudioPlayer(format);

wsola = new NewWaveformSimilarityBasedOverlapAdd(Parameters.slowdownDefaults(tempoSlider.getValue()/100.0,format.getSampleRate()));
dispatcher = NewAudioDispatcher.fromFile(inputFile,wsola.getInputBufferSize(),wsola.getOverlap());
wsola = new WaveformSimilarityBasedOverlapAdd(Parameters.slowdownDefaults(tempoSlider.getValue()/100.0,format.getSampleRate()));
dispatcher = AudioDispatcher.fromFile(inputFile,wsola.getInputBufferSize(),wsola.getOverlap());
wsola.setDispatcher(dispatcher);
dispatcher.addAudioProcessor(wsola);
dispatcher.addAudioProcessor(gain);
Expand Down Expand Up @@ -232,7 +232,7 @@ private static void startCli(String source,String target,double tempo) throws Un
/*
File inputFile = new File(source);
AudioFormat format = AudioSystem.getAudioFileFormat(inputFile).getFormat();
NewWaveformSimilarityBasedOverlapAdd wsola = new NewWaveformSimilarityBasedOverlapAdd(format,Parameters.slowdownDefaults(tempo,format.getSampleRate()));
WaveformSimilarityBasedOverlapAdd wsola = new WaveformSimilarityBasedOverlapAdd(format,Parameters.slowdownDefaults(tempo,format.getSampleRate()));
wsola.setWaveFormWriter(new WaveformWriter(format, wsola.getOutputBufferSize(), 0, target));
AudioDispatcher dispatcher = AudioDispatcher.fromFile(inputFile,wsola.getInputBufferSize(),wsola.getOverlap());
wsola.setDispatcher(dispatcher);
Expand Down
2 changes: 1 addition & 1 deletion examples/be/hogent/tarsos/dsp/example/UtterAsterisk.java
Expand Up @@ -131,7 +131,7 @@ private void setNewMixer(Mixer mixer) throws LineUnavailableException, Unsupport
overlap);

// add a processor, handle percussion event.
dispatcher.addAudioProcessor(new PitchProcessor(algo, sampleRate, bufferSize, overlap, 0, this));
dispatcher.addAudioProcessor(new PitchProcessor(algo, sampleRate, bufferSize, 0, this));

// run the dispatcher (on a new thread).
new Thread(dispatcher,"Audio dispatching").start();
Expand Down

0 comments on commit 91bfc59

Please sign in to comment.