Skip to content

Commit 389d91a

Browse files
authored
Merge pull request #2441 from capdevon/capdevon-LowPassFilter-no-args
com.jme3.audio.LowPassFilter lacks the required no-argument constructor for jME deserialization
2 parents 069d4e7 + 3eebd56 commit 389d91a

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

jme3-core/src/main/java/com/jme3/audio/LowPassFilter.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,21 @@ public class LowPassFilter extends Filter {
4949
/**
5050
* The overall volume scaling of the filtered sound
5151
*/
52-
protected float volume;
52+
protected float volume = 1.0f;
5353
/**
5454
* The volume scaling of the high frequencies allowed to pass through. Valid values range
5555
* from 0.0 to 1.0, where 0.0 completely eliminates high frequencies and 1.0 lets them pass
5656
* through unchanged.
5757
*/
58-
protected float highFreqVolume;
58+
protected float highFreqVolume = 1.0f;
59+
60+
/**
61+
* Constructs a low-pass filter with default settings.
62+
* Required for jME deserialization.
63+
*/
64+
public LowPassFilter() {
65+
super();
66+
}
5967

6068
/**
6169
* Constructs a low-pass filter.
@@ -128,16 +136,16 @@ public void setVolume(float volume) {
128136
public void write(JmeExporter ex) throws IOException {
129137
super.write(ex);
130138
OutputCapsule oc = ex.getCapsule(this);
131-
oc.write(volume, "volume", 0);
132-
oc.write(highFreqVolume, "hf_volume", 0);
139+
oc.write(volume, "volume", 1f);
140+
oc.write(highFreqVolume, "hf_volume", 1f);
133141
}
134142

135143
@Override
136144
public void read(JmeImporter im) throws IOException {
137145
super.read(im);
138146
InputCapsule ic = im.getCapsule(this);
139-
volume = ic.readFloat("volume", 0);
140-
highFreqVolume = ic.readFloat("hf_volume", 0);
147+
volume = ic.readFloat("volume", 1f);
148+
highFreqVolume = ic.readFloat("hf_volume", 1f);
141149
}
142150

143151
/**
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.jme3.audio;
2+
3+
import com.jme3.asset.AssetManager;
4+
import com.jme3.asset.DesktopAssetManager;
5+
import com.jme3.export.binary.BinaryExporter;
6+
import org.junit.Assert;
7+
import org.junit.Test;
8+
9+
/**
10+
* Automated tests for the Filter class.
11+
*
12+
* @author capdevon
13+
*/
14+
public class AudioFilterTest {
15+
16+
/**
17+
* Tests serialization and de-serialization of a {@code LowPassFilter}.
18+
*/
19+
@Test
20+
public void testSaveAndLoad() {
21+
AssetManager assetManager = new DesktopAssetManager(true);
22+
23+
LowPassFilter f = new LowPassFilter(.5f, .5f);
24+
LowPassFilter copy = BinaryExporter.saveAndLoad(assetManager, f);
25+
26+
float delta = 0.001f;
27+
Assert.assertEquals(f.getVolume(), copy.getVolume(), delta);
28+
Assert.assertEquals(f.getHighFreqVolume(), copy.getHighFreqVolume(), delta);
29+
}
30+
31+
}

0 commit comments

Comments
 (0)