Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
epoxy
GitHub Repository: epoxy/proj11
Path: blob/master/SLICK_HOME/src/org/newdawn/slick/openal/AudioLoader.java
1461 views
1
package org.newdawn.slick.openal;
2
3
import java.io.IOException;
4
import java.io.InputStream;
5
import java.net.URL;
6
7
/**
8
* A utility to provide a simple and rational interface to the
9
* slick internals
10
*
11
* @author kevin
12
*/
13
public class AudioLoader {
14
/** AIF Format Indicator */
15
private static final String AIF = "AIF";
16
/** WAV Format Indicator */
17
private static final String WAV = "WAV";
18
/** OGG Format Indicator */
19
private static final String OGG = "OGG";
20
/** MOD/XM Format Indicator */
21
private static final String MOD = "MOD";
22
/** MOD/XM Format Indicator */
23
private static final String XM = "XM";
24
25
/** True if the audio loader has be initialised */
26
private static boolean inited = false;
27
28
/**
29
* Initialise the audio loader
30
*/
31
private static void init() {
32
if (!inited) {
33
SoundStore.get().init();
34
inited = true;
35
}
36
}
37
38
/**
39
* Get audio data in a playable state by loading the complete audio into
40
* memory.
41
*
42
* @param format The format of the audio to be loaded (something like "XM" or "OGG")
43
* @param in The input stream from which to load the audio data
44
* @return An object representing the audio data
45
* @throws IOException Indicates a failure to access the audio data
46
*/
47
public static Audio getAudio(String format, InputStream in) throws IOException {
48
init();
49
50
if (format.equals(AIF)) {
51
return SoundStore.get().getAIF(in);
52
}
53
if (format.equals(WAV)) {
54
return SoundStore.get().getWAV(in);
55
}
56
if (format.equals(OGG)) {
57
return SoundStore.get().getOgg(in);
58
}
59
60
throw new IOException("Unsupported format for non-streaming Audio: "+format);
61
}
62
63
/**
64
* Get audio data in a playable state by setting up a stream that can be piped into
65
* OpenAL - i.e. streaming audio
66
*
67
* @param format The format of the audio to be loaded (something like "XM" or "OGG")
68
* @param url The location of the data that should be streamed
69
* @return An object representing the audio data
70
* @throws IOException Indicates a failure to access the audio data
71
*/
72
public static Audio getStreamingAudio(String format, URL url) throws IOException {
73
init();
74
75
if (format.equals(OGG)) {
76
return SoundStore.get().getOggStream(url);
77
}
78
if (format.equals(MOD)) {
79
return SoundStore.get().getMOD(url.openStream());
80
}
81
if (format.equals(XM)) {
82
return SoundStore.get().getMOD(url.openStream());
83
}
84
85
throw new IOException("Unsupported format for streaming Audio: "+format);
86
}
87
88
/**
89
* Allow the streaming system to update itself
90
*/
91
public static void update() {
92
init();
93
94
SoundStore.get().poll(0);
95
}
96
}
97
98