AudioBuffer_read_interp_pw   xtlang


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm

Implementation

;; where pw is between 0.0 - 1.0
;; and chooses between 'segments' of the audio file
;; where a segment is 1 * looplgth samples long
;; the number of segments is then frames / looplgth
(bind-func AudioBuffer_read_interp_pw
  (lambda (buffer:AudioBuffer* freq:SAMPLE chan:i64 pw:float)
    (set! pw (* pw 0.9999999))
    (let ((channels:i64 (AudioBuffer_channels buffer))
          (frames (AudioBuffer_frames buffer))
          (looplgth (AudioBuffer_loop_frames buffer))
          (loopstart (AudioBuffer_loop_start buffer))
          (oneshot (= looplgth 0))
          (segments (if oneshot 0 (/ frames looplgth)))
          (phase:double (AudioBuffer_phase buffer))
          (rate (/ (convert freq) (convert (midi2frq_local (convert (AudioBuffer_root_pitch buffer))))))
          (pos:double phase)
          (lgth:i64 (if oneshot
                      (- (- frames 1) loopstart)
                      (clamp looplgth
                            0
                            (- frames loopstart))))
          (lgthf:double (convert lgth))
          (offset (* (convert (floor (* pw (convert segments)))) looplgth))
          (mix (% (* pw (convert segments)) 1.0))
          (dat1 (AudioBuffer_ptr buffer offset chan))
          (dat2 (AudioBuffer_ptr buffer (% (+ offset looplgth) frames) chan))
          (dy1 0.0) (dx0 0.0) (dx1 0.0) (dx2 0.0)
          (y1 0.0) (x0 0.0) (x1 0.0) (x2 0.0)
          (y1pos:i64 (* channels (convert (floor (% (- pos rate) lgthf)))))
          (x0pos:i64 (* channels (convert (floor pos))))
          (x1pos:i64 (* channels (convert (floor (% (+ pos rate) lgthf)))))
          (x2pos:i64 (* channels (convert (floor (% (+ pos rate rate) lgthf))))))
      (if (> pos lgthf) 0.0 ;; return silence when past the end (shouldn't happen if looping)
          (begin
            (set! dy1 (- (pref dat2 y1pos) (pref dat1 y1pos)))
            (set! y1 (if (and oneshot (< x0pos 1)) 0.0 (+ (pref dat1 y1pos) (* dy1 mix))))
            (set! dx0 (- (pref dat2 x0pos) (pref dat1 x0pos)))
            (set! x0 (+ (pref dat1 x0pos) (* dx0 mix)))
            (set! dx1 (- (pref dat2 x1pos) (pref dat1 x1pos)))
            (set! x1 (+ (pref dat1 x1pos) (* dx1 mix)))
            (set! dx2 (- (pref dat2 x2pos) (pref dat1 x2pos)))
            (set! x2 (+ (pref dat1 x2pos) (* dx2 mix)))
            (if (= chan 0) ;; increment phase
                (AudioBuffer_set_phase buffer
                                      (if oneshot
                                          (+ pos rate)
                                          (% (+ pos rate) lgthf))))
            ;; return interpolated result
            (hermite_interp_local (dtof (% pos 1.0)) y1 x0 x1 x2))))))


Back to Index

Similar Entries

  • AudioBuffer    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • AudioBuffer    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • AudioBuffer    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • AudioBuffer    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • AudioBuffer    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • AudioBuffer_concat    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • AudioBuffer_cstring    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • AudioBuffer_data_b64    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • AudioBuffer_data_b64_cstring    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • AudioBuffer_from_aiff    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • AudioBuffer_from_wave    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • AudioBuffer_malloc    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • AudioBuffer_read    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • AudioBuffer_read    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • AudioBuffer_read_interp    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • AudioBuffer_read_interp_mix    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • AudioBuffer_read_looped    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • AudioBuffer_read_looped    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • AudioBuffer_set_data_b64    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • AudioBuffer_shared_data    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • PARAM_OSC1_PW    scheme    /digego/extempore/tree/v0.8.9/libs/core/instruments-scm.xtm
  • PARAM_OSC1_PW    scheme    /digego/extempore/tree/v0.8.9/libs/core/instruments-scm.xtm
  • PARAM_OSC1_PW    scheme    /digego/extempore/tree/v0.8.9/examples/sharedsystem/audiosetup.xtm
  • PARAM_OSC2_PW    scheme    /digego/extempore/tree/v0.8.9/libs/core/instruments-scm.xtm
  • PARAM_OSC2_PW    scheme    /digego/extempore/tree/v0.8.9/libs/core/instruments-scm.xtm
  • PARAM_OSC2_PW    scheme    /digego/extempore/tree/v0.8.9/examples/sharedsystem/audiosetup.xtm
  • PARAM_OSC3_PW    scheme    /digego/extempore/tree/v0.8.9/libs/core/instruments-scm.xtm
  • PARAM_OSC3_PW    scheme    /digego/extempore/tree/v0.8.9/examples/sharedsystem/audiosetup.xtm
  • PARAM_OSC4_PW    scheme    /digego/extempore/tree/v0.8.9/libs/core/instruments-scm.xtm
  • PARAM_OSC4_PW    scheme    /digego/extempore/tree/v0.8.9/examples/sharedsystem/audiosetup.xtm
  • aiProcess_FlipWindingOrder    scheme    /digego/extempore/tree/v0.8.9/libs/external/assimp.xtm
  • astra_readX    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/orbbec_test.xtm
  • astra_reader    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/orbbec_test.xtm
  • audiofile_aiff_read_samples    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • audiofile_read_samples    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • audiofile_wave_read_samples    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • dl_osc1_pw    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/dlogue.xtm
  • dl_osc1_pw    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/dlogue.xtm
  • dl_osc2_pw    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/dlogue.xtm
  • dl_osc2_pw    xtlang    /digego/extempore/tree/v0.8.9/libs/core/instruments/dlogue.xtm
  • impc:compiler:print-already-bound-error    scheme    /digego/extempore/tree/v0.8.9/runtime/llvmti.xtm
  • interp2d    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/kinect_fire.xtm
  • midi_read_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/external/portmidi.xtm
  • midi_read_msg    xtlang    /digego/extempore/tree/v0.8.9/libs/external/midi.xtm
  • nonblocking_read_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/nanomsg-request.xtm
  • nonblocking_read_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/nanomsg-reply.xtm
  • nonblocking_read_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/nanomsg-respondent.xtm
  • nonblocking_read_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/nanomsg-surveyor.xtm
  • ocv_imread    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/xtmcv.xtm
  • ocv_imread    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/xtmcv.xtm
  • ocv_imread    scheme    /digego/extempore/tree/v0.8.9/libs/contrib/xtmcv.xtm
  • ocv_imread1    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/xtmcv.xtm
  • ocv_imread2    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/xtmcv.xtm
  • ocv_read    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/xtmcv.xtm
  • ocv_read    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/xtmcv.xtm
  • ocv_read    scheme    /digego/extempore/tree/v0.8.9/libs/contrib/xtmcv.xtm
  • ocv_read1    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/xtmcv.xtm
  • ocv_read2    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/xtmcv.xtm
  • read_and_write_frame    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/opencv_test.xtm
  • set_sampler_audiobuffer    xtlang    /digego/extempore/tree/v0.8.9/libs/external/instruments_ext.xtm
  • sf_read_file_into_buffer    xtlang    /digego/extempore/tree/v0.8.9/libs/external/sndfile.xtm
  • svm_read_line    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/svm.xtm
  • svm_read_problem    xtlang    /digego/extempore/tree/v0.8.9/libs/contrib/svm.xtm
  • sys_file_read    xtlang    /digego/extempore/tree/v0.8.9/libs/external/system.xtm
  • sys_pwd    xtlang    /digego/extempore/tree/v0.8.9/libs/external/system.xtm
  • thread_native_call    xtlang    /digego/extempore/tree/v0.8.9/libs/core/xthread.xtm
  • thread_native_call_with_zone    xtlang    /digego/extempore/tree/v0.8.9/libs/core/xthread.xtm
  • xhid_read    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/hid.xtm