• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Main repository of MikuMikuStudio


Commit MetaInfo

Revisión8b17d76093edd26a38692ac2295fba9e379b9a9a (tree)
Tiempo2003-11-02 08:34:00
AutorAnakan <Anakan@75d0...>
CommiterAnakan

Log Message

sound system sharing buffers

git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@145 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

Cambiar Resumen

Diferencia incremental

Binary files /dev/null and b/data/sound/laser.mp3 differ
Binary files /dev/null and b/data/sound/laser.wav differ
Binary files /dev/null and b/data/sound/tech_idle_loop.wav differ
Binary files /dev/null and b/data/sound/turn.mp3 differ
Binary files a/data/sound/walk.wav and /dev/null differ
--- a/src/com/jme/sound/Playlist.java
+++ b/src/com/jme/sound/IEffect.java
@@ -31,24 +31,20 @@
3131 */
3232
3333 /*
34- * Created on 27 oct. 2003
34+ * Created on 31 oct. 2003
3535 *
3636 */
3737 package com.jme.sound;
3838
39+
40+
3941 /**
4042 * @author Arman Ozcelik
4143 *
4244 */
43-public interface Playlist {
44-
45- public void queueSound(String name);
46-
47- public boolean hasNext();
48-
49- public SoundStream next();
45+public interface IEffect extends ISound{
5046
51- public int length();
47+ public int getName();
5248
5349
5450 }
--- /dev/null
+++ b/src/com/jme/sound/IEffectPlayer.java
@@ -0,0 +1,82 @@
1+/*
2+ * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
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 met:
7+ *
8+ * Redistributions of source code must retain the above copyright notice, this
9+ * list of conditions and the following disclaimer.
10+ *
11+ * Redistributions in binary form must reproduce the above copyright notice,
12+ * this list of conditions and the following disclaimer in the documentation
13+ * and/or other materials provided with the distribution.
14+ *
15+ * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
16+ * names of its contributors may be used to endorse or promote products derived
17+ * from this software without specific prior written permission.
18+ *
19+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+ * POSSIBILITY OF SUCH DAMAGE.
30+ *
31+ */
32+
33+/*
34+ * Created on 31 oct. 2003
35+ *
36+ */
37+package com.jme.sound;
38+
39+import com.jme.math.Vector3f;
40+
41+/**
42+ * @author Arman Ozcelik
43+ *
44+ */
45+public interface IEffectPlayer extends ISource {
46+
47+ public static final int PLAYING = 1;
48+ public static final int LOOPING = 2;
49+ public static final int PAUSED = 3;
50+ public static final int STOPPED = 4;
51+
52+ public void play(IEffect effect);
53+
54+ public void loop(IEffect effect);
55+
56+ public void pause();
57+
58+ public void stop();
59+
60+ public int getStatus();
61+
62+ public Vector3f getPosition();
63+
64+ public void setPosition(Vector3f pos);
65+
66+ public Vector3f getVelocity();
67+
68+ public void setVelocity(Vector3f vel);
69+
70+ public float getPitch();
71+
72+ public void setPitch(float pitch);
73+
74+ public void setVolume(float volume);
75+
76+ public void setPlayersVolume(float volume);
77+
78+ public void setMaxDistance(float maxDistance);
79+
80+ public float getVolume();
81+
82+}
--- /dev/null
+++ b/src/com/jme/sound/IMusic.java
@@ -0,0 +1,48 @@
1+/*
2+ * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
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 met:
7+ *
8+ * Redistributions of source code must retain the above copyright notice, this
9+ * list of conditions and the following disclaimer.
10+ *
11+ * Redistributions in binary form must reproduce the above copyright notice,
12+ * this list of conditions and the following disclaimer in the documentation
13+ * and/or other materials provided with the distribution.
14+ *
15+ * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
16+ * names of its contributors may be used to endorse or promote products derived
17+ * from this software without specific prior written permission.
18+ *
19+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+ * POSSIBILITY OF SUCH DAMAGE.
30+ *
31+ */
32+
33+/*
34+ * Created on 31 oct. 2003
35+ *
36+ */
37+package com.jme.sound;
38+
39+/**
40+ * @author Arman Ozcelik
41+ *
42+ */
43+public interface IMusic extends ISound{
44+
45+ public void setStream(SoundStream stream);
46+
47+
48+}
--- a/src/com/jme/sound/SoundSource.java
+++ b/src/com/jme/sound/IMusicPlayer.java
@@ -31,51 +31,34 @@
3131 */
3232
3333 /*
34- * Created on 23 oct. 2003
34+ * Created on 31 oct. 2003
3535 *
3636 */
3737 package com.jme.sound;
3838
39-import com.jme.math.Vector3f;
40-
4139 /**
4240 * @author Arman Ozcelik
4341 *
4442 */
45-public interface SoundSource {
46-
47- public int getSourceNumber();
48-
49- public void setStream(SoundStream stream);
43+public interface IMusicPlayer extends ISource{
5044
51- public SoundStream getStream();
45+ public static final int PLAYING=1;
46+ public static final int PAUSED=3;
47+ public static final int STOPPED=4;
48+
49+ public void setNumberOfBuffers(int numBuffers);
5250
53- public void play(String name);
51+ public int getNumberOfBuffers();
5452
55- public void stop();
53+ public void play(String song);
5654
5755 public void pause();
5856
59- public void updatePosition(float x, float y, float z);
60-
61- public void updateVelocity(float x, float y, float z);
57+ public void stop();
6258
6359 public boolean isPlaying();
6460
65- public boolean isPaused();
66-
6761 public boolean isStopped();
6862
69- public void setNumberOfBuffers(int buffers);
70-
71- public Vector3f getPosition();
72-
73- public void setMaxVolume(float value);
74-
75- public void setVolume(float factor);
76-
77- public void setPlaylist(Playlist p);
78-
79-
80-
63+ public boolean isPaused();
8164 }
--- a/src/com/jme/sound/SoundRenderer.java
+++ b/src/com/jme/sound/IRenderer.java
@@ -33,14 +33,20 @@ package com.jme.sound;
3333
3434 /**
3535 * @author Arman Ozcelik
36- * @version $Id: SoundRenderer.java,v 1.3 2003-10-25 02:23:09 Anakan Exp $
36+ * @version $Id: IRenderer.java,v 1.1 2003-11-01 23:27:33 Anakan Exp $
3737 */
38-public interface SoundRenderer {
38+public interface IRenderer {
3939
4040
4141 public void addSoundPlayer(Object name);
4242
4343 public void loadSoundAs(String name, String file);
4444
45- public SoundSource getSoundPlayer(Object name);
45+ public IEffectPlayer getSoundPlayer(Object name);
46+
47+ public IMusicPlayer getMusicPlayer();
48+
49+
50+
51+
4652 }
\ No newline at end of file
--- /dev/null
+++ b/src/com/jme/sound/ISound.java
@@ -0,0 +1,53 @@
1+/*
2+ * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
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 met:
7+ *
8+ * Redistributions of source code must retain the above copyright notice, this
9+ * list of conditions and the following disclaimer.
10+ *
11+ * Redistributions in binary form must reproduce the above copyright notice,
12+ * this list of conditions and the following disclaimer in the documentation
13+ * and/or other materials provided with the distribution.
14+ *
15+ * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
16+ * names of its contributors may be used to endorse or promote products derived
17+ * from this software without specific prior written permission.
18+ *
19+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+ * POSSIBILITY OF SUCH DAMAGE.
30+ *
31+ */
32+
33+/*
34+ * Created on 31 oct. 2003
35+ *
36+ */
37+package com.jme.sound;
38+
39+
40+
41+/**
42+ * @author Arman Ozcelik
43+ *
44+ */
45+public interface ISound {
46+
47+ public static final int SOUND_TYPE_MUSIC=1;
48+ public static final int SOUND_TYPE_EFFECT=2;
49+
50+ public int getSoundType();
51+
52+
53+}
--- /dev/null
+++ b/src/com/jme/sound/ISoundBuffer.java
@@ -0,0 +1,68 @@
1+/*
2+ * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
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 met:
7+ *
8+ * Redistributions of source code must retain the above copyright notice, this
9+ * list of conditions and the following disclaimer.
10+ *
11+ * Redistributions in binary form must reproduce the above copyright notice,
12+ * this list of conditions and the following disclaimer in the documentation
13+ * and/or other materials provided with the distribution.
14+ *
15+ * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
16+ * names of its contributors may be used to endorse or promote products derived
17+ * from this software without specific prior written permission.
18+ *
19+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+ * POSSIBILITY OF SUCH DAMAGE.
30+ *
31+ */
32+
33+/*
34+ * Created on 31 oct. 2003
35+ *
36+ */
37+package com.jme.sound;
38+
39+import java.nio.ByteBuffer;
40+
41+/**
42+ * @author Arman Ozcelik
43+ *
44+ */
45+public interface ISoundBuffer {
46+
47+ public static final int MONO8=1;
48+ public static final int MONO16=2;
49+ public static final int STEREO8=3;
50+ public static final int STEREO16=4;
51+
52+
53+ public void load(String name);
54+
55+ public int getBufferNumber();
56+
57+ public ByteBuffer getBufferData();
58+
59+ public int getChannels();
60+
61+ public int getSampleRate();
62+
63+ public void release();
64+
65+
66+
67+
68+}
--- /dev/null
+++ b/src/com/jme/sound/ISource.java
@@ -0,0 +1,53 @@
1+/*
2+ * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
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 met:
7+ *
8+ * Redistributions of source code must retain the above copyright notice, this
9+ * list of conditions and the following disclaimer.
10+ *
11+ * Redistributions in binary form must reproduce the above copyright notice,
12+ * this list of conditions and the following disclaimer in the documentation
13+ * and/or other materials provided with the distribution.
14+ *
15+ * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
16+ * names of its contributors may be used to endorse or promote products derived
17+ * from this software without specific prior written permission.
18+ *
19+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+ * POSSIBILITY OF SUCH DAMAGE.
30+ *
31+ */
32+
33+/*
34+ * Created on 31 oct. 2003
35+ *
36+ */
37+package com.jme.sound;
38+
39+/**
40+ * @author Arman Ozcelik
41+ *
42+ */
43+public interface ISource {
44+
45+ public static final int STREAMING=1;
46+
47+ public static final int BUFFERING=2;
48+
49+ public int getType();
50+
51+ public int getSourceNumber();
52+
53+}
--- /dev/null
+++ b/src/com/jme/sound/LWJGLEffectPlayer.java
@@ -0,0 +1,207 @@
1+/*
2+ * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
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 met:
7+ *
8+ * Redistributions of source code must retain the above copyright notice, this
9+ * list of conditions and the following disclaimer.
10+ *
11+ * Redistributions in binary form must reproduce the above copyright notice,
12+ * this list of conditions and the following disclaimer in the documentation
13+ * and/or other materials provided with the distribution.
14+ *
15+ * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
16+ * names of its contributors may be used to endorse or promote products derived
17+ * from this software without specific prior written permission.
18+ *
19+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+ * POSSIBILITY OF SUCH DAMAGE.
30+ *
31+ */
32+
33+/*
34+ * Created on 31 oct. 2003
35+ *
36+ */
37+package com.jme.sound;
38+
39+import org.lwjgl.openal.AL;
40+
41+import com.jme.math.Vector3f;
42+
43+/**
44+ * @author Arman Ozcelik
45+ *
46+ */
47+public class LWJGLEffectPlayer implements IEffectPlayer {
48+
49+ private int sourceNumber;
50+ private int status;
51+ private Vector3f position;
52+ private Vector3f velocity;
53+ private float gain=1.0f;
54+ private float pitch=1.0f;
55+ private static float maxVolume=1.0f;
56+
57+ public LWJGLEffectPlayer(int playerNumber) {
58+ sourceNumber = playerNumber;
59+ position=new Vector3f(0, 0, 1);
60+ velocity=new Vector3f(0,0,.1f);
61+ }
62+
63+ public void play(IEffect effect) {
64+ if(effect==null) return;
65+ status=PLAYING;
66+ AL.alGetError();
67+ if (AL.alGetError() != AL.AL_NO_ERROR) {
68+ System.err.println("Error generating audio source.");
69+ }
70+ AL.alSourcei(sourceNumber, AL.AL_BUFFER, effect.getName());
71+ AL.alSourcef(sourceNumber, AL.AL_PITCH, getPitch());
72+ AL.alSourcef(sourceNumber, AL.AL_GAIN, getVolume());
73+ AL.alSource3f(
74+ sourceNumber,
75+ AL.AL_POSITION,
76+ getPosition().x,
77+ getPosition().y,
78+ getPosition().z);
79+ AL.alSource3f(
80+ sourceNumber,
81+ AL.AL_VELOCITY,
82+ getVelocity().x,
83+ getVelocity().y,
84+ getVelocity().z);
85+ AL.alSourcei(sourceNumber, AL.AL_LOOPING, AL.AL_FALSE);
86+
87+ AL.alSourcePlay(sourceNumber);
88+
89+
90+ }
91+
92+ /* (non-Javadoc)
93+ * @see com.jme.sound.IEffectPlayer#loop(com.jme.sound.IEffect, int)
94+ */
95+ public void loop(IEffect effect) {
96+ if(effect==null) return;
97+ status=LOOPING;
98+ AL.alGetError();
99+ if (AL.alGetError() != AL.AL_NO_ERROR) {
100+ System.err.println("Error generating audio source.");
101+ }
102+ AL.alSourcei(sourceNumber, AL.AL_BUFFER, effect.getName());
103+ AL.alSourcef(sourceNumber, AL.AL_PITCH, getPitch());
104+ AL.alSourcef(sourceNumber, AL.AL_GAIN, getVolume());
105+ AL.alSource3f(
106+ sourceNumber,
107+ AL.AL_POSITION,
108+ getPosition().x,
109+ getPosition().y,
110+ getPosition().z);
111+ AL.alSource3f(
112+ sourceNumber,
113+ AL.AL_VELOCITY,
114+ getVelocity().x,
115+ getVelocity().y,
116+ getVelocity().z);
117+ AL.alSourcei(sourceNumber, AL.AL_LOOPING, AL.AL_TRUE);
118+
119+ AL.alSourcePlay(sourceNumber);
120+
121+ }
122+
123+
124+ public void pause() {
125+ AL.alSourcePause(sourceNumber);
126+ }
127+
128+ public void stop() {
129+ AL.alSourceStop(sourceNumber);
130+ status = STOPPED;
131+ }
132+
133+ public int getStatus() {
134+ if(AL.alGetSourcei(sourceNumber, AL.AL_SOURCE_STATE) != AL.AL_PLAYING){
135+ status=STOPPED;
136+ }
137+ return status;
138+ }
139+
140+ public int getType() {
141+ return BUFFERING;
142+ }
143+
144+ public int getSourceNumber() {
145+ return sourceNumber;
146+ }
147+
148+
149+ public Vector3f getPosition() {
150+ return position;
151+ }
152+
153+
154+ public void setPosition(Vector3f pos) {
155+ position.x=pos.x;
156+ position.y=pos.y;
157+ position.z=pos.z;
158+
159+ }
160+
161+
162+ public Vector3f getVelocity() {
163+
164+ return velocity;
165+ }
166+
167+
168+ public void setVelocity(Vector3f vel) {
169+ velocity.x=vel.x;
170+ velocity.y=vel.y;
171+ velocity.z=vel.z;
172+ }
173+
174+
175+ public float getPitch() {
176+ return pitch;
177+ }
178+
179+
180+
181+ public void setPitch(float pitch) {
182+ this.pitch=pitch;
183+ }
184+
185+
186+ public void setVolume(float volume) {
187+ gain=volume*maxVolume;
188+ }
189+
190+
191+ public float getVolume() {
192+ return gain;
193+ }
194+
195+
196+ public void setPlayersVolume(float volume) {
197+ maxVolume=volume;
198+ }
199+
200+
201+ public void setMaxDistance(float maxDistance) {
202+ AL.alSourcef(sourceNumber, AL.AL_MAX_DISTANCE, maxDistance);
203+ }
204+
205+
206+
207+}
--- /dev/null
+++ b/src/com/jme/sound/LWJGLMP3Buffer.java
@@ -0,0 +1,76 @@
1+/*
2+ * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
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 met:
7+ *
8+ * Redistributions of source code must retain the above copyright notice, this
9+ * list of conditions and the following disclaimer.
10+ *
11+ * Redistributions in binary form must reproduce the above copyright notice,
12+ * this list of conditions and the following disclaimer in the documentation
13+ * and/or other materials provided with the distribution.
14+ *
15+ * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
16+ * names of its contributors may be used to endorse or promote products derived
17+ * from this software without specific prior written permission.
18+ *
19+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+ * POSSIBILITY OF SUCH DAMAGE.
30+ *
31+ */
32+
33+/*
34+ * Created on 1 nov. 2003
35+ *
36+ */
37+package com.jme.sound;
38+
39+import java.nio.ByteBuffer;
40+import java.nio.ByteOrder;
41+import java.nio.IntBuffer;
42+
43+import org.lwjgl.openal.AL;
44+
45+/**
46+ * @author Arman Ozcelik
47+ *
48+ */
49+public class LWJGLMP3Buffer extends MP3Buffer {
50+
51+ IntBuffer buffer;
52+
53+ public LWJGLMP3Buffer() {
54+ buffer= ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
55+ AL.alGenBuffers(buffer);
56+ }
57+
58+ public int getBufferNumber() {
59+
60+ return buffer.get(0);
61+ }
62+
63+ public int getChannels() {
64+ switch (channels) {
65+ case MONO8 :
66+ return AL.AL_FORMAT_MONO8;
67+ case MONO16 :
68+ return AL.AL_FORMAT_MONO16;
69+ case STEREO8 :
70+ return AL.AL_FORMAT_STEREO8;
71+ case STEREO16 :
72+ return AL.AL_FORMAT_STEREO16;
73+ }
74+ return 0;
75+ }
76+}
--- a/src/com/jme/sound/LWJGLMP3Stream.java
+++ b/src/com/jme/sound/LWJGLMP3Stream.java
@@ -1,24 +1,3 @@
1-package com.jme.sound;
2-import java.io.BufferedInputStream;
3-import java.io.ByteArrayOutputStream;
4-import java.io.FileInputStream;
5-import java.io.IOException;
6-import java.io.InputStream;
7-import java.nio.ByteBuffer;
8-import java.nio.ByteOrder;
9-import java.nio.IntBuffer;
10-
11-import javax.sound.sampled.AudioFormat;
12-
13-import org.lwjgl.openal.AL;
14-
15-import javazoom.jl.decoder.Bitstream;
16-import javazoom.jl.decoder.BitstreamException;
17-import javazoom.jl.decoder.Decoder;
18-import javazoom.jl.decoder.DecoderException;
19-import javazoom.jl.decoder.Header;
20-import javazoom.jl.decoder.SampleBuffer;
21-
221 /*
232 * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
243 * All rights reserved.
@@ -60,6 +39,25 @@ import javazoom.jl.decoder.SampleBuffer;
6039 * @author Arman Ozcelik
6140 *
6241 */
42+package com.jme.sound;
43+import java.io.BufferedInputStream;
44+import java.io.FileInputStream;
45+import java.io.IOException;
46+import java.io.InputStream;
47+import java.nio.ByteBuffer;
48+import java.nio.ByteOrder;
49+import java.nio.IntBuffer;
50+
51+import javax.sound.sampled.AudioFormat;
52+
53+import org.lwjgl.openal.AL;
54+
55+import javazoom.jl.decoder.Bitstream;
56+import javazoom.jl.decoder.BitstreamException;
57+import javazoom.jl.decoder.Decoder;
58+import javazoom.jl.decoder.DecoderException;
59+import javazoom.jl.decoder.Header;
60+import javazoom.jl.decoder.SampleBuffer;
6361 public class LWJGLMP3Stream implements SoundStream {
6462
6563 private AudioFormat format;
@@ -140,8 +138,6 @@ public class LWJGLMP3Stream implements SoundStream {
140138
141139 public ByteBuffer read() throws IOException {
142140 try {
143-
144- ByteArrayOutputStream buffer = new ByteArrayOutputStream();
145141 Header header = stream.readFrame();
146142 if (header == null) {
147143 //TODO reload?
@@ -149,25 +145,24 @@ public class LWJGLMP3Stream implements SoundStream {
149145 }
150146 if (sampleBuf == null) {
151147 sampleBuf =
152- new SampleBuffer(
153- header.frequency(),
154- (header.mode() == Header.SINGLE_CHANNEL) ? 1 : 2);
148+ new SampleBuffer(header.frequency(), (header.mode() == Header.SINGLE_CHANNEL) ? 1 : 2);
155149 decoder.setOutputBuffer(sampleBuf);
156150 }
157- channels =
158- (header.mode() == Header.SINGLE_CHANNEL)
159- ? AL.AL_FORMAT_MONO16
160- : AL.AL_FORMAT_STEREO16;
161- sampleRate = header.frequency();
162- sampleBuf = (SampleBuffer) decoder.decodeFrame(header, stream);
151+ if (channels == 0) {
152+ channels =
153+ (header.mode() == Header.SINGLE_CHANNEL) ? AL.AL_FORMAT_MONO8 : AL.AL_FORMAT_STEREO16;
154+ }
155+ if (sampleRate == 0) {
156+ sampleRate = header.frequency();
157+ }
158+ //sampleBuf = (SampleBuffer) decoder.decodeFrame(header, stream);
159+ decoder.decodeFrame(header, stream);
163160 stream.closeFrame();
164-
165- buffer.write(toByteArray(sampleBuf.getBuffer(), 0, sampleBuf.getBufferLength()));
166- ByteBuffer obuf = ByteBuffer.allocateDirect(buffer.size());
167- obuf.put(buffer.toByteArray());
168- obuf.rewind();
169- return obuf;
170-
161+ byte[] obuf = toByteArray(sampleBuf.getBuffer(), 0, sampleBuf.getBufferLength());
162+ ByteBuffer buf = ByteBuffer.allocateDirect(obuf.length);
163+ buf.put(obuf);
164+ buf.rewind();
165+ return buf;
171166 } catch (BitstreamException bs) {
172167 bs.printStackTrace();
173168 } catch (DecoderException e) {
@@ -188,11 +183,9 @@ public class LWJGLMP3Stream implements SoundStream {
188183 protected byte[] toByteArray(short[] samples, int offs, int len) {
189184 byte[] b = new byte[len * 2];
190185 int idx = 0;
191- short s;
192186 while (len-- > 0) {
193- s = samples[offs++];
194- b[idx++] = (byte) (s & 0x00FF);
195- b[idx++] = (byte) ((s >>> 8) & 0x00FF);
187+ b[idx++] = (byte) (samples[offs++] & 0x00FF);
188+ b[idx++] = (byte) ((samples[offs] >>> 8) & 0x00FF);
196189 }
197190 return b;
198191 }
--- a/src/com/jme/sound/LWJGLSoundRenderer.java
+++ b/src/com/jme/sound/LWJGLSoundRenderer.java
@@ -37,26 +37,29 @@ import java.nio.IntBuffer;
3737
3838 import org.lwjgl.openal.AL;
3939
40-
41-import com.jme.sound.utils.StreamRepository;
42-import com.jme.sound.utils.SourceRepository;
43-
44-
40+import com.jme.sound.utils.EffectPlayerRepository;
41+import com.jme.sound.utils.EffectRepository;
4542
4643 /**
4744 * @author Arman Ozcelik
48- * @version $Id: LWJGLSoundRenderer.java,v 1.3 2003-10-25 02:23:09 Anakan Exp $
45+ * @version $Id: LWJGLSoundRenderer.java,v 1.4 2003-11-01 23:28:10 Anakan Exp $
4946 */
50-public class LWJGLSoundRenderer implements SoundRenderer {
51-
52- private float[] listenerPos = { 0.0f, 0.0f, 0.0f };
47+public class LWJGLSoundRenderer implements IRenderer {
48+
49+ private float[] listenerPos= { 0.0f, 0.0f, 0.0f };
5350 //Velocity of the listener.
54- private float[] listenerVel = { 0.0f, 0.0f, 0.0f };
51+ private float[] listenerVel= { 0.0f, 0.0f, 0.0f };
5552 //Orientation of the listener. (first 3 elements are "at", second 3 are "up")
56- private float[] listenerOri = { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f };
53+ private float[] listenerOri= { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f };
54+
55+ private IMusicPlayer player;
5756
5857 public LWJGLSoundRenderer() {
58+ IntBuffer source= ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
59+ AL.alGenSources(source);
60+ player= new LWJGLSource(source.get(0));
5961 setListenerValues();
62+
6063 }
6164
6265 private void setListenerValues() {
@@ -65,24 +68,46 @@ public class LWJGLSoundRenderer implements SoundRenderer {
6568 AL.alListener3f(AL.AL_ORIENTATION, listenerOri[0], listenerOri[1], listenerOri[2]);
6669 }
6770
68-
69-
70- public void addSoundPlayer(Object name){
71- IntBuffer source=ByteBuffer.allocateDirect(4 ).order(ByteOrder.nativeOrder()).asIntBuffer();
71+ public void addSoundPlayer(Object name) {
72+ IntBuffer source= ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
7273 AL.alGenSources(source);
73- SourceRepository.getRepository().bind(name, new LWJGLSource(source.get(0)));
74+ EffectPlayerRepository.getRepository().bind(name, new LWJGLEffectPlayer(source.get(0)));
75+ }
76+
77+ public void loadSoundAs(String name, String file) {
78+ ISoundBuffer buffer= null;
79+ if (file.endsWith(".wav")) {
80+ System.out.println("Loading " + file + " as " + name);
81+ buffer= new LWJGLWaveBuffer();
82+ buffer.load(file);
83+ }
84+ if (file.endsWith(".mp3")) {
85+ System.out.println("Loading " + file + " as " + name);
86+ buffer= new LWJGLMP3Buffer();
87+ buffer.load(file);
88+ }
89+
90+ AL.alBufferData(
91+ buffer.getBufferNumber(),
92+ buffer.getChannels(),
93+ buffer.getBufferData(),
94+ buffer.getBufferData().capacity(),
95+ buffer.getSampleRate());
96+ if (AL.alGetError() != AL.AL_NO_ERROR) {
97+ System.err.println("Error generating audio buffer");
98+ }
99+ SoundEffect effect= new SoundEffect(buffer.getBufferNumber(), IEffect.SOUND_TYPE_EFFECT);
100+ EffectRepository.getRepository().bind(name, effect);
101+ buffer.release();
74102 }
75-
76-
77-
78- public void loadSoundAs(String name, String file){
79- StreamRepository.getInstance().bind(name, file);
103+
104+ public IEffectPlayer getSoundPlayer(Object name) {
105+ return EffectPlayerRepository.getRepository().getSource(name);
80106 }
81107
82-
83- public SoundSource getSoundPlayer(Object name) {
84- return SourceRepository.getRepository().getSource(name);
108+ public IMusicPlayer getMusicPlayer() {
109+
110+ return player;
85111 }
86-
87112
88113 }
--- a/src/com/jme/sound/LWJGLSoundSystem.java
+++ b/src/com/jme/sound/LWJGLSoundSystem.java
@@ -36,15 +36,16 @@ import org.lwjgl.openal.AL;
3636
3737 /**
3838 * @author Arman Ozcelik
39- * @version $Id: LWJGLSoundSystem.java,v 1.4 2003-10-28 16:33:26 Anakan Exp $
39+ * @version $Id: LWJGLSoundSystem.java,v 1.5 2003-11-01 23:28:10 Anakan Exp $
4040 */
4141 public class LWJGLSoundSystem extends SoundSystem {
4242
43- private LWJGLSoundRenderer renderer;
44- private boolean created;
43+ private LWJGLSoundRenderer renderer;
4544
4645 public LWJGLSoundSystem(){
47- initOpenAL();
46+ if(!created){
47+ initOpenAL();
48+ }
4849 renderer=new LWJGLSoundRenderer();
4950 created = true;
5051
@@ -53,7 +54,7 @@ public class LWJGLSoundSystem extends SoundSystem {
5354 /**
5455 * TODO Comment
5556 */
56- public SoundRenderer getRenderer() {
57+ public IRenderer getRenderer() {
5758 return renderer;
5859 }
5960
@@ -71,7 +72,6 @@ public class LWJGLSoundSystem extends SoundSystem {
7172 private void initOpenAL() {
7273 try {
7374 AL.create();
74- Thread.sleep(1000);
7575 } catch (Exception e) {
7676 e.printStackTrace();
7777 }
--- a/src/com/jme/sound/LWJGLSource.java
+++ b/src/com/jme/sound/LWJGLSource.java
@@ -40,30 +40,32 @@ import java.io.IOException;
4040 import java.nio.ByteBuffer;
4141 import java.nio.ByteOrder;
4242 import java.nio.IntBuffer;
43+import java.util.logging.Level;
4344
4445 import org.lwjgl.openal.AL;
4546
4647 import com.jme.math.Vector3f;
47-import com.jme.sound.utils.StreamRepository;
48+import com.jme.util.LoggingSystem;
4849
4950 /**
5051 * @author Arman Ozcelik
5152 *
5253 */
53-public class LWJGLSource implements SoundSource {
54+public class LWJGLSource implements IMusicPlayer {
5455
5556 private int sourceNumber;
5657 private SoundStream stream;
5758 private boolean paused, playing;
5859 private BufferedPlayer player;
59- private int numberOfBuffers = 1;
60+ private int numberOfBuffers= 1;
6061 private Vector3f position;
61- private Playlist playList;
6262
6363 public LWJGLSource(int sourceNum) {
64- this.sourceNumber = sourceNum;
65- position = new Vector3f();
66- player = new BufferedPlayer();
64+ this.sourceNumber= sourceNum;
65+ position= new Vector3f();
66+ player= new BufferedPlayer();
67+ player.start();
68+ LoggingSystem.getLogger().log(Level.INFO, "LWJGLSoundSource created. SourceNumber: " + sourceNum);
6769 }
6870
6971 /**
@@ -82,7 +84,7 @@ public class LWJGLSource implements SoundSource {
8284 stop();
8385 }
8486 stream.close();
85- this.stream = stream;
87+ this.stream= stream;
8688 }
8789
8890 /**
@@ -99,24 +101,20 @@ public class LWJGLSource implements SoundSource {
99101 * If the sound type is wave then the number of buffers is set to 1.
100102 * @param name the sound name.
101103 */
102- public void play(String name) {
103-
104- if (playList != null && playList.hasNext()){
105-
106- }else {
107- String file = StreamRepository.getInstance().getStream(name);
108- if (file.endsWith(".mp3")) {
109- if (numberOfBuffers < 8)
110- numberOfBuffers = 8;
111- setStream(new LWJGLMP3Stream(file));
112- }
113- if (file.endsWith(".wav")) {
114- setNumberOfBuffers(1);
115- setStream(new LWJGLWaveStream(file));
116- }
104+ public void play(String file) {
105+ playing= true;
106+ paused= false;
107+ //String file= StreamRepository.getInstance().getStream(name);
108+ if (file.endsWith(".mp3")) {
109+ if (numberOfBuffers < 8)
110+ numberOfBuffers= 128;
111+ setStream(new LWJGLMP3Stream(file));
117112 }
118- player = new BufferedPlayer();
119- player.start();
113+ if (file.endsWith(".wav")) {
114+ setNumberOfBuffers(1);
115+ setStream(new LWJGLWaveStream(file));
116+ }
117+
120118
121119 }
122120
@@ -129,7 +127,7 @@ public class LWJGLSource implements SoundSource {
129127 * @param z the z position of the source
130128 */
131129 public void updatePosition(float x, float y, float z) {
132- Vector3f newPos = new Vector3f(x, y, z);
130+ Vector3f newPos= new Vector3f(x, y, z);
133131 updatePosition(newPos);
134132 }
135133
@@ -140,10 +138,10 @@ public class LWJGLSource implements SoundSource {
140138 * @param pos the new position of the source
141139 */
142140 public void updatePosition(Vector3f pos) {
143- position.x = pos.x;
144- position.y = pos.y;
145- position.z = pos.z;
146- float length = position.length();
141+ position.x= pos.x;
142+ position.y= pos.y;
143+ position.z= pos.z;
144+ float length= position.length();
147145 if (isPlaying() && !isPaused()) {
148146 AL.alSource3f(
149147 sourceNumber,
@@ -182,19 +180,19 @@ public class LWJGLSource implements SoundSource {
182180
183181 public void stop() {
184182 AL.alSourceStop(sourceNumber);
185- playing = false;
186- paused = false;
183+ playing= false;
184+ paused= false;
187185 }
188186
189187 public void pause() {
190188 if (isPlaying()) {
191189 AL.alSourcePause(sourceNumber);
192- paused = true;
190+ paused= true;
193191 }
194192 }
195193
196194 public void setNumberOfBuffers(int buffs) {
197- numberOfBuffers = buffs;
195+ numberOfBuffers= buffs;
198196
199197 }
200198
@@ -212,11 +210,9 @@ public class LWJGLSource implements SoundSource {
212210 private IntBuffer buffers;
213211 private IntBuffer temp;
214212 protected BufferedPlayer() {
215- buffers =
216- ByteBuffer
217- .allocateDirect(4 * numberOfBuffers)
218- .order(ByteOrder.nativeOrder())
219- .asIntBuffer();
213+ buffers=
214+ ByteBuffer.allocateDirect(4 * numberOfBuffers).order(ByteOrder.nativeOrder()).asIntBuffer();
215+ temp= ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
220216 AL.alGenBuffers(buffers);
221217 }
222218
@@ -225,14 +221,12 @@ public class LWJGLSource implements SoundSource {
225221 }
226222
227223 public boolean streamBuffer(int bufferNumber) {
228- ByteBuffer data = null;
224+ ByteBuffer data= null;
229225 try {
230- data = stream.read();
231-
226+ data= stream.read();
232227 if (data.capacity() == 0) {
233228 return false;
234229 }
235-
236230 } catch (IOException e) {
237231 e.printStackTrace();
238232 }
@@ -242,6 +236,8 @@ public class LWJGLSource implements SoundSource {
242236 data,
243237 data.capacity(),
244238 stream.getSampleRate());
239+ data.clear();
240+ data=null;
245241 return true;
246242 }
247243
@@ -249,7 +245,7 @@ public class LWJGLSource implements SoundSource {
249245
250246 if (plays())
251247 return true;
252- for (int a = 0; a < buffers.capacity(); a++) {
248+ for (int a= 0; a < buffers.capacity(); a++) {
253249 if (!streamBuffer(buffers.get(a)))
254250 return false;
255251 }
@@ -259,16 +255,13 @@ public class LWJGLSource implements SoundSource {
259255 }
260256
261257 public boolean update() {
262- boolean active = true;
263- int processed = AL.alGetSourcei(sourceNumber, AL.AL_BUFFERS_PROCESSED);
258+ boolean active= true;
259+ int processed= AL.alGetSourcei(sourceNumber, AL.AL_BUFFERS_PROCESSED);
264260 while ((processed > 0)) {
265-
266261 processed--;
267- temp = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
268-
269262 AL.alSourceUnqueueBuffers(sourceNumber, temp);
263+ active= streamBuffer(temp.get(0));
270264
271- active = streamBuffer(temp.get(0));
272265 AL.alSourceQueueBuffers(sourceNumber, temp);
273266 }
274267
@@ -276,22 +269,16 @@ public class LWJGLSource implements SoundSource {
276269 }
277270
278271 public void run() {
279- if (playList != null && playList.hasNext()) {
280- setStream(playList.next());
281- if(stream.getStreamType()==SoundStream.MP3_SOUND_STREAM){
282- if(numberOfBuffers<8){
283- numberOfBuffers=8;
284- }
285- }
286- if(stream.getStreamType()==SoundStream.WAV_SOUND_STREAM){
287- numberOfBuffers=1;
272+
273+ while (stream == null) {
274+ try {
275+ Thread.sleep(10);
276+ } catch (InterruptedException e) {
277+ e.printStackTrace();
288278 }
289279 }
290- if (stream == null)
291- return; //DISPLAY ERROR?
280+ LoggingSystem.getLogger().log(Level.INFO, "New Stream " + stream);
292281
293- playing = true;
294- paused = false;
295282 playback();
296283 while (update()) {
297284 if (!plays()) {
@@ -300,16 +287,26 @@ public class LWJGLSource implements SoundSource {
300287 }
301288 }
302289 }
290+
303291 AL.alSourceStop(sourceNumber);
304- if(playList !=null && playList.hasNext()) run();//argh recursive call
305- playing = false;
306- paused = false;
292+ AL.alSourceUnqueueBuffers(sourceNumber, buffers);
293+ playing= false;
294+ paused= false;
295+ stream= null;
296+ run();
297+
307298 }
308299
309300 }
301+ /* (non-Javadoc)
302+ * @see com.jme.sound.IMusicPlayer#getNumberOfBuffers()
303+ */
304+ public int getNumberOfBuffers() {
305+ return numberOfBuffers;
306+ }
310307
311- public void setPlaylist(Playlist p) {
312- playList = p;
308+ public int getType() {
309+ return STREAMING;
313310 }
314311
315312 }
--- /dev/null
+++ b/src/com/jme/sound/LWJGLWaveBuffer.java
@@ -0,0 +1,74 @@
1+/*
2+ * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
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 met:
7+ *
8+ * Redistributions of source code must retain the above copyright notice, this
9+ * list of conditions and the following disclaimer.
10+ *
11+ * Redistributions in binary form must reproduce the above copyright notice,
12+ * this list of conditions and the following disclaimer in the documentation
13+ * and/or other materials provided with the distribution.
14+ *
15+ * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
16+ * names of its contributors may be used to endorse or promote products derived
17+ * from this software without specific prior written permission.
18+ *
19+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+ * POSSIBILITY OF SUCH DAMAGE.
30+ *
31+ */
32+
33+/*
34+ * Created on 31 oct. 2003
35+ *
36+ */
37+package com.jme.sound;
38+
39+import java.nio.ByteBuffer;
40+import java.nio.ByteOrder;
41+import java.nio.IntBuffer;
42+
43+import org.lwjgl.openal.AL;
44+
45+/**
46+ * @author Arman Ozcelik
47+ *
48+ */
49+public class LWJGLWaveBuffer extends WaveBuffer {
50+ IntBuffer buffer;
51+
52+ public LWJGLWaveBuffer(){
53+ buffer=ByteBuffer.allocateDirect(4 ).order(ByteOrder.nativeOrder()).asIntBuffer();
54+ AL.alGenBuffers(buffer);
55+ }
56+
57+ public int getBufferNumber() {
58+
59+ return buffer.get(0);
60+ }
61+
62+
63+ public int getChannels() {
64+ switch(channels){
65+ case MONO8: return AL.AL_FORMAT_MONO8;
66+ case MONO16: return AL.AL_FORMAT_MONO16;
67+ case STEREO8: return AL.AL_FORMAT_STEREO8;
68+ case STEREO16:return AL.AL_FORMAT_STEREO16;
69+ }
70+ return 0;
71+ }
72+
73+
74+}
--- a/src/com/jme/sound/LWJGLWaveStream.java
+++ b/src/com/jme/sound/LWJGLWaveStream.java
@@ -36,7 +36,6 @@
3636 */
3737 package com.jme.sound;
3838
39-
4039 import java.io.File;
4140 import java.io.FileNotFoundException;
4241 import java.io.IOException;
@@ -69,7 +68,7 @@ public class LWJGLWaveStream implements SoundStream {
6968 private int length;
7069
7170 private int offset;
72-
71+
7372 private boolean isRead;
7473
7574 /**
@@ -85,7 +84,6 @@ public class LWJGLWaveStream implements SoundStream {
8584
8685 }
8786
88-
8987 private void initChannels() {
9088 // get channels
9189 if (format.getChannels() == 1) {
@@ -111,7 +109,8 @@ public class LWJGLWaveStream implements SoundStream {
111109 }
112110
113111 public ByteBuffer read() throws IOException {
114- if(isRead) return ByteBuffer.allocateDirect(0);
112+ if (isRead)
113+ return ByteBuffer.allocateDirect(0);
115114 try {
116115 audioStream = AudioSystem.getAudioInputStream(new File(file));
117116 } catch (FileNotFoundException e) {
@@ -121,21 +120,24 @@ public class LWJGLWaveStream implements SoundStream {
121120 } catch (IOException e) {
122121 e.printStackTrace();
123122 }
124- format = audioStream.getFormat();
125- sampleRate = (int) format.getSampleRate();
126- initChannels();
127- length =
128- format.getChannels()
129- * (int) audioStream.getFrameLength()
130- * format.getSampleSizeInBits()
131- / 8;
123+ if (format == null) {
124+ format = audioStream.getFormat();
125+ }
126+ if (sampleRate == 0) {
127+ sampleRate = (int) format.getSampleRate();
128+ }
129+ if(channels==0){
130+ initChannels();
131+ }
132+
133+ length = format.getChannels() * (int) audioStream.getFrameLength() * format.getSampleSizeInBits() / 8;
132134 ByteBuffer buffer = null;
133135 byte[] temp = new byte[length];
134136 audioStream.read(temp);
135137 buffer = ByteBuffer.allocateDirect(length);
136138 buffer.put(temp);
137139 buffer.rewind();
138- isRead=true;
140+ isRead = true;
139141 return buffer;
140142
141143 }
@@ -202,9 +204,7 @@ public class LWJGLWaveStream implements SoundStream {
202204 return length;
203205 }
204206
205-
206-
207- public int getStreamType() {
207+ public int getStreamType() {
208208 return WAV_SOUND_STREAM;
209209 }
210210
--- /dev/null
+++ b/src/com/jme/sound/MP3Buffer.java
@@ -0,0 +1,149 @@
1+/*
2+ * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
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 met:
7+ *
8+ * Redistributions of source code must retain the above copyright notice, this
9+ * list of conditions and the following disclaimer.
10+ *
11+ * Redistributions in binary form must reproduce the above copyright notice,
12+ * this list of conditions and the following disclaimer in the documentation
13+ * and/or other materials provided with the distribution.
14+ *
15+ * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
16+ * names of its contributors may be used to endorse or promote products derived
17+ * from this software without specific prior written permission.
18+ *
19+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+ * POSSIBILITY OF SUCH DAMAGE.
30+ *
31+ */
32+
33+/*
34+ * Created on 1 nov. 2003
35+ *
36+ */
37+package com.jme.sound;
38+
39+import java.io.BufferedInputStream;
40+import java.io.ByteArrayOutputStream;
41+import java.io.FileInputStream;
42+import java.io.IOException;
43+import java.io.InputStream;
44+import java.nio.ByteBuffer;
45+
46+import javazoom.jl.decoder.Bitstream;
47+import javazoom.jl.decoder.BitstreamException;
48+import javazoom.jl.decoder.Decoder;
49+import javazoom.jl.decoder.DecoderException;
50+import javazoom.jl.decoder.Header;
51+import javazoom.jl.decoder.SampleBuffer;
52+
53+/**
54+ * @author Arman Ozcelik
55+ *
56+ */
57+public abstract class MP3Buffer implements ISoundBuffer {
58+
59+ private Decoder decoder;
60+
61+ private Bitstream stream;
62+
63+ private SampleBuffer sampleBuf;
64+
65+ private int sampleRate;
66+
67+ protected int channels;
68+
69+ protected ByteBuffer data;
70+
71+ public void load(String file) {
72+ try {
73+ InputStream in= new FileInputStream(file);
74+ BufferedInputStream bin= new BufferedInputStream(in);
75+ decoder= new Decoder();
76+ stream= new Bitstream(bin);
77+ } catch (IOException ioe) {
78+ ioe.printStackTrace();
79+ }
80+ ByteArrayOutputStream out=new ByteArrayOutputStream();
81+ try {
82+ Header header= null;
83+ while ((header= stream.readFrame()) != null) {
84+ if (sampleBuf == null) {
85+ sampleBuf=
86+ new SampleBuffer(
87+ header.frequency(),
88+ (header.mode() == Header.SINGLE_CHANNEL) ? 1 : 2);
89+ decoder.setOutputBuffer(sampleBuf);
90+ }
91+ if (channels == 0) {
92+ channels= (header.mode() == Header.SINGLE_CHANNEL) ? MONO16 : STEREO16;
93+ }
94+ if (sampleRate == 0) {
95+ sampleRate= header.frequency();
96+ }
97+ //sampleBuf = (SampleBuffer) decoder.decodeFrame(header, stream);
98+ decoder.decodeFrame(header, stream);
99+ stream.closeFrame();
100+ out.write(toByteArray(sampleBuf.getBuffer(), 0, sampleBuf.getBufferLength()));
101+
102+ }
103+ byte[] obuf= out.toByteArray();
104+ data= ByteBuffer.allocateDirect(obuf.length);
105+ data.put(obuf);
106+ data.rewind();
107+
108+
109+ } catch (BitstreamException bs) {
110+ bs.printStackTrace();
111+ } catch (DecoderException e) {
112+ e.printStackTrace();
113+ } catch (IOException e) {
114+
115+ e.printStackTrace();
116+ }
117+
118+ }
119+
120+
121+
122+ public ByteBuffer getBufferData() {
123+ return data;
124+ }
125+
126+
127+
128+
129+ public int getSampleRate() {
130+ return sampleRate;
131+ }
132+
133+
134+ public void release() {
135+ data.clear();
136+ data=null;
137+ }
138+
139+ protected byte[] toByteArray(short[] samples, int offs, int len) {
140+ byte[] b= new byte[len * 2];
141+ int idx= 0;
142+ while (len-- > 0) {
143+ b[idx++]= (byte) (samples[offs++] & 0x00FF);
144+ b[idx++]= (byte) ((samples[offs] >>> 8) & 0x00FF);
145+ }
146+ return b;
147+ }
148+
149+}
--- /dev/null
+++ b/src/com/jme/sound/SoundEffect.java
@@ -0,0 +1,62 @@
1+/*
2+ * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
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 met:
7+ *
8+ * Redistributions of source code must retain the above copyright notice, this
9+ * list of conditions and the following disclaimer.
10+ *
11+ * Redistributions in binary form must reproduce the above copyright notice,
12+ * this list of conditions and the following disclaimer in the documentation
13+ * and/or other materials provided with the distribution.
14+ *
15+ * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
16+ * names of its contributors may be used to endorse or promote products derived
17+ * from this software without specific prior written permission.
18+ *
19+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+ * POSSIBILITY OF SUCH DAMAGE.
30+ *
31+ */
32+
33+/*
34+ * Created on 31 oct. 2003
35+ *
36+ */
37+package com.jme.sound;
38+
39+/**
40+ * @author Arman Ozcelik
41+ *
42+ */
43+public class SoundEffect implements IEffect {
44+
45+ private int name;
46+ private int type;
47+
48+ public SoundEffect(int name, int type){
49+ this.name=name;
50+ this.type=type;
51+ }
52+
53+ public int getName() {
54+ return name;
55+ }
56+
57+
58+ public int getSoundType() {
59+ return type;
60+ }
61+
62+}
--- a/src/com/jme/sound/SoundSystem.java
+++ b/src/com/jme/sound/SoundSystem.java
@@ -31,18 +31,18 @@
3131 */
3232 package com.jme.sound;
3333
34-
35-
3634 /**
3735 * @author Arman Ozcelik
38- * @version $Id: SoundSystem.java,v 1.3 2003-10-25 02:23:09 Anakan Exp $
36+ * @version $Id: SoundSystem.java,v 1.4 2003-11-01 23:28:11 Anakan Exp $
3937 */
4038 public abstract class SoundSystem {
4139 /**
4240 * The list of current implemented rendering APIs that subclass SoundSystem.
4341 */
44- public static final String[] rendererNames = { "LWJGL" };
45-
42+ public static final String[] rendererNames= { "LWJGL" };
43+
44+ protected static boolean created;
45+
4646 /**
4747 *
4848 * <code>getSoundSystem</code> is a factory method that creates the
@@ -53,7 +53,7 @@ public abstract class SoundSystem {
5353 * @param key the display system to use.
5454 * @return the appropriate display system specified by the key.
5555 */
56- public static SoundSystem getSoundSystem(String key) {
56+ public static SoundSystem getSoundEffectSystem(String key) {
5757 if ("LWJGL".equalsIgnoreCase(key)) {
5858 return new LWJGLSoundSystem();
5959 }
@@ -72,7 +72,7 @@ public abstract class SoundSystem {
7272 * compatible with the used <code>SoundSystem</code>.
7373 */
7474
75- public abstract SoundRenderer getRenderer();
75+ public abstract IRenderer getRenderer();
7676
7777 /**
7878 * <code>isCreated</code> returns the current status of the sound
@@ -84,9 +84,4 @@ public abstract class SoundSystem {
8484
8585 public abstract boolean isCreated();
8686
87-
88-
89-
90-
91-
9287 }
--- /dev/null
+++ b/src/com/jme/sound/WaveBuffer.java
@@ -0,0 +1,128 @@
1+/*
2+ * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
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 met:
7+ *
8+ * Redistributions of source code must retain the above copyright notice, this
9+ * list of conditions and the following disclaimer.
10+ *
11+ * Redistributions in binary form must reproduce the above copyright notice,
12+ * this list of conditions and the following disclaimer in the documentation
13+ * and/or other materials provided with the distribution.
14+ *
15+ * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
16+ * names of its contributors may be used to endorse or promote products derived
17+ * from this software without specific prior written permission.
18+ *
19+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+ * POSSIBILITY OF SUCH DAMAGE.
30+ *
31+ */
32+
33+/*
34+ * Created on 31 oct. 2003
35+ *
36+ */
37+package com.jme.sound;
38+
39+import java.io.File;
40+import java.io.FileNotFoundException;
41+import java.io.IOException;
42+import java.nio.ByteBuffer;
43+
44+import javax.sound.sampled.AudioFormat;
45+import javax.sound.sampled.AudioInputStream;
46+import javax.sound.sampled.AudioSystem;
47+import javax.sound.sampled.UnsupportedAudioFileException;
48+
49+/**
50+ * @author Arman Ozcelik
51+ *
52+ */
53+public abstract class WaveBuffer implements ISoundBuffer {
54+
55+ protected int bufferNumber;
56+ protected int channels;
57+ protected int sampleRate;
58+ protected ByteBuffer data;
59+ private AudioFormat format;
60+ private AudioInputStream audioStream;
61+
62+ public void load(String file) {
63+ try {
64+ audioStream = AudioSystem.getAudioInputStream(new File(file));
65+ } catch (FileNotFoundException e) {
66+ e.printStackTrace();
67+ } catch (UnsupportedAudioFileException e) {
68+ e.printStackTrace();
69+ } catch (IOException e) {
70+ e.printStackTrace();
71+ }
72+ format = audioStream.getFormat();
73+ sampleRate = (int) format.getSampleRate();
74+ System.out.println("Sample Rate "+sampleRate);
75+ initChannels();
76+ int length =
77+ format.getChannels() * (int) audioStream.getFrameLength() * format.getSampleSizeInBits() / 8;
78+ byte[] temp = new byte[length];
79+ try {
80+ audioStream.read(temp, 0, length);
81+ } catch (IOException e1) {
82+ e1.printStackTrace();
83+ }
84+ data = ByteBuffer.allocateDirect(length);
85+ data.put(temp);
86+ data.rewind();
87+ System.out.println("Data length "+data.capacity());
88+ }
89+
90+ public int getSampleRate() {
91+ return sampleRate;
92+ }
93+
94+ public ByteBuffer getBufferData() {
95+ return data;
96+ }
97+
98+ public void release() {
99+ data.clear();
100+ data = null;
101+ }
102+
103+ private void initChannels() {
104+ // get channels
105+ if (format.getChannels() == 1) {
106+ if (format.getSampleSizeInBits() == 8) {
107+ channels = MONO8;
108+ } else if (format.getSampleSizeInBits() == 16) {
109+ channels = MONO16;
110+ } else {
111+ assert false : "Illegal sample size";
112+ }
113+ } else if (format.getChannels() == 2) {
114+ if (format.getSampleSizeInBits() == 8) {
115+ channels = STEREO8;
116+ } else if (format.getSampleSizeInBits() == 16) {
117+ channels = STEREO16;
118+ } else {
119+ assert false : "Illegal sample size";
120+ }
121+ } else {
122+ assert false : "Only mono or stereo is supported";
123+ }
124+ System.out.println("Channels "+ channels);
125+
126+ }
127+
128+}
--- a/src/com/jme/sound/action/SoundBackwardAction.java
+++ b/src/com/jme/sound/action/SoundBackwardAction.java
@@ -38,7 +38,9 @@ package com.jme.sound.action;
3838
3939 import com.jme.input.action.KeyBackwardAction;
4040 import com.jme.renderer.Camera;
41-import com.jme.sound.SoundSource;
41+import com.jme.sound.IEffectPlayer;
42+import com.jme.sound.utils.EffectRepository;
43+
4244
4345 /**
4446 * @author Arman Ozcelik
@@ -47,13 +49,13 @@ import com.jme.sound.SoundSource;
4749 public class SoundBackwardAction extends KeyBackwardAction {
4850
4951 private String sound;
50- private SoundSource player;
52+ private IEffectPlayer player;
5153
5254 /**
5355 * @param camera
5456 * @param speed
5557 */
56- public SoundBackwardAction(Camera camera, float speed, SoundSource soundPlayer, String soundName) {
58+ public SoundBackwardAction(Camera camera, float speed, IEffectPlayer soundPlayer, String soundName) {
5759 super(camera, speed);
5860 player = soundPlayer;
5961 sound = soundName;
@@ -64,8 +66,8 @@ public class SoundBackwardAction extends KeyBackwardAction {
6466 */
6567 public void performAction(float time) {
6668 super.performAction(time);
67- if (player != null && !player.isPlaying()) {
68- player.play(sound);
69+ if (player != null && player.getStatus() !=IEffectPlayer.PLAYING) {
70+ player.play(EffectRepository.getRepository().getSource(sound));
6971 }
7072 }
7173 }
--- a/src/com/jme/sound/action/SoundForwardAction.java
+++ b/src/com/jme/sound/action/SoundForwardAction.java
@@ -38,7 +38,9 @@ package com.jme.sound.action;
3838
3939 import com.jme.input.action.KeyForwardAction;
4040 import com.jme.renderer.Camera;
41-import com.jme.sound.SoundSource;
41+import com.jme.sound.IEffect;
42+import com.jme.sound.IEffectPlayer;
43+import com.jme.sound.utils.EffectRepository;
4244
4345 /**
4446 * @author Arman Ozcelik
@@ -46,27 +48,29 @@ import com.jme.sound.SoundSource;
4648 */
4749 public class SoundForwardAction extends KeyForwardAction {
4850
49- private SoundSource player;
51+ private IEffectPlayer player;
5052 private String sound;
5153
5254 /**
5355 * @param camera
5456 * @param speed
5557 */
56- public SoundForwardAction(Camera camera, float speed, SoundSource soundPlayer, String soundName) {
58+ public SoundForwardAction(Camera camera, float speed, IEffectPlayer soundPlayer, String soundName) {
5759 super(camera, speed);
58- player = soundPlayer;
59- sound = soundName;
60+ player= soundPlayer;
61+ sound= soundName;
6062 }
6163
6264 /**
63- * @see com.jme.input.action.InputAction#performAction(float)
64- */
65+ * @see com.jme.input.action.InputAction#performAction(float)
66+ */
6567 public void performAction(float time) {
6668 super.performAction(time);
67- if (player != null && !player.isPlaying()) {
68- player.play(sound);
69+ if (player != null && player.getStatus() != IEffectPlayer.PLAYING) {
70+ IEffect effect=EffectRepository.getRepository().getSource(sound);
71+ if(effect !=null){
72+ player.play(effect);
73+ }
6974 }
7075 }
71-
7276 }
--- a/src/com/jme/sound/action/SoundLookDownAction.java
+++ b/src/com/jme/sound/action/SoundLookDownAction.java
@@ -38,7 +38,8 @@ package com.jme.sound.action;
3838
3939 import com.jme.input.action.KeyLookDownAction;
4040 import com.jme.renderer.Camera;
41-import com.jme.sound.SoundSource;
41+import com.jme.sound.IEffectPlayer;
42+import com.jme.sound.utils.EffectRepository;
4243
4344 /**
4445 * @author Arman Ozcelik
@@ -47,15 +48,15 @@ import com.jme.sound.SoundSource;
4748 public class SoundLookDownAction extends KeyLookDownAction {
4849
4950 private String sound;
50- private SoundSource player;
51+ private IEffectPlayer player;
5152 /**
5253 * @param camera
5354 * @param speed
5455 */
55- public SoundLookDownAction(Camera camera, float speed, SoundSource soundPlayer, String soundName) {
56+ public SoundLookDownAction(Camera camera, float speed, IEffectPlayer soundPlayer, String soundName) {
5657 super(camera, speed);
57- player = soundPlayer;
58- sound = soundName;
58+ player= soundPlayer;
59+ sound= soundName;
5960 }
6061
6162 /**
@@ -63,8 +64,8 @@ public class SoundLookDownAction extends KeyLookDownAction {
6364 */
6465 public void performAction(float time) {
6566 super.performAction(time);
66- if (player != null && !player.isPlaying()) {
67- player.play(sound);
67+ if (player != null && player.getStatus() != IEffectPlayer.PLAYING) {
68+ player.play(EffectRepository.getRepository().getSource(sound));
6869 }
6970 }
70-}
71+}
\ No newline at end of file
--- a/src/com/jme/sound/action/SoundLookUpAction.java
+++ b/src/com/jme/sound/action/SoundLookUpAction.java
@@ -38,7 +38,8 @@ package com.jme.sound.action;
3838
3939 import com.jme.input.action.KeyLookUpAction;
4040 import com.jme.renderer.Camera;
41-import com.jme.sound.SoundSource;
41+import com.jme.sound.IEffectPlayer;
42+import com.jme.sound.utils.EffectRepository;
4243
4344 /**
4445 * @author Arman Ozcelik
@@ -47,15 +48,15 @@ import com.jme.sound.SoundSource;
4748 public class SoundLookUpAction extends KeyLookUpAction {
4849
4950 private String sound;
50- private SoundSource player;
51+ private IEffectPlayer player;
5152 /**
5253 * @param camera
5354 * @param speed
5455 */
55- public SoundLookUpAction(Camera camera, float speed, SoundSource soundPlayer, String soundName) {
56+ public SoundLookUpAction(Camera camera, float speed, IEffectPlayer soundPlayer, String soundName) {
5657 super(camera, speed);
57- player = soundPlayer;
58- sound = soundName;
58+ player= soundPlayer;
59+ sound= soundName;
5960 }
6061
6162 /**
@@ -63,8 +64,8 @@ public class SoundLookUpAction extends KeyLookUpAction {
6364 */
6465 public void performAction(float time) {
6566 super.performAction(time);
66- if (player != null && !player.isPlaying()) {
67- player.play(sound);
67+ if (player != null && player.getStatus() != IEffectPlayer.PLAYING) {
68+ player.play(EffectRepository.getRepository().getSource(sound));
6869 }
6970 }
70-}
71+}
\ No newline at end of file
--- a/src/com/jme/sound/action/SoundRotateLeftAction.java
+++ b/src/com/jme/sound/action/SoundRotateLeftAction.java
@@ -38,7 +38,8 @@ package com.jme.sound.action;
3838
3939 import com.jme.input.action.KeyRotateLeftAction;
4040 import com.jme.renderer.Camera;
41-import com.jme.sound.SoundSource;
41+import com.jme.sound.IEffectPlayer;
42+import com.jme.sound.utils.EffectRepository;
4243
4344 /**
4445 * @author Arman Ozcelik
@@ -47,15 +48,15 @@ import com.jme.sound.SoundSource;
4748 public class SoundRotateLeftAction extends KeyRotateLeftAction {
4849
4950 private String sound;
50- private SoundSource player;
51+ private IEffectPlayer player;
5152 /**
5253 * @param camera
5354 * @param speed
5455 */
55- public SoundRotateLeftAction(Camera camera, float speed, SoundSource soundPlayer, String soundName) {
56+ public SoundRotateLeftAction(Camera camera, float speed, IEffectPlayer soundPlayer, String soundName) {
5657 super(camera, speed);
57- player = soundPlayer;
58- sound = soundName;
58+ player= soundPlayer;
59+ sound= soundName;
5960 }
6061
6162 /**
@@ -63,8 +64,8 @@ public class SoundRotateLeftAction extends KeyRotateLeftAction {
6364 */
6465 public void performAction(float time) {
6566 super.performAction(time);
66- if (player != null && !player.isPlaying()) {
67- player.play(sound);
67+ if (player != null && player.getStatus() != IEffectPlayer.PLAYING) {
68+ player.play(EffectRepository.getRepository().getSource(sound));
6869 }
6970 }
70-}
71+}
\ No newline at end of file
--- a/src/com/jme/sound/action/SoundRotateRightAction.java
+++ b/src/com/jme/sound/action/SoundRotateRightAction.java
@@ -38,7 +38,8 @@ package com.jme.sound.action;
3838
3939 import com.jme.input.action.KeyRotateRightAction;
4040 import com.jme.renderer.Camera;
41-import com.jme.sound.SoundSource;
41+import com.jme.sound.IEffectPlayer;
42+import com.jme.sound.utils.EffectRepository;
4243
4344 /**
4445 * @author Arman Ozcelik
@@ -46,24 +47,24 @@ import com.jme.sound.SoundSource;
4647 */
4748 public class SoundRotateRightAction extends KeyRotateRightAction {
4849 private String sound;
49- private SoundSource player;
50- /**
51- * @param camera
52- * @param speed
53- */
54- public SoundRotateRightAction(Camera camera, float speed, SoundSource soundPlayer, String soundName) {
55- super(camera, speed);
56- player = soundPlayer;
57- sound = soundName;
58- }
50+ private IEffectPlayer player;
51+ /**
52+ * @param camera
53+ * @param speed
54+ */
55+ public SoundRotateRightAction(Camera camera, float speed, IEffectPlayer soundPlayer, String soundName) {
56+ super(camera, speed);
57+ player= soundPlayer;
58+ sound= soundName;
59+ }
5960
60- /**
61- * @see com.jme.input.action.InputAction#performAction(float)
62- */
63- public void performAction(float time) {
64- super.performAction(time);
65- if (player != null && !player.isPlaying()) {
66- player.play(sound);
67- }
61+ /**
62+ * @see com.jme.input.action.InputAction#performAction(float)
63+ */
64+ public void performAction(float time) {
65+ super.performAction(time);
66+ if (player != null && player.getStatus() != IEffectPlayer.PLAYING) {
67+ player.play(EffectRepository.getRepository().getSource(sound));
6868 }
6969 }
70+}
\ No newline at end of file
--- a/src/com/jme/sound/action/SoundStrafeLeftAction.java
+++ b/src/com/jme/sound/action/SoundStrafeLeftAction.java
@@ -38,7 +38,8 @@ package com.jme.sound.action;
3838
3939 import com.jme.input.action.KeyStrafeLeftAction;
4040 import com.jme.renderer.Camera;
41-import com.jme.sound.SoundSource;
41+import com.jme.sound.IEffectPlayer;
42+import com.jme.sound.utils.EffectRepository;
4243
4344 /**
4445 * @author Arman Ozcelik
@@ -46,15 +47,15 @@ import com.jme.sound.SoundSource;
4647 */
4748 public class SoundStrafeLeftAction extends KeyStrafeLeftAction {
4849 private String sound;
49- private SoundSource player;
50+ private IEffectPlayer player;
5051 /**
5152 * @param camera
5253 * @param speed
5354 */
54- public SoundStrafeLeftAction(Camera camera, float speed, SoundSource soundPlayer, String soundName) {
55+ public SoundStrafeLeftAction(Camera camera, float speed, IEffectPlayer soundPlayer, String soundName) {
5556 super(camera, speed);
56- player = soundPlayer;
57- sound = soundName;
57+ player= soundPlayer;
58+ sound= soundName;
5859 }
5960
6061 /**
@@ -62,8 +63,8 @@ public class SoundStrafeLeftAction extends KeyStrafeLeftAction {
6263 */
6364 public void performAction(float time) {
6465 super.performAction(time);
65- if (player != null && !player.isPlaying()) {
66- player.play(sound);
66+ if (player != null && player.getStatus() != IEffectPlayer.PLAYING) {
67+ player.play(EffectRepository.getRepository().getSource(sound));
6768 }
6869 }
69-}
70+}
\ No newline at end of file
--- a/src/com/jme/sound/action/SoundStrafeRightAction.java
+++ b/src/com/jme/sound/action/SoundStrafeRightAction.java
@@ -38,7 +38,8 @@ package com.jme.sound.action;
3838
3939 import com.jme.input.action.KeyStrafeRightAction;
4040 import com.jme.renderer.Camera;
41-import com.jme.sound.SoundSource;
41+import com.jme.sound.IEffectPlayer;
42+import com.jme.sound.utils.EffectRepository;
4243
4344 /**
4445 * @author Arman Ozcelik
@@ -47,15 +48,15 @@ import com.jme.sound.SoundSource;
4748 public class SoundStrafeRightAction extends KeyStrafeRightAction {
4849
4950 private String sound;
50- private SoundSource player;
51+ private IEffectPlayer player;
5152 /**
5253 * @param camera
5354 * @param speed
5455 */
55- public SoundStrafeRightAction(Camera camera, float speed, SoundSource soundPlayer, String soundName) {
56+ public SoundStrafeRightAction(Camera camera, float speed, IEffectPlayer soundPlayer, String soundName) {
5657 super(camera, speed);
57- player = soundPlayer;
58- sound = soundName;
58+ player= soundPlayer;
59+ sound= soundName;
5960 }
6061
6162 /**
@@ -63,8 +64,8 @@ public class SoundStrafeRightAction extends KeyStrafeRightAction {
6364 */
6465 public void performAction(float time) {
6566 super.performAction(time);
66- if (player != null && !player.isPlaying()) {
67- player.play(sound);
67+ if (player != null && player.getStatus() != IEffectPlayer.PLAYING) {
68+ player.play(EffectRepository.getRepository().getSource(sound));
6869 }
6970 }
70-}
71+}
\ No newline at end of file
--- a/src/com/jme/sound/utils/SourceRepository.java
+++ b/src/com/jme/sound/utils/EffectPlayerRepository.java
@@ -31,51 +31,42 @@
3131 */
3232
3333 /*
34- * Created on 23 oct. 2003
34+ * Created on 31 oct. 2003
3535 *
3636 */
3737 package com.jme.sound.utils;
3838
39-
4039 import java.util.Hashtable;
4140
42-import com.jme.sound.SoundSource;
43-
44-
41+import com.jme.sound.IEffectPlayer;
4542
4643 /**
4744 * @author Arman Ozcelik
4845 *
4946 */
50-public class SourceRepository {
47+public class EffectPlayerRepository {
48+
49+ private Hashtable repository = new Hashtable();
50+ private static EffectPlayerRepository instance;
51+
52+ private EffectPlayerRepository() {
5153
52- private Hashtable repository=new Hashtable();
53- private static SourceRepository instance;
54-
55- private SourceRepository() {
56-
5754 }
58-
59- public synchronized static SourceRepository getRepository(){
60- if(instance==null){
61- instance=new SourceRepository();
55+
56+ public synchronized static EffectPlayerRepository getRepository() {
57+ if (instance == null) {
58+ instance = new EffectPlayerRepository();
6259 }
63- return instance;
60+ return instance;
6461 }
65-
66- public void bind(Object player, SoundSource source){
62+
63+ public void bind(Object player, IEffectPlayer source) {
6764 repository.put(player, source);
68-
65+
6966 }
70-
71- public SoundSource getSource(Object player){
72- return (SoundSource)repository.get(player);
67+
68+ public IEffectPlayer getSource(Object player) {
69+ return (IEffectPlayer) repository.get(player);
7370 }
74-
75-
76-
77-
78-
79-
8071
8172 }
--- /dev/null
+++ b/src/com/jme/sound/utils/EffectRepository.java
@@ -0,0 +1,74 @@
1+/*
2+ * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
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 met:
7+ *
8+ * Redistributions of source code must retain the above copyright notice, this
9+ * list of conditions and the following disclaimer.
10+ *
11+ * Redistributions in binary form must reproduce the above copyright notice,
12+ * this list of conditions and the following disclaimer in the documentation
13+ * and/or other materials provided with the distribution.
14+ *
15+ * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
16+ * names of its contributors may be used to endorse or promote products derived
17+ * from this software without specific prior written permission.
18+ *
19+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+ * POSSIBILITY OF SUCH DAMAGE.
30+ *
31+ */
32+
33+/*
34+ * Created on 31 oct. 2003
35+ *
36+ */
37+package com.jme.sound.utils;
38+
39+import java.util.Hashtable;
40+import com.jme.sound.IEffect;
41+
42+/**
43+ * @author Arman Ozcelik
44+ *
45+ */
46+public class EffectRepository {
47+
48+ private Hashtable repository= new Hashtable();
49+ private Hashtable queued= new Hashtable();
50+ private static EffectRepository instance;
51+
52+ private EffectRepository() {
53+
54+ }
55+
56+ public synchronized static EffectRepository getRepository() {
57+ if (instance == null) {
58+ instance= new EffectRepository();
59+ }
60+ return instance;
61+ }
62+
63+ public void bind(String name, IEffect source) {
64+ repository.put(name, source);
65+
66+ }
67+
68+ public IEffect getSource(String name) {
69+ return (IEffect)repository.get(name);
70+
71+
72+ }
73+
74+}
--- a/src/com/jme/sound/LWJGLPlaylist.java
+++ b/src/com/jme/sound/utils/OnDemandSoundLoader.java
@@ -31,54 +31,84 @@
3131 */
3232
3333 /*
34- * Created on 27 oct. 2003
34+ * Created on 1 nov. 2003
3535 *
3636 */
37-package com.jme.sound;
37+package com.jme.sound.utils;
3838
3939 import java.util.ArrayList;
4040
41-import com.jme.sound.utils.StreamRepository;
41+import org.lwjgl.openal.AL;
42+
43+import com.jme.sound.IEffect;
44+import com.jme.sound.ISoundBuffer;
45+import com.jme.sound.LWJGLMP3Buffer;
46+import com.jme.sound.LWJGLWaveBuffer;
47+import com.jme.sound.SoundEffect;
4248
4349 /**
4450 * @author Arman Ozcelik
45- *
46- * This class thread unsafe. A playlist sould be filled once for ever.
4751 *
4852 */
49-public class LWJGLPlaylist implements Playlist {
53+public class OnDemandSoundLoader extends Thread {
54+
55+ private boolean killed;
56+ private ArrayList batchList= new ArrayList();
57+ private ArrayList output= new ArrayList();
58+ private long waitTime;
5059
51- private ArrayList preloaded;
52- /**
53- *
54- */
55- public LWJGLPlaylist() {
56- preloaded = new ArrayList();
60+ protected OnDemandSoundLoader() {
5761 }
5862
59- public void queueSound(String name) {
60- String file = StreamRepository.getInstance().getStream(name);
61- if (file.endsWith(".mp3")) {
62- preloaded.add(new LWJGLMP3Stream(file));
63- }
64- if (file.endsWith(".wav")) {
65- preloaded.add(new LWJGLWaveStream(file));
66- }
63+ public OnDemandSoundLoader queueSound(String name, String file) {
64+ batchList.add(name);
65+ batchList.add(file);
66+ return this;
6767 }
6868
69- public SoundStream next() {
70- if (preloaded.size() > 0) {
71- return (SoundStream) preloaded.remove(0);
69+ public void run() {
70+ while (!killed) {
71+ String name= null;
72+ String file= null;
73+ if (batchList.size() >= 2) {
74+ synchronized (batchList) {
75+ name= (String)batchList.remove(0);
76+ file= (String)batchList.remove(0);
77+
78+ }
79+ ISoundBuffer buffer= null;
80+ if (file.endsWith(".wav")) {
81+ System.out.println("Loading " + file + " as " + name);
82+ buffer= new LWJGLWaveBuffer();
83+ buffer.load(file);
84+ }
85+ if (file.endsWith(".mp3")) {
86+ System.out.println("Loading " + file + " as " + name);
87+ buffer= new LWJGLMP3Buffer();
88+ buffer.load(file);
89+ }
90+ AL.alBufferData(
91+ buffer.getBufferNumber(),
92+ buffer.getChannels(),
93+ buffer.getBufferData(),
94+ buffer.getBufferData().capacity(),
95+ buffer.getSampleRate());
96+ if (AL.alGetError() != AL.AL_NO_ERROR) {
97+ System.err.println("Error generating audio buffer");
98+ }
99+ SoundEffect effect= new SoundEffect(buffer.getBufferNumber(), IEffect.SOUND_TYPE_EFFECT);
100+ EffectRepository rep=EffectRepository.getRepository();
101+ synchronized(rep){
102+ rep.bind(name, effect);
103+ }
104+ buffer.release();
105+
106+ }
107+
72108 }
73- return null;
74- }
75109
76- public boolean hasNext() {
77- return preloaded.size() > 0;
78110 }
111+
79112
80- public int length() {
81- return preloaded.size();
82- }
83113
84114 }
--- a/src/com/jme/test/sound/TestSound.java
+++ b/src/com/jme/test/sound/TestSound.java
@@ -4,8 +4,10 @@
44 */
55 package com.jme.test.sound;
66
7+import com.jme.sound.IEffectPlayer;
8+import com.jme.sound.IRenderer;
79 import com.jme.sound.SoundSystem;
8-import com.jme.sound.SoundRenderer;
10+import com.jme.sound.utils.EffectRepository;
911
1012
1113
@@ -17,28 +19,22 @@ public class TestSound{
1719
1820
1921 public static void main(String[] args) throws InterruptedException {
20- SoundSystem system=SoundSystem.getSoundSystem("LWJGL");
21- SoundRenderer renderer=system.getRenderer();
22- renderer.addSoundPlayer("MONSTER");
22+ SoundSystem system=SoundSystem.getSoundEffectSystem("LWJGL");
23+ IRenderer renderer=system.getRenderer();
24+
2325 renderer.addSoundPlayer("NPC");
2426
25- renderer.loadSoundAs("music", "cu.wav");
26- renderer.loadSoundAs("bored", "01.mp3");
27+ renderer.loadSoundAs("music", "../data/sound/walk.mp3");
2728
28- renderer.getSoundPlayer("MONSTER").setNumberOfBuffers(1);
29- renderer.getSoundPlayer("NPC").setNumberOfBuffers(128);
3029
31- renderer.getSoundPlayer("MONSTER").updatePosition(1, 0, 0);
32- renderer.getSoundPlayer("NPC").updatePosition(0, 0, 0);
33- renderer.getSoundPlayer("NPC").updateVelocity(0, 0, 0);
3430
3531 //renderer.getSoundPlayer("MONSTER").play("music");
36- renderer.getSoundPlayer("NPC").play("bored");
32+ renderer.getSoundPlayer("NPC").play(EffectRepository.getRepository().getSource("music"));
3733
3834
39- //while(renderer.getSoundPlayer("MONSTER").isPlaying()){
40- // Thread.sleep(1000);
41- //}
35+ while(renderer.getSoundPlayer("NPC").getStatus()==IEffectPlayer.PLAYING){
36+ Thread.sleep(1000);
37+ }
4238
4339
4440 }
--- a/src/com/jme/test/sound/TestSoundLoop.java
+++ b/src/com/jme/test/sound/TestSoundLoop.java
@@ -32,6 +32,8 @@
3232 package com.jme.test.sound;
3333
3434
35+
36+
3537 import com.jme.app.AbstractGame;
3638 import com.jme.image.Texture;
3739 import com.jme.math.Vector3f;
@@ -47,8 +49,8 @@ import com.jme.system.LWJGLDisplaySystem;
4749 import com.jme.util.TextureManager;
4850
4951
52+import com.jme.sound.IRenderer;
5053 import com.jme.sound.SoundSystem;
51-import com.jme.sound.SoundRenderer;
5254
5355 /**
5456 * <code>TestSoundLoop</code>
@@ -60,7 +62,7 @@ public class TestSoundLoop extends AbstractGame {
6062 private Text text;
6163 private Camera cam;
6264 private Node scene;
63- private SoundRenderer soundRenderer;
65+ private IRenderer soundRenderer;
6466
6567 public static void main(String[] args) {
6668 TestSoundLoop app = new TestSoundLoop();
@@ -73,10 +75,7 @@ public class TestSoundLoop extends AbstractGame {
7375 * @see com.jme.app.AbstractGame#update()
7476 */
7577 protected void update() {
76- if(!soundRenderer.getSoundPlayer("NPC").isPlaying()) {
77- soundRenderer.getSoundPlayer("NPC").play("bored");
78-
79- }
78+
8079 }
8180
8281 /**
@@ -108,7 +107,7 @@ public class TestSoundLoop extends AbstractGame {
108107 System.exit(1);
109108 }
110109
111- SoundSystem system=SoundSystem.getSoundSystem("LWJGL");
110+ SoundSystem system=SoundSystem.getSoundEffectSystem("LWJGL");
112111 soundRenderer=system.getRenderer();
113112
114113
@@ -138,7 +137,7 @@ public class TestSoundLoop extends AbstractGame {
138137 ts.setEnabled(true);
139138 ts.setTexture(
140139 TextureManager.loadTexture(
141- "data/Font/font.png",
140+ "../data/Font/font.png",
142141 Texture.MM_LINEAR,
143142 Texture.FM_LINEAR,
144143 true));
@@ -158,16 +157,13 @@ public class TestSoundLoop extends AbstractGame {
158157
159158 soundRenderer.addSoundPlayer("MONSTER");
160159 soundRenderer.addSoundPlayer("NPC");
161-
160+
162161 soundRenderer.loadSoundAs("music", "cu.wav");
163- soundRenderer.loadSoundAs("bored", "data/music/02 Butterfly Wings.mp3");
164-
165- soundRenderer.getSoundPlayer("MONSTER").setNumberOfBuffers(1);
166- soundRenderer.getSoundPlayer("NPC").setNumberOfBuffers(128);
162+ soundRenderer.loadSoundAs("bored", "../data/sound/03.mp3");
167163
168- soundRenderer.getSoundPlayer("MONSTER").updatePosition(1, 0, 0);
169- soundRenderer.getSoundPlayer("NPC").updatePosition(0, 0, 0);
170- soundRenderer.getSoundPlayer("NPC").updateVelocity(0, 0, 0);
164+
165+
166+
171167
172168 }
173169
--- a/src/com/jme/test/sound/TestSoundMove.java
+++ b/src/com/jme/test/sound/TestSoundMove.java
@@ -51,8 +51,9 @@ import com.jme.system.JmeException;
5151 import com.jme.system.LWJGLDisplaySystem;
5252 import com.jme.util.TextureManager;
5353
54+import com.jme.sound.IRenderer;
5455 import com.jme.sound.SoundSystem;
55-import com.jme.sound.SoundRenderer;
56+
5657 /**
5758 * @author Arman Ozcelik
5859 *
@@ -62,7 +63,7 @@ public class TestSoundMove extends AbstractGame {
6263 private Text text;
6364 private Camera cam;
6465 private Node scene;
65- private SoundRenderer soundRenderer;
66+ private IRenderer soundRenderer;
6667 private RelativeMouse mouse;
6768 float x;
6869 float y;
@@ -80,24 +81,7 @@ public class TestSoundMove extends AbstractGame {
8081 protected void update() {
8182 mouse.update();
8283
83- if (!soundRenderer.getSoundPlayer("NPC").isPlaying()) {
84- soundRenderer.getSoundPlayer("NPC").play("bored");
85-
86- } else {
87- if (mouse.getLocalTranslation().x > 0) {
88- x+=0.05f;
89- } else if (mouse.getLocalTranslation().x < 0) {
90- x-= 0.5f;
91- }
92- if (mouse.getLocalTranslation().y > 0) {
93- y+=0.05f;
94- } else if (mouse.getLocalTranslation().y < 0) {
95- y-=0.05f;
96- }
97- soundRenderer.getSoundPlayer("NPC").updatePosition(x, y, 0);
98- text.print("Position: x=" + x + " , y=" +
99- y);
100- }
84+
10185 }
10286
10387 /**
@@ -132,7 +116,7 @@ public class TestSoundMove extends AbstractGame {
132116 System.exit(1);
133117 }
134118 InputSystem.createInputSystem(properties.getRenderer());
135- SoundSystem system = SoundSystem.getSoundSystem("LWJGL");
119+ SoundSystem system = SoundSystem.getSoundEffectSystem("LWJGL");
136120 soundRenderer = system.getRenderer();
137121
138122 ColorRGBA blueColor = new ColorRGBA();
@@ -207,12 +191,7 @@ public class TestSoundMove extends AbstractGame {
207191 soundRenderer.loadSoundAs("music", "walk.wav");
208192 soundRenderer.loadSoundAs("bored", "03.mp3");
209193
210- soundRenderer.getSoundPlayer("MONSTER").setNumberOfBuffers(1);
211- soundRenderer.getSoundPlayer("NPC").setNumberOfBuffers(128);
212194
213- soundRenderer.getSoundPlayer("MONSTER").updatePosition(0, 0, 0);
214- soundRenderer.getSoundPlayer("NPC").updatePosition(0, 0, 0);
215- soundRenderer.getSoundPlayer("NPC").updateVelocity(0, 0, 0);
216195
217196 }
218197