I'm looking for a way to play random sounds - in the form of
programmatically-generated on-the-fly tones of arbitrary duration and
frequency, similar to the old cartoon stereotype of "this is what a
computer hard at work sounds like".
"Back in the day", it was possible to use something like the following
BASIC-like snippet to achieve a reasonable approximation of the result I
want:
10 do something
20 do something else
30 GOSUB 100
40 do something else
50 etc etc etc
99 END
100 REM play 20 random tones of random duration
110 FOR I = 1 TO 20
120 Note = RND(255)
130 Duration = RND(255)
140 PLAY(Note,Duration)
150 NEXT I
160 RETURN
Of course, this assumes that the BASIC in question (as several did) had
a "PLAY" keyword that took a tone and duration input, and made a noise
corresponding to the inputs come out of the speaker.
In digging around on Apple's site, I can find lots of ways to play
*CANNED* sound tracks - MP3 files, QT movie audio tracks, various other
"flavors" of canned sound, but nothing that lets me do what I'm trying
to accomplish "on the fly". I can't even find any method of saying "I
want X milliseconds of frequency Y to come out of the speaker" without
having it come from a "pre-built" file (or something that looks like it
has come from such a file) of some sort - not even at an ultra-low
level, never mind from any sort of high level API that works with 10.3.9
(or, for that matter, nothing even as far back as 7.5.5!)
There *MUST* be a way to "directly tickle the chips", even if it means
the equivalent of POKE-ing values into memory locations and then hitting
a memory-mapped "go make it happen" switch - if there wasn't, playing an
MPEG, an AIFF file, or similar simply wouldn't be possible - but it
appears to be buried so deep that nothing I've looked at touches on it.
Yes, I realize I'm looking for something that's almost certainly a
"right down on the bare metal" type of thing, but that's just fine with
me.
Anybody got any ideas for me, as far as where to look for information,
or even code that will do what I'm looking for?

Signature
Don Bruder - dakidd@sonic.net - If your "From:" address isn't on my whitelist,
or the subject of the message doesn't contain the exact text "PopperAndShadow"
somewhere, any message sent to this address will go in the garbage without my
ever knowing it arrived. Sorry... <http://www.sonic.net/~dakidd> for more info
Andrew Plotkin - 25 Oct 2007 04:44 GMT
> I'm looking for a way to play random sounds - in the form of
> programmatically-generated on-the-fly tones of arbitrary duration and
> frequency, similar to the old cartoon stereotype of "this is what a
> computer hard at work sounds like".
This is one source file from a project of mine, which does that sort
of thing with CoreAudio:
https://boodler.svn.sourceforge.net/svnroot/boodler/core/branch/rel_1_6_1/src/cb
oodle/audev-macosx.c
It locates a sound device, sets it up, and starts it.
If you look in the audev_loop function, it calls mixfunc() repeatedly
-- you could supply a function of that form, which fills in a buffer
with sound data (32-bit, 2-channel). It then stuffs the buffer into
the sound device.
Alternatively, you could just download the entire project (Boodler, at
<http://eblong.com/zarf/boodler/>.) It's a framework for playing
random sounds. Once you have it set up, doing what you want is
possible in about five lines of Python.
--Z

Signature
"And Aholibamah bare Jeush, and Jaalam, and Korah: these were the borogoves..."
*
If the Bush administration hasn't shipped you to Syria for interrogation, it's
for one reason: they don't feel like it. Not because you're innocent.
Don Bruder - 25 Oct 2007 05:57 GMT
> > I'm looking for a way to play random sounds - in the form of
> > programmatically-generated on-the-fly tones of arbitrary duration and
> > frequency, similar to the old cartoon stereotype of "this is what a
> > computer hard at work sounds like".
<snip for space>
> Alternatively, you could just download the entire project (Boodler, at
> <http://eblong.com/zarf/boodler/>.) It's a framework for playing
> random sounds. Once you have it set up, doing what you want is
> possible in about five lines of Python.
I've got it downloading now. Come morning, I'll put an eyeball on it and
start trying to see if maybe it'll get me somewhere resembling the place
I'm trying to go. Thanks!

Signature
Don Bruder - dakidd@sonic.net - If your "From:" address isn't on my whitelist,
or the subject of the message doesn't contain the exact text "PopperAndShadow"
somewhere, any message sent to this address will go in the garbage without my
ever knowing it arrived. Sorry... <http://www.sonic.net/~dakidd> for more info