0

How to extract data corresponding to definite time intervals from a .wav file?

I have been given a few .wav files and asked to separate the header and data. From the obtained data, samples corresponding to every 160-microseconds should be separated and copied to buffers.

I have now separated the header and got the following information:

Channels: 2, 
Frames: 632956
Sample Rate: 44100, 
Block Align: 4
Valid Bits: 16, 
Bytes per sample: 2

For separating samples corresponding to every 160-microseconds, I am not able to calculate. I tried the following way:

Total bits per 160-microsecond = ((sampling_rate * bit depth) / (time))
 = ((44100 * 16) / (160 * 1000000)) = 0.00441 bits.

I am sure that there is a mistake in the above calculation since there exist 44100 samples per second and hence for 160-microseconds there should exist bits count which is a positive natural number and cannot be a decimal value.

Can someone help with this calculation? Thanks.

  • Possible duplicate of [Reading wav file in Java](https://stackoverflow.com/questions/5210147/reading-wav-file-in-java) – Nikolai Shevchenko May 13 '19 at 19:43
  • @NikolayShevchenko No my question is different. I am attempting to read chunks of data equivalent to a particular time interval. And stuck in calculating the same. Let's say, I read the wav file as mentioned in the other thread and obtain all the data in a byte buffer, how am I pull the data equivalent to 160-microseconds. This is my primary question. – user3022690 May 14 '19 at 02:53

1 Answers1

0

The number of sampling intervals, which fit into time window

N = length_of_time_window / length_of_sampling_interval =
   = length_of_time_window * sampling_frequency = 0.00016 s * 44100 = 7.056

Obviously, the 160 microseconds interval is not divisible by sampling interval, but you can use 7 samples, which corresponds to 158 microseconds. Since each sample should store data for 2 channels, each using 2 bytes, the number of bytes is

Bytes = N * channels * bytes_per_sample = 7 samples * 2 channel * 2 bytes_per_sample
      = 28 bytes
John Smith
  • 1,027
  • 15
  • 31