Old 02-14-2020, 06:16 PM   #1
Per Lichtman
Human being with feelings
 
Join Date: Jun 2008
Posts: 65
Default Labeling Peaks

I'm creating a sample pool from organic drum performances I originally did without sampling in mind. The hits vary greatly in dynamics based on the piece and I would like to label them based on the dynamics without having to go through and sort hundreds (possibly thousands) of them manually.

My current workflow is to use dynamic split then Batch File/Item Converter>Add Selected Media Items but the great list of wildcards doesn't include one for peak/RMS or anything similar.

Does anybody have any tips?
Per Lichtman is offline   Reply With Quote
Old 02-14-2020, 11:55 PM   #2
ErBird
Human being with feelings
 
Join Date: Jan 2017
Location: Los Angeles
Posts: 380
Default

You could have a script that reads either peak, RMS, or loudness per item and changes the item name to that value. Would that be helpful?
ErBird is offline   Reply With Quote
Old 02-15-2020, 01:14 AM   #3
Per Lichtman
Human being with feelings
 
Join Date: Jun 2008
Posts: 65
Default

Yes, that would be perfect. How could that be accomplished?
Per Lichtman is offline   Reply With Quote
Old 02-15-2020, 06:13 PM   #4
ErBird
Human being with feelings
 
Join Date: Jan 2017
Location: Los Angeles
Posts: 380
Default

I'll take any chance I get to practice coding. See if this works for you.
It measures peak RMS (300 ms window) for each item and changes the item name to match.
You'll need to download SWS/S&M if you don't have it.

Lua Script:
Code:
--description: Set Item Names to Peak RMS Value

num_items   = reaper.CountMediaItems(0)
window_size = 0.3 -- RMS Window Size (seconds)

for i=1,num_items do
  item   = reaper.GetMediaItem(0,i-1)
  take   = reaper.GetTake(item,0)
  length = reaper.GetMediaItemInfo_Value(item,"D_LENGTH") -- Store Original Item Length
  if length < 2*window_size then
    length_mult = math.ceil(2*window_size/length)
    new_length  = length*length_mult
    reaper.SetMediaItemLength(item,new_length,0) -- Increase Item Length for Proper Analysis
  end
  -- Initialize Arrays
  array = reaper.new_array(1)
  RMSs  = reaper.new_array(1)
  array.resize(0)
  RMSs.resize(0)
  
  -- Analyze Item Peak RMS
  _               = reaper.NF_AnalyzeMediaItemPeakAndRMS(item,window_size,array,array,RMSs,array)
  peak_RMS        = RMSs[1]
  peak_RMS_string = string.format("%.9f", peak_RMS) -- Change "%.#f" to set Decimal Precision
  
  reaper.SetMediaItemLength(item,length,0) -- Restore Original Item Length
  _,_ = reaper.GetSetMediaItemTakeInfo_String(take,"P_NAME",peak_RMS_string .. " dB RMS",1)
end

function exit()
  reaper.SetMediaItemLength(item,length,0)
end

reaper.atexit(exit)

Code:
--description: Set Item Names to Peak Value

num_items = reaper.CountMediaItems(0)

for i=1,num_items do
  item = reaper.GetMediaItem(0,i-1)
  take = reaper.GetTake(item,0)
  peak = reaper.NF_GetMediaItemMaxPeak(item)
  peak_string = string.format("%.9f", peak) -- Change "%.#f" to set Decimal Precision
  _,_ = reaper.GetSetMediaItemTakeInfo_String(take,"P_NAME",peak_string .. " dB Peak",1)
end

Last edited by ErBird; 02-15-2020 at 09:36 PM. Reason: Added peak script
ErBird is offline   Reply With Quote
Old 02-15-2020, 06:18 PM   #5
Per Lichtman
Human being with feelings
 
Join Date: Jun 2008
Posts: 65
Default

Thank you so much! I’ll try that right away once I figure out where to paste code.
Per Lichtman is offline   Reply With Quote
Old 02-15-2020, 06:21 PM   #6
ErBird
Human being with feelings
 
Join Date: Jan 2017
Location: Los Angeles
Posts: 380
Default

