Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.ByteArrayOutputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.InputStreamReader;
- import javax.sound.sampled.AudioFormat;
- import paulscode.sound.SoundSystem;
- import paulscode.sound.SoundSystemConfig;
- import paulscode.sound.Vector3D;
- import paulscode.sound.libraries.LibraryLWJGLOpenAL;
- public class Main {
- public static void main(String[] args) throws Throwable {
- BufferedReader systemIn = new BufferedReader(new InputStreamReader(System.in));
- System.out.println("Pausing");
- systemIn.readLine();
- float sampleRate = 8000;
- int sampleSizeInBits = 8;
- int channels = 1;
- boolean signed = false;
- boolean bigEndian = false;
- System.out.println("Setting up sound system.");
- String sourceName = "TestSource";
- SoundSystemConfig.addLibrary(LibraryLWJGLOpenAL.class);
- SoundSystem system = new SoundSystem();
- system.rawDataStream(format, false, sourceName, 0, 0, 0, SoundSystemConfig.ATTENUATION_NONE, 1f);
- System.out.println("Reading sound.");
- FileInputStream fileIn = new FileInputStream(new File("PATH_TO_SOUND_FILE"));
- ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
- byte[] buffer = new byte[1024];
- int read = -1;
- while((read = fileIn.read(buffer)) != -1) {
- byte[] data = new byte[read];
- System.arraycopy(buffer, 0, data, 0, read);
- system.feedRawAudioData(sourceName, data);
- byteOut.write(data);
- }
- fileIn.close();
- System.out.println("Finished reading sound.");
- System.out.println("Building buffer of sound.");
- buffer = byteOut.toByteArray();
- for(int i=0; i<10; i++) {
- system.feedRawAudioData(sourceName, buffer);
- }
- System.out.println("Finished building buffer.");
- Thread.sleep(10 * 1000);
- Vector3D pos = system.getListenerData().position.add(new Vector3D(5, 5, 5));
- System.out.println("Moving listener to: " + pos);
- system.setListenerPosition(pos.x, pos.y, pos.z);
- Thread.sleep(10 * 1000);
- System.out.println("Moving source to: " + pos);
- system.setPosition(sourceName, pos.x, pos.y, pos.z);
- Thread.sleep(10 * 1000);
- pos = pos.add(new Vector3D(-5, -5, -5));
- System.out.println("Moving listener back to: " + pos);
- system.setListenerPosition(pos.x, pos.y, pos.z);
- Thread.sleep(10 * 1000);
- System.out.println("Sound done.");
- system.cleanup();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement