When you have signed 16-bit samples, you should use a signed 16-bit data type for your buffer:
typedef short int s16;
s16 *buffer = malloc(size_in_bytes);
(You should use SND_PCM_FORMAT_S16
to get the endianness correct.)
In the buffer, every four values are one frame.
for (i = 0; i < capture; i++) {
ch1 = buffer[i * 4 + 0];
ch2 = buffer[i * 4 + 1];
ch3 = buffer[i * 4 + 2];
ch4 = buffer[i * 4 + 3];
// or use a loop over 0..3
...
}
Alternatively, if you want to access all the samples of one specific channel, go over the buffer in steps of four:
// for the first channel
for (i = 0; i < capture; i++) {
sample = buffer[i * 4 + 0];
...
}