/// <summary> /// 音声処理管理部を作成する。 /// </summary> /// <param name="id">この端末のID(どの端末が近くにいるのかの表示に利用)</param> /// <param name="sendBack">比較用データ取得deligate</param> /// <param name="sendInterval">近接センシング用データ送信周期(ミリ秒, 7000ms以下とする)</param> /// <param name="fftLength">比較をかけるサウンドデータのバイト数(32000/s)</param> /// <param name="proximityKeepCycle">一度のTrue判定が影響を及ぼす周期数</param> /// <param name="soundDirectory">音声ログ(16kbps, 16bit)保存のためのディレクトリ</param> /// <param name="errorFile">エラーログを書き出すファイル</param> public SoundControl(string id, SendBackSignalDelegate sendBack, int fftLength, int sendInterval, int proximityKeepCycle, string soundDirectory, string errorFile) { try { this.id = id; SystemDirectory = Path.Combine(soundDirectory, "system"); LogFile = Path.Combine(SystemDirectory, DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".log"); diffTimeDictonary = new Dictionary <string, long>(); sendBackDeligate = sendBack; completeSendBack = new AsyncCallback(CompleteSendBackMethod); SoundControl.soundDirectory = soundDirectory; SoundControl.errorFile = errorFile; if (sendInterval > 7000) { sendInterval = 7000; } CreateDirectory(); this.sendInterval = sendInterval; this.proximityKeepCycle = proximityKeepCycle; dataBuffer = new DataBuffer(this, fftLength); //音量の設定 int mixer; Mixer.init(out mixer); //Mixer初期化 Mixer.SetMainVolume(mixer, 50); //Mainのボリュームを50%に設定 Mixer.SetWaveOutVolume(mixer, 50); //WavOutを50%に設定 Mixer.SetMicRecordVolume(mixer, 100); //マイク録音を100%に設定 // デバイス初期化 CaptureDevicesCollection devices = new CaptureDevicesCollection(); applicationDevice = new Capture(devices[0].DriverGuid); if (applicationDevice != null) { inputFormat = new WaveFormat(); inputFormat.BitsPerSample = BitsPerSample; inputFormat.Channels = Channels; inputFormat.SamplesPerSecond = SamplesPerSec; inputFormat.FormatTag = WaveFormatTag.Pcm; inputFormat.BlockAlign = BlockAlign; inputFormat.AverageBytesPerSecond = AvgBytesPerSec; recordingThread = new Thread(new ThreadStart(RecordWorker)); recordingThread.IsBackground = true; CreateCaptureBuffer(); isActive = true; } } catch (Exception e) { SoundControl.WriteErrorLog(e.ToString()); } }