Ejemplo n.º 1
0
 private void AsioRecording_Load(object sender, System.EventArgs e)
 {
     // we don't play via Bass, but only via BassAsio
     // not playing anything via BASS, so don't need an update thread
     Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0);
     // setup BASS - "no sound" device and Init first Asio device
     if (Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, this.Handle) &&
         BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_DEFAULT))
     {
         // just here as a demo ;-)
         BASS_ASIO_CHANNELINFO info = new BASS_ASIO_CHANNELINFO();
         int chan = 0;
         while (true)
         {
             if (!BassAsio.BASS_ASIO_ChannelGetInfo(false, chan, info))
             {
                 break;
             }
             Console.WriteLine(info.ToString());
             chan++;
         }
     }
     else
     {
         MessageBox.Show(this, "Bass_Init error!");
     }
 }
Ejemplo n.º 2
0
        private void SimpleAsio_Load(object sender, System.EventArgs e)
        {
            //BassNet.Registration("your email", "your regkey");

            // get the Asio devices and init them
            this.comboBoxAsioOutputDevice.Items.AddRange(BassAsio.BASS_ASIO_GetDeviceInfos());
            for (int i = 0; i < this.comboBoxAsioOutputDevice.Items.Count; i++)
            {
                if (!BassAsio.BASS_ASIO_Init(i, BASSASIOInit.BASS_ASIO_DEFAULT))
                {
                    this.comboBoxAsioOutputDevice.Items[i] = BassAsio.BASS_ASIO_ErrorGetCode();
                }
            }
            this.comboBoxAsioOutputDevice.SelectedIndex = 0;
            this.comboBoxAsioInputDevice.Items.AddRange(BassAsio.BASS_ASIO_GetDeviceInfos());
            this.comboBoxAsioInputDevice.SelectedIndex = this.comboBoxAsioOutputDevice.SelectedIndex;

            // get the bass devices, init them and set the default one
            this.comboBoxBassDevice.Items.AddRange(Bass.BASS_GetDeviceInfos());
            int n = 0;

            foreach (BASS_DEVICEINFO info in this.comboBoxBassDevice.Items)
            {
                Bass.BASS_Init(n, 44100, BASSInit.BASS_DEVICE_DEFAULT, this.Handle);
                if (info.IsDefault)
                {
                    this.comboBoxBassDevice.SelectedItem = info;
                }
                n++;
            }
        }
Ejemplo n.º 3
0
        private void DefaultASIOAudioOutput_Load(object sender, EventArgs e)
        {
            try
            {
                int n;
                int selecteddeviceprev    = (int)KeppySynthConfiguratorMain.SynthSettings.GetValue("defaultAdev", 0);
                BASS_ASIO_DEVICEINFO info = new BASS_ASIO_DEVICEINFO();
                BassAsio.BASS_ASIO_GetDeviceInfo(selecteddeviceprev, info);
                DefOut.Text = String.Format("Def. ASIO output: {0}", info.ToString());
                for (n = 0; BassAsio.BASS_ASIO_GetDeviceInfo(n, info); n++)
                {
                    DevicesList.Items.Add(info.ToString());
                }

                if (n < 1)
                {
                    Functions.ShowErrorDialog(1, System.Media.SystemSounds.Asterisk, "Error", "No ASIO devices installed!\n\nClick OK to close this window.", false, null);
                    Close();
                    return;
                }

                DevicesList.SelectedIndex = selecteddeviceprev;
                MaxThreads.Text           = String.Format("ASIO is allowed to use a maximum of {0} threads.", Environment.ProcessorCount);
                BassAsio.BASS_ASIO_Init(DevicesList.SelectedIndex, 0);

                DeviceTrigger();
                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.Message.ToString(), "Oh no! Keppy's Synthesizer encountered an error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
                Dispose();
            }
        }
Ejemplo n.º 4
0
        public OutputASIO(string DeviceName, int Frequency, GetSampleDelegate Callback24, GetSampleDelegate Callback16, Player Player)
            : base(DeviceName, Player)
        {
            needsUnload = true;

            playing = false;

            callback16 = Callback16;
            callback24 = Callback24;

            deviceNum = getDeviceNum(DeviceName);

            if (initializedDevice >= 0)
            {
                BassAsio.BASS_ASIO_Free();
                initializedDevice = -1;
            }

            if (deviceNum < 0 || !BassAsio.BASS_ASIO_Init(deviceNum))
            {
                System.Diagnostics.Debug.WriteLine(BassAsio.BASS_ASIO_ErrorGetCode());
                return;
            }

            initializedDevice = deviceNum;

            if (!setup(Frequency))
            {
                return;
            }

            playing = true;
        }
Ejemplo n.º 5
0
        public DefaultASIOAudioOutput()
        {
            InitializeComponent();

            try
            {
                if (GetASIODevicesCount() < 1)
                {
                    Functions.ShowErrorDialog(ErrorType.Error, System.Media.SystemSounds.Asterisk, "Error", "No ASIO devices installed!\n\nClick OK to close this window.", false, null);
                    Close();
                    Dispose();
                }

                BASS_ASIO_DEVICEINFO info = new BASS_ASIO_DEVICEINFO();

                // Populate devices list
                for (int n = 0; BassAsio.BASS_ASIO_GetDeviceInfo(n, info); n++)
                {
                    DevicesList.Items.Add(info.ToString());
                }

                // Load previous device from registry
                String PreviousDevice = (String)OmniMIDIConfiguratorMain.SynthSettings.GetValue("ASIOOutput", "None");
                DefOut.Text = String.Format("Def. ASIO output: {0}", PreviousDevice);

                DevicesList.SelectedIndex = 0;
                for (int n = 0; n < DevicesList.Items.Count; n++)
                {
                    if (DevicesList.Items[n].Equals(PreviousDevice))
                    {
                        DevicesList.SelectedIndex = n;
                        break;
                    }
                }

                MaxThreads.Text = String.Format("ASIO is allowed to use a maximum of {0} threads.", Environment.ProcessorCount);

                BassAsio.BASS_ASIO_Init(DevicesList.SelectedIndex, BASSASIOInit.BASS_ASIO_THREAD | BASSASIOInit.BASS_ASIO_JOINORDER);
                GetASIODeviceInfo();

                DeviceTrigger(true);
                DevicesList.SelectedIndexChanged += new EventHandler(DevicesList_SelectedIndexChanged);

                /*
                 * Unavailable at the moment
                 *
                 * if (Convert.ToInt32(OmniMIDIConfiguratorMain.SynthSettings.GetValue("ASIOSeparateThread", 0)) == 1)
                 * ASIOSeparateThread.Checked = true;
                 *
                 */
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to load the dialog.\nBASS is probably unable to start, or it's missing.\n\nError:\n" + ex.Message.ToString(), "Oh no! OmniMIDI encountered an error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
                Dispose();
            }
        }
Ejemplo n.º 6
0
 private void SimpleAsioFx_Load(object sender, System.EventArgs e)
 {
     // we don't play via Bass, but only via BassAsio
     // setup BASS - "no sound" device but 48000 (default for ASIO)
     if (!Bass.BASS_Init(0, 48000, 0, this.Handle) || !BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_DEFAULT))
     {
         MessageBox.Show(this, "Bass_Init error!");
     }
 }
Ejemplo n.º 7
0
        private void DevicesList_SelectedIndexChanged(object sender, EventArgs e)
        {
            DeviceCP.Enabled = true;

            BassAsio.BASS_ASIO_Free();
            BassAsio.BASS_ASIO_Init(DevicesList.SelectedIndex, BASSASIOInit.BASS_ASIO_THREAD | BASSASIOInit.BASS_ASIO_JOINORDER);
            GetASIODeviceInfo();

            DeviceTrigger(false);
        }
Ejemplo n.º 8
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
        }
