0

我正在尝试录制 wav 文件。我的应用程序需要允许用户在不同的采样率和位深度之间进行选择。不管我尝试什么语法,我总是得到相同比特率的文件。有人可以告诉我我做错了什么吗?

[DllImport("winmm.dll")]
private static extern long mciSendString(string command, StringBuilder retstring, int returnLength, IntPtr callback);

...

private void btnRecord_Click(object sender, EventArgs e)
{
    mciSendString("Open new Type waveaudio alias recSound", null, 0, IntPtr.Zero);
    mciSendString("setaudio recSound algorithm pcm", null, 0, IntPtr.Zero);
    mciSendString("setaudio recSound samplespersec to 44100", null, 0, IntPtr.Zero);
    DisableRecordingButtons();
    mciSendString("Record recSound", null, 0, IntPtr.Zero);
}
4

1 回答 1

2

setaudio 命令用于视频而不是音频。显然您需要使用 set 命令设置音频参数,并且需要以正确的顺序设置参数。设置命令应该是这样的......

string setCommand = "set recSound alignment 4 bitspersample " + BitDepth.ToString() + " samplespersec " + SampleRate.ToString() + " channels 1 bytespersec " +
            (BitDepth * SampleRate * 1 / 8).ToString() + " time format milliseconds format tag pcm";
        mciSendString(setCommand, null, 0, IntPtr.Zero);

对齐参数始终为 4,字节每秒始终为 (bitspersample * samplespersec * channels / 8)。

于 2018-02-06T16:11:04.417 回答