View Single Post
Old 06-13-2018, 09:53 PM   #1
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,984
Default PCM_Source_GetPeaks can anyone check?

Code:
  
  function GetPeaks(take, conf)
    if not take then return end
    local peakrate = conf.WF_peaks_resolution or 5000
    local src = GetMediaItemTake_Source( take )
      if not src then return end
      local src_len =  GetMediaSourceLength( src )
      local n_spls = math.floor(src_len*peakrate)
      if n_spls < 10 then return end 
      local n_ch = 1
      local want_extra_type = 115  -- 's' char
      local arr_sz = n_spls * n_ch * 3
      local buf = new_array(arr_sz)
        -------------
      local retval =  PCM_Source_GetPeaks(    src, 
                                        peakrate, 
                                        0,--starttime, 
                                        n_ch,--numchannels, 
                                        n_spls, 
                                        want_extra_type, 
                                        buf )
      local spl_cnt  = (retval & 0xfffff)
      peaks = {}      
      local id = 0
      local arr_s_sz = math.floor(arr_sz/3)
      for i=1, arr_s_sz,2 do  
        id = id + 1 
        peaks[id] = {val = buf[i],
                     pitch = buf[i+arr_s_sz*2],
                     pos = i * src_len / spl_cnt}
      end
      buf.clear()
      return peaks, src_len
  end
I try to build table which return value, pitch and position from (spectral) peaks. Am I doing this right? Not sure about minimum/maximum thing and pitch integers is MIDI pitch right?
mpl is offline   Reply With Quote