Audio Analysis in Extempore

23 views
Skip to first unread message

Jason Levine

unread,
Aug 20, 2015, 4:04:55 PM8/20/15
to Extempore
Hi all, 

I'm hoping to use Extempore in my latest audiovisual commission.  So I need to learn how to get samples from the DSP closure into functions from libraries like libXtract or aubio.  I figured I would teach myself by studying the spectral_meter.xtm example, but unfortunately it does not compile, complaining of:

Compiler Error cannot find symbol  fft_cpxd

in this function:

;; take the time_domain signal (time_buffer) and return the spectrum

(bind-func mag_spectrum



 
(let ((nbins 512) ; number of bins for spectrogram

       
(spectrum:double* (zalloc nbins))

       
(i:i64 0))

   
(lambda (audio:double* fft_window_size time_buffer freq_buffer)

     
(dotimes (i fft_window_size)

       
;; add sum of L and R channels into real component

       
;; of time_buffer (which is a buffer of complex values

       
(tset! (pref-ptr time_buffer i) 0

               
(+ (pref audio (* 2 i)) ; L channel

                 
(pref audio (+ 1 (* 2 i)))))) ; R channel

     
;; take DFT, store results in freq_buffer

     
(fft_cpxd time_buffer freq_buffer fft_window_size)



     
(bin_spectrum spectrum freq_buffer fft_window_size nbins))))



Is it possible that the FFT library has changed since the example was created?


Nonetheless I see where the audio samples are being passed to the spectrum analyzer in dsp.  How could I change this to to use the samples from "in" (for live input) instead of an audio file?


(bind-func dsp:DSP 100000000 ; make sure we allocate enough memory



 
(let ((audio_length 60)

       
(audio:double* (zalloc (* 44100 2 audio_length)))

 
(samples_read (read_audio_data "/path/to/audiofile.wav"

                                       audio

                                       
0

                                       
(* 44100 audio_length)))

       
(playhead 0)

       
(fft_window_size 1024)

       
(time_buffer:cpxd* (zalloc fft_window_size))

       
(freq_buffer:cpxd* (zalloc fft_window_size))

       
(i:i64 0))

   
(lambda (in time chan dat)

     
(if (and (= (modulo playhead fft_window_size) 0)

               
(= chan 0.0))

         
(mag_spectrum (pref-ptr audio playhead) fft_window_size

                        time_buffer freq_buffer
))

     
;; increment playhead once per (stereo) pair of samples

     
(if (= chan 1.0)

         
(set! playhead (modulo (+ playhead 1)

                                 
(* audio_length 44100))))

     
;; play audio

     
(pref audio (+ (dtoi64 chan) (* 2 playhead))))))



Thanks and please let me know if you know how to fix the spectral_meter.xtm example!

Jason


Reply all
Reply to author
Forward
0 new messages