Пример #1
0
        private void buttonStopRecording_Click(object sender, EventArgs e)
        {
            if (_asioIn != null)
            {
                if (_plmRec != null)
                {
                    _plmRec.Stop();
                    _plmRec = null;
                }
                // stop the device, since we don't need it anymore
                _asioIn.Stop();
                // and dispose (unjoin and disable any channel)
                _asioIn.Dispose();
                _asioIn = null;

                this.comboBoxAsioInputDevice.Enabled   = true;
                this.comboBoxAsioInputChannel.Enabled  = true;
                this.buttonStartRecording.Enabled      = true;
                this.buttonStopRecording.Enabled       = false;
                this.radioButtonNoFullDuplex.Checked   = true;
                this.radioButtonAsioFullDuplex.Checked = false;
                this.radioButtonBassFullDuplex.Checked = false;
                this.radioButtonNoFullDuplex.Enabled   = false;
                this.radioButtonAsioFullDuplex.Enabled = false;
                this.radioButtonBassFullDuplex.Enabled = false;
                this.comboBoxBassDevice.Enabled        = false;
                this.checkBoxSaveToWave.Enabled        = false;
                this.progressBarRecL.Value             = 0;
                this.progressBarRecR.Value             = 0;
            }
        }
Пример #2
0
        private void buttonStartRecording_Click(object sender, EventArgs e)
        {
            // now setup the ASIO handler (recording 48kHz, stereo)
            _asioIn = new BassAsioHandler(true, comboBoxAsioInputDevice.SelectedIndex, comboBoxAsioInputChannel.SelectedIndex * 2, 2, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT, 48000d);
            if (_asioIn.Start((int)this.numericUpDownAsioBuffer.Value, 1))
            {
                // use a DSP to measure the Level of the input
                _plmRec = new DSP_PeakLevelMeter(_asioIn.InputChannel, 0);
                _plmRec.Notification += new EventHandler(_plm_Rec_Notification);

                this.comboBoxAsioInputDevice.Enabled   = false;
                this.comboBoxAsioInputChannel.Enabled  = false;
                this.buttonStopRecording.Enabled       = true;
                this.buttonStartRecording.Enabled      = false;
                this.radioButtonNoFullDuplex.Enabled   = true;
                this.radioButtonAsioFullDuplex.Enabled = true;
                this.radioButtonBassFullDuplex.Enabled = true;
                this.comboBoxBassDevice.Enabled        = true;
                this.checkBoxSaveToWave.Enabled        = true;
            }
            else
            {
                _asioIn.Dispose();
                _asioIn = null;
                MessageBox.Show("Asio Device could not be started!");
            }
        }
Пример #3
0
        public override void Initialize(int deviceid)
        {
            //BassAsio.BASS_ASIO_ChannelEnable(true,
            this.FMyHandler = new BassAsioHandler(true, deviceid, this.index, this.count, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT, 48000);
            if (!BassAsio.BASS_ASIO_IsStarted())
            {
                BassAsio.BASS_ASIO_Start(0);
            }

            this.FMyHandler.SetFullDuplex(0, BASSFlag.BASS_STREAM_DECODE, false);

            this.BassHandle = this.FMyHandler.InputChannel;
            this.IsDecoding = true;
        }
