/// <summary>
        /// Retrieves information on a device and adds it to the static deviceinfo dictionary do it can be reused later.
        /// </summary>
        /// <param name="deviceNo">Device number to retrieve information on.</param>
        protected void CollectDeviceInfo(int deviceNo)
        {
            // Device info is saved in a dictionary so it can be reused lateron.
            if (!_deviceInfos.ContainsKey(deviceNo))
            {
                Log.Debug("Collecting device info");

                BASS_WASAPI_DEVICEINFO bassDeviceInfo = BassWasapi.BASS_WASAPI_GetDeviceInfo(deviceNo);
                if (bassDeviceInfo == null)
                {
                    throw new BassLibraryException("BASS_WASAPI_GetDeviceInfo");
                }

                BASS_WASAPI_INFO bassInfo = BassWasapi.BASS_WASAPI_GetInfo();
                if (bassInfo == null)
                {
                    throw new BassLibraryException("BASS_WASAPI_GetInfo");
                }

                DeviceInfo deviceInfo = new DeviceInfo
                {
                    Name     = bassDeviceInfo.name,
                    Driver   = "WASAPI",
                    Channels = bassInfo.chans,
                    MinRate  = bassInfo.freq,
                    MaxRate  = bassInfo.freq,
                };

                GetDeviceFormats(deviceNo, deviceInfo);
                lock (_deviceInfos)
                    _deviceInfos.Add(deviceNo, deviceInfo);
            }
            Log.Debug("WASAPI device info: {0}", _deviceInfos[_deviceNo].ToString());
        }
Пример #2
0
        public static void BASSInitSystem(Boolean PreviewMode)
        {
            try
            {
                Bass.BASS_StreamFree(MainWindow.KMCGlobals._recHandle);
                Bass.BASS_Free();
                Bass.BASS_Init(0, Properties.Settings.Default.AudioFreq, BASSInit.BASS_DEVICE_NOSPEAKER, IntPtr.Zero);

                if (!PreviewMode)
                {
                    Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_MIDI_VOICES, 100000);
                }
                else
                {
                    BassWasapi.BASS_WASAPI_Init(-1, 0, 2, BASSWASAPIInit.BASS_WASAPI_BUFFER, 0, 0, null, IntPtr.Zero);
                    BASS_WASAPI_DEVICEINFO info = new BASS_WASAPI_DEVICEINFO();
                    BassWasapi.BASS_WASAPI_GetDeviceInfo(BassWasapi.BASS_WASAPI_GetDevice(), info);
                    MainWindow.KMCGlobals.RealTimeFreq = info.mixfreq;
                    BassWasapi.BASS_WASAPI_Free();
                    Bass.BASS_Free();
                    Bass.BASS_Init(0, info.mixfreq, BASSInit.BASS_DEVICE_NOSPEAKER, IntPtr.Zero);
                    Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_MIDI_VOICES, 2000);
                }
            }
            catch (Exception ex)
            {
                BASSCloseStreamCrash(ex);
            }
        }
Пример #3
0
        private void DefaultWASAPIAudioOutput_Load(object sender, EventArgs e)
        {
            try
            {
                if ((int)KeppySynthConfiguratorMain.SynthSettings.GetValue("wasapiex", 0) == 1)
                {
                    ExAccess.Checked = true;
                }
                DevicesList.Items.Add("Default WASAPI output device");
                int selecteddeviceprev      = (int)KeppySynthConfiguratorMain.SynthSettings.GetValue("defaultWdev", 0);
                BASS_WASAPI_DEVICEINFO info = new BASS_WASAPI_DEVICEINFO();
                for (int n = 0; BassWasapi.BASS_WASAPI_GetDeviceInfo(n, info); n++)
                {
                    AddLineToList(info, n, selecteddeviceprev);
                }

                try { DevicesList.SelectedIndex = selecteddeviceprev; }
                catch { DevicesList.SelectedIndex = 0; }

                DevicesList.SelectedIndexChanged += new System.EventHandler(this.DevicesList_SelectedIndexChanged);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to load the dialog.\nBASS is probably unable to start, or it's missing.\n\nError:\n" + ex.ToString(), "Oh no! Keppy's Synthesizer encountered an error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
                Dispose();
            }
        }
Пример #4
0
        //Adds all valid detected WASAPI devices to the Device Selection menu item
        private void AddValidWasapiDevices()
        {
            deviceSelectionToolStripMenuItem.DropDownItems.Clear();
            BASS_WASAPI_DEVICEINFO[] devices        = BassWasapi.BASS_WASAPI_GetDeviceInfos();
            List <string>            deviceNameList = new List <string>();

            for (int i = 0; i < devices.Length; i++)
            {
                BASS_WASAPI_DEVICEINFO curDevice = devices[i];
                if (curDevice.IsEnabled && curDevice.SupportsRecording)
                {
                    string deviceName = curDevice.name;
                    if (curDevice.IsLoopback)
                    {
                        deviceName = deviceName + " (Loopback)";
                    }
                    if (deviceNameList.Contains(curDevice.name))
                    {
                        deviceName = string.Format("{0} ({1})", curDevice.name, i);
                    }
                    deviceNameList.Add(deviceName);

                    if (Properties.Settings.Default.DeviceIndex == i)
                    {
                        AddDeviceToMenuItem(deviceName, i, true);
                    }
                    else
                    {
                        AddDeviceToMenuItem(deviceName, i, false);
                    }
                }
            }

            AddDeviceToMenuItem("Reload Devices...", -2, false);
        }
        private void FillWASAPIDeviceList()
        {
            _WASAPIDevices.Clear();
            BassPlayerSettings settings = Controller.GetSettings();

            BASS_WASAPI_DEVICEINFO[] deviceDescriptions = BassWasapi.BASS_WASAPI_GetDeviceInfos();
            for (int i = 0; i < deviceDescriptions.Length; i++)
            {
                // Skip input devices, they have same name as output devices.
                BASS_WASAPI_DEVICEINFO deviceInfo = deviceDescriptions[i];
                if ((deviceInfo.flags & (BASSWASAPIDeviceInfo.BASS_DEVICE_INPUT | BASSWASAPIDeviceInfo.BASS_DEVICE_DISABLED /*| BASSWASAPIDeviceInfo.BASS_DEVICE_UNPLUGGED */)) != 0)
                {
                    continue;
                }

                ListItem deviceItem = new ListItem(Consts.KEY_NAME, deviceInfo.name)
                {
                    Selected = deviceInfo.name == settings.WASAPIDevice
                };
                deviceItem.SelectedProperty.Attach(delegate
                {
                    var selected = _WASAPIDevices.FirstOrDefault(d => d.Selected);
                    WASAPIDevice = selected != null ? selected.Labels[Consts.KEY_NAME].ToString() : string.Empty;
                });
                deviceItem.SetLabel(KEY_GROUP, "WASAPI");
                _WASAPIDevices.Add(deviceItem);
            }
            _WASAPIDevices.FireChange();
        }
