Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER Q&A, Tips, Tricks and Howto

Reply
 
Thread Tools Display Modes
Old 10-23-2017, 10:03 PM   #1
AugerJ
Human being with feelings
 
Join Date: Dec 2015
Posts: 476
Default Convert audio amplitude to Volume envelope

Hello.
Is this possible:
apply the actual volume (or gain) of an audio piece
as Volume envelope to another track or item?
AugerJ is offline   Reply With Quote
Old 10-24-2017, 02:36 AM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,900
Default

There was some experimental stuff made by spk77 for that :

Cockos Incorporated Forums - View Single Post - v5.0pre - New ReaScript functions/IDE testing

I think this is the last update of this, not sure

REAPER | Resources

(not in Reapack apparently).

Edit: not sure it is the right script. Let us know if you find it :P

Last edited by X-Raym; 10-24-2017 at 02:46 AM.
X-Raym is offline   Reply With Quote
Old 10-24-2017, 03:19 AM   #3
AugerJ
Human being with feelings
 
Join Date: Dec 2015
Posts: 476
Default

Thanks.
This script seems to be the one I needed:
mpl_Generate track volume automation item from audio take.lua

Last edited by AugerJ; 10-24-2017 at 03:51 AM.
AugerJ is offline   Reply With Quote
Old 10-24-2017, 09:49 AM   #4
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,984
Default

You can merge AI to envelope by right click on envelope, then 'Delete automation item, preserve points'.
Also it is probably better to generate AI from time selection of selected track ignoring takes selection instead direct item/take selection.
mpl is offline   Reply With Quote
Old 10-24-2017, 11:25 AM   #5
AugerJ
Human being with feelings
 
Join Date: Dec 2015
Posts: 476
Default

Quote:
Originally Posted by mpl View Post
You can merge AI to envelope by right click on envelope, then 'Delete automation item, preserve points'.
Thanks.

Quote:
Also it is probably better to generate AI from time selection of selected track ignoring takes selection instead direct item/take selection.
Currently I don't have an access to such a script )

By the way, in my case I had to move created AI 43ms left for it to align with the "source" item better.
AugerJ is offline   Reply With Quote
Old 06-04-2020, 08:03 PM   #6
woodslanding
Human being with feelings
 
woodslanding's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Posts: 633
Default

Wow, trying to use this and all I get is a bunch of points at level= -infinity.

Is there some trick to it?
__________________
eric moon
Very Stable Genius
https://gogolab.com/
woodslanding is offline   Reply With Quote
Old 06-05-2020, 09:39 AM   #7
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,900
Default

Pretty sure you have Fader Sacling actiavted on the track


Try to deactuvate it beforer unning the script


and if this solve the problem, the script would need an update o support it :P(just few lines of code)
X-Raym is offline   Reply With Quote
Old 06-05-2020, 12:25 PM   #8
woodslanding
Human being with feelings
 
woodslanding's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Posts: 633
Default

How would I do that? A search for fader scaling in the action list doesn't turn anything up, and I don't see it in the menus...
__________________
eric moon
Very Stable Genius
https://gogolab.com/
woodslanding is offline   Reply With Quote
Old 06-05-2020, 02:05 PM   #9
woodslanding
Human being with feelings
 
woodslanding's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Posts: 633
Default

Changing to Amplitude scaling did not change the results....

I'm using v1.1

EDIT: I right-clicked the envelope and changed its scaling. Now it works!

THANKS!!!!!!!
Attached Images
File Type: png faderScalingOFF.png (28.3 KB, 152 views)
__________________
eric moon
Very Stable Genius
https://gogolab.com/

Last edited by woodslanding; 06-05-2020 at 02:13 PM.
woodslanding is offline   Reply With Quote
Old 06-05-2020, 04:02 PM   #10
woodslanding
Human being with feelings
 
woodslanding's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Posts: 633
Default

OMG this is an awesome feature!!!

One FR: Could you make it affect the currently selected envelope, instead of always volume??

Heck, maybe I can figure that out myself...
__________________
eric moon
Very Stable Genius
https://gogolab.com/
woodslanding is offline   Reply With Quote
Old 06-06-2020, 08:42 AM   #11
woodslanding
Human being with feelings
 
