From 08aa16493c0015a215ae5856de72ae90e4fe9579 Mon Sep 17 00:00:00 2001 From: Nes370 Date: Sat, 20 Jul 2024 10:35:58 -0700 Subject: [PATCH] Update AudioExtractor.java --- src/goblincave/gitea/nes/AudioExtractor.java | 80 ++++++++++++++++++-- 1 file changed, 74 insertions(+), 6 deletions(-) diff --git a/src/goblincave/gitea/nes/AudioExtractor.java b/src/goblincave/gitea/nes/AudioExtractor.java index 238a7e1..b9525c5 100644 --- a/src/goblincave/gitea/nes/AudioExtractor.java +++ b/src/goblincave/gitea/nes/AudioExtractor.java @@ -205,6 +205,12 @@ public class AudioExtractor { } + /** + * Helper function to prompt user to select a WAV file. + * + * @param reader + * @return WAV file + */ private static File retrieveWave(BufferedReader reader) { String prompt = "Please provide a WAV file: " + PALE_YELLOW; @@ -249,6 +255,12 @@ public class AudioExtractor { } + /** + * Helper function to prompt user to select a file. + * + * @param reader + * @return file + */ private static File retrieveFile(BufferedReader reader, String prompt, String extension) { File file = null; @@ -274,6 +286,12 @@ public class AudioExtractor { } + /** + * Helper function to prompt user to select a color. + * + * @param reader + * @return color attribute + */ private static Attribute retrieveColor(BufferedReader reader) { String prompt = "\nCommand parameters: " + Ansi.colorize("Print", Attribute.BRIGHT_BLUE_TEXT()) @@ -337,6 +355,13 @@ public class AudioExtractor { } + /** + * Helper function to prompt user to select a program task. + * + * @param reader + * @param input + * @return operation + */ private static String retrieveOperation(BufferedReader reader, String input) { String operation = null; @@ -391,6 +416,7 @@ public class AudioExtractor { /** * Prompts the user for input without strict validation. + * * @param reader * @param prompt * @return input @@ -448,9 +474,10 @@ public class AudioExtractor { } /** - * Patches the provided WAV file by seeking out its data and smpl chunks, - * deletes any existing smpl chunk, - * then inserts a new smpl chunk with loop points set at the start and end of the data chunk. + * Patches a WAV file by seeking out its data and smpl chunks, + * replacing any existing smpl chunk with a new smpl chunk, + * setting loop points at the start and end of the data chunk. + * * @param waveFile */ private static void patch(File waveFile) { @@ -487,7 +514,7 @@ public class AudioExtractor { + buffer[1] * (int) Math.pow(16, 4) + buffer[0] * (int) Math.pow(16, 6); - } + } else throw new IOException("Data chunk not in file."); // Determine size of smpl chunk if(smplAddress > -1) { @@ -504,11 +531,36 @@ public class AudioExtractor { } - - // Create new sample chunk // Insert 68-byte sample chunk with loop before data chunk + byte[] smpl = new byte[68]; + // smpl (0) + smpl[0] = 0x73; + smpl[1] = 0x6D; + smpl[2] = 0x70; + smpl[3] = 0x6C; + // size (4) + smpl[4] = 0x3C; + // manufacturer (8) + // product (12) + // sample period (16) + // MIDI unity note (20) + smpl[20] = 0x3C; + // MIDI pitch fraction (24) + // SMPTE Format (28) + // SMPTE Offset (32) + // Number of Sample Loops (36) + smpl[36] = 0x01; + // Sample Loops size (40) + // loop ID (44) + // loop type (48) + // data start + // loop start (52) + // data end + // loop end (56) + // tuning fraction (60) + // play count (64) // Set loop points to start and end of data chunk @@ -519,6 +571,12 @@ public class AudioExtractor { } + /** + * Packs WAV files located at the extract directory into BIN files at the package directory. + * + * @param packDirectory + * @param extractDirectory + */ private static void pack(File packDirectory, File extractDirectory) { // Identify extracted folders @@ -546,7 +604,9 @@ public class AudioExtractor { // 3. If pack file already exists, insert WAV files into existing file. // 4. If pack file doesn't exist, create new file then insert WAV files. + } + // Hypothesis 1: Does Ridge Racer 6 use a predetermined address list for reading tracks from package? // Test 1: Try changing the address of a track and see if the game can handle it successfully. @@ -556,6 +616,14 @@ public class AudioExtractor { } + /** + * Extracts audio files to the extract directory from package files located at the package directory. + * Also supports FLAC conversion for BGM files. + * + * @param packDirectory + * @param extractDirectory + * @param compressBGM + */ public static void extract(File packDirectory, File extractDirectory, boolean compressBGM) { // TODO Delete