Remove the headers from several WAV files, and then concatenate the remaining data into one RAW file

扶醉桌前 提交于 2019-12-05 13:02:47

This code does what you describe (without the padding). It opens the mainFile an then inserts another file at a specified position. If both files have the same format it will work just fine.

public void InsertWave(string mainFile, string insertFile, long position)
{
    byte[] data = File.ReadAllBytes(insertFile);

    using (FileStream main = File.OpenWrite(mainFile))
    {
        main.Seek(position, SeekOrigin.Begin);
        main.Write(data, 0, data.Length);
        main.Close();
    }
}

If both files are 48,000 Hz, 8 bit PCM, signed, mono you can't do anything wrong. However, if one file is mono and the other is stereo or if one is 8 bit and the other is 16 bit your output will be distorted.

It doesn't even matter what format the files are actually using. As long as both have the same format and your position is a multiple of the sample size you will always end up with a valid wave file.

So if your output is distorted it is very likely that the files have different formats. If you convert stereo to mono you must also be aware that you cannot just mix both channels. You must reduve the level by 6dB to keep the same volume.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!