package mapped;

import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSPcmStream;
import net.runelite.rs.api.RSPcmStreamMixer;

@ObfuscatedName("bn")
public class PcmStreamMixer extends PcmStream implements RSPcmStreamMixer {
   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "Lon;"
   )
   NodeDeque subStreams;
   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "Lon;"
   )
   NodeDeque field243;
   @ObfuscatedName("ar")
   int field242;
   @ObfuscatedName("ao")
   int field244;

   public PcmStreamMixer() {
      this.subStreams = new NodeDeque();
      this.field243 = new NodeDeque();
      this.field242 = 0;
      this.field244 = -1;
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(Lbk;)V"
   )
   public final synchronized void method713(PcmStream var1) {
      this.subStreams.method7261(var1);
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(Lbk;)V"
   )
   public final synchronized void method745(PcmStream var1) {
      var1.remove_base();
   }

   @ObfuscatedName("ar")
   void method715_base() {
      if(this.field242 > 0) {
         for(PcmStreamMixerListener var1 = (PcmStreamMixerListener)this.field243.method7265(); var1 != null; var1 = (PcmStreamMixerListener)this.field243.method7235()) {
            var1.field385 -= this.field242;
         }

         this.field244 -= this.field242;
         this.field242 = 0;
      }

   }

   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "(Lsh;Lcx;)V"
   )
   void method716(Node var1, PcmStreamMixerListener var2) {
      while(this.field243.sentinel != var1 && ((PcmStreamMixerListener)var1).field385 <= var2.field385) {
         var1 = var1.previous;
      }

      NodeDeque.method7230(var2, var1);
      this.field244 = ((PcmStreamMixerListener)this.field243.sentinel.previous).field385;
   }

   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "(Lcx;)V"
   )
   void method717(PcmStreamMixerListener var1) {
      var1.remove_base();
      var1.remove2_base();
      Node var2 = this.field243.sentinel.previous;
      if(var2 == this.field243.sentinel) {
         this.field244 = -1;
      } else {
         this.field244 = ((PcmStreamMixerListener)var2).field385;
      }

   }

   @ObfuscatedName("au")
   @ObfuscatedSignature(
      descriptor = "()Lbk;"
   )
   protected PcmStream vmethod6210() {
      return (PcmStream)this.subStreams.method7265();
   }

   @ObfuscatedName("aa")
   @ObfuscatedSignature(
      descriptor = "()Lbk;"
   )
   protected PcmStream vmethod6222() {
      return (PcmStream)this.subStreams.method7235();
   }

   @ObfuscatedName("ac")
   protected int vmethod6210_base() {
      return 0;
   }

   @ObfuscatedName("al")
   public final synchronized void fill_base(int[] var1, int var2, int var3) {
      do {
         if(this.field244 < 0) {
            this.updateSubStreams_base(var1, var2, var3);
            return;
         }

         if(var3 + this.field242 < this.field244) {
            this.field242 += var3;
            this.updateSubStreams_base(var1, var2, var3);
            return;
         }

         int var4 = this.field244 - this.field242;
         this.updateSubStreams_base(var1, var2, var4);
         var2 += var4;
         var3 -= var4;
         this.field242 += var4;
         this.method715_base();
         PcmStreamMixerListener var5 = (PcmStreamMixerListener)this.field243.method7265();
         synchronized(var5) {
            int var7 = var5.update_base();
            if(var7 < 0) {
               var5.field385 = 0;
               this.method717(var5);
            } else {
               var5.field385 = var7;
               this.method716(var5.previous, var5);
            }
         }
      } while(var3 != 0);

   }

   @ObfuscatedName("az")
   void updateSubStreams_base(int[] var1, int var2, int var3) {
      for(PcmStream var4 = (PcmStream)this.subStreams.method7265(); var4 != null; var4 = (PcmStream)this.subStreams.method7235()) {
         var4.update_base(var1, var2, var3);
      }

   }

   @ObfuscatedName("ap")
   public final synchronized void skip_base(int var1) {
      do {
         if(this.field244 < 0) {
            this.skipSubStreams_base(var1);
            return;
         }

         if(this.field242 + var1 < this.field244) {
            this.field242 += var1;
            this.skipSubStreams_base(var1);
            return;
         }

         int var2 = this.field244 - this.field242;
         this.skipSubStreams_base(var2);
         var1 -= var2;
         this.field242 += var2;
         this.method715_base();
         PcmStreamMixerListener var3 = (PcmStreamMixerListener)this.field243.method7265();
         synchronized(var3) {
            int var5 = var3.update_base();
            if(var5 < 0) {
               var3.field385 = 0;
               this.method717(var3);
            } else {
               var3.field385 = var5;
               this.method716(var3.previous, var3);
            }
         }
      } while(var1 != 0);

   }

   @ObfuscatedName("av")
   void skipSubStreams_base(int var1) {
      for(PcmStream var2 = (PcmStream)this.subStreams.method7265(); var2 != null; var2 = (PcmStream)this.subStreams.method7235()) {
         var2.skip_base(var1);
      }

   }

   public void addSubStream(RSPcmStream var1) {
      this.method713((PcmStream)var1);
   }
}
