runTransmission ::
     RandomGen g => Options -> TransmissionM Builder a -> g -> Builder
runTransmission opts tr g = snd $ evalRWS (iterM run tr) () g
  where
    run (Transmit x f) = tell x *> f
    run (Noise x f) =
      state (pcmNoise (optSampleRate opts) (optNoiseVolume opts) x) >>= f
    run (RandDelayTime f) =
      state (randomR (optMinDelay opts, optMaxDelay opts)) >>= f
    run (Encode x f) = f $ pcmEncodeMessage (optSampleRate opts) x
runTransmission ::
     RandomGen g => Options -> TransmissionM Builder a -> g -> Builder
runTransmission opts tr g = snd $ evalRWS (iterM run tr) () g
  where
    run (Transmit x f) = tell x *> f
    run (Noise x f) =
      state (pcmNoise (optSampleRate opts) (optNoiseVolume opts) x) >>= f
    run (RandDelayTime f) =
      state (randomR (optMinDelay opts, optMaxDelay opts)) >>= f
    run (Encode x f) = f $ pcmEncodeMessage (optSampleRate opts) x
runTransmission opts tr g = snd $ evalRWS (iterM run tr) () g
  where
    run (Transmit x f) = tell x *> f
    run (Noise x f) =
      state (pcmNoise (optSampleRate opts) (optNoiseVolume opts) x) >>= f
    run (RandDelayTime f) =
      state (randomR (optMinDelay opts, optMaxDelay opts)) >>= f
    run (Encode x f) = f $ pcmEncodeMessage (optSampleRate opts) x