I'm trying to print out an wave from a wav file, but I'm kinda lost on how the length I should take for an sample.
this is what I would love to archieve (without the colors):
so for reading in my data I use the following code:
// 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 = Converts 2 bytes to an float between -1 and 1
So now I have 2 lists of data, but now how do I how many numbers I should take for creating 1 line?
what confuses me the most:
when you play a song, you can see in most music players the following data, this is in my eyes the representation of 1 sample.
but how do you know the value of each of those bars, and how many bars there are in a sample