コード例 #1
0
        public void CantSetNonBlockAlignedDelayBySamples()
        {
            var source = new TestSampleProvider(32000, 2);
            var osp = new OffsetSampleProvider(source);

            var ex = Assert.Throws<ArgumentException>(() => osp.DelayBySamples = 3);
            Assert.That(ex.Message.Contains("DelayBySamples"));
        }
コード例 #2
0
        public void CanSkipOver()
        {
            var source = new TestSampleProvider(32000, 1);
            var osp = new OffsetSampleProvider(source) {SkipOverSamples = 17};

            var expected = new float[] { 17,18,19,20,21,22,23,24 };
            osp.AssertReadsExpected(expected);
        }
コード例 #3
0
        public void CanAddLeadOut()
        {
            var source = new TestSampleProvider(32000, 1, 10);
            var osp = new OffsetSampleProvider(source) {LeadOutSamples = 5};

            var expected = new float[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0 };
            osp.AssertReadsExpected(expected);
        }
コード例 #4
0
        public void SettingPreDelayUsingTimeSpanReturnsCorrectTimeSpan()
        {
            var source = new TestSampleProvider(100, 2) { Position = 10 };
            var osp = new OffsetSampleProvider(source) { DelayBy = TimeSpan.FromSeconds(2.5) };

            Assert.AreEqual(2500, (int) osp.DelayBy.TotalMilliseconds);
            Assert.AreEqual(500, osp.DelayBySamples);
        }
コード例 #5
0
        public void CanTake()
        {
            var source = new TestSampleProvider(32000, 1);
            var osp = new OffsetSampleProvider(source) {TakeSamples = 7};

            var expected = new float[] { 0, 1, 2, 3, 4, 5, 6 };
            osp.AssertReadsExpected(expected, 10);
        }
コード例 #6
0
 public void DefaultShouldPassStraightThrough()
 {
     var source = new TestSampleProvider(32000, 1);
     var osp = new OffsetSampleProvider(source);
     
     var expected = new float[] { 0, 1, 2, 3, 4, 5, 6 };
     osp.AssertReadsExpected(expected);
 }
コード例 #7
0
        public void CanAddPreDelay()
        {
            var source = new TestSampleProvider(32000, 1) {Position = 10};
            var osp = new OffsetSampleProvider(source) {DelayBySamples = 5};

            var expected = new float[] { 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15 };
            osp.AssertReadsExpected(expected);
        }
コード例 #8
0
        public void CanAddPreDelayUsingTimeSpan()
        {
            var source = new TestSampleProvider(100, 1) { Position = 10 };
            var osp = new OffsetSampleProvider(source) { DelayBy = TimeSpan.FromSeconds(1) };

            var expected = Enumerable.Range(0,100).Select(x => 0f)
                            .Concat(Enumerable.Range(10,10).Select(x => (float)x)).ToArray();
            osp.AssertReadsExpected(expected);
        }
コード例 #9
0
        public void CantSetLeadOutSamplesAfterCallingRead()
        {
            var source = new TestSampleProvider(32000, 1);
            var osp = new OffsetSampleProvider(source);
            var buffer = new float[10];
            osp.Read(buffer, 0, buffer.Length);

            Assert.Throws<InvalidOperationException>(() => osp.LeadOutSamples = 4);
        }
コード例 #10
0
 private static OffsetSampleProvider CreateSignalGenerator(int @from, int channels)
 {
     var signalGenerator = new SignalGenerator(@from, channels);
     signalGenerator.Type = SignalGeneratorType.SawTooth;
     signalGenerator.Frequency = 512;
     signalGenerator.Gain = 0.3f;
     var offset = new OffsetSampleProvider(signalGenerator);
     offset.TakeSamples = @from * channels * 5; // 5 seconds
     return offset;
 }
