Reputation: 49
I am using libsndfile in C++ to read a WAV file. There are two points I don't understand:
sf_readf_float()
in library sndfile.h? Is there any method to do this?Upvotes: 1
Views: 3206
Reputation: 1104
The format field will give you the BPS. For e.g.: SF_FORMAT_PCM_16.
The sf_readf_float will convert the sample into the -1.0 to 1.0 range no matter the bps of the input sound. You only have to take care that about the audio channels. If the audio has 2 channels and you read 4 floats, you will have:
sample-1 of left channel
sample-1 of right channel
sample-2 of left channel
sample-2 of right channel
Then, to draw the point you must convert the [-1.0;1.0] to the viewport height. For e.g. if viewport is at Y=20 and the height is 300px, the formula is:
PY = (int)(20.0 + (sample_value / 2.0 + 0.5) * 300.0);
Upvotes: 3