Forums

removing dc offset from 24-bit sound samples

Started by Arun Chandra April 11, 2015
Arun Chandra wrote:
> hi folks, > > is there freely available C code to remove DC offset from 24-bit sound samples? > > I have tried modifying code that was released by robert bristow-johnson for use with 16-bit sounds, but I'm unable to modify it correctly for use with 24-bit sounds. > > any leads would be appreciated. > > Arun Chandra > COM 301 > Performing Arts > The Evergreen State College > Olympia WA 98505 >
The amplitude of the DC offset of a signal is simply the sum of all the samples divided by the number of samples. -- Les Cargill
wow!  thanks very much for all your comments!  Robert Bristow-Johnson's code worked perfectly.

Arun

Arun Chandra
COM 301
Performing Arts
The Evergreen State College
Olympia WA 98505
>robert bristow-johnson <rbj@audioimagination.com> writes: > >> On 4/11/15 4:00 AM, Marcel Mueller wrote: >>> On 11.04.15 05.14, Arun Chandra wrote: >>>> is there freely available C code to remove DC offset from 24-bit
sound
>>>> samples? >>> >>> First of all you need to decide which kind of filter you want to
apply.
>>> It is impossible to remove /only/ DC on the fly because you would
need
>>> to know all samples in the future. >> >> so how much DC is left if there is a zero squarely on z=1? > >He didn't say that you could not completely remove DC, but that you >cannot completely remove ONLY DC. Yeah, there are no infinitely-narrow >notch filters. >-- >Randy Yates >Digital Signal Labs >http://www.digitalsignallabs.com
If you already have the sample you can take the average of all the values. That is the DC component. This can then be subtracted from all the sample values. On the fly is a different story, but it seems the OP has recorded samples. Ced --------------------------------------- Posted through http://www.DSPRelated.com
On 4/11/15 2:14 PM, Arun Chandra wrote:
> > wow! thanks very much for all your comments! Robert Bristow-Johnson's code worked perfectly. >
i remember Tim had a variant that was more efficient. but because Google Groups is so f**ked up, i cannot find that post. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
"Cedron" <103185@DSPRelated> writes:

>>robert bristow-johnson <rbj@audioimagination.com> writes: >> >>> On 4/11/15 4:00 AM, Marcel Mueller wrote: >>>> On 11.04.15 05.14, Arun Chandra wrote: >>>>> is there freely available C code to remove DC offset from 24-bit > sound >>>>> samples? >>>> >>>> First of all you need to decide which kind of filter you want to > apply. >>>> It is impossible to remove /only/ DC on the fly because you would > need >>>> to know all samples in the future. >>> >>> so how much DC is left if there is a zero squarely on z=1? >> >>He didn't say that you could not completely remove DC, but that you >>cannot completely remove ONLY DC. Yeah, there are no infinitely-narrow >>notch filters. >>-- >>Randy Yates >>Digital Signal Labs >>http://www.digitalsignallabs.com > > If you already have the sample you can take the average of all the > values. That is the DC component. This can then be subtracted from all > the sample values. On the fly is a different story, but it seems the OP > has recorded samples.
Where do you get that from? I see nothing in his OP that states explicitly one way or the other. -- Randy Yates Digital Signal Labs http://www.digitalsignallabs.com
On 4/11/15 2:35 PM, Cedron wrote:
> > If you already have the sample you can take the average of all the > values. That is the DC component. This can then be subtracted from all > the sample values. On the fly is a different story, but it seems the OP > has recorded samples. >
another problem, while strictly speaking what Ced says is true, is that really it's the *local* DC that you want removed. so you can have a sound file that starts and ends with silence (and silence is zero), but the average of all samples might not be zero (due to some lopsided waveforms or something). if you subtract that average, then the beginning and end silence have a DC offset. "click" another reason you might not want to just subtract the average of a long sound file is that, over that long sound file, the DC component might drift and you want the value subtracted to also drift. there is an issue of response time of the DC-blocking filter which is directly related to how low the cutoff frequency is. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
> >Where do you get that from? I see nothing in his OP that states >explicitly one way or the other. >-- >Randy Yates >Digital Signal Labs >http://www.digitalsignallabs.com
Just an inference from his syntax. You are right, it isn't explicit which is why I used the qualified "seems". r b-j's point about localized DC is well taken (and much more interesting). I have seen some serious centerline drift in live recordings. It doesn't seem to impact playback too much though. Ced --------------------------------------- Posted through http://www.DSPRelated.com
"Cedron" <103185@DSPRelated> writes:
> [...] > r b-j's point about localized DC is well taken (and much more > interesting). I have seen some serious centerline drift in live > recordings. It doesn't seem to impact playback too much though.
If you are playing back without switching sources, I can see where you wouldn't notice too much. What happens when you switch the source in such scenarios? And why in the world would "live" versus studio make a difference in DC offset drift? -- Randy Yates Digital Signal Labs http://www.digitalsignallabs.com
>"Cedron" <103185@DSPRelated> writes: >> [...] >> r b-j's point about localized DC is well taken (and much more >> interesting). I have seen some serious centerline drift in live >> recordings. It doesn't seem to impact playback too much though. > >If you are playing back without switching sources, I can see where you >wouldn't notice too much. What happens when you switch the source in >such scenarios? > >And why in the world would "live" versus studio make a difference >in DC offset drift? >-- >Randy Yates >Digital Signal Labs >http://www.digitalsignallabs.com
Well, I've never owned a studio, but I would record bands live with two condenser mics, left and right channel. I never switched sources either, so I can't answer that either, I'm sorry. I would record shows and burn them to CDs for the bands. I also examined the recordings with software, which is where I noticed the drift. I suspect that any coupling capacitors in the playback circuits would not allow the DC (or minor slow fluctuations) to pass to the speakers. I have also written software in the past to generate tone files. I am familiar with the 'click' effect that r b-j referenced when there is a discontinuity in the sound samples. So, if you were to do a whole file pure DC adjustment, you would definitely want to put ramps on the ends. One more point. The algorithm in the source code in this thread does exponential smoothing with shift operations in lieu of multiplication and division. If (as I assumed) the entire file is available before processing, an exponential smoothing pass can be made in reverse. The two smoothed curves should be averaged and then the result subtracted from the signal. This will center the 'drift bumps' where they occur, rather than lagged, which is what happens with a moving average. (Shameless self promotion warning) I'll be addressing this technique in an upcoming blog article. In the meanwhile, please check out the two I've already written at dsprelated (dot) com. Ced --------------------------------------- Posted through http://www.DSPRelated.com
both you guys are a hoot.


-- 

r b-j                  rbj@audioimagination.com

"Imagination is more important than knowledge."