Main repository of MikuMikuStudio
Revisión | 8b17d76093edd26a38692ac2295fba9e379b9a9a (tree) |
---|---|
Tiempo | 2003-11-02 08:34:00 |
Autor | Anakan <Anakan@75d0...> |
Commiter | Anakan |
sound system sharing buffers
git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@145 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
@@ -31,24 +31,20 @@ | ||
31 | 31 | */ |
32 | 32 | |
33 | 33 | /* |
34 | - * Created on 27 oct. 2003 | |
34 | + * Created on 31 oct. 2003 | |
35 | 35 | * |
36 | 36 | */ |
37 | 37 | package com.jme.sound; |
38 | 38 | |
39 | + | |
40 | + | |
39 | 41 | /** |
40 | 42 | * @author Arman Ozcelik |
41 | 43 | * |
42 | 44 | */ |
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{ | |
50 | 46 | |
51 | - public int length(); | |
47 | + public int getName(); | |
52 | 48 | |
53 | 49 | |
54 | 50 | } |
@@ -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 | +} |
@@ -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 | +} |
@@ -31,51 +31,34 @@ | ||
31 | 31 | */ |
32 | 32 | |
33 | 33 | /* |
34 | - * Created on 23 oct. 2003 | |
34 | + * Created on 31 oct. 2003 | |
35 | 35 | * |
36 | 36 | */ |
37 | 37 | package com.jme.sound; |
38 | 38 | |
39 | -import com.jme.math.Vector3f; | |
40 | - | |
41 | 39 | /** |
42 | 40 | * @author Arman Ozcelik |
43 | 41 | * |
44 | 42 | */ |
45 | -public interface SoundSource { | |
46 | - | |
47 | - public int getSourceNumber(); | |
48 | - | |
49 | - public void setStream(SoundStream stream); | |
43 | +public interface IMusicPlayer extends ISource{ | |
50 | 44 | |
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); | |
52 | 50 | |
53 | - public void play(String name); | |
51 | + public int getNumberOfBuffers(); | |
54 | 52 | |
55 | - public void stop(); | |
53 | + public void play(String song); | |
56 | 54 | |
57 | 55 | public void pause(); |
58 | 56 | |
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(); | |
62 | 58 | |
63 | 59 | public boolean isPlaying(); |
64 | 60 | |
65 | - public boolean isPaused(); | |
66 | - | |
67 | 61 | public boolean isStopped(); |
68 | 62 | |
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(); | |
81 | 64 | } |
@@ -33,14 +33,20 @@ package com.jme.sound; | ||
33 | 33 | |
34 | 34 | /** |
35 | 35 | * @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 $ | |
37 | 37 | */ |
38 | -public interface SoundRenderer { | |
38 | +public interface IRenderer { | |
39 | 39 | |
40 | 40 | |
41 | 41 | public void addSoundPlayer(Object name); |
42 | 42 | |
43 | 43 | public void loadSoundAs(String name, String file); |
44 | 44 | |
45 | - public SoundSource getSoundPlayer(Object name); | |
45 | + public IEffectPlayer getSoundPlayer(Object name); | |
46 | + | |
47 | + public IMusicPlayer getMusicPlayer(); | |
48 | + | |
49 | + | |
50 | + | |
51 | + | |
46 | 52 | } |
\ No newline at end of file |
@@ -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 | +} |
@@ -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 | +} |
@@ -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 | +} |
@@ -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 | +} |
@@ -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 | +} |
@@ -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 | - | |
22 | 1 | /* |
23 | 2 | * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding |
24 | 3 | * All rights reserved. |
@@ -60,6 +39,25 @@ import javazoom.jl.decoder.SampleBuffer; | ||
60 | 39 | * @author Arman Ozcelik |
61 | 40 | * |
62 | 41 | */ |
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; | |
63 | 61 | public class LWJGLMP3Stream implements SoundStream { |
64 | 62 | |
65 | 63 | private AudioFormat format; |
@@ -140,8 +138,6 @@ public class LWJGLMP3Stream implements SoundStream { | ||
140 | 138 | |
141 | 139 | public ByteBuffer read() throws IOException { |
142 | 140 | try { |
143 | - | |
144 | - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); | |
145 | 141 | Header header = stream.readFrame(); |
146 | 142 | if (header == null) { |
147 | 143 | //TODO reload? |
@@ -149,25 +145,24 @@ public class LWJGLMP3Stream implements SoundStream { | ||
149 | 145 | } |
150 | 146 | if (sampleBuf == null) { |
151 | 147 | 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); | |
155 | 149 | decoder.setOutputBuffer(sampleBuf); |
156 | 150 | } |
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); | |
163 | 160 | 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; | |
171 | 166 | } catch (BitstreamException bs) { |
172 | 167 | bs.printStackTrace(); |
173 | 168 | } catch (DecoderException e) { |
@@ -188,11 +183,9 @@ public class LWJGLMP3Stream implements SoundStream { | ||
188 | 183 | protected byte[] toByteArray(short[] samples, int offs, int len) { |
189 | 184 | byte[] b = new byte[len * 2]; |
190 | 185 | int idx = 0; |
191 | - short s; | |
192 | 186 | 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); | |
196 | 189 | } |
197 | 190 | return b; |
198 | 191 | } |
@@ -37,26 +37,29 @@ import java.nio.IntBuffer; | ||
37 | 37 | |
38 | 38 | import org.lwjgl.openal.AL; |
39 | 39 | |
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; | |
45 | 42 | |
46 | 43 | /** |
47 | 44 | * @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 $ | |
49 | 46 | */ |
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 }; | |
53 | 50 | //Velocity of the listener. |
54 | - private float[] listenerVel = { 0.0f, 0.0f, 0.0f }; | |
51 | + private float[] listenerVel= { 0.0f, 0.0f, 0.0f }; | |
55 | 52 | //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; | |
57 | 56 | |
58 | 57 | public LWJGLSoundRenderer() { |
58 | + IntBuffer source= ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer(); | |
59 | + AL.alGenSources(source); | |
60 | + player= new LWJGLSource(source.get(0)); | |
59 | 61 | setListenerValues(); |
62 | + | |
60 | 63 | } |
61 | 64 | |
62 | 65 | private void setListenerValues() { |
@@ -65,24 +68,46 @@ public class LWJGLSoundRenderer implements SoundRenderer { | ||
65 | 68 | AL.alListener3f(AL.AL_ORIENTATION, listenerOri[0], listenerOri[1], listenerOri[2]); |
66 | 69 | } |
67 | 70 | |
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(); | |
72 | 73 | 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(); | |
74 | 102 | } |
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); | |
80 | 106 | } |
81 | 107 | |
82 | - | |
83 | - public SoundSource getSoundPlayer(Object name) { | |
84 | - return SourceRepository.getRepository().getSource(name); | |
108 | + public IMusicPlayer getMusicPlayer() { | |
109 | + | |
110 | + return player; | |
85 | 111 | } |
86 | - | |
87 | 112 | |
88 | 113 | } |
@@ -36,15 +36,16 @@ import org.lwjgl.openal.AL; | ||
36 | 36 | |
37 | 37 | /** |
38 | 38 | * @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 $ | |
40 | 40 | */ |
41 | 41 | public class LWJGLSoundSystem extends SoundSystem { |
42 | 42 | |
43 | - private LWJGLSoundRenderer renderer; | |
44 | - private boolean created; | |
43 | + private LWJGLSoundRenderer renderer; | |
45 | 44 | |
46 | 45 | public LWJGLSoundSystem(){ |
47 | - initOpenAL(); | |
46 | + if(!created){ | |
47 | + initOpenAL(); | |
48 | + } | |
48 | 49 | renderer=new LWJGLSoundRenderer(); |
49 | 50 | created = true; |
50 | 51 |
@@ -53,7 +54,7 @@ public class LWJGLSoundSystem extends SoundSystem { | ||
53 | 54 | /** |
54 | 55 | * TODO Comment |
55 | 56 | */ |
56 | - public SoundRenderer getRenderer() { | |
57 | + public IRenderer getRenderer() { | |
57 | 58 | return renderer; |
58 | 59 | } |
59 | 60 |
@@ -71,7 +72,6 @@ public class LWJGLSoundSystem extends SoundSystem { | ||
71 | 72 | private void initOpenAL() { |
72 | 73 | try { |
73 | 74 | AL.create(); |
74 | - Thread.sleep(1000); | |
75 | 75 | } catch (Exception e) { |
76 | 76 | e.printStackTrace(); |
77 | 77 | } |
@@ -40,30 +40,32 @@ import java.io.IOException; | ||
40 | 40 | import java.nio.ByteBuffer; |
41 | 41 | import java.nio.ByteOrder; |
42 | 42 | import java.nio.IntBuffer; |
43 | +import java.util.logging.Level; | |
43 | 44 | |
44 | 45 | import org.lwjgl.openal.AL; |
45 | 46 | |
46 | 47 | import com.jme.math.Vector3f; |
47 | -import com.jme.sound.utils.StreamRepository; | |
48 | +import com.jme.util.LoggingSystem; | |
48 | 49 | |
49 | 50 | /** |
50 | 51 | * @author Arman Ozcelik |
51 | 52 | * |
52 | 53 | */ |
53 | -public class LWJGLSource implements SoundSource { | |
54 | +public class LWJGLSource implements IMusicPlayer { | |
54 | 55 | |
55 | 56 | private int sourceNumber; |
56 | 57 | private SoundStream stream; |
57 | 58 | private boolean paused, playing; |
58 | 59 | private BufferedPlayer player; |
59 | - private int numberOfBuffers = 1; | |
60 | + private int numberOfBuffers= 1; | |
60 | 61 | private Vector3f position; |
61 | - private Playlist playList; | |
62 | 62 | |
63 | 63 | 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); | |
67 | 69 | } |
68 | 70 | |
69 | 71 | /** |
@@ -82,7 +84,7 @@ public class LWJGLSource implements SoundSource { | ||
82 | 84 | stop(); |
83 | 85 | } |
84 | 86 | stream.close(); |
85 | - this.stream = stream; | |
87 | + this.stream= stream; | |
86 | 88 | } |
87 | 89 | |
88 | 90 | /** |
@@ -99,24 +101,20 @@ public class LWJGLSource implements SoundSource { | ||
99 | 101 | * If the sound type is wave then the number of buffers is set to 1. |
100 | 102 | * @param name the sound name. |
101 | 103 | */ |
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)); | |
117 | 112 | } |
118 | - player = new BufferedPlayer(); | |
119 | - player.start(); | |
113 | + if (file.endsWith(".wav")) { | |
114 | + setNumberOfBuffers(1); | |
115 | + setStream(new LWJGLWaveStream(file)); | |
116 | + } | |
117 | + | |
120 | 118 | |
121 | 119 | } |
122 | 120 |
@@ -129,7 +127,7 @@ public class LWJGLSource implements SoundSource { | ||
129 | 127 | * @param z the z position of the source |
130 | 128 | */ |
131 | 129 | 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); | |
133 | 131 | updatePosition(newPos); |
134 | 132 | } |
135 | 133 |
@@ -140,10 +138,10 @@ public class LWJGLSource implements SoundSource { | ||
140 | 138 | * @param pos the new position of the source |
141 | 139 | */ |
142 | 140 | 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(); | |
147 | 145 | if (isPlaying() && !isPaused()) { |
148 | 146 | AL.alSource3f( |
149 | 147 | sourceNumber, |
@@ -182,19 +180,19 @@ public class LWJGLSource implements SoundSource { | ||
182 | 180 | |
183 | 181 | public void stop() { |
184 | 182 | AL.alSourceStop(sourceNumber); |
185 | - playing = false; | |
186 | - paused = false; | |
183 | + playing= false; | |
184 | + paused= false; | |
187 | 185 | } |
188 | 186 | |
189 | 187 | public void pause() { |
190 | 188 | if (isPlaying()) { |
191 | 189 | AL.alSourcePause(sourceNumber); |
192 | - paused = true; | |
190 | + paused= true; | |
193 | 191 | } |
194 | 192 | } |
195 | 193 | |
196 | 194 | public void setNumberOfBuffers(int buffs) { |
197 | - numberOfBuffers = buffs; | |
195 | + numberOfBuffers= buffs; | |
198 | 196 | |
199 | 197 | } |
200 | 198 |
@@ -212,11 +210,9 @@ public class LWJGLSource implements SoundSource { | ||
212 | 210 | private IntBuffer buffers; |
213 | 211 | private IntBuffer temp; |
214 | 212 | 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(); | |
220 | 216 | AL.alGenBuffers(buffers); |
221 | 217 | } |
222 | 218 |
@@ -225,14 +221,12 @@ public class LWJGLSource implements SoundSource { | ||
225 | 221 | } |
226 | 222 | |
227 | 223 | public boolean streamBuffer(int bufferNumber) { |
228 | - ByteBuffer data = null; | |
224 | + ByteBuffer data= null; | |
229 | 225 | try { |
230 | - data = stream.read(); | |
231 | - | |
226 | + data= stream.read(); | |
232 | 227 | if (data.capacity() == 0) { |
233 | 228 | return false; |
234 | 229 | } |
235 | - | |
236 | 230 | } catch (IOException e) { |
237 | 231 | e.printStackTrace(); |
238 | 232 | } |
@@ -242,6 +236,8 @@ public class LWJGLSource implements SoundSource { | ||
242 | 236 | data, |
243 | 237 | data.capacity(), |
244 | 238 | stream.getSampleRate()); |
239 | + data.clear(); | |
240 | + data=null; | |
245 | 241 | return true; |
246 | 242 | } |
247 | 243 |
@@ -249,7 +245,7 @@ public class LWJGLSource implements SoundSource { | ||
249 | 245 | |
250 | 246 | if (plays()) |
251 | 247 | return true; |
252 | - for (int a = 0; a < buffers.capacity(); a++) { | |
248 | + for (int a= 0; a < buffers.capacity(); a++) { | |
253 | 249 | if (!streamBuffer(buffers.get(a))) |
254 | 250 | return false; |
255 | 251 | } |
@@ -259,16 +255,13 @@ public class LWJGLSource implements SoundSource { | ||
259 | 255 | } |
260 | 256 | |
261 | 257 | 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); | |
264 | 260 | while ((processed > 0)) { |
265 | - | |
266 | 261 | processed--; |
267 | - temp = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer(); | |
268 | - | |
269 | 262 | AL.alSourceUnqueueBuffers(sourceNumber, temp); |
263 | + active= streamBuffer(temp.get(0)); | |
270 | 264 | |
271 | - active = streamBuffer(temp.get(0)); | |
272 | 265 | AL.alSourceQueueBuffers(sourceNumber, temp); |
273 | 266 | } |
274 | 267 |
@@ -276,22 +269,16 @@ public class LWJGLSource implements SoundSource { | ||
276 | 269 | } |
277 | 270 | |
278 | 271 | 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(); | |
288 | 278 | } |
289 | 279 | } |
290 | - if (stream == null) | |
291 | - return; //DISPLAY ERROR? | |
280 | + LoggingSystem.getLogger().log(Level.INFO, "New Stream " + stream); | |
292 | 281 | |
293 | - playing = true; | |
294 | - paused = false; | |
295 | 282 | playback(); |
296 | 283 | while (update()) { |
297 | 284 | if (!plays()) { |
@@ -300,16 +287,26 @@ public class LWJGLSource implements SoundSource { | ||
300 | 287 | } |
301 | 288 | } |
302 | 289 | } |
290 | + | |
303 | 291 | 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 | + | |
307 | 298 | } |
308 | 299 | |
309 | 300 | } |
301 | + /* (non-Javadoc) | |
302 | + * @see com.jme.sound.IMusicPlayer#getNumberOfBuffers() | |
303 | + */ | |
304 | + public int getNumberOfBuffers() { | |
305 | + return numberOfBuffers; | |
306 | + } | |
310 | 307 | |
311 | - public void setPlaylist(Playlist p) { | |
312 | - playList = p; | |
308 | + public int getType() { | |
309 | + return STREAMING; | |
313 | 310 | } |
314 | 311 | |
315 | 312 | } |
@@ -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 | +} |
@@ -36,7 +36,6 @@ | ||
36 | 36 | */ |
37 | 37 | package com.jme.sound; |
38 | 38 | |
39 | - | |
40 | 39 | import java.io.File; |
41 | 40 | import java.io.FileNotFoundException; |
42 | 41 | import java.io.IOException; |
@@ -69,7 +68,7 @@ public class LWJGLWaveStream implements SoundStream { | ||
69 | 68 | private int length; |
70 | 69 | |
71 | 70 | private int offset; |
72 | - | |
71 | + | |
73 | 72 | private boolean isRead; |
74 | 73 | |
75 | 74 | /** |
@@ -85,7 +84,6 @@ public class LWJGLWaveStream implements SoundStream { | ||
85 | 84 | |
86 | 85 | } |
87 | 86 | |
88 | - | |
89 | 87 | private void initChannels() { |
90 | 88 | // get channels |
91 | 89 | if (format.getChannels() == 1) { |
@@ -111,7 +109,8 @@ public class LWJGLWaveStream implements SoundStream { | ||
111 | 109 | } |
112 | 110 | |
113 | 111 | public ByteBuffer read() throws IOException { |
114 | - if(isRead) return ByteBuffer.allocateDirect(0); | |
112 | + if (isRead) | |
113 | + return ByteBuffer.allocateDirect(0); | |
115 | 114 | try { |
116 | 115 | audioStream = AudioSystem.getAudioInputStream(new File(file)); |
117 | 116 | } catch (FileNotFoundException e) { |
@@ -121,21 +120,24 @@ public class LWJGLWaveStream implements SoundStream { | ||
121 | 120 | } catch (IOException e) { |
122 | 121 | e.printStackTrace(); |
123 | 122 | } |
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; | |
132 | 134 | ByteBuffer buffer = null; |
133 | 135 | byte[] temp = new byte[length]; |
134 | 136 | audioStream.read(temp); |
135 | 137 | buffer = ByteBuffer.allocateDirect(length); |
136 | 138 | buffer.put(temp); |
137 | 139 | buffer.rewind(); |
138 | - isRead=true; | |
140 | + isRead = true; | |
139 | 141 | return buffer; |
140 | 142 | |
141 | 143 | } |
@@ -202,9 +204,7 @@ public class LWJGLWaveStream implements SoundStream { | ||
202 | 204 | return length; |
203 | 205 | } |
204 | 206 | |
205 | - | |
206 | - | |
207 | - public int getStreamType() { | |
207 | + public int getStreamType() { | |
208 | 208 | return WAV_SOUND_STREAM; |
209 | 209 | } |
210 | 210 |
@@ -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 | +} |
@@ -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 | +} |
@@ -31,18 +31,18 @@ | ||
31 | 31 | */ |
32 | 32 | package com.jme.sound; |
33 | 33 | |
34 | - | |
35 | - | |
36 | 34 | /** |
37 | 35 | * @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 $ | |
39 | 37 | */ |
40 | 38 | public abstract class SoundSystem { |
41 | 39 | /** |
42 | 40 | * The list of current implemented rendering APIs that subclass SoundSystem. |
43 | 41 | */ |
44 | - public static final String[] rendererNames = { "LWJGL" }; | |
45 | - | |
42 | + public static final String[] rendererNames= { "LWJGL" }; | |
43 | + | |
44 | + protected static boolean created; | |
45 | + | |
46 | 46 | /** |
47 | 47 | * |
48 | 48 | * <code>getSoundSystem</code> is a factory method that creates the |
@@ -53,7 +53,7 @@ public abstract class SoundSystem { | ||
53 | 53 | * @param key the display system to use. |
54 | 54 | * @return the appropriate display system specified by the key. |
55 | 55 | */ |
56 | - public static SoundSystem getSoundSystem(String key) { | |
56 | + public static SoundSystem getSoundEffectSystem(String key) { | |
57 | 57 | if ("LWJGL".equalsIgnoreCase(key)) { |
58 | 58 | return new LWJGLSoundSystem(); |
59 | 59 | } |
@@ -72,7 +72,7 @@ public abstract class SoundSystem { | ||
72 | 72 | * compatible with the used <code>SoundSystem</code>. |
73 | 73 | */ |
74 | 74 | |
75 | - public abstract SoundRenderer getRenderer(); | |
75 | + public abstract IRenderer getRenderer(); | |
76 | 76 | |
77 | 77 | /** |
78 | 78 | * <code>isCreated</code> returns the current status of the sound |
@@ -84,9 +84,4 @@ public abstract class SoundSystem { | ||
84 | 84 | |
85 | 85 | public abstract boolean isCreated(); |
86 | 86 | |
87 | - | |
88 | - | |
89 | - | |
90 | - | |
91 | - | |
92 | 87 | } |
@@ -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 | +} |
@@ -38,7 +38,9 @@ package com.jme.sound.action; | ||
38 | 38 | |
39 | 39 | import com.jme.input.action.KeyBackwardAction; |
40 | 40 | 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 | + | |
42 | 44 | |
43 | 45 | /** |
44 | 46 | * @author Arman Ozcelik |
@@ -47,13 +49,13 @@ import com.jme.sound.SoundSource; | ||
47 | 49 | public class SoundBackwardAction extends KeyBackwardAction { |
48 | 50 | |
49 | 51 | private String sound; |
50 | - private SoundSource player; | |
52 | + private IEffectPlayer player; | |
51 | 53 | |
52 | 54 | /** |
53 | 55 | * @param camera |
54 | 56 | * @param speed |
55 | 57 | */ |
56 | - public SoundBackwardAction(Camera camera, float speed, SoundSource soundPlayer, String soundName) { | |
58 | + public SoundBackwardAction(Camera camera, float speed, IEffectPlayer soundPlayer, String soundName) { | |
57 | 59 | super(camera, speed); |
58 | 60 | player = soundPlayer; |
59 | 61 | sound = soundName; |
@@ -64,8 +66,8 @@ public class SoundBackwardAction extends KeyBackwardAction { | ||
64 | 66 | */ |
65 | 67 | public void performAction(float time) { |
66 | 68 | 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)); | |
69 | 71 | } |
70 | 72 | } |
71 | 73 | } |
@@ -38,7 +38,9 @@ package com.jme.sound.action; | ||
38 | 38 | |
39 | 39 | import com.jme.input.action.KeyForwardAction; |
40 | 40 | 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; | |
42 | 44 | |
43 | 45 | /** |
44 | 46 | * @author Arman Ozcelik |
@@ -46,27 +48,29 @@ import com.jme.sound.SoundSource; | ||
46 | 48 | */ |
47 | 49 | public class SoundForwardAction extends KeyForwardAction { |
48 | 50 | |
49 | - private SoundSource player; | |
51 | + private IEffectPlayer player; | |
50 | 52 | private String sound; |
51 | 53 | |
52 | 54 | /** |
53 | 55 | * @param camera |
54 | 56 | * @param speed |
55 | 57 | */ |
56 | - public SoundForwardAction(Camera camera, float speed, SoundSource soundPlayer, String soundName) { | |
58 | + public SoundForwardAction(Camera camera, float speed, IEffectPlayer soundPlayer, String soundName) { | |
57 | 59 | super(camera, speed); |
58 | - player = soundPlayer; | |
59 | - sound = soundName; | |
60 | + player= soundPlayer; | |
61 | + sound= soundName; | |
60 | 62 | } |
61 | 63 | |
62 | 64 | /** |
63 | - * @see com.jme.input.action.InputAction#performAction(float) | |
64 | - */ | |
65 | + * @see com.jme.input.action.InputAction#performAction(float) | |
66 | + */ | |
65 | 67 | public void performAction(float time) { |
66 | 68 | 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 | + } | |
69 | 74 | } |
70 | 75 | } |
71 | - | |
72 | 76 | } |
@@ -38,7 +38,8 @@ package com.jme.sound.action; | ||
38 | 38 | |
39 | 39 | import com.jme.input.action.KeyLookDownAction; |
40 | 40 | import com.jme.renderer.Camera; |
41 | -import com.jme.sound.SoundSource; | |
41 | +import com.jme.sound.IEffectPlayer; | |
42 | +import com.jme.sound.utils.EffectRepository; | |
42 | 43 | |
43 | 44 | /** |
44 | 45 | * @author Arman Ozcelik |
@@ -47,15 +48,15 @@ import com.jme.sound.SoundSource; | ||
47 | 48 | public class SoundLookDownAction extends KeyLookDownAction { |
48 | 49 | |
49 | 50 | private String sound; |
50 | - private SoundSource player; | |
51 | + private IEffectPlayer player; | |
51 | 52 | /** |
52 | 53 | * @param camera |
53 | 54 | * @param speed |
54 | 55 | */ |
55 | - public SoundLookDownAction(Camera camera, float speed, SoundSource soundPlayer, String soundName) { | |
56 | + public SoundLookDownAction(Camera camera, float speed, IEffectPlayer soundPlayer, String soundName) { | |
56 | 57 | super(camera, speed); |
57 | - player = soundPlayer; | |
58 | - sound = soundName; | |
58 | + player= soundPlayer; | |
59 | + sound= soundName; | |
59 | 60 | } |
60 | 61 | |
61 | 62 | /** |
@@ -63,8 +64,8 @@ public class SoundLookDownAction extends KeyLookDownAction { | ||
63 | 64 | */ |
64 | 65 | public void performAction(float time) { |
65 | 66 | 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)); | |
68 | 69 | } |
69 | 70 | } |
70 | -} | |
71 | +} | |
\ No newline at end of file |
@@ -38,7 +38,8 @@ package com.jme.sound.action; | ||
38 | 38 | |
39 | 39 | import com.jme.input.action.KeyLookUpAction; |
40 | 40 | import com.jme.renderer.Camera; |
41 | -import com.jme.sound.SoundSource; | |
41 | +import com.jme.sound.IEffectPlayer; | |
42 | +import com.jme.sound.utils.EffectRepository; | |
42 | 43 | |
43 | 44 | /** |
44 | 45 | * @author Arman Ozcelik |
@@ -47,15 +48,15 @@ import com.jme.sound.SoundSource; | ||
47 | 48 | public class SoundLookUpAction extends KeyLookUpAction { |
48 | 49 | |
49 | 50 | private String sound; |
50 | - private SoundSource player; | |
51 | + private IEffectPlayer player; | |
51 | 52 | /** |
52 | 53 | * @param camera |
53 | 54 | * @param speed |
54 | 55 | */ |
55 | - public SoundLookUpAction(Camera camera, float speed, SoundSource soundPlayer, String soundName) { | |
56 | + public SoundLookUpAction(Camera camera, float speed, IEffectPlayer soundPlayer, String soundName) { | |
56 | 57 | super(camera, speed); |
57 | - player = soundPlayer; | |
58 | - sound = soundName; | |
58 | + player= soundPlayer; | |
59 | + sound= soundName; | |
59 | 60 | } |
60 | 61 | |
61 | 62 | /** |
@@ -63,8 +64,8 @@ public class SoundLookUpAction extends KeyLookUpAction { | ||
63 | 64 | */ |
64 | 65 | public void performAction(float time) { |
65 | 66 | 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)); | |
68 | 69 | } |
69 | 70 | } |
70 | -} | |
71 | +} | |
\ No newline at end of file |
@@ -38,7 +38,8 @@ package com.jme.sound.action; | ||
38 | 38 | |
39 | 39 | import com.jme.input.action.KeyRotateLeftAction; |
40 | 40 | import com.jme.renderer.Camera; |
41 | -import com.jme.sound.SoundSource; | |
41 | +import com.jme.sound.IEffectPlayer; | |
42 | +import com.jme.sound.utils.EffectRepository; | |
42 | 43 | |
43 | 44 | /** |
44 | 45 | * @author Arman Ozcelik |
@@ -47,15 +48,15 @@ import com.jme.sound.SoundSource; | ||
47 | 48 | public class SoundRotateLeftAction extends KeyRotateLeftAction { |
48 | 49 | |
49 | 50 | private String sound; |
50 | - private SoundSource player; | |
51 | + private IEffectPlayer player; | |
51 | 52 | /** |
52 | 53 | * @param camera |
53 | 54 | * @param speed |
54 | 55 | */ |
55 | - public SoundRotateLeftAction(Camera camera, float speed, SoundSource soundPlayer, String soundName) { | |
56 | + public SoundRotateLeftAction(Camera camera, float speed, IEffectPlayer soundPlayer, String soundName) { | |
56 | 57 | super(camera, speed); |
57 | - player = soundPlayer; | |
58 | - sound = soundName; | |
58 | + player= soundPlayer; | |
59 | + sound= soundName; | |
59 | 60 | } |
60 | 61 | |
61 | 62 | /** |
@@ -63,8 +64,8 @@ public class SoundRotateLeftAction extends KeyRotateLeftAction { | ||
63 | 64 | */ |
64 | 65 | public void performAction(float time) { |
65 | 66 | 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)); | |
68 | 69 | } |
69 | 70 | } |
70 | -} | |
71 | +} | |
\ No newline at end of file |
@@ -38,7 +38,8 @@ package com.jme.sound.action; | ||
38 | 38 | |
39 | 39 | import com.jme.input.action.KeyRotateRightAction; |
40 | 40 | import com.jme.renderer.Camera; |
41 | -import com.jme.sound.SoundSource; | |
41 | +import com.jme.sound.IEffectPlayer; | |
42 | +import com.jme.sound.utils.EffectRepository; | |
42 | 43 | |
43 | 44 | /** |
44 | 45 | * @author Arman Ozcelik |
@@ -46,24 +47,24 @@ import com.jme.sound.SoundSource; | ||
46 | 47 | */ |
47 | 48 | public class SoundRotateRightAction extends KeyRotateRightAction { |
48 | 49 | 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 | + } | |
59 | 60 | |
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)); | |
68 | 68 | } |
69 | 69 | } |
70 | +} | |
\ No newline at end of file |
@@ -38,7 +38,8 @@ package com.jme.sound.action; | ||
38 | 38 | |
39 | 39 | import com.jme.input.action.KeyStrafeLeftAction; |
40 | 40 | import com.jme.renderer.Camera; |
41 | -import com.jme.sound.SoundSource; | |
41 | +import com.jme.sound.IEffectPlayer; | |
42 | +import com.jme.sound.utils.EffectRepository; | |
42 | 43 | |
43 | 44 | /** |
44 | 45 | * @author Arman Ozcelik |
@@ -46,15 +47,15 @@ import com.jme.sound.SoundSource; | ||
46 | 47 | */ |
47 | 48 | public class SoundStrafeLeftAction extends KeyStrafeLeftAction { |
48 | 49 | private String sound; |
49 | - private SoundSource player; | |
50 | + private IEffectPlayer player; | |
50 | 51 | /** |
51 | 52 | * @param camera |
52 | 53 | * @param speed |
53 | 54 | */ |
54 | - public SoundStrafeLeftAction(Camera camera, float speed, SoundSource soundPlayer, String soundName) { | |
55 | + public SoundStrafeLeftAction(Camera camera, float speed, IEffectPlayer soundPlayer, String soundName) { | |
55 | 56 | super(camera, speed); |
56 | - player = soundPlayer; | |
57 | - sound = soundName; | |
57 | + player= soundPlayer; | |
58 | + sound= soundName; | |
58 | 59 | } |
59 | 60 | |
60 | 61 | /** |
@@ -62,8 +63,8 @@ public class SoundStrafeLeftAction extends KeyStrafeLeftAction { | ||
62 | 63 | */ |
63 | 64 | public void performAction(float time) { |
64 | 65 | 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)); | |
67 | 68 | } |
68 | 69 | } |
69 | -} | |
70 | +} | |
\ No newline at end of file |
@@ -38,7 +38,8 @@ package com.jme.sound.action; | ||
38 | 38 | |
39 | 39 | import com.jme.input.action.KeyStrafeRightAction; |
40 | 40 | import com.jme.renderer.Camera; |
41 | -import com.jme.sound.SoundSource; | |
41 | +import com.jme.sound.IEffectPlayer; | |
42 | +import com.jme.sound.utils.EffectRepository; | |
42 | 43 | |
43 | 44 | /** |
44 | 45 | * @author Arman Ozcelik |
@@ -47,15 +48,15 @@ import com.jme.sound.SoundSource; | ||
47 | 48 | public class SoundStrafeRightAction extends KeyStrafeRightAction { |
48 | 49 | |
49 | 50 | private String sound; |
50 | - private SoundSource player; | |
51 | + private IEffectPlayer player; | |
51 | 52 | /** |
52 | 53 | * @param camera |
53 | 54 | * @param speed |
54 | 55 | */ |
55 | - public SoundStrafeRightAction(Camera camera, float speed, SoundSource soundPlayer, String soundName) { | |
56 | + public SoundStrafeRightAction(Camera camera, float speed, IEffectPlayer soundPlayer, String soundName) { | |
56 | 57 | super(camera, speed); |
57 | - player = soundPlayer; | |
58 | - sound = soundName; | |
58 | + player= soundPlayer; | |
59 | + sound= soundName; | |
59 | 60 | } |
60 | 61 | |
61 | 62 | /** |
@@ -63,8 +64,8 @@ public class SoundStrafeRightAction extends KeyStrafeRightAction { | ||
63 | 64 | */ |
64 | 65 | public void performAction(float time) { |
65 | 66 | 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)); | |
68 | 69 | } |
69 | 70 | } |
70 | -} | |
71 | +} | |
\ No newline at end of file |
@@ -31,51 +31,42 @@ | ||
31 | 31 | */ |
32 | 32 | |
33 | 33 | /* |
34 | - * Created on 23 oct. 2003 | |
34 | + * Created on 31 oct. 2003 | |
35 | 35 | * |
36 | 36 | */ |
37 | 37 | package com.jme.sound.utils; |
38 | 38 | |
39 | - | |
40 | 39 | import java.util.Hashtable; |
41 | 40 | |
42 | -import com.jme.sound.SoundSource; | |
43 | - | |
44 | - | |
41 | +import com.jme.sound.IEffectPlayer; | |
45 | 42 | |
46 | 43 | /** |
47 | 44 | * @author Arman Ozcelik |
48 | 45 | * |
49 | 46 | */ |
50 | -public class SourceRepository { | |
47 | +public class EffectPlayerRepository { | |
48 | + | |
49 | + private Hashtable repository = new Hashtable(); | |
50 | + private static EffectPlayerRepository instance; | |
51 | + | |
52 | + private EffectPlayerRepository() { | |
51 | 53 | |
52 | - private Hashtable repository=new Hashtable(); | |
53 | - private static SourceRepository instance; | |
54 | - | |
55 | - private SourceRepository() { | |
56 | - | |
57 | 54 | } |
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(); | |
62 | 59 | } |
63 | - return instance; | |
60 | + return instance; | |
64 | 61 | } |
65 | - | |
66 | - public void bind(Object player, SoundSource source){ | |
62 | + | |
63 | + public void bind(Object player, IEffectPlayer source) { | |
67 | 64 | repository.put(player, source); |
68 | - | |
65 | + | |
69 | 66 | } |
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); | |
73 | 70 | } |
74 | - | |
75 | - | |
76 | - | |
77 | - | |
78 | - | |
79 | - | |
80 | 71 | |
81 | 72 | } |
@@ -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 | +} |
@@ -31,54 +31,84 @@ | ||
31 | 31 | */ |
32 | 32 | |
33 | 33 | /* |
34 | - * Created on 27 oct. 2003 | |
34 | + * Created on 1 nov. 2003 | |
35 | 35 | * |
36 | 36 | */ |
37 | -package com.jme.sound; | |
37 | +package com.jme.sound.utils; | |
38 | 38 | |
39 | 39 | import java.util.ArrayList; |
40 | 40 | |
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; | |
42 | 48 | |
43 | 49 | /** |
44 | 50 | * @author Arman Ozcelik |
45 | - * | |
46 | - * This class thread unsafe. A playlist sould be filled once for ever. | |
47 | 51 | * |
48 | 52 | */ |
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; | |
50 | 59 | |
51 | - private ArrayList preloaded; | |
52 | - /** | |
53 | - * | |
54 | - */ | |
55 | - public LWJGLPlaylist() { | |
56 | - preloaded = new ArrayList(); | |
60 | + protected OnDemandSoundLoader() { | |
57 | 61 | } |
58 | 62 | |
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; | |
67 | 67 | } |
68 | 68 | |
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 | + | |
72 | 108 | } |
73 | - return null; | |
74 | - } | |
75 | 109 | |
76 | - public boolean hasNext() { | |
77 | - return preloaded.size() > 0; | |
78 | 110 | } |
111 | + | |
79 | 112 | |
80 | - public int length() { | |
81 | - return preloaded.size(); | |
82 | - } | |
83 | 113 | |
84 | 114 | } |
@@ -4,8 +4,10 @@ | ||
4 | 4 | */ |
5 | 5 | package com.jme.test.sound; |
6 | 6 | |
7 | +import com.jme.sound.IEffectPlayer; | |
8 | +import com.jme.sound.IRenderer; | |
7 | 9 | import com.jme.sound.SoundSystem; |
8 | -import com.jme.sound.SoundRenderer; | |
10 | +import com.jme.sound.utils.EffectRepository; | |
9 | 11 | |
10 | 12 | |
11 | 13 |
@@ -17,28 +19,22 @@ public class TestSound{ | ||
17 | 19 | |
18 | 20 | |
19 | 21 | 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 | + | |
23 | 25 | renderer.addSoundPlayer("NPC"); |
24 | 26 | |
25 | - renderer.loadSoundAs("music", "cu.wav"); | |
26 | - renderer.loadSoundAs("bored", "01.mp3"); | |
27 | + renderer.loadSoundAs("music", "../data/sound/walk.mp3"); | |
27 | 28 | |
28 | - renderer.getSoundPlayer("MONSTER").setNumberOfBuffers(1); | |
29 | - renderer.getSoundPlayer("NPC").setNumberOfBuffers(128); | |
30 | 29 | |
31 | - renderer.getSoundPlayer("MONSTER").updatePosition(1, 0, 0); | |
32 | - renderer.getSoundPlayer("NPC").updatePosition(0, 0, 0); | |
33 | - renderer.getSoundPlayer("NPC").updateVelocity(0, 0, 0); | |
34 | 30 | |
35 | 31 | //renderer.getSoundPlayer("MONSTER").play("music"); |
36 | - renderer.getSoundPlayer("NPC").play("bored"); | |
32 | + renderer.getSoundPlayer("NPC").play(EffectRepository.getRepository().getSource("music")); | |
37 | 33 | |
38 | 34 | |
39 | - //while(renderer.getSoundPlayer("MONSTER").isPlaying()){ | |
40 | - // Thread.sleep(1000); | |
41 | - //} | |
35 | + while(renderer.getSoundPlayer("NPC").getStatus()==IEffectPlayer.PLAYING){ | |
36 | + Thread.sleep(1000); | |
37 | + } | |
42 | 38 | |
43 | 39 | |
44 | 40 | } |
@@ -32,6 +32,8 @@ | ||
32 | 32 | package com.jme.test.sound; |
33 | 33 | |
34 | 34 | |
35 | + | |
36 | + | |
35 | 37 | import com.jme.app.AbstractGame; |
36 | 38 | import com.jme.image.Texture; |
37 | 39 | import com.jme.math.Vector3f; |
@@ -47,8 +49,8 @@ import com.jme.system.LWJGLDisplaySystem; | ||
47 | 49 | import com.jme.util.TextureManager; |
48 | 50 | |
49 | 51 | |
52 | +import com.jme.sound.IRenderer; | |
50 | 53 | import com.jme.sound.SoundSystem; |
51 | -import com.jme.sound.SoundRenderer; | |
52 | 54 | |
53 | 55 | /** |
54 | 56 | * <code>TestSoundLoop</code> |
@@ -60,7 +62,7 @@ public class TestSoundLoop extends AbstractGame { | ||
60 | 62 | private Text text; |
61 | 63 | private Camera cam; |
62 | 64 | private Node scene; |
63 | - private SoundRenderer soundRenderer; | |
65 | + private IRenderer soundRenderer; | |
64 | 66 | |
65 | 67 | public static void main(String[] args) { |
66 | 68 | TestSoundLoop app = new TestSoundLoop(); |
@@ -73,10 +75,7 @@ public class TestSoundLoop extends AbstractGame { | ||
73 | 75 | * @see com.jme.app.AbstractGame#update() |
74 | 76 | */ |
75 | 77 | protected void update() { |
76 | - if(!soundRenderer.getSoundPlayer("NPC").isPlaying()) { | |
77 | - soundRenderer.getSoundPlayer("NPC").play("bored"); | |
78 | - | |
79 | - } | |
78 | + | |
80 | 79 | } |
81 | 80 | |
82 | 81 | /** |
@@ -108,7 +107,7 @@ public class TestSoundLoop extends AbstractGame { | ||
108 | 107 | System.exit(1); |
109 | 108 | } |
110 | 109 | |
111 | - SoundSystem system=SoundSystem.getSoundSystem("LWJGL"); | |
110 | + SoundSystem system=SoundSystem.getSoundEffectSystem("LWJGL"); | |
112 | 111 | soundRenderer=system.getRenderer(); |
113 | 112 | |
114 | 113 |
@@ -138,7 +137,7 @@ public class TestSoundLoop extends AbstractGame { | ||
138 | 137 | ts.setEnabled(true); |
139 | 138 | ts.setTexture( |
140 | 139 | TextureManager.loadTexture( |
141 | - "data/Font/font.png", | |
140 | + "../data/Font/font.png", | |
142 | 141 | Texture.MM_LINEAR, |
143 | 142 | Texture.FM_LINEAR, |
144 | 143 | true)); |
@@ -158,16 +157,13 @@ public class TestSoundLoop extends AbstractGame { | ||
158 | 157 | |
159 | 158 | soundRenderer.addSoundPlayer("MONSTER"); |
160 | 159 | soundRenderer.addSoundPlayer("NPC"); |
161 | - | |
160 | + | |
162 | 161 | 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"); | |
167 | 163 | |
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 | + | |
171 | 167 | |
172 | 168 | } |
173 | 169 |
@@ -51,8 +51,9 @@ import com.jme.system.JmeException; | ||
51 | 51 | import com.jme.system.LWJGLDisplaySystem; |
52 | 52 | import com.jme.util.TextureManager; |
53 | 53 | |
54 | +import com.jme.sound.IRenderer; | |
54 | 55 | import com.jme.sound.SoundSystem; |
55 | -import com.jme.sound.SoundRenderer; | |
56 | + | |
56 | 57 | /** |
57 | 58 | * @author Arman Ozcelik |
58 | 59 | * |
@@ -62,7 +63,7 @@ public class TestSoundMove extends AbstractGame { | ||
62 | 63 | private Text text; |
63 | 64 | private Camera cam; |
64 | 65 | private Node scene; |
65 | - private SoundRenderer soundRenderer; | |
66 | + private IRenderer soundRenderer; | |
66 | 67 | private RelativeMouse mouse; |
67 | 68 | float x; |
68 | 69 | float y; |
@@ -80,24 +81,7 @@ public class TestSoundMove extends AbstractGame { | ||
80 | 81 | protected void update() { |
81 | 82 | mouse.update(); |
82 | 83 | |
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 | + | |
101 | 85 | } |
102 | 86 | |
103 | 87 | /** |
@@ -132,7 +116,7 @@ public class TestSoundMove extends AbstractGame { | ||
132 | 116 | System.exit(1); |
133 | 117 | } |
134 | 118 | InputSystem.createInputSystem(properties.getRenderer()); |
135 | - SoundSystem system = SoundSystem.getSoundSystem("LWJGL"); | |
119 | + SoundSystem system = SoundSystem.getSoundEffectSystem("LWJGL"); | |
136 | 120 | soundRenderer = system.getRenderer(); |
137 | 121 | |
138 | 122 | ColorRGBA blueColor = new ColorRGBA(); |
@@ -207,12 +191,7 @@ public class TestSoundMove extends AbstractGame { | ||
207 | 191 | soundRenderer.loadSoundAs("music", "walk.wav"); |
208 | 192 | soundRenderer.loadSoundAs("bored", "03.mp3"); |
209 | 193 | |
210 | - soundRenderer.getSoundPlayer("MONSTER").setNumberOfBuffers(1); | |
211 | - soundRenderer.getSoundPlayer("NPC").setNumberOfBuffers(128); | |
212 | 194 | |
213 | - soundRenderer.getSoundPlayer("MONSTER").updatePosition(0, 0, 0); | |
214 | - soundRenderer.getSoundPlayer("NPC").updatePosition(0, 0, 0); | |
215 | - soundRenderer.getSoundPlayer("NPC").updateVelocity(0, 0, 0); | |
216 | 195 | |
217 | 196 | } |
218 | 197 |