1
我想写一个正弦波的32位WAV文件。我认为这个值可能在-2147483647和+2147483647之间,这可能是错误的,因为我没有得到所需的结果。32位的WAV文件元数据
//I add 8 to i because it is a stereo wav file and this way I'am able to modify only the left channel (or right)
for (int i = 0; i < capturedAudioBuffer.BytesRecorded; i=i+8)
{
//sin function gives a result between -1 and 1 therefore I convert it into the required range.
int sinval = (int)(2147483646 * ((System.Math.Sin(((i/8)/180.0f) * (double)System.Math.PI))));
byte[] b1 = new byte[4];
b1 = convertToByte(sinval);
capturedAudioBuffer.Buffer[i + 3] = b1[0];
capturedAudioBuffer.Buffer[i + 2] = b1[1];
capturedAudioBuffer.Buffer[i + 1] = b1[2];
capturedAudioBuffer.Buffer[i] = b1[3];
}
我创建了一个程序的正弦波,似乎最大值为BF 80 00 00和最小值为3F 80 00 00所以弄得我一点点。我找不到有关实际数据的信息,但是找不到文件头。那么有人能描述我这里发生了什么吗?
溶液(感谢罗马R.):
float sinval = (float)(((System.Math.Sin(((i/8)/180.0f) * (double)System.Math.PI))));
b1 = System.BitConverter.GetBytes(sinval);
capturedAudioBuffer.Buffer[i + 3] = b1[3];
capturedAudioBuffer.Buffer[i + 2] = b1[2];
capturedAudioBuffer.Buffer[i + 1] = b1[1];
capturedAudioBuffer.Buffer[i] = b1[0];
你怎么写wav头? – JeffRSon
32位PCM格式也可以使用单精度浮点值“-1.0..1.0”。标题必须指定它是'WAVE_FORMAT_IEEE_FLOAT'。 –
它比你工作。 – DalekSupreme