mirror of
https://github.com/shadowfacts/lwjgl2-arm64.git
synced 2026-04-06 23:14:19 +00:00
format/reindent
using phero resources defaults to a file now
This commit is contained in:
parent
851e5f2c08
commit
571a2fe348
6 changed files with 408 additions and 485 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue