1 /* 2000-08-10T18:03:54Z
3 * open X11 display and sound
35 char play[SAMPLE_MAX];
37 #if defined(AUDIO_UNIX_NATIVE)
38 static int sound_pid = -1;
39 int sound_pipe[2] = { -1, -1 }; /* for communication */
40 short *sound_data[SAMPLE_MAX]; /* pointer to sound data */
41 long sound_length[SAMPLE_MAX]; /* length of sound data */
43 static const char *sound_names[SAMPLE_MAX] =
45 "00.blank.au","01.roll.au","02.stone.au","03.nut.au","04.crack.au",
46 "05.bug.au","06.tank.au","07.android.au","08.spring.au","09.slurp.au",
47 "10.eater.au","11.alien.au","12.collect.au","13.diamond.au","14.squash.au",
48 "15.drip.au","16.push.au","17.dirt.au","18.acid.au","19.ball.au",
49 "20.grow.au","21.wonder.au","22.door.au","23.exit.au","24.dynamite.au",
50 "25.tick.au","26.press.au","27.wheel.au","28.boom.au","29.time.au",
53 static const int sound_volume[SAMPLE_MAX] =
55 20,100,100,100,100,20,20,100,100,100,
56 50,100,100,100,100,100,100,100,100,100,
57 100,20,100,100,100,100,100,20,100,100,
65 extern void tab_generate();
66 extern void ulaw_generate();
70 Bitmap *emc_bitmaps[2];
76 SetBitmaps_EM(emc_bitmaps);
78 objBitmap = emc_bitmaps[0];
79 sprBitmap = emc_bitmaps[1];
82 objPixmap = emc_bitmaps[0]->drawable;
83 sprPixmap = emc_bitmaps[1]->drawable;
85 objmaskBitmap = emc_bitmaps[0]->clip_mask;
86 sprmaskBitmap = emc_bitmaps[1]->clip_mask;
89 screenBitmap = CreateBitmap(MAX_BUF_XSIZE * TILEX, MAX_BUF_YSIZE * TILEY,
94 spriteBitmap = XCreatePixmap(display, window->drawable, TILEX, TILEY, 1);
95 if (spriteBitmap == 0)
96 Error(ERR_EXIT, "failed to create sprite pixmap for EM engine");
99 objmaskBitmap ? GXcopyInverted : sprmaskBitmap ? GXcopy : GXset;
100 gcValues.graphics_exposures = False;
101 spriteGC = XCreateGC(display, spriteBitmap, GCFunction | GCGraphicsExposures,
104 Error(ERR_EXIT, "failed to create sprite GC for EM engine");
107 /* ----------------------------------------------------------------- */
109 #if defined(AUDIO_UNIX_NATIVE)
111 #if defined(PLATFORM_LINUX) || defined(PLATFORM_BSD)
115 char name[MAXNAME+2];
118 for (i = 0; i < SAMPLE_MAX; i++)
124 snprintf(name, MAXNAME+2, "%s/%s/%s", arg_basedir, EM_SND_DIR,
129 snprintf(name, MAXNAME+2, "%s/%s", EM_SND_DIR, sound_names[i]);
133 Error(ERR_EXIT, "buffer overflow when reading sounds directory");
135 if (read_sample(name, &sound_data[i], &sound_length[i]))
140 int mult = sound_volume[i] * 65536 / (100 * MIXER_MAX);
141 stop = sound_data[i] + sound_length[i];
142 for (ptr = sound_data[i]; ptr < stop; ptr++)
143 *ptr = (*ptr * mult) / 65536;
147 if (pipe(sound_pipe) == -1)
149 Error(ERR_WARN, "unable to create sound pipe for EM engine -- no sound");
157 Error(ERR_WARN, "unable to fork sound thread for EM engine -- no sound");
162 close(sound_pipe[sound_pid == 0]); sound_pipe[sound_pid == 0] = -1;
164 _exit(sound_thread());
166 signal(SIGPIPE, SIG_IGN); /* dont crash if sound process dies */
169 #endif /* defined(PLATFORM_LINUX) || defined(PLATFORM_BSD) */
171 #endif /* AUDIO_UNIX_NATIVE */
178 /* pre-calculate some data */
182 progname = "emerald mine";
185 Error(ERR_EXIT, "em_open_all(): open_all() failed");
190 void em_close_all(void)
192 #if defined(AUDIO_UNIX_NATIVE)
197 kill(sound_pid, SIGTERM);
198 waitpid(sound_pid, 0, 0);
201 if (sound_pipe[0] != -1)
202 close(sound_pipe[0]);
203 if (sound_pipe[1] != -1)
204 close(sound_pipe[1]);
206 for (i = 0; i < SAMPLE_MAX; i++)
213 XFreeGC(display, spriteGC);
216 XFreePixmap(display, spriteBitmap);
220 /* ---------------------------------------------------------------------- */
222 void sound_play(void)
224 #if defined(AUDIO_UNIX_NATIVE)
225 if (sound_pipe[1] != -1)
227 if (write(sound_pipe[1], &play, sizeof(play)) == -1)
229 Error(ERR_WARN, "cannot write into pipe to child process -- no sounds");
231 if (sound_pipe[0] != -1)
233 close(sound_pipe[0]);
237 if (sound_pipe[1] != -1)
239 close(sound_pipe[1]);
245 memset(play, 0, sizeof(play));