Пример #6
0
        private void Main_Load(object sender, EventArgs e)
        {
            if (IsWinXPOrOlder())
            {
                if (!Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero))
                {
                    Error("Can't initialize device");
                    return;
                }
            }
            else
            {
                Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_NOSPEAKER, IntPtr.Zero);
                BassWasapi.BASS_WASAPI_Init(-1, 0, 2, BASSWASAPIInit.BASS_WASAPI_BUFFER | BASSWASAPIInit.BASS_WASAPI_SHARED, 0, 0, null, IntPtr.Zero);
                BASS_WASAPI_DEVICEINFO info = new BASS_WASAPI_DEVICEINFO();
                BassWasapi.BASS_WASAPI_GetDeviceInfo(BassWasapi.BASS_WASAPI_GetDevice(), info);
                BassWasapi.BASS_WASAPI_Free();
                Bass.BASS_Free();
                if (!Bass.BASS_Init(0, info.mixfreq, BASSInit.BASS_DEVICE_NOSPEAKER, IntPtr.Zero))
                {
                    Error("Can't initialize device");
                    return;
                }
            }

            GetInfoFromStream.RunWorkerAsync();
            KSIntegration.RunWorkerAsync();

            VoiceBar.Value = 100;

            VoiceBar.ContextMenu = VoiceUnlock;
            Position.ContextMenu = ShowTime;

            Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_MIDI_VOICES, 100000);
        }
Пример #7
0
        private void FillWASAPIDeviceList()
        {
            _WASAPIDevices.Clear();
            BassPlayerSettings settings = Controller.GetSettings();

            BASS_WASAPI_DEVICEINFO[] deviceDescriptions = BassWasapi.BASS_WASAPI_GetDeviceInfos();
            for (int i = 0; i < deviceDescriptions.Length; i++)
            {
                // Skip input devices, they have same name as output devices.
                BASS_WASAPI_DEVICEINFO deviceInfo = deviceDescriptions[i];
                bool skip = !WASAPIOutputDevice.IsValidDevice(deviceInfo);

                ServiceRegistration.Get <ILogger>().Debug("{5} WASAPI Device {0}: '{1}' Flags: {2} Device path: [{3}] Ch: {4}", i, deviceInfo.name, deviceInfo.flags, deviceInfo.id, deviceInfo.mixchans,
                                                          skip ? "Skip" : "Use ");
                if (skip)
                {
                    continue;
                }

                ListItem deviceItem = new ListItem(Consts.KEY_NAME, deviceInfo.name)
                {
                    Selected = deviceInfo.name == settings.WASAPIDevice
                };
                deviceItem.SelectedProperty.Attach(delegate
                {
                    var selected = _WASAPIDevices.FirstOrDefault(d => d.Selected);
                    WASAPIDevice = selected != null ? selected.Labels[Consts.KEY_NAME].ToString() : string.Empty;
                });
                deviceItem.SetLabel(KEY_GROUP, "WASAPI");
                _WASAPIDevices.Add(deviceItem);
            }
            _WASAPIDevices.FireChange();
        }
        //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;
        }
Пример #9
0
        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
        }
Пример #10
0
        /// <summary>
        /// 全てのデバイスのデバイス情報の配列を返す
        /// </summary>
        /// <returns>デバイス情報の配列</returns>
        public static BASS_WASAPI_DEVICEINFO[] GetDevices()
        {
            UInt32 id = 0;
            BASS_WASAPI_DEVICEINFO        info = new BASS_WASAPI_DEVICEINFO();
            List <BASS_WASAPI_DEVICEINFO> list = new List <BASS_WASAPI_DEVICEINFO>();

            while (BASS_WASAPI_GetDeviceInfo(id, out info))
            {
                list.Add(info);
                id++;
            }
            return(list.ToArray());
        }
Пример #11
0
        public AudioSpectrumDevice(BASS_WASAPI_DEVICEINFO device, int devindex, int channels)
        {
            _lines = channels;
            for (int i = 0; i < channels; i++)
            {
                JoyAxis channel = new JoyAxis("Channel " + (i + 1).ToString(), DataFlowDirection.Input, "")
                {
                    min_Value = 0, max_Value = 1
                };
                Channels.Add(channel);
            }

            this.devindex   = devindex;
            this.device     = device;
            this.DeviceName = device.name;
            this.StatusIcon = Properties.Resources.audio.ToImageSource();
            _fft            = new float[1024];
            _lastlevel      = 0;
            _hanctr         = 0;
            _t          = new DispatcherTimer();
            _t.Tick    += _t_Tick;
            _t.Interval = TimeSpan.FromMilliseconds(25); //40hz refresh rate
            //_t.IsEnabled = true;
            _process      = new WASAPIPROC(Process);
            _spectrumdata = new List <double>();
            _initialized  = false;


            //var str = (_devicelist.Items[_devicelist.SelectedIndex] as string)
            //            var array = str.Split(' ');
            //devindex = Convert.ToInt32(array[0]);
            bool 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();
            _t.IsEnabled = true;
            _t.Start();
        }
        public List <string> GetDevices()
        {
            List <string> Devices = new List <string>();

            for (int i = 0; i < BassWasapi.BASS_WASAPI_GetDeviceCount(); i++)
            {
                BASS_WASAPI_DEVICEINFO device = BassWasapi.BASS_WASAPI_GetDeviceInfo(i);
                if (device.IsEnabled && device.IsLoopback)
                {
                    Devices.Add(string.Format("{0} - {1}", i, device.name));
                }
            }

            return(Devices);
        }
