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); }
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); } }