"CODEBOX" single sample value retrieval
Hi there,
I'm trying to find a way to read a single sample value from a signal, and I've tried using the new "codebox" but I'm having difficulties.
The situation is there is a signal reading 0. with a single sample value of a positive number every couple seconds or so, the amount of time between these positive values changes. Think of it like a single sample pulse wave with both a fluctuating frequency and amplitude. I am trying to find a way to make that single positive value convert to a max message.
If I were to use "snapshot," I would think the signal would need to hold that positive value for much longer than a single sample. So, I've been trying to use "codebox" to replace those 0. values in the signal with the previous positive value passed through. However I've had no luck. Any help would be greatly appreciated!
wouldn't the sah operator be of some use? That's what it does, in fact - the sampled value is broadcast (as is everything in gen~ since nothing is ever "off") until the next value is sampled.
and, of course, what some outta the gen~ object *is* a block of samples, as would be the case with any MSP object. So if you want that output to be less than what your current signal vector is, you'd still use a smaller signal vector value. But doing that detection on the *inside* of the gen~ object is
pretty trivial.
so you don't need the codebox at all, unless you're really jonesing for writing command-line stuff. Unless I'm completely misunderstanding you....
That's great, thanks. Can't believe I missed that one. Maybe I was jonesing...
I can't see how gen~ is really needed for what you want to do, especially if you are trying to trigger a Max message (which can only be as precise in its timing as the Max scheduler interval). For what you describe, you can just use edge~. (See example below.) And as Gregory says, you could use sah~ (or peakamp~) if you want to get the actual value of the nonzero samples.
if you are interested in getting the period between pulses (and thus the frequency), take a look at the gen~.zerox example.
Or this:
This max timing limitation is very unpractical. I don't even need to trigger a max domain event, I just want to record certain sample values into a list for later analysis, and there seems to be no straightforward way of doing that.
CORRECTION:
writing a list is not a problem in gen~. [poke] in combination with [buffer] does that.