diff options
author | kbr <[email protected]> | 2007-05-15 05:32:36 +0000 |
---|---|---|
committer | kbr <[email protected]> | 2007-05-15 05:32:36 +0000 |
commit | 7f2ce67b36470786f6720763486e7ea4c1bc66fa (patch) | |
tree | 32fb092fa86123d5e90444f5f0d25e960bc6a043 /src | |
parent | 8f578ddb549db2835b98b3b7d3bbfbd553deb8a7 (diff) |
Fixed Issue 18: Added InputStream support for Buffer Creation for AudioSystem3D
Applied patch from conzar and also added symmetric loadSource(InputStream).
git-svn-id: file:///home/mbien/NetBeansProjects/JOGAMP/joal-sync/git-svn/../svn-server-sync/joal/trunk@527 03bf7f67-59de-4072-a415-9a990d468a3f
Diffstat (limited to 'src')
-rw-r--r-- | src/java/net/java/games/sound3d/AudioSystem3D.java | 58 |
1 files changed, 54 insertions, 4 deletions
diff --git a/src/java/net/java/games/sound3d/AudioSystem3D.java b/src/java/net/java/games/sound3d/AudioSystem3D.java index ea1affa..91fd45a 100644 --- a/src/java/net/java/games/sound3d/AudioSystem3D.java +++ b/src/java/net/java/games/sound3d/AudioSystem3D.java @@ -37,7 +37,7 @@ import net.java.games.joal.*; import net.java.games.joal.util.WAVData; import net.java.games.joal.util.WAVLoader; -import java.io.IOException; +import java.io.*; import javax.sound.sampled.UnsupportedAudioFileException; @@ -137,7 +137,7 @@ public class AudioSystem3D { * * @throws IOException If the file cannot be found or some other IO error * occurs. - * @throws UnsupportedAudioFileException If the format of the sudio data is + * @throws UnsupportedAudioFileException If the format of the audio data is * not supported */ public static Buffer loadBuffer(String filename) @@ -153,8 +153,37 @@ public class AudioSystem3D { } /** + * Loads a Sound3D buffer with the specified audio file. + * + * @param stream contains the stream associated with the audio file. + * + * @return a new Sound3D buffer containing the audio data from the + * passed stream. + * + * @throws IOException If the stream cannot be read or some other IO error + * occurs. + * @throws UnsupportedAudioFileException If the format of the audio data is + * not supported + */ + public static Buffer loadBuffer(InputStream stream) + throws IOException, UnsupportedAudioFileException { + Buffer result; + Buffer[] tmp = generateBuffers(1); + result = tmp[0]; + + if (!(stream instanceof BufferedInputStream)) { + stream = new BufferedInputStream(stream); + } + WAVData wd = WAVLoader.loadFromStream(stream); + + result.configure(wd.data, wd.format, wd.freq); + + return result; + } + + /** * Loads a Sound3D Source with the specified audio file. This is - * functionally equivelant to generateSource(loadBuffer(fileName)); + * functionally equivalent to generateSource(loadBuffer(fileName)); * * @param filename the name of the file to load. * @@ -163,7 +192,7 @@ public class AudioSystem3D { * * @throws IOException If the file cannot be found or some other IO error * occurs. - * @throws UnsupportedAudioFileException If the format of the sudio data is + * @throws UnsupportedAudioFileException If the format of the audio data is * not supported */ public static Source loadSource(String filename) @@ -174,6 +203,27 @@ public class AudioSystem3D { } /** + * Loads a Sound3D Source with the specified audio stream. This is + * functionally equivalent to generateSource(loadBuffer(stream)); + * + * @param stream contains the stream associated with the audio file. + * + * @return a new Sound3D Source containing the audio data from the + * passed stream. + * + * @throws IOException If the file cannot be found or some other IO error + * occurs. + * @throws UnsupportedAudioFileException If the format of the audio data is + * not supported + */ + public static Source loadSource(InputStream stream) + throws IOException, UnsupportedAudioFileException { + Buffer buffer = loadBuffer(stream); + + return generateSource(buffer); + } + + /** * Generates a set of uninitialized Source3D sources * * @param numSources the number of Sound3D sources to generate. |