find_peaks_log   xtlang


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

Implementation

; Multiresolution peak picking
; Causes buzzing when used in sPL.  This is an sPL issue not a find_peaks_log issue.
; If number of neighbours < 2 there is minimal buzzing
; This will require more work.  Doesn't give same results as MATLAB implementation
(bind-func find_peaks_log:[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);
          (pad_amount:i64 64)
          (peak_index:i64 0)
          (buff_padded:float* (salloc (+ buffer_len pad_amount)))
          (neighbours:i64 0)
          (dummy:i64 0))
      (dotimes (n pad_amount)
        (pset! buff_padded (+ buffer_len n) 0.0))
      (dotimes (n buffer_len)
        (pset! buff_padded n (pref buffer n)))
      (dotimes (n buffer_len) ;peak finding
        (cond ((< n 17)
                (pset! peaks_array peak_index n)
                (set! peak_index (+ peak_index 1)))
              (else (cond ((< n 33)
                           (cond ((= (greater_than_neighbours buff_padded n 1) 1)
                                  (pset! peaks_array peak_index n)
                                  (set! peak_index (+ peak_index 1)))
                                 (else 0)))
                          (else (cond ((< n 65)
                                       (cond ((= (greater_than_neighbours buff_padded n 2) 1) ;n 2
                                              (pset! peaks_array peak_index n)
                                              (set! peak_index (+ peak_index 1)))
                                             (else 0)))
                                      (else (cond ((< n 129)
                                                   (cond ((= (greater_than_neighbours buff_padded n 4) 1) ;n 4
                                                          (pset! peaks_array peak_index n)
                                                          (set! peak_index (+ peak_index 1)))
                                                         (else 0)))
                                                  (else (cond ((< n 257)
                                                               (cond ((= (greater_than_neighbours buff_padded n 8) 1) ;n 8
                                                                      (pset! peaks_array peak_index n)
                                                                      (set! peak_index (+ peak_index 1)))
                                                                     (else 0)))
                                                              (else (cond ((< n 513)
                                                                           (cond ((= (greater_than_neighbours buff_padded n 16) 1) ;n 16
                                                                                  (pset! peaks_array peak_index n)
                                                                                  (set! peak_index (+ peak_index 1)))
                                                                                 (else 0)))
                                                                          (else (cond ((< n 1025)
                                                                                       (cond ((= (greater_than_neighbours buff_padded n 32) 1) ;n 32
                                                                                              (pset! peaks_array peak_index n)
                                                                                              (set! peak_index (+ peak_index 1)))
                                                                                             (else 0)))
                                                                                      (else (cond ((= (greater_than_neighbours buff_padded n 64) 1) ;n 64
                                                                                                    (pset! peaks_array peak_index n)
                                                                                                    (set! peak_index (+ peak_index 1)))
                                                                                                  (else 0)))))))))))))))))
      (cond ((> peak_index 17)
              (pfill! region_lower 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17) ; The 17 ensures that the regions are continuous for entire range.
              (pfill! region_upper 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16)
              (dotimes (n (- peak_index 18))
                  (pset! region_lower (+ n 18) (ftoi64 (ceil (/ (i64tof (+ (pref peaks_array (+ n 18))
                                                                           (pref peaks_array (+ n 17))))
                                                                 (i64tof 2))))))
              (dotimes (n (- peak_index 18)) ;Set the region_upper bound
                  (pset! region_upper (+ n 17) (- (pref region_lower (+ n 18)) 1)))
                  (pset! region_upper (- peak_index 1) buffer_len))
            (else
              (pfill! peaks_array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)))
      ;(if (= trigger 1)
      ;  (begin
      ;    (set! trigger 0)
      ;    (println "peaks")
      ;    (dotimes (n peak_index)
      ;      (printf "%d," (pref peaks_array n)))
      ;    (println "\nlower")
      ;    (dotimes (n peak_index)
      ;      (printf "%d," (pref region_lower n)))
      ;    (println "\nupper")
      ;    (dotimes (n peak_index)
      ;      (printf "%d," (pref region_upper n)))
      ;    (println "")))
      peak_index)))


Back to Index

Similar Entries

  • Clog    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/gsl.xtm
  • ShaderProgram_print_info_log    xtlang    /digego/extempore/tree/v0.8.9/libs/external/gl/gl-objects.xtm
  • Shader_print_info_log    xtlang    /digego/extempore/tree/v0.8.9/libs/external/gl/gl-objects.xtm
  • 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
  • analogue-load-preset    scheme    /digego/extempore/tree/v0.8.9/libs/core/instruments/analogue_fileio-scm.xtm
  • analogue-load-state    scheme    /digego/extempore/tree/v0.8.9/libs/core/instruments/analogue_fileio-scm.xtm
  • analogue-reset    scheme    /digego/extempore/tree/v0.8.9/libs/core/instruments/analogue_fileio-scm.xtm
  • analogue-save-preset    scheme    /digego/extempore/tree/v0.8.9/libs/core/instruments/analogue_fileio-scm.xtm
  • analogueVec_fx    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/analogue.xtm
  • analogueVec_note    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/analogue.xtm
  • analogue_cc    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/analogue_midi.xtm
  • analogue_drwho_bass    xtlang    /digego/extempore/tree/v0.8.9/examples/core/covers.xtm
  • analogue_drwho_lead    xtlang    /digego/extempore/tree/v0.8.9/examples/core/covers.xtm
  • analogue_drwho_swoosh    xtlang    /digego/extempore/tree/v0.8.9/examples/core/covers.xtm
  • analogue_fx    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/analogue.xtm
  • analogue_get_mod_matrix    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/instrument_params.xtm
  • analogue_note    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/analogue.xtm
  • analogue_oxygene_bass    xtlang    /digego/extempore/tree/v0.8.9/examples/core/covers.xtm
  • analogue_oxygene_bass    xtlang    /digego/extempore/tree/v0.8.9/examples/core/synth.xtm
  • analogue_oxygene_lead    xtlang    /digego/extempore/tree/v0.8.9/examples/core/covers.xtm
  • analogue_oxygene_lead    xtlang    /digego/extempore/tree/v0.8.9/examples/core/synth.xtm
  • analogue_oxygene_riff    xtlang    /digego/extempore/tree/v0.8.9/examples/core/covers.xtm
  • analogue_pale_organ    xtlang    /digego/extempore/tree/v0.8.9/examples/core/covers.xtm
  • analogue_remove_file    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/analogue.xtm
  • analogue_reset    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/analogue.xtm
  • analogue_set_mod_matrix    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/instrument_params.xtm
  • blsawXAnalogue_c    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/analogue.xtm
  • bltriXAnalogue_c    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/analogue.xtm
  • cerberus_logRamp    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/cerberus_midi.xtm
  • cl:find-if    scheme    /digego/extempore/tree/v0.8.9/runtime/scheme.xtm
  • dlogue_fx    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/dlogue.xtm
  • dlogue_note    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/dlogue.xtm
  • find_node    xtlang    /digego/extempore/tree/v0.8.9/examples/core/godot_test1.xtm
  • find_peaks    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_analogue_synth_cc_name    xtlang    /digego/extempore/tree/v0.8.9/examples/sharedsystem/setup.xtm
  • get_dialog_handler    xtlang    /digego/extempore/tree/v0.8.9/libs/external/cef/cef.xtm
  • get_find_handler    xtlang    /digego/extempore/tree/v0.8.9/libs/external/cef/cef.xtm
  • get_jsdialog_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-bind-func-details-to-log    scheme    /digego/extempore/tree/v0.8.9/runtime/llvmti.xtm
  • impc:compiler:print-binding-details-to-log    scheme    /digego/extempore/tree/v0.8.9/runtime/llvmti.xtm
  • impc:compiler:print-could-not-resolve-types_find-expr    scheme    /digego/extempore/tree/v0.8.9/runtime/llvmti.xtm
  • impc:compiler:print-dylib-loading-details-to-log    scheme    /digego/extempore/tree/v0.8.9/runtime/llvmti.xtm
  • impc:compiler:print-lib-binding-details-to-log    scheme    /digego/extempore/tree/v0.8.9/runtime/llvmti.xtm
  • impc:compiler:print-polying-details-to-log    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
  • log-error    scheme    /digego/extempore/tree/v0.8.9/runtime/scheme.xtm
  • log-info    scheme    /digego/extempore/tree/v0.8.9/runtime/scheme.xtm
  • log-warn    scheme    /digego/extempore/tree/v0.8.9/runtime/scheme.xtm
  • logRamp    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/analogue_midi.xtm
  • oscXAnalogue_c    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/analogue.xtm
  • pc:find-closest    scheme    /digego/extempore/tree/v0.8.9/libs/core/pc_ivl.xtm
  • print_program_info_log    xtlang    /digego/extempore/tree/v0.8.9/libs/external/opengl.xtm
  • print_shader_info_log    xtlang    /digego/extempore/tree/v0.8.9/libs/external/opengl.xtm
  • xtm_find_bone    xtlang    /digego/extempore/tree/v0.8.9/libs/external/assimp.xtm