コード例 #11
0
 public RenderItemSampleProvider(RenderItem renderItem)
 {
     this.RenderItem = renderItem;
     var cachedSampleProvider = new CachedSoundSampleProvider(RenderItem.Sound);
     var offsetSampleProvider = new OffsetSampleProvider(new EnvelopeSampleProvider(cachedSampleProvider, RenderItem.Envelope, RenderItem.SkipOver))
     {
         DelayBySamples = (int)(RenderItem.PosMs * cachedSampleProvider.WaveFormat.SampleRate / 1000),
         TakeSamples = (int)(RenderItem.DurMs * cachedSampleProvider.WaveFormat.SampleRate / 1000),
         SkipOverSamples = (int)(RenderItem.SkipOver * cachedSampleProvider.WaveFormat.SampleRate / 1000)
     };
     this.signalChain = offsetSampleProvider;
     this.firstSample = offsetSampleProvider.DelayBySamples + offsetSampleProvider.SkipOverSamples;
     this.lastSample = this.firstSample + offsetSampleProvider.TakeSamples;
 }
コード例 #12
0
        public void CanTakeThirtySeconds()
        {
            var source = new TestSampleProvider(16000, 1);
            var osp = new OffsetSampleProvider(source) { Take = TimeSpan.FromSeconds(30) };
            var buffer = new float[16000];
            var totalRead = 0;
            while (true)
            {
                var read = osp.Read(buffer, 0, buffer.Length);
                totalRead += read;
                if (read == 0) break;
                Assert.IsTrue(totalRead <= 480000);

            }
            Assert.AreEqual(480000, totalRead);
        }
コード例 #13
0
 public void PlaySound(string sound, TimeSpan offset, TimeSpan length)
 {
     _Dispatcher.Invoke(new Action(() => {
         _output.Dispose();
         _output = new WaveOut();
     }));
     if (File.Exists("sounds\\"+sound))
     {
         var ac = new Action(() =>
         {
         //WaveOut _output = new WaveOut();
         _output.Stop();
             var file = new AudioFileReader("sounds\\" + sound);
             var trimmer = new OffsetSampleProvider(file);
             trimmer.SkipOver = (offset);
             if (length != TimeSpan.MaxValue)
                 trimmer.Take = (length);
             _output.Init(trimmer);
             _output.Play();
         });
         //{ Priority= ThreadPriority.Highest }.Start();
         _Dispatcher.BeginInvoke(ac);
     }
 }
コード例 #14
0
        public void HandlesSkipOverEntireSourceCorrectly()
        {
            var source = new TestSampleProvider(32000, 1, 10);
            var osp = new OffsetSampleProvider(source);
            osp.SkipOverSamples = 20;

            var expected = new float[] { };
            osp.AssertReadsExpected(expected, 20);
        }
コード例 #15
0
 private void buttonSave_Click(object sender, EventArgs e)
 {
     btnStop_Click(this,e);
     var sfd = new SaveFileDialog();
     sfd.Filter = "WAV File|*.wav";
     if (sfd.ShowDialog() == DialogResult.OK)
     {
         var osp = new OffsetSampleProvider(wg);
         osp.TakeSamples = wg.WaveFormat.SampleRate*20*wg.WaveFormat.Channels;
         WaveFileWriter.CreateWaveFile16(sfd.FileName, osp);
     }
 }
コード例 #16
0
 /// <summary>
 /// Concatenates one Sample Provider on the end of another with silence inserted
 /// </summary>
 /// <param name="sampleProvider">The sample provider to play first</param>
 /// <param name="silenceDuration">Silence duration to insert between the two</param>
 /// <param name="next">The sample provider to play next</param>
 /// <returns>A single sample provider</returns>
 public static ISampleProvider FollowedBy(this ISampleProvider sampleProvider, TimeSpan silenceDuration, ISampleProvider next)
 {
     var silenceAppended = new OffsetSampleProvider(sampleProvider) {LeadOut = silenceDuration};
     return new ConcatenatingSampleProvider(new[] { silenceAppended, next });
 }
