我正在使用NAudio打开wav文件。使用SimpleCompressor类之后,我还必须将文件的体积标准化为0db,但是我不知道该怎么做。目前,我有这个:

string strCompressedFile = "";

byte[] WaveData = new byte[audio.Length];


SimpleCompressorStream Compressor = new SimpleCompressorStream(audio);
Compressor.Enabled = true;

if (Compressor.Read(WaveData, 0, WaveData.Length) > 0)
{
    //doing the normalizing now
}

如何从新的字节数组WaveData中获取音量,以及如何更改音量?在WaveData中是整个wav文件,包括文件头

最佳答案

您绝对可以更改单个样本值,使其适合最大级别:

string strCompressedFile = "";

byte[] WaveData = new byte[audio.Length];

SimpleCompressorStream Compressor = new SimpleCompressorStream(audio);
Compressor.Enabled = true;

byte maxLevel = 20;

if (Compressor.Read(WaveData, 0, WaveData.Length) > 0)
{
    for (int i = 0; i < audio.Length; i++)
    {
        if (WaveData[i] > maxLevel)
        {
            WaveData[i] = maxLevel;
        }
    }
}

我添加了一个循环,循环访问所有示例,如果它的值大于maxLevel,我们将其设置为maxLevel

关于c# - 如何在C#中标准化WAV文件量?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44139457/

10-11 08:42