Esempio n. 1
0
        private void SimpleAsio_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (_asioOut != null)
            {
                _asioOut.Dispose();
            }
            if (_asioIn != null)
            {
                _asioIn.Dispose();
            }

            // free all ASIO devices
            for (int i = 0; i < this.comboBoxAsioOutputDevice.Items.Count; i++)
            {
                BassAsio.BASS_ASIO_SetDevice(i);
                BassAsio.BASS_ASIO_Free();
            }

            // free all BASS devices
            int n = 0;

            foreach (BASS_DEVICEINFO info in this.comboBoxBassDevice.Items)
            {
                Bass.BASS_SetDevice(n);
                Bass.BASS_Free();
                n++;
            }
        }
Esempio n. 2
0
        public void Evaluate(int SpreadMax)
        {
            #region Channel and device
            if (this.FPinInDevice.PinIsChanged ||
                this.FPinInEnabled.PinIsChanged ||
                this.FPinChannelCount.PinIsChanged ||
                this.FPinChannelIndex.PinIsChanged)
            {
                double ddevice;
                this.FPinInDevice.GetValue(0, out ddevice);
                int device = Convert.ToInt32(ddevice);

                if (device != -1)
                {
                    if (this.FChannelInfo.BassHandle.HasValue)
                    {
                        Bass.BASS_ChannelStop(this.FChannelInfo.BassHandle.Value);
                        Bass.BASS_StreamFree(this.FChannelInfo.BassHandle.Value);
                    }
                    this.manager.Delete(this.FChannelInfo.InternalHandle);

                    double enabled;
                    this.FPinInEnabled.GetValue(0, out enabled);
                    if (enabled >= 0.5)
                    {
                        double chancount, index;
                        this.FPinChannelCount.GetValue(0, out chancount);
                        this.FPinChannelIndex.GetValue(0, out index);

                        BassAsio.BASS_ASIO_Init(device);
                        BassAsio.BASS_ASIO_SetDevice(device);

                        this.FChannelInfo       = new InputChannelInfo();
                        this.FChannelInfo.Count = Convert.ToInt32(chancount);
                        this.FChannelInfo.Index = Convert.ToInt32(index);

                        this.manager.CreateChannel(this.FChannelInfo);
                        this.FChannelInfo.Initialize(device);

                        this.FPinOutHandle.SetValue(0, this.FChannelInfo.InternalHandle);

                        this.FPinOutStatus.SetString(0, "OK");
                    }
                    else
                    {
                        this.FPinOutHandle.SetValue(0, 0);
                        this.FPinOutStatus.SetString(0, "Disabled");
                    }
                }
            }
            #endregion
        }
