* handle sounds in emerald mine
*/
-#include "game_em.h"
+#include "main_em.h"
#if defined(AUDIO_UNIX_NATIVE)
#include <soundcard.h>
#endif
-#include "global.h"
-#include "sample.h"
-
static char audioname[] = "/dev/audio";
static const int sound_priority[SAMPLE_MAX] =
{
- SAMPLE_exit, SAMPLE_die, SAMPLE_time, SAMPLE_boom, SAMPLE_tick,
- SAMPLE_collect, SAMPLE_roll, SAMPLE_push, SAMPLE_dynamite, SAMPLE_press,
- SAMPLE_door, SAMPLE_dirt, SAMPLE_blank, SAMPLE_android, SAMPLE_ball,
- SAMPLE_grow, SAMPLE_squash, SAMPLE_crack, SAMPLE_slurp, SAMPLE_drip,
- SAMPLE_wonder, SAMPLE_wheel, SAMPLE_stone, SAMPLE_spring, SAMPLE_diamond,
- SAMPLE_nut, SAMPLE_bug, SAMPLE_tank, SAMPLE_eater, SAMPLE_alien,
+ SAMPLE_exit_open,
+ SAMPLE_exit_leave,
+ SAMPLE_die,
+ SAMPLE_time,
+ SAMPLE_boom,
+ SAMPLE_tick,
+ SAMPLE_collect,
+ SAMPLE_roll,
+ SAMPLE_push,
+ SAMPLE_dynamite,
+ SAMPLE_press,
+ SAMPLE_door,
+ SAMPLE_dirt,
+ SAMPLE_blank,
+ SAMPLE_android_clone,
+ SAMPLE_android_move,
+ SAMPLE_ball,
+ SAMPLE_grow,
+ SAMPLE_squash,
+ SAMPLE_wonderfall,
+ SAMPLE_crack,
+ SAMPLE_slurp,
+ SAMPLE_drip,
+ SAMPLE_wonder,
+ SAMPLE_wheel,
+ SAMPLE_stone,
+ SAMPLE_spring,
+ SAMPLE_diamond,
+ SAMPLE_nut,
+ SAMPLE_bug,
+ SAMPLE_tank,
+ SAMPLE_eater,
+ SAMPLE_eater_eat,
+ SAMPLE_alien,
SAMPLE_acid
};
{
int audio_fd; /* file descriptor of /dev/audio or -1 if not open */
int audio_format;
- int sample_rate;
+ // int sample_rate;
int fragment_size;
unsigned char *audio_buffer; /* actual buffer pumped to /dev/audio */
short *mix_buffer;
char sound_play[SAMPLE_MAX]; /* if set, we should be playing these sounds */
- long sound_pos[SAMPLE_MAX]; /* position in the sound */
+ int sound_pos[SAMPLE_MAX]; /* position in the sound */
int mix_play[MIXER_MAX]; /* which sounds we have chosen to mix (calculated each time) */
int mix_count;
int i;
audio_fd = -1;
audio_format = AUDIO_ULAW; /* defaults for non-OSS /dev/audio */
- sample_rate = 8000;
+ // sample_rate = 8000;
fragment_size = 256;
audio_buffer = 0;
mix_buffer = 0;
mix_count = 0;
- memset(sound_play, 0, sizeof(sound_play)); /* not playing any sounds */
+ clear_mem(sound_play, sizeof(sound_play)); /* not playing any sounds */
for (;;)
{
{
/* pick sounds to play, if any */
- if (sound_play[SAMPLE_exit] || sound_play[SAMPLE_die])
+ if (sound_play[SAMPLE_exit_open] ||
+ sound_play[SAMPLE_exit_leave] ||
+ sound_play[SAMPLE_die])
sound_play[SAMPLE_boom] = 0; /* no explosions if player goes home */
mix_count = 0;
goto reset;
}
- sample_rate = i;
+ // sample_rate = i;
if (ioctl(audio_fd, SNDCTL_DSP_GETBLKSIZE, &i) == -1)
{
Error(ERR_WARN, "unable to get block size in sound thread");
if (mix_count && audio_fd != -1)
{
/* prepare mix buffer */
- memset(mix_buffer, 0, fragment_size * sizeof(*mix_buffer));
+ clear_mem(mix_buffer, fragment_size * sizeof(*mix_buffer));
for (i = 0; i < mix_count; i++)
{
register short *mix_ptr = mix_buffer;
register short *sound_ptr =
sound_data[mix_play[i]] + sound_pos[mix_play[i]];
- register long count =
+ register int count =
sound_length[mix_play[i]] - sound_pos[mix_play[i]];
if (count > fragment_size)
free(audio_buffer);
if (mix_buffer)
free(mix_buffer);
+
goto loop; /* back to top */
fail:
return(0);
}
-int read_sample(char *name, short **data, long *length)
+int read_sample(char *name, short **data, int *length)
{
int result;
FILE *file = 0;
short *dataptr = 0;
- long datalength;
+ int datalength;
int i, actual, ch;
unsigned char buffer[24];
- unsigned long temp;
+ unsigned int temp;
file = fopen(name, "rb");
if (file == 0)
temp = buffer[12] << 24 | buffer[13] << 16 | buffer[14] << 8 | buffer[15];
if (temp != 1)
{
- fprintf(stderr, "%s: \"%s\": %s (%ld != 1)\n", progname, name,
+ fprintf(stderr, "%s: \"%s\": %s (%d != 1)\n", progname, name,
"bad encoding type", temp);
result = 1;
goto fail;
temp = buffer[16] << 24 | buffer[17] << 16 | buffer[18] << 8 | buffer[19];
if (temp != 8000)
{
- fprintf(stderr, "%s: \"%s\": %s (%ld != 8000)\n", progname, name,
+ fprintf(stderr, "%s: \"%s\": %s (%d != 8000)\n", progname, name,
"bad sample rate", temp);
result = 1;
goto fail;
temp = buffer[20] << 24 | buffer[21] << 16 | buffer[22] << 8 | buffer[23];
if (temp != 1)
{
- fprintf(stderr, "%s: \"%s\": %s (%ld != 1)\n", progname, name,
+ fprintf(stderr, "%s: \"%s\": %s (%d != 1)\n", progname, name,
"unsupported channels", temp);
result = 1;
goto fail;