| Author |
Message |
Acoustic Interloper

Joined: Jul 07, 2007 Posts: 2081 Location: Berks County, PA
Audio files: 90
|
Posted: Fri Nov 19, 2010 1:16 pm Post subject:
amplitude leveldetection in chuck? Subject description: How to detect quiet periods? |
 |
|
Any suggestions on how I'd go about detecting low-amplitude periods in an incoming audio stream, where my Chuck code gets to decide the hi-to-low and low-to-hi threshold values? I have an application that is using Lisa to buffer sound thanks to some help from this forum about a half year ago. Now I'd like to scan the audio, either as I am buffering it to Lisa or else after it's buffered in Lisa, for periods during which the amplitude goes below some threshold. I've looked through the docs and nothing obvious jumped out at me. Seems that I shouldn't have to go into frequency domain, since all I care about is overall level.
Thanks in advance. _________________ When the stream is deep
my wild little dog frolics,
when shallow, she drinks. |
|
|
Back to top
|
|
 |
Antimon

Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 373
G2 patch files: 100
|
Posted: Fri Nov 19, 2010 2:18 pm Post subject:
|
 |
|
A brute force method is what first comes to mind:
(pseudoish code)
| Code: | 0 => int currentMax;
fun void checkMax() {
while (true) {
Math.abs(currentSample()) => int mysample;
if (mysample > currentMax) {
mysample => currentMax;
}
currentMax / 1.0001 => currentMax;
1::samp => now;
}
}
spork ~ checkMax();
|
currentMax will hold an approximation of a recent maximum amplitude. Implement currentSample() to return whatever you're scanning. Adjust 1.001 to make currentMax "forget" quicker or slower. You might be able to change 1::samp to something longer with good approximation.
Please tell me if I've gone off on the wrong track. :) I guess some kind of low-pass filter solution could work too - I have a faint memory of using that somewhere...
/Stefan _________________ Antimon's Window
@soundcloud @Flattr home - you can't explain music |
|
|
Back to top
|
|
 |
Acoustic Interloper

Joined: Jul 07, 2007 Posts: 2081 Location: Berks County, PA
Audio files: 90
|
Posted: Fri Nov 19, 2010 2:32 pm Post subject:
|
 |
|
| Antimon wrote: | | Implement currentSample() to return whatever you're scanning. |
So, for example, I could use Lisa's valueAt() to gets and compare values, is that correct? Is that how I might implement currentSample()?
I am hoping to find a ugen that already does this, being concerned that Chuck might be too slow. I suppose I could get by sampling every few milliseconds.
Can I read the level of the adc directly in some way? What other suggestions on implementing currentSample()?
Thanks! _________________ When the stream is deep
my wild little dog frolics,
when shallow, she drinks. |
|
|
Back to top
|
|
 |
Acoustic Interloper

Joined: Jul 07, 2007 Posts: 2081 Location: Berks County, PA
Audio files: 90
|
Posted: Fri Nov 19, 2010 2:51 pm Post subject:
|
 |
|
Did a bit of reading the chuck docs -- I get back to this project a few times a year -- it looks like if I call the ugen.last() periodically (but not for every sample) and keep a rolling average of that value, it might get me what I want. Something to try  _________________ When the stream is deep
my wild little dog frolics,
when shallow, she drinks. |
|
|
Back to top
|
|
 |
Antimon

Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 373
G2 patch files: 100
|
Posted: Fri Nov 19, 2010 4:15 pm Post subject:
|
 |
|
yeah last works on dac as well:
dac.last() => int lastSample;
and lisa:
lisa.last() => int lastOutOfLisa;
I do functions that does simple stuff every sample occasionally. Something simple like this shouldn't bring it down too much - ChucK seems designed to handle this kind of stuff (though of course having it in native C will add less overhead). And of course the tight timing built into it makes it work like a charm.
/Stefan _________________ Antimon's Window
@soundcloud @Flattr home - you can't explain music |
|
|
Back to top
|
|
 |
Acoustic Interloper

Joined: Jul 07, 2007 Posts: 2081 Location: Berks County, PA
Audio files: 90
|
Posted: Fri Nov 19, 2010 6:16 pm Post subject:
|
 |
|
Thanks for your help! I put in a statistical sampling trace of adc.last() -- I only need to "sample the samples," so to speak -- this should work just fine.
One of these summers I am going to have enough time to actually get good at Chuck.
Have a good weekend. _________________ When the stream is deep
my wild little dog frolics,
when shallow, she drinks. |
|
|
Back to top
|
|
 |
|