PrimeMagic.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package QuickVerifyCrap;
  2. import java.io.FileNotFoundException;
  3. import java.io.IOException;
  4. import java.io.RandomAccessFile;
  5. public class PrimeMagic {
  6. public static void main(String[] args) throws IOException {
  7. double downscaler = 1.0/1.3;
  8. double[] multconst = new double[16];
  9. double mult = 1.0;
  10. for(int i=15;i>0;i--)
  11. {
  12. multconst[i]=mult;
  13. mult=mult*downscaler;
  14. }
  15. byte[] framelengths = new byte[]{0,0,0,0, 0,0,0,2, 4,8,16,32, 0,0,0,0};
  16. String basepath = "D:/LOA/000030";
  17. RandomAccessFile flash = new RandomAccessFile(basepath+"/flash.bin","r");
  18. int count = flash.readInt();
  19. count = Integer.reverseBytes(count);
  20. System.out.println(count);
  21. int dud = flash.readInt(); //2x unknown
  22. dud = flash.readInt();
  23. dud = flash.readInt();
  24. int[] fileoffsets = new int[count];
  25. int[] filelengths = new int[count];
  26. for(int i=0;i<count;i++)
  27. {
  28. int offset = Integer.reverseBytes(flash.readInt());
  29. int len = Integer.reverseBytes(flash.readInt());
  30. filelengths[i]=len;
  31. fileoffsets[i]=offset;
  32. }
  33. for(int i=0;i<count;i++)
  34. {
  35. System.out.println(count);
  36. System.out.println(fileoffsets[i]);
  37. flash.seek(fileoffsets[i]);
  38. dud = flash.readInt(); //flags & samplerate, ignure due to being const
  39. RandomAccessFile multipliers = new RandomAccessFile(basepath+"/flash."+i+".mult.bin","rw");
  40. RandomAccessFile modifiers = new RandomAccessFile(basepath+"/flash."+i+".mod.bin","rw");
  41. RandomAccessFile processedData = new RandomAccessFile(basepath+"/flash."+i+".proc.bin","rw");
  42. RandomAccessFile rawData = new RandomAccessFile(basepath+"/flash."+i+".raw.bin","rw");
  43. int limit = Integer.reverseBytes(flash.readInt());
  44. dud = flash.readInt(); //flags & samplerate, ignure due to being const
  45. long hardlimit = flash.getFilePointer()+limit;
  46. while(flash.getFilePointer()<hardlimit)
  47. {
  48. byte frameprefix = flash.readByte();
  49. byte multiplier = (byte)((frameprefix>>4)&0x0F);
  50. byte framelen = (byte)(frameprefix&0x0f);
  51. multipliers.write(multiplier);
  52. int mappedFramelen = framelengths[framelen];
  53. boolean tail=false;
  54. if(mappedFramelen==0)
  55. {
  56. tail=true;
  57. mappedFramelen= (int) (hardlimit- flash.getFilePointer()); //edgecase tail;
  58. }
  59. byte modifier = flash.readByte();
  60. modifiers.write(modifier);
  61. byte[] framecontent = new byte[mappedFramelen];
  62. flash.read(framecontent);
  63. for(int j=0;j<mappedFramelen;j++)
  64. {
  65. int rescaledSample = framecontent[j];
  66. rescaledSample *=multconst[multiplier];
  67. processedData.writeShort(rescaledSample);
  68. }
  69. rawData.write(framecontent);
  70. }
  71. multipliers.close();
  72. modifiers.close();
  73. processedData.close();
  74. rawData.close();
  75. }
  76. }
  77. }