woodslanding's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Posts: 633
Default

oh gosh, stupid easy!

Select an item, select an envelope (even on a different track) and away you go! Envelope must be set to linear mode, NOT fader mode. This is less likely with a non-volume envelope....

Volume is rarely where I want to send this anyway, and I rarely want the destination track the same as the source track...

Thanks MPL for writing this!!

Code:
-- @version 1.1
-- @author MPL  (tiny edit by Woodslanding)
-- @description Generate automation item on selected envelope from audio take
-- @website http://forum.cockos.com/showthread.php?t=188335
-- @changelog
--    + respect multiple items
--    + Consolidate undo
--    # fix proper add points positions

  
  for key in pairs(reaper) do _G[key]=reaper[key]  end  
  function m(s) reaper.ShowConsoleMsg(s)end
 
  ---------------------------------------------------------------------------------------------------------------------  
  function Get_take_data(take, window,item_len)
    local sum_t = {}
    local accessor = CreateTakeAudioAccessor(take)
    local src = GetMediaItemTake_Source(take)
    local numch = GetMediaSourceNumChannels(src)
    local rate = GetMediaSourceSampleRate(src)       
    local size = math.ceil(window*rate)
      
    for read_pos = 0, item_len, window do
      local buffer = new_array(size*2)
      local buffer_com = new_array(size*2)
      GetAudioAccessorSamples(
                          accessor , --AudioAccessor
                          rate, -- samplerate
                          numch, -- numchannels
                          read_pos, -- starttime_sec
                          size, -- numsamplesperchannel
                          buffer) --samplebuffer
                          
      -- merge buffers dy duplicating sum/2
        for i = 1, size*numch - 1, numch do
          buffer_com[i] = (buffer[i] + buffer[i+1])/numch
          buffer_com[i+1] = 0
        end
                                            
      -- Get RMS sum in defined range
        local buffer_com_t = buffer_com.table(1,size, true)
        local sum_com = 0
        for i = 1, size do sum_com = sum_com + math.abs(buffer_com_t[i]) end    
        table.insert(sum_t, sum_com)
          
      end
    DestroyAudioAccessor(accessor)

    -- normalize table
      local max_com = 0
      for i =1, #sum_t do max_com = math.max(max_com, sum_t[i]) end
      local com_mult = 1/max_com      
      for i =1, #sum_t do sum_t[i]= sum_t[i]*com_mult  end
      table.insert(sum_t, 1, 0)
      return sum_t
  end
  ---------------------------------------------------------------------------------------------------------------------
  function CalcAI(item, window_ms)
    if not item then return end
    local take =  reaper.GetActiveTake( item )
    if TakeIsMIDI( take ) then return end
        
    local i_pos = GetMediaItemInfo_Value( item, 'D_POSITION' )
    local i_len = GetMediaItemInfo_Value( item, 'D_LENGTH' )    
    if not  window_ms then return end 
       
    local t = Get_take_data(take, window_ms, i_len)
    local track = GetMediaItem_Track(item)
    SetOnlyTrackSelected(track)
    --env =  GetTrackEnvelopeByName( track, 'Volume' )
    env = GetSelectedEnvelope();
    if not env then 
      Main_OnCommand(40406,0) -- show vol envelope
      env =  GetTrackEnvelopeByName( track, 'Volume' )
    end
    local AI_idx = InsertAutomationItem( env, -1, i_pos, i_len )
    for i = 1, #t do InsertEnvelopePointEx( env, AI_idx, (i-1)*window_ms+i_pos, t[i], 0, 0, 0, true ) end
    Envelope_SortPointsEx( env, AI_idx )
    UpdateArrange()
  end
  
  local ret, window_ms =  reaper.GetUserInputs( 'RMS window', 1, '(seconds)', 0.05 )
  if ret then
    Undo_BeginBlock()
    window_ms = tonumber(window_ms)
    for i = 1,  CountSelectedMediaItems( 0 ) do
      local item = GetSelectedMediaItem(0,i-1)
      CalcAI(item, window_ms)
    end
    Undo_EndBlock( 'Generate AI from audio item', 0 )
  end
__________________
eric moon
Very Stable Genius
https://gogolab.com/
woodslanding 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 05:33 AM.


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