示例#1
0
        public void Dispose()
        {
            if (_device != null)
            {
                _device.Stop();
                _device.Dispose();
                _device = null;
            }
            if (_waveStream != null)
            {
                _waveStream.Close();
                _waveStream = null;
            }

            GC.Collect();
        }
 public void Close()
 {
     if (asio.PlaybackState != PlaybackState.Stopped)
     {
         asio.Stop();
     }
     asio.Dispose();
 }
示例#3
0
文件: Audio.cs 项目: LastExceed/Minia
 internal static void Abort()
 {
     asioOut.Stop();
     asioOut.Dispose();
     music.Dispose();
     hit.Dispose();
     miss.Dispose();
 }
示例#4
0
        private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
        {
            audioOutput.Stop();
            audioOutput.Dispose();

            if (midiIn != default(MidiIn))
            {
                midiIn.Stop();
                midiIn.Dispose();
            }
        }
 private void Stop()
 {
     if (running)
     {
         asioOut.Stop();
         asioOut.Dispose();
         asioOut             = null;
         running             = false;
         buttonBegin.Content = "Begin";
     }
 }
 public void StopRecord()
 {
     if (_asioOut == null)
     {
         return;
     }
     _asioOut.Stop();
     _cancellationTokenSource.Cancel();
     _recordTask.Wait();
     _asioOut.Dispose();
     _asioOut = null;
     _action  = null;
 }
示例#7
0
        private void button1_Click(object sender, EventArgs e)
        {
            //if (recorder != null)
            //{
            //    recorder.StopRecording();
            //    recorder.Dispose();
            //}

            if (asioDriver != null)
            {
                asioDriver.Stop();
                asioDriver.Dispose();
            }
        }
示例#8
0
        private void Stop()
        {
            asioOut.Stop();
            if (writer != null)
            {
                writer.Dispose();
                writer = null;
            }
            timer1.Enabled = false;
            SetButtonStates();
            int index = listBoxRecordings.Items.Add(fileName);

            listBoxRecordings.SelectedIndex = index;
        }
示例#9
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            FOutput.SliceCount = SpreadMax;

            if (FDriverIn.IsChanged)
            {
                CreateAsio();
                if (FPlayIn[0])
                {
                    FAsioOut.Play();
                }
            }

            if (FShowPanelIn[0])
            {
                FAsioOut.ShowControlPanel();
            }

            if (FWave != FWaveIn[0])
            {
                FWave = FWaveIn[0];
                CreateAsio();
                if (FPlayIn[0])
                {
                    FAsioOut.Play();
                }
            }

            if (FPlayIn.IsChanged)
            {
                if (FPlayIn[0])
                {
                    FAsioOut.Play();
                }
                else
                {
                    FAsioOut.Stop();
                }
            }
        }
示例#10
0
        public static void Main(string[] args)
        {
            var names = AsioOut.GetDriverNames();

            var asioDriverName = names[0];

            Console.WriteLine("Selected ASIO driver: {0}", asioDriverName);

            var asioOut = new AsioOut(asioDriverName);

            //var inputChannels = asioOut.DriverInputChannelCount;
            asioOut.InputChannelOffset = 0;
            asioOut.InitRecordAndPlayback(null, 1, SampleRate);
            asioOut.AudioAvailable += OnAsioOutAudioAvailable;
            var soundProcessTask = Task.Run(ProcessAudioData, CancellationTokenSource.Token)
                                   .ContinueWith(t =>
            {
                t.Exception?.Handle(e => true);
                Console.WriteLine("You have canceled the Sound Process task");
            }, TaskContinuationOptions.OnlyOnCanceled);
            var playerTask = Task.Run(PlayAlarm, CancellationTokenSource.Token)
                             .ContinueWith(t =>
            {
                t.Exception?.Handle(e => true);
                Console.WriteLine("You have canceled the PlayAlarm task");
            }, TaskContinuationOptions.OnlyOnCanceled);

            ;
            asioOut.Play(); // start recording
            Console.WriteLine("Press ENTER to exit");
            Console.ReadLine();

            asioOut.Stop();
            CancellationTokenSource.Cancel();

            Task.WaitAll(soundProcessTask, playerTask);
        }
示例#11
0
 public static void Dispose()
 {
     waveOut.Stop();
 }