Quote:
Originally Posted by Per Lichtman View Post
Thank you so much! I’ll try that right away once I figure out where to paste code.
NP. I just made a small change, so re-copy.

Also, Actions -> Show Action list -> ReaScript: New
Make sure it's .lua.

If RMS turns out unreliable at predicting dynamics, it could be changed to use peak level.

Last edited by ErBird; 02-15-2020 at 06:26 PM.
ErBird is offline   Reply With Quote
Old 02-15-2020, 06:25 PM   #7
Per Lichtman
Human being with feelings
 
Join Date: Jun 2008
Posts: 65
Default

Okay, re-copied and I’ve got SWS/S&M 2.1.0 #1 running in Reaper 5.99.

I’m about to try “ReaScript; Edit new reaScript (EEL or lua)...” and then the “run” version thereof.

-Crossing my fingers.-

*EDIT: Just saw the actions directions. Will follow those instead.*
Per Lichtman is offline   Reply With Quote
Old 02-15-2020, 06:35 PM   #8
Per Lichtman
Human being with feelings
 
Join Date: Jun 2008
Posts: 65
Default

I just tried on a few sample groups and it worked really well some of the percussion with a long decay (thank you so much!) but it not as well for particularly short hits.

Would it be possible to try the peak method you mentioned?
Per Lichtman is offline   Reply With Quote
Old 02-15-2020, 06:53 PM   #9
ErBird
Human being with feelings
 
Join Date: Jan 2017
Location: Los Angeles
Posts: 380
Default

Quote:
Originally Posted by Per Lichtman View Post
Would it be possible to try the peak method you mentioned?
Sure. Will post a little later.
ErBird is offline   Reply With Quote
Old 02-15-2020, 08:37 PM   #10
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,500
Default

There's also the SWS Label processor which can name takes according to peak levels (run action 'SWS/IX: Label processor' to bring it up).
nofish is offline   Reply With Quote
Old 02-15-2020, 08:48 PM   #11
Per Lichtman
Human being with feelings
 
Join Date: Jun 2008
Posts: 65
Default

Thanks - I'll try that, too. Much appreciated.
Per Lichtman is offline   Reply With Quote
Old 02-15-2020, 09:23 PM   #12
ErBird
Human being with feelings
 
Join Date: Jan 2017
Location: Los Angeles
Posts: 380
Default

Quote:
Originally Posted by nofish View Post
There's also the SWS Label processor which can name takes according to peak levels (run action 'SWS/IX: Label processor' to bring it up).
Hi nofish,

What would you do with files shorter than the RMS window? In the script, I set short items to 4x the RMS window before analysis (2x should do), but now I'm thinking I'll change that to be a whole number multiple of the original length.

Edit: It seems changing the length does nothing unless you glue first. Need to look into this further. Label Processor may be the better option atm.

Last edited by ErBird; 02-15-2020 at 09:45 PM.
ErBird is offline   Reply With Quote
Old 02-16-2020, 09:59 AM   #13
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,500
Default

For drum hits I'd maybe try something shorter than 300 ms window size.
Here I've dragged some random snare/bassdrum hits in, time selection is 300 ms.



Maybe something around 100 ms to catch the 'body' of the hits?
I haven't done detailed experiments with this either though.

Btw., speaking of the label processor:
For the /R argument (peak RMS) the window size can be set via action: 'SWS: Set RMS analysis/normalize options', so that can also be experimented with without need for scripting.

Last edited by nofish; 02-16-2020 at 10:17 AM.
nofish is offline   Reply With Quote
Old 02-17-2020, 07:54 PM   #14
ErBird
Human being with feelings
 
Join Date: Jan 2017
Location: Los Angeles
Posts: 380
Default

Thank you. That makes more sense. I for some reason thought the difference in lengths would figure into the RMS calc as a section with zero amplitude.

Shorter window it is.
ErBird is offline   Reply With Quote
Old 02-17-2020, 09:57 PM   #15
pipelineaudio
Mortal
 
pipelineaudio's Avatar
 
Join Date: Jan 2006
Location: Wickenburg, Arizona
Posts: 13,588
Default

ErBird, you are one seriously awesome person

(bro did you just assume my species?)
pipelineaudio 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 07:24 PM.


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