Пример #13
0
        private void AddLineToList(BASS_WASAPI_DEVICEINFO info, int n, int selecteddeviceprev)
        {
            if (info.IsDisabled)
            {
                if (info.IsInput)
                {
                    DevicesList.Items.Add(String.Format("{0} ({1})", info.ToString(), "Unsupported device, Disabled"));
                }
                else if (!info.IsInput)
                {
                    DevicesList.Items.Add(String.Format("{0} ({1})", info.ToString(), "Output device, Disabled"));
                }
                else if (info.IsLoopback)
                {
                    DevicesList.Items.Add(String.Format("{0} ({1})", info.ToString(), "Loopback device, Disabled"));
                }
            }
            else if (info.IsEnabled)
            {
                if (info.IsInput)
                {
                    DevicesList.Items.Add(String.Format("{0} ({1})", info.ToString(), "Unsupported device, Enabled"));
                }
                else if (!info.IsInput)
                {
                    DevicesList.Items.Add(String.Format("{0} ({1})", info.ToString(), "Output device, Enabled"));
                }
                else if (info.IsLoopback)
                {
                    DevicesList.Items.Add(String.Format("{0} ({1})", info.ToString(), "Loopback device, Enabled"));
                }
            }
            else if (info.IsUnplugged)
            {
                DevicesList.Items.Add(String.Format("{0} ({1})", info.ToString(), "Unplugged device"));
            }
            else
            {
                DevicesList.Items.Add(String.Format("{0} ({1})", info.ToString(), "Unknown device"));
            }

            if (n == selecteddeviceprev)
            {
                DefOut.Text = String.Format("Def. WASAPI audio output: {0}", DevicesList.Items[n].ToString());
            }
        }
Пример #14
0
 private void Init()
 {
     Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATETHREADS, false);
     if (!Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero))
     {
         throw new Exception("Init Error");
     }
     for (int i = 0; i < BassWasapi.BASS_WASAPI_GetDeviceCount(); i++)
     {
         BASS_WASAPI_DEVICEINFO device = BassWasapi.BASS_WASAPI_GetDeviceInfo(i);
         if (device.IsEnabled && device.IsLoopback)
         {
             devicelist.Items.Add(string.Format("{0} - {1}", i, device.name));
         }
     }
     devicelist.SelectedIndex = 0;
 }
Пример #15
0
        public static int GetInputDefaultDevice()
        {
            BASS_WASAPI_DEVICEINFO[] wasapiDevices = BassWasapi.BASS_WASAPI_GetDeviceInfos();
            int inputItem = 0;

            for (int i = 0; i < wasapiDevices.Length; i++)
            {
                BASS_WASAPI_DEVICEINFO info = wasapiDevices[i];

                if (info.IsInput && info.IsDefault)
                {
                    inputItem = i;
                    break;
                }
            }

            return(inputItem);
        }
Пример #16
0
        public static int GetOutputDefaultDevice()
        {
            BASS_WASAPI_DEVICEINFO[] wasapiDevices = BassWasapi.BASS_WASAPI_GetDeviceInfos();
            int outputItem = 0;

            for (int i = 0; i < wasapiDevices.Length; i++)
            {
                BASS_WASAPI_DEVICEINFO info = wasapiDevices[i];

                if (!info.IsInput && info.IsDefault)
                {
                    outputItem = i;
                    Player.DefaultDeviceLongName = info.name;
                    break;
                }
            }

            return(outputItem);
        }
Пример #17
0
        private void Init()
        {
            Boolean Result = false;

            for (int i = 0; i < BassWasapi.BASS_WASAPI_GetDeviceCount(); i++)
            {
                BASS_WASAPI_DEVICEINFO device = BassWasapi.BASS_WASAPI_GetDeviceInfo(i);
                if (device.IsEnabled && device.IsLoopback)
                {
                    _devace.Add(String.Format("{0} - {1}", i, device.name));
                }
            }

            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("Ошибка инициализации");
            }
        }
Пример #18
0
        public static JObject updateAudioDevices()
        {
            audioDevices.RemoveAll();
            audioDevices.Add("Default", defaultAudio());
            BASS_WASAPI_DEVICEINFO item = new BASS_WASAPI_DEVICEINFO();

            for (int n = 0; BassWasapi.BASS_WASAPI_GetDeviceInfo(n, item); n++)
            {
                if (item.IsEnabled && item.IsLoopback)
                {
                    var     device     = item.name.Split('(');
                    JObject deviceJson = new JObject();
                    deviceJson["id"]         = n;
                    deviceJson["fullName"]   = item.name;
                    deviceJson["firstName"]  = device[0];
                    deviceJson["secondName"] = device[1].Remove(device[1].Length - 1, 1);
                    deviceJson["isDefault"]  = item.IsDefault;
                    audioDevices.Add(item.name, deviceJson);
                }
            }
            return(audioDevices);
        }
Пример #19
0
        public static List <Tuple <string, int> > GetBassDevices()
        {
            List <Tuple <string, int> > deviceList = new List <Tuple <string, int> >();

            BASS_WASAPI_DEVICEINFO[] devices = BassWasapi.BASS_WASAPI_GetDeviceInfos();
            for (int i = 0; i < devices.Length; i++)
            {
                BASS_WASAPI_DEVICEINFO device = devices[i];
                if (!device.IsEnabled || !device.SupportsRecording)
                {
                    continue;
                }

                string deviceName = device.name;
                if (device.IsLoopback)
                {
                    deviceName += " (Loopback)";
                }

                deviceList.Add(new Tuple <string, int>(deviceName, i));
            }

            return(deviceList);
        }
