Files
raton4.0-source/Raton RAT/AudioPlayer.cs
T
2026-08-27 11:23:13 -06:00

92 lines
2.7 KiB
C#

// Decompiled with JetBrains decompiler
// Type: AudioPlayer
// Assembly: Raton, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 36C4E416-7F8D-4D23-930F-B5CCB0D810E7
// Assembly location: C:\Users\user\Desktop\v3.8.0 Deluxe Plugins (v4.0.0) cracked\Raton.exe
using NAudio.Wave;
using NAudio.Wave.SampleProviders;
using System;
using System.Collections.Generic;
#nullable disable
public static class AudioPlayer
{
private static readonly Dictionary<string, AudioPlayer.AudioStream> streams = new Dictionary<string, AudioPlayer.AudioStream>();
private static readonly object lockObj = new object();
private static readonly WaveFormat format = new WaveFormat(44100, 16 /*0x10*/, 1);
public static void Play(string uid, byte[] data, int length)
{
lock (AudioPlayer.lockObj)
{
AudioPlayer.AudioStream audioStream;
if (!AudioPlayer.streams.TryGetValue(uid, out audioStream))
{
try
{
audioStream = new AudioPlayer.AudioStream()
{
Buffer = new BufferedWaveProvider(AudioPlayer.format)
{
BufferDuration = TimeSpan.FromSeconds(20.0),
DiscardOnBufferOverflow = true
},
Mixer = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(AudioPlayer.format.SampleRate, AudioPlayer.format.Channels))
{
ReadFully = true
}
};
audioStream.SampleProvider = new Wave16ToFloatProvider((IWaveProvider) audioStream.Buffer).ToSampleProvider();
audioStream.Mixer.AddMixerInput(audioStream.SampleProvider);
audioStream.Output = new WaveOutEvent()
{
DesiredLatency = 100
};
audioStream.Output.Init((ISampleProvider) audioStream.Mixer);
audioStream.Output.Play();
AudioPlayer.streams[uid] = audioStream;
}
catch (Exception ex)
{
return;
}
}
try
{
audioStream.Buffer.AddSamples(data, 0, length);
}
catch (Exception ex)
{
}
}
}
public static void Remove(string uid)
{
lock (AudioPlayer.lockObj)
{
AudioPlayer.AudioStream audioStream;
if (!AudioPlayer.streams.TryGetValue(uid, out audioStream))
return;
try
{
audioStream.Output?.Stop();
audioStream.Output?.Dispose();
}
catch
{
}
AudioPlayer.streams.Remove(uid);
}
}
private class AudioStream
{
public BufferedWaveProvider Buffer;
public ISampleProvider SampleProvider;
public MixingSampleProvider Mixer;
public WaveOutEvent Output;
}
}