X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame_em%2Fsound.c;h=9ed5ac3dd740fec974363087b5310ee970e1bde8;hb=c3218c06da4da799c906a5adaacd625583f65616;hp=afaabcd4e933dae77ab49fde25b36f58d83299c2;hpb=c5321d9d36d0a74062651d0352fbbaccbe125eca;p=rocksndiamonds.git diff --git a/src/game_em/sound.c b/src/game_em/sound.c index afaabcd4..9ed5ac3d 100644 --- a/src/game_em/sound.c +++ b/src/game_em/sound.c @@ -3,7 +3,7 @@ * handle sounds in emerald mine */ -#include "game_em.h" +#include "main_em.h" #if defined(AUDIO_UNIX_NATIVE) @@ -20,19 +20,44 @@ #include #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 }; @@ -46,7 +71,7 @@ int sound_thread(void) 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; @@ -61,7 +86,7 @@ int sound_thread(void) 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 (;;) { @@ -69,7 +94,9 @@ int sound_thread(void) { /* 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; @@ -267,14 +294,14 @@ int sound_thread(void) 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) @@ -339,6 +366,7 @@ int sound_thread(void) free(audio_buffer); if (mix_buffer) free(mix_buffer); + goto loop; /* back to top */ fail: @@ -352,16 +380,16 @@ int sound_thread(void) 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) @@ -426,7 +454,7 @@ int read_sample(char *name, short **data, long *length) 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; @@ -436,7 +464,7 @@ int read_sample(char *name, short **data, long *length) 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; @@ -446,7 +474,7 @@ int read_sample(char *name, short **data, long *length) 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;