--- /dev/null
+/*
+ * Copyright (c) 2009-2011 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 com.jme3.audio;
+
+/**
+ * Holds render thread specific audio context information.
+ *
+ * @author Paul Speed
+ */
+public class AudioContext {
+
+ private static ThreadLocal<AudioRenderer> audioRenderer = new ThreadLocal<AudioRenderer>();
+
+ public static void setAudioRenderer( AudioRenderer ar ) {
+ audioRenderer.set(ar);
+ }
+
+ public static AudioRenderer getAudioRenderer() {
+ return audioRenderer.get();
+ }
+}
*/
public class AudioNode extends Node {
- protected AudioRenderer renderer;
-
protected boolean loop = false;
protected float volume = 1;
protected float pitch = 1;
}
/**
- * Serialization only. Do not use.
+ * Creates a new <code>AudioNode</code> without any audio data set.
*/
public AudioNode() {
}
* Creates a new <code>AudioNode</code> without any audio data set.
*
* @param audioRenderer The audio renderer to use for playing. Cannot be null.
+ *
+ * @deprecated AudioRenderer parameter is ignored.
*/
public AudioNode(AudioRenderer audioRenderer) {
- if (audioRenderer == null)
- throw new IllegalArgumentException("audioRenderer cannot be null");
-
- this.renderer = audioRenderer;
}
/**
* @param audioRenderer The audio renderer to use for playing. Cannot be null.
* @param audioData The audio data contains the audio track to play.
* @param key The audio key that was used to load the AudioData
+ *
+ * @deprecated AudioRenderer parameter is ignored.
*/
public AudioNode(AudioRenderer audioRenderer, AudioData audioData, AudioKey key) {
- this(audioRenderer);
+ setAudioData(audioData, key);
+ }
+
+ /**
+ * Creates a new <code>AudioNode</code> with the given data and key.
+ *
+ * @param audioData The audio data contains the audio track to play.
+ * @param key The audio key that was used to load the AudioData
+ */
+ public AudioNode(AudioData audioData, AudioKey key) {
setAudioData(audioData, key);
}
* the stream cache is used. When enabled, the audio stream will
* be read entirely but not decoded, allowing features such as
* seeking, looping and determining duration.
+ *
+ * @deprecated AudioRenderer parameter is ignored.
*/
public AudioNode(AudioRenderer audioRenderer, AssetManager assetManager, String name, boolean stream, boolean streamCache) {
- this(audioRenderer);
+ this.key = new AudioKey(name, stream, streamCache);
+ this.data = (AudioData) assetManager.loadAsset(key);
+ }
+
+ /**
+ * Creates a new <code>AudioNode</code> with the given audio file.
+ *
+ * @param assetManager The asset manager to use to load the audio file
+ * @param name The filename of the audio file
+ * @param stream If true, the audio will be streamed gradually from disk,
+ * otherwise, it will be buffered.
+ * @param streamCache If stream is also true, then this specifies if
+ * the stream cache is used. When enabled, the audio stream will
+ * be read entirely but not decoded, allowing features such as
+ * seeking, looping and determining duration.
+ */
+ public AudioNode(AssetManager assetManager, String name, boolean stream, boolean streamCache) {
this.key = new AudioKey(name, stream, streamCache);
this.data = (AudioData) assetManager.loadAsset(key);
}
* @param name The filename of the audio file
* @param stream If true, the audio will be streamed gradually from disk,
* otherwise, it will be buffered.
+ *
+ * @deprecated AudioRenderer parameter is ignored.
*/
public AudioNode(AudioRenderer audioRenderer, AssetManager assetManager, String name, boolean stream) {
this(audioRenderer, assetManager, name, stream, false);
/**
* Creates a new <code>AudioNode</code> with the given audio file.
*
+ * @param assetManager The asset manager to use to load the audio file
+ * @param name The filename of the audio file
+ * @param stream If true, the audio will be streamed gradually from disk,
+ * otherwise, it will be buffered.
+ *
+ * @deprecated AudioRenderer parameter is ignored.
+ */
+ public AudioNode(AssetManager assetManager, String name, boolean stream) {
+ this(assetManager, name, stream, false);
+ }
+
+ /**
+ * Creates a new <code>AudioNode</code> with the given audio file.
+ *
* @param audioRenderer The audio renderer to use for playing. Cannot be null.
* @param assetManager The asset manager to use to load the audio file
* @param name The filename of the audio file
*/
public AudioNode(AudioRenderer audioRenderer, AssetManager assetManager, String name) {
- this(audioRenderer, assetManager, name, false);
+ this(assetManager, name, false);
+ }
+
+ /**
+ * Creates a new <code>AudioNode</code> with the given audio file.
+ *
+ * @param assetManager The asset manager to use to load the audio file
+ * @param name The filename of the audio file
+ */
+ public AudioNode(AssetManager assetManager, String name) {
+ this(assetManager, name, false);
+ }
+
+ protected AudioRenderer getRenderer() {
+ AudioRenderer result = AudioContext.getAudioRenderer();
+ if( result == null )
+ throw new IllegalStateException( "No audio renderer available, make sure call is being performed on render thread." );
+ return result;
}
/**
* Start playing the audio.
*/
public void play(){
- renderer.playSource(this);
+ getRenderer().playSource(this);
}
/**
* instances already playing.
*/
public void playInstance(){
- renderer.playSourceInstance(this);
+ getRenderer().playSourceInstance(this);
}
/**
* Stop playing the audio that was started with {@link AudioNode#play() }.
*/
public void stop(){
- renderer.stopSource(this);
+ getRenderer().stopSource(this);
}
/**
public void setDryFilter(Filter dryFilter) {
this.dryFilter = dryFilter;
if (channel >= 0)
- renderer.updateSourceParam(this, AudioParam.DryFilter);
+ getRenderer().updateSourceParam(this, AudioParam.DryFilter);
}
/**
public void setLooping(boolean loop) {
this.loop = loop;
if (channel >= 0)
- renderer.updateSourceParam(this, AudioParam.Looping);
+ getRenderer().updateSourceParam(this, AudioParam.Looping);
}
/**
this.pitch = pitch;
if (channel >= 0)
- renderer.updateSourceParam(this, AudioParam.Pitch);
+ getRenderer().updateSourceParam(this, AudioParam.Pitch);
}
/**
this.volume = volume;
if (channel >= 0)
- renderer.updateSourceParam(this, AudioParam.Volume);
+ getRenderer().updateSourceParam(this, AudioParam.Volume);
}
/**
public void setVelocity(Vector3f velocity) {
this.velocity.set(velocity);
if (channel >= 0)
- renderer.updateSourceParam(this, AudioParam.Velocity);
+ getRenderer().updateSourceParam(this, AudioParam.Velocity);
}
/**
public void setReverbEnabled(boolean reverbEnabled) {
this.reverbEnabled = reverbEnabled;
if (channel >= 0)
- renderer.updateSourceParam(this, AudioParam.ReverbEnabled);
+ getRenderer().updateSourceParam(this, AudioParam.ReverbEnabled);
}
/**
public void setReverbFilter(Filter reverbFilter) {
this.reverbFilter = reverbFilter;
if (channel >= 0)
- renderer.updateSourceParam(this, AudioParam.ReverbFilter);
+ getRenderer().updateSourceParam(this, AudioParam.ReverbFilter);
}
/**
this.maxDistance = maxDistance;
if (channel >= 0)
- renderer.updateSourceParam(this, AudioParam.MaxDistance);
+ getRenderer().updateSourceParam(this, AudioParam.MaxDistance);
}
/**
this.refDistance = refDistance;
if (channel >= 0)
- renderer.updateSourceParam(this, AudioParam.RefDistance);
+ getRenderer().updateSourceParam(this, AudioParam.RefDistance);
}
/**
public void setDirectional(boolean directional) {
this.directional = directional;
if (channel >= 0)
- renderer.updateSourceParam(this, AudioParam.IsDirectional);
+ getRenderer().updateSourceParam(this, AudioParam.IsDirectional);
}
/**
public void setDirection(Vector3f direction) {
this.direction = direction;
if (channel >= 0)
- renderer.updateSourceParam(this, AudioParam.Direction);
+ getRenderer().updateSourceParam(this, AudioParam.Direction);
}
/**
public void setInnerAngle(float innerAngle) {
this.innerAngle = innerAngle;
if (channel >= 0)
- renderer.updateSourceParam(this, AudioParam.InnerAngle);
+ getRenderer().updateSourceParam(this, AudioParam.InnerAngle);
}
/**
public void setOuterAngle(float outerAngle) {
this.outerAngle = outerAngle;
if (channel >= 0)
- renderer.updateSourceParam(this, AudioParam.OuterAngle);
+ getRenderer().updateSourceParam(this, AudioParam.OuterAngle);
}
/**
public void setPositional(boolean positional) {
this.positional = positional;
if (channel >= 0)
- renderer.updateSourceParam(this, AudioParam.IsPositional);
+ getRenderer().updateSourceParam(this, AudioParam.IsPositional);
}
@Override
super.updateGeometricState();
if (updatePos && channel >= 0)
- renderer.updateSourceParam(this, AudioParam.Position);
+ getRenderer().updateSourceParam(this, AudioParam.Position);
}
@Override