format/reindent
using phero resources defaults to a file now
This commit is contained in:
parent
851e5f2c08
commit
571a2fe348
|
@ -50,14 +50,18 @@ import org.lwjgl.fmod3.callbacks.FSoundStreamCallback;
|
|||
* @version $Revision$
|
||||
*/
|
||||
public class DSPTest {
|
||||
|
||||
public static int bytesPerSample;
|
||||
public static int channels;
|
||||
|
||||
|
||||
public static int bytesPerSample;
|
||||
|
||||
public static int channels;
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length < 1) {
|
||||
System.out.println("Usage:\n DSPTest <file>");
|
||||
return;
|
||||
|
||||
// default to phero.mp3
|
||||
args = new String[] { "res\\phero.mp3"};
|
||||
System.out.println("Using default: " + args[0]);
|
||||
}
|
||||
|
||||
File file = new File(args[0]);
|
||||
|
@ -84,56 +88,54 @@ public class DSPTest {
|
|||
FSoundStream stream = FSound.FSOUND_Stream_Open(args[0], FSound.FSOUND_NORMAL, 0, 0);
|
||||
|
||||
if (stream != null) {
|
||||
System.out.println("Creating dsp unit");
|
||||
FSoundDSPUnit unit = FSound.FSOUND_Stream_CreateDSP(stream, new DSPTest().new TestDspCallback("1"), 1);
|
||||
FSound.FSOUND_DSP_SetActive(unit, true);
|
||||
FSoundDSPUnit unit2 = FSound.FSOUND_Stream_CreateDSP(stream, new DSPTest().new TestDspCallback("2"), 0);
|
||||
FSound.FSOUND_DSP_SetActive(unit2, true);
|
||||
System.out.println("Created: " + unit);
|
||||
System.out.println("Created: " + unit2);
|
||||
|
||||
switch(FSound.FSOUND_GetMixer()) {
|
||||
case FSound.FSOUND_MIXER_AUTODETECT:
|
||||
case FSound.FSOUND_MIXER_BLENDMODE:
|
||||
case FSound.FSOUND_MIXER_QUALITY_AUTODETECT:
|
||||
case FSound.FSOUND_MIXER_QUALITY_FPU:
|
||||
case FSound.FSOUND_MIXER_MONO:
|
||||
case FSound.FSOUND_MIXER_QUALITY_MONO:
|
||||
case FSound.FSOUND_MIXER_MAX:
|
||||
bytesPerSample = 8;
|
||||
break;
|
||||
default:
|
||||
bytesPerSample = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
channels = FSound.FSOUND_Stream_GetMode(stream);
|
||||
if((channels & FSound.FSOUND_STEREO) == FSound.FSOUND_STEREO) {
|
||||
channels = 2;
|
||||
} else {
|
||||
channels = 1;
|
||||
}
|
||||
|
||||
FSound.FSOUND_Stream_SetEndCallback(stream, new FSoundStreamCallback() {
|
||||
System.out.println("Creating dsp unit");
|
||||
FSoundDSPUnit unit = FSound.FSOUND_Stream_CreateDSP(stream, new DSPTest().new TestDspCallback("1"), 1);
|
||||
FSound.FSOUND_DSP_SetActive(unit, true);
|
||||
System.out.println("Created: " + unit);
|
||||
|
||||
switch (FSound.FSOUND_GetMixer()) {
|
||||
case FSound.FSOUND_MIXER_AUTODETECT:
|
||||
case FSound.FSOUND_MIXER_BLENDMODE:
|
||||
case FSound.FSOUND_MIXER_QUALITY_AUTODETECT:
|
||||
case FSound.FSOUND_MIXER_QUALITY_FPU:
|
||||
case FSound.FSOUND_MIXER_MONO:
|
||||
case FSound.FSOUND_MIXER_QUALITY_MONO:
|
||||
case FSound.FSOUND_MIXER_MAX:
|
||||
bytesPerSample = 8;
|
||||
break;
|
||||
default:
|
||||
bytesPerSample = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
channels = FSound.FSOUND_Stream_GetMode(stream);
|
||||
if ((channels & FSound.FSOUND_STEREO) == FSound.FSOUND_STEREO) {
|
||||
channels = 2;
|
||||
} else {
|
||||
channels = 1;
|
||||
}
|
||||
|
||||
FSound.FSOUND_Stream_SetEndCallback(stream, new FSoundStreamCallback() {
|
||||
|
||||
public void FSOUND_STREAMCALLBACK(FSoundStream stream, ByteBuffer buff, int len) {
|
||||
System.out.println("Done");
|
||||
}
|
||||
});
|
||||
|
||||
FSound.FSOUND_Stream_SetSyncCallback(stream, new FSoundStreamCallback() {
|
||||
public void FSOUND_STREAMCALLBACK(FSoundStream stream, ByteBuffer buff, int len) {
|
||||
System.out.println("SYNCPOINT");
|
||||
try {
|
||||
byte[] data = new byte[buff.capacity()];
|
||||
buff.get(data);
|
||||
System.out.println("Syncpoint @ " + len + ": " + new String(data));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
System.out.println("Done");
|
||||
}
|
||||
});
|
||||
|
||||
FSound.FSOUND_Stream_SetSyncCallback(stream, new FSoundStreamCallback() {
|
||||
|
||||
public void FSOUND_STREAMCALLBACK(FSoundStream stream, ByteBuffer buff, int len) {
|
||||
System.out.println("SYNCPOINT");
|
||||
try {
|
||||
byte[] data = new byte[buff.capacity()];
|
||||
buff.get(data);
|
||||
System.out.println("Syncpoint @ " + len + ": " + new String(data));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FSound.FSOUND_Stream_Play(0, stream);
|
||||
|
||||
System.out.println("Press enter to stop playing");
|
||||
|
@ -145,8 +147,8 @@ public class DSPTest {
|
|||
System.out.println("Done playing. Cleaning up");
|
||||
FSound.FSOUND_Stream_Stop(stream);
|
||||
FSound.FSOUND_Stream_Close(stream);
|
||||
FSound.FSOUND_DSP_Free(unit);
|
||||
FSound.FSOUND_DSP_Free(unit2);
|
||||
FSound.FSOUND_DSP_Free(unit);
|
||||
//FSound.FSOUND_DSP_Free(unit2);
|
||||
} else {
|
||||
System.out.println("Unable to play: " + args[0]);
|
||||
System.out.println("Error: " + FMOD.FMOD_ErrorString(FSound.FSOUND_GetError()));
|
||||
|
@ -155,32 +157,32 @@ public class DSPTest {
|
|||
FSound.FSOUND_Close();
|
||||
FMOD.destroy();
|
||||
}
|
||||
|
||||
public class TestDspCallback implements FSoundDSPCallback {
|
||||
|
||||
private String name;
|
||||
|
||||
public TestDspCallback(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public class TestDspCallback implements FSoundDSPCallback {
|
||||
|
||||
/*
|
||||
* @see org.lwjgl.fmod3.callbacks.FSoundDSPCallback#FSOUND_DSPCALLBACK(java.nio.ByteBuffer, java.nio.ByteBuffer, int)
|
||||
*/
|
||||
public ByteBuffer FSOUND_DSPCALLBACK(ByteBuffer originalbuffer, ByteBuffer newbuffer, int length) {
|
||||
short leftChannel;
|
||||
short rightChannel;
|
||||
|
||||
for(int i=0; i<length; i++) {
|
||||
leftChannel = originalbuffer.getShort();
|
||||
//rightChannel = originalbuffer.getShort();
|
||||
|
||||
// keep left, mute right channel
|
||||
newbuffer.putShort(leftChannel);
|
||||
//newbuffer.putShort(rightChannel);
|
||||
}
|
||||
newbuffer.rewind();
|
||||
return newbuffer;
|
||||
}
|
||||
}
|
||||
private String name;
|
||||
|
||||
public TestDspCallback(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.lwjgl.fmod3.callbacks.FSoundDSPCallback#FSOUND_DSPCALLBACK(java.nio.ByteBuffer, java.nio.ByteBuffer, int)
|
||||
*/
|
||||
public ByteBuffer FSOUND_DSPCALLBACK(ByteBuffer originalbuffer, ByteBuffer newbuffer, int length) {
|
||||
short leftChannel;
|
||||
short rightChannel;
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
leftChannel = originalbuffer.getShort();
|
||||
rightChannel = originalbuffer.getShort();
|
||||
|
||||
// mute right channel
|
||||
newbuffer.putShort(leftChannel);
|
||||
newbuffer.putShort((short) 0);
|
||||
}
|
||||
newbuffer.rewind();
|
||||
return newbuffer;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,12 +31,8 @@
|
|||
*/
|
||||
package org.lwjgl.test.fmod3;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import org.lwjgl.fmod3.FMOD;
|
||||
import org.lwjgl.fmod3.FMODException;
|
||||
|
@ -51,104 +47,59 @@ import org.lwjgl.fmod3.FSound;
|
|||
* @version $Revision$
|
||||
*/
|
||||
public class MusicPlayer {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
if(args.length < 1) {
|
||||
System.out.println("Usage:\n MusicPlayer <file>");
|
||||
return;
|
||||
}
|
||||
|
||||
File file = new File(args[0]);
|
||||
if (!file.exists()) {
|
||||
System.out.println("No such file: " + args[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
FMOD.create();
|
||||
} catch (FMODException fmode) {
|
||||
fmode.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Initializing FMOD");
|
||||
if(!FSound.FSOUND_Init(44100, 32, 0)) {
|
||||
System.out.println("Failed to initialize FMOD");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Loading " + args[0]);
|
||||
|
||||
// choose either way of loading...
|
||||
|
||||
// using name (path)
|
||||
FMusicModule module = FMusic.FMUSIC_LoadSong(args[0]);
|
||||
|
||||
// using name (path), extended mode
|
||||
//FMusicModule module = FMusic.FMUSIC_LoadSongEx(args[0], 0, 0, 0, null);
|
||||
|
||||
// using memory buffers
|
||||
//ByteBuffer data = getData(args[0]);
|
||||
//FMusicModule module = FMusic.FMUSIC_LoadSongEx(data, 0, data.remaining(), FSound.FSOUND_LOADMEMORY, null);
|
||||
|
||||
if(module != null) {
|
||||
System.out.println("Loaded. Playing module of type: " + FMusic.FMUSIC_GetType(module));
|
||||
FMusic.FMUSIC_PlaySong(module);
|
||||
|
||||
System.out.println("Press enter to stop playing");
|
||||
try {
|
||||
System.in.read();
|
||||
} catch (IOException ioe) {
|
||||
}
|
||||
FMusic.FMUSIC_StopSong(module);
|
||||
|
||||
System.out.println("Done playing. Cleaning up");
|
||||
FMusic.FMUSIC_FreeSong(module);
|
||||
} else {
|
||||
System.out.println("Unable to play: " + args[0]);
|
||||
System.out.println("Error: " + FMOD.FMOD_ErrorString(FSound.FSOUND_GetError()));
|
||||
}
|
||||
|
||||
FSound.FSOUND_Close();
|
||||
FMOD.destroy();
|
||||
if (args.length < 1) {
|
||||
System.out.println("Usage:\n MusicPlayer <file>");
|
||||
|
||||
// default to Missing_you.mod
|
||||
args = new String[] { "res\\Missing_you.mod"};
|
||||
System.out.println("Using default: " + args[0]);
|
||||
}
|
||||
|
||||
File file = new File(args[0]);
|
||||
if (!file.exists()) {
|
||||
System.out.println("No such file: " + args[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
FMOD.create();
|
||||
} catch (FMODException fmode) {
|
||||
fmode.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Initializing FMOD");
|
||||
if (!FSound.FSOUND_Init(44100, 32, 0)) {
|
||||
System.out.println("Failed to initialize FMOD");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Loading " + args[0]);
|
||||
|
||||
// using name (path)
|
||||
FMusicModule module = FMusic.FMUSIC_LoadSong(args[0]);
|
||||
|
||||
if (module != null) {
|
||||
System.out.println("Loaded. Playing module of type: " + FMusic.FMUSIC_GetType(module));
|
||||
FMusic.FMUSIC_PlaySong(module);
|
||||
|
||||
System.out.println("Press enter to stop playing");
|
||||
try {
|
||||
System.in.read();
|
||||
} catch (IOException ioe) {
|
||||
}
|
||||
FMusic.FMUSIC_StopSong(module);
|
||||
|
||||
System.out.println("Done playing. Cleaning up");
|
||||
FMusic.FMUSIC_FreeSong(module);
|
||||
} else {
|
||||
System.out.println("Unable to play: " + args[0]);
|
||||
System.out.println("Error: " + FMOD.FMOD_ErrorString(FSound.FSOUND_GetError()));
|
||||
}
|
||||
|
||||
FSound.FSOUND_Close();
|
||||
FMOD.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the file into a ByteBuffer
|
||||
*
|
||||
* @param filename
|
||||
* Name of file to load
|
||||
* @return ByteBuffer containing file data
|
||||
*/
|
||||
static protected ByteBuffer getData(String filename) {
|
||||
ByteBuffer buffer = null;
|
||||
|
||||
System.out.println("Attempting to load: " + filename);
|
||||
|
||||
try {
|
||||
BufferedInputStream bis = new BufferedInputStream(StreamPlayer.class.getClassLoader().getResourceAsStream(filename));
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
int bufferLength = 4096;
|
||||
byte[] readBuffer = new byte[bufferLength];
|
||||
int read = -1;
|
||||
|
||||
while ((read = bis.read(readBuffer, 0, bufferLength)) != -1) {
|
||||
baos.write(readBuffer, 0, read);
|
||||
}
|
||||
|
||||
//done reading, close
|
||||
bis.close();
|
||||
|
||||
// if ogg vorbis data, we need to pass it unmodified to alBufferData
|
||||
buffer = ByteBuffer.allocateDirect(baos.size());
|
||||
buffer.order(ByteOrder.nativeOrder());
|
||||
buffer.put(baos.toByteArray());
|
||||
buffer.flip();
|
||||
System.out.println("loaded " + buffer.remaining() + " bytes");
|
||||
} catch (Exception ioe) {
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,12 +31,8 @@
|
|||
*/
|
||||
package org.lwjgl.test.fmod3;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import org.lwjgl.fmod3.FMOD;
|
||||
import org.lwjgl.fmod3.FMODException;
|
||||
|
@ -50,45 +46,48 @@ import org.lwjgl.fmod3.FSoundStream;
|
|||
* @version $Revision$
|
||||
*/
|
||||
public class StreamPlayer {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length < 1) {
|
||||
System.out.println("Usage:\n StreamPlayer <file>");
|
||||
return;
|
||||
|
||||
// default to phero.mp3
|
||||
args = new String[] { "res\\phero.mp3"};
|
||||
System.out.println("Using default: " + args[0]);
|
||||
}
|
||||
|
||||
|
||||
File file = new File(args[0]);
|
||||
if (!file.exists()) {
|
||||
System.out.println("No such file: " + args[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
FMOD.create();
|
||||
} catch (FMODException fmode) {
|
||||
fmode.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
System.out.println("Initializing FMOD");
|
||||
if (!FSound.FSOUND_Init(44100, 32, 0)) {
|
||||
System.out.println("Failed to initialize FMOD");
|
||||
System.out.println("Error: " + FMOD.FMOD_ErrorString(FSound.FSOUND_GetError()));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
System.out.println("Loading " + args[0]);
|
||||
FSoundStream stream = FSound.FSOUND_Stream_Open(args[0], FSound.FSOUND_NORMAL, 0, 0);
|
||||
|
||||
|
||||
if (stream != null) {
|
||||
FSound.FSOUND_Stream_Play(0, stream);
|
||||
|
||||
|
||||
System.out.println("Press enter to stop playing");
|
||||
try {
|
||||
System.in.read();
|
||||
} catch (IOException ioe) {
|
||||
}
|
||||
|
||||
|
||||
System.out.println("Done playing. Cleaning up");
|
||||
FSound.FSOUND_Stream_Stop(stream);
|
||||
FSound.FSOUND_Stream_Close(stream);
|
||||
|
@ -96,47 +95,8 @@ public class StreamPlayer {
|
|||
System.out.println("Unable to play: " + args[0]);
|
||||
System.out.println("Error: " + FMOD.FMOD_ErrorString(FSound.FSOUND_GetError()));
|
||||
}
|
||||
|
||||
|
||||
FSound.FSOUND_Close();
|
||||
FMOD.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the file into a ByteBuffer
|
||||
*
|
||||
* @param filename
|
||||
* Name of file to load
|
||||
* @return ByteBuffer containing file data
|
||||
*/
|
||||
static protected ByteBuffer getData(String filename) {
|
||||
ByteBuffer buffer = null;
|
||||
|
||||
System.out.println("Attempting to load: " + filename);
|
||||
|
||||
try {
|
||||
BufferedInputStream bis = new BufferedInputStream(StreamPlayer.class.getClassLoader().getResourceAsStream(filename));
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
int bufferLength = 4096;
|
||||
byte[] readBuffer = new byte[bufferLength];
|
||||
int read = -1;
|
||||
|
||||
while ((read = bis.read(readBuffer, 0, bufferLength)) != -1) {
|
||||
baos.write(readBuffer, 0, read);
|
||||
}
|
||||
|
||||
//done reading, close
|
||||
bis.close();
|
||||
|
||||
// if ogg vorbis data, we need to pass it unmodified to alBufferData
|
||||
buffer = ByteBuffer.allocateDirect(baos.size());
|
||||
buffer.order(ByteOrder.nativeOrder());
|
||||
buffer.put(baos.toByteArray());
|
||||
buffer.flip();
|
||||
System.out.println("loaded " + buffer.remaining() + " bytes");
|
||||
} catch (Exception ioe) {
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
}
|
|
@ -48,57 +48,57 @@ import org.lwjgl.fmod3.FSoundStream;
|
|||
* @version $Revision$
|
||||
*/
|
||||
public class StreamPlayerMemory {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length < 1) {
|
||||
System.out.println("Usage:\n StreamPlayerMemory <file>");
|
||||
|
||||
// default to phero-eveningtest.mp3
|
||||
args = new String[] { "phero-eveningtest.mp3" };
|
||||
System.out.println("Using default: " + args[0]);
|
||||
}
|
||||
|
||||
|
||||
// default to phero.mp3
|
||||
args = new String[] { "phero2.ogg"};
|
||||
System.out.println("Using default: " + args[0]);
|
||||
}
|
||||
|
||||
try {
|
||||
FMOD.create();
|
||||
} catch (FMODException fmode) {
|
||||
fmode.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
System.out.println("Initializing FMOD");
|
||||
if (!FSound.FSOUND_Init(44100, 32, 0)) {
|
||||
System.out.println("Failed to initialize FMOD");
|
||||
System.out.println("Error: " + FMOD.FMOD_ErrorString(FSound.FSOUND_GetError()));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ByteBuffer data = getData(args[0]);
|
||||
FSoundStream stream = FSound.FSOUND_Stream_Open(data, FSound.FSOUND_LOADMEMORY, 0, data.capacity());
|
||||
|
||||
|
||||
if (stream != null) {
|
||||
FSound.FSOUND_Stream_Play(0, stream);
|
||||
|
||||
// busy wait until done
|
||||
int length = FSound.FSOUND_Stream_GetLengthMs(stream);
|
||||
String time = ((length / 1000) / 60) + "m " + ((length / 1000) % 60) + "s";
|
||||
System.out.println("Waiting " + time + ", for song to finish");
|
||||
|
||||
try {
|
||||
Thread.sleep(length);
|
||||
} catch (InterruptedException inte) {
|
||||
}
|
||||
|
||||
|
||||
// busy wait until done
|
||||
int length = FSound.FSOUND_Stream_GetLengthMs(stream);
|
||||
String time = ((length / 1000) / 60) + "m " + ((length / 1000) % 60) + "s";
|
||||
System.out.println("Waiting " + time + ", for song to finish");
|
||||
|
||||
try {
|
||||
Thread.sleep(length);
|
||||
} catch (InterruptedException inte) {
|
||||
}
|
||||
|
||||
FSound.FSOUND_Stream_Stop(stream);
|
||||
FSound.FSOUND_Stream_Close(stream);
|
||||
} else {
|
||||
System.out.println("Unable to play: " + args[0]);
|
||||
System.out.println("Error: " + FMOD.FMOD_ErrorString(FSound.FSOUND_GetError()));
|
||||
}
|
||||
|
||||
|
||||
FSound.FSOUND_Close();
|
||||
FMOD.destroy();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads the file into a ByteBuffer
|
||||
*
|
||||
|
@ -108,24 +108,25 @@ public class StreamPlayerMemory {
|
|||
*/
|
||||
static protected ByteBuffer getData(String filename) {
|
||||
ByteBuffer buffer = null;
|
||||
|
||||
|
||||
System.out.println("Attempting to load: " + filename);
|
||||
|
||||
|
||||
try {
|
||||
BufferedInputStream bis = new BufferedInputStream(StreamPlayerMemory.class.getClassLoader().getResourceAsStream(filename));
|
||||
BufferedInputStream bis = new BufferedInputStream(StreamPlayerMemory.class.getClassLoader()
|
||||
.getResourceAsStream(filename));
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
|
||||
int bufferLength = 4096;
|
||||
byte[] readBuffer = new byte[bufferLength];
|
||||
int read = -1;
|
||||
|
||||
|
||||
while ((read = bis.read(readBuffer, 0, bufferLength)) != -1) {
|
||||
baos.write(readBuffer, 0, read);
|
||||
}
|
||||
|
||||
|
||||
//done reading, close
|
||||
bis.close();
|
||||
|
||||
|
||||
// if ogg vorbis data, we need to pass it unmodified to alBufferData
|
||||
buffer = ByteBuffer.allocateDirect(baos.size());
|
||||
buffer.order(ByteOrder.nativeOrder());
|
||||
|
|
|
@ -45,41 +45,41 @@ import org.lwjgl.fmod3.FSound;
|
|||
* @version $Revision$
|
||||
*/
|
||||
public class StreamTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
FMOD.create();
|
||||
} catch (FMODException fmode) {
|
||||
fmode.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
IntBuffer caps = BufferUtils.createIntBuffer(1);
|
||||
FSound.FSOUND_SetOutput(FSound.FSOUND_OUTPUT_DSOUND);
|
||||
|
||||
int count = FSound.FSOUND_GetNumDrivers();
|
||||
System.out.println("Found: " + count + " drivers");
|
||||
for(int i=0;i<count; i++) {
|
||||
FSound.FSOUND_GetDriverCaps(i, caps);
|
||||
System.out.println(i + " (" + FSound.FSOUND_GetDriverName(i) + ") = " + caps.get(0));
|
||||
}
|
||||
|
||||
// init
|
||||
if (!FSound.FSOUND_Init(44100, 32, 0)) {
|
||||
System.out.println("Failed to initialize FMOD");
|
||||
System.out.println("Error: " + FMOD.FMOD_ErrorString(FSound.FSOUND_GetError()));
|
||||
return;
|
||||
}
|
||||
|
||||
IntBuffer mem = BufferUtils.createIntBuffer(2);
|
||||
FSound.FSOUND_GetMemoryStats(mem);
|
||||
System.out.println("Allocated: " + mem.get(0) + ", Max: " + mem.get(1));
|
||||
|
||||
IntBuffer hwChannels = BufferUtils.createIntBuffer(3);
|
||||
FSound.FSOUND_GetNumHWChannels(hwChannels);
|
||||
System.out.println("2d: " + hwChannels.get(0) + ", 3d: " + hwChannels.get(1) + ", total: " + hwChannels.get(2));
|
||||
|
||||
FSound.FSOUND_Close();
|
||||
FMOD.destroy();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
FMOD.create();
|
||||
} catch (FMODException fmode) {
|
||||
fmode.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
IntBuffer caps = BufferUtils.createIntBuffer(1);
|
||||
FSound.FSOUND_SetOutput(FSound.FSOUND_OUTPUT_DSOUND);
|
||||
|
||||
int count = FSound.FSOUND_GetNumDrivers();
|
||||
System.out.println("Found: " + count + " drivers");
|
||||
for (int i = 0; i < count; i++) {
|
||||
FSound.FSOUND_GetDriverCaps(i, caps);
|
||||
System.out.println(i + " (" + FSound.FSOUND_GetDriverName(i) + ") = " + caps.get(0));
|
||||
}
|
||||
|
||||
// init
|
||||
if (!FSound.FSOUND_Init(44100, 32, 0)) {
|
||||
System.out.println("Failed to initialize FMOD");
|
||||
System.out.println("Error: " + FMOD.FMOD_ErrorString(FSound.FSOUND_GetError()));
|
||||
return;
|
||||
}
|
||||
|
||||
IntBuffer mem = BufferUtils.createIntBuffer(2);
|
||||
FSound.FSOUND_GetMemoryStats(mem);
|
||||
System.out.println("Allocated: " + mem.get(0) + ", Max: " + mem.get(1));
|
||||
|
||||
IntBuffer hwChannels = BufferUtils.createIntBuffer(3);
|
||||
FSound.FSOUND_GetNumHWChannels(hwChannels);
|
||||
System.out.println("2d: " + hwChannels.get(0) + ", 3d: " + hwChannels.get(1) + ", total: " + hwChannels.get(2));
|
||||
|
||||
FSound.FSOUND_Close();
|
||||
FMOD.destroy();
|
||||
}
|
||||
}
|
|
@ -51,202 +51,211 @@ import org.lwjgl.fmod3.callbacks.FMusicCallback;
|
|||
* @version $Revision$
|
||||
*/
|
||||
public class SyncTest {
|
||||
|
||||
/** Path to file to play */
|
||||
private String filePath;
|
||||
|
||||
/** Module instance loaded */
|
||||
private FMusicModule module;
|
||||
|
||||
/** Whether test is running */
|
||||
private boolean running = true;
|
||||
|
||||
/** Current row */
|
||||
private int row;
|
||||
|
||||
/** Current order */
|
||||
private int order;
|
||||
|
||||
/** Number of orders in the song */
|
||||
private int numOrders;
|
||||
|
||||
|
||||
/** Path to file to play */
|
||||
private String filePath;
|
||||
|
||||
/** Module instance loaded */
|
||||
private FMusicModule module;
|
||||
|
||||
/** Whether test is running */
|
||||
private boolean running = true;
|
||||
|
||||
/** Current row */
|
||||
private int row;
|
||||
|
||||
/** Current order */
|
||||
private int order;
|
||||
|
||||
/** Number of orders in the song */
|
||||
private int numOrders;
|
||||
|
||||
/**
|
||||
* Creates a new SyncTest
|
||||
* @param string
|
||||
*/
|
||||
public SyncTest(String filePath) {
|
||||
this.filePath = filePath;
|
||||
|
||||
// create thread to exit when a key has been pressed
|
||||
Thread t = new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
System.in.read();
|
||||
} catch (IOException ioe) {
|
||||
}
|
||||
running = false;
|
||||
}
|
||||
};
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
this.filePath = filePath;
|
||||
|
||||
// create thread to exit when a key has been pressed
|
||||
Thread t = new Thread() {
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
System.in.read();
|
||||
} catch (IOException ioe) {
|
||||
}
|
||||
running = false;
|
||||
}
|
||||
};
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
// check for file existance
|
||||
File file = new File(args[0]);
|
||||
if (!file.exists()) {
|
||||
System.out.println("No such file: " + args[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
// initialize FMOD
|
||||
try {
|
||||
System.out.println("Initializing FMOD");
|
||||
|
||||
if (args.length < 1) {
|
||||
System.out.println("Usage:\n SyncTest <file>");
|
||||
|
||||
// default to Missing_you.mod
|
||||
args = new String[] { "res\\Missing_you.mod"};
|
||||
System.out.println("Using default: " + args[0]);
|
||||
}
|
||||
|
||||
// check for file existance
|
||||
File file = new File(args[0]);
|
||||
if (!file.exists()) {
|
||||
System.out.println("No such file: " + args[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
// initialize FMOD
|
||||
try {
|
||||
System.out.println("Initializing FMOD");
|
||||
FMOD.create();
|
||||
} catch (FMODException fmode) {
|
||||
fmode.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
// start actual test
|
||||
SyncTest sync = new SyncTest(args[0]);
|
||||
sync.executeTest();
|
||||
|
||||
// start actual test
|
||||
SyncTest sync = new SyncTest(args[0]);
|
||||
sync.executeTest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the test
|
||||
*/
|
||||
public void executeTest() {
|
||||
// do setup
|
||||
setup();
|
||||
|
||||
// if we have a module - get going
|
||||
if (module != null) {
|
||||
// high priority... - might otherwise skip
|
||||
Sys.setProcessPriority(Sys.HIGH_PRIORITY);
|
||||
|
||||
// go go go!
|
||||
run();
|
||||
}
|
||||
|
||||
// we're done - clean up
|
||||
destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup FMOD
|
||||
*/
|
||||
private void setup() {
|
||||
if (!FSound.FSOUND_Init(44100, 32, 0)) {
|
||||
System.out.println("Failed to initialize FMOD");
|
||||
System.out.println("Error: " + FMOD.FMOD_ErrorString(FSound.FSOUND_GetError()));
|
||||
return;
|
||||
}
|
||||
|
||||
// load module
|
||||
System.out.println("Loading " + filePath);
|
||||
module = FMusic.FMUSIC_LoadSong(filePath);
|
||||
|
||||
if (module == null) {
|
||||
System.out.println("Unable to load " + filePath + ": " + FMOD.FMOD_ErrorString(FSound.FSOUND_GetError()));
|
||||
return;
|
||||
}
|
||||
|
||||
// get number of orders
|
||||
numOrders = FMusic.FMUSIC_GetNumOrders(module);
|
||||
|
||||
// install order callback
|
||||
FMusic.FMUSIC_SetOrderCallback(module, new FMusicCallback() {
|
||||
public void FMUSIC_CALLBACK(FMusicModule module, int param) {
|
||||
order = param;
|
||||
}
|
||||
}, 1);
|
||||
|
||||
// install row callback
|
||||
// will be called once PER CHANNEL! - but since we only set the row
|
||||
// no harm is done :)
|
||||
FMusic.FMUSIC_SetRowCallback(module, new FMusicCallback() {
|
||||
public void FMUSIC_CALLBACK(FMusicModule module, int param) {
|
||||
row = param;
|
||||
}
|
||||
}, 1);
|
||||
|
||||
// try to add some userdata
|
||||
ByteBuffer buffer = BufferUtils.createByteBuffer(24);
|
||||
buffer.putInt(1).putInt(2).putInt(3).putInt(4).putInt(5).putInt(6).rewind();
|
||||
FMusic.FMUSIC_SetUserData(module, buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update status of module - spew it out in console
|
||||
*/
|
||||
private void update() {
|
||||
// mark as not running when finished
|
||||
if(FMusic.FMUSIC_IsFinished(module)) {
|
||||
running = false;
|
||||
}
|
||||
|
||||
int patternLength = FMusic.FMUSIC_GetPatternLength(module, order);
|
||||
int time = FMusic.FMUSIC_GetTime(module) / 1000;
|
||||
int time2 = FMusic.FMUSIC_GetTime(module) % 1000 / 10;
|
||||
double cpu = Math.round(FSound.FSOUND_GetCPUUsage() * 100.0) / 100.0;
|
||||
|
||||
System.out.println("O: " +
|
||||
((order < 10) ? "0" : "") + order + "/" + numOrders + " | R: "
|
||||
+ ((row < 10) ? "0" : "") + row + "/" + patternLength + " | T: "
|
||||
+ time + "."
|
||||
+ ((time2 < 10) ? "0" : "") + time2 + " | BPM: " + FMusic.FMUSIC_GetBPM(module) + " | Play: " + FMusic.FMUSIC_IsFinished(module)
|
||||
+ " | C: " + FSound.FSOUND_GetChannelsPlaying() + " | CPU: " + cpu);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the actual test - that is, play | update ad nausea
|
||||
*/
|
||||
private void run() {
|
||||
// play
|
||||
FMusic.FMUSIC_PlaySong(module);
|
||||
|
||||
// loop, printing update, if we actually changed row
|
||||
int lastRow = row;
|
||||
while(running) {
|
||||
if(lastRow != row) {
|
||||
lastRow = row;
|
||||
update();
|
||||
} else {
|
||||
pause(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Executes the test
|
||||
*/
|
||||
public void executeTest() {
|
||||
// do setup
|
||||
setup();
|
||||
|
||||
// if we have a module - get going
|
||||
if (module != null) {
|
||||
// high priority... - might otherwise skip
|
||||
Sys.setProcessPriority(Sys.HIGH_PRIORITY);
|
||||
|
||||
// go go go!
|
||||
run();
|
||||
}
|
||||
|
||||
// we're done - clean up
|
||||
destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup FMOD
|
||||
*/
|
||||
private void setup() {
|
||||
if (!FSound.FSOUND_Init(44100, 32, 0)) {
|
||||
System.out.println("Failed to initialize FMOD");
|
||||
System.out.println("Error: " + FMOD.FMOD_ErrorString(FSound.FSOUND_GetError()));
|
||||
return;
|
||||
}
|
||||
|
||||
// load module
|
||||
System.out.println("Loading " + filePath);
|
||||
module = FMusic.FMUSIC_LoadSong(filePath);
|
||||
|
||||
if (module == null) {
|
||||
System.out.println("Unable to load " + filePath + ": " + FMOD.FMOD_ErrorString(FSound.FSOUND_GetError()));
|
||||
return;
|
||||
}
|
||||
|
||||
// get number of orders
|
||||
numOrders = FMusic.FMUSIC_GetNumOrders(module);
|
||||
|
||||
// install order callback
|
||||
FMusic.FMUSIC_SetOrderCallback(module, new FMusicCallback() {
|
||||
|
||||
public void FMUSIC_CALLBACK(FMusicModule module, int param) {
|
||||
order = param;
|
||||
}
|
||||
}, 1);
|
||||
|
||||
// install row callback
|
||||
// will be called once PER CHANNEL! - but since we only set the row
|
||||
// no harm is done :)
|
||||
FMusic.FMUSIC_SetRowCallback(module, new FMusicCallback() {
|
||||
|
||||
public void FMUSIC_CALLBACK(FMusicModule module, int param) {
|
||||
row = param;
|
||||
}
|
||||
}, 1);
|
||||
|
||||
// try to add some userdata
|
||||
ByteBuffer buffer = BufferUtils.createByteBuffer(24);
|
||||
buffer.putInt(1).putInt(2).putInt(3).putInt(4).putInt(5).putInt(6).rewind();
|
||||
FMusic.FMUSIC_SetUserData(module, buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update status of module - spew it out in console
|
||||
*/
|
||||
private void update() {
|
||||
// mark as not running when finished
|
||||
if (FMusic.FMUSIC_IsFinished(module)) {
|
||||
running = false;
|
||||
}
|
||||
|
||||
int patternLength = FMusic.FMUSIC_GetPatternLength(module, order);
|
||||
int time = FMusic.FMUSIC_GetTime(module) / 1000;
|
||||
int time2 = FMusic.FMUSIC_GetTime(module) % 1000 / 10;
|
||||
double cpu = Math.round(FSound.FSOUND_GetCPUUsage() * 100.0) / 100.0;
|
||||
|
||||
System.out.println("O: " + ((order < 10) ? "0" : "") + order + "/" + numOrders + " | R: " + ((row < 10) ? "0" : "")
|
||||
+ row + "/" + patternLength + " | T: " + time + "." + ((time2 < 10) ? "0" : "") + time2 + " | BPM: "
|
||||
+ FMusic.FMUSIC_GetBPM(module) + " | Play: " + FMusic.FMUSIC_IsFinished(module) + " | C: "
|
||||
+ FSound.FSOUND_GetChannelsPlaying() + " | CPU: " + cpu);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the actual test - that is, play | update ad nausea
|
||||
*/
|
||||
private void run() {
|
||||
// play
|
||||
FMusic.FMUSIC_PlaySong(module);
|
||||
|
||||
// loop, printing update, if we actually changed row
|
||||
int lastRow = row;
|
||||
while (running) {
|
||||
if (lastRow != row) {
|
||||
lastRow = row;
|
||||
update();
|
||||
} else {
|
||||
pause(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param i
|
||||
*/
|
||||
private void pause(long i) {
|
||||
try {
|
||||
Thread.sleep(i);
|
||||
} catch (InterruptedException inte) {
|
||||
}
|
||||
try {
|
||||
Thread.sleep(i);
|
||||
} catch (InterruptedException inte) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// clean up our own mess
|
||||
private void destroy() {
|
||||
if(module != null) {
|
||||
// retrieve userdata
|
||||
ByteBuffer buffer = FMusic.FMUSIC_GetUserData(module, 24);
|
||||
|
||||
// should contain 1,2,3,4,5,6
|
||||
for(int i=0; i<6; i++) {
|
||||
System.out.println(buffer.getInt());
|
||||
}
|
||||
|
||||
FMusic.FMUSIC_FreeSong(module);
|
||||
}
|
||||
FSound.FSOUND_Close();
|
||||
FMOD.destroy();
|
||||
}
|
||||
private void destroy() {
|
||||
if (module != null) {
|
||||
// retrieve userdata
|
||||
ByteBuffer buffer = FMusic.FMUSIC_GetUserData(module, 24);
|
||||
|
||||
// should contain 1,2,3,4,5,6
|
||||
for (int i = 0; i < 6; i++) {
|
||||
System.out.println(buffer.getInt());
|
||||
}
|
||||
|
||||
FMusic.FMUSIC_FreeSong(module);
|
||||
}
|
||||
FSound.FSOUND_Close();
|
||||
FMOD.destroy();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue