简体   繁体   English

如何从另一个音频波中减去一个音频波?

[英]How to subtract one audio wave from another?

How to subtract one audio wave from another?如何从另一个音频波中减去一个音频波? In general and in C# (or if we cannot do it in C# in C/C++)一般情况下和在 C# 中(或者如果我们不能在 C/C++ 中的 C# 中做到这一点)

I have sound wave A and sound wave B (BTW: they are in PCM) I want to subtract B from A我有声波 A 和声波 B(顺便说一句:它们在 PCM 中)我想从 A 中减去 B

What do I need?我需要什么? Open Source Libs (NOT GPL, but LGPL will be ok) Tutorials on how to do such operation (with or without using libs) Articles on this topic开源库(不是 GPL,但 LGPL 可以)关于如何进行此类操作的教程(使用或不使用库)关于此主题的文章

PS: it's all about AEC… PS:这都是关于AEC的......

If the samples are normalised to the same level, and are stored in a signed format such that the "zero level" is 0 or 0.0 , the answer is fairly simple:如果样本被归一化到相同级别,并以有符号格式存储,使得“零级别”为00.0 ,则答案相当简单:

S_C = (S_A / 2) - (S_B / 2);

for each sample S_A and S_B in A and B.对于 A 和 B 中的每个样本S_AS_B

If you are using unsigned values for the samples then you will need to do more work: first, you need to convert them to a signed value with a zero centre (eg, if you have 16 bit unsigned samples, subtract 32768 from each), then apply the formula, then convert them back to the unsigned format.如果您对样本使用无符号值,则需要做更多工作:首先,您需要将它们转换为中心为零的有符号值(例如,如果您有 16 位无符号样本,则从每个样本中减去 32768),然后应用公式,然后将它们转换回无符号格式。 Be careful of overflow - here's an example of how to do the conversions for the aforementioned 16 bit samples:小心溢出 - 下面是如何对上述 16 位样本进行转换的示例:

#define PCM_16U_ZERO 32768

short pcm_16u_to_16s(unsigned short u)
{
    /* Ensure that we never overflow a signed integer value */
    return (u < PCM_16U_ZERO) ? (short)u - PCM_16U_ZERO : (short)(u - PCM_16U_ZERO);
}

unsigned short pcm_16s_to_16u(short s)
{
    /* As long as we convert to unsigned before the addition, unsigned arithmetic
       does the right thing */
    return (unsigned short)s + PCM_16U_ZERO;
}

https://stackoverflow.com/questions/1723563/acoustic-echo-cancellation-aec-in-wpf-with-c Asks a similar question and has an accepted answer. https://stackoverflow.com/questions/1723563/acoustic-echo-cancellation-aec-in-wpf-with-c提出了一个类似的问题并得到了一个公认的答案。 The suggested library does have some sort of Echo Cancellation I think.我认为建议的库确实具有某种回声消除功能。

Unfortunately I haven't used any open source audio libraries.不幸的是,我没有使用任何开源音频库。 I have used Fmod to process audio before, I don't remember there being any AEC in it, but you can get access to the raw audio as it processes it and run your own code on it.我以前使用Fmod处理音频,我不记得其中有任何 AEC,但是您可以在处理原始音频时访问原始音频并在其上运行您自己的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM