Write() public method

Add data to output buffer, sending to encoder when buffer full
public Write ( byte buffer, int offset, int count ) : void
buffer byte Source buffer
offset int Offset of data in buffer
count int Length of data
return void
        private void WriteFrame(FrameDecompressedEventArgs <Mp3Frame> e)
        {
            if (State != StreamRecorderStates.Recording)
            {
                return;
            }

            if (e.DecompressedDataLen <= 0)
            {
                return;
            }

            if (_mp3writer == null)
            {
                _mp3writer = new LameMP3FileWriter(
                    _fileStream,
                    e.DecompressedFormat,
                    e.Frame.BitRate,
                    new ID3TagData {
                    Title   = $"{e.StreamSource.DisplayName} ({DateTime.Now.ToString()})",
                    Comment = e.StreamSource.StreamUrl
                }
                    );
            }

            _mp3writer.Write(e.DecompressedData, 0, e.DecompressedDataLen);
        }
示例#2
0
        private void splitMp3(string trackPath, int startPos, int endPos, MediaFoundationReader reader, ID3TagData tagData)
        {
            int progress = 0;

            using (var writer = new NAudio.Lame.LameMP3FileWriter(trackPath, reader.WaveFormat, NAudio.Lame.LAMEPreset.V3, tagData))
            {
                reader.Position = startPos;
                byte[] buffer = new byte[1024];
                while (reader.Position < endPos)
                {
                    int bytesRequired = (int)(endPos - reader.Position);
                    if (bytesRequired > 0)
                    {
                        int bytesToRead = Math.Min(bytesRequired, buffer.Length);
                        int bytesRead   = reader.Read(buffer, 0, bytesToRead);
                        if (bytesRead > 0)
                        {
                            writer.Write(buffer, 0, bytesRead);
                            progress += bytesRead;
                        }
                    }
                }
            }
        }
示例#3
0
        internal static void CreateMp3File(string filename, IWaveProvider sourceProvider, int bitRate, Action<long> progressCallback)
        {
            Debug.Assert(progressCallback != null);

            using (var writer = new LameMP3FileWriter(filename, sourceProvider.WaveFormat, bitRate))
            {
                long outputLength = 0;
                var buffer = new byte[sourceProvider.WaveFormat.AverageBytesPerSecond * 4];
                while (true)
                {
                    int bytesRead = sourceProvider.Read(buffer, 0, buffer.Length);
                    if (bytesRead == 0)
                    {
                        // end of source provider
                        break;
                    }
                    outputLength += bytesRead;
                    // Write will throw exception if WAV file becomes too large
                    writer.Write(buffer, 0, bytesRead);

                    progressCallback(bytesRead);
                }
            }
        }