Пример #20
0
        public static void BASSStreamSystemRT(String str, Boolean PreviewMode)
        {
            try
            {
                MainWindow.KMCGlobals._recHandle = BassMidi.BASS_MIDI_StreamCreateFile(str, 0L, 0L, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT, 0);
                BASSCheckError();

                BASS_MIDI_EVENT[] eventChunk;
                try
                {
                    // Thank you so much Falcosoft for helping me there!!!
                    // Visit his website: http://falcosoft.hu/index.html#start
                    MainWindow.KMCGlobals.eventc = (UInt32)BassMidi.BASS_MIDI_StreamGetEvents(MainWindow.KMCGlobals._recHandle, -1, 0, null); // Counts all the events in the MIDI
                    MainWindow.KMCGlobals.events = new BASS_MIDI_EVENT[MainWindow.KMCGlobals.eventc];                                         // Creates an array with the events count as size
                    for (int i = 0; i <= (MainWindow.KMCGlobals.eventc / 50000000); i++)
                    {
                        int subCount = Math.Min(50000000, (int)MainWindow.KMCGlobals.eventc - (i * 50000000));
                        eventChunk = new BASS_MIDI_EVENT[subCount];
                        BassMidi.BASS_MIDI_StreamGetEvents(MainWindow.KMCGlobals._recHandle, -1, 0, eventChunk, i * 50000000, subCount); //Falcosoft: to avoid marshalling errors pass the smaller local buffer to the function
                        eventChunk.CopyTo(MainWindow.KMCGlobals.events, i * 50000000);                                                   //Falcosoft: copy local buffer to global one at each iteration
                    }
                    eventChunk = null;
                }
                catch
                {
                    BASSCloseStreamException(new MIDILoadError("This MIDI is too big for the real-time conversion process.\n\nMake sure you're using the 64-bit version of the converter."));
                }

                Bass.BASS_StreamFree(MainWindow.KMCGlobals._recHandle);
                MainWindow.KMCGlobals._recHandle = BassMidi.BASS_MIDI_StreamCreate(16,
                                                                                   BASSFlag.BASS_STREAM_DECODE |
                                                                                   (PreviewMode ? 0 : (Properties.Settings.Default.SincInter ? BASSFlag.BASS_MIDI_SINCINTER : 0)) |
                                                                                   BASSFlag.BASS_SAMPLE_FLOAT |
                                                                                   BASSFlag.BASS_SAMPLE_SOFTWARE,
                                                                                   0);
                BASSCheckError();

                if (PreviewMode)
                {
                    BASS_WASAPI_DEVICEINFO infoDW = new BASS_WASAPI_DEVICEINFO();

                    BassWasapi.BASS_WASAPI_Init(-1, 0, 2, BASSWASAPIInit.BASS_WASAPI_BUFFER, 0, 0, null, IntPtr.Zero);
                    BassWasapi.BASS_WASAPI_GetDevice();
                    BassWasapi.BASS_WASAPI_GetDeviceInfo(BassWasapi.BASS_WASAPI_GetDevice(), infoDW);
                    BassWasapi.BASS_WASAPI_Free();

                    BassWasapi.BASS_WASAPI_Init(-1, infoDW.mixfreq, 2, BASSWASAPIInit.BASS_WASAPI_SHARED, infoDW.minperiod, 0, null, IntPtr.Zero);
                    BASSCheckError();
                }

                BASSInitializeChanAttributes();
                BASSTempoAndFilter();

                if (Path.GetFileNameWithoutExtension(str).Length >= 49)
                {
                    MainWindow.KMCGlobals.NewWindowName = Path.GetFileNameWithoutExtension(str).Truncate(45);
                }
                else
                {
                    MainWindow.KMCGlobals.NewWindowName = Path.GetFileNameWithoutExtension(str);
                }
                MainWindow.KMCGlobals._plm         = new Un4seen.Bass.Misc.DSP_PeakLevelMeter(MainWindow.KMCGlobals._recHandle, 1);
                MainWindow.KMCGlobals._plm.CalcRMS = true;
            }
            catch (Exception ex)
            {
                BASSCloseStreamException(ex);
            }
        }
Пример #21
0
 public DeviceInfo(BASS_WASAPI_DEVICEINFO info, int num)
 {
     WasapiDeviceInfo = info;
     WasapiDeviceNum  = num;
 }
Пример #22
0
        private BassWasapiHandler _wasapiOutput; //Speedy thing comes out

        #endregion Fields

        #region Constructors

        public MainForm()
        {
            InitializeComponent();
            SP.Close();
            watcher.Path = Directory.GetCurrentDirectory();
            watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                                   | NotifyFilters.FileName | NotifyFilters.DirectoryName;

            // Only watch json config.
            watcher.Filter = "config.json";
            watcher.Changed += OnChanged;
            watcher.EnableRaisingEvents = true;

            string[] ports = SerialPort.GetPortNames();

            foreach (string port in ports)
            {
                comboBox1.Items.Add(port);
            }
            window = new RenderWindow(SFMLPanel.Handle);
            try
            {
                Device = Convert.ToInt16(ini.IniReadValue("recent_device", "DeviceNumber"));
            }
            catch (Exception)
            {
                Device = -1;
            }

            //Try Applying general settings
            try
            {
                if (ini.IniReadValue("GeneralSettings", "MintoTray") == "True")
                {
                    Check_MintoTray.Checked = true;
                }

                SP.PortName = ini.IniReadValue("GeneralSettings", "COM");
            }
            catch (Exception)
            {
                try
                {
                    SP.PortName = ini.IniReadValue("GeneralSettings", "COM");
                }
                catch
                {
                }
                Check_MintoTray.Checked = false;
            }
            Console.WriteLine("COM PORT: " + ini.IniReadValue("GeneralSettings", "COM"));

            //serialPort1.PortName = "COM3"

            SP.BaudRate = 115200;
            try
            {
                SP.Open();
            }

            catch
            {
                if (!comError)
                {
                    comError = true;
                    Console.WriteLine("No COM Port set or can't comunicate with the com port");
                }
            }

            //If you see this, plz don't take my kredz
            //This is so you don't see the dumb HERPADERP BASS IS STARTING spash screen
            BassNet.Registration("*****@*****.**", "2X2832371834322");
            //Start base itself
            //Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);

            //Populate the possible devices list
            var info = new BASS_WASAPI_DEVICEINFO();
            var Devices = new int[BassWasapi.BASS_WASAPI_GetDeviceCount()]; //List of devices

            for (int n = 0; BassWasapi.BASS_WASAPI_GetDeviceInfo(n, info); n++)
            {
                if (info.SupportsRecording && info.IsEnabled)
                {
                    DeviceList.Items.Add(info.ToString());
                    Devices[n] = n;
                    if (n == Device)
                    {
                        DeviceList.SelectedItem = info.ToString();
                    }
                }
            }

            //DeviceList.SelectedIndex = 2;

            if (StartBass()) //No errors and a device was properly chosen
            {
                TrayContextEnable.Enabled = true;
            }
        }
Пример #23
0
        private void ChangeDevice(object sender, EventArgs e)
        {
            var Selection = (ComboBox) sender;

            if (stream != -1) //Bass is started already
            {
                var info = new BASS_WASAPI_DEVICEINFO();
                bool Restart = false;
                for (int n = 0; BassWasapi.BASS_WASAPI_GetDeviceInfo(n, info); n++)
                {
                    if (info.ToString() == Selection.SelectedItem.ToString())
                    {
                        Device = n;

                        ini.IniWriteValue("recent_device", "DeviceNumber", n.ToString());
                        Restart = true;
                    }
                }
                if (Restart) Application.Restart();

                /*
                if (StartBass())//RE. START. EVERYTHING.
                {
                    PlayButton.Enabled = true;
                    TrayContextEnable.Enabled = true;

                }
                 * */
            }
            else //Only do this if bass hasn't started yet.
            {
                // Debug1.Text = Selection.SelectedItem.ToString();
                var info = new BASS_WASAPI_DEVICEINFO();

                for (int n = 0; BassWasapi.BASS_WASAPI_GetDeviceInfo(n, info); n++)
                {
                    if (info.ToString() == Selection.SelectedItem.ToString())
                    {
                        Device = n;
                        ini.IniWriteValue("recent_device", "DeviceNumber", n.ToString());
                        Application.Restart();
                    }
                }
            }
        }
