❔ Reading a WAV file
I am trying to read wav files and save the DATA to a float array, but the array has a length of about 40 with all wav files I have tried to use.
I think the issue is reading the bytes as up until then the sample rate, bit depth works fine. The issue could be the WAV files themselves aswell as they are downloaded from youtube.
The code is from stackoverflow: https://stackoverflow.com/questions/8754111/how-to-read-the-data-in-a-wav-file-to-an-array and it is the post by P i
(the one that is just one readWav() function)
Stack Overflow
How to read the data in a wav file to an array
I need to get all the samples of a wav file into an array (or two if you need to do that to keep the stereo) so that I can apply some modifications to them. I was wondering if this is easily done (
21 Replies
WAV Files: File Structure, Case Analysis and PCM Explained
Learn the definition and file structure of wave format here, with an explanation of the PCM that stores the wav file.
Will maybe help
Offset for data seems to be
44
based on Subchunk2Size
Do you know where I could get a clean WAV file? Beacuse when I used a hex editor I found out the WAV files downloaded from youtube have a ton of bytes that are just 00?
And I dont think they should be there
I am so confused man, I work on this with my teacher and for some reason his WAV got read successfully and about 1,5million values were stored in the array and I cannot get it to work at all ;(
You can use https://imhex.werwolv.net/ to create your own format and parse it.
to debunk the format issue
ImHex
A Hex Editor for Reverse Engineers, Programmers and people who value their retinas when working at 3 AM.
The pattern used is similar to that of C.
Are you sure that the site is actually converting them?
and not just renaming the extension
well I have already looked at the hex but I really lack the knowledge in this but honestly based on the site you provided the WAV file doesnt look right
I would recommend using NAudio for this
You can load the file using that library and write the samples out
Yeah, my teacher told me to do it without using a library, but if I wont be able to do it over the weekend I will probably have to
Ah, so this is for a class and you have to do it manually
Well technically, it is not graded. I am also not forced to not use a library he just said that it would be preffered
I would recommend using NAudio then, get the program functioning, and then slowly replace parts of it with your own code
You could even study how NAudio works to figure out what you might be missing
Aight that sound like a good idea
It'll probably be more motivating too, it's a lot more enjoyable when you aren't hitting a brick wall and you have something working right in front of you
You could also try writing some code that loads the audio file with NAudio and your code, then compare the data NAudio gives you with what you read
If you get something wrong, that would make it much easier to figure out what it is
Ok thanks for the help
Just found out the code actually works if the WAV file is structured right
So I guess i shouldnt use online converters
Yeah, converters usually forks it up, or just straight out renames the extension
FINALLY
Audacity actually is able to convert a MP3 file to WAV without adding unnecessary bytes at the start of the file
You can also validate that it is a WAV file by checking the magic header
Right lads thanks for the help
https://en.wikipedia.org/wiki/List_of_file_signatures
it should always start with those bytes (pattern)
Thanks man, this showed me a lot about file structure and hex code it is pretty interesting
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.