我想从Kinect录制音频流并将其保存在我的电脑中,所以我在这里引用示例代码。 http://channel9.msdn.com/Series/KinectQuickstart/Audio-Fundamentals
这是我的部分代码。
var border = new Border() {BorderBrush = Colors.Red, BorderThickness = new Thickness(10)};
border.Child = new Image();
SetNativeControl(border);
排队时出现错误" bw.Write(format.wFormatTag);"当我编译代码,但WAVEFORMATEX中的其他行没有错误时,我添加了" Bass.Net"我的参考和使用" Un4seen.Bass" ,但我还是无法修复它。
答案 0 :(得分:0)
看来你正在混合几种不同的SDK。在您提供的链接中,WAVEFORMATEX
定义如下:
struct WAVEFORMATEX
{
public ushort wFormatTag;
public ushort nChannels;
public uint nSamplesPerSec;
public uint nAvgBytesPerSec;
public ushort nBlockAlign;
public ushort wBitsPerSample;
public ushort cbSize;
}
因此,没有枚举值或Un4seen.Bass
引用。写头文件的功能略有不同(仅wFormatTag
值不同):
/// <summary>
/// A bare bones WAV file header writer
/// </summary>
static void WriteWavHeader(Stream stream, int dataLength)
{
//We need to use a memory stream because the BinaryWriter will close the underlying stream when it is closed
using (var memStream = new MemoryStream(64))
{
int cbFormat = 18; //sizeof(WAVEFORMATEX)
WAVEFORMATEX format = new WAVEFORMATEX()
{
wFormatTag = 1,
nChannels = 1,
nSamplesPerSec = 16000,
nAvgBytesPerSec = 32000,
nBlockAlign = 2,
wBitsPerSample = 16,
cbSize = 0
};
using (var bw = new BinaryWriter(memStream))
{
//RIFF header
WriteString(memStream, "RIFF");
bw.Write(dataLength + cbFormat + 4); //File size - 8
WriteString(memStream, "WAVE");
WriteString(memStream, "fmt ");
bw.Write(cbFormat);
//WAVEFORMATEX
bw.Write(format.wFormatTag);
bw.Write(format.nChannels);
bw.Write(format.nSamplesPerSec);
bw.Write(format.nAvgBytesPerSec);
bw.Write(format.nBlockAlign);
bw.Write(format.wBitsPerSample);
bw.Write(format.cbSize);
//data header
WriteString(memStream, "data");
bw.Write(dataLength);
memStream.WriteTo(stream);
}
}
}
WriteString
也负责将其转换为ASCII。我正在引用上面演示文稿中引用的.zip文件(“下载Quickstart slides and samples”,KinectforWindowsSDKV1 \ 6.Audio \ AudioRecorder \ AudioRecorder \ MainWindow.xaml.cs)