{
InputStream is = new FileInputStream(inputFilename);
byte[] module = new byte[ASAP.MODULE_MAX];
int module_len = is.read(module);
is.close();
ASAP asap = new ASAP();
asap.load(inputFilename, module, module_len);
ASAP_ModuleInfo module_info = asap.getModuleInfo();
if (song < 0)
song = module_info.default_song;
if (duration < 0) {
duration = module_info.durations[song];
if (duration < 0)
duration = 180 * 1000;
}
asap.playSong(song, duration);
asap.mutePokeyChannels(muteMask);
if (outputFilename == null) {
int i = inputFilename.lastIndexOf('.');
outputFilename = inputFilename.substring(0, i + 1) + (outputHeader ? "wav" : "raw");
}
OutputStream os;
if (outputFilename.equals("-"))
os = System.out;
else
os = new FileOutputStream(outputFilename);
byte[] buffer = new byte[8192];
if (outputHeader) {
asap.getWavHeader(buffer, format);
os.write(buffer, 0, ASAP.WAV_HEADER_BYTES);
}
int n_bytes;
do {
n_bytes = asap.generate(buffer, format);
os.write(buffer, 0, n_bytes);
} while (n_bytes == buffer.length);
os.close();
outputFilename = null;
song = -1;