Would this code for dc bias adjust work?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Would this code for dc bias adjust work?

David R. Sky
Hi Edgar,

The first macro below, peak, is from nyquist.lsp from a pre-1.2.3
Audacity. Would the remaining code be valid to adjust a signal's
(expression's) dc bias, without using an hp filter?

David

;; (PEAK sound-expression number-of-samples) - find peak amplitude
;
; NOTE: this used to be called s-max
;
(defmacro peak (expression maxlen)
    `(snd-max ',expression ,maxlen))

(defmacro inv-peak (expression maxlen)
    `(snd-min ',expression ,maxlen))

(defun bias-adjust (expression)
(setf high (peak expression ny:all)) ; maximum signal height
(setf low (inv-peak expression ny:all)) ; minimum signal height
(setf amplitude (- high low)) ; peak-to-peak
(setf mid-amp (/ amplitude 2.0)) ; midpoint of signal
(setf adjust (- mid-amp)) ; dc bias to add to or subtract from
; expression, so expression goes from -value to +value

(sum expression adjust))


(bias-adjust s)



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Audacity-nyquist mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/audacity-nyquist
Reply | Threaded
Open this post in threaded view
|

Correction for code I just posted...

David R. Sky
Hi Edgar,

I made some math errors, corrections below. David

;; (PEAK sound-expression number-of-samples) - find peak amplitude
;
; NOTE: this used to be called s-max
;
(defmacro peak (expression maxlen)
    `(snd-max ',expression ,maxlen))

(defmacro inv-peak (expression maxlen)
    `(snd-min ',expression ,maxlen))

(defun bias-adjust (expression)
(setf high (peak expression ny:all)) ; maximum signal height
(setf low (inv-peak expression ny:all)) ; minimum signal height
(setf center (* 0.5 (+ high low))) ; midpoint of signal
(setf adjust (- center)) ; dc bias to add to or subtract from
; expression, so expression goes from -value to +value

(sum expression adjust))


(bias-adjust s)



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Audacity-nyquist mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/audacity-nyquist