【问题标题】:32bit wav file metadata32 位 wav 文件元数据
【发布时间】:2013-07-04 07:01:20
【问题描述】:

我正在尝试将正弦波写入立体声 32 位 wav 文件。我假设该值可以在 -2147483647 和 +2147483647 之间,这可能是错误的,因为我没有得到所需的结果。

//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,所以我有点困惑。除了文件的标题,我找不到任何关于实际数据的信息。那么有人可以描述一下这里发生了什么吗?

解决方案(感谢 Roman 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头文件怎么写?

标签: c# audio wav


【解决方案1】:

32 位 PCM 格式也可以使用(甚至更频繁)单精度浮点值,范围为 -1.0..1.0

标头必须将其指定为WAVE_FORMAT_IEEE_FLOAT,有关详细信息,请参阅Extensible Wave-Format Descriptors

【讨论】:

    猜你喜欢
    • 2011-01-04
    • 2013-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-20
    • 1970-01-01
    相关资源
    最近更新 更多