I hope someone can help me solve this little problem.
;; "zero_to_five.xtm"
;; George Wright
;; I have a mono wav file in which the words “Zero One Two Three Four Five” are spoken”.
;; I have opened it in Audacity.app" and exported as a Signed 16-bit PCM wav file named
;; "zero_to_five16.wav"
(sys:load "libs/core/audio_dsp.xtm")
(sys:load "libs/core/audiobuffer.xtm")
;; I can load this into an audiobuffer named "zero2five16":
(bind-val zero2five16 AudioBuffer* (AudioBuffer "Extempore_SavedStuff/SAVED_samples/Words_zero_to_five/zero_to_five16.wav"))
;; (bind-val zero2five AudioBuffer* (AudioBuffer "Extempore_SavedStuff/SAVED_samples/Words_zero_to_five/zero_to_five.aiff"))
;; and play:
(bind-func dsp:DSP
(let ((ab zero2five16))
(lambda (in time chan dat)
(AudioBuffer_read ab chan))))
(dsp:set! dsp)
;; or play repeatedly:
(bind-func dsp:DSP
(let ((ab zero2five16))
(lambda (in time chan dat)
(AudioBuffer_read_looped ab chan))))
;; Now if I play the same file in the Audacity app with the “Start & End Selections” set to Samples, I find that the word ”three” begins after about 87114 samples and ends at about 114374 samples. So I can get the next play to start at the word “three” by setting the playhead to 87114 samples. This works nicer if the non-looped version is re-evaluated.
($ (AudioBuffer_set_playhead zero2five16 87114))
;; I can get it to start at the word "three" by setting the playhead at 114374
($ (AudioBuffer_set_playhead zero2five16 114374))
;; After each time I evaluate this line of code it will sound ”three four five”
; then revert to “Zero One Two Three Four Five” as before if you are on looped.
;; Now what I would like to learn to do is to have it play just the word ”three” only - either just once or repeatedly.
;; In other words I want it to loop from 87114 samples to 114374 samples.
;; And to finish off my wish list I would like to have a random word or group of consecutive words looped with beginning and end sample numbers chosen from a list.
;; I can't see a way to set the end of play.
;; I have looked at (ab:AudioBuffer* seek_to)
;; and the
;; (ab:AudioBuffer* frame chan) version of AudioBuffer_read
;; but I have been able to make them do what I wanted.
;; I’m not clear on what the frame variable is supposed to do. I realise it is sample number times chan number. In audioBuffer.xtm at line 271 or line 288, is it the number of frames to read/loop, the beginning frame of the loop or the number of frames to move the playhead on each cycle or what? I couldn’t get it to make sense.
I'll try to attach the audio file in following post. I can't see how to do it in the google groups page.
Regards
George