diff --git a/res/pack_dj_menu.csv b/res/pack_dj_menu.csv index bfbdbde..b8e3c80 100644 --- a/res/pack_dj_menu.csv +++ b/res/pack_dj_menu.csv @@ -1,23 +1,23 @@ Track,Speaker,Transcript,Context -1,Normal,, -2,Normal,, -3,Normal,, -4,Normal,, -5,Normal,, -6,Normal,, -7,Normal,, -8,Normal,, -9,Normal,, -10,Normal,, -11,Normal,, -12,Normal,, -13,Normal,, -14,Normal,, -15,Normal,, -16,Normal,, -17,Normal,, -18,Normal,, -19,Normal,, +1,Normal,Ridge Racer,Title screen +2,Normal,Ridge Racer,Title screen +3,Normal,Ridge Racer,Title screen +4,Normal,Ridge Racer,Title screen +5,Normal,Ridge Racer,Title screen +6,Normal,Ridge Racer,Title screen +7,Normal,Ridge Racer,Title screen +8,Normal,"Welcome to the AV player. Enjoy great music, and even greater replays.",AV Player +9,Normal,"Welcome to the AV player. Enjoy great music, and even greater replays.",AV Player +10,Normal,"Welcome to the AV player. Enjoy great music, and even greater replays.",AV Player +11,Normal,"Welcome to the AV player. Enjoy great music, and even greater replays.",AV Player +12,Normal,"Welcome to the AV player. Remember, you can always enjoy these tunes while you're driving too.",AV Player +13,Normal,Here's the next tune.,AV Player +14,Normal,Here's the next tune.,AV Player +15,Normal,Here's the next tune.,AV Player +16,Normal,Here's the next tune.,AV Player +17,Normal,I can feel this race is gonna be really hot. Now start your engine and get ready.,Pre-race +18,Normal,I can feel this race is gonna be really hot. Now start your engine and get ready.,Pre-race +19,Normal,Hah aww yeah… I can feel this race is gonna be really hot. Now start your engine and get ready.,Pre-race 20,Normal,, 21,Normal,, 22,Normal,, diff --git a/src/goblincave/gitea/nes/AudioExtractor.java b/src/goblincave/gitea/nes/AudioExtractor.java index 9a4750b..474e440 100644 --- a/src/goblincave/gitea/nes/AudioExtractor.java +++ b/src/goblincave/gitea/nes/AudioExtractor.java @@ -33,7 +33,7 @@ public class AudioExtractor { * Activate alternate behavior for command line terminal. * Specifically prints things in a narrower width, and overwrites previous lines to add color. */ - private final static boolean CMD_MODE = false; + private final static boolean CMD_MODE = true; /** * ANSI code to go up one line, followed by a carriage return. @@ -51,6 +51,11 @@ public class AudioExtractor { * Indicates the start of a RIFF header in WAV files. */ private final static int ASCII_RIFF = 0x5249_4646; + /** + * Hex value for the ASCII sequence "fmt ". + * Indicates the start of a format chunk in WAV files. + */ + private final static int ASCII_fmt = 0x666D_7420; /** * Hex value for the ASCII sequence "smpl". * Indicates the start of a sample chunk in WAV files. @@ -61,7 +66,16 @@ public class AudioExtractor { * Indicates the start of a data chunk in WAV files. */ private final static int ASCII_data = 0x6461_7461; - + /** + * Hex value for the ASCII sequence "ALIG". + * Indicates the start of an alignment chunk in WAV files. + */ + private final static int ASCII_ALIG = 0x414C_4947; + /** + * Hex value for the ASCII sequence "x2st". + * Indicates the start of an XMA stream chunk in WAV files. + */ + private final static int ASCII_x2st = 0x7832_7374; /** * BIN files must first be extracted from game disk to use this program. * By default uses program directory for I/O and saves audio as WAV.
@@ -125,6 +139,10 @@ public class AudioExtractor { if(args.length == 0) { // no arguments provided switch(operation) { + case "identify": + File unknownFile = retrieveFile(reader, "Please enter the path of a file: " + ANSI_BEIGE); + identify(unknownFile); + break; case "extract": // extract // Determine package directory File currentDir = new File(new File(AudioExtractor.class.getProtectionDomain().getCodeSource().getLocation().toURI()) @@ -234,6 +252,39 @@ public class AudioExtractor { } + /** + * Helper method to convert a number of bytes to a more readable form. + * + * @param bytes + * @return legible form + */ + private static String convertBytes(long bytes) { + + final String[] units = new String[] {"B", "KB", "MB", "GB", "TB"}; + int i = (int) (Math.log10(bytes) / Math.log10(1024)); + double value = bytes / Math.pow(1024, i); + return String.format("%.2f %s", value, units[i]); + + } + + public static void identify(File file) { + // TODO check for characteristics of BIN or WAV files + String name = file.getName(); + System.out.println("Name:\t" + name); + + long size = file.length(); + System.out.println("Size:\t" + size + " Bytes" + (size > 1024 ? " (" + convertBytes(size) + ")" : "")); + + // file extension + int extIndex = name.lastIndexOf('.'); + String extension = null; + if(extIndex > 0 && extIndex < name.length() - 1) + extension = name.substring(extIndex + 1); + + // check if RIFF header + + } + /** * Extracts audio files to the extract directory from package files located at the package directory. * Also supports FLAC conversion for BGM files. @@ -557,6 +608,39 @@ public class AudioExtractor { } + /** + * Helper function to prompt user to select a file. + * + * @param reader + * @return file + */ + private static File retrieveFile(BufferedReader reader, String prompt) { + + File file = null; + + String input = null; + boolean valid = false; + do { + System.out.print(prompt); + try { + input = reader.readLine(); + file = new File(input); + if(file.exists()) { + if(file.isFile()) { + valid = true; + } else System.out.println(Ansi.colorize("Path does not resolve to a file.")); + } else System.out.println(Ansi.colorize("File does not exist.")); + } catch (IOException e) { + System.out.println(Ansi.colorize("Invalid file.")); + } + } while(!valid); + + System.out.print(Ansi.colorize("\n")); + + return file; + + } + /** * Helper function to prompt user to select a file. * @@ -577,8 +661,8 @@ public class AudioExtractor { if(file.exists()) { if(file.getName().toLowerCase().endsWith(extension)) { valid = true; - } else System.out.println("File does not have " + extension.toUpperCase() + " file extension"); - } else System.out.println("File does not exist."); + } else System.out.println(Ansi.colorize("File does not have " + extension.toUpperCase() + " file extension")); + } else System.out.println(Ansi.colorize("File does not exist.")); } catch (IOException e) { System.out.println(Ansi.colorize("Invalid file.")); } @@ -667,7 +751,7 @@ public class AudioExtractor { private static String retrieveOperation(BufferedReader reader, String input) { String operation = null; - String[] values = {"extract", "pack", "patch", "print", "exit"}; + String[] values = {"identify", "extract", "pack", "patch", "print", "exit"}; if(input != null) for(int i = 0; i < values.length; i++) @@ -677,10 +761,12 @@ public class AudioExtractor { if(operation == null) { String prompt = "\n" + Ansi.colorize("Operations", Attribute.BRIGHT_YELLOW_TEXT(), Attribute.BOLD()) + ":\n" - + "- " + Ansi.colorize("Extract", Attribute.BRIGHT_RED_TEXT()) + " audio tracks from package\n" - + "- " + Ansi.colorize("Pack", Attribute.YELLOW_TEXT()) + " audio tracks into package\n" - + "- " + Ansi.colorize("Patch", Attribute.BRIGHT_GREEN_TEXT()) + " audio track to loop indefinitely\n" - + "- " + Ansi.colorize("Print", Attribute.BRIGHT_BLUE_TEXT()) + " Ridge Racer 6 style ASCII logo\n" + + "- " + Ansi.colorize("Identify", Attribute.BRIGHT_RED_TEXT()) + " a package or audio file\n" + + "- " + Ansi.colorize("Extract", Attribute.TEXT_COLOR(0xFF, 0x68, 0x1F)) + " audio tracks from a package (BIN to WAV)\n" + + "- " + Ansi.colorize("Convert", Attribute.TEXT_COLOR(0xFF, 0xEA, 0x00)) + " audio tracks to another format (XMA to PCM / WAV to FLAC)\n" + + "- " + Ansi.colorize("Patch", Attribute.BRIGHT_GREEN_TEXT()) + " an audio track to repeat (PCM-encoded WAV)\n" + + "- " + Ansi.colorize("Pack", Attribute.BRIGHT_BLUE_TEXT()) + " audio tracks into a package (WAV to BIN)\n" + + "- " + Ansi.colorize("Print", Attribute.TEXT_COLOR(0x6B, 0x4C, 0xE3)) + " a Ridge Racer 6 style ASCII logo\n" + "- " + Ansi.colorize("Exit", Attribute.BRIGHT_MAGENTA_TEXT()) + " program\n" + "\nPlease select an operation: " + ANSI_BEIGE; @@ -690,18 +776,23 @@ public class AudioExtractor { Attribute color = null; switch(operation.toLowerCase()) { - case "extract": + case "identify": color = Attribute.BRIGHT_RED_TEXT(); break; - case "package": - color = Attribute.YELLOW_TEXT(); + case "extract": + color = Attribute.TEXT_COLOR(0xFF, 0x68, 0x1F); break; + case "convert": + color = Attribute.TEXT_COLOR(0xFF, 0xEA, 0x00); case "patch": color = Attribute.BRIGHT_GREEN_TEXT(); break; - case "print": + case "pack": color = Attribute.BRIGHT_BLUE_TEXT(); break; + case "print": + color = Attribute.TEXT_COLOR(0x6B, 0x4C, 0xE3); + break; case "exit": color = Attribute.BRIGHT_MAGENTA_TEXT(); break;