Exemple #1
0
        /// <summary>
        /// Writes to file.
        /// </summary>
        public void Write(byte[] Data, int Offset, int Count)
        {
            lock (_syncLock)
            {
                if (_riff && _writer.BaseStream.Length + Count > uint.MaxValue)
                {
                    throw new ArgumentException("WAV file too large", nameof(Count));
                }

                if (_encoder != null)
                {
                    _encoder.EnsureBufferIsSufficient(ref _encodedBuffer, Count);

                    var encodedLength = _encoder.Encode(Data, Offset, Count, _encodedBuffer, 0);

                    if (encodedLength <= 0)
                    {
                        return;
                    }

                    _writer.Write(_encodedBuffer, 0, encodedLength);
                    Length += encodedLength;
                }
                else
                {
                    _writer.Write(Data, Offset, Count);
                    Length += Count;
                }
            }
        }
        void AudioProviderOnDataAvailable(object Sender, DataAvailableEventArgs DataAvailableEventArgs)
        {
            _audioEncoder.EnsureBufferIsSufficient(ref _encodedBuffer, DataAvailableEventArgs.Length);

            var encodedLength = _audioEncoder.Encode(DataAvailableEventArgs.Buffer, 0, DataAvailableEventArgs.Length, _encodedBuffer, 0);

            DataAvailable?.Invoke(this, new DataAvailableEventArgs(_encodedBuffer, encodedLength));
        }