Hi!
I am loading a WAV file with
sf::InputSoundFile in C++ and I want to extract the samples for each channel separately. As far as I know the method
sf::InputSoundFile::read(Int16 *samples, Uint64 maxCount) writes an array of interleaved samples to
samples. Each sample is then made up by 16 bits, the first 8 belonging to a channel, and the remaining 8 belonging to the other. My silly question is: should I consider each 8-bits part as an Int8 or as a Uint8? I am very much confused.
A code snippet that performs the conversion from interleaved to separate channels would be also appreciated!
What follows is my attempt to do this conversion.
sf::Int16 samples[1024];
sf::Int16 mono[1024];
file.read(samplesData, 1024);
if (file.getChannelCount() == 2){
for(int k = 0; k < 1024; ++k){
sf::Int16 right = samples[k] & 0x00FF;
sf::Int16 left = (samples[k] & 0xFF00) >> 8;
mono[k] = (right+left)/2; // mean of the two channels
}
}