単純なDirectSoundプログラムを実行しようとすると例外が発生します。ここでは、コードです:DirectSound: "値が予想される範囲内に収まらない。" Notifyを初期化するとき
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);
)上の例外を取得します。
何が間違っているかわかりません。バッファーが正しく初期化されました。
バッファに20msのサウンド(= 320バイト)を保持させたい。 '* 2 'は単なるテストに過ぎませんでした。 – lzm
リアルタイムで生成されたサウンドデータを再生したい場合、どのようなC#フレームワークを使用しますか? – lzm
'waveOutOpen' APIコールはまだ最高ですが、IMHO(これは自分のソフトウェアシンセサイザアプリケーションに使用します)。ここには良いC#ラッパープロジェクトへのリンクがあります:http://www.koders.com/csharp/fidA53BE0F5147E80A51FAC4A7CA140B80436D056EC.aspx – MusiGenesis