How to access to L and R channel samples of stereo audio file separately?

人盡茶涼 提交于 2021-02-08 08:26:24

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!