Beispiel #1
0
        public WaveformData For(Uri source)
        {
            var audioStream = _waveProviderFactory.Create(source);

            using (audioStream as IDisposable)
                return(Generate(audioStream));
        }
Beispiel #2
0
        private void CropToFile(CropAudioRequest message, string fileName)
        {
            var reader = _factory.Create(message.Selection.Source);

            using (reader as IDisposable)
                using (var writer = new LameMP3FileWriter(fileName, reader.WaveFormat, BitRate))
                {
                    var inputLength = (int)(message.Selection.Duration * reader.WaveFormat.AverageBytesPerSecond);
                    var bytesLeft   = inputLength;
                    var buffer      = new byte[reader.WaveFormat.AverageBytesPerSecond];
                    reader.CurrentTime = TimeSpan.FromSeconds(message.Selection.Start);
                    while (bytesLeft > 0)
                    {
                        var bytesRead = reader.Read(buffer, 0, Math.Min(buffer.Length, bytesLeft));
                        writer.Write(buffer, 0, bytesRead);
                        bytesLeft -= bytesRead;
                    }
                }

            _events.PublishOnUIThread(new CropAudioResponse(new Uri(fileName)));
        }