Some time ago, tedd posed a question to the list concerning
generation of variable frequency sounds. At first it appeared that
current Macs are limited by their controller chips to generating only
MIDI sounds. However, I discovered several apps that were able to
produce variable frequencies down to fractions of a hertz independent
of octave structure. I shared these with tedd, but to date am still
stymied as to how the developers did this.
While studying Carbon, I came across a recommendation that a new command--
rateMultiplierCmd -- when used as part of the sound record, could be
used to produce variable frequencies.
Here is the C code from Apple's developer web site:
OSErr RaisePitchOneOctave(SndChannelPtr chan)
{
SndCommand cmd;
OSErr err;
cmd.cmd = rateMultiplierCmd;
cmd.param1 = 0;
cmd.param2 = 0x00020000; // rate of 2.0
err = SndDoImmediate(chan, &cmd);
return (err);
}
Here is my FB^3 translation of the C code (which may or may not be
correct, but should serve as a basis for discussion. The C code above
lists only one value form cmd.param2, but below I have commented out
several others shown in a chart on Apple's sample code page.):
LOCAL
DIM err AS HANDLE
DIM @cmd
DIM @rateMultiplierCmd
LOCAL FN RaisePitchOneOctave( soundChannelPtr )
cmd.cmd = rateMultiplierCmd
cmd.param1 = 0
// Decimal value 1.0
// Plays sound at normal pitch setting (default)
'cmd.param2 = 0x00010000
// Decimal value 2.0
// Plays sound at a pitch shifted up one octave
cmd.param2 = 0x00030000
// Decimal value 0.5
// Plays sounds at a pitch shifted down one octave
'cmd.param2 = 0x00005000
// Decimal value 1.5
// Plays sounds at a pitch shifted up half an octave
'cmd.param2 = 0x00015000
// Decimal value 0.0
// Repeat last audio sample indefinitely,
// which effectively pauses playback on this channel
'cmd.param2 = 0x00000000
err = FN SNDDOIMMEDIATE( soundChannelPtr, cmd )
END FN
My question to the list is, can anyone see how to incorporate this
code into a working demo? It appears that by altering the second cmd
parameter, this function could be used to generate a variety of
frequencies (probably more accurately described as pitch shifts). But
as to implementation, I'm stuck.
Ken