示例#12
0
        /// <summary>
        /// コールバックの中から呼び出さないこと(ハングします)
        /// </summary>
        public static void Stop()
        {
            if (waveOut != null)
            {
                try
                {
                    //waveOut.Pause();
                    waveOut.Stop();
                    while (waveOut.PlaybackState != PlaybackState.Stopped)
                    {
                        System.Threading.Thread.Sleep(1);
                    }
                    waveOut.Dispose();
                }
                catch { }
                waveOut = null;
            }

            if (wasapiOut != null)
            {
                try
                {
                    //wasapiOut.Pause();
                    wasapiOut.Stop();
                    while (wasapiOut.PlaybackState != PlaybackState.Stopped)
                    {
                        System.Threading.Thread.Sleep(1);
                    }
                    wasapiOut.Dispose();
                }
                catch { }
                wasapiOut = null;
            }

            if (dsOut != null)
            {
                try
                {
                    //dsOut.Pause();
                    dsOut.Stop();
                    while (dsOut.PlaybackState != PlaybackState.Stopped)
                    {
                        System.Threading.Thread.Sleep(1);
                    }
                    dsOut.Dispose();
                }
                catch { }
                dsOut = null;
            }

            if (asioOut != null)
            {
                try
                {
                    //asioOut.Pause();
                    asioOut.Stop();
                    while (asioOut.PlaybackState != PlaybackState.Stopped)
                    {
                        System.Threading.Thread.Sleep(1);
                    }
                    asioOut.Dispose();
                }
                catch { }
                asioOut = null;
            }

            if (nullOut != null)
            {
                try
                {
                    nullOut.Stop();
                    while (nullOut.PlaybackState != PlaybackState.Stopped)
                    {
                        Thread.Sleep(1);
                    }
                    nullOut.Dispose();
                }
                catch { }
                nullOut = null;
            }

            //一休み
            //for (int i = 0; i < 10; i++)
            //{
            //    System.Threading.Thread.Sleep(1);
            //    System.Windows.Forms.Application.DoEvents();
            //}
        }
示例#13
0
 public void Stop()
 {
     AsioOut.Stop();
 }
示例#14
0
 private void Form1_FormClosed(object sender, FormClosedEventArgs e)
 {
     audioOutput.Stop();
 }
示例#15
0
        private void RunGenerator()
        {
            var timer = new DispatcherTimer {
                Interval = TimeSpan.FromMilliseconds(1)
            };

            List <Cell> .Enumerator enumerator = new List <Cell> .Enumerator();

            _state = State.Initializing;
            timer.Start();
            timer.Tick += (sender, args) =>
            {
                if (_state == State.Initializing)
                {
                    Generator      = _generators[_currentGeneratorIndex];
                    StepCount      = 0;
                    timer.Interval = TimeSpan.FromMilliseconds(Generator.RecommendedTimeStep);
                    _state         = State.Running;
                }
                if (_state == State.Running)
                {
                    var currentCell = Generator.NextStep();
                    if (currentCell == null)
                    {
                        _state         = State.StartReset;
                        timer.Interval = TimeSpan.FromSeconds(1);
                        _sineWaveProvider.Frequency = 0;
                    }
                    else
                    {
                        _sineWaveProvider.Frequency = CellToFrequency(currentCell);
                        StepCount++;
                    }
                }
                else if (_state == State.StartReset)
                {
                    timer.Interval = TimeSpan.FromMilliseconds(0.5);
                    Generator.Steps.Reverse();
                    enumerator = Generator.Steps.GetEnumerator();
                    _state     = State.Resetting;
                }
                else if (_state == State.Resetting)
                {
                    while (enumerator.MoveNext())
                    {
                        if (enumerator.Current.CellState == CellState.Unvisited)
                        {
                            continue;
                        }

                        _sineWaveProvider.Frequency  = CellToFrequency(enumerator.Current);
                        enumerator.Current.CellState = CellState.Unvisited;
                        enumerator.Current.Walls     = Direction.East | Direction.North | Direction.South | Direction.West;
                        break;
                    }
                    if (enumerator.Current == null)
                    {
                        _state = State.FinishedReset;
                    }
                }
                else if (_state == State.FinishedReset)
                {
                    _sineWaveProvider.Frequency = 0;
                    timer.Interval = TimeSpan.FromSeconds(1);
                    _currentGeneratorIndex++;
                    _state = _currentGeneratorIndex == _generators.Count ? State.End : State.Initializing;
                }
                else if (_state == State.End)
                {
                    _asio.Stop();
                    //waveOut.Stop();
                    timer.Stop();
                }
            };
        }
示例#16
0
 private void Stop()
 {
     asioOut.Stop();
     timer1.Enabled = false;
     SetButtonStates();
 }
 public void Dispose()
 {
     _asioOut?.Stop();
 }
