package mapped;

import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSVorbisSample;

@ObfuscatedName("cv")
public class VorbisSample extends Node implements RSVorbisSample {
   @ObfuscatedName("aa")
   @ObfuscatedSignature(
      descriptor = "Lcw;"
   )
   static class60 field359;
   @ObfuscatedName("ac")
   static int field377;
   @ObfuscatedName("al")
   static int field361;
   @ObfuscatedName("az")
   @ObfuscatedSignature(
      descriptor = "[Lcf;"
   )
   static VorbisCodebook[] field362;
   @ObfuscatedName("ap")
   @ObfuscatedSignature(
      descriptor = "[Lbu;"
   )
   static VorbisFloor[] field363;
   @ObfuscatedName("av")
   @ObfuscatedSignature(
      descriptor = "[Lbs;"
   )
   static VorbisResidue[] field364;
   @ObfuscatedName("ax")
   @ObfuscatedSignature(
      descriptor = "[Lbr;"
   )
   static VorbisMapping[] field365;
   @ObfuscatedName("as")
   static boolean[] field378;
   @ObfuscatedName("ay")
   static int[] field367;
   @ObfuscatedName("ak")
   static boolean field368;
   @ObfuscatedName("ae")
   static float[] field374;
   @ObfuscatedName("an")
   static float[] field375;
   @ObfuscatedName("ag")
   static float[] field355;
   @ObfuscatedName("ad")
   static float[] field376;
   @ObfuscatedName("af")
   static float[] field358;
   @ObfuscatedName("be")
   static float[] field366;
   @ObfuscatedName("bd")
   static int[] field380;
   @ObfuscatedName("bl")
   static int[] field381;
   @ObfuscatedName("at")
   byte[][] field357;
   @ObfuscatedName("ah")
   int sampleRate;
   @ObfuscatedName("ar")
   int sampleCount;
   @ObfuscatedName("ao")
   int start;
   @ObfuscatedName("ab")
   int end;
   @ObfuscatedName("au")
   boolean field379;
   @ObfuscatedName("aj")
   float[] field369;
   @ObfuscatedName("am")
   int field370;
   @ObfuscatedName("aq")
   int field371;
   @ObfuscatedName("ai")
   boolean field372;
   @ObfuscatedName("aw")
   float[] field373;
   @ObfuscatedName("bi")
   byte[] samples;
   @ObfuscatedName("bv")
   int field383;
   @ObfuscatedName("bf")
   int field384;

   static {
      field359 = new class60();
      field368 = false;
   }

   VorbisSample(byte[] var1) {
      this.read_base(var1);
   }

   @ObfuscatedName("ah")
   void read_base(byte[] var1) {
      Buffer var2 = new Buffer(var1);
      this.sampleRate = var2.readInt_base();
      this.sampleCount = var2.readInt_base();
      this.start = var2.readInt_base();
      this.end = var2.readInt_base();
      if(this.end < 0) {
         this.end = ~this.end;
         this.field379 = true;
      }

      int var3 = var2.readInt_base();
      this.field357 = new byte[var3][];

      for(int var4 = 0; var4 < var3; ++var4) {
         int var5 = 0;

         int var6;
         do {
            var6 = var2.readUnsignedByte_base();
            var5 += var6;
         } while(var6 >= 255);

         byte[] var7 = new byte[var5];
         var2.readBytes_base(var7, 0, var5);
         this.field357[var4] = var7;
      }

   }

