NHDT->ANH, nethack->anethack, nhdat->anhdat
[aNetHack.git] / sys / mac / macsnd.c
blob68e29486d97414e7856cfc5164d26d65b16b0e96
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. */
5 /*
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.
14 * - h+ 921128
17 #include "hack.h"
18 #include "mactty.h"
19 #include "macwin.h"
20 #if 1 /*!TARGET_API_MAC_CARBON*/
21 #include <Sound.h>
22 #include <Resources.h>
23 #endif
25 #ifndef freqDurationCmd
26 #define freqDurationCmd 40
27 #endif
29 #define SND_BUFFER(s) (&(*s)[20])
30 #define SND_LEN(s) (GetHandleSize(s) - 42)
32 void
33 mac_speaker(struct obj *instr, char *melody)
35 SndChannelPtr theChannel = (SndChannelPtr) 0;
36 SndCommand theCmd;
37 Handle theSound;
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 ?
46 if (flags.silent) {
47 return;
51 * Is this a known instrument ?
53 strcpy(n, actualn);
54 theName[0] = strlen(n);
55 theSound = GetNamedResource('snd ', theName);
56 if (!theSound) {
57 return;
59 HLock(theSound);
62 * Set up the synth
64 if (SndNewChannel(&theChannel, sampledSynth, initMono + initNoInterp,
65 (void *) 0) == noErr) {
66 char midi_note[] = { 57, 59, 60, 62, 64, 65, 67 };
68 short err;
69 short snd_len = SND_LEN(theSound) / 18;
71 theCmd.cmd = soundCmd;
72 theCmd.param1 = 0;
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') {
84 *melody -= 8;
86 while (*melody < 'A') {
87 *melody += 8;
89 theCmd.cmd = freqDurationCmd;
90 theCmd.param1 = snd_len;
91 theCmd.param2 = midi_note[*melody - 'A'];
92 err = SndDoCommand(theChannel, &theCmd, false);
93 melody++;
95 SndDisposeChannel(theChannel, false); /* Sync wait for completion */
96 ReleaseResource(theSound);
100 void
101 tty_nhbell(void)
103 Handle h = GetNamedResource('snd ', "\paNetHack Bell");
105 if (h) {
106 HLock(h);
107 SndPlay((SndChannelPtr) 0, (SndListHandle) h, 0);
108 ReleaseResource(h);
109 } else
110 SysBeep(30);