public static void SetDevice(int inputDevice, int outputDevice) { thisControl = PlayerControl.MainFormControl; //Get some info about their selected input device var inputdeviceinfo = BassWasapi.BASS_WASAPI_GetDeviceInfo(inputDevice); InputDevice = inputDevice; InputDeviceInfo = inputdeviceinfo; //Get some info about their selected ouput device var outputdeviceinfo = BassWasapi.BASS_WASAPI_GetDeviceInfo(outputDevice); OutputDevice = outputDevice; OutputDeviceInfo = outputdeviceinfo; if (!m_isWasapiInit) { Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_FLOATDSP, true); Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, PlayerControl.MainFormControl.Handle); Player.Mixer = MixerStreamCreate(outputdeviceinfo.mixfreq); if (Player.Mixer == 0) { var error = Bass.BASS_ErrorGetCode(); MessageBox.Show(error.ToString(), "Could not create mixer!"); Bass.BASS_Free(); return; } _outstream = Player.Mixer; _instream = Bass.BASS_StreamCreatePush(inputdeviceinfo.mixfreq, inputdeviceinfo.mixchans, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE, IntPtr.Zero); // create a stream to receive the data // string fn = @"D:\tanie\karaokeNow Resources\LdVocal_01.wav"; // _instream = Bass.BASS_StreamCreateFile(fn, 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_LOOP); //_stream[0] = BassMix.BASS_Split_StreamCreate(_instream, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE, null);//_instream; //_stream[1] = BassMix.BASS_Split_StreamCreate(_instream, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE, null);// _instream; //_stream[2] = BassMix.BASS_Split_StreamCreate(_instream, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE, null);//_instream; //_stream[3] = BassMix.BASS_Split_StreamCreate(_instream, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE, null);//_instream; // _outstream = BassMix.BASS_Mixer_StreamCreate(outputdeviceinfo.mixfreq, outputdeviceinfo.mixchans, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE); // Player.Mixer = _outstream; //Group 1 VST Effects ============================================================ Channel1Fx.SetEffects(_instream); //Group 2 VST Effects ============================================================ // Channel2Fx.SetEffects(_stream[1]); //Group 3 VST Effects ============================================================ //Channel3Fx.SetEffects(_stream[2]); //Group 4 VST Effects ============================================================ //Channel4Fx.SetEffects(_stream[3]); BassMix.BASS_Mixer_StreamAddChannel(_outstream, _instream, 0); // BassMix.BASS_Mixer_StreamAddChannel(_outstream, _stream[1], 0); //BassMix.BASS_Mixer_StreamAddChannel(_outstream, _stream[2], 0); // BassMix.BASS_Mixer_StreamAddChannel(_outstream, _stream[3], 0); m_isWasapiInit = true; } _wasapiInProc = new WASAPIPROC(InputProc); GC.KeepAlive(_wasapiInProc); _wasapiOutProc = new WASAPIPROC(OutputProc); GC.KeepAlive(_wasapiOutProc); //Set the input device so subsequent calls are on it BassWasapi.BASS_WASAPI_SetDevice(InputDevice); // Initialize BASS WASAPI input BASS_WASAPI_INFO input = new BASS_WASAPI_INFO(); BassWasapi.BASS_WASAPI_GetInfo(input); BassWasapi.BASS_WASAPI_Init(inputDevice, inputdeviceinfo.mixfreq, inputdeviceinfo.mixchans, BASSWASAPIInit.BASS_WASAPI_EVENT | BASSWASAPIInit.BASS_WASAPI_BUFFER | BASSWASAPIInit.BASS_WASAPI_SHARED, input.buflen, 0, _wasapiInProc, IntPtr.Zero); //Set the output device so subsequent calls are on it BassWasapi.BASS_WASAPI_SetDevice(OutputDevice); BASS_WASAPI_INFO output = new BASS_WASAPI_INFO(); BassWasapi.BASS_WASAPI_GetInfo(output); // Initialize BASS WASAPI output BassWasapi.BASS_WASAPI_Init(outputDevice, outputdeviceinfo.mixfreq, outputdeviceinfo.mixchans, BASSWASAPIInit.BASS_WASAPI_EVENT | BASSWASAPIInit.BASS_WASAPI_SHARED, output.buflen, 0, _wasapiOutProc, IntPtr.Zero); }
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); }