我正在尝试从 wav 文件中打印出波形,但我有点迷失了样本的长度。
这就是我想要归档的(没有颜色):
因此,为了读取我的数据,我使用以下代码:
// first we need to read our wav file, so we can get our info:
byte[] wav = File.ReadAllBytes(filename);
// then we are going to get our file's info
info.NumChannnels = wav[22];
info.SampleRate = bytesToInt(wav[24], wav[25]);
// nr of samples is the length - the 44 bytes that where needed for the offset
int samples = (wav.Length - 44) / 2;
// if there are 2 channels, we need to devide the nr of sample in 2
if (info.NumChannnels == 2) samples /= 2;
// create the array
leftChannel = new List<float>();
if (info.NumChannnels == 2) rightChannel = new List<float>();
else rightChannel = null;
int pos = 44; // start of data chunk
for (int i = 0; i < samples; i++) {
leftChannel.Add(bytesToFloat(wav[pos], wav[pos + 1]));
pos += 2;
if (info.NumChannnels == 2) {
rightChannel.Add(bytesToFloat(wav[pos], wav[pos + 1]));
pos += 2;
}
}
BytesToFloat = 将 2 个字节转换为 -1 和 1 之间的浮点数
所以现在我有 2 个数据列表,但是现在我应该用多少个数字来创建 1 行?
最让我困惑的是:当你播放一首歌时,你可以在大多数音乐播放器中看到以下数据,这在我看来是 1 个样本的表示。
但是你怎么知道每个条的值,以及样本中有多少条