How to record audio and modify the signal?
-
Hello everyone, i wan't to create something like a active noise cancellation system . So i want to record audio with a mic in c# and modify the signal, that i get the "negative" or opposite signal and play that negative signal of the ingoing signal. I've never recorded any audio and don't understand, what i get in such a recorded stream. Do i get simple integer values, which i only need to opposite (value * -1) and write them to another stream and put them through or what do i need to do?
-
Hello everyone, i wan't to create something like a active noise cancellation system . So i want to record audio with a mic in c# and modify the signal, that i get the "negative" or opposite signal and play that negative signal of the ingoing signal. I've never recorded any audio and don't understand, what i get in such a recorded stream. Do i get simple integer values, which i only need to opposite (value * -1) and write them to another stream and put them through or what do i need to do?
Hmm. Good luck! Firstly, if you get and audio stream there are many different encodings it could come in. Probably the most common would be 44.1KHz 16 bit. So you'd be dealing with buffers of shorts. Obviously, if you negate this signal and add this to the original, everything cancels out and you end up with silence, so I suspect what you want to do is use two input signals, a reference one, and a background one. Now, because the mics will be in different positions, you'll likely get a phase shift and this will vary depending on the frequency composition of what you're recording. You could actually end up boosting a signal rather than cancelling it if you phase is shifted 180 degrees. I would imagine an effective way to do this is firstly to translate the signal from the time domain to the frequency domain, then compare and adjust the amplitude of the frequency bands, and convert it back again. This involves heavy duty mathematics. Lower frequencies are easier to cancel than higher ones as you may have observed if you have some noise cancelling headphones. Scary stuff, and with the best of respect unless you're well versed in the field of digital signal processing I'd consider doing something else.
Regards, Rob Philpott.
-
Hello everyone, i wan't to create something like a active noise cancellation system . So i want to record audio with a mic in c# and modify the signal, that i get the "negative" or opposite signal and play that negative signal of the ingoing signal. I've never recorded any audio and don't understand, what i get in such a recorded stream. Do i get simple integer values, which i only need to opposite (value * -1) and write them to another stream and put them through or what do i need to do?
If all you want to do is change the phase of your audio signal, you don't need a computer or an app, all it takes is swapping the wires to the speaker! However, noise, by its very definition, is a random signal; meaning whatever it is you capture with a MIC is a thing of the past and will sound like, but be far from identical to, the noise you will encounter later. Cancellation by adding something works fine on predictable sounds, such as the (50Hz or so) rumble of an engine; noise cancellation normally is done through filtering, not by addition. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
Hello everyone, i wan't to create something like a active noise cancellation system . So i want to record audio with a mic in c# and modify the signal, that i get the "negative" or opposite signal and play that negative signal of the ingoing signal. I've never recorded any audio and don't understand, what i get in such a recorded stream. Do i get simple integer values, which i only need to opposite (value * -1) and write them to another stream and put them through or what do i need to do?
-
Hello everyone, i wan't to create something like a active noise cancellation system . So i want to record audio with a mic in c# and modify the signal, that i get the "negative" or opposite signal and play that negative signal of the ingoing signal. I've never recorded any audio and don't understand, what i get in such a recorded stream. Do i get simple integer values, which i only need to opposite (value * -1) and write them to another stream and put them through or what do i need to do?
A simple method (for sine wave signals or predictable noise) is to simply invert the signal and play back at point of origin. This is used in engine noise reduction systems and in top-end industrial machinery.
------------------------------------ I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave CCC League Table Link CCC Link[^]
-
Hello everyone, i wan't to create something like a active noise cancellation system . So i want to record audio with a mic in c# and modify the signal, that i get the "negative" or opposite signal and play that negative signal of the ingoing signal. I've never recorded any audio and don't understand, what i get in such a recorded stream. Do i get simple integer values, which i only need to opposite (value * -1) and write them to another stream and put them through or what do i need to do?
Well, I think that making a noise cancellation system can be a bit more complex than just taking the opposite of the sound samples (depending on what you are trying to do). Typically, sound signals are represented as arrays of either integer of floating point values, also known as samples. There are many ways to represent an audio sample, but the floating point representation usually works best since it results in less loss of precision during processing since it tends to attenuate quantization issues. Good reading material is available in Wikipedia, here[^], here[^] and here[^]. A few years ago I have also written an example on how to record an audio signal from the microphone in C# using SlimDX.[^]. I hope it helps (at least to get started with audio processing). Best regards, Cesar
Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines
-
A simple method (for sine wave signals or predictable noise) is to simply invert the signal and play back at point of origin. This is used in engine noise reduction systems and in top-end industrial machinery.
------------------------------------ I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave CCC League Table Link CCC Link[^]
Exactly that is what i want to do! I know, that callibration of that isn't simple and so on, but i want to try it. If it would be easy, it would by uninteresting. So how can i record audio from a microphone and simply invert the signal and put it out over my speakers?