Old 08-26-2008, 04:49 AM   #1
Jonas_Eriksson_Swe
Human being with feelings
 
Jonas_Eriksson_Swe's Avatar
 
Join Date: Jan 2007
Location: Umeå, Sweden
Posts: 947
Default How do I detect transients?

Hey all,

Does anyone know an effective way detect transients (in audio) in JS? I've read some stuff about detecting transients in general and they all seem doable but if anyone has any pointers on a good way to do it in JS that would be most appreciated.

Regards,
- Jonas
Jonas_Eriksson_Swe is offline   Reply With Quote
Old 08-26-2008, 04:58 AM   #2
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 15,750
Default

I think a pretty standard thing is to track a volume window or envelope, and if the incoming signal gets much higher than the envelope, that means the signal is increasing quickly and you have a transient. You then need to go back in time to the beginning of the transient, so you need some latency.
schwa is offline   Reply With Quote
Old 08-26-2008, 05:16 AM   #3
Jonas_Eriksson_Swe
Human being with feelings
 
Jonas_Eriksson_Swe's Avatar
 
Join Date: Jan 2007
Location: Umeå, Sweden
Posts: 947
Default

Thanks for the quick reply, schwa. I'll try that when I get home (am at work now), do you think I could just compare the actual incoming sample value with the windowed one or do I need to compare a bigger window with a very small one (for reliability)? And while we're on the subject is it standard procedure to check the difference (between the windowed signal/envelope and the incoming signal) in relative or absolute terms?

Regards,
- Jonas

Last edited by Jonas_Eriksson_Swe; 08-26-2008 at 05:25 AM.
Jonas_Eriksson_Swe is offline   Reply With Quote
Old 08-26-2008, 07:23 AM   #4
LOSER
Human being with feelings
 
Join Date: May 2006
Posts: 2,373
Default

Here is something I quickly wrote, maybe you'll find it useful:
Code:
desc:Transient Detector (NOT AN FX!!!)

@init
db = 8.685889638;
idb = 0.115129254;

@slider

rel = 30/srate; // env detector drop in db per sample

tblock = 10/1000 * srate; // block length in spls

trigFactdB = 3; // rms energy rise in db for positive transient 

//reset stuff
env = 0;
env_sum = 0;
env_sum_old = 1000000000;
pos = 0;
t = 0;

@sample

in = max( log( abs(spl0) ) * db , -150); // get input, convert -> db, max to above -150 to prevent -inf#

env = in > env ? in : max(env - rel, in); // do envelope

// rms block measurement / compare
env_sum += env;
(pos+=1) >= tblock ?
(
  pos = 0;
  env_sum /= tblock;
  t = env_sum > env_sum_old+trigFactdB;
  env_sum_old = env_sum;
  env_sum = 0;
);

spl1 = spl0 = t; // t = 1 == transient; t = 0 == no transient :)
Anyway, this is basically integrating over the envelope in chunks of size tblock and if the rms energy from on block to the next rises over trigFactdB a transient is detected and thus t = 1.
Just do a rising edge detect on t to get the transient on set.

Note this is doing this in chunks of tblock length so t will be delayed by tblock AND only updated every tblock samples. Dunno what you need it for but you can easily make the RMS block measurement/compare a running sum RMS and compare each sample and use lookahead to get the most accurate edge of t.

Anyway hope this helps.
LOSER is offline   Reply With Quote
Old 08-26-2008, 09:53 AM   #5
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 15,750
Default

As it happens I did look at this question in detail once ... here's a plot of a bit of a drum kit recording (rectified, in red) with a 2.5 ms fast envelope and a 50 ms slow envelope:



The input signal at around sample 29000 is the hi-hat closing, and floppiness at around 27500 the kick drum resonating. The goal would be onset detection that catches 29000 as a transient but doesn't get fooled by 27500.
schwa is offline   Reply With Quote
Old 08-26-2008, 10:04 AM   #6
LOSER
Human being with feelings
 
Join Date: May 2006
Posts: 2,373
Default

Quote:
Originally Posted by schwa View Post
As it happens I did look at this question in detail once ... here's a plot of a bit of a drum kit recording (rectified, in red) with a 2.5 ms fast envelope and a 50 ms slow envelope:

[...]

The input signal at around sample 29000 is the hi-hat closing, and floppiness at around 27500 the kick drum resonating. The goal would be onset detection that catches 29000 as a transient but doesn't get fooled by 27500.
Cool. Can you try my little script from above and see how it does?
LOSER is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 03:26 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.