(bind-func AudioBuffer_concat
(lambda (ab1:AudioBuffer* ab2:AudioBuffer*)
(if (or (<> (AudioBuffer_samplerate ab1) (AudioBuffer_samplerate ab2))
(<> (AudioBuffer_channels ab1) (AudioBuffer_channels ab2)))
(begin (println "Error: cannot concat incompatible audiobuffers") null) ;; return null on error!
(let ((new (AudioBuffer (+ (AudioBuffer_frames ab1) (AudioBuffer_frames ab2))
(AudioBuffer_channels ab1)
(AudioBuffer_samplerate ab1)))
(dat1 (AudioBuffer_ptr new 0 0))
(dat2 (AudioBuffer_ptr new (AudioBuffer_frames ab1) 0)))
(memcpy (cast dat1) (cast (AudioBuffer_ptr ab1 0 0)) (* (AudioBuffer_frames ab1) (AudioBuffer_channels ab1) 4))
(memcpy (cast dat2) (cast (AudioBuffer_ptr ab2 0 0)) (* (AudioBuffer_frames ab2) (AudioBuffer_channels ab2) 4))
new))))