[CM] Sample rate conversion on multi-channel sound question.

Bill Schottstaedt bil at ccrma.Stanford.EDU
Tue, 30 Oct 2007 12:03:00 -0700


> I wish to stretch stereo samples using src in CLM.  Unfortunately the 
> manual examples use outa producing mono result.  I'm currently working 
> on a system to iterate the source signal channels to produce temporary 
> mono files, perform the src, and then reassemble the results.  I'm 
> wondering if there might not be a simpler way? 

This is the Common Lisp CLM?  Here's one way:

(definstrument simple-src (start-time duration amp srt filename)
  (let* ((beg (floor (* start-time *srate*)))
         (end (+ beg (floor (* duration *srate*))))
         (chans (min (mus-channels *output*) (mus-channels filename)))
         (srcs (make-array chans)))
    (loop for i from 0 below chans do
      (setf (aref srcs i) (make-src :srate srt :input (make-file->sample :file filename :channel i))))
    (run
      (loop for i from beg below end do
        (loop for k from 0 below chans do
          (out-any i (* amp (src (aref srcs k))) k))))))


;(with-sound (:channels 2) (simple-src 0 2 .5 1.5 "/home/bil/cl/2.snd"))

The main changes from the example in the manual are the array of src's,
and make-file->sample so that each src gets the specific channel to read.