How to subtract one sound wave from another?

How to subtract one sound wave from another? In general, and in C # (or if we cannot do this in C # in C / C ++)

I have sound wave A and sound wave B (BTW: they are in PCM) I want to subtract B from A

What I need? Open Source Libs (NOT GPL, but LGPL will be fine) Tutorials on how to do such an operation (with or without libs) Related articles

PS: all about AEC ...

+4
source share
2 answers

If the samples are normalized to the same level and stored in a signed format, so that the "zero level" is 0 or 0.0 , the answer is quite simple:

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

for each sample S_A and S_B in and B.

If you use unsigned values โ€‹โ€‹for samples, you will need to do more work: first, you need to convert them to a value with a sign with a zero center (for example, if you have 16-bit unsigned samples, subtract 32768 from each), then apply the formula and then convert them back to unsigned format. Be careful with overflow - here is an example of how to do conversions for the above 16-bit patterns:

 #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; } 
+5
source

https://stackoverflow.com/questions/1723563/acoustic-echo-cancellation-aec-in-wpf-with-c He asks a similar question and accepts the accepted answer. The proposed library does have a kind of echo cancellation, I think.

Unfortunately, I have not used any open source audio libraries. I used Fmod to process sound before, I donโ€™t remember that it has AEC, but you can access how it processes it and runs its own code on it.

0
source

All Articles