First, let’s look at what multichan-expand is and does:
MULTICHAN-EXPAND is a macro that takes as it’s arguments, “a function and its list of arguments”.
Example, the function MULT:
(mult a b)
To use MULTICHAN-EXPAND with the above function:
(multichan-expand #'mult a b)
What the macro does, is to look for arrays in the function’s arguments. If an array is found, then the function is applied to each element of the array in turn, and returns an array containing each of the results.
When printed, an array looks like: #(e1 e2 …)
Example:
(setf a (vector 1 2 3)) ;an array with 3 elements
(setf b 2)
(format nil "~a" (multichan-expand #'mult a b)) ;prints #(2 4 6)
If more than one argument is an array, then all of them must have the same number of arguments. The function will then be run using the first element of each array, then the second element, and so on.
The name “multichan-expand” refers to it’s common usage(and the reason it was written) for handling multi-channel sounds. Multi-channel sounds are arrays. A “stereo sound” is an array of two “sounds” (left and right channels).
I suspect that the reason that you had difficulty with multichan-expand is due to your use of TRACK within functions.
Consider this code:
(defun sampleval ()
(print (snd-fetch *track*)))
(sampleval)
The function SAMPLEVAL fetches and prints the value of the first sample of the selected sound from TRACK.
Because SND-FETCH requires a (mono) “sound”, SAMPLEVAL also only works with mono tracks.
Perhaps we can use MULTICHAN-EXPAND to make SAMPLEVAL work with a stereo track ?
Try this (spoiler, it doesn’t work, but use Debug so that you can see the error message)
(defun sampleval ()
(print (snd-fetch *track*)))
(multichan-expand #'sampleval)
The reason that it doesn’t work is that we are NOT expanding the stereo sound array. The only argument passed to MULTICHAN-EXPAND is the function name “sampleval”. What we need to do is to expand TRACK, and pass each element of the stereo array to the function SAMPLEVAL.
So the SAMPLEVAL function needs to look like this:
(defun sampleval (sig)
(print (snd-fetch sig)))
I use the variable name “sig” as an abbreviation of “signal”. Other common names that you may encounter are “snd” or “sound” or “s”, but personally I’m not keen on these names as they can easily be confused with other things, hence I usually use “sig” as the variable name.
We then need to call the function like this (mono track)
(defun sampleval (sig)
(print (snd-fetch sig)))
(sampleval *track*)
NOW we can use multichan-expand and send each channel in track to SAMPLEVAL in turn.
(defun sampleval (sig)
(print (snd-fetch sig)))
(multichan-expand #'sampleval *track*)
(use Debug to see the two printed values)