Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
epoxy
GitHub Repository: epoxy/proj11
Path: blob/master/SLICK_HOME/src/org/newdawn/slick/openal/MODSound.java
1461 views
1
package org.newdawn.slick.openal;
2
3
import ibxm.Module;
4
import ibxm.OpenALMODPlayer;
5
6
import java.io.IOException;
7
import java.io.InputStream;
8
import java.nio.IntBuffer;
9
10
import org.lwjgl.BufferUtils;
11
import org.lwjgl.openal.AL10;
12
13
/**
14
* A sound as a MOD file - can only be played as music
15
*
16
* @author Kevin Glass
17
*/
18
public class MODSound extends AudioImpl {
19
/** The MOD play back system */
20
private static OpenALMODPlayer player = new OpenALMODPlayer();
21
22
/** The module to play back */
23
private Module module;
24
/** The sound store this belongs to */
25
private SoundStore store;
26
27
/**
28
* Create a mod sound to be played back
29
*
30
* @param store The store this sound belongs to
31
* @param in The input stream to read the data from
32
* @throws IOException Indicates a failure to load a sound
33
*/
34
public MODSound(SoundStore store, InputStream in) throws IOException {
35
this.store = store;
36
module = OpenALMODPlayer.loadModule(in);
37
}
38
39
/**
40
* @see org.newdawn.slick.openal.AudioImpl#playAsMusic(float, float, boolean)
41
*/
42
public int playAsMusic(float pitch, float gain, boolean loop) {
43
cleanUpSource();
44
45
player.play(module, store.getSource(0), loop, SoundStore.get().isMusicOn());
46
player.setup(pitch, 1.0f);
47
store.setCurrentMusicVolume(gain);
48
49
store.setMOD(this);
50
51
return store.getSource(0);
52
}
53
54
/**
55
* Clean up the buffers applied to the sound source
56
*/
57
private void cleanUpSource() {
58
AL10.alSourceStop(store.getSource(0));
59
IntBuffer buffer = BufferUtils.createIntBuffer(1);
60
int queued = AL10.alGetSourcei(store.getSource(0), AL10.AL_BUFFERS_QUEUED);
61
62
while (queued > 0)
63
{
64
AL10.alSourceUnqueueBuffers(store.getSource(0), buffer);
65
queued--;
66
}
67
68
AL10.alSourcei(store.getSource(0), AL10.AL_BUFFER, 0);
69
}
70
71
/**
72
* Poll the streaming on the MOD
73
*/
74
public void poll() {
75
player.update();
76
}
77
78
/**
79
* @see org.newdawn.slick.openal.AudioImpl#playAsSoundEffect(float, float, boolean)
80
*/
81
public int playAsSoundEffect(float pitch, float gain, boolean loop) {
82
return -1;
83
}
84
85
/**
86
* @see org.newdawn.slick.openal.AudioImpl#stop()
87
*/
88
public void stop() {
89
store.setMOD(null);
90
}
91
92
/**
93
* @see org.newdawn.slick.openal.AudioImpl#getPosition()
94
*/
95
public float getPosition() {
96
throw new RuntimeException("Positioning on modules is not currently supported");
97
}
98
99
/**
100
* @see org.newdawn.slick.openal.AudioImpl#setPosition(float)
101
*/
102
public boolean setPosition(float position) {
103
throw new RuntimeException("Positioning on modules is not currently supported");
104
}
105
}
106
107