#region 建構函數
public CaptureSound()
{
InitializeCommon();
InitializeDeviceSelector();
InitializeWaveFormatSelector();
Initialize();
}
public CaptureSound(Capture device)
{
InitializeCommon();
selectedDevice = device;
InitializeWaveFormatSelector();
Initialize();
}
public CaptureSound(WaveFormat waveFormat)
{
InitializeCommon();
selectedFormat = waveFormat;
InitializeDeviceSelector();
Initialize();
}
public CaptureSound(Capture device, WaveFormat waveFormat)
{
InitializeCommon();
selectedDevice = device;
selectedFormat = waveFormat;
Initialize();
}
#endregion
// 共用初始化邏輯
private void InitializeCommon()
{
isRecording = false;
positionNotify = new BufferPositionNotify[5];
notificationEvent = null;
buffer = null;
fileName = string.Empty;
notify = null;
notifyThread = null;
waveFile = null;
writer = null;
captureBufferSize = 0;
nextCaptureOffset = 0;
sampleCount = 0L;
notifySize = 0;
}
設計重點:
• 共用欄位初始化提煉至 InitializeCommon() 避免重複。
• 支援裝置/格式任意組合,滿足不同錄音場景需求。