Ejemplo n.º 9
0
        private void DevicesList_SelectedIndexChanged(object sender, EventArgs e)
        {
            Functions.SetDefaultDevice(1, DevicesList.SelectedIndex);
            BassAsio.BASS_ASIO_Free();
            BassAsio.BASS_ASIO_Init(DevicesList.SelectedIndex, 0);
            int value = DeviceTrigger();

            if (value == DeviceStatus.DEVICE_UNSTABLE)
            {
                MessageBox.Show("This device might crash the app, while in use.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (value == DeviceStatus.DEVICE_UNSUPPORTED)
            {
                MessageBox.Show("This device is unsupported.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Show the ASIO Devices Control Panel
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btAsioDeviceSettings_Click(object sender, EventArgs e)
 {
     // Free ASIO and reinit it again
     BassAsio.BASS_ASIO_Free();
     if (BassAsio.BASS_ASIO_Init(soundDeviceComboBox.SelectedIndex, BASSASIOInit.BASS_ASIO_DEFAULT))
     {
         if (!BassAsio.BASS_ASIO_ControlPanel())
         {
             MessageBox.Show(this, "Selected ASIO device does not have a Control Panel",
                             "MediaPortal - Setup", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
     }
     else
     {
         MessageBox.Show(this, "Error initialising the selected ASIO device",
                         "MediaPortal - Setup", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
Ejemplo n.º 11
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);
                    }
                }
            }
        }
Ejemplo n.º 12
0
 private void asioDeviceComboBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     // Free the selecetd device and activate the new one
     BassAsio.BASS_ASIO_Free();
     if (BassAsio.BASS_ASIO_Init(asioDeviceComboBox.SelectedIndex))
     {
         BASS_ASIO_INFO info = BassAsio.BASS_ASIO_GetInfo();
         if (info != null)
         {
             lbNumberOfChannels.Text = String.Format("Selected device has {0} output channel(s).", info.outputs);
         }
         else
         {
             lbNumberOfChannels.Text = "Couldn't get channel information for selected device";
         }
     }
     else
     {
         MessageBox.Show(this, "Error initialising the selected ASIO device",
                         "MediaPortal - Setup", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Load ASIO Settings
        /// </summary>
        public override void LoadSettings()
        {
            using (Settings xmlreader = new MPSettings())
            {
                bool   _useASIO            = xmlreader.GetValueAsBool("audioplayer", "asio", false);
                string _asioDeviceSelected = xmlreader.GetValueAsString("audioplayer", "asiodevice", "None");
                hScrollBarBalance.Value = xmlreader.GetValueAsInt("audioplayer", "asiobalance", 0);
                useASIOCheckBox.Checked = _useASIO;

                if (_useASIO)
                {
                    BASS_ASIO_DEVICEINFO[] asioDevices = BassAsio.BASS_ASIO_GetDeviceInfos();
                    // Check if the ASIO device read is amongst the one retrieved
                    bool found = false;
                    for (int i = 0; i < asioDevices.Length; i++)
                    {
                        if (asioDevices[i].name == _asioDeviceSelected)
                        {
                            found = true;
                            bool rc = BassAsio.BASS_ASIO_Init(i);
                            break;
                        }
                    }
                    if (found)
                    {
                        asioDeviceComboBox.SelectedItem = _asioDeviceSelected;
                    }
                    else
                    {
                        Log.Warn("Selected ASIO Device not found. {0}", _asioDeviceSelected);
                    }
                }
                else
                {
                    asioDeviceComboBox.Enabled = false;
                    btSettings.Enabled         = false;
                }
            }
        }
 private void DefaultASIOAudioOutput_Load(object sender, EventArgs e)
 {
     try
     {
         int selecteddeviceprev    = (int)KeppySynthConfiguratorMain.SynthSettings.GetValue("defaultAdev", 0);
         BASS_ASIO_DEVICEINFO info = new BASS_ASIO_DEVICEINFO();
         BassAsio.BASS_ASIO_GetDeviceInfo(selecteddeviceprev, info);
         DefOut.Text = String.Format("Def. ASIO output: {0}", info.ToString());
         for (int n = 0; BassAsio.BASS_ASIO_GetDeviceInfo(n, info); n++)
         {
             DevicesList.Items.Add(info.ToString());
         }
         DevicesList.SelectedIndex = selecteddeviceprev;
         MaxThreads.Text           = String.Format("ASIO is allowed to use a maximum of {0} threads.", Environment.ProcessorCount);
         BassAsio.BASS_ASIO_Init(DevicesList.SelectedIndex, 0);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Unable to load the dialog.\nBASS is probably unable to start, or it's missing.\n\nError:\n" + ex.Message.ToString(), "Oh no! Keppy's Synthesizer encountered an error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
         Close();
         Dispose();
     }
 }
 private void DevicesList_SelectedIndexChanged(object sender, EventArgs e)
 {
     Functions.SetDefaultDevice(1, DevicesList.SelectedIndex);
     BassAsio.BASS_ASIO_Free();
     BassAsio.BASS_ASIO_Init(DevicesList.SelectedIndex, 0);
 }
Ejemplo n.º 16
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);
            }
        }
Ejemplo n.º 17
0
        // メソッド

        public CSoundDeviceASIO(long n希望バッファサイズms, int _nASIODevice)
        {
            // 初期化。

            Trace.TraceInformation("BASS (ASIO) の初期化を開始します。");
            this.e出力デバイス            = ESoundDeviceType.Unknown;
            this.n実出力遅延ms           = 0;
            this.n経過時間ms            = 0;
            this.n経過時間を更新したシステム時刻ms = CTimer.n未使用;
            this.tmシステムタイマ          = new CTimer();
            this.nASIODevice        = _nASIODevice;

            #region [ BASS registration ]
            // BASS.NET ユーザ登録(BASSスプラッシュが非表示になる)。
            BassNet.Registration("*****@*****.**", "2X9181017152222");
            #endregion

            #region [ BASS Version Check ]
            // BASS のバージョンチェック。
            int nBASSVersion = Utils.HighWord(Bass.BASS_GetVersion());
            if (nBASSVersion != Bass.BASSVERSION)
            {
                throw new DllNotFoundException(string.Format("bass.dll のバージョンが異なります({0})。このプログラムはバージョン{1}で動作します。", nBASSVersion, Bass.BASSVERSION));
            }

            int nBASSMixVersion = Utils.HighWord(BassMix.BASS_Mixer_GetVersion());
            if (nBASSMixVersion != BassMix.BASSMIXVERSION)
            {
                throw new DllNotFoundException(string.Format("bassmix.dll のバージョンが異なります({0})。このプログラムはバージョン{1}で動作します。", nBASSMixVersion, BassMix.BASSMIXVERSION));
            }

            int nBASSASIO = Utils.HighWord(BassAsio.BASS_ASIO_GetVersion());
            if (nBASSASIO != BassAsio.BASSASIOVERSION)
            {
                throw new DllNotFoundException(string.Format("bassasio.dll のバージョンが異なります({0})。このプログラムはバージョン{1}で動作します。", nBASSASIO, BassAsio.BASSASIOVERSION));
            }
            #endregion

            // BASS の設定。

            this.bIsBASSFree = true;

            if (!Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0))           // 0:BASSストリームの自動更新を行わない。
            {
                Trace.TraceWarning($"BASS_SetConfig({nameof(BASSConfig.BASS_CONFIG_UPDATEPERIOD)}) に失敗しました。[{Bass.BASS_ErrorGetCode()}]");
            }
            if (!Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATETHREADS, 0))           // 0:BASSストリームの自動更新を行わない。
            {
                Trace.TraceWarning($"BASS_SetConfig({nameof(BASSConfig.BASS_CONFIG_UPDATETHREADS)}) に失敗しました。[{Bass.BASS_ErrorGetCode()}]");
            }

            // BASS の初期化。

            int nデバイス = 0;                      // 0:"no device" … BASS からはデバイスへアクセスさせない。アクセスは BASSASIO アドオンから行う。
            int n周波数  = 44100;                  // 仮決め。最終的な周波数はデバイス(≠ドライバ)が決める。
            if (!Bass.BASS_Init(nデバイス, n周波数, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero))
            {
                throw new Exception(string.Format("BASS の初期化に失敗しました。(BASS_Init)[{0}]", Bass.BASS_ErrorGetCode().ToString()));
            }

            Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_CURVE_VOL, true);

//Debug.WriteLine( "BASS_Init()完了。" );
            #region [ デバッグ用: ASIOデバイスのenumerateと、ログ出力 ]
//			CEnumerateAllAsioDevices.GetAllASIODevices();
//Debug.WriteLine( "BassAsio.BASS_ASIO_GetDeviceInfo():" );
//            int a, count = 0;
//            BASS_ASIO_DEVICEINFO asioDevInfo;
//            for ( a = 0; ( asioDevInfo = BassAsio.BASS_ASIO_GetDeviceInfo( a ) ) != null; a++ )
//            {
//                Trace.TraceInformation( "ASIO Device {0}: {1}, driver={2}", a, asioDevInfo.name, asioDevInfo.driver );
//                count++; // count it
//            }
            #endregion

            // BASS ASIO の初期化。
            BASS_ASIO_INFO asioInfo = null;
            if (BassAsio.BASS_ASIO_Init(nASIODevice, BASSASIOInit.BASS_ASIO_THREAD))                    // 専用スレッドにて起動
            {
                #region [ ASIO の初期化に成功。]
                //-----------------
                this.e出力デバイス           = ESoundDeviceType.ASIO;
                asioInfo               = BassAsio.BASS_ASIO_GetInfo();
                this.n出力チャンネル数         = asioInfo.outputs;
                this.db周波数             = BassAsio.BASS_ASIO_GetRate();
                this.fmtASIOデバイスフォーマット = BassAsio.BASS_ASIO_ChannelGetFormat(false, 0);

                Trace.TraceInformation("BASS を初期化しました。(ASIO, デバイス:\"{0}\", 入力{1}, 出力{2}, {3}Hz, バッファ{4}~{6}sample ({5:0.###}~{7:0.###}ms), デバイスフォーマット:{8})",
                                       asioInfo.name,
                                       asioInfo.inputs,
                                       asioInfo.outputs,
                                       this.db周波数.ToString("0.###"),
                                       asioInfo.bufmin, asioInfo.bufmin * 1000 / this.db周波数,
                                       asioInfo.bufmax, asioInfo.bufmax * 1000 / this.db周波数,
                                       this.fmtASIOデバイスフォーマット.ToString()
                                       );
                this.bIsBASSFree = false;
                #region [ debug: channel format ]
                //BASS_ASIO_CHANNELINFO chinfo = new BASS_ASIO_CHANNELINFO();
                //int chan = 0;
                //while ( true )
                //{
                //    if ( !BassAsio.BASS_ASIO_ChannelGetInfo( false, chan, chinfo ) )
                //        break;
                //    Debug.WriteLine( "Ch=" + chan + ": " + chinfo.name.ToString() + ", " + chinfo.group.ToString() + ", " + chinfo.format.ToString() );
                //    chan++;
                //}
                #endregion
                //-----------------
                #endregion
            }
            else
            {
                #region [ ASIO の初期化に失敗。]
                //-----------------
                BASSError errcode = Bass.BASS_ErrorGetCode();
                string    errmes  = errcode.ToString();
                if (errcode == BASSError.BASS_OK)
                {
                    errmes = "BASS_OK; The device may be dissconnected";
                }
                Bass.BASS_Free();
                this.bIsBASSFree = true;
                throw new Exception(string.Format("BASS (ASIO) の初期化に失敗しました。(BASS_ASIO_Init)[{0}]", errmes));
                //-----------------
                #endregion
            }


            // ASIO 出力チャンネルの初期化。

            this.tAsioProc = new ASIOPROC(this.tAsio処理);                                  // アンマネージに渡す delegate は、フィールドとして保持しておかないとGCでアドレスが変わってしまう。
            if (!BassAsio.BASS_ASIO_ChannelEnable(false, 0, this.tAsioProc, IntPtr.Zero)) // 出力チャンネル0 の有効化。
            {
                #region [ ASIO 出力チャンネルの初期化に失敗。]
                //-----------------
                BassAsio.BASS_ASIO_Free();
                Bass.BASS_Free();
                this.bIsBASSFree = true;
                throw new Exception(string.Format("Failed BASS_ASIO_ChannelEnable() [{0}]", BassAsio.BASS_ASIO_ErrorGetCode().ToString()));
                //-----------------
                #endregion
            }
            for (int i = 1; i < this.n出力チャンネル数; i++)                            // 出力チャネルを全てチャネル0とグループ化する。
            {                                                                   // チャネル1だけを0とグループ化すると、3ch以上の出力をサポートしたカードでの動作がおかしくなる
                if (!BassAsio.BASS_ASIO_ChannelJoin(false, i, 0))
                {
                    #region [ 初期化に失敗。]
                    //-----------------
                    BassAsio.BASS_ASIO_Free();
                    Bass.BASS_Free();
                    this.bIsBASSFree = true;
                    throw new Exception(string.Format("Failed BASS_ASIO_ChannelJoin({1}) [{0}]", BassAsio.BASS_ASIO_ErrorGetCode().ToString(), i));
                    //-----------------
                    #endregion
                }
            }
            if (!BassAsio.BASS_ASIO_ChannelSetFormat(false, 0, this.fmtASIOチャンネルフォーマット))                        // 出力チャンネル0のフォーマット
            {
                #region [ ASIO 出力チャンネルの初期化に失敗。]
                //-----------------
                BassAsio.BASS_ASIO_Free();
                Bass.BASS_Free();
                this.bIsBASSFree = true;
                throw new Exception(string.Format("Failed BASS_ASIO_ChannelSetFormat() [{0}]", BassAsio.BASS_ASIO_ErrorGetCode().ToString()));
                //-----------------
                #endregion
            }

            // ASIO 出力と同じフォーマットを持つ BASS ミキサーを作成。

            var flag = BASSFlag.BASS_MIXER_NONSTOP | BASSFlag.BASS_STREAM_DECODE;               // デコードのみ=発声しない。ASIO に出力されるだけ。
            if (this.fmtASIOデバイスフォーマット == BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT)
            {
                flag |= BASSFlag.BASS_SAMPLE_FLOAT;
            }
            this.hMixer = BassMix.BASS_Mixer_StreamCreate((int)this.db周波数, this.n出力チャンネル数, flag);

            if (this.hMixer == 0)
            {
                BASSError err = Bass.BASS_ErrorGetCode();
                BassAsio.BASS_ASIO_Free();
                Bass.BASS_Free();
                this.bIsBASSFree = true;
                throw new Exception(string.Format("BASSミキサ(mixing)の作成に失敗しました。[{0}]", err));
            }

            // BASS ミキサーの1秒あたりのバイト数を算出。

            var mixerInfo    = Bass.BASS_ChannelGetInfo(this.hMixer);
            int nサンプルサイズbyte = 0;
            switch (this.fmtASIOチャンネルフォーマット)
            {
            case BASSASIOFormat.BASS_ASIO_FORMAT_16BIT: nサンプルサイズbyte = 2; break;

            case BASSASIOFormat.BASS_ASIO_FORMAT_24BIT: nサンプルサイズbyte = 3; break;

            case BASSASIOFormat.BASS_ASIO_FORMAT_32BIT: nサンプルサイズbyte = 4; break;

            case BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT: nサンプルサイズbyte = 4; break;
            }
            //long nミキサーの1サンプルあたりのバイト数 = /*mixerInfo.chans*/ 2 * nサンプルサイズbyte;
            long nミキサーの1サンプルあたりのバイト数 = mixerInfo.chans * nサンプルサイズbyte;
            this.nミキサーの1秒あたりのバイト数 = nミキサーの1サンプルあたりのバイト数 * mixerInfo.freq;


            // 単純に、hMixerの音量をMasterVolumeとして制御しても、
            // ChannelGetData()の内容には反映されない。
            // そのため、もう一段mixerを噛ませて、一段先のmixerからChannelGetData()することで、
            // hMixerの音量制御を反映させる。
            this.hMixer_DeviceOut = BassMix.BASS_Mixer_StreamCreate(
                (int)this.db周波数, this.n出力チャンネル数, flag);
            if (this.hMixer_DeviceOut == 0)
            {
                BASSError errcode = Bass.BASS_ErrorGetCode();
                BassAsio.BASS_ASIO_Free();
                Bass.BASS_Free();
                this.bIsBASSFree = true;
                throw new Exception(string.Format("BASSミキサ(最終段)の作成に失敗しました。[{0}]", errcode));
            }
            {
                bool b1 = BassMix.BASS_Mixer_StreamAddChannel(this.hMixer_DeviceOut, this.hMixer, BASSFlag.BASS_DEFAULT);
                if (!b1)
                {
                    BASSError errcode = Bass.BASS_ErrorGetCode();
                    BassAsio.BASS_ASIO_Free();
                    Bass.BASS_Free();
                    this.bIsBASSFree = true;
                    throw new Exception(string.Format("BASSミキサ(最終段とmixing)の接続に失敗しました。[{0}]", errcode));
                }
                ;
            }


            // 出力を開始。

            this.nバッファサイズsample = (int)(n希望バッファサイズms * this.db周波数 / 1000.0);
            //this.nバッファサイズsample = (int)  nバッファサイズbyte;
            if (!BassAsio.BASS_ASIO_Start(this.nバッファサイズsample))                         // 範囲外の値を指定した場合は自動的にデフォルト値に設定される。
            {
                BASSError err = BassAsio.BASS_ASIO_ErrorGetCode();
                BassAsio.BASS_ASIO_Free();
                Bass.BASS_Free();
                this.bIsBASSFree = true;
                throw new Exception("ASIO デバイス出力開始に失敗しました。" + err.ToString());
            }
            else
            {
                int n遅延sample   = BassAsio.BASS_ASIO_GetLatency(false);                 // この関数は BASS_ASIO_Start() 後にしか呼び出せない。
                int n希望遅延sample = (int)(n希望バッファサイズms * this.db周波数 / 1000.0);
                this.n実バッファサイズms = this.n実出力遅延ms = (long)(n遅延sample * 1000.0f / this.db周波数);
                Trace.TraceInformation("ASIO デバイス出力開始:バッファ{0}sample(希望{1}) [{2}ms(希望{3}ms)]", n遅延sample, n希望遅延sample, this.n実出力遅延ms, n希望バッファサイズms);
            }
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Инициализация звуковой карты в стандартном режиме.
 /// </summary>
 /// <param name="SoundCard"></param>
 /// <param name="BitRate"></param>
 /// <param name="DeviceProperties"></param>
 public static void Initiate(int SoundCard             = -1, int BitRate = 44100,
                             BASSInit DeviceProperties = BASSInit.BASS_DEVICE_DEFAULT)
 {
     BassAsio.BASS_ASIO_Init(SoundCard, BASSASIOInit.BASS_ASIO_DEFAULT);
 }
Ejemplo n.º 19
0
        public static void SetDevice(int inputChannel, int outputChannel)
        {
            //  Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0);
            //   Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_FLOATDSP, true);
            // BassAsio.BASS_ASIO_Init(0, BASSASIOInit.BASS_ASIO_DEFAULT);
            //   Bass.BASS_Init(0, (int)samplerate, 0, IntPtr.Zero);

            //   m_asioInputHandlers = new BassAsioHandler();
            //   m_asioOutputHandlers = new BassAsioHandler();
            devinfo              = new BASS_ASIO_DEVICEINFO();
            m_asioInputChannels  = new List <object>();
            m_asioOutputChannels = new List <object>();
            thisControl          = PlayerControl.MainFormControl;
            m_inputChannel       = inputChannel;
            m_outputChannel      = outputChannel;

            /*   for (int n = 0; BassAsio.BASS_ASIO_GetDeviceInfo(n, devinfo); n++)
             * {
             *     if (devinfo.name.Contains("ASIO4ALL"))
             *     {
             *         if (!BassAsio.BASS_ASIO_IsStarted())
             *             BassAsio.BASS_ASIO_Init(n, BASSASIOInit.BASS_ASIO_DEFAULT);
             *
             *         samplerate = BassAsio.BASS_ASIO_GetRate();
             *         m_asiodevice = n;
             *
             *         BASS_ASIO_INFO asioinfo = BassAsio.BASS_ASIO_GetInfo();
             *         if (asioinfo != null)
             *         {
             *             // assuming stereo input
             *             for (int i = 0; i < asioinfo.inputs; i += 2)
             *             {
             *                 BASS_ASIO_CHANNELINFO chanInfo = BassAsio.BASS_ASIO_ChannelGetInfo(true, i);
             *                 if (chanInfo != null)
             *                     GetAsioInputChannels.Add(chanInfo);
             *
             *                 if (chanInfo.name.Contains("VB-Audio Point 1"))
             *                     GetVlcAsioInputChannel = i;
             *             }
             *
             *             for (int o = 0; o < asioinfo.outputs; o += 2)
             *             {
             *                 BASS_ASIO_CHANNELINFO chanInfo = BassAsio.BASS_ASIO_ChannelGetInfo(false, o);
             *                 if (chanInfo != null)
             *                     GetAsioOutputChannels.Add(chanInfo);
             *             }
             *         }
             *     }
             *
             * }
             *
             * CreateInputs(m_inputChannel);
             * CreateOutput(m_outputChannel);
             * Connect();
             * int ggg = 0;*/


            for (int n = 0; BassAsio.BASS_ASIO_GetDeviceInfo(n, devinfo); n++)
            {
                if (devinfo.name.Contains("ASIO4ALL"))
                {
                    if (!BassAsio.BASS_ASIO_IsStarted())
                    {
                        BassAsio.BASS_ASIO_Init(n, BASSASIOInit.BASS_ASIO_THREAD);
                    }

                    samplerate   = BassAsio.BASS_ASIO_GetRate();
                    m_asiodevice = n;

                    BASS_ASIO_INFO asioinfo = BassAsio.BASS_ASIO_GetInfo();
                    if (asioinfo != null)
                    {
                        // assuming stereo input
                        for (int i = 0; i < asioinfo.inputs; i += 2)
                        {
                            BASS_ASIO_CHANNELINFO chanInfo = BassAsio.BASS_ASIO_ChannelGetInfo(true, i);
                            if (chanInfo != null)
                            {
                                GetAsioInputChannels.Add(chanInfo);
                            }

                            if (chanInfo.name.Contains("VB-Audio Point 1"))
                            {
                                VlcAsioInputChannel = i;
                            }
                        }

                        for (int o = 0; o < asioinfo.outputs; o += 2)
                        {
                            BASS_ASIO_CHANNELINFO chanInfo = BassAsio.BASS_ASIO_ChannelGetInfo(false, o);
                            if (chanInfo != null)
                            {
                                AsioOutputChannels.Add(chanInfo);
                            }
                        }
                    }

                    BassAsio.BASS_ASIO_ChannelSetVolume(true, m_inputChannel, PlayerControl.MicVolumeScroll.Value * 0.01f);
                    BassAsio.BASS_ASIO_ChannelSetVolume(true, m_inputChannel + 1, PlayerControl.MicVolumeScroll.Value * 0.01f);

                    _asioProc = new ASIOPROC(AsioCallback);
                }
            }

            if (!m_bassinit)
            {
                Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0);
                Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_FLOATDSP, true);
                Bass.BASS_Init(0, 48000, 0, IntPtr.Zero);

                Player.Mixer = MixerStreamCreate((int)samplerate);

                if (Player.Mixer == 0)
                {
                    var error = Bass.BASS_ErrorGetCode();
                    MessageBox.Show(error.ToString(), "Could not create mixer!");
                    Bass.BASS_Free();
                    return;
                }

                m_mixerChannel = Player.Mixer;

                m_streamInputMic = Bass.BASS_StreamCreatePush((int)samplerate, 2, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT, IntPtr.Zero);
                StreamInputVlc   = Bass.BASS_StreamCreatePush((int)samplerate, 2, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT, IntPtr.Zero);

                //m_streamInputMic = Bass.BASS_StreamCreateFile(f, 0L, 0L, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_SAMPLE_LOOP);
                //m_stream[0] = BassMix.BASS_Split_StreamCreate(m_streamInputMic, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE, null);//_instream;
                //m_stream[1] = BassMix.BASS_Split_StreamCreate(m_streamInputMic, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE, null);// _instream;
                //m_stream[2] = BassMix.BASS_Split_StreamCreate(m_streamInputMic, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE, null);//_instream;
                //m_stream[3] = BassMix.BASS_Split_StreamCreate(m_streamInputMic, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE, null);//_instream;


                //Group 1 VST Effects ============================================================
                Channel1Fx.SetEffects(m_streamInputMic);


                //Group 2 VST Effects ============================================================
                // Channel2Fx.SetEffects(m_stream[1]);


                //Group 3 VST Effects ============================================================
                // Channel3Fx.SetEffects(m_stream[2]);


                //Group 4 VST Effects ============================================================
                // Channel4Fx.SetEffects(m_stream[3]);

                BassMix.BASS_Mixer_StreamAddChannel(m_mixerChannel, StreamInputVlc, BASSFlag.BASS_MIXER_DOWNMIX | BASSFlag.BASS_STREAM_AUTOFREE);
                BassMix.BASS_Mixer_StreamAddChannel(m_mixerChannel, m_streamInputMic, BASSFlag.BASS_MIXER_DOWNMIX | BASSFlag.BASS_STREAM_AUTOFREE);
                // BassMix.BASS_Mixer_StreamAddChannel(m_mixerChannel, m_stream[1], BASSFlag.BASS_MIXER_DOWNMIX | BASSFlag.BASS_STREAM_AUTOFREE);
                //BassMix.BASS_Mixer_StreamAddChannel(m_mixerChannel, m_stream[2], BASSFlag.BASS_MIXER_DOWNMIX | BASSFlag.BASS_STREAM_AUTOFREE);
                //BassMix.BASS_Mixer_StreamAddChannel(m_mixerChannel, m_stream[3], BASSFlag.BASS_MIXER_DOWNMIX | BASSFlag.BASS_STREAM_AUTOFREE);
                BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(m_mixerChannel);

                m_bassinit = true;
            }

            //BassAsio.BASS_ASIO_ControlPanel();
            BassAsio.BASS_ASIO_ChannelEnable(true, VlcAsioInputChannel, _asioProc, new IntPtr(StreamInputVlc));
            BassAsio.BASS_ASIO_ChannelJoin(true, VlcAsioInputChannel + 1, VlcAsioInputChannel);
            BassAsio.BASS_ASIO_ChannelSetFormat(true, VlcAsioInputChannel, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT);
            BassAsio.BASS_ASIO_ChannelSetRate(true, VlcAsioInputChannel, samplerate);
            BassAsio.BASS_ASIO_SetRate(samplerate);

            BassAsio.BASS_ASIO_ChannelEnable(true, m_inputChannel, _asioProc, new IntPtr(m_streamInputMic));
            BassAsio.BASS_ASIO_ChannelJoin(true, m_inputChannel + 1, m_inputChannel);
            BassAsio.BASS_ASIO_ChannelSetFormat(true, m_inputChannel, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT);
            BassAsio.BASS_ASIO_ChannelSetRate(true, m_inputChannel, samplerate);
            BassAsio.BASS_ASIO_SetRate(samplerate);

            BassAsio.BASS_ASIO_ChannelEnable(false, m_outputChannel, _asioProc, new IntPtr(m_mixerChannel));
            BassAsio.BASS_ASIO_ChannelJoin(false, m_outputChannel + 1, m_outputChannel);
            BassAsio.BASS_ASIO_ChannelSetFormat(false, m_outputChannel, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT);
            BassAsio.BASS_ASIO_ChannelSetRate(false, m_outputChannel, samplerate);
            BassAsio.BASS_ASIO_SetRate(samplerate);
        }