1 /* aNetHack 0.0.1 macsnd.c $ANH-Date: 1432512798 2015/05/25 00:13:18 $ $ANH-Branch: master $:$ANH-Revision: 1.10 $ */
2 /* Copyright (c) 1992 by Jon Watte */
3 /* aNetHack may be freely redistributed. See license for details. */
6 * This file contains music playing code.
8 * If we were REALLY determinated, we would make the sound play
9 * asynchronously, but I'll save that one for a rainy day...
11 * This may break A/UX, since it defines MAC but we need to
12 * check that the toolbox is booted. I'll defer that one too.
20 #if 1 /*!TARGET_API_MAC_CARBON*/
22 #include <Resources.h>
25 #ifndef freqDurationCmd
26 #define freqDurationCmd 40
29 #define SND_BUFFER(s) (&(*s)[20])
30 #define SND_LEN(s) (GetHandleSize(s) - 42)
33 mac_speaker(struct obj
*instr
, char *melody
)
35 SndChannelPtr theChannel
= (SndChannelPtr
) 0;
38 unsigned char theName
[32];
39 char *n
= (char *) &theName
[1];
40 int typ
= instr
->otyp
;
41 const char *actualn
= OBJ_NAME(objects
[typ
]);
44 * First: are we in the library ?
51 * Is this a known instrument ?
54 theName
[0] = strlen(n
);
55 theSound
= GetNamedResource('snd ', theName
);
64 if (SndNewChannel(&theChannel
, sampledSynth
, initMono
+ initNoInterp
,
65 (void *) 0) == noErr
) {
66 char midi_note
[] = { 57, 59, 60, 62, 64, 65, 67 };
69 short snd_len
= SND_LEN(theSound
) / 18;
71 theCmd
.cmd
= soundCmd
;
73 theCmd
.param2
= (long) SND_BUFFER(theSound
);
74 err
= SndDoCommand(theChannel
, &theCmd
, false);
77 * We rack 'em up all in a row
78 * The mac will play them correctly and then end, since
79 * we do a sync close below.
82 while (*melody
&& !err
) {
83 while (*melody
> 'G') {
86 while (*melody
< 'A') {
89 theCmd
.cmd
= freqDurationCmd
;
90 theCmd
.param1
= snd_len
;
91 theCmd
.param2
= midi_note
[*melody
- 'A'];
92 err
= SndDoCommand(theChannel
, &theCmd
, false);
95 SndDisposeChannel(theChannel
, false); /* Sync wait for completion */
96 ReleaseResource(theSound
);
103 Handle h
= GetNamedResource('snd ', "\paNetHack Bell");
107 SndPlay((SndChannelPtr
) 0, (SndListHandle
) h
, 0);