From df3ce7dec3e6e6906023bf3d2bded7f7ddd7ff06 Mon Sep 17 00:00:00 2001 From: Wyatt Gillette Date: Sat, 3 May 2025 17:51:17 +0200 Subject: [PATCH 1/8] Update TestReverb: code cleanup Refactored the TestReverb example code for improved clarity. This commit restructures the demo to explicitly highlight its individual components, making it easier to understand the flow and functionality. --- .../main/java/jme3test/audio/TestReverb.java | 100 ++++++++++++------ 1 file changed, 65 insertions(+), 35 deletions(-) diff --git a/jme3-examples/src/main/java/jme3test/audio/TestReverb.java b/jme3-examples/src/main/java/jme3test/audio/TestReverb.java index aff0a2d464..602e17a191 100644 --- a/jme3-examples/src/main/java/jme3test/audio/TestReverb.java +++ b/jme3-examples/src/main/java/jme3test/audio/TestReverb.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2012 jMonkeyEngine + * Copyright (c) 2009-2025 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,50 +35,80 @@ import com.jme3.audio.AudioData; import com.jme3.audio.AudioNode; import com.jme3.audio.Environment; +import com.jme3.audio.LowPassFilter; +import com.jme3.material.Material; +import com.jme3.math.ColorRGBA; import com.jme3.math.FastMath; import com.jme3.math.Vector3f; +import com.jme3.scene.Geometry; +import com.jme3.scene.Mesh; +import com.jme3.scene.shape.Box; +import com.jme3.scene.shape.Sphere; +import com.jme3.system.AppSettings; public class TestReverb extends SimpleApplication { - private AudioNode audioSource; - private float time = 0; - private float nextTime = 1; + public static void main(String[] args) { + TestReverb app = new TestReverb(); + app.start(); + } + + private AudioNode audio; + private float time = 0; + private float nextTime = 1; + + @Override + public void simpleInitApp() { + flyCam.setMoveSpeed(25f); + flyCam.setDragToRotate(true); + + cam.setLocation(Vector3f.UNIT_XYZ.mult(50f)); + cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y); + + audioRenderer.setEnvironment(Environment.Cavern); - public static void main(String[] args) { - TestReverb test = new TestReverb(); - test.start(); - } + audio = new AudioNode(assetManager, "Sound/Effects/Bang.wav", AudioData.DataType.Buffer); + audio.setPositional(true); + audio.setReverbEnabled(true); + audio.setReverbFilter(new LowPassFilter(1, 1)); + rootNode.attachChild(audio); - @Override - public void simpleInitApp() { - audioSource = new AudioNode(assetManager, "Sound/Effects/Bang.wav", - AudioData.DataType.Buffer); + Geometry marker = makeShape("Marker", new Sphere(16, 16, .5f), ColorRGBA.Red); + audio.attachChild(marker); - float[] eax = new float[]{15, 38.0f, 0.300f, -1000, -3300, 0, - 1.49f, 0.54f, 1.00f, -2560, 0.162f, 0.00f, 0.00f, 0.00f, - -229, 0.088f, 0.00f, 0.00f, 0.00f, 0.125f, 1.000f, 0.250f, - 0.000f, -5.0f, 5000.0f, 250.0f, 0.00f, 0x3f}; - audioRenderer.setEnvironment(new Environment(eax)); - Environment env = Environment.Cavern; - audioRenderer.setEnvironment(env); - } + Geometry floor = makeShape("Floor", new Box(20f, .05f, 20f), ColorRGBA.Blue); + rootNode.attachChild(floor); + } + + private Geometry makeShape(String name, Mesh mesh, ColorRGBA color) { + Geometry geo = new Geometry(name, mesh); + Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); + mat.setColor("Color", color); + geo.setMaterial(mat); + return geo; + } - @Override - public void simpleUpdate(float tpf) { - time += tpf; + @Override + public void simpleUpdate(float tpf) { + time += tpf; - if (time > nextTime) { - Vector3f v = new Vector3f(); - v.setX(FastMath.nextRandomFloat()); - v.setY(FastMath.nextRandomFloat()); - v.setZ(FastMath.nextRandomFloat()); - v.multLocal(40, 2, 40); - v.subtractLocal(20, 1, 20); + if (time > nextTime) { + time = 0; + nextTime = FastMath.nextRandomFloat() * 2 + 0.5f; + + Vector3f position = getRandomPosition(); + audio.setLocalTranslation(position); + audio.playInstance(); + } + } - audioSource.setLocalTranslation(v); - audioSource.playInstance(); - time = 0; - nextTime = FastMath.nextRandomFloat() * 2 + 0.5f; + private Vector3f getRandomPosition() { + Vector3f vec = new Vector3f(); + vec.setX(FastMath.nextRandomFloat()); + vec.setY(FastMath.nextRandomFloat()); + vec.setZ(FastMath.nextRandomFloat()); + vec.multLocal(40, 2, 40); + vec.subtractLocal(20, 1, 20); + return vec; } - } } From 22c64b1e70a37acf34d1ba6771f6aa348eb0eabe Mon Sep 17 00:00:00 2001 From: Wyatt Gillette Date: Sat, 3 May 2025 19:05:08 +0200 Subject: [PATCH 2/8] Update getRandomPosition() method --- .../src/main/java/jme3test/audio/TestReverb.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jme3-examples/src/main/java/jme3test/audio/TestReverb.java b/jme3-examples/src/main/java/jme3test/audio/TestReverb.java index 602e17a191..7271473142 100644 --- a/jme3-examples/src/main/java/jme3test/audio/TestReverb.java +++ b/jme3-examples/src/main/java/jme3test/audio/TestReverb.java @@ -103,10 +103,10 @@ public void simpleUpdate(float tpf) { } private Vector3f getRandomPosition() { - Vector3f vec = new Vector3f(); - vec.setX(FastMath.nextRandomFloat()); - vec.setY(FastMath.nextRandomFloat()); - vec.setZ(FastMath.nextRandomFloat()); + float x = FastMath.nextRandomFloat(); + float y = FastMath.nextRandomFloat(); + float z = FastMath.nextRandomFloat(); + Vector3f vec = new Vector3f(x, y, z); vec.multLocal(40, 2, 40); vec.subtractLocal(20, 1, 20); return vec; From 3c814471d3d44c9a5a7a825a91653995eeaa9d20 Mon Sep 17 00:00:00 2001 From: Wyatt Gillette Date: Mon, 5 May 2025 22:53:06 +0200 Subject: [PATCH 3/8] Replaced box with grid --- .../src/main/java/jme3test/audio/TestReverb.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/jme3-examples/src/main/java/jme3test/audio/TestReverb.java b/jme3-examples/src/main/java/jme3test/audio/TestReverb.java index 7271473142..62a5d650d7 100644 --- a/jme3-examples/src/main/java/jme3test/audio/TestReverb.java +++ b/jme3-examples/src/main/java/jme3test/audio/TestReverb.java @@ -35,16 +35,14 @@ import com.jme3.audio.AudioData; import com.jme3.audio.AudioNode; import com.jme3.audio.Environment; -import com.jme3.audio.LowPassFilter; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.FastMath; import com.jme3.math.Vector3f; import com.jme3.scene.Geometry; import com.jme3.scene.Mesh; -import com.jme3.scene.shape.Box; +import com.jme3.scene.debug.Grid; import com.jme3.scene.shape.Sphere; -import com.jme3.system.AppSettings; public class TestReverb extends SimpleApplication { @@ -59,7 +57,8 @@ public static void main(String[] args) { @Override public void simpleInitApp() { - flyCam.setMoveSpeed(25f); + + flyCam.setMoveSpeed(50f); flyCam.setDragToRotate(true); cam.setLocation(Vector3f.UNIT_XYZ.mult(50f)); @@ -68,16 +67,14 @@ public void simpleInitApp() { audioRenderer.setEnvironment(Environment.Cavern); audio = new AudioNode(assetManager, "Sound/Effects/Bang.wav", AudioData.DataType.Buffer); - audio.setPositional(true); - audio.setReverbEnabled(true); - audio.setReverbFilter(new LowPassFilter(1, 1)); rootNode.attachChild(audio); Geometry marker = makeShape("Marker", new Sphere(16, 16, .5f), ColorRGBA.Red); audio.attachChild(marker); - Geometry floor = makeShape("Floor", new Box(20f, .05f, 20f), ColorRGBA.Blue); - rootNode.attachChild(floor); + Geometry grid = makeShape("DebugGrid", new Grid(21, 21, 4), ColorRGBA.Blue); + grid.center().move(0, 0, 0); + rootNode.attachChild(grid); } private Geometry makeShape(String name, Mesh mesh, ColorRGBA color) { @@ -111,4 +108,5 @@ private Vector3f getRandomPosition() { vec.subtractLocal(20, 1, 20); return vec; } + } From ad12842c4322df4c8af96cd00ae64f0d9d31938d Mon Sep 17 00:00:00 2001 From: Wyatt Gillette Date: Tue, 6 May 2025 17:55:03 +0200 Subject: [PATCH 4/8] Update TestReverb.java Added more test Environments and some options to enable/disable the Reverb Filter --- .../main/java/jme3test/audio/TestReverb.java | 85 ++++++++++++++++--- 1 file changed, 72 insertions(+), 13 deletions(-) diff --git a/jme3-examples/src/main/java/jme3test/audio/TestReverb.java b/jme3-examples/src/main/java/jme3test/audio/TestReverb.java index 62a5d650d7..8c03b9bf42 100644 --- a/jme3-examples/src/main/java/jme3test/audio/TestReverb.java +++ b/jme3-examples/src/main/java/jme3test/audio/TestReverb.java @@ -35,6 +35,11 @@ import com.jme3.audio.AudioData; import com.jme3.audio.AudioNode; import com.jme3.audio.Environment; +import com.jme3.audio.LowPassFilter; +import com.jme3.input.KeyInput; +import com.jme3.input.controls.ActionListener; +import com.jme3.input.controls.KeyTrigger; +import com.jme3.input.controls.Trigger; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.FastMath; @@ -44,37 +49,65 @@ import com.jme3.scene.debug.Grid; import com.jme3.scene.shape.Sphere; -public class TestReverb extends SimpleApplication { +public class TestReverb extends SimpleApplication implements ActionListener { public static void main(String[] args) { TestReverb app = new TestReverb(); app.start(); } - private AudioNode audio; + private AudioNode audioSource; private float time = 0; private float nextTime = 1; + /** + * ### Effects ### + * Changing a parameter value in the Effect Object after it has been attached to the Auxiliary Effect + * Slot will not affect the effect in the effect slot. To update the parameters of the effect in the effect + * slot, an application must update the parameters of an Effect object and then re-attach it to the + * Auxiliary Effect Slot. + */ + private int index = 0; + private final Environment[] environments = { + Environment.Cavern, + Environment.AcousticLab, + Environment.Closet, + Environment.Dungeon, + Environment.Garage + }; + @Override public void simpleInitApp() { - flyCam.setMoveSpeed(50f); - flyCam.setDragToRotate(true); - - cam.setLocation(Vector3f.UNIT_XYZ.mult(50f)); - cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y); + configureCamera(); - audioRenderer.setEnvironment(Environment.Cavern); + audioRenderer.setEnvironment(environments[index]); - audio = new AudioNode(assetManager, "Sound/Effects/Bang.wav", AudioData.DataType.Buffer); - rootNode.attachChild(audio); + audioSource = new AudioNode(assetManager, "Sound/Effects/Bang.wav", AudioData.DataType.Buffer); + audioSource.setLooping(false); + audioSource.setPositional(true); + audioSource.setMaxDistance(100); + audioSource.setRefDistance(5); + audioSource.setReverbFilter(new LowPassFilter(1f, 1f)); + audioSource.setVolume(1f); + rootNode.attachChild(audioSource); Geometry marker = makeShape("Marker", new Sphere(16, 16, .5f), ColorRGBA.Red); - audio.attachChild(marker); + audioSource.attachChild(marker); Geometry grid = makeShape("DebugGrid", new Grid(21, 21, 4), ColorRGBA.Blue); grid.center().move(0, 0, 0); rootNode.attachChild(grid); + + registerInputMappings(); + } + + private void configureCamera() { + flyCam.setMoveSpeed(50f); + flyCam.setDragToRotate(true); + + cam.setLocation(Vector3f.UNIT_XYZ.mult(50f)); + cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y); } private Geometry makeShape(String name, Mesh mesh, ColorRGBA color) { @@ -94,8 +127,8 @@ public void simpleUpdate(float tpf) { nextTime = FastMath.nextRandomFloat() * 2 + 0.5f; Vector3f position = getRandomPosition(); - audio.setLocalTranslation(position); - audio.playInstance(); + audioSource.setLocalTranslation(position); + audioSource.playInstance(); } } @@ -109,4 +142,30 @@ private Vector3f getRandomPosition() { return vec; } + @Override + public void onAction(String name, boolean isPressed, float tpf) { + if (!isPressed) return; + + if (name.equals("toggleReverbEnabled")) { + boolean reverbEnabled = audioSource.isReverbEnabled(); + audioSource.setReverbEnabled(!reverbEnabled); + System.out.println("reverbEnabled: " + audioSource.isReverbEnabled()); + + } else if (name.equals("nextEnvironment")) { + index = (index + 1) % environments.length; + audioRenderer.setEnvironment(environments[index]); + System.out.println("Next Environment Index: " + index); + } + } + + private void registerInputMappings() { + addMapping("toggleReverbEnabled", new KeyTrigger(KeyInput.KEY_SPACE)); + addMapping("nextEnvironment", new KeyTrigger(KeyInput.KEY_N)); + } + + private void addMapping(String mappingName, Trigger... triggers) { + inputManager.addMapping(mappingName, triggers); + inputManager.addListener(this, mappingName); + } + } From b3fb4588f6efe9a7bf5c1d07a169c9c671e7fd1b Mon Sep 17 00:00:00 2001 From: Wyatt Gillette Date: Wed, 7 May 2025 15:51:46 +0200 Subject: [PATCH 5/8] increase marker sphere radius --- jme3-examples/src/main/java/jme3test/audio/TestReverb.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-examples/src/main/java/jme3test/audio/TestReverb.java b/jme3-examples/src/main/java/jme3test/audio/TestReverb.java index 8c03b9bf42..1af0516dde 100644 --- a/jme3-examples/src/main/java/jme3test/audio/TestReverb.java +++ b/jme3-examples/src/main/java/jme3test/audio/TestReverb.java @@ -92,7 +92,7 @@ public void simpleInitApp() { audioSource.setVolume(1f); rootNode.attachChild(audioSource); - Geometry marker = makeShape("Marker", new Sphere(16, 16, .5f), ColorRGBA.Red); + Geometry marker = makeShape("Marker", new Sphere(16, 16, 1f), ColorRGBA.Red); audioSource.attachChild(marker); Geometry grid = makeShape("DebugGrid", new Grid(21, 21, 4), ColorRGBA.Blue); From 8e35d58832a3b5889fa3c7f693dece9841f3760c Mon Sep 17 00:00:00 2001 From: Wyatt Gillette Date: Thu, 8 May 2025 11:03:59 +0200 Subject: [PATCH 6/8] added comments --- jme3-examples/src/main/java/jme3test/audio/TestReverb.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jme3-examples/src/main/java/jme3test/audio/TestReverb.java b/jme3-examples/src/main/java/jme3test/audio/TestReverb.java index 1af0516dde..177bb93ba0 100644 --- a/jme3-examples/src/main/java/jme3test/audio/TestReverb.java +++ b/jme3-examples/src/main/java/jme3test/audio/TestReverb.java @@ -81,15 +81,16 @@ public void simpleInitApp() { configureCamera(); + // Activate the Environment preset audioRenderer.setEnvironment(environments[index]); + // Activate 3D audio audioSource = new AudioNode(assetManager, "Sound/Effects/Bang.wav", AudioData.DataType.Buffer); audioSource.setLooping(false); audioSource.setPositional(true); audioSource.setMaxDistance(100); audioSource.setRefDistance(5); - audioSource.setReverbFilter(new LowPassFilter(1f, 1f)); - audioSource.setVolume(1f); + audioSource.setReverbEnabled(true); rootNode.attachChild(audioSource); Geometry marker = makeShape("Marker", new Sphere(16, 16, 1f), ColorRGBA.Red); From 9ee8a330263d493640d0ac367fdea5973c37c870 Mon Sep 17 00:00:00 2001 From: Wyatt Gillette Date: Thu, 8 May 2025 11:04:26 +0200 Subject: [PATCH 7/8] remove unused imports --- jme3-examples/src/main/java/jme3test/audio/TestReverb.java | 1 - 1 file changed, 1 deletion(-) diff --git a/jme3-examples/src/main/java/jme3test/audio/TestReverb.java b/jme3-examples/src/main/java/jme3test/audio/TestReverb.java index 177bb93ba0..b3e5eec2a1 100644 --- a/jme3-examples/src/main/java/jme3test/audio/TestReverb.java +++ b/jme3-examples/src/main/java/jme3test/audio/TestReverb.java @@ -35,7 +35,6 @@ import com.jme3.audio.AudioData; import com.jme3.audio.AudioNode; import com.jme3.audio.Environment; -import com.jme3.audio.LowPassFilter; import com.jme3.input.KeyInput; import com.jme3.input.controls.ActionListener; import com.jme3.input.controls.KeyTrigger; From 606d064cce3bb0a5fa3f83bbb12f772798704ac9 Mon Sep 17 00:00:00 2001 From: Wyatt Gillette Date: Thu, 8 May 2025 19:06:42 +0200 Subject: [PATCH 8/8] Update TestReverb: add reverbFilter --- .../src/main/java/jme3test/audio/TestReverb.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/jme3-examples/src/main/java/jme3test/audio/TestReverb.java b/jme3-examples/src/main/java/jme3test/audio/TestReverb.java index b3e5eec2a1..e21a870993 100644 --- a/jme3-examples/src/main/java/jme3test/audio/TestReverb.java +++ b/jme3-examples/src/main/java/jme3test/audio/TestReverb.java @@ -35,6 +35,7 @@ import com.jme3.audio.AudioData; import com.jme3.audio.AudioNode; import com.jme3.audio.Environment; +import com.jme3.audio.LowPassFilter; import com.jme3.input.KeyInput; import com.jme3.input.controls.ActionListener; import com.jme3.input.controls.KeyTrigger; @@ -48,6 +49,9 @@ import com.jme3.scene.debug.Grid; import com.jme3.scene.shape.Sphere; +/** + * @author capdevon + */ public class TestReverb extends SimpleApplication implements ActionListener { public static void main(String[] args) { @@ -86,10 +90,12 @@ public void simpleInitApp() { // Activate 3D audio audioSource = new AudioNode(assetManager, "Sound/Effects/Bang.wav", AudioData.DataType.Buffer); audioSource.setLooping(false); + audioSource.setVolume(1.2f); audioSource.setPositional(true); audioSource.setMaxDistance(100); audioSource.setRefDistance(5); audioSource.setReverbEnabled(true); + audioSource.setReverbFilter(new LowPassFilter(1f, 1f)); rootNode.attachChild(audioSource); Geometry marker = makeShape("Marker", new Sphere(16, 16, 1f), ColorRGBA.Red); @@ -147,9 +153,9 @@ public void onAction(String name, boolean isPressed, float tpf) { if (!isPressed) return; if (name.equals("toggleReverbEnabled")) { - boolean reverbEnabled = audioSource.isReverbEnabled(); - audioSource.setReverbEnabled(!reverbEnabled); - System.out.println("reverbEnabled: " + audioSource.isReverbEnabled()); + boolean reverbEnabled = !audioSource.isReverbEnabled(); + audioSource.setReverbEnabled(reverbEnabled); + System.out.println("reverbEnabled: " + reverbEnabled); } else if (name.equals("nextEnvironment")) { index = (index + 1) % environments.length;