1 /* SCCS Id: @(#)macsnd.c 3.1 92/11/28 */
2 /* Copyright (c) 1992 by Jon Watte */
3 /* NetHack 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 !TARGET_API_MAC_CARBON
22 # include <Resources.h>
24 # define freqDurationCmd 40
27 #define SND_BUFFER(s) (&(*s)[20])
28 #define SND_LEN(s) (GetHandleSize(s)-42)
32 mac_speaker (struct obj *instr, char *melody) {
33 SndChannelPtr theChannel = (SndChannelPtr) 0;
36 unsigned char theName [32];
37 char *n = (char *) &theName [1];
38 int typ = instr->otyp;
39 const char *actualn = OBJ_NAME (objects [typ]);
42 * First: are we in the library ?
49 * Is this a known instrument ?
52 theName [0] = strlen (n);
53 theSound = GetNamedResource ('snd ', theName);
62 if (SndNewChannel(&theChannel, sampledSynth, initMono +
63 initNoInterp, (void *) 0) == noErr) {
64 char midi_note [] = {57, 59, 60, 62, 64, 65, 67};
67 short snd_len = SND_LEN (theSound) / 18;
69 theCmd.cmd = soundCmd;
71 theCmd.param2 = (long) SND_BUFFER (theSound);
72 err = SndDoCommand (theChannel, &theCmd, false);
75 * We rack 'em up all in a row
76 * The mac will play them correctly and then end, since
77 * we do a sync close below.
80 while (*melody && ! err) {
81 while (*melody > 'G') {
84 while (*melody < 'A') {
87 theCmd.cmd = freqDurationCmd;
88 theCmd.param1 = snd_len;
89 theCmd.param2 = midi_note [*melody - 'A'];
90 err = SndDoCommand (theChannel, &theCmd, false);
93 SndDisposeChannel (theChannel, false); /* Sync wait for completion */
94 ReleaseResource (theSound);
98 void tty_nhbell (void) {
99 Handle h = GetNamedResource ('snd ', "\pNetHack Bell");
103 SndPlay ((SndChannelPtr) 0, (SndListHandle) h, 0);