コード例 #1
0
        public IWavePlayer CreateDevice(int latency)
        {
            IWavePlayer          device;
            WaveCallbackStrategy strategy = _waveOutSettingsPanel.CallbackStrategy;

            if (strategy == WaveCallbackStrategy.Event)
            {
                WaveOutEvent waveOut = new WaveOutEvent
                {
                    DeviceNumber   = _waveOutSettingsPanel.SelectedDeviceNumber,
                    DesiredLatency = latency
                };
                device = waveOut;
            }
            else
            {
                WaveCallbackInfo callbackInfo = strategy == WaveCallbackStrategy.NewWindow ? WaveCallbackInfo.NewWindow() : WaveCallbackInfo.FunctionCallback();
                WaveOut          outputDevice = new WaveOut(callbackInfo)
                {
                    DeviceNumber   = _waveOutSettingsPanel.SelectedDeviceNumber,
                    DesiredLatency = latency
                };
                device = outputDevice;
            }
            // TODO: configurable number of buffers

            return(device);
        }
コード例 #2
0
ファイル: WaveOutPlugin.cs プロジェクト: suterma/Replayer
        /// <summary>
        /// Creates the device.
        /// </summary>
        /// <param name="latency">The latency.</param>
        /// <returns></returns>
        public IWavePlayer CreateDevice(int latency)
        {
            IWavePlayer device;
            //Existing Window is the default, probably most suitable for Replayer.
            WaveCallbackStrategy strategy     = WaveCallbackStrategy.ExistingWindow;
            WaveCallbackInfo     callbackInfo = strategy == WaveCallbackStrategy.NewWindow ? WaveCallbackInfo.NewWindow() : WaveCallbackInfo.FunctionCallback();
            WaveOut outputDevice = new WaveOut(callbackInfo)
            {
                DeviceNumber   = waveOutSettingsPanel.SelectedDeviceNumber,
                DesiredLatency = latency
            };

            device = outputDevice;
            return(device);
        }
コード例 #3
0
ファイル: WaveCallbackInfo.cs プロジェクト: Punloeu/karaoke
 private WaveCallbackInfo(WaveCallbackStrategy strategy, IntPtr handle)
 {
     this.Strategy = strategy;
     this.Handle = handle;
 }
コード例 #4
0
 public WaveOutPlugin(WaveCallbackStrategy strategy, int selectedDevice)
 {
     SelectedDeviceNumber = selectedDevice;
     CallbackStrategy     = strategy;
 }
コード例 #5
0
ファイル: WaveCallbackInfo.cs プロジェクト: teetow/teevegas
 private WaveCallbackInfo(WaveCallbackStrategy strategy, IntPtr handle)
 {
     Strategy = strategy;
     Handle   = handle;
 }
コード例 #6
0
 private WaveCallbackInfo(WaveCallbackStrategy strategy, IntPtr handle)
 {
     this.Strategy = strategy;
     this.Handle   = handle;
 }
コード例 #7
0
 public CallbackComboItem(string text, WaveCallbackStrategy strategy)
 {
     Text     = text;
     Strategy = strategy;
 }
コード例 #8
0
 public CallbackComboItem(string text, WaveCallbackStrategy strategy)
 {
     this.Text = text;
     this.Strategy = strategy;
 }
コード例 #9
0
ファイル: WaveCallbackInfo.cs プロジェクト: teetow/teevegas
		private WaveCallbackInfo(WaveCallbackStrategy strategy, IntPtr handle)
		{
			Strategy = strategy;
			Handle = handle;
		}
コード例 #10
0
        public void Play()
        {
            if (String.IsNullOrEmpty(AudioFile) || !System.IO.File.Exists(AudioFile))
            {
                OnOpenFileClick(null, null);
            }

            if (String.IsNullOrEmpty(AudioFile))
            {
                return;
            }

            switch (Preferences.OutputDevice)
            {
            case "WaveOut":
                for (int deviceId = 0; deviceId < WaveOut.DeviceCount; deviceId++)
                {
                    var capabilities = WaveOut.GetCapabilities(deviceId);
                }

                WaveCallbackStrategy strategy = WaveCallbackStrategy.NewWindow;
                if (Preferences.WaveOutCallback == "Function")
                {
                    strategy = WaveCallbackStrategy.FunctionCallback;
                }
                if (Preferences.WaveOutCallback == "Window")
                {
                    strategy = WaveCallbackStrategy.NewWindow;
                }
                if (Preferences.WaveOutCallback == "Event")
                {
                    strategy = WaveCallbackStrategy.Event;
                }

                m_SelectedOutputDevicePlugin = new WaveOutPlugin(strategy, Preferences.WaveOutDevice);

                break;

            case "WasapiOut":
                var endPoints = new MMDeviceEnumerator().EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active);
                m_SelectedOutputDevicePlugin = new WasapiOutPlugin(
                    endPoints[Preferences.WasapiOutDevice],
                    Preferences.WasapiOutExclusiveMode == "True" ? AudioClientShareMode.Exclusive : AudioClientShareMode.Shared,
                    Preferences.WasapiOutIsEventCallback == "True",
                    Preferences.RequestedLatency);

                break;

            case "NullOut":
                string output;
                string player = MainWindow.iniFile.GetString("Externals", "AudioPlayer", "C:\\Program Files (x86)\\AIMP2\\AIMP2.exe");
                if (!player.Contains(":"))
                {
                    //player = System.IO.Path.Combine(Environment.CurrentDirectory, player);
                }
                FileExecutionHelper.ExecutionHelper.RunCmdCommand(
                    "\"" + player + "\" " +
                    "\"" + AudioFile + "\"", out output, false, 1251);
                return;

            //break;
            case "DirectSound":
            default:
                m_SelectedOutputDevicePlugin = new DirectSoundOutPlugin();
                break;
            }



            if (!m_SelectedOutputDevicePlugin.IsAvailable)
            {
                MessageBox.Show("The selected output driver is not available on this system");
                return;
            }

            if (m_WaveOut != null)
            {
                if (m_WaveOut.PlaybackState == PlaybackState.Playing)
                {
                    return;
                }
                else if (m_WaveOut.PlaybackState == PlaybackState.Paused)
                {
                    System.Threading.Tasks.Task.Factory.StartNew(new Action(() =>
                    {
                        m_WaveOut.Play();
                    }));

                    return;
                }
            }

            // we are in a stopped state
            try
            {
                CreateWaveOut();

                m_DispatcherTimer.Start();

                Dispatcher.Invoke(delegate { LoadTrackTags(); });
            }
            catch (TagLib.CorruptFileException tagLibCorruptFileException)
            {
                Dispatcher.Invoke(delegate { TextBlockTrackTitle.Text = string.Format("{0}  {1}", System.IO.Path.GetFileName(AudioFile), tagLibCorruptFileException.Message); });
            }
            catch (Exception driverCreateException)
            {
                Core.CommandHelper.Log(String.Format("driverCreateException {0}", driverCreateException.Message));
                //MessageBox.Show(String.Format("driverCreateException {0}", driverCreateException.Message));
                return;
            }

            sampleProvider = null;
            try
            {
                sampleProvider = CreateInputStream(AudioFile);
            }
            catch (Exception createException)
            {
                Core.CommandHelper.Log(String.Format("createException {0}", createException.Message));
                //MessageBox.Show(String.Format("createException {0}", createException.Message), "Error Loading File");
                return;
            }

            try
            {
                //if (m_FadeInOutSampleProvider != null && !(audioFileReader is FlacReader))
                //    waveOut.Init(m_FadeInOutSampleProvider);
                //else
                m_WaveOut.Init(sampleProvider);
            }
            catch (Exception initException)
            {
                Core.CommandHelper.Log(String.Format("initException {0}", initException.Message));
                //MessageBox.Show(String.Format("initException {0}", initException.Message), "Error Initializing Output");
                return;
            }


            Dispatcher.Invoke(delegate { InvokeSetVolumeDelegate((float)SliderVolume.Value); });
            System.Threading.Tasks.Task.Factory.StartNew(new Action(() =>
            {
                m_WaveOut.Play();
                sampleAggregator = new SampleAggregator(fftDataSize);
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsPlaying"));
            }));

            //try
            //{
            //    System.Threading.Tasks.Task.Factory.StartNew(new Action(() =>
            //    {
            //        InitWaveformPainter(sampleProvider);
            //    }));

            //}
            //catch (Exception waveFormException)
            //{
            //    MessageBox.Show(String.Format("waveFormException {0}", waveFormException.Message), "Error Initializing Output");
            //    return;
            //}
        }