Esempio n. 1
0
            /// <summary>Reads bytes from this wave stream</summary>
            /// <param name="buffer">buffer to read into</param>
            /// <param name="offset">offset into buffer</param>
            /// <param name="count">number of bytes required</param>
            /// <returns>Number of bytes read.</returns>
            /// <exception cref="T:System.ArgumentException">Thrown if an invalid number of bytes requested</exception>
            public int Read(byte[] buffer, int offset, int count)
            {
                if (count % this.m_bytesPerSample != 0)
                {
                    throw new ArgumentException("Must read an whole number of samples", nameof(count));
                }
                Array.Clear((Array)buffer, offset, count);
                int val1 = 0;

                byte[] numArray = new byte[count];
                lock (this.m_inputs)
                {
                    var node = this.m_inputs.First;
                    while (node != null)
                    {
                        int num = node.Value.Read(numArray, 0, count);
                        val1 = Math.Max(val1, num);
                        if (num > 0)
                        {
                            Mixer32.Sum32BitAudio(buffer, offset, numArray, num);
                        }
                        else
                        {
                            // Input exhaustion.  We should remove and dispose if we can.
                            this.m_inputs.Remove(node);
                            if (this.DisposeInputOnCompletion && node.Value is IDisposable x)
                            {
                                x.Dispose();
                            }
                        }
                        node = node.Next;
                    }
                }
                return(val1);
            }
Esempio n. 2
0
        public static void Dispose()
        {
            if (mp3Channel != null)
            {
                mp3Channel.Dispose();
            }
            DisposeVST();

            if (UsedLibrary == AudioLibrary.NAudio)
            {
                Samples.Clear();
                if (playbackDevice != null)
                {
                    playbackDevice.Stop();
                    playbackDevice.Dispose();
                    playbackDevice = null;
                }

                if (Mixer32 != null)
                {
                    Mixer32.Dispose(); Mixer32 = null;
                }
            }
            UsedLibrary = AudioLibrary.Null;
        }
Esempio n. 3
0
 public SimpleAudioPlayer(int deviceNumber = 0)
 {
     this.m_waveOut = new WaveOut
     {
         DeviceNumber = deviceNumber
     };
     this.m_mixer = new Mixer32(true);
     this.m_waveOut.Init(this.m_mixer);
     this.m_waveOut.PlaybackStopped += this.OnPlaybackStopped;
 }
Esempio n. 4
0
        public static void DisposeVST()
        {
            if (Mixer32 != null)
            {
                Mixer32.RemoveInputStream(vstStream);
            }

            if (vstStream != null)
            {
                vstStream.Dispose();
            }
            vstStream = null;

            if (GeneralVST != null)
            {
                GeneralVST.DisposeVST();
            }
            GeneralVST = null;
        }