当我尝试运行一个简单的 DirectSound 程序时,我遇到了这个异常。这是代码:
using System;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.DirectX.DirectSound;
namespace AudioDemo
{
class Program
{
[DllImport("user32.dll")]
private static extern IntPtr GetDesktopWindow();
static void Main(string[] args)
{
// output device
var device = new Device();
device.SetCooperativeLevel(GetDesktopWindow(), CooperativeLevel.Normal);
// format description
var format = new WaveFormat
{
BitsPerSample = 8,
Channels = 1,
FormatTag = WaveFormatTag.Pcm,
SamplesPerSecond = 8000
};
format.BlockAlign = (short)(format.BitsPerSample / 8 * format.Channels);
format.AverageBytesPerSecond = format.SamplesPerSecond * format.BlockAlign;
var outputLatency = 20;
var frameSize = format.AverageBytesPerSecond * outputLatency / 1000;
// buffer
var description = new BufferDescription
{
BufferBytes = frameSize,
Format = format,
DeferLocation = true,
GlobalFocus = true
};
var outputBuffer = new SecondaryBuffer(description, device);
// buffer notifications
var notify = new Notify(outputBuffer);
// ...
}
}
}
var notify = new Notify(outputBuffer);
我在最后一行( )上得到了异常。
不知道出了什么问题。缓冲区已正确初始化。