[CM] re: samples->seconds

Bill Schottstaedt bil@ccrma.Stanford.EDU
Fri, 10 Sep 2004 03:34:54 -0700

 > I've taken to setting both *clm-srate* and *srate* before starting any  work --
 > and below we have reference to mus-srate. It has never been  clear to me which one,
 > if any, was "official." Often setting only one  of them I would get unpredictable
 > results, depending on what instrument  I was using, etc. Rather than tracking down
 > the problem, I just started  using the shotgun approach.
 > Particularly when one is designing one's own instruments: which one  "should" one
 > reference to make sample-rate based calculations?

*srate*.  Here's a paragraph I added to clm.html:

<p>In both Scheme and CL, the *clm-* variables (like *clm-srate*) set the default values.
In CL the corresponding un-clm'd versions (*srate*) hold the current values.  So, if
with-sound doesn't include the :srate argument, *srate* is the same as *clm-srate*;
otherwise it reflects the :srate value for the duration of the with-sound call.
The local variables (in CL) that are currently exported are:
*srate*, *safety*, and *debug*.  Unexported, but available in the clm package
are *channels*, *data-format*, *header-type*, *notehook*, *clipped*, *verbose*,
and *statistics*.

mus-srate is used in Snd (and clm.c). In that context, *clm-srate* holds
the default with-sound setting, and mus-srate holds the current value
(rather than try to deal with dynamic variables in Scheme).  (with-sound's
can be nested, so *srate* is (intended to be) a dynamic variable in
CL, but I'm not sure that was ever a good idea).

In Snd/C/CLM, we have mus-sound-srate (a sound file's srate given the filename),
mus-srate (the current with-sound or CLM output srate), srate (the currently
selected sound's srate), and *clm-srate* (in ws.scm -- the default with-sound
:srate argument value).

You could yoke mus-srate to srate by adding a couple hook functions:

(add-hook! select-sound-hook (lambda (snd) (set! (mus-srate) (srate snd))))
(add-hook! after-open-hook (lambda (snd) (set! (mus-srate) (srate snd))))

You can set the default srate to be 44100 in CL by (setf *clm-srate* 44100).
In Snd it would be (set! *clm-srate* 44100) after loading ws.scm.

Also, in CL there was a sound-srate that was the same as mus-sound-srate;
it's still in CLM-3, but I wish it weren't.  And mus-audio-srate which
refers to the DAC srate.