Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (525)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Bin2Wav creates a wav from raw data (eg CD)  (Read 1737 times)
0 Members and 1 Guest are viewing this topic.
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Posted 2004-02-03 13:51:48 »

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 (Roll Eyes) 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.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
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 ) {}
            }
      }
}

弾幕 ☆ @mahonnaiseblog
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (66 views)
2014-11-26 15:22:04

toopeicgaming1999 (58 views)
2014-11-26 15:20:36

toopeicgaming1999 (12 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (29 views)
2014-11-25 11:26:43

Gibbo3771 (24 views)
2014-11-24 19:59:16

trollwarrior1 (37 views)
2014-11-22 12:13:56

xFryIx (76 views)
2014-11-13 12:34:49

digdugdiggy (53 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!