public BassAudioProvider(BassItem Device) { if (Device == null) { throw new ArgumentNullException(); } Bass.RecordInit(Device.Id); var devInfo = Bass.RecordGetDeviceInfo(Device.Id); if (devInfo.IsLoopback) { var playbackDevice = FindPlaybackDevice(devInfo); if (playbackDevice != -1) { Bass.Init(playbackDevice); Bass.CurrentDevice = playbackDevice; _silenceHandle = Bass.CreateStream(44100, 2, BassFlags.Default, Extensions.SilenceStreamProcedure); Bass.ChannelSetAttribute(_silenceHandle, ChannelAttribute.Volume, 0); } } Bass.CurrentRecordingDevice = Device.Id; var info = Bass.RecordingInfo; _recordingHandle = Bass.RecordStart(info.Frequency, info.Channels, BassFlags.RecordPause, RecordProcedure); }
void InitDevice(BassItem Device) { _devices.Add(Device.Id, new RecordingItem { DeviceId = Device.Id }); Device.PropertyChanged += (S, E) => { if (E.PropertyName == nameof(Device.Active)) { if (Device.Active) { AddDevice(Device); } else { RemoveDevice(Device); } } }; if (Device.Active) { AddDevice(Device); } }
public override IAudioProvider GetAudioProvider() { var rec = SelectedRecordingSource is BassItem r ? r : null; var loop = SelectedLoopbackSource is BassItem l ? l : null; if (rec == null && loop == null) { return(null); } return(BassItem.GetAudioProvider(rec, loop)); }
void AddDevice(BassItem Device) { lock (_syncLock) { if (_devices[Device.Id].RecordingHandle != 0) { return; } Bass.RecordInit(Device.Id); var devInfo = Bass.RecordGetDeviceInfo(Device.Id); if (devInfo.IsLoopback) { var playbackDevice = FindPlaybackDevice(devInfo); if (playbackDevice != -1) { Bass.Init(playbackDevice); Bass.CurrentDevice = playbackDevice; var silence = Bass.CreateStream(44100, 2, BassFlags.Default, Extensions.SilenceStreamProcedure); Bass.ChannelSetAttribute(silence, ChannelAttribute.Volume, 0); _devices[Device.Id].SilenceHandle = silence; } } Bass.CurrentRecordingDevice = Device.Id; var info = Bass.RecordingInfo; var handle = Bass.RecordStart(info.Frequency, info.Channels, BassFlags.RecordPause, null); _devices[Device.Id].RecordingHandle = handle; BassMix.MixerAddChannel(_mixer, handle, BassFlags.MixerDownMix | BassFlags.MixerLimit); if (_running) { Bass.ChannelPlay(handle); } } }
void RemoveDevice(BassItem Device) { lock (_syncLock) { if (_devices[Device.Id].RecordingHandle == 0) return; var handle = _devices[Device.Id].RecordingHandle; BassMix.MixerRemoveChannel(handle); Bass.StreamFree(handle); _devices[Device.Id].RecordingHandle = 0; Bass.StreamFree(_devices[Device.Id].SilenceHandle); _devices[Device.Id].SilenceHandle = 0; } }
protected override void OnRefresh() { var infos = new ArrayList(); for (int i = 0; Bass.RecordGetDeviceInfo(i, out var info); ++i) { var bassItem = new BassItem(i, info.Name); if (info.IsLoopback) { AvailableLoopbackSources.Add(bassItem); if ("Speakers".Equals(info.Type.ToString())) { this.SelectedLoopbackSource = bassItem; } } else { AvailableRecordingSources.Add(bassItem); this.SelectedRecordingSource = bassItem; } } }
public static IAudioProvider GetAudioProvider(BassItem RecordingDevice, BassItem LoopbackDevice) { return(new MixedAudioProvider(RecordingDevice?._id, LoopbackDevice?._id)); }
void InitDevice(BassItem Device) { _devices.Add(Device.Id, new RecordingItem { DeviceId = Device.Id }); void AddDevice() { lock (_syncLock) { if (_devices[Device.Id].RecordingHandle != 0) { return; } Bass.RecordInit(Device.Id); Bass.CurrentRecordingDevice = Device.Id; var info = Bass.RecordingInfo; var handle = Bass.RecordStart(info.Frequency, info.Channels, BassFlags.Float | BassFlags.RecordPause, null); _devices[Device.Id].RecordingHandle = handle; BassMix.MixerAddChannel(_mixer, handle, BassFlags.MixerDownMix); if (_running) { Bass.ChannelPlay(handle); } } } void RemoveDevice() { lock (_syncLock) { if (_devices[Device.Id].RecordingHandle == 0) { return; } var handle = _devices[Device.Id].RecordingHandle; BassMix.MixerRemoveChannel(handle); Bass.StreamFree(handle); _devices[Device.Id].RecordingHandle = 0; } } Device.PropertyChanged += (S, E) => { if (E.PropertyName == nameof(Device.Active)) { if (Device.Active) { AddDevice(); } else { RemoveDevice(); } } }; if (Device.Active) { AddDevice(); } }
void InitLoopbackDevice(BassItem LoopbackDevice) { var playbackDevice = FindPlaybackDevice(LoopbackDevice.Id); _loopback.Add(LoopbackDevice.Id, new LoopbackItem { DeviceId = LoopbackDevice.Id, PlaybackDeviceId = playbackDevice }); void AddDevice() { lock (_syncLock) { if (_loopback[LoopbackDevice.Id].RecordingHandle != 0) { return; } Bass.Init(playbackDevice); Bass.CurrentDevice = playbackDevice; var silence = Bass.CreateStream(44100, 2, BassFlags.Float, ManagedBass.Extensions.SilenceStreamProcedure); _loopback[LoopbackDevice.Id].SilenceStreamHandle = silence; Bass.RecordInit(LoopbackDevice.Id); Bass.CurrentRecordingDevice = LoopbackDevice.Id; var info = Bass.RecordingInfo; var handle = Bass.RecordStart(info.Frequency, info.Channels, BassFlags.Float | BassFlags.RecordPause, null); _loopback[LoopbackDevice.Id].RecordingHandle = handle; BassMix.MixerAddChannel(_mixer, handle, BassFlags.MixerDownMix); if (_running) { Bass.ChannelPlay(silence); Bass.ChannelPlay(handle); } } } void RemoveDevice() { lock (_syncLock) { if (_loopback[LoopbackDevice.Id].RecordingHandle == 0) { return; } var item = _loopback[LoopbackDevice.Id]; BassMix.MixerRemoveChannel(item.RecordingHandle); Bass.StreamFree(item.RecordingHandle); Bass.StreamFree(item.SilenceStreamHandle); _loopback[LoopbackDevice.Id].RecordingHandle = 0; _loopback[LoopbackDevice.Id].SilenceStreamHandle = 0; } } LoopbackDevice.PropertyChanged += (S, E) => { if (E.PropertyName == nameof(LoopbackDevice.Active)) { if (LoopbackDevice.Active) { AddDevice(); } else { RemoveDevice(); } } }; if (LoopbackDevice.Active) { AddDevice(); } }