LH 1 rok temu
rodzic
commit
03e72641a8

+ 81 - 0
QuickStuff/src/main/java/QuickVerifyCrap/PrimeMagic.java

@@ -0,0 +1,81 @@
+package QuickVerifyCrap;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+
+public class PrimeMagic {
+    public static void main(String[] args) throws IOException {
+        double downscaler = 1.0/1.3;
+        double[] multconst = new double[16];
+        double mult = 1.0;
+        for(int i=15;i>0;i--)
+        {
+            multconst[i]=mult;
+            mult=mult*downscaler;
+        }
+        byte[] framelengths = new byte[]{0,0,0,0, 0,0,0,2, 4,8,16,32, 0,0,0,0};
+
+
+        String basepath = "D:/LOA/000030";
+        RandomAccessFile flash = new RandomAccessFile(basepath+"/flash.bin","r");
+        int count = flash.readInt();
+        count = Integer.reverseBytes(count);
+        System.out.println(count);
+        int dud = flash.readInt(); //2x unknown
+        dud = flash.readInt();
+        dud = flash.readInt();
+        int[] fileoffsets = new int[count];
+        int[] filelengths = new int[count];
+        for(int i=0;i<count;i++)
+        {
+            int offset = Integer.reverseBytes(flash.readInt());
+            int len = Integer.reverseBytes(flash.readInt());
+            filelengths[i]=len;
+            fileoffsets[i]=offset;
+        }
+        for(int i=0;i<count;i++)
+        {
+            System.out.println(count);
+            System.out.println(fileoffsets[i]);
+            flash.seek(fileoffsets[i]);
+            dud = flash.readInt(); //flags & samplerate, ignure due to being const
+            RandomAccessFile multipliers = new RandomAccessFile(basepath+"/flash."+i+".mult.bin","rw");
+            RandomAccessFile modifiers = new RandomAccessFile(basepath+"/flash."+i+".mod.bin","rw");
+            RandomAccessFile processedData = new RandomAccessFile(basepath+"/flash."+i+".proc.bin","rw");
+            RandomAccessFile rawData = new RandomAccessFile(basepath+"/flash."+i+".raw.bin","rw");
+            int limit = Integer.reverseBytes(flash.readInt());
+            dud = flash.readInt(); //flags & samplerate, ignure due to being const
+            long hardlimit = flash.getFilePointer()+limit;
+            while(flash.getFilePointer()<hardlimit)
+            {
+                byte frameprefix = flash.readByte();
+                byte multiplier = (byte)((frameprefix>>4)&0x0F);
+                byte framelen = (byte)(frameprefix&0x0f);
+                multipliers.write(multiplier);
+                int mappedFramelen = framelengths[framelen];
+                boolean tail=false;
+                if(mappedFramelen==0)
+                {
+                    tail=true;
+                    mappedFramelen= (int) (hardlimit- flash.getFilePointer()); //edgecase tail;
+                }
+                byte modifier = flash.readByte();
+                modifiers.write(modifier);
+                byte[] framecontent = new byte[mappedFramelen];
+                flash.read(framecontent);
+                for(int j=0;j<mappedFramelen;j++)
+                {
+                    int rescaledSample = framecontent[j];
+                    rescaledSample *=multconst[multiplier];
+                    processedData.writeShort(rescaledSample);
+                }
+                rawData.write(framecontent);
+            }
+            multipliers.close();
+            modifiers.close();
+            processedData.close();
+            rawData.close();
+        }
+    }
+}