Apparently this isn’t game related. However, I thought that maybe one or two people here might be interested in such a piece of code or let’s say in this kind of programm.
It takes RAW data (e.g. from IsoBusters context menu “Extract RAW Data (2352 bytes/block”) as input, creates a WAV header (it’s hardcoded except that “Length Of Data To Follow” in the DATA Chunk wich is just the filelength of the bin file) and then the RAW data is copied to the end.
“Why don’t you just rip it as wav?”, I hear you ask… well, sometimes that doesn’t work, because the TOC has wrong entries (::)) and the “audio” tracks get recognised as “data” tracks.
In that case you just need to take that data and put it into a wav file… with a hex editor of your choice or with this programm.
Disclaimer: This piece of source is provided “AS IS”. I’m not responsible for any damage. Use at your own risk. Compile and run it only if you understand what it does. It doesn’t bypass any copy protection schemes - the only thing it does is creating wav files out of raw data.
import java.io.*;
public class Bin2Wav
{
static int []head=
{
//RIFF Chunk (12 bytes in length total)
0x52, //"RIFF" (ASCII Characters)
0x49,
0x46,
0x46,
0xD4, //Total Length Of Package To Follow (Binary, little endian)
0x2D,
0x11,
0x02,
0x57, //"WAVE" (ASCII Characters)
0x41,
0x56,
0x45,
//FORMAT Chunk (24 bytes in length total)
0x66, //"fmt_" (ASCII Characters)
0x6D,
0x74,
0x20,
0x10, //Length Of FORMAT Chunk (Binary, always 0x10)
0x00,
0x00,
0x00,
0x01, //Always 0x01
0x00,
0x02, //Channel Numbers (Always 0x01=Mono, 0x02=Stereo)
0x00,
0x44, //Sample Rate (Binary, in Hz)
0xAC,
0x00,
0x00,
0x10, //Bytes Per Second
0xB1,
0x02,
0x00,
0x04, //Bytes Per Sample: 1=8 bit Mono, 2=8 bit Stereo or 16 bit Mono, 4=16 bit Stereo
0x00,
0x10, //Bits Per Sample
0x00,
//DATA Chunk
0x64, //"data" (ASCII Characters)
0x61,
0x74,
0x61
};
public static void main(String[] args) throws IOException
{
try
{
if (args.length == 0)
throw new IllegalArgumentException("Wrong number of arguments");
File inFile=new File(args[0]);
File outFile;
if(args.length==1)
outFile=new File(args[0]+".wav");
else
outFile=new File(args[1]);
long len=inFile.length();
FileInputStream inStream=new FileInputStream(inFile);
DataOutputStream outStream=new DataOutputStream(new FileOutputStream(outFile));
System.out.println(inFile.getAbsolutePath() + " has " + len + " bytes.\n");
System.out.println("writing header");
for(int i=0;i<head.length;i++)
{
outStream.writeByte(head[i]);
}
outStream.writeInt(endian((int)len));
outStream.flush();
System.out.println("copying data (samples)");
copy(inStream, outStream);
System.out.println("\nk. done.");
}
catch (Exception e)
{
System.err.println(e);
System.err.println("Usage: java Bin2Wav infile.bin [outfile.wav]");
}
}
public static int endian( int x )
{
int a = x >>> 24 ;
int b = ( x >>> 16 ) & 0xff ;
int c = ( x >>> 8 ) & 0xff ;
int d = x & 0xff ;
x = ( d << 24 ) | ( c << 16 ) | ( b << 8 ) | a ;
return x ;
}
static void copy( InputStream fis, OutputStream fos )
{
try
{
byte buffer[] = new byte[0xffff];
int nbytes;
while ( (nbytes = fis.read(buffer)) != -1 )
fos.write( buffer, 0, nbytes );
}
catch( IOException e )
{
System.err.println( e );
}
finally
{
if ( fis != null )
try
{
fis.close();
}
catch ( IOException e ) {}
try
{
if ( fos != null )
fos.close();
}
catch ( IOException e ) {}
}
}
}