コード例 #17
0
        public void CanFollowTakeWithLeadout()
        {
            var source = new TestSampleProvider(32000, 1) { Position = 10 };
            var osp = new OffsetSampleProvider(source) { TakeSamples = 10, LeadOutSamples = 5};

            
            var expected = new float[] { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 0, 0, 0, 0 };
            osp.AssertReadsExpected(expected);
        }
コード例 #18
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var file = new AudioFileReader(FileName);
            var trimmed = new OffsetSampleProvider(file);
            trimmed.SkipOver = pwfc.SelectionStart;
            trimmed.Take = pwfc.SelectionEnd - pwfc.SelectionStart;

            WaveFileWriter.CreateWaveFile(@"c:\temp\trimmed.wav", new SampleToWaveProvider(trimmed));
            pwfc.ClearWaveForm();

            FileName = @"c:\temp\trimmed.wav";
            LoadSound(sound0, 0);

            var player = new WaveOutEvent();
            player.Init(trimmed);
            player.Play();
        }
コード例 #19
0
        private void pwfc_MouseUp(object sender, MouseButtonEventArgs e)
        {
            var file = new AudioFileReader(FileName);
            var trimmed = new OffsetSampleProvider(file);
            trimmed.SkipOver = pwfc.SelectionStart;
            trimmed.Take = TimeSpan.FromMilliseconds(Math.Abs(pwfc.SelectionEnd.TotalMilliseconds - pwfc.SelectionStart.TotalMilliseconds));

            //WaveFileWriter.CreateWaveFile(@"c:\temp\trimmed.wav", new SampleToWaveProvider(trimmed));
            new Task(() =>
            {
                var player = new WaveOutEvent();
                player.Init(trimmed);
                player.Play();
                while (player.PlaybackState != PlaybackState.Stopped)
                {
                    System.Threading.Thread.Sleep(100);
                }
                file.Close();
            }).Start();
        }
コード例 #20
0
 public void WaveFormatIsSampeAsSource()
 {
     var source = new TestSampleProvider(32000, 1, 10);
     var osp = new OffsetSampleProvider(source);
     Assert.AreEqual(source.WaveFormat, osp.WaveFormat);
 }
コード例 #21
0
        public void MaintainsTakeState()
        {
            var source = new TestSampleProvider(32000, 1);
            var osp = new OffsetSampleProvider(source) {TakeSamples = 15};

            var expected = new float[] { 0, 1, 2, 3, 4, 5, 6, 7 };
            osp.AssertReadsExpected(expected);
            var expected2 = new float[] { 8, 9, 10, 11, 12, 13, 14 };
            osp.AssertReadsExpected(expected2, 20);
        }
コード例 #22
0
        public void MaintainsPredelayState()
        {
            var source = new TestSampleProvider(32000, 1) {Position = 10};
            var osp = new OffsetSampleProvider(source) {DelayBySamples = 10};

            var expected = new float[] {0, 0, 0, 0, 0,};
            osp.AssertReadsExpected(expected);
            var expected2 = new float[] {0, 0, 0, 0, 0,};
            osp.AssertReadsExpected(expected2);
            var expected3 = new float[] {10, 11, 12, 13, 14, 15};
            osp.AssertReadsExpected(expected3);
        }
コード例 #23
0
        public void LeadOutWithoutTakeOnlyBeginsAfterSourceIsCompletelyRead()
        {
            var source = new TestSampleProvider(32000, 1, 10);
            var osp = new OffsetSampleProvider(source) { LeadOutSamples = 5 };

            var expected = new float[] { 0, 1, 2, 3, 4, 5, 6 };
            osp.AssertReadsExpected(expected, 7);
            var expected2 = new float[] { 7, 8, 9, 0, 0, 0 };
            osp.AssertReadsExpected(expected2, 6);
            var expected3 = new float[] { 0, 0 };
            osp.AssertReadsExpected(expected3, 6);
        }