   @ObfuscatedName("ao")
   float[] method1114_base(int var1) {
      class60 var2 = new class60();
      var2.method1189_base(this.field357[var1], 0);
      this.field373 = new float[field361];
      var2.method1188_base();
      int var3 = var2.method1187_base(LoginScreenAnimation.iLog_base(field367.length - 1));
      boolean var4 = field378[var3];
      int var5 = var4?field361:field377;
      boolean var6 = false;
      boolean var7 = false;
      if(var4) {
         var6 = var2.method1188_base() != 0;
         var7 = var2.method1188_base() != 0;
      }

      int var8 = var5 >> 1;
      int var9;
      int var10;
      int var11;
      if(var4 && !var6) {
         var9 = (var5 >> 2) - (field377 >> 2);
         var10 = (field377 >> 2) + (var5 >> 2);
         var11 = field377 >> 1;
      } else {
         var9 = 0;
         var10 = var8;
         var11 = var5 >> 1;
      }

      int var12;
      int var13;
      int var14;
      if(var4 && !var7) {
         var12 = var5 - (var5 >> 2) - (field377 >> 2);
         var13 = (field377 >> 2) + (var5 - (var5 >> 2));
         var14 = field377 >> 1;
      } else {
         var12 = var8;
         var13 = var5;
         var14 = var5 >> 1;
      }

      VorbisMapping var15 = field365[field367[var3]];
      int var16 = var15.field341;
      int var17 = var15.field343[var16];
      class59 var18 = field363[var17].method780_base(var2);
      boolean var19 = !var18.method1173_base();

      int var20;
      for(var20 = 0; var20 < var15.field340; ++var20) {
         VorbisResidue var21 = field364[var15.field342[var20]];
         float[] var22 = this.field373;
         var21.method895_base(var22, var5 >> 1, var19, var2);
      }

      if(var18.method1173_base()) {
         var16 = var15.field341;
         int var10000 = var15.field343[var16];
         var18.method1172_base(this.field373, var5 >> 1);
      }

      int var44;
      int var45;
      if(!var18.method1173_base()) {
         for(var20 = var5 >> 1; var20 < var5; ++var20) {
            this.field373[var20] = 0.0F;
         }
      } else {
         var20 = var5 >> 1;
         var44 = var5 >> 2;
         var45 = var5 >> 3;
         float[] var46 = this.field373;

         int var24;
         for(var24 = 0; var24 < var20; ++var24) {
            var46[var24] *= 0.5F;
         }

         for(var24 = var20; var24 < var5; ++var24) {
            var46[var24] = -var46[var5 - var24 - 1];
         }

         float[] var47 = var4?field376:field374;
         float[] var25 = var4?field358:field375;
         float[] var26 = var4?field366:field355;
         int[] var27 = var4?field381:field380;

         int var28;
         float var29;
         float var30;
         float var31;
         float var32;
         for(var28 = 0; var28 < var44; ++var28) {
            var29 = var46[var28 * 4] - var46[var5 - var28 * 4 - 1];
            var30 = var46[var28 * 4 + 2] - var46[var5 - var28 * 4 - 3];
            var31 = var47[var28 * 2];
            var32 = var47[var28 * 2 + 1];
            var46[var5 - var28 * 4 - 1] = var29 * var31 - var30 * var32;
            var46[var5 - var28 * 4 - 3] = var29 * var32 + var30 * var31;
         }

         float var33;
         float var34;
         for(var28 = 0; var28 < var45; ++var28) {
            var29 = var46[var20 + var28 * 4 + 3];
            var30 = var46[var20 + var28 * 4 + 1];
            var31 = var46[var28 * 4 + 3];
            var32 = var46[var28 * 4 + 1];
            var46[var20 + var28 * 4 + 3] = var29 + var31;
            var46[var20 + var28 * 4 + 1] = var30 + var32;
            var33 = var47[var20 - 4 - var28 * 4];
            var34 = var47[var20 - 3 - var28 * 4];
            var46[var28 * 4 + 3] = (var29 - var31) * var33 - (var30 - var32) * var34;
            var46[var28 * 4 + 1] = (var30 - var32) * var33 + (var29 - var31) * var34;
         }

         var28 = LoginScreenAnimation.iLog_base(var5 - 1);

         int var49;
         int var50;
         int var51;
         int var52;
         for(var49 = 0; var49 < var28 - 3; ++var49) {
            var50 = var5 >> var49 + 2;
            var51 = 8 << var49;

            for(var52 = 0; var52 < 2 << var49; ++var52) {
               int var53 = var5 - var50 * var52 * 2;
               int var54 = var5 - var50 * (var52 * 2 + 1);

               for(int var35 = 0; var35 < var5 >> var49 + 4; ++var35) {
                  int var36 = var35 * 4;
                  float var37 = var46[var53 - 1 - var36];
                  float var38 = var46[var53 - 3 - var36];
                  float var39 = var46[var54 - 1 - var36];
                  float var40 = var46[var54 - 3 - var36];
                  var46[var53 - 1 - var36] = var37 + var39;
                  var46[var53 - 3 - var36] = var38 + var40;
                  float var41 = var47[var35 * var51];
                  float var42 = var47[var35 * var51 + 1];
                  var46[var54 - 1 - var36] = (var37 - var39) * var41 - (var38 - var40) * var42;
                  var46[var54 - 3 - var36] = (var38 - var40) * var41 + (var37 - var39) * var42;
               }
            }
         }

         for(var49 = 1; var49 < var45 - 1; ++var49) {
            var50 = var27[var49];
            if(var49 < var50) {
               var51 = var49 * 8;
               var52 = var50 * 8;
               var33 = var46[var51 + 1];
               var46[var51 + 1] = var46[var52 + 1];
               var46[var52 + 1] = var33;
               var33 = var46[var51 + 3];
               var46[var51 + 3] = var46[var52 + 3];
               var46[var52 + 3] = var33;
               var33 = var46[var51 + 5];
               var46[var51 + 5] = var46[var52 + 5];
               var46[var52 + 5] = var33;
               var33 = var46[var51 + 7];
               var46[var51 + 7] = var46[var52 + 7];
               var46[var52 + 7] = var33;
            }
         }

         for(var49 = 0; var49 < var20; ++var49) {
            var46[var49] = var46[var49 * 2 + 1];
         }

         for(var49 = 0; var49 < var45; ++var49) {
            var46[var5 - 1 - var49 * 2] = var46[var49 * 4];
            var46[var5 - 2 - var49 * 2] = var46[var49 * 4 + 1];
            var46[var5 - var44 - 1 - var49 * 2] = var46[var49 * 4 + 2];
            var46[var5 - var44 - 2 - var49 * 2] = var46[var49 * 4 + 3];
         }

         for(var49 = 0; var49 < var45; ++var49) {
            var30 = var26[var49 * 2];
            var31 = var26[var49 * 2 + 1];
            var32 = var46[var20 + var49 * 2];
            var33 = var46[var20 + var49 * 2 + 1];
            var34 = var46[var5 - 2 - var49 * 2];
            float var55 = var46[var5 - 1 - var49 * 2];
            float var56 = var31 * (var32 - var34) + var30 * (var33 + var55);
            var46[var20 + var49 * 2] = (var32 + var34 + var56) * 0.5F;
            var46[var5 - 2 - var49 * 2] = (var32 + var34 - var56) * 0.5F;
            var56 = var31 * (var33 + var55) - var30 * (var32 - var34);
            var46[var20 + var49 * 2 + 1] = (var33 - var55 + var56) * 0.5F;
            var46[var5 - 1 - var49 * 2] = (-var33 + var55 + var56) * 0.5F;
         }

         for(var49 = 0; var49 < var44; ++var49) {
            var46[var49] = var46[var20 + var49 * 2] * var25[var49 * 2] + var46[var20 + var49 * 2 + 1] * var25[var49 * 2 + 1];
            var46[var20 - 1 - var49] = var46[var20 + var49 * 2] * var25[var49 * 2 + 1] - var46[var20 + var49 * 2 + 1] * var25[var49 * 2];
         }

         for(var49 = 0; var49 < var44; ++var49) {
            var46[var49 + (var5 - var44)] = -var46[var49];
         }

         for(var49 = 0; var49 < var44; ++var49) {
            var46[var49] = var46[var44 + var49];
         }

         for(var49 = 0; var49 < var44; ++var49) {
            var46[var44 + var49] = -var46[var44 - var49 - 1];
         }

         for(var49 = 0; var49 < var44; ++var49) {
            var46[var20 + var49] = var46[var5 - var49 - 1];
         }

         for(var49 = var9; var49 < var10; ++var49) {
            var30 = (float)Math.sin(((double)(var49 - var9) + 0.5D) / (double)var11 * 0.5D * 3.141592653589793D);
            this.field373[var49] *= (float)Math.sin(1.5707963267948966D * (double)var30 * (double)var30);
         }

         for(var49 = var12; var49 < var13; ++var49) {
            var30 = (float)Math.sin(((double)(var49 - var12) + 0.5D) / (double)var14 * 0.5D * 3.141592653589793D + 1.5707963267948966D);
            this.field373[var49] *= (float)Math.sin(1.5707963267948966D * (double)var30 * (double)var30);
         }
      }

      float[] var43 = null;
      if(this.field370 > 0) {
         var44 = var5 + this.field370 >> 2;
         var43 = new float[var44];
         int var23;
         if(!this.field372) {
            for(var45 = 0; var45 < this.field371; ++var45) {
               var23 = var45 + (this.field370 >> 1);
               var43[var45] += this.field369[var23];
            }
         }

         if(var18.method1173_base()) {
            for(var45 = var9; var45 < var5 >> 1; ++var45) {
               var23 = var43.length - (var5 >> 1) + var45;
               var43[var23] += this.field373[var45];
            }
         }
      }

      float[] var48 = this.field369;
      this.field369 = this.field373;
      this.field373 = var48;
      this.field370 = var5;
      this.field371 = var13 - (var5 >> 1);
      this.field372 = !var18.method1173_base();
      return var43;
   }

