46 lines
832 B
C#
46 lines
832 B
C#
using System;
|
|
using OpenTK.Audio;
|
|
|
|
namespace AudioStreamer
|
|
{
|
|
public class OpenALSource : BaseAudioSource, AudioOutput
|
|
{
|
|
public event NewAudioAvailable NewAudioAvailable;
|
|
AudioCapture capture;
|
|
|
|
public OpenALSource()
|
|
{
|
|
if (AudioCapture.AvailableDevices.Count < 1){
|
|
throw new Exception("No Audio Device available");
|
|
}
|
|
|
|
capture = new AudioCapture(AudioCapture.DefaultDevice, 44100, OpenTK.Audio.OpenAL.ALFormat.Mono16, 8192);
|
|
}
|
|
|
|
public override void Start()
|
|
{
|
|
capture.Start();
|
|
}
|
|
|
|
public override void Stop()
|
|
{
|
|
capture.Stop();
|
|
}
|
|
|
|
public override void Source()
|
|
{
|
|
while (capture.AvailableSamples >= 64)
|
|
{
|
|
Int16[] chunk = new Int16[64];
|
|
capture.ReadSamples(chunk, 64);
|
|
|
|
if (NewAudioAvailable != null)
|
|
{
|
|
NewAudioAvailable.Invoke(this, chunk);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|