/// <summary> /// Stops playing back audio. /// </summary> public void Stop() { if (this.audioDevice != null) { LinuxAudioInterop.Close(this.audioDevice); this.audioDevice = null; } }
/// <summary> /// Stops playing back audio. /// </summary> private void OnPipelineStop() { if (this.audioDevice != null) { LinuxAudioInterop.Close(this.audioDevice); this.audioDevice = null; } }
/// <summary> /// Stops playing back audio. /// </summary> private void OnUnsubscribed() { if (this.audioDevice != null) { LinuxAudioInterop.Close(this.audioDevice); this.audioDevice = null; } }
/// <summary> /// Called when the pipeline is shutting down. /// </summary> public void Stop() { var audioDevice = Interlocked.Exchange(ref this.audioDevice, null); if (audioDevice != null) { LinuxAudioInterop.Close(audioDevice); } }
/// <summary> /// Called when the pipeline is shutting down. /// </summary> private void OnPipelineStop() { var audioDevice = Interlocked.Exchange(ref this.audioDevice, null); if (audioDevice != null) { LinuxAudioInterop.Close(audioDevice); } }
/// <summary> /// Starts playing back audio. /// </summary> /// <param name="onCompleted">Delegate to call when the execution completed</param> /// <param name="descriptor">If set, describes the playback constraints</param> public void Start(Action onCompleted, ReplayDescriptor descriptor) { this.audioDevice = LinuxAudioInterop.Open( this.configuration.DeviceName, LinuxAudioInterop.Mode.Playback, (int)this.configuration.Format.SamplesPerSec, this.configuration.Format.Channels, LinuxAudioInterop.ConfigurationFormat(this.configuration)); }
/// <summary> /// Receiver for the audio data. /// </summary> /// <param name="audioData">A buffer containing the next chunk of audio data.</param> public override void Receive(Message <AudioBuffer> audioData) { // take action only if format is different if (this.audioDevice != null && audioData.Data.HasValidData) { var data = audioData.Data; LinuxAudioInterop.Write(this.audioDevice, data.Data, data.Length / this.frameSize); } }
/// <summary> /// Starts playing back audio. /// </summary> private void OnPipelineStart() { this.audioDevice = LinuxAudioInterop.Open( this.configuration.DeviceName, LinuxAudioInterop.Mode.Playback, (int)this.configuration.Format.SamplesPerSec, this.configuration.Format.Channels, LinuxAudioInterop.ConfigurationFormat(this.configuration)); }
/// <inheritdoc/> public void Start(Action <DateTime> notifyCompletionTime) { // notify that this is an infinite source component notifyCompletionTime(DateTime.MaxValue); this.audioDevice = LinuxAudioInterop.Open( this.configuration.DeviceName, LinuxAudioInterop.Mode.Capture, (int)this.configuration.Format.SamplesPerSec, this.configuration.Format.Channels, LinuxAudioInterop.ConvertFormat(this.configuration.Format)); this.background = new Thread(new ThreadStart(() => { const int blockSize = 256; var format = this.configuration.Format; var length = blockSize * format.BitsPerSample / 8; var buf = new byte[length]; while (!this.isStopping) { try { LinuxAudioInterop.Read(this.audioDevice, buf, blockSize); } catch { if (this.audioDevice != null) { throw; } } // Only create a new buffer if necessary if ((this.buffer.Data == null) || (this.buffer.Length != length)) { this.buffer = new AudioBuffer(length, format); } // Copy the data Array.Copy(buf, this.buffer.Data, length); // use the end of the last sample in the packet as the originating time DateTime originatingTime = this.pipeline.GetCurrentTime().AddSeconds((double)length / format.AvgBytesPerSec); // post the data to the output stream this.audioBuffers.Post(this.buffer, originatingTime); } })) { IsBackground = true }; this.isStopping = false; this.background.Start(); }
private void Stop() { // stop any running background thread and wait for it to terminate this.isStopping = true; this.background?.Join(); var audioDevice = Interlocked.Exchange(ref this.audioDevice, null); if (audioDevice != null) { LinuxAudioInterop.Close(audioDevice); } }
/// <summary> /// Called to start capturing audio from the microphone. /// </summary> /// <param name="onCompleted">Delegate to call when the execution completed</param> /// <param name="descriptor">If set, describes the playback constraints</param> public void Start(Action onCompleted, ReplayDescriptor descriptor) { this.audioDevice = LinuxAudioInterop.Open( this.configuration.DeviceName, LinuxAudioInterop.Mode.Capture, (int)this.configuration.Format.SamplesPerSec, this.configuration.Format.Channels, LinuxAudioInterop.ConfigurationFormat(this.configuration)); new Thread(new ThreadStart(() => { const int blockSize = 256; var format = this.configuration.Format; var length = blockSize * format.BitsPerSample / 8; var buf = new byte[length]; while (this.audioDevice != null) { try { LinuxAudioInterop.Read(this.audioDevice, buf, blockSize); } catch (Exception ex) { if (this.audioDevice != null) { throw ex; } } // Only create a new buffer if necessary if ((this.buffer.Data == null) || (this.buffer.Length != length)) { this.buffer = new AudioBuffer(length, format); } // Copy the data Array.Copy(buf, this.buffer.Data, length); // use the end of the last sample in the packet as the originating time DateTime originatingTime = this.pipeline.GetCurrentTime().AddSeconds(length / format.AvgBytesPerSec); // post the data to the output stream this.audioBuffers.Post(this.buffer, originatingTime); } })) { IsBackground = true }.Start(); }