How to find average / average sound in Nyquist

I am trying to write a simple measuring plugin for Audacity, and it is about as much fun as dropping stones on my skull. All I want to do is take a piece of sound and find the average of all samples (fragment DC offset ) so that I can represent this as a number for the user, and so I can subtract the DC offset from the samples for further processing. I know and understand the math I want to do, but I donโ€™t understand how to do this in Lisp / XLisp / Nyquist / whatever.

Background information in this stream

As far as I know, there is no function for this. For some reason, the snd-avg function does not actually calculate the average sound value, as you might expect. It first executes the absolute value, and then calculates the average value , calculates the average value and then performs the absolute value. Although there is a separate snd-abs function that can do this. >: (

So I have to write my own? Does this mean converting sound to an array and then calculating its average value?

(snd-fetch-array sound len step)

Reads sequential arrays of samples from sound, returning either an FLONUM or NIL array when the sound ends.

(snd-samples sound limit)

Converts patterns to a lisp array.

Nyquist Functions

And thereโ€™s not even an average function, so will I have to do the amount too? But do math functions only work on lists? So, do I need to convert an array to a list?

And it will also use a huge amount of memory for longer signals (18 bytes per sample), so it would be better to process it in pieces and make an aggregate average . But I donโ€™t even know how to make an unoptimized version.

No, (hp s 0.1) will not work because:

  • I want to remove only DC and keep arbitrarily low frequencies. 0.01 Hz should pass unchanged, DC should be removed.
  • The high-pass filter is causal, and the first waveform samples remain unchanged, regardless of which knee frequency you use, making it useless for measuring peak samples, etc.
+4
source share
1 answer

NEVERMIND

snd-maxsamp computes the absolute value, not snd-avg . snd-avg works just fine. Here's how to squeeze a number out of it ("FLONUM"):

 (snd-fetch (snd-avg s (round len) (round len) OP-AVERAGE)) 

This creates a negative number for negative samples and a positive number for positive samples, as it should be.

Should this question be deleted or left as an example to others?

0
source

All Articles