Пример #4
0
        private void buttonOpenFile_Click(object sender, System.EventArgs e)
        {
            this.openFileDialog.FileName = _fileName;
            if (DialogResult.OK == this.openFileDialog.ShowDialog(this))
            {
                if (File.Exists(this.openFileDialog.FileName))
                {
                    _fileName = this.openFileDialog.FileName;
                    // create the decoding stream
                    _stream = Bass.BASS_StreamCreateFile(_fileName, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
                    if (_stream != 0)
                    {
                        // now setup the ASIO handler
                        _asioOut = new BassAsioHandler(comboBoxAsioOutputDevice.SelectedIndex, comboBoxAsioOutputChannel.SelectedIndex * 2, _stream);
                        if (_asioOut.Start((int)this.numericUpDownAsioBuffer.Value, 1))
                        {
                            // use a DSP to measure the Level
                            _plmPlay = new DSP_PeakLevelMeter(_asioOut.OutputChannel, 0);
                            _plmPlay.Notification += new EventHandler(_plm_Play_Notification);

                            this.comboBoxAsioOutputDevice.Enabled  = false;
                            this.comboBoxAsioOutputChannel.Enabled = false;
                            this.buttonOpenFile.Enabled            = false;
                            this.buttonStop.Enabled = true;
                        }
                        else
                        {
                            _asioOut.Dispose();
                            _asioOut = null;
                            MessageBox.Show("Asio Device could not be started!");
                        }
                    }
                    else
                    {
                        MessageBox.Show(String.Format("Error = {0}", Bass.BASS_ErrorGetCode()));
                    }
                }
                else
                {
                    _fileName = String.Empty;
                }
            }
        }
Пример #5
0
        private void buttonStop_Click(object sender, System.EventArgs e)
        {
            if (_asioOut != null)
            {
                // stop the DSP
                _plmPlay.Stop();
                _plmPlay = null;
                // stop the device, since we don't need it anymore
                _asioOut.Stop();
                // and dispose (unjoin and disable any channel)
                _asioOut.Dispose();
                _asioOut = null;
                // and free the source channel
                Bass.BASS_StreamFree(_stream);
                _stream = 0;

                this.comboBoxAsioOutputDevice.Enabled  = true;
                this.comboBoxAsioOutputChannel.Enabled = true;
                this.buttonOpenFile.Enabled            = true;
                this.buttonStop.Enabled     = false;
                this.progressBarPlayL.Value = 0;
                this.progressBarPlayR.Value = 0;
            }
        }
Пример #6
0
        private void buttonStart_Click(object sender, System.EventArgs e)
        {
            asio = new BassAsioHandler(true, 0, 0, 2, BASSASIOFormat.BASS_ASIO_FORMAT_16BIT, 44100);

            // set a mirror on output channel 0 (for monitoring)
            asio.SetMirror(0);
            this.checkBoxMonitor.Checked = true;

            // start ASIO (actually starts recording/playing)
            BASS_ASIO_INFO info = BassAsio.BASS_ASIO_GetInfo();
            bool           ok   = asio.Start(info.bufmax);

            if (!ok)
            {
                MessageBox.Show("Could not start ASIO : " + BassAsio.BASS_ASIO_ErrorGetCode().ToString());
            }

            // now setup the encoder on the provided asio bass channel (which will be created by the above SetFullDuplex call)
            if (radioButtonLAME.Checked)
            {
                lame              = new EncoderLAME(asio.InputChannel);
                lame.InputFile    = null;               //STDIN
                lame.OutputFile   = "test.mp3";
                lame.LAME_Bitrate = (int)EncoderLAME.BITRATE.kbps_128;
                lame.LAME_Mode    = EncoderLAME.LAMEMode.Default;
                lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality;
                lame.Start(null, IntPtr.Zero, false);
                enc = lame;
            }
            else if (radioButtonOGG.Checked)
            {
                ogg                    = new EncoderOGG(asio.InputChannel);
                ogg.InputFile          = null;          //STDIN
                ogg.OutputFile         = "test.ogg";
                ogg.OGG_UseQualityMode = true;
                ogg.OGG_Quality        = 4.0f;
                ogg.Start(null, IntPtr.Zero, false);
                enc = ogg;
            }
            else if (radioButtonAAC.Checked)
            {
                aac              = new EncoderNeroAAC(asio.InputChannel);
                aac.InputFile    = null;                //STDIN
                aac.OutputFile   = "test.mp4";
                aac.NERO_Bitrate = 64;
                aac.Start(null, IntPtr.Zero, false);
                enc = aac;
            }
            else if (radioButtonWAVE.Checked)
            {
                // writing 16-bit wave file here (even if we use a float asio channel)
                wav            = new EncoderWAV(asio.InputChannel);
                wav.InputFile  = null;                 // STDIN
                wav.OutputFile = "test.wav";
                wav.Start(null, IntPtr.Zero, false);
                enc = wav;
            }

            this.buttonStart.Enabled = false;

            // display the level
            plm               = new DSP_PeakLevelMeter(asio.InputChannel, 0);
            plm.UpdateTime    = 0.1f;          // 100ms
            plm.Notification += new EventHandler(plm_Notification);
        }
Пример #7
0
    /// <summary>
    /// Init BASS, when a Audio file is to be played
    /// </summary>
    public void InitBass()
    {
      try
      {
        Log.Info("BASS: Initializing BASS audio engine...");
        bool initOK = false;
        if (_useASIO)
        {
          Log.Info("BASS: Using ASIO device: {0}", _asioDevice);
          BASS_ASIO_DEVICEINFO[] asioDevices = BassAsio.BASS_ASIO_GetDeviceInfos();
          // Check if the ASIO device read is amongst the one retrieved
          for (int i = 0; i < asioDevices.Length; i++)
          {
            if (asioDevices[i].name == _asioDevice)
            {
              _asioDeviceNumber = i;
              break;
            }
          }
          if (_asioDeviceNumber > -1)
          {
            // 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 but 48000 (default for ASIO)
            initOK = (Bass.BASS_Init(0, 48000, 0, IntPtr.Zero) && BassAsio.BASS_ASIO_Init(_asioDeviceNumber));

            // When used in config the ASIO_INIT fails. Ignore it here, to be able using the visualisations
            if (Application.ExecutablePath.Contains("Configuration"))
            {
              initOK = true;
            }
          }
          else
          {
            initOK = false;
            Log.Error("BASS: Specified ASIO device not found. BASS is disabled.");
          }
        }
        else
        {
          int soundDevice = GetSoundDevice();

          initOK =
            (Bass.BASS_Init(soundDevice, 44100, BASSInit.BASS_DEVICE_DEFAULT | BASSInit.BASS_DEVICE_LATENCY, IntPtr.Zero));
        }
        if (initOK)
        {
          // Create an 8 Channel Mixer, which should be running until stopped.
          // The streams to play are added to the active screen
          if (_Mixing && _mixer == 0)
          {
            _mixer = BassMix.BASS_Mixer_StreamCreate(44100, 8,
                                                     BASSFlag.BASS_MIXER_NONSTOP | BASSFlag.BASS_STREAM_AUTOFREE);
          }
          else if (_useASIO && _mixer == 0)
          {
            // For ASIO we neeed an Decoding Mixer with the number of Channels equals the ASIO Channels
            _mixer = BassMix.BASS_Mixer_StreamCreate(44100, 2,
                                                     BASSFlag.BASS_MIXER_NONSTOP | BASSFlag.BASS_STREAM_DECODE);
            // assign ASIO and assume the ASIO format, samplerate and number of channels from the BASS stream
            _asioHandler = new BassAsioHandler(0, 0, _mixer);
          }

          Log.Info("BASS: Initialization done.");
          _Initialized = true;
          _BassFreed = false;
        }
        else
        {
          BASSError error = Bass.BASS_ErrorGetCode();
          if (_useASIO)
          {
            BASSError errorasio = BassAsio.BASS_ASIO_ErrorGetCode();
            Log.Error("BASS: Error initializing BASS audio engine {0} Asio: {1}",
                      Enum.GetName(typeof (BASSError), error), Enum.GetName(typeof (BASSError), errorasio));
          }
          else
            Log.Error("BASS: Error initializing BASS audio engine {0}", Enum.GetName(typeof (BASSError), error));
        }
      }
      catch (Exception ex)
      {
        Log.Error("BASS: Initialize failed. Reason: {0}", ex.Message);
      }
    }
Пример #8
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);
            }
        }