-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IO error when reading 32-bit WAV file #21
Comments
Hi @asehgal123, thanks for reporting this! Can you upload the WAV file you're trying to read? My guess is something is weird about the WAV file header. An alternative solution is to use a different library (one designed just for reading audio files) to read your WAV file. I think NAudio has a module which can do this. |
Apparently github won't allow me to upload wav file, can I email that to you? |
Interesting! Perhaps try zipping it, then uploading it? You're welcome to email it to me too, though if it's too big for email it might not come through |
These 2 files are a better example of the issue, original won't work but converted does. |
It doubled in size because the original is mono but the converted one is stereo 🤔 Interestingly the source audio is a 32-bit WAV file, and I'm pretty sure that's the core problem here, but I'll work try to get get it supported anyhow. We're making progress here, but it might take another day or two... thanks for uploading these samples! 👍 Reading it outputs this:
|
This comment has been minimized.
This comment has been minimized.
@asehgal123 install NAudio then use its double[] audio;
int sampleRate;
using (var audioFileReader = new AudioFileReader("asehgal-original.wav"))
{
sampleRate = audioFileReader.WaveFormat.SampleRate;
var wholeFile = new List<float>((int)(audioFileReader.Length / 4));
var readBuffer = new float[audioFileReader.WaveFormat.SampleRate * audioFileReader.WaveFormat.Channels];
int samplesRead = 0;
while ((samplesRead = audioFileReader.Read(readBuffer, 0, readBuffer.Length)) > 0)
wholeFile.AddRange(readBuffer.Take(samplesRead));
audio = Array.ConvertAll(wholeFile.ToArray(), x => (double)x);
}
int fftSize = 8192;
var spec = new Spectrogram(sampleRate, fftSize, stepSize: 4_000, maxFreq: 2_000);
spec.Add(audio);
spec.SaveImage("asehgal.png", intensity: 10_000, dB: true); The audio file you provided is pretty boring - it's just silence - but the bottom 2kHz of its spectrogram looks like this when you run the code above: Hope it helps! |
thanks for your time and help. I will try this out. |
First of all great package, I am definately going to play around with it.
However I am gettting follwing error on line 105 in WavFile.cs
System.IO.EndOfStreamException: 'Unable to read beyond the end of the stream.'
By reading the source code it looks like the loop on line 103 goes through to sampleCount which is calculated based on blocksize. For some reason blocksize is being read as 1 (if I set it to 2 then everything works). I am new to this so I don't fully understand the file format.
Wav file that I am loading has channelCount of 1 and blockSize of 1 (Is that even correct? could it be that wav file is incorrect), you think you can take a look at this issue?
The text was updated successfully, but these errors were encountered: