private void CaptureAudio(object parameter)
{
string scratchDirectory = (string)parameter;
string outputFileName = Path.Combine(scratchDirectory, "kinectaudio.wav");
using (var fileStream = new FileStream(outputFileName, FileMode.Create))
{
using (var sampleStream = new StreamWriter(new FileStream(Path.Combine(scratchDirectory, "kinectaudiosamples.log"), FileMode.Create)))
{
WavWriter.WriteWavHeader(fileStream);
//Simply copy the data from the stream down to the file
int count;
while (isRunning && ((count = kinectStream.Read(buffer, 0, buffer.Length)) > 0))
{
fileStream.Write(buffer, 0, count);
recordingLength += count;
double confidence = kinectSource.SoundSourceAngleConfidence;
double a = ANGLE_CHANGE_SMOOTHING_FACTOR * confidence;
angle = (1 - a) * angle + a * kinectSource.SoundSourceAngle;
sampleStream.WriteLine(recordingLength + "\t" +
angle + "\t" +
confidence + "\t" +
kinectSource.BeamAngle);
}
//Complete the wav file by updating the header
WavWriter.UpdateDataLength(fileStream, recordingLength);
}
}
}