public static void InitializeAudioDevice(string device) { try { if (audioDevices.ContainsKey(device)) { selectedaudioDevices = (JObject)audioDevices[device]; } else { selectedaudioDevices = defaultAudio(); } BassWasapi.BASS_WASAPI_Stop(true); BassWasapi.BASS_WASAPI_Free(); Bass.BASS_Free(); Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero); BassWasapi.BASS_WASAPI_Init((int)selectedaudioDevices["id"], 0, 0, BASSWASAPIInit.BASS_WASAPI_BUFFER, 1f, 0.05f, ESPRGB._process, IntPtr.Zero); BassWasapi.BASS_WASAPI_Start(); } catch { selectedaudioDevices = defaultAudio(); BassWasapi.BASS_WASAPI_Stop(true); BassWasapi.BASS_WASAPI_Free(); Bass.BASS_Free(); Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero); BassWasapi.BASS_WASAPI_Init((int)selectedaudioDevices["id"], 0, 0, BASSWASAPIInit.BASS_WASAPI_BUFFER, 1f, 0.05f, ESPRGB._process, IntPtr.Zero); BassWasapi.BASS_WASAPI_Start(); } }
//Reinitializes active WASAPI device if necessary private void UpdateDevice() { if (WASAPIDeviceIndex == -1) { return; } if (deviceInitialized) { Console.WriteLine("Deinitializing WASAPI device"); BassWasapi.BASS_WASAPI_Stop(true); BassWasapi.BASS_WASAPI_Free(); deviceInitialized = false; } BASS_WASAPI_DEVICEINFO devInfo = BassWasapi.BASS_WASAPI_GetDeviceInfo(WASAPIDeviceIndex); if (devInfo == null) { throw new WASAPIInitializationException("Device " + WASAPIDeviceIndex + " is invalid!"); } if (!BassWasapi.BASS_WASAPI_Init(WASAPIDeviceIndex, devInfo.mixfreq, devInfo.mixchans, BASSWASAPIInit.BASS_WASAPI_AUTOFORMAT | BASSWASAPIInit.BASS_WASAPI_BUFFER, 0f, 0f, WasapiProc, IntPtr.Zero)) { BASSError error = Bass.BASS_ErrorGetCode(); throw new WASAPIInitializationException("Unable to initialize WASAPI device " + WASAPIDeviceIndex, error); } if (!BassWasapi.BASS_WASAPI_Start()) { BASSError error = Bass.BASS_ErrorGetCode(); throw new WASAPIInitializationException("Unable to start WASAPI!", error); } Console.WriteLine("WASAPI device initialized"); deviceNumber = WASAPIDeviceIndex; sampleFrequency = devInfo.mixfreq; BuildLookupTables(); deviceInitialized = true; }
public static void Stop() { // Stop WASAPI BassWasapi.BASS_WASAPI_SetDevice(InputDevice); BassWasapi.BASS_WASAPI_Stop(false); BassWasapi.BASS_WASAPI_SetDevice(OutputDevice); BassWasapi.BASS_WASAPI_Stop(false); }
public void Disable(ComboBox deviceList) { deviceList.IsEnabled = true; BassWasapi.BASS_WASAPI_Stop(true); BassWasapi.BASS_WASAPI_Free(); _initialized = false; _displayRefreshTimer.IsEnabled = false; }
private void ButtonSpectrumOff_Click(object sender, EventArgs e) { analyzer.Enable = false; analyzer.DisplayEnable = false; BassWasapi.BASS_WASAPI_Stop(true); ButtonSpectrumOn.Enabled = true; comboBox1.Enabled = true; timer1.Enabled = false; LabelValores.Text = " Me Me Me Me Me "; }
private BassEngine() { //Setup Bass bullshit BassNet.Registration("*****@*****.**", "2X1837515183722"); BassNet.OmitCheckVersion = true; Bass.LoadMe(); Bass.BASS_Init(0, 48000, 0, IntPtr.Zero); BassWasapi.LoadMe(); if (!Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_SPEAKERS, Process.GetCurrentProcess().MainWindowHandle)) { Console.WriteLine("Bass initialization error!"); } #region WASAPI int WASAPIDeviceIndex = -100; var devices = BassWasapi.BASS_WASAPI_GetDeviceInfos(); for (int i = 0; i < devices.Length; i++) { if (devices[i].IsEnabled && devices[i].SupportsRecording && devices[i].IsLoopback) { WASAPIDeviceIndex = i; break; } } if (WASAPIDeviceIndex != -100) { BASS_WASAPI_DEVICEINFO devInfo = devices[WASAPIDeviceIndex]; if (devInfo.IsInitialized) { Console.WriteLine("Deinitializing WASAPI device"); BassWasapi.BASS_WASAPI_Stop(true); BassWasapi.BASS_WASAPI_Free(); } if (!BassWasapi.BASS_WASAPI_Init(WASAPIDeviceIndex, devInfo.mixfreq, devInfo.mixchans, BASSWASAPIInit.BASS_WASAPI_AUTOFORMAT | BASSWASAPIInit.BASS_WASAPI_BUFFER, 0f, 0f, new WASAPIPROC(delegate(IntPtr buffer, int length, IntPtr user) { return(1); }), IntPtr.Zero)) { BASSError error = Bass.BASS_ErrorGetCode(); } if (!BassWasapi.BASS_WASAPI_Start()) { BASSError error = Bass.BASS_ErrorGetCode(); } IsPlaying = true; } else { IsPlaying = false; } #endregion WASAPI }
public void stop() { BassWasapi.BASS_WASAPI_SetDevice(outIndex); BassWasapi.BASS_WASAPI_Stop(true); BassWasapi.BASS_WASAPI_Free(); Bass.BASS_Free(); BassWasapi.BASS_WASAPI_SetDevice(sourceIndex); BassWasapi.BASS_WASAPI_Stop(true); BassWasapi.BASS_WASAPI_Free(); Bass.BASS_Free(); }
public bool StopDevice() { timer.IsEnabled = false; var result = BassWasapi.BASS_WASAPI_Stop(true); var result2 = true;//Bass.BASS_Stop(); var wasSuccessful = BassWasapi.BASS_WASAPI_Free(); var wasSuccessful2 = Bass.BASS_Free(); return(result && result2 && wasSuccessful && wasSuccessful2); }
public bool Disable() { if (_enabled) { BassWasapi.BASS_WASAPI_Stop(true); _t.IsEnabled = false; _enabled = false; return(true); } return(false); }
public void enableClick(bool enable) { _t.IsEnabled = enable; _initialized = enable; if (enable == false) { BassWasapi.BASS_WASAPI_Stop(true); BassWasapi.BASS_WASAPI_Free(); Bass.BASS_Free(); } Enable = enable; }
/// <summary> /// BASSを破棄する /// </summary> public void Dispose() { /* * Shut down */ if (enablewasapi) { BassWasapi.BASS_WASAPI_Stop(true); } Bass.BASS_Stop(); Bass.BASS_Free(); Bass.BASS_PluginFree(0); Bass.FreeMe(); }
public override void Stop() { if (_deviceState == DeviceState.Stopped) { return; } Log.Debug("Stopping output"); _deviceState = DeviceState.Stopped; if (!BassWasapi.BASS_WASAPI_Stop(true)) { throw new BassLibraryException("BASS_WASAPI_Stop"); } }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { BassWasapi.BASS_WASAPI_Stop(true); string[] array = (devicelist.Items[devicelist.SelectedIndex] as string).Split(' '); devindex = int.Parse(array[0]); if (!BassWasapi.BASS_WASAPI_Init(devindex, 0, 0, BASSWASAPIInit.BASS_WASAPI_BUFFER, 1f, 0.05f, process, IntPtr.Zero)) { BASSError error = Bass.BASS_ErrorGetCode(); if (error.ToString() != "BASS_ERROR_INIT") { MessageBox.Show(error.ToString()); } } BassWasapi.BASS_WASAPI_Start(); }
// initialization private void NewInit() { _t.Stop(); _deviceCount = 0; bool result = false; List <int> DeviceActiveIndex = new List <int>(); for (int i = 0; i < BassWasapi.BASS_WASAPI_GetDeviceCount(); i++) { var device = BassWasapi.BASS_WASAPI_GetDeviceInfo(i); if (device.IsEnabled && device.IsLoopback) { DeviceActiveIndex.Add(i); _deviceCount++; } } Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATETHREADS, false); result = Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero); if (!result) { throw new Exception("Init Error"); } if (_enable) { if (!_initialized) { devindex = DeviceActiveIndex[DeviceActiveIndex.Count - 1]; result = BassWasapi.BASS_WASAPI_Init(devindex, 0, 0, BASSWASAPIInit.BASS_WASAPI_BUFFER, 1f, 0.05f, _process, IntPtr.Zero); if (!result) { var error = Bass.BASS_ErrorGetCode(); MessageBox.Show(error.ToString()); } else { _initialized = true; } } BassWasapi.BASS_WASAPI_Start(); } else { BassWasapi.BASS_WASAPI_Stop(true); } System.Threading.Thread.Sleep(500); _t.Start(); }
private void PlayPauseBtn_Click(object sender, EventArgs e) { if (PlayPauseBtn.Text == "Play") { if (chan != 0) { PlayPauseBtn.Text = "Pause"; if (IsWinXPOrOlder()) { Bass.BASS_ChannelPause(chan); } else { BassWasapi.BASS_WASAPI_Stop(false); } } else { PlayPauseBtn.Text = "Pause"; } } else { if (chan != 0) { PlayPauseBtn.Text = "Play"; if (IsWinXPOrOlder()) { Bass.BASS_ChannelPlay(chan, false); } else { BassWasapi.BASS_WASAPI_Start(); } } else { PlayPauseBtn.Text = "Play"; } } }
public static void ReleaseResources(bool StillRendering, bool Closing) { foreach (Int32 Stream in MainWindow.VSTs._DummyVSTHandles) { BassVst.BASS_VST_ChannelRemoveDSP(0, Stream); } if (MainWindow.KMCGlobals.SoundFonts != null) { foreach (BASS_MIDI_FONTEX pr in MainWindow.KMCGlobals.SoundFonts) { BassMidi.BASS_MIDI_FontFree(pr.font); } } BassVst.BASS_VST_ChannelRemoveDSP(0, MainWindow.VSTs._DummyLoudMaxHan); MainWindow.KMCGlobals.DoNotCountNotes = false; BassWasapi.BASS_WASAPI_Stop(true); BassWasapi.BASS_WASAPI_Free(); Bass.BASS_StreamFree(MainWindow.KMCGlobals._recHandle); BassVst.BASS_VST_ChannelFree(MainWindow.VSTs._VSTiHandle); MainWindow.KMCStatus.IsKMCBusy = StillRendering; MainWindow.KMCStatus.IsKMCNowExporting = false; MainWindow.KMCGlobals.eventc = 0; MainWindow.KMCGlobals.events = null; if (Closing) { Bass.BASS_Free(); MainWindow.KMCGlobals.ActiveVoicesInt = 0; MainWindow.KMCStatus.IsKMCBusy = false; MainWindow.KMCGlobals.NewWindowName = null; MainWindow.KMCStatus.RenderingMode = false; RTF.CPUUsage = 0.0f; RTF.ActiveVoices = 0.0f; } }
/// <summary> /// End of Playback for a stream has been signaled /// Send event to Bass player to start playback of next song /// </summary> /// <param name="handle"></param> /// <param name="stream"></param> /// <param name="data"></param> /// <param name="userData"></param> private void PlaybackEndProc(int handle, int stream, int data, IntPtr userData) { try { MusicStream musicstream; // Get the GC handle of the pinned object try { musicstream = (MusicStream)_pinnedObjects[userData.ToInt32()].Target; } catch (KeyNotFoundException ex) { Log.Error("BASS: GCHandle of Musicstream not found in Dictionary {0} {1}", userData.ToInt32(), ex.Message); return; } Log.Debug("BASS: End of Song {0}", musicstream.FilePath); // We need to find out, if the nextsongs sample rate and / or number of channels are different to the one just ended // If this is the case we need a new mixer and the OnMusicStreamMessage needs to be invoked in a thread to avoid crashes. // In order to have gapless playback, it needs to be invoked in sync. MusicStream nextStream = null; Playlists.PlayListItem nextSong = Playlists.PlayListPlayer.SingletonPlayer.GetNextItem(); MusicStream._fileType = Utils.GetFileType(musicstream.FilePath); if (nextSong != null && MusicStream._fileType.FileMainType != FileMainType.WebStream) { nextStream = new MusicStream(nextSong.FileName, true); } else if (MusicStream._fileType.FileMainType == FileMainType.WebStream) { if (MusicStreamMessage != null) { MusicStreamMessage(musicstream, MusicStream.StreamAction.InternetStreamChanged); return; } } bool newMixerNeeded = false; if (nextStream != null && nextStream.BassStream != 0) { if (_bassPlayer.NewMixerNeeded(nextStream)) { newMixerNeeded = true; } nextStream.Dispose(); } if (newMixerNeeded) { if (Config.MusicPlayer == AudioPlayer.WasApi && BassWasapi.BASS_WASAPI_IsStarted()) { BassWasapi.BASS_WASAPI_Stop(true); } // Unplug the Source channel from the mixer Log.Debug("BASS: Unplugging source channel from Mixer."); BassMix.BASS_Mixer_ChannelRemove(musicstream.BassStream); // invoke a thread because we need a new mixer Log.Debug("BASS: Next song needs a new mixer."); new Thread(() => { if (MusicStreamMessage != null) { MusicStreamMessage(musicstream, MusicStream.StreamAction.Crossfading); } }) { Name = "BASS" }.Start(); } else { if (MusicStreamMessage != null) { MusicStreamMessage(musicstream, MusicStream.StreamAction.Crossfading); } } } catch (AccessViolationException ex) { Log.Error("BASS: Caught AccessViolationException in Playback End Proc {0}", ex.Message); } }
public void PauseCapture() { BassWasapi.BASS_WASAPI_Stop(true); }
/// <summary> /// Останавливает процесс получения данных. /// </summary> public void Stop() { _timer.Stop(); BassWasapi.BASS_WASAPI_Stop(true); }
public void EnableBASS(bool setto) { if (setto) { if (BassWasapi.BASS_WASAPI_IsStarted()) { BassWasapi.BASS_WASAPI_Stop(true); } BassWasapi.BASS_WASAPI_Free(); Bass.BASS_Free(); if (VisualizerThread != null) { RunVisualizerThread = false; while (VisualizerThread.Status == TaskStatus.Running) { Thread.Sleep(5); Application.DoEvents(); } VisualizerThread.Dispose(); } String SerialOut = ""; MainFormClass.VisualizerFromSeriesIDNumericUpDown.Invoke((MethodInvoker) delegate { MainFormClass.VisualizerToSeriesIDNumericUpDown.Invoke((MethodInvoker) delegate { SerialOut = "6;" + MainFormClass.VisualizerFromSeriesIDNumericUpDown.Value + ";" + MainFormClass.VisualizerToSeriesIDNumericUpDown.Value; }); }); MainFormClass.SendDataBySerial(SerialOut); BassProcess = new WASAPIPROC(Process); var array = (MainFormClass.AudioSourceComboBox.Items[MainFormClass.AudioSourceComboBox.SelectedIndex] as string).Split(' '); int devindex = Convert.ToInt32(array[0]); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATETHREADS, false); Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero); bool result = BassWasapi.BASS_WASAPI_Init(devindex, 0, 0, BASSWASAPIInit.BASS_WASAPI_BUFFER, 1f, 0.05f, BassProcess, IntPtr.Zero); if (!result) { var error = Bass.BASS_ErrorGetCode(); MessageBox.Show(error.ToString()); } BassWasapi.BASS_WASAPI_Start(); RunVisualizerThread = true; VisualizerThread = new Task(delegate { AudioDataThread(); }); VisualizerThread.Start(); } else { if (VisualizerThread != null) { RunVisualizerThread = false; while (VisualizerThread.Status == TaskStatus.Running) { Thread.Sleep(5); Application.DoEvents(); } VisualizerThread.Dispose(); } if (BassWasapi.BASS_WASAPI_IsStarted()) { BassWasapi.BASS_WASAPI_Stop(true); } BassWasapi.BASS_WASAPI_Free(); Bass.BASS_Free(); } }
//cleanup public void Free() { BassWasapi.BASS_WASAPI_Stop(true); BassWasapi.BASS_WASAPI_Free(); //Bass.BASS_Free(); }
async Task StartVisualizer(bool Start, string DeviceName) { if (Start) { if (RunVisualizer) { RunVisualizer = false; while (VisualizersRunning) { await Task.Delay(10); } } if (BassWasapi.BASS_WASAPI_IsStarted()) { BassWasapi.BASS_WASAPI_Stop(true); } BassWasapi.BASS_WASAPI_Free(); Bass.BASS_Free(); BassProcess = new WASAPIPROC(Process); var array = (AudioSourceCombobox.Items[AudioSourceCombobox.SelectedIndex] as string).Split(' '); int devindex = Convert.ToInt32(array[0]); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATETHREADS, false); Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero); bool result = BassWasapi.BASS_WASAPI_Init(devindex, 0, 0, BASSWASAPIInit.BASS_WASAPI_BUFFER, 1f, 0.05f, BassProcess, IntPtr.Zero); if (!result) { var error = Bass.BASS_ErrorGetCode(); MessageBox.Show(error.ToString()); } BassWasapi.BASS_WASAPI_Start(); RunVisualizer = true; VisualizersRunning = true; Task VisualizerThreadStart = new Task(delegate { VisualizerThread(); }); VisualizerThreadStart.Start(); } else { if (RunVisualizer) { RunVisualizer = false; while (VisualizersRunning) { await Task.Delay(10); } } for (int i = 0; i < VisualizerStack.Count; i++) { VisualizerStack[i].VisualizerControlBeatZoneCanvas.Children.Clear(); } if (BassWasapi.BASS_WASAPI_IsStarted()) { BassWasapi.BASS_WASAPI_Stop(true); } BassWasapi.BASS_WASAPI_Free(); Bass.BASS_Free(); } }