Skip to content

Commit

Permalink
Added the VUMeter
Browse files Browse the repository at this point in the history
  • Loading branch information
wrey75 committed Oct 31, 2017
1 parent 7aefa55 commit a816f1e
Show file tree
Hide file tree
Showing 15 changed files with 1,239 additions and 956 deletions.
30 changes: 15 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,21 @@
</dependency>
-->

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>2.9.1</version>
</dependency>

<dependency>
<groupId>com.googlecode.soundlibs</groupId>
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/com/oxande/wavecleaner/WaveCleaner.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package com.oxande.wavecleaner;

import java.io.File;
import java.io.IOException;

import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import org.apache.logging.log4j.Logger;

import com.oxande.wavecleaner.audio.AudioCache;
import com.oxande.wavecleaner.audio.AudioDocument;
import com.oxande.wavecleaner.ui.MainScreen;
import com.oxande.wavecleaner.util.ProcessingLegacy;
import com.oxande.wavecleaner.util.logging.LogFactory;
Expand Down Expand Up @@ -101,6 +98,19 @@ public AudioRecordingStream loadFileStream(File f){
return stream;
}

/**
* Retrieve an audio recorder.
*
* @param f the file to save the sound.
* @param sampleRate the sample rate
* @return the {@link AudioRecorder}.
*/
public AudioRecorder getAudioRecorder(File f, float sampleRate){
AudioInput in = this.minim.getLineIn(Minim.STEREO, (int)(sampleRate / 20), sampleRate);
AudioRecorder stream = minim.createRecorder(in, f.getAbsolutePath());
return stream;
}

/**
* Check for old temporary files created by other instances. If found, they are deleted.
* Note the deletion works only if the file is not locked (then 2 instances can run
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/com/oxande/wavecleaner/audio/AudioDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
import com.oxande.wavecleaner.WaveCleaner;
import com.oxande.wavecleaner.filters.AudioDocumentPlayer;
import com.oxande.wavecleaner.filters.AudioPlayerListener;
import com.oxande.wavecleaner.filters.PreamplifierFilter;
import com.oxande.wavecleaner.filters.DecrackleFilter;
import com.oxande.wavecleaner.filters.PreamplifierFilter;
import com.oxande.wavecleaner.util.ListenerManager;
import com.oxande.wavecleaner.util.logging.LogFactory;

import ddf.minim.AudioOutput;
import ddf.minim.Minim;
import ddf.minim.MultiChannelBuffer;
import ddf.minim.spi.AudioRecordingStream;

Expand Down Expand Up @@ -54,7 +53,7 @@ public class AudioDocument /*implements AudioListener*/ {
int nbChannels = 2;
private int totalSamples = 0;
public DecrackleFilter decrackFilter = new DecrackleFilter();
public PreamplifierFilter controlFilter = new PreamplifierFilter(null);
public PreamplifierFilter preamplifer = new PreamplifierFilter(null);


private RMSSample[] samples = null;
Expand Down Expand Up @@ -275,8 +274,8 @@ public synchronized void stop() {
this.documentPlayer.pause();
// lineOut.removeListener(this);
this.documentPlayer.unpatch(decrackFilter);
decrackFilter.unpatch(controlFilter);
controlFilter.unpatch(lineOut);
decrackFilter.unpatch(preamplifer);
preamplifer.unpatch(lineOut);
LOG.info("PAUSED");
// for (AudioDocumentListener listener : listeners) {
// listener.audioPaused();
Expand All @@ -303,8 +302,8 @@ public synchronized void play(int pos) {
}

// this.lineOut.addListener(this);
controlFilter.setPlayer(player);
player.patch(decrackFilter).patch(controlFilter).patch(lineOut);
preamplifer.setPlayer(player);
player.patch(decrackFilter).patch(preamplifer).patch(lineOut);
// REAL VERSION player.patch(lineOut);
player.rewind();
player.play();
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/oxande/wavecleaner/filters/AudioFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public float setControl(String name, float value ){
LOG.error("Parameter '{}' unknown.", name);
return 0.0f;
}
LOG.debug("Parameter '{}' set to {}.", name, value);
p.setValue(value);
return p.getValue();
}
Expand Down Expand Up @@ -217,8 +216,10 @@ void setValue( float v ){
LOG.warn("Parameter '{}' set to maximum {} instead of {}", name, max, v);
v = max;
}
LOG.debug("Parameter '{}' set to {}", name, v);
this.input.setLastValue(v);
if( v != this.input.getLastValue() ){
LOG.debug("Parameter '{}' set to {}", name, v);
this.input.setLastValue(v);
}
}

public float getValue(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.apache.logging.log4j.Logger;

import com.oxande.wavecleaner.ui.VUMeterComponent;
import com.oxande.wavecleaner.util.ConvertUtils;
import com.oxande.wavecleaner.util.logging.LogFactory;

Expand Down Expand Up @@ -52,6 +53,7 @@ public class PreamplifierFilter extends AudioFilter {
public static final int LEFT_RIGHT = 3;

private AudioDocumentPlayer player;
private VUMeterComponent vumeter = null;

public PreamplifierFilter( AudioDocumentPlayer player){
super();
Expand All @@ -72,6 +74,18 @@ public void setPlayer(AudioDocumentPlayer player){
LOG.debug("New player is now {}", player);
this.player = player;
}

public void setVUMeter(VUMeterComponent vumeter){
this.vumeter = vumeter;
this.vumeter.setSampleRate(this.sampleRate());
}

@Override
protected void sampleRateChanged(){
if( this.vumeter != null ){
this.vumeter.setSampleRate(this.sampleRate());
}
}

protected void process(MultiChannelBuffer buff) {
if(player == null){
Expand Down Expand Up @@ -117,6 +131,10 @@ protected void process(MultiChannelBuffer buff) {
sample[ch] = sample[ch] * mValue;
buff.setSample(ch, i, sample[ch]);
}

if( vumeter != null ){
vumeter.push(sample);
}
}
}

Expand Down
31 changes: 31 additions & 0 deletions src/main/java/com/oxande/wavecleaner/filters/VUMeter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.oxande.wavecleaner.filters;

import com.oxande.wavecleaner.ui.VUMeterComponent;

import ddf.minim.UGen;

public class VUMeter extends UGen {

private UGen audio;
private VUMeterComponent vu = new VUMeterComponent();
private float[] tickBuffer;

public VUMeterComponent getComponent(){
return this.vu;
}

@Override
protected void addInput(UGen in)
{
this.audio = in;
this.tickBuffer = new float[in.channelCount()];
}

@Override
protected void uGenerate(float[] channels) {
audio.tick(tickBuffer);

System.arraycopy(tickBuffer, 0, channels, 0, tickBuffer.length);
}

}
Loading

0 comments on commit a816f1e

Please sign in to comment.