Help with counter object

seabed's icon

Hello Max users,

I need some help to control the data of a counter. Actually I am trying to calculate the median of a signal and then count how many times the signal's value is bigger than its median. For that purpose I use snapshot, zl.group and zl.median. I don't know if there is a simpler way.

So for every 512 values (that's zl.group size) I calculate the median and count how many of these values exceed it. Then reset the counter and count again for the new median and so on. The problem is that I want to keep only the last value of the counter before reset it, for further use. Can you help me understand how to do it?

Cheers

Wetterberg's icon

you can use "int" to hold the number for you. Make good use of the "trigger" object, to order it so that you store the value before resetting.

If you need any more specific help I'd need to see the patch, I think.

seabed's icon

Hey thanks for the help. Here is my patch. I added the sound generator so as you can test it. I suggest you to drag&drop an audio file with a big duration. As you can read in the bubbles, for a set of 100 values, I count how many of them exceed a pair of calculated medians. Then I want to keep the last number just before the counter is reset.

Max Patch
Copy patch and select New From Clipboard in Max.

I know about trigger but I can't find how to use it so as to hold just the last number. Can you help me please?

Wetterberg's icon

that's why I mentioned the "int" object. That's what's actually holding the object.

seabed's icon

Yes I know but I can't find how it can hold just the last number before reset.

Chris Muir's icon
Max Patch
Copy patch and select New From Clipboard in Max.
Wetterberg's icon

^^^^ like that, yeah. ^^^^

seabed's icon

Oh thanks! That works smoothly.

Here is another one more complicated question. I noticed that there is a kind of delay due to snapshot and group objects. Let's say that snapshot's interval time is 4 samples and the size of group 11025 samples. I suppose that means 11025 samples/sec as long as s.r. is 44100Hz. Right?

Max Patch
Copy patch and select New From Clipboard in Max.

However it takes almost 4 secs to calculate the first median. Any idea why this is happening? I am trying to synchronize the incoming signal with a delay~ but it's not so strict synchronization.

Roman Thilenius's icon

snapshot~ does not introduce any delay, except that its output is no longer running at signal rate. (but, at least, high priority, so it will be quite accurate if overdrive is on.)

seabed's icon

Yes, it seems like having overdrive on makes it more accurate. Thanks!

seabed's icon

Hi again,

well as it is said snapshot's output is no longer running at signal rate as long as time interval is 1ms. Is there any way to have snapshot's output running at signal rate (44.1kHz) ?

Wetterberg's icon

No, snapshot~ is made to downsample from signal rate to scheduler rate.

I'd do the averaging in signal rate instead. have you had a look at avg~?

Roman Thilenius's icon

if snapshot~ would run at signal rate it would just output the input. :)

seabed's icon

@ Wetterberg: Ok i see. I know about avg but as long as my signal is interpolated (a lot of zeroes) I am interested in median and not average value.

@ Roman: Hehe, you are right. But I am using zl.group and zl.median which are both using lists. So snapshot~ seems to be the only way to convert a signal to list.

seabed's icon

By the way, if a signal is connected to number~ then from the right outlet you have the incoming signal value as float a at signal rate. Am I right? I noticed that in that way the output rate is even slower than that of snapshot~ (1ms interval time). Isn't that strange or do I miss something?

broc's icon

Look at the inspector of number~. The default update interval is 100ms, and it can be set to 20ms as minimum.

seabed's icon

Oh ok. So obviously snapshot with interval to 1ms is the closest you can get to signal rate. I can't understand why there isn't any way to convert a signal value to float at signal rate.