   @ObfuscatedName("aa")
   @ObfuscatedSignature(
      descriptor = "([I)Lbt;"
   )
   RawSound method1113(int[] var1) {
      if(var1 != null && var1[0] <= 0) {
         return null;
      } else {
         if(this.samples == null) {
            this.field370 = 0;
            this.field369 = new float[field361];
            this.samples = new byte[this.sampleCount];
            this.field383 = 0;
            this.field384 = 0;
         }

         for(; this.field384 < this.field357.length; ++this.field384) {
            if(var1 != null && var1[0] <= 0) {
               return null;
            }

            float[] var2 = this.method1114_base(this.field384);
            if(var2 != null) {
               int var3 = this.field383;
               int var4 = var2.length;
               if(var4 > this.sampleCount - var3) {
                  var4 = this.sampleCount - var3;
               }

               for(int var5 = 0; var5 < var4; ++var5) {
                  int var6 = (int)(128.0F + var2[var5] * 128.0F);
                  if((var6 & -256) != 0) {
                     var6 = ~var6 >> 31;
                  }

                  this.samples[var3++] = (byte)(var6 - 128);
               }

               if(var1 != null) {
                  var1[0] -= var3 - this.field383;
               }

               this.field383 = var3;
            }
         }

         this.field369 = null;
         byte[] var7 = this.samples;
         this.samples = null;
         return new RawSound(this.sampleRate, var7, this.start, this.end, this.field379);
      }
   }

