コード例 #1
0
 /// <summary>
 /// Stops playing back audio.
 /// </summary>
 public void Stop()
 {
     if (this.audioDevice != null)
     {
         LinuxAudioInterop.Close(this.audioDevice);
         this.audioDevice = null;
     }
 }
コード例 #2
0
 /// <summary>
 /// Stops playing back audio.
 /// </summary>
 private void OnPipelineStop()
 {
     if (this.audioDevice != null)
     {
         LinuxAudioInterop.Close(this.audioDevice);
         this.audioDevice = null;
     }
 }
コード例 #3
0
ファイル: AudioPlayer.cs プロジェクト: sandrist/psi
 /// <summary>
 /// Stops playing back audio.
 /// </summary>
 private void OnUnsubscribed()
 {
     if (this.audioDevice != null)
     {
         LinuxAudioInterop.Close(this.audioDevice);
         this.audioDevice = null;
     }
 }
コード例 #4
0
 /// <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));
 }
コード例 #5
0
 /// <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));
 }
コード例 #6
0
ファイル: AudioCapture.cs プロジェクト: sandrist/psi
        /// <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();
        }
コード例 #7
0
        /// <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();
        }