SOUNDP

I was writing some new input processor modules today for my new plug-in which uses two channels and ran into a bit
of a “snag” about determining if a user was using mono or stereo tracks.

The (IF (ARRAYP S) (YADDA YADDA)) would work if using the (IF (T) (NIL)) form of this IF statement (in this case),
but I never dug the IF THEN ELSE form of IF so I was searching for a better sollution.

Anyway, I tried

(IF (ATOM S) (YADDA YADDA))

and this worked, but also returned “true” for stereo tracks.

I was much disappointed when I tried:

(IF (SOUNDP S) (PRINT "YES"))

To my surprise, this actually works (printing “YES” for mono tracks) and returns NIL/“false” for stereo tracks.

As SOUNDP is undocumented (as far as I know), I thought i’d mention it here…

Also, this worked in Audacity 1.2.6 so I’m not sure if 1.3 supports it still… :open_mouth:

See here: http://www.cs.cmu.edu/~rbd/doc/nyquist/part8.html#index279

Stereo Sounds are passed to Nyquist as an array with two elements. Each element is a sound.

So for mono, the “s” global is a
For stereo, the “s” global is an array

(if (arrayp s)(print "stereo")) ; prints "stereo" for stereo tracks
(if (soundp s)(print "mono")) ; prints "mono" for mono tracks
(if (arrayp s)
   (if (soundp (aref s 0))(print "left channel"))) ; prints "left channel" for stereo tracks
(if (arrayp s)
   (if (soundp (aref s 1))(print "right channel")))  ; prints "right channel" for stereo tracks



(if (arrayp s)(print "stereo")(print "mono"))
; Prints "stereo" for stereo tracks and "mono" for mono tracks.

Oh yeah, I guess it IS in the manual. I did a Bing search on it and came up with nothing so I guess I figured it wasn’t in there.
Good to know though. Things like this always escape me. Like the time I couldn’t find the (floatp) code anywhere and had to
think of creative uses for (integerp). Finally, after like six months I finally found (floatp), thus saving some coding time.

I find this page of the manual invaluable: http://www.cs.cmu.edu/~rbd/doc/nyquist/indx.html