首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

用 C# 編寫網路電話 (6):SoundPlayer 播放控制與 CaptureSound 私有欄位

     編輯:關於C語言

SoundPlayer 公開方法

#region 公開方法
public void Stop()
{
    isRunning = false;
    if (m_Buffer != null) m_Buffer.Stop();
}

public void Write(byte[] data)
{
    try
    {
        Console.WriteLine("播放聲音:{0}", data.Length);
        circularBuffer.Write(data);
    }
    catch (Exception) { }
}
#endregion

CaptureSound 私有欄位定義

public class CaptureSound
{
    #region 私有成員
    private const int NumberRecordNotifications = 4;
    private readonly BufferPositionNotify[] positionNotify;
    private Capture selectedDevice;
    private CaptureBuffer buffer;
    private int captureBufferSize;
    private string fileName;
    private bool isRecording;
    private int nextCaptureOffset;
    private AutoResetEvent notificationEvent;
    private Notify notify;
    private int notifySize;
    private Thread notifyThread;
    private long sampleCount;
    private WaveFormat selectedFormat;
    private FileStream waveFile;
    private BinaryWriter writer;
    #endregion
    // ...
}

關鍵點:
• circularBuffer 環狀緩衝區解耦網路接收與播放執行緒。
• NumberRecordNotifications = 4 將緩衝區切四段,觸發通知頻率平衡延遲與 CPU 佔用。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved