AudioBuffer - even more tricks
Gidday again
I have loaded another file of further developed examples of use of AudioBuffer onto my Gist.
“play_5_notes_in_temp.xtm”
To run all the examples you require three audio files loaded into extempore/tmp/
I attach the files in the following post. “five_notes.wav" , “WellMayWeSay75.wav”, “nothingWillSave.wav"
I copy here a small section from “play_5_notes_in_temp.xtm”
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(sys:load "libs/core/audiobuffer.xtm")
;; This dsp version will load the "five_notes.wav" file from a tmp folder into a buffer.
(bind-func dsp:DSP
(let ((ab (AudioBuffer "tmp/five_notes.wav")))
(AudioBuffer_set_playhead ab 0)
(lambda (in time chan dat)
(AudioBuffer_read ab chan))))
;; and play the buffer
(dsp:set! dsp)
;; Now if I play the same file in the Audacity app with the “Start & End Selections”
;; in the selection toolbar set to Samples, I find that the first note begins at zero
;; and ends after about 26867 samples. The next silence position is at about 53250 samples.
;; I obtained the boundaries between notes in Audacity by looking for silence points in the file.
:; The sample note boundaries in "five_notes.wav" are (0 26867 53250 79702 106084 132675)
;; Generate a buffer just once instead of regenerating repeatedly.
(bind-val ab5 AudioBuffer* (AudioBuffer "tmp/five_notes.wav"))
($ (println ab5))
;; Now generate an array of note boundaries
(bind-func smpl_bndry ;; boundaries in an array
(lambda ()
(let ((array6:|6,i64|* (alloc))) ;; An array of 6 i64 items
(afill! array6 0 26867 53250 79702 106084 132675) ;; Fill array
array6)))
($ (println (smpl_bndry)))
;; AudioBuffer_read_interp_pw
;; Play a selection of notes from a random starting point.
(bind-func dsp:DSP
(let ((ab ab5) ;; the audiobuffer already built
(v6 (smpl_bndry)) ;; The array of six i64 integers already built
(note_r (imp_rand1_i64 5) )) ;; A random i64 from 0 1 2 3 4
(AudioBuffer_set_loop_start ab (aref v6 note_r)) ;; start from random silent position
(AudioBuffer_set_phase ab5 0.0) ;; I found this step to be critical for some functions
;; set the loop frames large enough to include 2 notes.
(AudioBuffer_set_loop_frames ab (* 2 26867)) ;; This should select just 32notes
(lambda (in time chan dat)
(AudioBuffer_read_interp_pw ab (* 0.9 261.6) chan 0.4)))) ;; There's a mix going on between neighbouring segments
;; changing the root pitch causes notes to be played at higher/lower frequency.
;; changing the pw value 0.0 to 1.0 will shift emphasis in the mix.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
I still haven’t figured out how to use the “frames” version of AudioBuffer_read:
or even what it is supposed to do, so if anyone could enlighten me I would appreciate it.
Regards
George