예제 #1
0
        public async void PlayAsync(int loopCount = -1, int fadeOutTime = 2000)
        {
            await Task.Run(async() =>
            {
                CorePlayer.Play(loopCount, fadeOutTime);

                IsPlaying = true;
                while (true)
                {
                    CorePlayer.GetBuffer(_buffer);

                    if (!CorePlayer.IsPlaying || _cts.IsCancellationRequested)
                    {
                        break;
                    }

                    var b = ToByte(_buffer);


                    _bwp.AddSamples(b, 0, b.Length);

                    while (_bwp.BufferedBytes > _buffer.Length * 8)
                    {
                        await Task.Delay(1);
                    }
                }
                IsPlaying = false;
            });
        }
예제 #2
0
        public async Task SaveAsync(string path, int loopCount = 2, MidiFile mf = null)
        {
            CorePlayer.Stop();
            if (mf != null)
            {
                CorePlayer.Load(mf);
            }
            CorePlayer.Play(loopCount);

            using (var wfw = new WaveFileWriter(path, new WaveFormat()))
            {
                while (CorePlayer.IsPlaying)
                {
                    byte[] b = ToByte(CorePlayer.GetBuffer(_buffer));
                    await wfw.WriteAsync(b, 0, b.Length);
                }
            }
        }