find_peaks   xtlang


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/libs/contrib/TSM_library.xtm

Implementation

;find peaks as per Laroche and Dolson (bigger than 4 neighbours)
;In the future, consider the efficiency difference of zero padding a copy of the buffer
;versus maths of accounting for out of bounds indexes
;The code is certainly easier using zero padding
;This code assumes that the peaks memory allocated is correctly sized or bigger
;The number of peaks is returned to allow for easier function use. (ceil(buffer_size/3)) for > 4 neighbours
(bind-func find_peaks:[i64,float*,i64,i64*,i64*,i64*]*
  (lambda (buffer:float* buffer_len:i64 peaks_array:i64* region_lower:i64* region_upper:i64*)
    (let ((n:i64 0);
          (peak_index:i64 0)
          (buff_padded:float* (salloc (+ buffer_len 4))))
      (pset! buff_padded 0 0.0) ;Zero pad the buffer
      (pset! buff_padded 1 0.0)
      (pset! buff_padded (+ buffer_len 2) 0.0)
      (pset! buff_padded (+ buffer_len 3) 0.0)
      (dotimes (n buffer_len)
        (pset! buff_padded (+ n 2) (pref buffer n)))
      (dotimes (n buffer_len) ;peak finding
        (if (> (pref buff_padded (+ n 2)) (pref buff_padded n))
          (if (> (pref buff_padded (+ n 2)) (pref buff_padded (+ n 1)))
            (if (> (pref buff_padded (+ n 2)) (pref buff_padded (+ n 3)))
              (if (> (pref buff_padded (+ n 2)) (pref buff_padded (+ n 4)))
                (begin
                  (pset! peaks_array peak_index n)
                  (set! peak_index (+ peak_index 1))))))))  ;After all peaks are found, peak index becomes the number of peaks
      (if (> peak_index 0)
        (begin
          (pset! region_lower 0 0) ;Set the region_lower bound
          (dotimes (n (- peak_index 1))
            (pset! region_lower (+ n 1) (ftoi64 (ceil (/ (i64tof (+ (pref peaks_array n)
                                                                    (pref peaks_array (+ n 1))))
                                                         (i64tof 2))))))


Back to Index

Similar Entries

  • Widget_find_inorder    xtlang    /digego/extempore/tree/v0.8.9/libs/external/gui.xtm
  • Widget_find_postorder    xtlang    /digego/extempore/tree/v0.8.9/libs/external/gui.xtm
  • Widget_find_preorder    xtlang    /digego/extempore/tree/v0.8.9/libs/external/gui.xtm
  • aiProcess_FindDegenerates    scheme    /digego/extempore/tree/v0.8.9/libs/external/assimp.xtm
  • aiProcess_FindInstances    scheme    /digego/extempore/tree/v0.8.9/libs/external/assimp.xtm
  • aiProcess_FindInvalidData    scheme    /digego/extempore/tree/v0.8.9/libs/external/assimp.xtm
  • ai_find_matching_node    xtlang    /digego/extempore/tree/v0.8.9/libs/external/assimp.xtm
  • cl:find-if    scheme    /digego/extempore/tree/v0.8.9/runtime/scheme.xtm
  • find_node    xtlang    /digego/extempore/tree/v0.8.9/examples/core/godot_test1.xtm
  • find_peaks_log    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/TSM_library.xtm
  • find_previous_peak    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/TSM_library.xtm
  • find_sexprs    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/cas.xtm
  • find_sqr_exprs    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/cas.xtm
  • get_find_handler    xtlang    /digego/extempore/tree/v0.8.9/libs/external/cef/cef.xtm
  • gui_find_leaf_inorder    xtlang    /digego/extempore/tree/v0.8.9/libs/external/gui.xtm
  • gui_find_leaf_postorder    xtlang    /digego/extempore/tree/v0.8.9/libs/external/gui.xtm
  • gui_find_leaf_preorder    xtlang    /digego/extempore/tree/v0.8.9/libs/external/gui.xtm
  • gui_find_next_id    xtlang    /digego/extempore/tree/v0.8.9/libs/external/gui.xtm
  • gui_find_parent    xtlang    /digego/extempore/tree/v0.8.9/libs/external/gui.xtm
  • gui_find_widget_with_id    xtlang    /digego/extempore/tree/v0.8.9/libs/external/gui.xtm
  • iffchunk_find_dumb    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • iffchunk_find_smart    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • impc:compiler:print-could-not-resolve-types_find-expr    scheme    /digego/extempore/tree/v0.8.9/runtime/llvmti.xtm
  • impc:ti:find-all-vars    scheme    /digego/extempore/tree/v0.8.9/runtime/llvmti.xtm
  • impc:ti:find-unresolved-simple-types    scheme    /digego/extempore/tree/v0.8.9/runtime/llvmti.xtm
  • instrument_find_note    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments.xtm
  • pc:find-closest    scheme    /digego/extempore/tree/v0.8.9/libs/core/pc_ivl.xtm
  • xtm_find_bone    xtlang    /digego/extempore/tree/v0.8.9/libs/external/assimp.xtm