public void CheckMultiSourceRandomSeeking()
        {
            var stream1 = new SineGeneratorStream(44100, 440, new TimeSpan(0, 0, 1));
            var stream2 = new SineGeneratorStream(44100, 440, new TimeSpan(0, 0, 1));
            var cc      = new ConcatenationStream(stream1, stream2);

            int seekOffset = 200 * stream1.SampleBlockSize;

            // Check seek into first segment
            cc.Position = seekOffset;
            Assert.AreEqual(seekOffset, cc.Position);
            var bytesRead = StreamUtil.ReadAllAndCount(cc);

            Assert.AreEqual(cc.Length - seekOffset, bytesRead);

            // Check seek into second segment
            cc.Position = stream1.Length + seekOffset;
            Assert.AreEqual(stream1.Length + seekOffset, cc.Position);
            bytesRead = StreamUtil.ReadAllAndCount(cc);
            Assert.AreEqual(cc.Length - stream1.Length - seekOffset, bytesRead);

            // Check seek back into first segment
            cc.Position = seekOffset;
            Assert.AreEqual(seekOffset, cc.Position);
            bytesRead = StreamUtil.ReadAllAndCount(cc);
            Assert.AreEqual(cc.Length - seekOffset, bytesRead);
        }
        public void CheckMultiSourceSeekToEnd()
        {
            var stream1 = new SineGeneratorStream(44100, 440, new TimeSpan(0, 0, 1));
            var stream2 = new SineGeneratorStream(44100, 440, new TimeSpan(0, 0, 1));
            var cc      = new ConcatenationStream(stream1, stream2);

            // Seek to the end where zero bytes are expected to be read
            cc.Position = cc.Length;
            var bytesRead = StreamUtil.ReadAllAndCount(cc);

            Assert.AreEqual(0, bytesRead);
        }
        public void CheckSingleSourceLength()
        {
            var stream = new SineGeneratorStream(44100, 440, new TimeSpan(0, 0, 1));
            var cc     = new ConcatenationStream(stream);

            // Ensure that the lengths match
            Assert.AreEqual(stream.Length, cc.Length);

            var bytesRead = StreamUtil.ReadAllAndCount(cc);

            // Ensure that the read bytes equals the length
            Assert.AreEqual(stream.Length, bytesRead);
        }
Beispiel #4
0
        public IAudioStream CreateAudioStream()
        {
            IAudioStream stream = null;

            if (MultiFile)
            {
                stream = new ConcatenationStream(FileInfos.Select(fi => AudioStreamFactory.FromFileInfoIeee32(fi)).ToArray());
            }
            else
            {
                stream = AudioStreamFactory.FromFileInfoIeee32(FileInfo);
            }
            return(new TimeWarpStream(stream, timeWarps));
        }
        public void CheckSingleSourceSeeking()
        {
            var stream = new SineGeneratorStream(44100, 440, new TimeSpan(0, 0, 1));
            var cc     = new ConcatenationStream(stream);

            int seek = 200 * stream.SampleBlockSize;

            cc.Position = seek;

            // Ensure that the position is correct
            Assert.AreEqual(seek, cc.Position);

            var bytesRead = StreamUtil.ReadAllAndCount(cc);

            // Ensure that the expected remaining bytes match the seek position
            Assert.AreEqual(cc.Length - seek, bytesRead);
        }
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker     = sender as BackgroundWorker;
            Parameters       parameters = (Parameters)e.Argument;

            var streams = parameters.SourceFiles.Select(fi => AudioStreamFactory.FromFileInfo(fi));

            // load source stream
            var sourceStream = new ConcatenationStream(streams.ToArray());

            var    firstFile            = parameters.SourceFiles.First();
            string targetFileNamePrefix = firstFile.FullName.Remove(firstFile.FullName.Length - firstFile.Extension.Length);
            string targetFileNameSuffix = firstFile.Extension;

            int        partCount  = 0;
            Random     random     = new Random();
            CropStream cropStream = new CropStream(sourceStream, 0, 0);

            while (sourceStream.Position < sourceStream.Length)
            {
                partCount++;
                int  length     = random.Next(parameters.MinLength, parameters.MaxLength); // length in seconds of the current part to write
                long byteLength = TimeUtil.TimeSpanToBytes(new TimeSpan(TimeUtil.SECS_TO_TICKS * length), cropStream.Properties);

                Debug.WriteLine("writing part " + partCount + " (" + length + " secs = " + byteLength + " bytes)");
                Debug.WriteLine("before: " + cropStream.Begin + " / " + cropStream.End + " / " + cropStream.Position + " / " + sourceStream.Position);
                cropStream.Begin    = cropStream.End;
                cropStream.End     += sourceStream.Length - cropStream.Begin < byteLength ? sourceStream.Length - cropStream.Begin : byteLength;
                cropStream.Position = 0;
                Debug.WriteLine("after : " + cropStream.Begin + " / " + cropStream.End + " / " + cropStream.Position + " / " + sourceStream.Position);
                AudioStreamFactory.WriteToFile(cropStream, String.Format("{0}.part{1:000}{2}", targetFileNamePrefix, partCount, targetFileNameSuffix));

                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    Debug.WriteLine("canceled");
                    return;
                }
                worker.ReportProgress((int)((double)sourceStream.Position / sourceStream.Length * 100));
            }
            Debug.WriteLine("finished");
        }
 public void CheckMultiSourceMatchingFormat()
 {
     var stream1 = new SineGeneratorStream(44100, 440, new TimeSpan(0, 0, 1));
     var stream2 = new SineGeneratorStream(96000, 440, new TimeSpan(0, 0, 1));
     var cc      = new ConcatenationStream(stream1, stream2);
 }