【问题标题】:Split wav file into byte arrays with NAudio使用 NAudio 将 wav 文件拆分为字节数组
【发布时间】:2021-04-05 09:23:37
【问题描述】:

我想知道如何将 WAV 文件的通道拆分为带有 PCM 数据的两个字节数组。

我一直在尝试用 NAudio 做到这一点,但我无法做到。

【问题讨论】:

    标签: c# .net visual-studio winforms naudio


    【解决方案1】:

    您可以尝试以下方法将 wav 文件拆分为两个字节数组。

     using (WaveFileReader pcm = new WaveFileReader(@"E:\\test.wav"))
                {
                    int samplesDesired = 5000;
                    byte[] buffer = new byte[samplesDesired * 4];
                    short[] left = new short[samplesDesired];
                    short[] right = new short[samplesDesired];
                    int bytesRead = pcm.Read(buffer, 0, 10000);
                    int index = 0;
                    for (int sample = 0; sample < bytesRead / 4; sample++)
                    {
                        left[sample] = BitConverter.ToInt16(buffer, index);
                        index += 2;
                        right[sample] = BitConverter.ToInt16(buffer, index);
                        index += 2;
                    }
          
                    MessageBox.Show("success");
                }
    

    【讨论】:

      猜你喜欢
      • 2013-08-19
      • 1970-01-01
      • 2011-02-09
      • 1970-01-01
      • 1970-01-01
      • 2016-10-26
      • 1970-01-01
      • 1970-01-01
      • 2017-12-07
      相关资源
      最近更新 更多