本文介绍了如何分别访问立体声音频文件的左声道和右声道样本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有8位(单声道和立体声) .wav 文件.处理此文件时,我必须声明指向样本数组的指针.

Suppose I have 8-bits (mono and stereo) .wav files.When processing of this file I have to declare pointer to array of samples.

假设我为样本创建数组.然后,如果它是 mono ,我将使用 for(i = 0; i< n; i ++)读取每个样本.

Suppose I create array for samples. Then if it is mono, I read each sample using for(i = 0; i < n; i++ ).

问:如何分别访问左右声道(立体声)?

PS

我已经阅读了很多有关单声道,立体声和* .wave"的信息,但我仍然不明白如何实现对每个声道的单独访问...

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...

推荐答案

您仍然有示例数组,问题是如何处理各个值.这是您的操作方式:

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];
    // ...
  }
}

这篇关于如何分别访问立体声音频文件的左声道和右声道样本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-23 07:27