问题
Suppose I have 8-bits (mono and stereo) .wav files. When processing of this file I have to declare pointer to array of samples.
Suppose I create array for samples. Then if it is mono
, I read each sample using for(i = 0; i < n; i++ )
.
Q: How can I access right and left channels separately (stereo)?
PS
I've read a lot about "mono, stereo and *.wave" but still I can't understand how can I realise access to each channell separately...
回答1:
You still have array of samples, the question is how you address individual values. This is how you do it:
const UCHAR* pnSamples = ...
if(bMono)
{
for(INT nIndex = 0; ...)
{
const UCHAR nSample = pnSamples[nIndex];
// ...
}
} else
if(bStereo)
{
for(INT nIndex = 0; ...)
{
const UCHAR nLeftSample = pnSamples[2 * nIndex + 0];
const UCHAR nRightSample = pnSamples[2 * nIndex + 1];
// ...
}
}
来源:https://stackoverflow.com/questions/16569859/how-to-access-to-l-and-r-channel-samples-of-stereo-audio-file-separately