【问题标题】:Correct way to set MCI audio parameters in C#在 C# 中设置 MCI 音频参数的正确方法
【发布时间】:2018-02-07 00:11:04
【问题描述】:

我正在尝试录制 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);
}

【问题讨论】:

    标签: c# audio-recording mci


    【解决方案1】:

    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);
    

    alignment 参数始终为 4,bytespersec 始终为 (bitspersample * samplespersec * channels / 8)。

    【讨论】:

      猜你喜欢
      • 2016-03-13
      • 1970-01-01
      • 1970-01-01
      • 2017-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-19
      相关资源
      最近更新 更多