private void BeginPlaybackInternal <TInput>(BufferNeededCallback <TInput> callback) where TInput : unmanaged { if (callback == null) { throw new ArgumentNullException(nameof(callback)); } if (this.disposed) { throw new ObjectDisposedException(nameof(AudioPlayer)); } if (this.Playing) { throw new InvalidOperationException("Playback has already started."); } this.callbackRaiser = this.Format.SampleFormat switch { SampleFormat.UnsignedPcm8 => new CallbackRaiser <TInput, byte>(callback), SampleFormat.SignedPcm16 => new CallbackRaiser <TInput, short>(callback), SampleFormat.IeeeFloat32 => new CallbackRaiser <TInput, float>(callback), _ => throw new ArgumentException("Sample format is not support.") }; this.Playing = true; this.Start(true); }
/// <summary> /// Begins playback of the background stream of 8-bit PCM data. /// </summary> /// <param name="callback">Delegate invoked when more data is needed for the playback buffer.</param> /// <exception cref="ArgumentNullException"><paramref name="callback"/> is null.</exception> /// <exception cref="InvalidOperationException">The stream is already playing.</exception> /// <exception cref="ObjectDisposedException">The <see cref="AudioPlayer"/> instance has been disposed.</exception> public void BeginPlayback(BufferNeededCallback <byte> callback) => this.BeginPlaybackInternal(callback);