Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions jme3-core/src/main/java/com/jme3/audio/LowPassFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,21 @@ public class LowPassFilter extends Filter {
/**
* The overall volume scaling of the filtered sound
*/
protected float volume;
protected float volume = 1.0f;
/**
* The volume scaling of the high frequencies allowed to pass through. Valid values range
* from 0.0 to 1.0, where 0.0 completely eliminates high frequencies and 1.0 lets them pass
* through unchanged.
*/
protected float highFreqVolume;
protected float highFreqVolume = 1.0f;

/**
* Constructs a low-pass filter with default settings.
* Required for jME deserialization.
*/
public LowPassFilter() {
super();
}

/**
* Constructs a low-pass filter.
Expand Down Expand Up @@ -128,16 +136,16 @@ public void setVolume(float volume) {
public void write(JmeExporter ex) throws IOException {
super.write(ex);
OutputCapsule oc = ex.getCapsule(this);
oc.write(volume, "volume", 0);
oc.write(highFreqVolume, "hf_volume", 0);
oc.write(volume, "volume", 1f);
oc.write(highFreqVolume, "hf_volume", 1f);
}

@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule ic = im.getCapsule(this);
volume = ic.readFloat("volume", 0);
highFreqVolume = ic.readFloat("hf_volume", 0);
volume = ic.readFloat("volume", 1f);
highFreqVolume = ic.readFloat("hf_volume", 1f);
}

/**
Expand Down
31 changes: 31 additions & 0 deletions jme3-core/src/test/java/com/jme3/audio/AudioFilterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.jme3.audio;

import com.jme3.asset.AssetManager;
import com.jme3.asset.DesktopAssetManager;
import com.jme3.export.binary.BinaryExporter;
import org.junit.Assert;
import org.junit.Test;

/**
* Automated tests for the Filter class.
*
* @author capdevon
*/
public class AudioFilterTest {

/**
* Tests serialization and de-serialization of a {@code LowPassFilter}.
*/
@Test
public void testSaveAndLoad() {
AssetManager assetManager = new DesktopAssetManager(true);

LowPassFilter f = new LowPassFilter(.5f, .5f);
LowPassFilter copy = BinaryExporter.saveAndLoad(assetManager, f);

float delta = 0.001f;
Assert.assertEquals(f.getVolume(), copy.getVolume(), delta);
Assert.assertEquals(f.getHighFreqVolume(), copy.getHighFreqVolume(), delta);
}

}