Search code examples
c#naudio

How to get the corresponding time of a byte from WAV file?


I'm sorry that it's kind of hard to put this concept into the question title, maybe somebody could help, thanks!

I was able to get the "byte-wised" waveform watching this video.

Turned the whole WAV file into a byte array, now my question is:

How could I get the corresponding time from the certain index of the byte array!?

For example, b[3520] corresponding to 0.013s!?

I had thought about maybe I could divide the total timespan of the WAV file by the total length of the bit array, then I would know how much time each byte occupy.

But I was sketchy about the accuracy, is there any more accurate way to do such a thing!?

Much appreciated.


Solution

  • I would try using WaveFormat.BitsPerSample and WaveFormat.SampleRate.

    eg. BitsPerSample = 32 => 4bytes WaveFormat.SampleRate = 44100 => 4*44100bytes/sec I don't know if this way will be more accurate.