Пример #24
0
        private void Preferences_Load(object sender, EventArgs e)
        {
            try
            {
                PrefTabControl.SelectTab(PlayerControl.PRefsTabIndex);
                m_tooltip.SetToolTip(chkBoxRefreshAsio, "Enable this option when noise artifact is present in audio.");

                string videoDir = Main_Form.iniFileHelper.Read("Video", "Video Path");

                videoLbl.Text = videoDir == string.Empty ? "Video: Default" : "Video: " + videoDir;

                if (videoDir == string.Empty)
                {
                    videoDir = VlcPlayer.BGVideoPath + @"VIDEO_NATURE\";
                }

                PlayerControl.GetVideoBG(videoDir);

                PlayerControl.SetDefaultVideoBG(panelPlayer.Handle);

                DataTable dt = new DataTable();
                dt.Columns.Add("ID", typeof(int));
                dt.Columns.Add("Name");

                DataRow dr = dt.NewRow();

                if (Equalizer.ArrBandValue[11].PreSet == -1)
                {
                    dr["Name"] = "";
                    dr["ID"]   = 0;

                    dt.Rows.Add(dr);

                    defBandValue = Equalizer.ArrBandValue;
                }

                for (int i = 0; i < VlcPlayer.EqPresets.Values.Count(); i++)
                {
                    dr         = dt.NewRow();
                    dr["Name"] = VlcPlayer.EqPresets[i].Name;
                    dr["ID"]   = VlcPlayer.EqPresets[i].Index;

                    dt.Rows.Add(dr);
                }

                comboBoxEQPresets.DataSource    = dt;// VlcPlayer.EqPresets.Values.ToList();
                comboBoxEQPresets.DisplayMember = "Name";
                comboBoxEQPresets.DropDownStyle = ComboBoxStyle.DropDownList;

                comboBoxEQPresets.SelectedIndex = Equalizer.ArrBandValue[11].PreSet;

                SetBandGain();

                if (PlayerControl.DefaultAudioOutput == DefaultAudioOutput.Bass)
                {
                    radioBtnBass.Checked     = true;
                    asio_control_btn.Enabled = false;
                }

                if (PlayerControl.DefaultAudioOutput == DefaultAudioOutput.Wasapi)
                {
                    radioBtnWasapi.Checked   = true;
                    asio_control_btn.Enabled = false;
                }

                if (PlayerControl.DefaultAudioOutput == DefaultAudioOutput.Asio)
                {
                    radioBtnAsio.Checked     = true;
                    asio_control_btn.Enabled = true;
                }

                if (Player.IsWasapiInitialized)
                {
                    int defaulInputDevice  = 0;
                    int defaulOutputDevice = 0;
                    this.comboBoxInputDevice.Items.Clear();
                    this.comboBoxOutputDevice.Items.Clear();
                    BASS_WASAPI_DEVICEINFO[] wasapiDevices = BassWasapi.BASS_WASAPI_GetDeviceInfos();
                    for (int i = 0; i < wasapiDevices.Length; i++)
                    {
                        BASS_WASAPI_DEVICEINFO info = wasapiDevices[i];

                        if (info.IsEnabled && info.IsInput)
                        {
                            defaulInputDevice = i;
                            int index = this.comboBoxInputDevice.Items.Add(new DeviceInfo(info, defaulInputDevice)); //string.Format("{0} - {1}", i, info.name));
                            if (info.IsDefault)
                            {
                                this.comboBoxInputDevice.SelectedIndex = index;
                            }

                            //defaulInputDevice++;
                        }

                        if (info.IsEnabled && !info.IsInput)
                        {
                            defaulOutputDevice = i;
                            int index = this.comboBoxOutputDevice.Items.Add(new DeviceInfo(info, defaulOutputDevice));
                            if (info.IsDefault)
                            {
                                this.comboBoxOutputDevice.SelectedIndex = index;
                            }

                            // defaulOutputDevice++;
                        }
                    }

                    RefreshEffects();
                }

                if (Player.IsAsioInitialized)
                {
                    this.comboBoxInputDevice.Items.Clear();
                    this.comboBoxInputDevice.Items.AddRange(BassAsioDevice.GetAsioInputChannels.ToArray());
                    if (this.comboBoxInputDevice.Items.Count > 0)
                    {
                        this.comboBoxInputDevice.SelectedIndex = BassAsioDevice.inputDevice;
                    }

                    this.comboBoxOutputDevice.Items.Clear();
                    this.comboBoxOutputDevice.Items.AddRange(BassAsioDevice.AsioOutputChannels.ToArray());
                    if (this.comboBoxOutputDevice.Items.Count > 0)
                    {
                        this.comboBoxOutputDevice.SelectedIndex = BassAsioDevice.outputDevice;
                    }

                    microphone_setting.Enabled = true;

                    if (AppSettings.Get <bool>("IsAsioAutoRestart"))
                    {
                        chkBoxRefreshAsio.Checked = true;
                    }
                    else
                    {
                        chkBoxRefreshAsio.Checked = false;
                    }

                    chkBoxRefreshAsio.Enabled = true;

                    groupMicrophoneEffects.Enabled = true;

                    RefreshEffects();
                }

                if (Player.IsBassInitialized)
                {
                    this.comboBoxOutputDevice.Items.Clear();
                    this.comboBoxOutputDevice.Items.AddRange(Bass.BASS_GetDeviceInfos());

                    if (this.comboBoxOutputDevice.Items.Count > 0)
                    {
                        this.comboBoxOutputDevice.SelectedIndex = Player.DefaultDevice;
                    }

                    microphone_setting.Enabled     = false;
                    chkBoxRefreshAsio.Enabled      = false;
                    groupMicrophoneEffects.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                Logger.LogFile(ex.Message, "", "Preferences_Load", ex.LineNumber(), this.Name);
            }
        }
 public WASAPIDeviceInfo(BASS_WASAPI_DEVICEINFO deviceInfo, bool exclusive, int minRate, int maxRate, int channels)
 {
     if (!exclusive)
     {
       _MinRate = deviceInfo.mixfreq;
       _MaxRate = deviceInfo.mixfreq;
       _Channels = deviceInfo.mixchans;
     }
     else
     {
       _MinRate = minRate;
       _MaxRate = maxRate;
       _Channels = channels;
     }
 }
Пример #26
0
 /// <summary>
 /// Checks if the given <paramref name="deviceInfo"/> represents a valid, currently available output device.
 /// </summary>
 /// <param name="deviceInfo">Device info</param>
 /// <returns><c>true</c> if valid.</returns>
 public static bool IsValidDevice(BASS_WASAPI_DEVICEINFO deviceInfo)
 {
     return(!(deviceInfo.IsDisabled || deviceInfo.IsUnplugged || deviceInfo.IsInput || deviceInfo.IsLoopback || deviceInfo.flags == BASSWASAPIDeviceInfo.BASS_DEVICE_UNKNOWN));
 }
Пример #27
0
        /// <summary>
        /// Create a mixer using the stream attributes
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public bool CreateMixer(MusicStream stream)
        {
            Log.Debug("BASS: ---------------------------------------------");
            Log.Debug("BASS: Creating BASS mixer stream");

            bool result = false;

            BASSFlag mixerFlags = BASSFlag.BASS_MIXER_NONSTOP | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_MIXER_NORAMPIN;

            if (Config.MusicPlayer == AudioPlayer.Asio || Config.MusicPlayer == AudioPlayer.WasApi)
            {
                mixerFlags |= BASSFlag.BASS_STREAM_DECODE;
            }

            int outputChannels = _bassPlayer.DeviceChannels;

            _mixingMatrix = null;

            // See, if we need Upmixing
            if (outputChannels > stream.ChannelInfo.chans)
            {
                Log.Debug("BASS: Found more output channels ({0}) than input channels ({1}). Check for upmixing.", outputChannels,
                          stream.ChannelInfo.chans);
                _mixingMatrix = CreateMixingMatrix(stream.ChannelInfo.chans);
                if (_mixingMatrix != null)
                {
                    outputChannels = Math.Min(_mixingMatrix.GetLength(0), outputChannels);
                    _upmixing      = true;
                }
                else
                {
                    outputChannels = stream.ChannelInfo.chans;
                }
            }
            else if (outputChannels < stream.ChannelInfo.chans)
            {
                // Downmix to Stereo
                Log.Debug("BASS: Found more input channels ({0}) than output channels ({1}). Downmix.", stream.ChannelInfo.chans,
                          outputChannels);
                outputChannels = Math.Min(outputChannels, 2);
            }

            Log.Debug("BASS: Creating {0} channel mixer with sample rate of {1}", outputChannels, stream.ChannelInfo.freq);
            _mixer = BassMix.BASS_Mixer_StreamCreate(stream.ChannelInfo.freq, outputChannels, mixerFlags);
            if (_mixer == 0)
            {
                Log.Error("BASS: Unable to create Mixer.  Reason: {0}.",
                          Enum.GetName(typeof(BASSError), Bass.BASS_ErrorGetCode()));
                return(false);
            }

            switch (Config.MusicPlayer)
            {
            case AudioPlayer.Bass:
            case AudioPlayer.DShow:

                if (!Bass.BASS_ChannelPlay(_mixer, false))
                {
                    Log.Error("BASS: Unable to start Mixer.  Reason: {0}.", Enum.GetName(typeof(BASSError), Bass.BASS_ErrorGetCode()));
                    return(false);
                }

                result = true;

                break;

            case AudioPlayer.Asio:

                Log.Info("BASS: Initialising ASIO device");

                if (BassAsio.BASS_ASIO_IsStarted() && !BassAsio.BASS_ASIO_Stop())
                {
                    Log.Error("BASS: Error stopping Asio Device: {0}", BassAsio.BASS_ASIO_ErrorGetCode());
                }

                // Disable and Unjoin all the channels
                if (!BassAsio.BASS_ASIO_ChannelReset(false, -1, BASSASIOReset.BASS_ASIO_RESET_ENABLE))
                {
                    Log.Error("BASS: Error disabling Asio Channels: {0}", BassAsio.BASS_ASIO_ErrorGetCode());
                }

                if (!BassAsio.BASS_ASIO_ChannelReset(false, -1, BASSASIOReset.BASS_ASIO_RESET_JOIN))
                {
                    Log.Error("BASS: Error unjoining Asio Channels: {0}", BassAsio.BASS_ASIO_ErrorGetCode());
                }

                _asioProc = new ASIOPROC(AsioCallback);

                BassAsio.BASS_ASIO_ChannelSetVolume(false, -1, (float)Config.StreamVolume / 100f);

                // enable 1st output channel...(0=first)
                Log.Debug("BASS: Joining Asio Channel #{0}", "0");
                BassAsio.BASS_ASIO_ChannelEnable(false, 0, _asioProc, new IntPtr(_mixer));

                // and join the next channels to it
                int numChannels = Math.Max(stream.ChannelInfo.chans, outputChannels);
                for (int i = 1; i < numChannels; i++)
                {
                    Log.Debug("BASS: Joining Asio Channel #{0}", i);
                    BassAsio.BASS_ASIO_ChannelJoin(false, i, 0);
                }

                // since we joined the channels, the next commands will apply to all channles joined
                // so setting the values to the first channels changes them all automatically
                // set the source format (float, as the decoding channel is)
                if (!BassAsio.BASS_ASIO_ChannelSetFormat(false, 0, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT))
                {
                    Log.Error("BASS: Error setting Asio Sample Format: {0}", BassAsio.BASS_ASIO_ErrorGetCode());
                }

                // set the source rate
                Log.Debug("BASS: Set sample rate to {0}", stream.ChannelInfo.freq);
                if (!BassAsio.BASS_ASIO_ChannelSetRate(false, 0, (double)stream.ChannelInfo.freq))
                {
                    Log.Error("BASS: Error setting Asio Channel Samplerate: {0}", BassAsio.BASS_ASIO_ErrorGetCode());
                }

                // try to set the device rate too (saves resampling)
                if (!BassAsio.BASS_ASIO_SetRate((double)stream.ChannelInfo.freq))
                {
                    Log.Error("BASS: Error setting Asio Samplerate: {0}", BassAsio.BASS_ASIO_ErrorGetCode());
                }

                // and start playing it...start output using default buffer/latency
                if (!BassAsio.BASS_ASIO_Start(0))
                {
                    Log.Error("BASS: Error starting Asio playback: {0}", BassAsio.BASS_ASIO_ErrorGetCode());
                }
                Log.Info("BASS: Finished initialising ASIO device");
                result = true;

                break;

            case AudioPlayer.WasApi:

                Log.Info("BASS: Initialising WASAPI device");

                try
                {
                    BassWasapi.BASS_WASAPI_Free();
                    Log.Debug("BASS: Freed WASAPI device");
                }
                catch (Exception ex)
                {
                    Log.Error("BASS: Exception freeing WASAPI. {0} {1}", ex.Message, ex.StackTrace);
                }

                BASSWASAPIInit initFlags = BASSWASAPIInit.BASS_WASAPI_AUTOFORMAT;

                _wasapiProc = new WASAPIPROC(WasApiCallback);

                bool wasApiExclusiveSupported = true;

                // Check if we have an uneven number of channels
                var chkChannels = outputChannels % 2;
                if (chkChannels == 1)
                {
                    Log.Warn("BASS: Found uneven number of channels {0}. increase output channels.", outputChannels);
                    outputChannels++;                 // increase the number of output channels
                    wasApiExclusiveSupported = false; // And indicate that we need a new mixer
                }

                // Handle the special cases of 3.0, 4.0 and 5.0 files being played on a 5.1 or 6.1 device
                if (outputChannels == 3) // a 3.0 file
                {
                    Log.Info("BASS: Found a 3 channel file. Set upmixing with LFE, LR, RR set to silent");
                    _mixingMatrix            = CreateThreeDotZeroUpMixMatrix();
                    outputChannels           = _bassPlayer.DeviceChannels; // WASAPI device should be initialised with all channels active
                    wasApiExclusiveSupported = false;                      // And indicate that we need a new mixer
                }
                else if (outputChannels == 4)                              // a 4.0 file
                {
                    Log.Info("BASS: Found a 4 channel file. Set upmixing with Center and LFE set to silent");
                    _mixingMatrix            = CreateFourDotZeroUpMixMatrix();
                    outputChannels           = _bassPlayer.DeviceChannels; // WASAPI device should be initialised with all channels active
                    wasApiExclusiveSupported = false;                      // And indicate that we need a new mixer
                }
                else if (outputChannels == 5)                              // a 5.0 file
                {
                    Log.Info("BASS: Found a 5 channel file. Set upmixing with LFE set to silent");
                    _mixingMatrix            = CreateFiveDotZeroUpMixMatrix();
                    outputChannels           = _bassPlayer.DeviceChannels; // WASAPI device should be initialised with all channels active
                    wasApiExclusiveSupported = false;                      // And indicate that we need a new mixer
                }

                // If Exclusive mode is used, check, if that would be supported, otherwise init in shared mode
                if (Config.WasApiExclusiveMode)
                {
                    initFlags        |= BASSWASAPIInit.BASS_WASAPI_EXCLUSIVE;
                    _wasapiShared     = false;
                    _wasapiMixedChans = 0;
                    _wasapiMixedFreq  = 0;

                    BASSWASAPIFormat wasapiFormat = BassWasapi.BASS_WASAPI_CheckFormat(_bassPlayer.DeviceNumber,
                                                                                       stream.ChannelInfo.freq,
                                                                                       outputChannels,
                                                                                       BASSWASAPIInit.BASS_WASAPI_EXCLUSIVE);
                    if (wasapiFormat == BASSWASAPIFormat.BASS_WASAPI_FORMAT_UNKNOWN)
                    {
                        Log.Warn("BASS: WASAPI exclusive mode not directly supported. Let BASS WASAPI choose better mode.");
                        wasApiExclusiveSupported = false;
                    }
                }
                else
                {
                    Log.Debug("BASS: Init WASAPI shared mode with Event driven system enabled.");
                    initFlags |= BASSWASAPIInit.BASS_WASAPI_SHARED | BASSWASAPIInit.BASS_WASAPI_EVENT;

                    // In case of WASAPI Shared mode we need to setup the mixer to use the same sample rate as set in
                    // the Windows Mixer, otherwise we wioll have increased playback speed
                    BASS_WASAPI_DEVICEINFO devInfo = BassWasapi.BASS_WASAPI_GetDeviceInfo(_bassPlayer.DeviceNumber);
                    Log.Debug("BASS: Creating {0} channel mixer for frequency {1}", devInfo.mixchans, devInfo.mixfreq);
                    _mixer = BassMix.BASS_Mixer_StreamCreate(devInfo.mixfreq, devInfo.mixchans, mixerFlags);
                    if (_mixer == 0)
                    {
                        Log.Error("BASS: Unable to create Mixer.  Reason: {0}.",
                                  Enum.GetName(typeof(BASSError), Bass.BASS_ErrorGetCode()));
                        return(false);
                    }
                    _wasapiShared = true;
                }

                Log.Debug("BASS: Try to init WASAPI with a Frequency of {0} and {1} channels", stream.ChannelInfo.freq, outputChannels);

                if (BassWasapi.BASS_WASAPI_Init(_bassPlayer.DeviceNumber, stream.ChannelInfo.freq, outputChannels,
                                                initFlags | BASSWASAPIInit.BASS_WASAPI_BUFFER, Convert.ToSingle(Config.BufferingMs / 1000.0), 0f, _wasapiProc, IntPtr.Zero))
                {
                    BASS_WASAPI_INFO wasapiInfo = BassWasapi.BASS_WASAPI_GetInfo();

                    Log.Debug("BASS: ---------------------------------------------");
                    Log.Debug("BASS: Buffer Length: {0}", wasapiInfo.buflen);
                    Log.Debug("BASS: Channels: {0}", wasapiInfo.chans);
                    Log.Debug("BASS: Frequency: {0}", wasapiInfo.freq);
                    Log.Debug("BASS: Format: {0}", wasapiInfo.format.ToString());
                    Log.Debug("BASS: InitFlags: {0}", wasapiInfo.initflags.ToString());
                    Log.Debug("BASS: Exclusive: {0}", wasapiInfo.IsExclusive.ToString());
                    Log.Debug("BASS: ---------------------------------------------");
                    Log.Info("BASS: WASAPI Device successfully initialised");

                    // Now we need to check, if WASAPI decided to switch to a different mode
                    if (Config.WasApiExclusiveMode && !wasApiExclusiveSupported)
                    {
                        // Recreate Mixer with new value
                        Log.Debug("BASS: Creating new {0} channel mixer for frequency {1}", wasapiInfo.chans, wasapiInfo.freq);
                        _mixer = BassMix.BASS_Mixer_StreamCreate(wasapiInfo.freq, wasapiInfo.chans, mixerFlags);
                        if (_mixer == 0)
                        {
                            Log.Error("BASS: Unable to create Mixer.  Reason: {0}.",
                                      Enum.GetName(typeof(BASSError), Bass.BASS_ErrorGetCode()));
                            return(false);
                        }
                    }

                    BassWasapi.BASS_WASAPI_SetVolume(BASSWASAPIVolume.BASS_WASAPI_CURVE_DB, (float)Config.StreamVolume / 100f);
                    BassWasapi.BASS_WASAPI_Start();
                    result = true;
                }
                else
                {
                    Log.Error("BASS: Couldn't init WASAPI device. Error: {0}", Enum.GetName(typeof(BASSError), Bass.BASS_ErrorGetCode()));
                }
                break;
            }

            if (result)
            {
                Log.Debug("BASS: Successfully created BASS Mixer stream");
            }
            return(result);
        }
Пример #28
0
    /// <summary>
    /// Initialises the Wasapi Device
    /// </summary>
    /// <returns></returns>
    private bool InitWasapi()
    {
      bool result = false;

      Log.Info("BASS: Using WASAPI device: {0}", Config.SoundDevice);
      BASS_WASAPI_DEVICEINFO[] wasapiDevices = BassWasapi.BASS_WASAPI_GetDeviceInfos();

      int i = 0;
      // Check if the WASAPI device read is amongst the one retrieved
      for (i = 0; i < wasapiDevices.Length; i++)
      {
        if (wasapiDevices[i].name == Config.SoundDevice && wasapiDevices[i].id == Config.SoundDeviceID)
        {
          _deviceNumber = i;
          break;
        }
      }

      if (_deviceNumber > -1)
      {
        // Get some information about the Device
        _wasapiDeviceInfo = wasapiDevices[i];
        if (_wasapiDeviceInfo != null)
        {
          // Get the number of supported speakers from Config
          _deviceOutputChannels = GetWasApiSpeakers();

          Log.Info("BASS: Device Information");
          Log.Info("BASS: ---------------------------------------------");
          Log.Info("BASS: Name: {0}", _wasapiDeviceInfo.name);
          Log.Debug("BASS: Id: {0}", _wasapiDeviceInfo.id);
          Log.Debug("BASS: Type: {0}", _wasapiDeviceInfo.type.ToString());
          Log.Info("BASS: Shared Mode Channels: {0}", _wasapiDeviceInfo.mixchans);
          Log.Info("BASS: Shared Mode Samplerate: {0}", _wasapiDeviceInfo.mixfreq);
          GetWasApiFormats();
          Log.Info("BASS: ---------------------------------------------");

          result = true;
        }
        else
        {
          Log.Error("BASS: Error getting Device Info: {0}", Bass.BASS_ErrorGetCode());
        }
      }
      else
      {
        Log.Error("BASS: Specified WASAPI device not found. BASS is disabled.");
      }

      return result;
    }
Пример #29
0
 public static extern bool BASS_WASAPI_GetDeviceInfo(
     int device,
     BASS_WASAPI_DEVICEINFO info
     );