我正在试着录制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);
}发布于 2018-02-07 00:11:04
setaudio命令用于视频,而不是音频。显然,您需要使用set命令设置音频参数,并且参数需要以正确的顺序设置。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,bytespersec始终为(bitspersample * samplespersec *channel/ 8)。
https://stackoverflow.com/questions/48605360
复制相似问题