--- he.c.orig 2003-09-09 21:27:20.000000000 +0900 +++ he.c 2003-09-12 16:00:27.000000000 +0900 @@ -10,12 +10,14 @@ * ESC キー:リセット */ +#define MULTIPLY_MAX 20 typedef struct { SDL_AudioSpec spec; Uint8 *buffer; - Uint32 length; + Uint32 length[MULTIPLY_MAX]; Uint32 length_backup; - Uint8 *position; + Uint8 *position[MULTIPLY_MAX]; + int playing[MULTIPLY_MAX]; } audio_t; SDL_Surface *he_push= NULL, *he_normal= NULL, *he_num= NULL; @@ -33,17 +35,21 @@ /* サウンドデータの読み込み */ audio_t LoadAudio(const char *filename) { audio_t a; - + int i; if(SDL_LoadWAV("he.wav", - &a.spec, &a.buffer, &a.length)== NULL) { + &a.spec, &a.buffer, &a.length[0])== NULL) { fprintf(stderr, "Could not open test.wav: %s\n", SDL_GetError()); exit(-1); } - a.position= a.buffer; - a.length_backup= a.length; + a.length_backup= a.length[0]; + for(i = 0; i < MULTIPLY_MAX; i++){ + a.position[i]= a.buffer; + a.playing[i] = 0; + if(i > 0) a.length[i] = a.length[0]; + } return a; } @@ -54,27 +60,53 @@ void audio_callback(void *userdata, Uint8 *stream, int len) { + int i; audio_t *audio; audio= (audio_t*)userdata; - if(len== 0) return; - if(audio->length< len) - len= audio->length; + for(i = 0; i < MULTIPLY_MAX; i++){ + if(audio->playing[i] == 0) continue; + if(audio->length[i]< len) + len= audio->length[i]; - SDL_MixAudio(stream, audio->position, len, SDL_MIX_MAXVOLUME); + SDL_MixAudio(stream, audio->position[i], len, 80/*SDL_MIX_MAXVOLUME*/); - audio->position+= len; - audio->length-= len; + audio->position[i]+= len; + audio->length[i]-= len; + if(audio->length[i] <= 0) audio->playing[i] = 0; + } +} +int num_playing(audio_t *a) +{ + int result = 0; int i; + for(i = 0; i < MULTIPLY_MAX; i++){ + if(a->playing[i] == 1){ + result++; + } + } + return result; } void audioPlay(audio_t *a) { - SDL_PauseAudio(1); - SDL_LockAudio(); - a->position= a->buffer; - a->length= a->length_backup; - SDL_UnlockAudio(); - SDL_PauseAudio(0); + int i; + if(num_playing(a) > 0){ + SDL_PauseAudio(1); + SDL_LockAudio(); + } + + for(i = 0; i < MULTIPLY_MAX; i++){ + if(a->playing[i] == 0){ + a->position[i]= a->buffer; + a->length[i]= a->length_backup; + a->playing[i] = 1; + break; + } + } + if(num_playing(a) > 0){ + SDL_UnlockAudio(); + SDL_PauseAudio(0); + } } void SetupAudioDevice(audio_t *audio) {