如何使用RtAudio调整音频声像 [英] How to adjust audio panning with RtAudio

查看:75
本文介绍了如何使用RtAudio调整音频声像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Rtaudio库,我想实现一个音频程序,在其中我可以控制声像(例如,将声音从左声道移到右声道).

I use Rtaudio library and I would like to implement an audio program where I can control the panning (e.g. shifting the sound from the left channel to the right channel).

在我的特定情况下,我使用双工模式(您可以在此处找到示例:

In my specific case, I use a duplex mode (you can find an example here: duplex mode). It means that I link the microphone input to the speaker output.

我应该在输出缓冲区上应用过滤器吗?什么样的过滤器?
谁能帮我吗?

Should I apply a filter on the output buffer? What kind of filter?
Can anyone help me?

推荐答案

要减少左侧的信号,只需将左侧的每个样本乘以小于或等于1的数字,我们称其为l.同样地,对于右边,我们将其称为r.一般来说,您不希望乘以大于1的数字,否则可能会导致信号失真.

To reduce the signal on the left, simply multiply every sample on the left by a number less than or equal to 1, let's call it l. Similarly for the right, we'll call that number r. Generally speaking you don't want to multiply by a number greater than 1, or you might cause the signal to distort.

l和r都是摇摄位置"的功能.如何从平移位置获取数字是一些讨论的问题.如果只是为了简单起见,则可以使用极限值线性减小这些值:

l and r are both functions of the "pan position". How you get from pan position to your numbers is a matter of some discussion. If this is for something simple, you can just ramp the values down linearly, using these values at the extremes:

Hard Left:
l=1; r=0
Center:
l=1; r=1
Hard Right:
l=0; r=1;

如果这是一个奇特的东西,您应该在Google上搜索泛法".这是一个看起来不错的开始的示例:

If this is something fancier, you should google for "pan law". Here's an example that looks like a good start:

http://www.kvraudio.com/forum/viewtopic.php?p = 4264576

更新:我从未使用过RT音频(我通常使用PortAudio,这是相似的),但是我认为要平移的代码看起来像这样,其中l和r如上定义(假设类型为int32_t-带符号的32位整数):/p>

UPDATE: I've never used RT audio (I usually use PortAudio, which is similar), but I think code to pan would look something like this, with l and r as defined above (assuming a type int32_t - signed 32 bit integer):

int inout( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
           double streamTime, RtAudioStreamStatus status, void *data )
{
  if ( status ) std::cout << "Stream over/underflow detected." << std::endl;

  int32_t *ob = (int32_t *)outputBuffer;
  int32_t *in = (int32_t *)inputBuffer;

  unsigned long *bytes = (unsigned long *) data;
  int i =0;
  while( i < bytes / 4 ) {
     ob[i] = (int32_t) ( ib[i] * l + .5 );
     ++i;
     ob[i] = (int32_t) ( ib[i] * r + .5 );
     ++i;
  }
  return 0;
}

这篇关于如何使用RtAudio调整音频声像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