Initial revision
[old-projects.git] / ekit / com / hexidec / util / CMUScodec.java
diff --git a/ekit/com/hexidec/util/CMUScodec.java b/ekit/com/hexidec/util/CMUScodec.java
new file mode 100644 (file)
index 0000000..da300fd
--- /dev/null
@@ -0,0 +1 @@
+/*\rGNU General Public License\r\rCMUScodec\rCopyright (C) 2002  Howard A Kistler\r\rThis program is free software; you can redistribute it and/or\rmodify it under the terms of the GNU General Public License\ras published by the Free Software Foundation; either version 2\rof the License, or (at your option) any later version.\r\rThis program is distributed in the hope that it will be useful,\rbut WITHOUT ANY WARRANTY; without even the implied warranty of\rMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\rGNU General Public License for more details.\r\rYou should have received a copy of the GNU General Public License\ralong with this program; if not, write to the Free Software\rFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r*/\r\rpackage com.hexidec.util;\r\rimport java.awt.AWTException;\rimport java.io.File;\rimport java.io.FileInputStream;\rimport java.io.FileNotFoundException;\rimport java.io.FileOutputStream;\rimport java.io.FileWriter;\rimport java.io.IOException;\r\r/** CMUScodec\r  *\r  * Utility for reading (and eventually converting) Deluxe Music\r  * Construction Set (DMCS) files\r  *\r  * @author Howard Kistler\r  * @version 0.1\r  *\r  * VERSION HISTORY\r  * 0.1 (03/13/2002) - initial creation (03/13/2002)\r  */\r\rpublic class CMUScodec\r{\r\r//  Constants ---------------------------------------------------------------------------->\r\r/*\r       CMUS File Structure\r\r   FILE HEADER\r    ====================\r   (At the beginning of each file)\r\r       IFF Form Chunk\r         4 bytes - FORM\r         4 bytes - ?\r            4 bytes - CMUS\r\r        Score Header Chunk\r             4 bytes - SCHD\r         10 bytes - 00 00 00 1A 00 02 00 00 00 02\r               2 bytes - (significant number[s]?)\r             2 bytes - 00 04 (# of channels maybe?)\r         2 bytes - Ch\r           12 bytes - 00 00 00 00 00 00 0C E6 00 00 0C E6\r         2 bytes - (2 byte significant number, or 00 and 1 byte significant?)\r\r  DSCR HEADER BLOCK\r              4 bytes - DSCR\r         14 bytes - ?\r\r  Staff Table Chunk\r              4 bytes - STAF\r         X bytes - ? (1 entry per staff in score)\r\r      DSTF HEADER BLOCK\r              4 bytes - DSTF\r         X bytes - ?\r\r   LFON HEADER BLOCK\r              4 bytes - LFON\r         4 bytes - 00 00 00 0F\r          4 bytes - 00 00 00 08\r          X bytes - Font Name\r            2 bytes - 00 00\r\r       SONG BODY\r      ====================\r\r  TRCK BLOCKS\r            4 bytes - TRCK\r         X bytes - track data\r\r  INSTRUMENT BLOCK\r       ====================\r\r  Each Instrument Contains:\r              4 bytes - FORM\r         4 bytes - (number?)\r            8 bytes - INSTINHD\r             4 bytes - 00 00 00 0A\r          1 byte  - Instrument Number\r            1 byte  - (zero pad?)\r          8 bytes - 00 00 FF FF 40 00 00 00\r              4 bytes - NAME\r         4 bytes - Name Byte Count\r              Y bytes - Name Bytes (Y = value from above)\r            1 byte  - (zero pad?)\r          [Optional Instrument Path]\r                     4 bytes - SFIL\r                 4 bytes - Path Byte Count\r                      Y bytes - Path Bytes (Y = value from above)\r            1 byte  - (zero pad)\r\r*/\r\r      // Decoder Vars\r        private static byte[] bData;\r   private static int iPlace;\r\r//  Public Vartypes ---------------------------------------------------------------------->\r\r       public final static int FILETYPE_DMCS   = 0;\r   public final static int FILETYPE_CMUS   = 1;\r   public final static int FILETYPE_SMUS   = 2;\r   public final static int FILETYPE_TEXT   = 3;\r   public final static int FILETYPE_FINALE = 4;\r\r  private final static byte NUL = (byte)0;\r\r//  Constructor -------------------------------------------------------------------------->\r\r public CMUScodec()\r     {\r      }\r\r//  Decode Method ------------------------------------------------------------------------>\r\r        public static void decode(String sourceFile, String destFile)\r  throws FileNotFoundException, IOException, AWTException\r        {\r              convertToTextFile(sourceFile, destFile);\r       }\r\r//  Encode Method ------------------------------------------------------------------------>\r\r        public static void encode(String sourceFile, String destFile, int fileType)\r    throws FileNotFoundException, IOException, AWTException\r        {\r//            String newFormat = convertToFormat(sourceFile, fileType);\r//            writeToDMCSFile(newFormat, destFile);\r  }\r\r//  CMUS-to-TEXT File Conversion -------------------------------------------------------->\r\r protected static void convertToTextFile(String inFile, String outFile)\r throws IOException\r     {\r              File srcFile = new File(inFile);\r               FileInputStream fis = new FileInputStream(srcFile);\r            int filesize = (int)(srcFile.length());\r                bData = new byte[filesize];\r            iPlace = 0;\r            int iCounter = 0;\r              while(iCounter < filesize)\r             {\r                      bData[iCounter] = (byte)(fis.read());\r                  iCounter++;\r            }\r              fis.close();\r\r          FileWriter fw = new FileWriter(new File(outFile));\r\r            String sOutput = "FILE SIZE  : " + srcFile.length() + "\r";\r            fw.write(sOutput, 0, sOutput.length());\r\r               sOutput = "BYTES READ : " + iCounter + "\r";\r           fw.write(sOutput, 0, sOutput.length());\r\r               sOutput = "====================\rFILE CONTENTS\r====================\r";\r               fw.write(sOutput, 0, sOutput.length());\r\r               while(iPlace < iCounter)\r               {\r                      String chunk = "" + (char)(bData[iPlace++]) + (char)(bData[iPlace++]) + (char)(bData[iPlace++]) + (char)(bData[iPlace++]);\r                     if     (chunk.equals("FORM")) { parseFORM(fw); }\r                       else if(chunk.equals("SCHD")) { parseSCHD(fw); }\r                       else if(chunk.equals("DSCR")) { parseDSCR(fw); }\r                       else if(chunk.equals("STAF")) { parseSTAF(fw); }\r                       else if(chunk.equals("DSTF")) { parseDSTF(fw); }\r                       else if(chunk.equals("LFON")) { parseLFON(fw); }\r                       else if(chunk.equals("TRCK")) { parseTRCK(fw); }\r                       else if(chunk.equals("INHD")) { parseINHD(fw); }\r                       else if(chunk.equals("NAME")) { parseNAME(fw); }\r                       else if(chunk.equals("SFIL")) { parseSFIL(fw); }\r                       else\r                   { \r                             sOutput = "UNKNOWN CHUNK : " + chunk + "\r";\r                           fw.write(sOutput, 0, sOutput.length());\r                                iPlace = iCounter;\r                             break;\r                 }\r              }\r/*\r           4 bytes - FORM\r         4 bytes - (number?)\r            4 bytes - INST\r         4 bytes - type : INHD, SFIL, SHAR or others\r            4 bytes - 00 00 00 0A\r          1 byte  - Instrument Number\r            1 byte  - (zero pad?)\r          8 bytes - 00 00 FF FF 40 00 00 00\r              4 bytes - NAME\r         4 bytes - Name Byte Count\r              Y bytes - Name Bytes (Y = value from above)\r            1 byte  - (zero pad?)\r          [Optional Instrument Path]\r                     4 bytes - SFIL\r                 4 bytes - Path Byte Count\r                      Y bytes - Path Bytes (Y = value from above)\r            1 byte  - (zero pad)\r*/\r\r               fw.flush();\r            fw.close();\r    }\r\r//  Chunk Parsing Methods---------------------------------------------------------------->\r\r private static void parseFORM(FileWriter fw)\r   throws IOException\r     {\r              String sOutput = "--------------------\rFORM CHUNK\r--------------------\r";\r           fw.write(sOutput, 0, sOutput.length());\r\r               sOutput = "FORM BLOCK : FORM\r";\r               fw.write(sOutput, 0, sOutput.length());\r\r               int iSize =\r                    (int)(\r                         ((bData[iPlace++]) << 24) +\r                            ((bData[iPlace++]) << 16) +\r                            ((bData[iPlace++]) <<  8) +\r                            ((bData[iPlace++])      )\r                              );\r             sOutput = "SIZE BLOCK : " + iSize + "\r";\r              fw.write(sOutput, 0, sOutput.length());\r\r               sOutput = "TYPE BLOCK : " + (char)(bData[iPlace++]) + (char)(bData[iPlace++]) + (char)(bData[iPlace++]) + (char)(bData[iPlace++]) + "\r";\r              fw.write(sOutput, 0, sOutput.length());\r        }\r\r     private static void parseSCHD(FileWriter fw)\r   throws IOException\r     {\r              String sOutput = "--------------------\rSCORE HEADER CHUNK\r--------------------\r";\r           fw.write(sOutput, 0, sOutput.length());\r\r               sOutput = "SCHD BLOCK : SCHD\r";\r               fw.write(sOutput, 0, sOutput.length());\r\r               int iData =\r                    (int)(\r                         ((bData[iPlace++]) <<  8) +\r                            ((bData[iPlace++])      )\r                              );\r             sOutput = "WORD BLOCK 1 : " + iData + "\r";\r            fw.write(sOutput, 0, sOutput.length());\r\r               iData =\r                        (int)(\r                         ((bData[iPlace++]) <<  8) +\r                            ((bData[iPlace++])      )\r                              );\r             sOutput = "WORD BLOCK 2 : " + iData + "\r";\r            fw.write(sOutput, 0, sOutput.length());\r\r               iData =\r                        (int)(\r                         ((bData[iPlace++]) <<  8) +\r                            ((bData[iPlace++])      )\r                              );\r             sOutput = "WORD BLOCK 3 : " + iData + "\r";\r            fw.write(sOutput, 0, sOutput.length());\r\r               iData =\r                        (int)(\r                         ((bData[iPlace++]) <<  8) +\r                            ((bData[iPlace++])      )\r                              );\r             sOutput = "WORD BLOCK 4 : " + iData + "\r";\r            fw.write(sOutput, 0, sOutput.length());\r\r               iData =\r                        (int)(\r                         ((bData[iPlace++]) <<  8) +\r                            ((bData[iPlace++])      )\r                              );\r             sOutput = "WORD BLOCK 5 : " + iData + "\r";\r            fw.write(sOutput, 0, sOutput.length());\r\r               sOutput = "BYTE 6a: " + bData[iPlace++] + "\r";\r                fw.write(sOutput, 0, sOutput.length());\r                sOutput = "BYTE 6b: " + bData[iPlace++] + "\r";\r                fw.write(sOutput, 0, sOutput.length());\r\r               iData =\r                        (int)(\r                         ((bData[iPlace++]) <<  8) +\r                            ((bData[iPlace++])      )\r                              );\r             sOutput = "WORD BLOCK 7+: " + iData + "\r";\r            fw.write(sOutput, 0, sOutput.length());\r\r               sOutput = "Ch BLOCK : " + (char)(bData[iPlace++]) + (char)(bData[iPlace++]) + "\r";\r            fw.write(sOutput, 0, sOutput.length());\r\r               for(int i = 0; i < 6; i++)\r             {\r                      iData =\r                                (int)(\r                                 ((bData[iPlace++]) <<  8) +\r                                    ((bData[iPlace++])      )\r                                      );\r                     sOutput = "SUB WORD " + (i + 1) + ": " + iData + "\r";\r                 fw.write(sOutput, 0, sOutput.length());\r                }\r\r             iData =\r                        (int)(\r                         ((bData[iPlace++]) <<  8) +\r                            ((bData[iPlace++])      )\r                              );\r             sOutput = "SUB WORD 7 : " + iData + "\r";\r              fw.write(sOutput, 0, sOutput.length());\r        }\r\r     private static void parseDSCR(FileWriter fw)\r   throws IOException\r     {\r              String sOutput = "--------------------\rDSCR CHUNK\r--------------------\r";\r           fw.write(sOutput, 0, sOutput.length());\r\r               sOutput = "DSCR BLOCK : DSCR\r";\r               fw.write(sOutput, 0, sOutput.length());\r\r               for(int i = 0; i < 7; i++)\r             {\r                      int iData =\r                            (int)(\r                                 ((bData[iPlace++]) <<  8) +\r                                    ((bData[iPlace++])      )\r                                      );\r                     sOutput = "DSCR WORD " + i + ": " + iData + "\r";\r                      fw.write(sOutput, 0, sOutput.length());\r                }\r      }\r\r     private static void parseSTAF(FileWriter fw)\r   throws IOException\r     {\r              String sOutput = "--------------------\rSTAFF TABLE CHUNK\r--------------------\r";\r            fw.write(sOutput, 0, sOutput.length());\r\r               sOutput = "STAF BLOCK : STAF\r";\r               fw.write(sOutput, 0, sOutput.length());\r\r               int iStaffLeadByte =\r                   (int)(\r                         (bData[iPlace++] <<  8) +\r                              (bData[iPlace++]      )\r                                );\r             sOutput = "STAF Lead Byte : " + iStaffLeadByte + "\r";\r         fw.write(sOutput, 0, sOutput.length());\r\r               int iStaffByteCount =\r                  (int)(\r                         (bData[iPlace++] <<  8) +\r                              (bData[iPlace++]      )\r                                );\r             sOutput = "STAF Byte Count : " + iStaffByteCount + "\r";\r               fw.write(sOutput, 0, sOutput.length());\r\r               for(int i = 0; i < iStaffByteCount; i++)\r               {\r                      sOutput = "STAF Byte " + (i+1) + " : " + bData[iPlace++] + "\r";\r                       fw.write(sOutput, 0, sOutput.length());\r                }\r      }\r\r     private static void parseDSTF(FileWriter fw)\r   throws IOException\r     {\r              String sOutput = "--------------------\rDSTF CHUNK\r--------------------\r";\r           fw.write(sOutput, 0, sOutput.length());\r\r               sOutput = "DSTF BLOCK : DSTF\r";\r               fw.write(sOutput, 0, sOutput.length());\r\r               int iDstaffLeadByte =\r                  (int)(\r                         (bData[iPlace++] <<  8) +\r                              (bData[iPlace++]      )\r                                );\r             sOutput = "DSTF Lead Byte : " + iDstaffLeadByte + "\r";\r                fw.write(sOutput, 0, sOutput.length());\r\r               int iDstaffByteCount =\r                 (int)(\r                         (bData[iPlace++] <<  8) +\r                              (bData[iPlace++]      )\r                                );\r             sOutput = "DSTF Byte Count : " + iDstaffByteCount + "\r";\r              fw.write(sOutput, 0, sOutput.length());\r\r               for(int i = 0; i < iDstaffByteCount; i++)\r              {\r                      sOutput = "DSTF Byte " + (i+1) + " : " + bData[iPlace++] + "\r";\r                       fw.write(sOutput, 0, sOutput.length());\r                }\r      }\r\r     private static void parseLFON(FileWriter fw)\r   throws IOException\r     {\r              String sOutput = "--------------------\rLYRIC FONT CHUNK\r--------------------\r";\r             fw.write(sOutput, 0, sOutput.length());\r\r               sOutput = "LFON BLOCK : LFON\r";\r               fw.write(sOutput, 0, sOutput.length());\r\r               int iFontNumber =\r                      (int)(\r                         ((bData[iPlace++]) << 24) +\r                            ((bData[iPlace++]) << 16) +\r                            ((bData[iPlace++]) <<  8) +\r                            ((bData[iPlace++])      )\r                              );\r             sOutput = "FONT NUMBER : " + iFontNumber + "\r";\r               fw.write(sOutput, 0, sOutput.length());\r\r               int iFontHeight =\r                      (int)(\r                         ((bData[iPlace++]) << 24) +\r                            ((bData[iPlace++]) << 16) +\r                            ((bData[iPlace++]) <<  8) +\r                            ((bData[iPlace++])      )\r                              );\r             sOutput = "FONT HEIGHT : " + iFontHeight + "\r";\r               fw.write(sOutput, 0, sOutput.length());\r\r               sOutput = "Font Name : ";\r              while(bData[iPlace++] != NUL)\r          {\r                      sOutput = sOutput + (char)(bData[iPlace-1]);\r           }\r              sOutput = sOutput + "\r";\r              fw.write(sOutput, 0, sOutput.length());\r\r               sOutput = "[TERMNUL] : " + bData[iPlace++] + "\r";\r             fw.write(sOutput, 0, sOutput.length());\r        }\r\r     private static void parseTRCK(FileWriter fw)\r   throws IOException\r     {\r              String sOutput = "--------------------\rTRACK CHUNK\r--------------------\r";\r          fw.write(sOutput, 0, sOutput.length());\r\r               sOutput = "TRCK BLOCK : TRCK\r";\r               fw.write(sOutput, 0, sOutput.length());\r\r               int iTrackLeadByte =\r                   (int)(\r                         (bData[iPlace++] <<  8) +\r                              (bData[iPlace++]      )\r                                );\r             sOutput = "TRCK Lead Byte : " + iTrackLeadByte + "\r";\r         fw.write(sOutput, 0, sOutput.length());\r\r               int iTrackByteCount =\r                  (int)(\r                         (bData[iPlace++] <<  8) +\r                              (bData[iPlace++]      )\r                                );\r             sOutput = "TRCK Byte Count : " + iTrackByteCount + "\r";\r               fw.write(sOutput, 0, sOutput.length());\r\r               int iTrackStaff =\r                      (int)(\r                         (bData[iPlace++] <<  8) +\r                              (bData[iPlace++]      )\r                                );\r             sOutput = "TRCK Staff : " + iTrackStaff + "\r";\r                fw.write(sOutput, 0, sOutput.length());\r\r               int iTrackTrack =\r                      (int)(\r                         (bData[iPlace++] <<  8) +\r                              (bData[iPlace++]      )\r                                );\r             sOutput = "TRCK Track : " + iTrackTrack + "\r";\r                fw.write(sOutput, 0, sOutput.length());\r\r               int iTrackFlags =\r                      (int)(\r                         (bData[iPlace++] <<  8) +\r                              (bData[iPlace++]      )\r                                );\r             sOutput = "TRCK Flags : " + iTrackFlags + "\r";\r                fw.write(sOutput, 0, sOutput.length());\r\r               int iTrackTransposition =\r                      (int)(\r                         (bData[iPlace++] <<  8) +\r                              (bData[iPlace++]      )\r                                );\r             sOutput = "TRCK Trans : " + iTrackTransposition + "\r";\r                fw.write(sOutput, 0, sOutput.length());\r\r               for(int i = 0; i < iTrackByteCount - 8;)\r               {\r                      int iItemLength = (int)(bData[iPlace++]);\r                      sOutput = "ITEM LEN  : " + iItemLength + "\r";\r                 fw.write(sOutput, 0, sOutput.length());\r                        i++;\r\r                  sOutput = "ITEM TYPE : " + bData[iPlace++] + "\r";\r                     fw.write(sOutput, 0, sOutput.length());\r                        i++;\r\r                  int iItemXPos =\r                                (int)(\r                                 (bData[iPlace++] <<  8) +\r                                      (bData[iPlace++]      )\r                                        );\r                     sOutput = "ITEM XPOS : " + iItemXPos + "\r";\r                   fw.write(sOutput, 0, sOutput.length());\r                        i++;i++;\r\r                      int iItemStart =\r                               (int)(\r                                 (bData[iPlace++] <<  8) +\r                                      (bData[iPlace++]      )\r                                        );\r                     sOutput = "ITEM START: " + iItemStart + "\r";\r                  fw.write(sOutput, 0, sOutput.length());\r                        i++;i++;\r\r                      for(int j = 0; j < iItemLength - 3; j++)\r                       {\r                              int iItemData =\r                                        (int)(\r                                         (bData[iPlace++] <<  8) +\r                                              (bData[iPlace++]      )\r                                                );\r                             sOutput = "ITEM WORD " + j + " : " + iItemData + "\r";\r                         fw.write(sOutput, 0, sOutput.length());\r                                i++;i++;\r                       }\r              }\r      }\r\r     private static void parseINHD(FileWriter fw)\r   throws IOException\r     {\r              String sOutput = "--------------------\rINSTRUMENT HEADER CHUNK\r--------------------\r";\r              fw.write(sOutput, 0, sOutput.length());\r\r               sOutput = "INHD BLOCK : INHD\r";\r               fw.write(sOutput, 0, sOutput.length());\r\r               int iPadding =\r                 (int)(\r                         (bData[iPlace++] <<  8) +\r                              (bData[iPlace++]      )\r                                );\r             sOutput = "(HEADPAD)  : " + iPadding + "\r";\r           fw.write(sOutput, 0, sOutput.length());\r                byte instrumentNumber = bData[iPlace++];\r               sOutput = "INST #     : " + instrumentNumber + "\r";\r           fw.write(sOutput, 0, sOutput.length());\r                byte instrumentFlags  = bData[iPlace++];\r               sOutput = "INST FLAGS : " + instrumentFlags + "\r";\r            fw.write(sOutput, 0, sOutput.length());\r                int  instrumentTune   =\r                        (int)(\r                         (bData[iPlace++] <<  8) +\r                              (bData[iPlace++]      )\r                                );\r             sOutput = "INST TUNE  : " + instrumentTune + "\r";\r             fw.write(sOutput, 0, sOutput.length());\r                int  instrumentVolume =\r                        (int)(\r                         (bData[iPlace++] <<  8) +\r                              (bData[iPlace++]      )\r                                );\r             sOutput = "INST VOL   : " + instrumentVolume + "\r";\r           fw.write(sOutput, 0, sOutput.length());\r                byte instrumentPan = bData[iPlace++];\r          sOutput = "INST PAN   : " + instrumentNumber + "\r";\r           fw.write(sOutput, 0, sOutput.length());\r                byte instrumentMIDIChannel = bData[iPlace++];\r          sOutput = "MIDI CHAN   : " + instrumentNumber + "\r";\r          fw.write(sOutput, 0, sOutput.length());\r                byte instrumentMIDIPreset = bData[iPlace++];\r           sOutput = "MIDI PRESET : " + instrumentNumber + "\r";\r          fw.write(sOutput, 0, sOutput.length());\r                byte instrumentMIDIPort = bData[iPlace++];\r             sOutput = "MIDI PORT   : " + instrumentNumber + "\r";\r          fw.write(sOutput, 0, sOutput.length());\r                iPadding =\r                     (int)(\r                         (bData[iPlace++] <<  8) +\r                              (bData[iPlace++]      )\r                                );\r             sOutput = "(TAILPAD)  : " + iPadding + "\r";\r           fw.write(sOutput, 0, sOutput.length());\r        }\r\r     private static void parseNAME(FileWriter fw)\r   throws IOException\r     {\r              String sOutput = "--------------------\rINSTRUMENT NAME CHUNK\r--------------------\r";\r                fw.write(sOutput, 0, sOutput.length());\r\r               sOutput = "NAME BLOCK : NAME\r";\r               fw.write(sOutput, 0, sOutput.length());\r\r               int iNameHeadInt =\r                     (int)(\r                         (bData[iPlace++] <<  8) +\r                              (bData[iPlace++]      )\r                                );\r             sOutput = "NAME HEAD  : " + iNameHeadInt + "\r";\r               fw.write(sOutput, 0, sOutput.length());\r\r               int iNameByteCount =\r                   (int)(\r                         (bData[iPlace++] <<  8) +\r                              (bData[iPlace++]      )\r                                );\r             sOutput = "NAME BYTES : " + iNameByteCount + "\r";\r             fw.write(sOutput, 0, sOutput.length());\r\r               sOutput = "Instrument Name : ";\r                for(int i = 1; i < iNameByteCount; i++)\r                {\r                      sOutput = sOutput + (char)(bData[iPlace++]);\r           }\r              sOutput = sOutput + "\r";\r              fw.write(sOutput, 0, sOutput.length());\r\r               sOutput = "(PADNUL1)  : " + bData[iPlace++] + "\r";\r            fw.write(sOutput, 0, sOutput.length());\r\r               if((int)(iNameByteCount / 2.0) < (iNameByteCount / 2.0))\r               {\r                      sOutput = "(PADNUL2)  : " + bData[iPlace++] + "\r";\r                    fw.write(sOutput, 0, sOutput.length());\r                }\r      }\r\r     private static void parseSFIL(FileWriter fw)\r   throws IOException\r     {\r              String sOutput = "--------------------\rINSTRUMENT SAMPLE FILE CHUNK\r--------------------\r";\r         fw.write(sOutput, 0, sOutput.length());\r\r               sOutput = "SFIL BLOCK : SFIL\r";\r               fw.write(sOutput, 0, sOutput.length());\r\r               int iSampleFileBytes =\r                 (int)(\r                         ((bData[iPlace++]) << 24) +\r                            ((bData[iPlace++]) << 16) +\r                            ((bData[iPlace++]) <<  8) +\r                            ((bData[iPlace++])      )\r                              );\r             sOutput = "SFIL BYTES : " + iSampleFileBytes + "\r";\r           fw.write(sOutput, 0, sOutput.length());\r\r               sOutput = "Sample File Name : ";\r               for(int i = 1; i < iSampleFileBytes; i++)\r              {\r                      sOutput = sOutput + (char)(bData[iPlace++]);\r           }\r              sOutput = sOutput + "\r";\r              fw.write(sOutput, 0, sOutput.length());\r\r               sOutput = "(PADNUL)   : " + bData[iPlace++] + "\r";\r            fw.write(sOutput, 0, sOutput.length());\r        }\r\r//  File Write Method ------------------------------------------------------------------->\r\r protected static void writeToDMCSFile(String fileData, String outFile)\r throws IOException\r     {\r/*\r           FileOutputStream fos = new FileOutputStream(new File(outFile));\r\r               byte FileSizeByte1 = (byte)(fileData.length()         & 0xFF);\r         byte FileSizeByte2 = (byte)((fileData.length() >> 8)  & 0xFF);\r         byte FileSizeByte3 = (byte)((fileData.length() >> 16) & 0xFF);\r         byte FileSizeByte4 = (byte)((fileData.length() >> 24) & 0xFF);\r\r                byte[] DMCSFileHeader = new byte[]\r             {\r                      FileHeaderFormWord[0], FileHeaderFormWord[1], FileHeaderFormWord[2], FileHeaderFormWord[3],\r                    FileSizeByte1,         FileSizeByte2,         FileSizeByte3,         FileSizeByte4,\r                    FileHeaderTypeWord[0], FileHeaderTypeWord[1], FileHeaderTypeWord[2], FileHeaderTypeWord[3],\r                    FileHeaderOSAMWord[0], FileHeaderOSAMWord[1], FileHeaderOSAMWord[2], FileHeaderOSAMWord[3],\r                    FileHeaderTailWord[0], FileHeaderTailWord[1], FileHeaderTailWord[2], FileHeaderTailWord[3]\r             };\r             fos.write(DMCSFileHeader);\r\r            byte BitmapWidthByte1      = (byte)(IntBitmapWidth          & 0xFF);\r           byte BitmapWidthByte2      = (byte)((IntBitmapWidth >> 8)   & 0xFF);\r           byte BitmapWidthByte3      = (byte)((IntBitmapWidth >> 16)  & 0xFF);\r           byte BitmapWidthByte4      = (byte)((IntBitmapWidth >> 24)  & 0xFF);\r           byte BitmapHeightByte1     = (byte)(IntBitmapHeight         & 0xFF);\r           byte BitmapHeightByte2     = (byte)((IntBitmapHeight >> 8)  & 0xFF);\r           byte BitmapHeightByte3     = (byte)((IntBitmapHeight >> 16) & 0xFF);\r           byte BitmapHeightByte4     = (byte)((IntBitmapHeight >> 24) & 0xFF);\r           byte BitmapImageSizeByte1  = (byte)(IntBitmapSize           & 0xFF);\r           byte BitmapImageSizeByte2  = (byte)((IntBitmapSize >> 8)    & 0xFF);\r           byte BitmapImageSizeByte3  = (byte)((IntBitmapSize >> 16)   & 0xFF);\r           byte BitmapImageSizeByte4  = (byte)((IntBitmapSize >> 24)   & 0xFF);\r\r          byte[] BitmapBodyHeader = new byte[] {\r                 InfoHeaderSizeByte1,        InfoHeaderSizeByte2,        InfoHeaderSizeByte3,        InfoHeaderSizeByte4,\r                       BitmapWidthByte1,           BitmapWidthByte2,           BitmapWidthByte3,           BitmapWidthByte4,\r                  BitmapHeightByte1,          BitmapHeightByte2,          BitmapHeightByte3,          BitmapHeightByte4,\r                 BitmapPlanesByte1,          BitmapPlanesByte2,\r                 BitmapBitCountByte1,        BitmapBitCountByte2,\r                       BitmapCompressionByte1,     BitmapCompressionByte2,     BitmapCompressionByte3,     BitmapCompressionByte4,\r                    BitmapImageSizeByte1,       BitmapImageSizeByte2,       BitmapImageSizeByte3,       BitmapImageSizeByte4,\r                      BitmapXPixelsPerMByte1,     BitmapXPixelsPerMByte2,     BitmapXPixelsPerMByte3,     BitmapXPixelsPerMByte4,\r                    BitmapYPixelsPerMByte1,     BitmapYPixelsPerMByte2,     BitmapYPixelsPerMByte3,     BitmapYPixelsPerMByte4,\r                    BitmapColorsUsedByte1,      BitmapColorsUsedByte2,      BitmapColorsUsedByte3,      BitmapColorsUsedByte4,\r                     BitmapColorsImportantByte1, BitmapColorsImportantByte2, BitmapColorsImportantByte3, BitmapColorsImportantByte4\r         };\r             fos.write(BitmapBodyHeader);\r\r          int bodySize = IntBitmapWidth * IntBitmapHeight;\r               int bitPad = 4 - ((IntBitmapWidth * 3) % 4);\r           if(bitPad == 4) { bitPad = 0; }\r                int countRow = 1;\r              int indexRow = bodySize - IntBitmapWidth;\r              int indexLastRow = indexRow;\r           byte[] rgbArray = new byte[3];\r\r                for(int i = 0; i < bodySize; i++)\r              {\r                      int colorValue = PixelMap[indexRow];\r                   rgbArray[0] = (byte)(colorValue         & 0xFF); // red\r                        rgbArray[1] = (byte)((colorValue >> 8)  & 0xFF); // green\r                      rgbArray[2] = (byte)((colorValue >> 16) & 0xFF); // blue\r                       fos.write(rgbArray);\r                   if(countRow == IntBitmapWidth)\r                 {\r                              // pad row to 4 bits requirement\r                               for(int p = 0; p < bitPad; p++)\r                                {\r                                      fos.write(0x00);\r                               }\r                              countRow = 1;\r                          indexRow = indexLastRow - IntBitmapWidth;\r                              indexLastRow = indexRow;\r                       }\r                      else\r                   {\r                              countRow++;\r                    }\r                      indexRow++;\r            }\r\r             fos.flush();\r           fos.close();\r*/\r        }\r\r     public static void main(String[] args)\r {\r              if(args.length < 3)\r            {\r                      System.out.println("USAGE : CMUScodec -action input output");\r          }\r              else\r           {\r                      if(args[0].equals("-t"))\r                       {\r                              try\r                            {\r                                      decode(args[1], args[2]);\r                              }\r                              catch(Exception e)\r                             {\r                                      System.out.println(e);\r                         }\r                      }\r                      else\r                   {\r                              System.out.println("action " + args[0] + "not yet supported");\r                 }\r              }\r      }\r\r}\r
\ No newline at end of file