Skip to content

Commit 8eff650

Browse files
authored
add HighPassFilter class
1 parent 389d91a commit 8eff650

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
* Copyright (c) 2009-2025 jMonkeyEngine
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
package com.jme3.audio;
33+
34+
import com.jme3.export.InputCapsule;
35+
import com.jme3.export.JmeExporter;
36+
import com.jme3.export.JmeImporter;
37+
import com.jme3.export.OutputCapsule;
38+
import com.jme3.util.NativeObject;
39+
40+
import java.io.IOException;
41+
42+
/**
43+
* Represents an OpenAL EFX High-Pass Filter.
44+
* Changes to settings are applied immediately to the native OpenAL filter.
45+
*/
46+
public class HighPassFilter extends Filter {
47+
48+
// Default values based on OpenAL EFX specification defaults
49+
protected float volume = 1.0f;
50+
protected float lowFreqVolume = 1.0f;
51+
52+
/**
53+
* Constructs a low-pass filter with default settings.
54+
* Required for jME deserialization
55+
*/
56+
public HighPassFilter(){}
57+
58+
protected HighPassFilter(int id) {
59+
super(id);
60+
}
61+
62+
public HighPassFilter(float volume, float lowFreqVolume) {
63+
super();
64+
setVolume(volume);
65+
setLowFreqVolume(lowFreqVolume);
66+
}
67+
68+
public float getVolume() {
69+
return volume;
70+
}
71+
72+
/**
73+
* Sets the gain of the High-Pass filter.
74+
* The change is immediately applied to the native OpenAL filter.
75+
*
76+
* @param volume The gain value (0.0 to 1.0).
77+
*/
78+
public void setVolume(float volume) {
79+
if (volume < 0 || volume > 1)
80+
throw new IllegalArgumentException("Volume must be between 0 and 1");
81+
82+
this.volume = volume;
83+
this.updateNeeded = true;
84+
}
85+
86+
public float getLowFreqVolume() {
87+
return lowFreqVolume;
88+
}
89+
90+
/**
91+
* Sets the gain at low frequencies for the High-Pass filter.
92+
* The change is immediately applied to the native OpenAL filter.
93+
*
94+
* @param lowFreqVolume The low-frequency gain value (0.0 to 1.0).
95+
*/
96+
public void setLowFreqVolume(float lowFreqVolume) {
97+
if (lowFreqVolume < 0 || lowFreqVolume > 1)
98+
throw new IllegalArgumentException("Low freq volume must be between 0 and 1");
99+
100+
this.lowFreqVolume = lowFreqVolume;
101+
this.updateNeeded = true;
102+
}
103+
104+
@Override
105+
public NativeObject createDestructableClone() {
106+
return new HighPassFilter(this.id);
107+
}
108+
109+
/**
110+
* Retrieves a unique identifier for this filter. Used internally for native object management.
111+
*
112+
* @return a unique long identifier.
113+
*/
114+
@Override
115+
public long getUniqueId() {
116+
return ((long) OBJTYPE_FILTER << 32) | (0xffffffffL & (long) id);
117+
}
118+
119+
@Override
120+
public void write(JmeExporter ex) throws IOException {
121+
super.write(ex);
122+
OutputCapsule oc = ex.getCapsule(this);
123+
oc.write(this.volume, "volume", 10.f);
124+
oc.write(this.lowFreqVolume, "lf_volume", 1.0f);
125+
}
126+
127+
@Override
128+
public void read(JmeImporter im) throws IOException {
129+
super.read(im);
130+
InputCapsule ic = im.getCapsule(this);
131+
this.volume = ic.readFloat("volume", 1.0f);
132+
this.lowFreqVolume = ic.readFloat("lf_volume", 1.0f);
133+
}
134+
}

0 commit comments

Comments
 (0)