Question

Im searching for a way to convert Wave files into a list of numbers to cross-correlate the resulting vectors (like the numbers you get when you read a wave file on MATLAB)

0.6653 -0.8445 0.9589 -0.9999 0.9643 -0.8547 0.6797 -0.4525 0.1907 0.0858 -0.3557 0.5983 -0.7951 0.9309 -0.9953 0.9835 -0.8962 0.7402 -0.5275 0.2742

is there a way to do that in Android or even C/C++? i really dont know how to start.

Was it helpful?

Solution

WAVE file format is fairly simple, especially if you're interested in linear PCM encoded data. Descriptions of the format is available from various sources, such as here and here.

Using these, you should be able to decode:

  • the header ("RIFF" chunk)
  • the "fmt " chunk which contains various information such as the number of bytes per samples, the number of channels (ie. mono, stereo, or more), sampling rate, etc.
  • and the "data" chunk which if the main thing that you'll want to look at in order to create a MATLAB-like vector.

If you're dealing with single channel (ie. mono) WAVE files, the data is fairly straightforward to decode. The number of samples should then corresponds (give-or-take a few bytes for padding) to the size of the data block divided by the number of bytes per sample (the number of bits per sample is available from the "fmt " chunk). The mapping of the samples' integer to a [0-1] floating point value can be done by multiplying by a constant (eg. 1.0/128 for 1-byte-per-sample).

For multi-channel WAVE files, keep in mind that channel data are interleaved (e.g. sample 1 left/right, sample 2 left/right, ...)

Note also that there are a number of tutorial/samples floating around (such as this sample in C or this sample in Java), and various open source sound libraries which you may use as a starting point.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top