electro-music.org   Dedicated to experimental electro-acoustic
and electronic music
 
 Front Page  |  Radio  |  Forum  |  Media  |  Playlists  |  Wiki
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
amplitude leveldetection in chuck?
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [6 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
Acoustic Interloper



Joined: Jul 07, 2007
Posts: 2081
Location: Berks County, PA
Audio files: 90

PostPosted: Fri Nov 19, 2010 1:16 pm    Post subject: amplitude leveldetection in chuck?
Subject description: How to detect quiet periods?
Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Visit poster's website
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 373
G2 patch files: 100

PostPosted: Fri Nov 19, 2010 2:18 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Visit poster's website
Acoustic Interloper



Joined: Jul 07, 2007
Posts: 2081
Location: Berks County, PA
Audio files: 90

PostPosted: Fri Nov 19, 2010 2:32 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Visit poster's website
Acoustic Interloper



Joined: Jul 07, 2007
Posts: 2081
Location: Berks County, PA
Audio files: 90

PostPosted: Fri Nov 19, 2010 2:51 pm    Post subject: Reply with quote  Mark this post and the followings unread

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 Smile
_________________
When the stream is deep
my wild little dog frolics,
when shallow, she drinks.
Back to top
View user's profile Send private message Visit poster's website
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 373
G2 patch files: 100

PostPosted: Fri Nov 19, 2010 4:15 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Visit poster's website
Acoustic Interloper



Joined: Jul 07, 2007
Posts: 2081
Location: Berks County, PA
Audio files: 90

PostPosted: Fri Nov 19, 2010 6:16 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [6 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
Log in
Username:     Password:      Log me on automatically each visit    


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2026 by electro-music.org