简体   繁体   English

根据.wav音频样本创建一个整数数组。 NAudio C#

[英]creating an integer array from .wav audio samples. NAudio C#

I am very new to digital audio programming and am not sure on if what I am doing is correct to get the desired outcome. 我对数字音频编程非常陌生,不确定我在做什么是否正确以达到期望的结果。 I am trying to take a .wav file, and save the individual samples in an array so i can analyze them. 我正在尝试获取.wav文件,并将单个样本保存在数组中,以便我可以对其进行分析。 I am using NAudio AudioFileReader, the following code prints out a vast number of floating point numbers, I have no idea if they would be correct, or they are being altered when converted. 我正在使用NAudio AudioFileReader,下面的代码打印出了大量的浮点数,我不知道它们是否正确,或者在转换时会被更改。 Ideally I would like them as 32 bit integers. 理想情况下,我希望它们为32位整数。 Any advice on how to get there and understand greatly appreciated. 任何有关如何到达那里和理解的建议都将受到赞赏。

  AudioFileReader readertest = new AudioFileReader("C:\\Users\\minford\\Downloads\\Kalimba.wav");
  int bytesnumber = (int)readertest.Length;
  var buffer = new float[bytesnumber];
  readertest.Read(buffer,0,bytesnumber);

        for(int i = 0; i <buffer.Length; i++){
            Console.Write(buffer[i]+ ", ");

        }

Yes, this will print out all the samples as floating point normalised into the range +/- 1.0. 是的,这会将所有样本打印为标准化为+/- 1.0范围内的浮点。 And yes, you will see lots of numbers as there will be many thousands of samples per second. 是的,您会看到很多数字,因为每秒将有成千上万的样本。 I'm not sure why you need them as 32 bit integers. 我不确定为什么需要使用32位整数。 It's likely that the original samples are 16 bit integers, which is the most common choice for WAV files. 原始样本很可能是16位整数,这是WAV文件的最常见选择。 You can use WaveFileReader to read the raw data out into a byte array, and then use any one of several techniques for converting byte array to short array. 您可以使用WaveFileReader将原始数据读出到字节数组中,然后使用几种将字节数组转换为短数组的技术中的任何一种。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM