How to subtract one audio wave from another? In general and in C# (or if we cannot do it 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 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
PS: it’s all about AEC…
If the samples are normalised to the same level, and are stored in a signed format such that the "zero level" is
0
or0.0
, the answer is fairly simple:for each sample
S_A
andS_B
in A and 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. Be careful of overflow - here's an example of how to do the conversions for the aforementioned 16 bit samples: