示例#1
0
        protected AudioFilter()
        {
            ID = alGenFilter();
            Audio.CheckALError("Could not create Filter");

            Audio.Filters.Add(this);
        }
示例#2
0
        public void Start()
        {
            if (Active)
            {
                alcCaptureStart(ptr);
                Audio.CheckALError("Could not start capture for CaptureDevice");

                IsRecording = true;
            }
        }
示例#3
0
        public void Stop()
        {
            if (Active)
            {
                alcCaptureStop(ptr);
                Audio.CheckALError("Could not stop capture for CaptureDevice");

                IsRecording = false;
            }
        }
示例#4
0
        public void Destroy()
        {
            if (Active)
            {
                Stop();

                alcCaptureCloseDevice(ptr);
                Audio.CheckALError("Could not close CaptureDevice");
                ptr = IntPtr.Zero;

                Audio.CaptureDevices.Remove(this);
            }
        }
示例#5
0
        internal AudioStream(AudioBuffer buffer, AudioSource source)
        {
            this.source = source;

            codec  = new AudioCodec(buffer.File);
            format = Audio.GetalBufferFormat(codec.Channels, codec.BitDepth);

            alGenBuffers(bufferIDs.Length, bufferIDs);
            Audio.CheckALError("Could not create Buffers");

            fillInitialBuffers();

            Audio.Streams.Add(this);
        }
示例#6
0
        internal void Destroy()
        {
            codec.Destroy();

            alDeleteBuffers(bufferIDs.Length, bufferIDs);
            Audio.CheckALError("Could not destroy Buffers");

            for (int i = 0; i < bufferIDs.Length; i++)
            {
                bufferIDs[i] = default;
            }

            Audio.Streams.Remove(this);
        }
示例#7
0
        public void Destroy()
        {
            for (int i = Sources.Count - 1; i >= 0; i--)
            {
                Sources[i].Buffer = null;
            }

            if (!Streamed)
            {
                alDeleteBuffer(ID);
                Audio.CheckALError("Could not destroy Buffer");
                ID = default;
            }

            Audio.Buffers.Remove(this);

            destroyed = true;
        }
示例#8
0
        public void Destroy()
        {
            for (int i = Sources.Count - 1; i >= 0; i--)
            {
                Sources[i].Filter = null;
            }

            for (int i = Channels.Count - 1; i >= 0; i--)
            {
                Channels[i].Filter = null;
            }

            alDeleteFilter(ID);
            Audio.CheckALError("Could not destroy Filter");
            ID = default;

            Audio.Filters.Remove(this);
        }
示例#9
0
        private void fillInitialBuffers()
        {
            for (int i = 0; i < bufferIDs.Length; i++)
            {
                byte[] bytes = codec.GetData(bufferSize, source.Looping);

                if (bytes.Length == 0)
                {
                    return;
                }

                alBufferData(bufferIDs[i], format, bytes, bytes.Length, codec.SampleRate);
                Audio.CheckALError("Could not set Buffer Data");

                alSourceQueueBuffers(source.ID, bufferIDs[i]);
                Audio.CheckALError("Could not queue Buffer");
            }
        }
示例#10
0
        public AudioBuffer(byte[] data, int channels, int bitDepth, int sampleRate)
        {
            File     = "";
            Streamed = false;

            ID = alGenBuffer();
            Audio.CheckALError("Could not create Buffer");

            Size    = data.Length;
            Samples = Size / channels / (bitDepth / 8);
            Length  = (float)Samples / sampleRate;

            // Debug
            //Output.WriteLine($"Buffer: Size: {Size} Samples: {Samples} sampleRate: {sampleRate} Length: {Length}s channels: {channels} bitDepth: {bitDepth}");

            alBufferData(ID, Audio.GetalBufferFormat(channels, bitDepth), data, data.Length, sampleRate);
            Audio.CheckALError("Could not set Buffer Data");

            Audio.Buffers.Add(this);
        }
示例#11
0
        internal void Update()
        {
            while (source.BuffersProcessed > 1)
            {
                alSourceUnqueueBuffers(source.ID, out uint bufferID);
                Audio.CheckALError("Could not unqueue Buffer");

                byte[] bytes = codec.GetData(bufferSize, source.Looping);

                if (bytes.Length == 0)
                {
                    continue;
                }

                alBufferData(bufferID, format, bytes, bytes.Length, codec.SampleRate);
                Audio.CheckALError("Could not set Buffer Data");

                alSourceQueueBuffers(source.ID, bufferID);
                Audio.CheckALError("Could not queue Buffer");
            }
        }
示例#12
0
        public AudioBuffer(string file, bool streamed = false)
        {
            if (!System.IO.File.Exists(file))
            {
                throw new FileNotFoundException("Audio file not found.", file);
            }

            File     = file;
            Streamed = streamed;

            if (Streamed)
            {
                AudioCodec codec = new AudioCodec(file);
                Size    = codec.Size;
                Samples = codec.Samples;
                Length  = codec.Length;
                codec.Destroy();
            }
            else
            {
                ID = alGenBuffer();
                Audio.CheckALError("Could not create Buffer");

                byte[] bytes = AudioCodec.Decode(file, out float length, out int channels, out int samples, out int sampleRate, out int bitDepth);
                Size    = bytes.Length;
                Samples = samples;
                Length  = length;

                alBufferData(ID, Audio.GetalBufferFormat(channels, bitDepth), bytes, bytes.Length, sampleRate);
                Audio.CheckALError("Could not set Buffer Data");
            }

            // Debug
            //Output.WriteLine($"Buffer: Size: {Size} Samples: {Samples} Length: {Length}s");

            Audio.Buffers.Add(this);
        }
示例#13
0
 public HighpassFilter() : base()
 {
     alFilteri(ID, AL_FILTER_TYPE, AL_FILTER_HIGHPASS);
     Audio.CheckALError("Could not set Filter Type");
     Apply();
 }
示例#14
0
 public EchoEffect() : base()
 {
     alEffecti(ID, AL_EFFECT_TYPE, AL_EFFECT_ECHO);
     Audio.CheckALError("Could not set Effect Type");
     Apply();
 }
示例#15
0
 private void UnqueueBuffers()
 {
     // This is more robust than alSourceUnqueueBuffers
     alSourcei(source.ID, alSourceiParameter.Buffer, AL_NONE);
     Audio.CheckALError("Could not set AudioSource.Buffer in AudioStream.UnqueueBuffers()");
 }
示例#16
0
 public ChorusEffect() : base()
 {
     alEffecti(ID, AL_EFFECT_TYPE, AL_EFFECT_CHORUS);
     Audio.CheckALError("Could not set Effect Type");
     Apply();
 }
示例#17
0
 public DistortionEffect() : base()
 {
     alEffecti(ID, AL_EFFECT_TYPE, AL_EFFECT_DISTORTION);
     Audio.CheckALError("Could not set Effect Type");
     Apply();
 }