Sum of samples values of an audio track
Forum rules
This forum is for Audacity on Windows.
Please state which version of Windows you are using,
and the exact three-section version number of Audacity from "Help menu > About Audacity".
Audacity 1.2.x and 1.3.x are obsolete and no longer supported. If you still have those versions, please upgrade at https://www.audacityteam.org/download/.
The old forums for those versions are now closed, but you can still read the archives of the 1.2.x and 1.3.x forums.
Please state which version of Windows you are using,
and the exact three-section version number of Audacity from "Help menu > About Audacity".
Audacity 1.2.x and 1.3.x are obsolete and no longer supported. If you still have those versions, please upgrade at https://www.audacityteam.org/download/.
The old forums for those versions are now closed, but you can still read the archives of the 1.2.x and 1.3.x forums.
Sum of samples values of an audio track
Sorry if my question sounds somehow naïve.
Is there a plug-ins which gives, in a way, the algebraic sum of all samples of a ‘wav’ track?
The sum, in case of a normal audio track, is zero or close to it.
But if the values of the ‘wav’ samples were corrupted, this sum would likely be far from zero. In case the sum is a big number and exceeds a certain high limit, the plug-ins needs returning the value of the limit only.
Thank you.
Kerim
Is there a plug-ins which gives, in a way, the algebraic sum of all samples of a ‘wav’ track?
The sum, in case of a normal audio track, is zero or close to it.
But if the values of the ‘wav’ samples were corrupted, this sum would likely be far from zero. In case the sum is a big number and exceeds a certain high limit, the plug-ins needs returning the value of the limit only.
Thank you.
Kerim
Re: Sum of samples values of an audio track
So long as you're not dealing with a very long track, and the track is mono, running this code in the Nyquist Prompt effect will give you the sum:
Code: Select all
;type analyze
;version 4
(let ((t1 (/ (1- len) *sound-srate*))
(integral (mult (/ *sound-srate* len) (integrate *track*))))
(print (abs-env (sref integral t1))))
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
Re: Sum of samples values of an audio track
Thank you, Steve. You are fast as usual
For instance, the word 'integral' on your code reminded me the low pass filter. Even with 0.1 Hz bandwidth (lowest limit), the filter output gives a good visual sign about the average DC of the track.
Edit1:
I run 2.3.0 on windows 7. I tested your code on a short mono track ("M_RoadToHell_ChrisRea1.wav", I uploaded earlier). I got:
Edit2:
Very sorry, I forgot to select the track.
Now I got the value 0.000110
Thank you again.
Edit3:
Actually, it is 0.000110462 (Debug Output).
For instance, the word 'integral' on your code reminded me the low pass filter. Even with 0.1 Hz bandwidth (lowest limit), the filter output gives a good visual sign about the average DC of the track.
Edit1:
I run 2.3.0 on windows 7. I tested your code on a short mono track ("M_RoadToHell_ChrisRea1.wav", I uploaded earlier). I got:
Code: Select all
error: division by zero
Function: #<Subr-/: #a2f1780>
Arguments:
44100
0
Function: #<FSubr-LET: #a2ec230>
Arguments:
((T1 (/ (1- LEN) *SOUND-SRATE*)) (INTEGRAL (MULT (/ *SOUND-SRATE* LEN) (INTEGRATE *TRACK*))))
(PRINT (ABS-ENV (SREF INTEGRAL T1)))
1>Very sorry, I forgot to select the track.
Now I got the value 0.000110
Thank you again.
Edit3:
Actually, it is 0.000110462 (Debug Output).
Re: Sum of samples values of an audio track
That could have been avoided by error checking. for example:
Code: Select all
;type analyze
;version 4
(cond
((= len 0)
"Error.\nSelection Required")
((arrayp *track*)
"Error.\nStereo tracks are not supported.")
(t
(let ((t1 (/ (1- len) *sound-srate*))
(integral (mult (/ *sound-srate* len)
(integrate *track*))))
(print (abs-env (sref integral t1))))))
Another way you could do that would be to duplicate the track, then use the Normalize effect to "Remove DC offset" (only), then invert the duplicate track and mix the two tracks (Tracks menu > Mix > Mix and Render). The result will be the DC offset. This could also be automated with a Macro (https://manual.audacityteam.org/man/macros.html), or a Nyquist-Macro (https://manual.audacityteam.org/man/nyquist_macros.html).
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
Re: Sum of samples values of an audio track
Another good solution, thank you.steve wrote: ↑Mon Mar 04, 2019 8:34 am[Another way you could do that would be to duplicate the track, then use the Normalize effect to "Remove DC offset" (only), then invert the duplicate track and mix the two tracks (Tracks menu > Mix > Mix and Render). The result will be the DC offset. This could also be automated with a Macro (https://manual.audacityteam.org/man/macros.html), or a Nyquist-Macro (https://manual.audacityteam.org/man/nyquist_macros.html).
(Here it is 10:43 AM, so I thought you were in bed now on the other side of the planet
Re: Sum of samples values of an audio track
Just for kicks, here's a version that can handle stereo tracks. If you wanted to, you could add "headers" to convert this into an installable plug-in (https://wiki.audacityteam.org/wiki/Nyqu ... nce#header).
Code: Select all
;type analyze
;version 4
(defun get-offset(sig)
(let ((t1 (/ (1- len) *sound-srate*))
(integral (mult (/ *sound-srate* len)
(integrate sig))))
(abs-env (sref integral t1))))
(setf *float-format* "%.4f") ;format with 4 decimal places
(if (= len 0)
"Error.\nSelection Required"
(if (arrayp *track*)
(format nil "Left offset: ~a~%Right offset: ~a"
(get-offset (aref *track* 0))
(get-offset (aref *track* 1)))
(format nil "Offset: ~a" (get-offset *track*))))
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
Re: Sum of samples values of an audio track
Thank you, Steve, for the extra work. I saved it and I will install it as a new plug-in.
Although this sum/average function may help, as I mentioned earlier, in detecting corrupted samples in rare cases, it is useful in the case (about which we will talk later if you like) when a different signature is inserted in every copy of an audio file but without affecting in any way the audio quality and its originality... also its DC zero average.
Edited
Although this sum/average function may help, as I mentioned earlier, in detecting corrupted samples in rare cases, it is useful in the case (about which we will talk later if you like) when a different signature is inserted in every copy of an audio file but without affecting in any way the audio quality and its originality... also its DC zero average.
Edited
Last edited by KerimF on Mon Mar 04, 2019 11:37 pm, edited 2 times in total.
Re: Sum of samples values of an audio track
I think the following headers are enough to let your codes (for mono and stereo) be installable plug-ins:
and
Edit:
Corrected
Code: Select all
;nyquist plug-in
;version 4
;type analyze
;name "SumMono"
;author "Steve_AudacityTeam"
Code: Select all
;nyquist plug-in
;version 4
;type analyze
;name "SumStereo"
;author "Steve_AudacityTeam"
Corrected
Last edited by KerimF on Mon Mar 04, 2019 11:46 pm, edited 1 time in total.
Re: Sum of samples values of an audio track
It should probably be ";type analyze", given that it is analyzing the audio.
";type process" is intended for plug-ins that return a modified (processed) version of the selected audio.
";type process" is intended for plug-ins that return a modified (processed) version of the selected audio.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)