aboutsummaryrefslogtreecommitdiff
path: root/engine/src/test/jme3test/audio
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/test/jme3test/audio')
-rw-r--r--engine/src/test/jme3test/audio/TestAmbient.java83
-rw-r--r--engine/src/test/jme3test/audio/TestDoppler.java104
-rw-r--r--engine/src/test/jme3test/audio/TestMusicPlayer.form117
-rw-r--r--engine/src/test/jme3test/audio/TestMusicPlayer.java298
-rw-r--r--engine/src/test/jme3test/audio/TestMusicStreaming.java56
-rw-r--r--engine/src/test/jme3test/audio/TestOgg.java68
-rw-r--r--engine/src/test/jme3test/audio/TestReverb.java79
-rw-r--r--engine/src/test/jme3test/audio/TestWav.java60
8 files changed, 865 insertions, 0 deletions
diff --git a/engine/src/test/jme3test/audio/TestAmbient.java b/engine/src/test/jme3test/audio/TestAmbient.java
new file mode 100644
index 0000000..c6b38c2
--- /dev/null
+++ b/engine/src/test/jme3test/audio/TestAmbient.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2009-2010 jMonkeyEngine All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package jme3test.audio;
+
+import com.jme3.app.SimpleApplication;
+import com.jme3.audio.AudioNode;
+import com.jme3.audio.Environment;
+import com.jme3.material.Material;
+import com.jme3.math.ColorRGBA;
+import com.jme3.math.Vector3f;
+import com.jme3.scene.Geometry;
+import com.jme3.scene.shape.Box;
+
+public class TestAmbient extends SimpleApplication {
+
+ private AudioNode nature, waves;
+
+ public static void main(String[] args) {
+ TestAmbient test = new TestAmbient();
+ test.start();
+ }
+
+ @Override
+ public void simpleInitApp() {
+ 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};
+ Environment env = new Environment(eax);
+ audioRenderer.setEnvironment(env);
+
+ waves = new AudioNode(assetManager, "Sound/Environment/Ocean Waves.ogg", false);
+ waves.setPositional(true);
+ waves.setLocalTranslation(new Vector3f(0, 0,0));
+ waves.setMaxDistance(100);
+ waves.setRefDistance(5);
+
+ nature = new AudioNode(assetManager, "Sound/Environment/Nature.ogg", true);
+ nature.setVolume(3);
+
+ waves.playInstance();
+ nature.play();
+
+ // just a blue box to mark the spot
+ Box box1 = new Box(Vector3f.ZERO, .5f, .5f, .5f);
+ Geometry player = new Geometry("Player", box1);
+ Material mat1 = new Material(assetManager,
+ "Common/MatDefs/Misc/Unshaded.j3md");
+ mat1.setColor("Color", ColorRGBA.Blue);
+ player.setMaterial(mat1);
+ rootNode.attachChild(player);
+ }
+
+ @Override
+ public void simpleUpdate(float tpf) {
+ }
+}
diff --git a/engine/src/test/jme3test/audio/TestDoppler.java b/engine/src/test/jme3test/audio/TestDoppler.java
new file mode 100644
index 0000000..3368874
--- /dev/null
+++ b/engine/src/test/jme3test/audio/TestDoppler.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2009-2010 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package jme3test.audio;
+
+import com.jme3.app.SimpleApplication;
+import com.jme3.audio.AudioNode;
+import com.jme3.audio.Environment;
+import com.jme3.math.FastMath;
+import com.jme3.math.Vector3f;
+import org.lwjgl.openal.AL10;
+import org.lwjgl.openal.AL11;
+
+/**
+ * Test Doppler Effect
+ */
+public class TestDoppler extends SimpleApplication {
+
+ private AudioNode ufo;
+
+ private float x = 20, z = 0;
+ private float rate = -0.05f;
+ private float xDist = 20;
+ private float zDist = 5;
+ private float angle = FastMath.TWO_PI;
+
+ public static void main(String[] args){
+ TestDoppler test = new TestDoppler();
+ test.start();
+ }
+
+ @Override
+ public void simpleInitApp(){
+ audioRenderer.setEnvironment(Environment.Dungeon);
+ AL10.alDistanceModel(AL11.AL_EXPONENT_DISTANCE);
+
+ ufo = new AudioNode(assetManager, "Sound/Effects/Beep.ogg", false);
+ ufo.setPositional(true);
+ ufo.setLooping(true);
+ ufo.setReverbEnabled(true);
+ ufo.setRefDistance(100000000);
+ ufo.setMaxDistance(100000000);
+ ufo.play();
+ }
+
+ @Override
+ public void simpleUpdate(float tpf){
+ //float x = (float) (Math.cos(angle) * xDist);
+ float dx = (float) Math.sin(angle) * xDist;
+
+ //float z = (float) (Math.sin(angle) * zDist);
+ float dz = (float)(-Math.cos(angle) * zDist);
+
+ x += dx * tpf * 0.05f;
+ z += dz * tpf * 0.05f;
+
+ angle += tpf * rate;
+
+ if (angle > FastMath.TWO_PI){
+ angle = FastMath.TWO_PI;
+ rate = -rate;
+ }else if (angle < -0){
+ angle = -0;
+ rate = -rate;
+ }
+
+ ufo.setVelocity(new Vector3f(dx, 0, dz));
+ ufo.setLocalTranslation(x, 0, z);
+ ufo.updateGeometricState();
+
+ System.out.println("LOC: " + (int)x +", " + (int)z +
+ ", VEL: " + (int)dx + ", " + (int)dz);
+ }
+
+}
diff --git a/engine/src/test/jme3test/audio/TestMusicPlayer.form b/engine/src/test/jme3test/audio/TestMusicPlayer.form
new file mode 100644
index 0000000..dced8a4
--- /dev/null
+++ b/engine/src/test/jme3test/audio/TestMusicPlayer.form
@@ -0,0 +1,117 @@
+<?xml version="1.1" encoding="UTF-8" ?>
+
+<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
+ <Properties>
+ <Property name="defaultCloseOperation" type="int" value="3"/>
+ </Properties>
+ <SyntheticProperties>
+ <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
+ </SyntheticProperties>
+ <Events>
+ <EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="formWindowClosing"/>
+ </Events>
+ <AuxValues>
+ <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
+ <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
+ <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
+ <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
+ <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
+ <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,0,82,0,0,1,-112"/>
+ </AuxValues>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
+ <SubComponents>
+ <Container class="javax.swing.JPanel" name="pnlButtons">
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
+ <BorderConstraints direction="Center"/>
+ </Constraint>
+ </Constraints>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout"/>
+ <SubComponents>
+ <Component class="javax.swing.JSlider" name="sldVolume">
+ <Properties>
+ <Property name="majorTickSpacing" type="int" value="20"/>
+ <Property name="orientation" type="int" value="1"/>
+ <Property name="paintTicks" type="boolean" value="true"/>
+ <Property name="value" type="int" value="100"/>
+ </Properties>
+ <Events>
+ <EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="sldVolumeStateChanged"/>
+ </Events>
+ </Component>
+ <Component class="javax.swing.JButton" name="btnRewind">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="&lt;&lt;"/>
+ </Properties>
+ </Component>
+ <Component class="javax.swing.JButton" name="btnStop">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="[ ]"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnStopActionPerformed"/>
+ </Events>
+ </Component>
+ <Component class="javax.swing.JButton" name="btnPlay">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="II / &gt;"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnPlayActionPerformed"/>
+ </Events>
+ </Component>
+ <Component class="javax.swing.JButton" name="btnFF">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="&gt;&gt;"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnFFActionPerformed"/>
+ </Events>
+ </Component>
+ <Component class="javax.swing.JButton" name="btnOpen">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Open ..."/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnOpenActionPerformed"/>
+ </Events>
+ </Component>
+ </SubComponents>
+ </Container>
+ <Container class="javax.swing.JPanel" name="pnlBar">
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
+ <BorderConstraints direction="First"/>
+ </Constraint>
+ </Constraints>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout"/>
+ <SubComponents>
+ <Component class="javax.swing.JLabel" name="lblTime">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="0:00-0:00"/>
+ <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
+ <Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
+ <EmptyBorder bottom="3" left="3" right="3" top="3"/>
+ </Border>
+ </Property>
+ </Properties>
+ </Component>
+ <Component class="javax.swing.JSlider" name="sldBar">
+ <Properties>
+ <Property name="value" type="int" value="0"/>
+ </Properties>
+ <Events>
+ <EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="sldBarStateChanged"/>
+ </Events>
+ </Component>
+ </SubComponents>
+ </Container>
+ </SubComponents>
+</Form>
diff --git a/engine/src/test/jme3test/audio/TestMusicPlayer.java b/engine/src/test/jme3test/audio/TestMusicPlayer.java
new file mode 100644
index 0000000..9edafad
--- /dev/null
+++ b/engine/src/test/jme3test/audio/TestMusicPlayer.java
@@ -0,0 +1,298 @@
+/*
+ * Copyright (c) 2009-2010 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package jme3test.audio;
+
+import com.jme3.asset.AssetInfo;
+import com.jme3.asset.AssetLoader;
+import com.jme3.audio.AudioNode.Status;
+import com.jme3.audio.*;
+import com.jme3.audio.plugins.OGGLoader;
+import com.jme3.audio.plugins.WAVLoader;
+import com.jme3.system.AppSettings;
+import com.jme3.system.JmeSystem;
+import java.io.*;
+import javax.swing.JFileChooser;
+
+public class TestMusicPlayer extends javax.swing.JFrame {
+
+ private AudioRenderer ar;
+ private AudioData musicData;
+ private AudioNode musicSource;
+ private float musicLength = 0;
+ private float curTime = 0;
+ private Listener listener = new Listener();
+
+ public TestMusicPlayer() {
+ initComponents();
+ setLocationRelativeTo(null);
+ initAudioPlayer();
+ }
+
+ private void initAudioPlayer(){
+ AppSettings settings = new AppSettings(true);
+ settings.setRenderer(null); // disable rendering
+ settings.setAudioRenderer("LWJGL");
+ ar = JmeSystem.newAudioRenderer(settings);
+ ar.initialize();
+ ar.setListener(listener);
+ AudioContext.setAudioRenderer(ar);
+ }
+
+ /** This method is called from within the constructor to
+ * initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is
+ * always regenerated by the Form Editor.
+ */
+ @SuppressWarnings("unchecked")
+ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ pnlButtons = new javax.swing.JPanel();
+ sldVolume = new javax.swing.JSlider();
+ btnRewind = new javax.swing.JButton();
+ btnStop = new javax.swing.JButton();
+ btnPlay = new javax.swing.JButton();
+ btnFF = new javax.swing.JButton();
+ btnOpen = new javax.swing.JButton();
+ pnlBar = new javax.swing.JPanel();
+ lblTime = new javax.swing.JLabel();
+ sldBar = new javax.swing.JSlider();
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+ addWindowListener(new java.awt.event.WindowAdapter() {
+ public void windowClosing(java.awt.event.WindowEvent evt) {
+ formWindowClosing(evt);
+ }
+ });
+
+ pnlButtons.setLayout(new javax.swing.BoxLayout(pnlButtons, javax.swing.BoxLayout.LINE_AXIS));
+
+ sldVolume.setMajorTickSpacing(20);
+ sldVolume.setOrientation(javax.swing.JSlider.VERTICAL);
+ sldVolume.setPaintTicks(true);
+ sldVolume.setValue(100);
+ sldVolume.addChangeListener(new javax.swing.event.ChangeListener() {
+ public void stateChanged(javax.swing.event.ChangeEvent evt) {
+ sldVolumeStateChanged(evt);
+ }
+ });
+ pnlButtons.add(sldVolume);
+
+ btnRewind.setText("<<");
+ pnlButtons.add(btnRewind);
+
+ btnStop.setText("[ ]");
+ btnStop.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ btnStopActionPerformed(evt);
+ }
+ });
+ pnlButtons.add(btnStop);
+
+ btnPlay.setText("II / >");
+ btnPlay.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ btnPlayActionPerformed(evt);
+ }
+ });
+ pnlButtons.add(btnPlay);
+
+ btnFF.setText(">>");
+ btnFF.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ btnFFActionPerformed(evt);
+ }
+ });
+ pnlButtons.add(btnFF);
+
+ btnOpen.setText("Open ...");
+ btnOpen.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ btnOpenActionPerformed(evt);
+ }
+ });
+ pnlButtons.add(btnOpen);
+
+ getContentPane().add(pnlButtons, java.awt.BorderLayout.CENTER);
+
+ pnlBar.setLayout(new javax.swing.BoxLayout(pnlBar, javax.swing.BoxLayout.LINE_AXIS));
+
+ lblTime.setText("0:00-0:00");
+ lblTime.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));
+ pnlBar.add(lblTime);
+
+ sldBar.setValue(0);
+ sldBar.addChangeListener(new javax.swing.event.ChangeListener() {
+ public void stateChanged(javax.swing.event.ChangeEvent evt) {
+ sldBarStateChanged(evt);
+ }
+ });
+ pnlBar.add(sldBar);
+
+ getContentPane().add(pnlBar, java.awt.BorderLayout.PAGE_START);
+
+ pack();
+ }// </editor-fold>//GEN-END:initComponents
+
+ private void btnOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOpenActionPerformed
+ JFileChooser chooser = new JFileChooser();
+ chooser.setAcceptAllFileFilterUsed(true);
+ chooser.setDialogTitle("Select OGG file");
+ chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
+ chooser.setMultiSelectionEnabled(false);
+ if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION){
+ btnStopActionPerformed(null);
+
+ final File selected = chooser.getSelectedFile();
+ AssetLoader loader = null;
+ if(selected.getName().endsWith(".wav")){
+ loader = new WAVLoader();
+ }else{
+ loader = new OGGLoader();
+ }
+
+ AudioKey key = new AudioKey(selected.getName(), true, true);
+ try{
+ musicData = (AudioData) loader.load(new AssetInfo(null, key) {
+ @Override
+ public InputStream openStream() {
+ try{
+ return new FileInputStream(selected);
+ }catch (FileNotFoundException ex){
+ ex.printStackTrace();
+ }
+ return null;
+ }
+ });
+ }catch (IOException ex){
+ ex.printStackTrace();
+ }
+
+ musicSource = new AudioNode(musicData, key);
+ musicLength = musicData.getDuration();
+ updateTime();
+ }
+ }//GEN-LAST:event_btnOpenActionPerformed
+
+ private void updateTime(){
+ int max = (int) (musicLength * 100);
+ int pos = (int) (curTime * 100);
+ sldBar.setMaximum(max);
+ sldBar.setValue(pos);
+
+ int minutesTotal = (int) (musicLength / 60);
+ int secondsTotal = (int) (musicLength % 60);
+ int minutesNow = (int) (curTime / 60);
+ int secondsNow = (int) (curTime % 60);
+ String txt = String.format("%01d:%02d-%01d:%02d", minutesNow, secondsNow,
+ minutesTotal, secondsTotal);
+ lblTime.setText(txt);
+ }
+
+ private void btnPlayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPlayActionPerformed
+ if (musicSource == null){
+ btnOpenActionPerformed(evt);
+ return;
+ }
+
+ if (musicSource.getStatus() == Status.Playing){
+ musicSource.setPitch(1);
+ ar.pauseSource(musicSource);
+ }else{
+ musicSource.setPitch(1);
+ musicSource.play();
+ }
+ }//GEN-LAST:event_btnPlayActionPerformed
+
+ private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
+ ar.cleanup();
+ }//GEN-LAST:event_formWindowClosing
+
+ private void sldVolumeStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_sldVolumeStateChanged
+ listener.setVolume( (float) sldVolume.getValue() / 100f);
+ ar.setListener(listener);
+ }//GEN-LAST:event_sldVolumeStateChanged
+
+ private void btnStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStopActionPerformed
+ if (musicSource != null){
+ musicSource.setPitch(1);
+ ar.stopSource(musicSource);
+ }
+ }//GEN-LAST:event_btnStopActionPerformed
+
+ private void btnFFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFFActionPerformed
+ if (musicSource.getStatus() == Status.Playing){
+ musicSource.setPitch(2);
+ }
+ }//GEN-LAST:event_btnFFActionPerformed
+
+ private void sldBarStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_sldBarStateChanged
+ if (musicSource != null && !sldBar.getValueIsAdjusting()){
+ curTime = sldBar.getValue() / 100f;
+ if (curTime < 0)
+ curTime = 0;
+
+ musicSource.setTimeOffset(curTime);
+// if (musicSource.getStatus() == Status.Playing){
+// musicSource.stop();
+// musicSource.play();
+// }
+ updateTime();
+ }
+ }//GEN-LAST:event_sldBarStateChanged
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String args[]) {
+ java.awt.EventQueue.invokeLater(new Runnable() {
+ public void run() {
+ new TestMusicPlayer().setVisible(true);
+ }
+ });
+ }
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JButton btnFF;
+ private javax.swing.JButton btnOpen;
+ private javax.swing.JButton btnPlay;
+ private javax.swing.JButton btnRewind;
+ private javax.swing.JButton btnStop;
+ private javax.swing.JLabel lblTime;
+ private javax.swing.JPanel pnlBar;
+ private javax.swing.JPanel pnlButtons;
+ private javax.swing.JSlider sldBar;
+ private javax.swing.JSlider sldVolume;
+ // End of variables declaration//GEN-END:variables
+
+}
diff --git a/engine/src/test/jme3test/audio/TestMusicStreaming.java b/engine/src/test/jme3test/audio/TestMusicStreaming.java
new file mode 100644
index 0000000..49159af
--- /dev/null
+++ b/engine/src/test/jme3test/audio/TestMusicStreaming.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2009-2010 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package jme3test.audio;
+
+import com.jme3.app.SimpleApplication;
+import com.jme3.asset.plugins.UrlLocator;
+import com.jme3.audio.AudioNode;
+
+public class TestMusicStreaming extends SimpleApplication {
+
+ public static void main(String[] args){
+ TestMusicStreaming test = new TestMusicStreaming();
+ test.start();
+ }
+
+ @Override
+ public void simpleInitApp(){
+ assetManager.registerLocator("http://www.vorbis.com/music/", UrlLocator.class);
+ AudioNode audioSource = new AudioNode(assetManager, "Lumme-Badloop.ogg", true);
+ audioSource.play();
+ }
+
+ @Override
+ public void simpleUpdate(float tpf){}
+
+} \ No newline at end of file
diff --git a/engine/src/test/jme3test/audio/TestOgg.java b/engine/src/test/jme3test/audio/TestOgg.java
new file mode 100644
index 0000000..59b8d04
--- /dev/null
+++ b/engine/src/test/jme3test/audio/TestOgg.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2009-2010 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package jme3test.audio;
+
+import com.jme3.app.SimpleApplication;
+import com.jme3.audio.AudioNode;
+import com.jme3.audio.LowPassFilter;
+
+public class TestOgg extends SimpleApplication {
+
+ private AudioNode audioSource;
+
+ public static void main(String[] args){
+ TestOgg test = new TestOgg();
+ test.start();
+ }
+
+ @Override
+ public void simpleInitApp(){
+ System.out.println("Playing without filter");
+ audioSource = new AudioNode(assetManager, "Sound/Effects/Foot steps.ogg", true);
+ audioSource.play();
+ }
+
+ @Override
+ public void simpleUpdate(float tpf){
+ if (audioSource.getStatus() != AudioNode.Status.Playing){
+ audioRenderer.deleteAudioData(audioSource.getAudioData());
+
+ System.out.println("Playing with low pass filter");
+ audioSource = new AudioNode(assetManager, "Sound/Effects/Foot steps.ogg", true);
+ audioSource.setDryFilter(new LowPassFilter(1f, .1f));
+ audioSource.setVolume(3);
+ audioSource.play();
+ }
+ }
+
+}
diff --git a/engine/src/test/jme3test/audio/TestReverb.java b/engine/src/test/jme3test/audio/TestReverb.java
new file mode 100644
index 0000000..0a20096
--- /dev/null
+++ b/engine/src/test/jme3test/audio/TestReverb.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2009-2010 jMonkeyEngine All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package jme3test.audio;
+
+import com.jme3.app.SimpleApplication;
+import com.jme3.audio.AudioNode;
+import com.jme3.audio.Environment;
+import com.jme3.math.FastMath;
+import com.jme3.math.Vector3f;
+
+public class TestReverb extends SimpleApplication {
+
+ private AudioNode audioSource;
+ private float time = 0;
+ private float nextTime = 1;
+
+ public static void main(String[] args) {
+ TestReverb test = new TestReverb();
+ test.start();
+ }
+
+ @Override
+ public void simpleInitApp() {
+ audioSource = new AudioNode(assetManager, "Sound/Effects/Bang.wav");
+
+ 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);
+ }
+
+ @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);
+
+ audioSource.setLocalTranslation(v);
+ audioSource.playInstance();
+ time = 0;
+ nextTime = FastMath.nextRandomFloat() * 2 + 0.5f;
+ }
+ }
+}
diff --git a/engine/src/test/jme3test/audio/TestWav.java b/engine/src/test/jme3test/audio/TestWav.java
new file mode 100644
index 0000000..7e73ded
--- /dev/null
+++ b/engine/src/test/jme3test/audio/TestWav.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2009-2010 jMonkeyEngine All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package jme3test.audio;
+
+import com.jme3.app.SimpleApplication;
+import com.jme3.audio.AudioNode;
+
+public class TestWav extends SimpleApplication {
+
+ private float time = 0;
+ private AudioNode audioSource;
+
+ public static void main(String[] args) {
+ TestWav test = new TestWav();
+ test.start();
+ }
+
+ @Override
+ public void simpleUpdate(float tpf) {
+ time += tpf;
+ if (time > 1f) {
+ audioSource.playInstance();
+ time = 0;
+ }
+
+ }
+
+ @Override
+ public void simpleInitApp() {
+ audioSource = new AudioNode(assetManager, "Sound/Effects/Gun.wav", false);
+ audioSource.setLooping(false);
+ }
+}