   @ObfuscatedName("at")
   static float float32Unpack_base(int var0) {
      int var1 = var0 & 2097151;
      int var2 = var0 & Integer.MIN_VALUE;
      int var3 = (var0 & 2145386496) >> 21;
      if(var2 != 0) {
         var1 = -var1;
      }

      return (float)((double)var1 * Math.pow(2.0D, (double)(var3 - 788)));
   }

   @ObfuscatedName("ar")
   static void method1133_base(byte[] var0) {
      class60 var1 = field359;
      var1.method1189_base(var0, 0);
      field377 = 1 << var1.method1187_base(4);
      field361 = 1 << var1.method1187_base(4);

      int var2;
      int var3;
      int var4;
      int var5;
      int var6;
      for(var2 = 0; var2 < 2; ++var2) {
         var3 = var2 != 0?field361:field377;
         var4 = var3 >> 1;
         var5 = var3 >> 2;
         var6 = var3 >> 3;
         float[] var7 = new float[var4];

         for(int var8 = 0; var8 < var5; ++var8) {
            var7[var8 * 2] = (float)Math.cos((double)(var8 * 4) * 3.141592653589793D / (double)var3);
            var7[var8 * 2 + 1] = -((float)Math.sin((double)(var8 * 4) * 3.141592653589793D / (double)var3));
         }

         float[] var13 = new float[var4];

         for(int var9 = 0; var9 < var5; ++var9) {
            var13[var9 * 2] = (float)Math.cos((double)(var9 * 2 + 1) * 3.141592653589793D / (double)(var3 * 2));
            var13[var9 * 2 + 1] = (float)Math.sin((double)(var9 * 2 + 1) * 3.141592653589793D / (double)(var3 * 2));
         }

         float[] var14 = new float[var5];

         for(int var10 = 0; var10 < var6; ++var10) {
            var14[var10 * 2] = (float)Math.cos((double)(var10 * 4 + 2) * 3.141592653589793D / (double)var3);
            var14[var10 * 2 + 1] = -((float)Math.sin((double)(var10 * 4 + 2) * 3.141592653589793D / (double)var3));
         }

         int[] var15 = new int[var6];
         int var11 = LoginScreenAnimation.iLog_base(var6 - 1);

         for(int var12 = 0; var12 < var6; ++var12) {
            var15[var12] = class361.method6868_base(var12, var11);
         }

         if(var2 != 0) {
            field376 = var7;
            field358 = var13;
            field366 = var14;
            field381 = var15;
         } else {
            field374 = var7;
            field375 = var13;
            field355 = var14;
            field380 = var15;
         }
      }

      var2 = var1.method1187_base(8) + 1;
      field362 = new VorbisCodebook[var2];

      for(var3 = 0; var3 < var2; ++var3) {
         field362[var3] = new VorbisCodebook();
      }

      var3 = var1.method1187_base(6) + 1;

      for(var4 = 0; var4 < var3; ++var4) {
         var1.method1187_base(16);
      }

      var3 = var1.method1187_base(6) + 1;
      field363 = new VorbisFloor[var3];

      for(var4 = 0; var4 < var3; ++var4) {
         field363[var4] = new VorbisFloor();
      }

      var4 = var1.method1187_base(6) + 1;
      field364 = new VorbisResidue[var4];

      for(var5 = 0; var5 < var4; ++var5) {
         field364[var5] = new VorbisResidue();
      }

      var5 = var1.method1187_base(6) + 1;
      field365 = new VorbisMapping[var5];

      for(var6 = 0; var6 < var5; ++var6) {
         field365[var6] = new VorbisMapping();
      }

      var6 = var1.method1187_base(6) + 1;
      field378 = new boolean[var6];
      field367 = new int[var6];

      for(int var16 = 0; var16 < var6; ++var16) {
         field378[var16] = var1.method1188_base() != 0;
         var1.method1187_base(16);
         var1.method1187_base(16);
         field367[var16] = var1.method1187_base(8);
      }

   }

   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "(Lol;)Z"
   )
   static boolean method1116(AbstractArchive var0) {
      if(!field368) {
         byte[] var1 = var0.takeFile_base(0, 0);
         if(var1 == null) {
            return false;
         }

         method1133_base(var1);
         field368 = true;
      }

      return true;
   }

   @ObfuscatedName("au")
   @ObfuscatedSignature(
      descriptor = "(Lol;II)Lcv;"
   )
   static VorbisSample method1115(AbstractArchive var0, int var1, int var2) {
      if(!method1116(var0)) {
         var0.tryLoadFile_base(var1, var2);
         return null;
      } else {
         byte[] var3 = var0.takeFile_base(var1, var2);
         return var3 == null?null:new VorbisSample(var3);
      }
   }
}