Esempio n. 3
0
        public void Asio_Setup(int dev)
        {
            if (!(dev == -1))
            {
                BassAsio.BASS_ASIO_Free();                             //przygotowanie BASS_Asio - zwolnienie istniejącego i
                Bass.BASS_Free();
                BassAsio.BASS_ASIO_SetDevice(dev);                     //wybór urządzenia

                if (!BassAsio.BASS_ASIO_Init(dev, 0))                  //inicjacja urządzenia + przechwycenie wyjątku
                {
                    BASSError blad = BassAsio.BASS_ASIO_ErrorGetCode(); MessageBox.Show("błąd inicjalizacji: " + blad.ToString());
                }
                else
                {
                    Bass.BASS_Init(-1, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);

                    int strumien = Bass.BASS_StreamCreateFile(_hGCFile.AddrOfPinnedObject(), 0L, length, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
                    _myAsioProc = new Un4seen.BassAsio.ASIOPROC(AsioCallback);
                    BassAsio.BASS_ASIO_ChannelEnable(false, 0, _myAsioProc, new IntPtr(strumien));
                    int num_ch = 0;


                    if (binaural)
                    {
                        first_ch = Convert.ToInt16(textBox1.Text);
                        num_ch   = 2;
                    }
                    else
                    {
                        num_ch   = BitConverter.ToUInt16(audio_buffer, 22);
                        first_ch = 0;
                    }

                    for (int i = first_ch; i < num_ch + first_ch; i++)
                    {
                        BassAsio.BASS_ASIO_ChannelSetFormat(false, i, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT);
                    }
                    for (int i = first_ch + 1; i < num_ch + first_ch; i++)
                    {
                        BassAsio.BASS_ASIO_ChannelJoin(false, i, 0);
                    }
                }
            }
        }
Esempio n. 4
0
        private void comboBoxAsioInputDevice_SelectedIndexChanged(object sender, EventArgs e)
        {
            // get the available Asio channels
            this.comboBoxAsioInputChannel.Items.Clear();
            this.comboBoxAsioInputChannel.Text = "";
            int n = this.comboBoxAsioInputDevice.SelectedIndex;

            if (BassAsio.BASS_ASIO_GetDevice() == n || BassAsio.BASS_ASIO_SetDevice(n))
            {
                BASS_ASIO_INFO info = BassAsio.BASS_ASIO_GetInfo();
                if (info != null)
                {
                    // assuming stereo input
                    for (int i = 0; i < info.inputs; i += 2)
                    {
                        BASS_ASIO_CHANNELINFO chanInfo = BassAsio.BASS_ASIO_ChannelGetInfo(true, i);
                        if (chanInfo != null)
                        {
                            this.comboBoxAsioInputChannel.Items.Add(chanInfo);
                        }
                    }
                    if (this.comboBoxAsioInputChannel.Items.Count > 0)
                    {
                        this.comboBoxAsioInputChannel.SelectedIndex = 0;
                    }
                }
                else
                {
                    MessageBox.Show(String.Format("AsioError = {0}", BassAsio.BASS_ASIO_ErrorGetCode()));
                }
            }
            else
            {
                MessageBox.Show(String.Format("AsioError = {0}", BassAsio.BASS_ASIO_ErrorGetCode()));
            }
        }
Esempio n. 5
0
 public static void Start()
 {
     BassAsio.BASS_ASIO_SetDevice(m_asiodevice);
     BassAsio.BASS_ASIO_Start(0);
 }
Esempio n. 6
0
 /// <summary>
 /// Установка устройства для воспроизведения
 /// </summary>
 /// <param name="device">Номер устройства</param>
 /// <returns></returns>
 protected override bool SetDevice(int device)
 {
     return(BassAsio.BASS_ASIO_SetDevice(device));
 }
Esempio n. 7
0
        public void Evaluate(int SpreadMax)
        {
            try
            {
                #region Channel and device
                if (this.FPinInChannels.PinIsChanged || this.FPinInDevice.PinIsChanged)
                {
                    double dbldevice;
                    this.FPinInDevice.GetValue(0, out dbldevice);

                    this.FDeviceIndex = Convert.ToInt32(dbldevice);
                    if (this.FDeviceIndex != -1)
                    {
                        BassAsio.BASS_ASIO_Init(this.FDeviceIndex);
                        BassAsio.BASS_ASIO_SetDevice(this.FDeviceIndex);
                    }

                    this.FOutputHandled.Clear();
                    BassAsio.BASS_ASIO_Stop();

                    BassAsio.BASS_ASIO_ChannelReset(false, -1, BASSASIOReset.BASS_ASIO_RESET_PAUSE | BASSASIOReset.BASS_ASIO_RESET_JOIN);

                    if (this.FDeviceIndex != -1 && this.FPinInChannels.IsConnected)
                    {
                        int    asiooutindex = 0;
                        double dhandle;
                        for (int i = 0; i < this.FPinInChannels.SliceCount; i++)
                        {
                            this.FPinInChannels.GetValue(i, out dhandle);
                            int handle = Convert.ToInt32(dhandle);

                            if (handle != 0 && handle != -1)
                            {
                                ChannelInfo channel = this.manager.GetChannel(handle);

                                if (channel.BassHandle == null)
                                {
                                    //Initialize channel (in nosound)
                                    channel.Initialize(0);
                                }

                                //Check if the channel has its own handler
                                if (!BassAsioUtils.InputChannels.ContainsKey(handle))
                                {
                                    BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(channel.BassHandle.Value);

                                    BassAsio.BASS_ASIO_ChannelEnable(false, asiooutindex, myAsioProc, new IntPtr(handle));
                                    if (info.chans == 1)
                                    {
                                        //No need to join on mono channels
                                        asiooutindex++;
                                    }
                                    else
                                    {
                                        for (int chan = 1; chan < info.chans; chan++)
                                        {
                                            bool join = BassAsio.BASS_ASIO_ChannelJoin(false, asiooutindex + chan, asiooutindex);
                                            if (!join)
                                            {
                                                this.FHost.Log(TLogType.Error, "Error: join failed");
                                                this.FHost.Log(TLogType.Error, BassAsio.BASS_ASIO_ErrorGetCode().ToString());
                                            }
                                        }

                                        BassAsio.BASS_ASIO_ChannelSetFormat(false, asiooutindex, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT);
                                        BassAsio.BASS_ASIO_ChannelSetRate(false, asiooutindex, (double)info.freq);
                                        BassAsio.BASS_ASIO_SetRate((double)info.freq);

                                        asiooutindex += info.chans;
                                    }
                                }
                                else
                                {
                                    BassAsioHandler handler = BassAsioUtils.InputChannels[handle].Handler;
                                    handler.SetMirror(asiooutindex);
                                    asiooutindex += 2;
                                    this.FOutputHandled.Add(asiooutindex);
                                    this.FOutputHandled.Add(asiooutindex + 1);
                                }
                            }
                        }

                        bool start = BassAsio.BASS_ASIO_Start(0);
                        if (!start)
                        {
                            this.FPinErrorCode.SetString(0, BassAsio.BASS_ASIO_ErrorGetCode().ToString());
                            this.FHost.Log(TLogType.Error, "Error: Start failed");
                            this.FHost.Log(TLogType.Error, BassAsio.BASS_ASIO_ErrorGetCode().ToString());
                        }
                        else
                        {
                            this.FPinErrorCode.SetString(0, "OK");
                        }

                        UpdateChannels();
                    }
                }

                if (FControlPanel.PinIsChanged)
                {
                    double v;
                    FControlPanel.GetValue(0, out v);
                    if (v > 0.5)
                    {
                        BassAsio.BASS_ASIO_ControlPanel();
                    }
                }
                #endregion

                #region Volume
                if (this.FPinInVolumeOutput.PinIsChanged)
                {
                    if (this.FDeviceIndex != -1 || this.FPinInVolumeOutput.SliceCount > 0)
                    {
                        BASS_ASIO_INFO deviceinfo = BassAsio.BASS_ASIO_GetInfo();

                        int current = 0;
                        for (int i = 0; i < deviceinfo.outputs; i++)
                        {
                            double vol;

                            this.FPinInVolumeOutput.GetValue(current, out vol);
                            BassAsio.BASS_ASIO_ChannelSetVolume(false, i, (float)vol);

                            //Bin for the channels
                            current++;
                            if (current == this.FPinInVolumeOutput.SliceCount)
                            {
                                current = 0;
                            }
                        }
                    }
                }
                #endregion

                #region Is Active Pin
                if (this.FPinInActive.PinIsChanged)
                {
                    UpdateChannels();
                }
                #endregion
            }
            catch (Exception ex)
            {
                this.FHost.Log(TLogType.Error, ex.Message);
                this.FHost.Log(TLogType.Error, ex.StackTrace);
            }
        }