Closed swharden closed 3 years ago
To improve readability I refactored this:
using var afr = new NAudio.Wave.AudioFileReader(filePath);
int sampleRate = afr.WaveFormat.SampleRate;
int sampleCount = (int) (afr.Length / afr.WaveFormat.BitsPerSample / 8);
to this:
using var afr = new NAudio.Wave.AudioFileReader(filePath);
int sampleRate = afr.WaveFormat.SampleRate;
int bytesPerSample = afr.WaveFormat.BitsPerSample / 8;
int sampleCount = (int)afr.Length / bytesPerSample;
I don't have a reason to doubt the output. With my test WAV files in the data folder it matches my expectation based on tests using Python's scipy.io.wavfile
module. @shirok1 if you can provide a WAV file that fails this test upload it here and I can take a closer look.
from scipy.io import wavfile
samplerate, data = wavfile.read("cant-do-that-44100.wav")
EDIT: Python falls over with obscure formats like 32-bit floating format. I used GoldWave to calculate WAV file data length in this case to get accurate values that match NAudio and ReadWAV()
(#33)
Content originally posted by @shirok1 in #33:
Wrong
sampleCount
expression inReadWAV
(readme.md)I guess this
sampleCount
is an estimation of the final size of theList<double> audio
. However, 253296 is 64 times smaller than 16210944. So the most reasonable explanation is/8
is a typo of*8
.This "typo" causes the birth of garbage twice as large as the
audio
itself.