Example #1
0
        public WaveInProvider(WaveInDevice Device, int FrameRate, WaveFormat Wf)
        {
            _waveInEvent = new WaveInEvent
            {
                DeviceNumber       = Device.DeviceNumber,
                BufferMilliseconds = (int)Math.Ceiling(1000 / (decimal)FrameRate),
                NumberOfBuffers    = 3,
                WaveFormat         = new NWaveFormat(Wf.SampleRate, Wf.BitsPerSample, Wf.Channels)
            };

            IsSynchronizable = true;
            WaveFormat       = Wf;

            Setup();
        }
Example #2
0
        public WaveInProvider(WaveInDevice Device, WaveFormat Wf)
        {
            _waveInEvent = new WaveInEvent
            {
                DeviceNumber       = Device.DeviceNumber,
                BufferMilliseconds = 100,
                NumberOfBuffers    = 3,
                WaveFormat         = new NWaveFormat(Wf.SampleRate, Wf.BitsPerSample, Wf.Channels)
            };

            IsSynchronizable = false;
            WaveFormat       = Wf;

            Setup();
        }
Example #3
0
        /// <summary>
        /// Create a new instance of <see cref="LoopbackProvider"/>.
        /// </summary>
        /// <param name="Device"><see cref="WasapiLoopbackDevice"/> to use.</param>
        /// <param name="IncludeSilence">Whether to record silence?... default = true</param>
        public LoopbackProvider(WasapiLoopbackDevice Device, bool IncludeSilence = true)
        {
            _deviceIndex = Device.DeviceIndex;
            _proc        = Procedure;

            if (IncludeSilence)
            {
                _silencePlayer = new Silence(PlaybackDevice.Devices.First(Dev => Dev.Info.Driver == Device.Info.ID));
            }

            BassWasapi.Init(_deviceIndex, Procedure: _proc);
            BassWasapi.CurrentDevice = Device.DeviceIndex;

            var info = BassWasapi.Info;

            WaveFormat = WaveFormat.CreateIeeeFloatWaveFormat(info.Frequency, info.Channels);
        }
Example #4
0
        /// <summary>
        /// Creates a new synchronizable instance of <see cref="WaveInProvider"/> to be used with an <see cref="IRecorder"/>.
        /// </summary>
        /// <param name="Device">The Recording Device.</param>
        /// <param name="Wf"><see cref="WaveFormat"/> to use.</param>
        /// <param name="FrameRate">The <see cref="IRecorder"/>'s FrameRate.</param>
        public WaveInProvider(WaveInDevice Device, WaveFormat Wf, int FrameRate)
        {
            IsSynchronizable = FrameRate != -1;

            _waveInEvent = new WaveInEvent
            {
                DeviceNumber       = Device.DeviceNumber,
                BufferMilliseconds = IsSynchronizable ? (int)Math.Ceiling(1000 / (decimal)FrameRate) : 100,
                NumberOfBuffers    = 3,
                WaveFormat         = new NWaveFormat(Wf.SampleRate, Wf.BitsPerSample, Wf.Channels)
            };

            WaveFormat = Wf;

            _waveInEvent.RecordingStopped += (Sender, Args) => RecordingStopped?.Invoke(this, new EndEventArgs(Args.Exception));

            _waveInEvent.DataAvailable += (Sender, Args) => DataAvailable?.Invoke(this, new DataAvailableEventArgs(Args.Buffer, Args.BytesRecorded));
        }
Example #5
0
        /// <summary>
        /// Create a new instance of <see cref="LoopbackProvider"/>.
        /// </summary>
        /// <param name="Device"><see cref="MMDevice"/> to use.</param>
        /// <param name="IncludeSilence">Whether to record silence?... default = true</param>
        public LoopbackProvider(MMDevice Device, bool IncludeSilence = true)
        {
            _capture = new WasapiLoopbackCapture(Device);

            _capture.DataAvailable    += (Sender, Args) => DataAvailable?.Invoke(this, new DataAvailableEventArgs(Args.Buffer, Args.BytesRecorded));
            _capture.RecordingStopped += (Sender, Args) => RecordingStopped?.Invoke(this, new EndEventArgs(Args.Exception));

            var mixFormat = _capture.WaveFormat;

            WaveFormat = WaveFormat.CreateIeeeFloatWaveFormat(mixFormat.SampleRate, mixFormat.Channels);

            if (!IncludeSilence)
            {
                return;
            }

            _silenceOut = new WasapiOut(Device, AudioClientShareMode.Shared, false, 100);
            _silenceOut.Init(new SilenceProvider());
        }
Example #6
0
        /// <summary>
        /// Creates a new synchronizable instance of <see cref="RecordingProvider"/> to be used with an <see cref="IRecorder"/>.
        /// </summary>
        /// <param name="Device">The Recording Device.</param>
        /// <param name="Wf"><see cref="WaveFormat"/> to use.</param>
        /// <param name="FrameRate">The <see cref="IRecorder"/>'s FrameRate.</param>
        public RecordingProvider(RecordingDevice Device, WaveFormat Wf, int FrameRate)
        {
            WaveFormat = Wf;

            BASS.RecordInit(Device.DeviceIndex);

            BASS.CurrentRecordingDevice = Device.DeviceIndex;

            var flags = BassFlags.RecordPause;

            if (Wf.Encoding == WaveFormatEncoding.Float && Wf.BitsPerSample == 32)
            {
                flags |= BassFlags.Float;
            }

            else if (Wf.Encoding == WaveFormatEncoding.Pcm && Wf.BitsPerSample == 8)
            {
                flags |= BassFlags.Byte;
            }

            else if (!(Wf.Encoding == WaveFormatEncoding.Pcm && Wf.BitsPerSample == 16))
            {
                throw new ArgumentException(nameof(Wf));
            }

            IsSynchronizable = FrameRate != -1;

            if (IsSynchronizable)
            {
                BASS.RecordingBufferLength = 3000 / FrameRate;
            }

            _handle = IsSynchronizable ? BASS.RecordStart(Wf.SampleRate, Wf.Channels, flags, BASS.RecordingBufferLength / 3, Procedure, IntPtr.Zero)
                                      : BASS.RecordStart(Wf.SampleRate, Wf.Channels, flags, Procedure);

            BASS.ChannelSetSync(_handle, SyncFlags.Free, 0, (H, C, D, U) => RecordingStopped?.Invoke(this, new EndEventArgs(null)));
        }
Example #7
0
 /// <summary>
 /// Creates a new instance of <see cref="RecordingProvider"/>.
 /// </summary>
 /// <param name="Device">The Recording Device.</param>
 /// <param name="Wf"><see cref="WaveFormat"/> to use.</param>
 public RecordingProvider(RecordingDevice Device, WaveFormat Wf)
     : this(Device, Wf, -1)
 {
 }
Example #8
0
 /// <summary>
 /// Creates a new instance of <see cref="WaveInProvider"/>.
 /// </summary>
 /// <param name="Device">The Recording Device.</param>
 /// <param name="Wf"><see cref="WaveFormat"/> to use.</param>
 public WaveInProvider(WaveInDevice Device, WaveFormat Wf)
     : this(Device, Wf, -1)
 {
 }
Example #9
0
 public IAudioFileWriter GetAudioFileWriter(string FileName, Screna.Audio.WaveFormat Wf)
 {
     return(Encode ? new AudioFileWriter(FileName, new Mp3EncoderLame(Wf.Channels, Wf.SampleRate, SelectedBitRate))
                   : new AudioFileWriter(FileName, Wf));
 }