void snis_slider_poke_input(struct slider *s, double input, int with_sound) { s->input = input; if (s->clicked) { s->clicked(s); if (slider_sound != -1 && with_sound) wwviaudio_add_sound(slider_sound); } }
void play_thruster_sound(void) { static struct timeval t = {0}; struct timeval now; gettimeofday(&now, NULL); if (now.tv_sec != t.tv_sec || (now.tv_usec - t.tv_usec > 300000)) { t = now; wwviaudio_add_sound(THRUSTER); } }
void add_sound(int sound) { struct timeval t; gettimeofday(&t, NULL); #define SOUND_TIME_LIMIT 5 /* seconds */ if ((t.tv_sec - last_sound_time.tv_sec) < SOUND_TIME_LIMIT) return; last_sound_time = t; wwviaudio_add_sound(sound); }
int main(int argc, char *argv[]) { int rc; char *sound_device_str; int sound_device = -1; char *sound_file = "share/snis/sounds/red-alert.ogg"; printf("Space Nerds In Space audio test program.\n"); printf("How to use this program:\n"); printf("Type the following:\n"); printf(" make snis_test_audio\n"); printf(" ./snis_test_audio\n\n"); printf("Or, if you want to try a sound device other than the default, such as device 6:\n\n"); printf(" ./snis_test_audio 6\n\n"); printf("The device numbers should be listed below.\n\n\n"); if (argc > 1) { sound_device_str = argv[1]; rc = sscanf(sound_device_str, "%d", &sound_device); if (rc != 1) { sound_device = -1; } } if (sound_device >= 0) { printf("Manually setting sound device to %d\n", sound_device); wwviaudio_set_sound_device(sound_device); } rc = wwviaudio_initialize_portaudio(10, 10); printf("wwviaudio_initialize_portaudio returned %d\n", rc); if (rc != 0) { return rc; } sound_device = wwviaudio_get_sound_device(); rc = wwviaudio_read_ogg_clip(0, sound_file); if (rc != 0) { printf("Failed to read %s\n", sound_file); exit(1); } wwviaudio_list_devices(); printf("Attempting to play sound '%s' to device %d... ", sound_file, sound_device); fflush(stdout); wwviaudio_add_sound(0); sleep(1); printf("...finished attempting to play sound\n"); return 0; }
static int snis_slider_button_press_vertical(struct slider *s, int x, int y) { if (x < s->x || x > s->x + s->height || y < s->y - 5 || y > s->y + s->length + 5) return 0; if (y >= s->y + s->length) s->input = 0.0; else if (y <= s->y) s->input = 1.0; else s->input = ((double) (s->y + s->length) - (double) y) / (double) s->length; if (s->clicked) { s->clicked(s); if (slider_sound != -1) wwviaudio_add_sound(slider_sound); } return 1; }
int snis_slider_button_press(struct slider *s, int x, int y) { if (s->vertical) return snis_slider_button_press_vertical(s, x, y); if (x < s->x - 5 || x > s->x + s->length + 5 || y < s->y || y > s->y + s->height) return 0; if (x >= s->x + s->length) s->input = 1.0; else if (x <= s->x) s->input = 0.0; else s->input = ((double) x - (double) s->x) / (double) s->length; if (s->clicked) { s->clicked(s); if (slider_sound != -1) wwviaudio_add_sound(slider_sound); } return 1; }