/// <summary> /// Creates a new instance of <see cref="Record"/>. /// </summary> public Record(RecordDevice Device, int Frequency, int Channels, Resolution Resolution = Resolution.Short) { Bass.Init(0); Device.Init(); Bass.CurrentRecordingDevice = Device.Index; _handle = Bass.RecordStart(Frequency, Channels, BassFlags.RecordPause | Resolution.ToBassFlag(), Processing); AudioFormat = WaveFormat.FromChannel(_handle); }
/// <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))); }