示例#18
0
        const int EXTRARECORDINGTIME = 10;// Extra recording time in seconds. Make sure we dont miss anything.

        private void processAudioFile()
        {
            goBtn.IsEnabled      = false;
            asioDevice.IsEnabled = false;

            bool fail = true;


            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title = "Select w64 file to process";

            if (ofd.ShowDialog() == true)
            {
                SaveFileDialog sfd = new SaveFileDialog();

                string suffix = "";


                sfd.FileName = ofd.FileName + ".ASIOLFLA" + suffix + ".w64";
                if (sfd.ShowDialog() == true)
                {
                    SuperWAV         inputAudio = new SuperWAV(ofd.FileName);
                    SuperWAV.WavInfo inInfo     = inputAudio.getWavInfo();

                    if (inInfo.channelCount != 2)
                    {
                        MessageBox.Show("Only files with a channel count of 2 supported.");
                    }
                    else
                    {
                        fail = false;

                        // Allocate an output file.
                        SuperWAV outputAudio = new SuperWAV(sfd.FileName, SuperWAV.WavFormat.WAVE64, inInfo.sampleRate, 2, inInfo.audioFormat, inInfo.bitsPerSample);

                        ConcurrentQueue <float[]> sampleBuffer = new ConcurrentQueue <float[]>();
                        float[] tmp;

                        bool processingActive = true;

                        UInt64 outputFileOffset = 0;

                        // Do actual processing.
                        AsioOut          asioOut        = new AsioOut(selectedAsioDevice);
                        SuperWAVProvider sampleProvider = new SuperWAVProvider(inputAudio);
                        IWaveProvider    waveProvider   = new SampleToWaveProvider(sampleProvider);
                        asioOut.InitRecordAndPlayback(waveProvider, 2, (int)inInfo.sampleRate);
                        asioOut.AudioAvailable += (object sender, AsioAudioAvailableEventArgs e) => {
                            sampleBuffer.Enqueue(e.GetAsInterleavedSamples());
                        };

                        _ = Task.Run(() => {
                            Task writerTask = Task.Run(() => {
                                float[] tmp2;
                                while (processingActive)
                                {
                                    while (sampleBuffer.Count > 0)
                                    {
                                        if (!processingActive)
                                        {
                                            break;
                                        }
                                        if (sampleBuffer.TryDequeue(out tmp2))
                                        {
                                            outputAudio.writeFloatArrayFast(tmp2, outputFileOffset);
                                            outputFileOffset += (ulong)tmp2.Length / 2;
                                        }
                                    }

                                    System.Threading.Thread.Sleep(10); // Just make sure we don't eat up all CPU with constant checks of the queue, pointless
                                }
                            });
                            // Progress updates
                            Task progressTask = Task.Run(() => {
                                while (processingActive)
                                {
                                    double progress = (double)sampleProvider.InputOffset / (inputAudio.DataLengthInTicks + inInfo.sampleRate * EXTRARECORDINGTIME);
                                    Dispatcher.Invoke(() => {
                                        progressBar.Value = progress * 100.0;
                                    });
                                    if (progress > 1.0)
                                    {
                                        processingActive = false;
                                        asioOut.Stop();
                                    }
                                    System.Threading.Thread.Sleep(100);
                                }
                            });
                            writerTask.Wait();
                            progressTask.Wait();
                            Dispatcher.Invoke(() => {
                                goBtn.IsEnabled      = true;
                                asioDevice.IsEnabled = true;
                            });
                        });


                        asioOut.Play(); // start recording
                    }
                }
            }



            if (fail)
            {
                goBtn.IsEnabled      = true;
                asioDevice.IsEnabled = true;
            }
        }
示例#19
0
 public void Stop()
 {
     driver.Stop();
 }
示例#20
0
        private void StartStopSineWave()
        {
            if (asioOut == null)
            {
                button1.Content = "Stop Sound";
                Console.WriteLine("User Selected Channels: " + selectedChannels);
                WaveOutCapabilities outdeviceInfo = WaveOut.GetCapabilities(0);
                waveOutChannels = outdeviceInfo.Channels;
                asioOut         = new AsioOut(0);

                int waveOutDevices = WaveOut.DeviceCount;
                for (int i = 0; i < waveOutDevices; i++)
                {
                    outdeviceInfo = WaveOut.GetCapabilities(i);
                    Console.WriteLine("Device {0}: {1}, {2} channels",
                                      i, outdeviceInfo.ProductName, outdeviceInfo.Channels);
                }

                List <IWaveProvider> inputs = new List <IWaveProvider>();
                frequencies = new List <int>();
                centerbins  = new List <int>();

                for (int c = 0; c < selectedChannels; c++)
                {
                    if (c != (selectedChannels - 1))
                    {
                        inputs.Add(new SineWaveProvider32(0, 0.25f, 44100, 1));
                        frequencies.Add(0);
                        centerbins.Add((int)Math.Round((0) / 10.768));
                    }
                    else
                    {
                        inputs.Add(new SineWaveProvider32(600, 0.25f, 44100, 1));
                        frequencies.Add(300);
                        centerbins.Add((int)Math.Round((600) / 10.768));
                    }
                }

                var splitter = new MultiplexingWaveProvider(inputs, selectedChannels);
                try
                {
                    asioOut.Init(splitter);
                    asioOut.Play();
                }
                catch (System.ArgumentException)
                {
                    Console.WriteLine("Invalid audio channel count. Please select a lower number of audio channels");
                }
                //waveOut = new WaveOut();
                //waveOut.Init(sineWaveProvider);
                //waveOut.Init(splitter);

                Console.WriteLine("Number of Channels: " + asioOut.NumberOfOutputChannels);
                Console.WriteLine("Playback Latency: " + asioOut.PlaybackLatency);
            }
            else
            {
                asioOut.Stop();
                asioOut.Dispose();
                asioOut         = null;
                button1.Content = "Start Sound";

                frequencies.Clear();
                centerbins.Clear();
                //Foutstream.Clear();
            }
        }