static void reset_device (int wait_p) { if (wait_p) audio_drain (audio_fd, 1); else audio_flush_play (audio_fd); if (reset_device_p) audio_set_play_config (audio_fd, &dev_hdr); if (reset_volume_p) audio_set_play_gain (audio_fd, &old_volume); }
static void sigint(int sig) { /* flush output queues before exiting */ if (Audio_fd >= 0) { (void) audio_flush_play(Audio_fd); /* restore saved parameters */ if (Volume != INT_MAX) (void) audio_set_play_gain(Audio_fd, &Savevol); if ((Audio_ctlfd >= 0) && (audio_cmp_hdr(&Save_hdr, &Dev_hdr) != 0)) { (void) audio_set_play_config(Audio_fd, &Save_hdr); } } exit(1); }
static int init_device (int volume, unsigned char *data, int fd, unsigned int *header_length) { #ifdef SUNOS4_0_3 if (header_length) *header_length = 0; return 0; #else Audio_hdr file_hdr; reset_volume_p = 0; reset_device_p = 0; if (data && fd) ABORT (); /* one or the other */ if (AUDIO_SUCCESS != audio_get_play_config (audio_fd, &dev_hdr)) { perror ("Not a valid audio device"); return 1; } if (AUDIO_SUCCESS != (data ? audio_decode_filehdr (data, &file_hdr, header_length) : audio_read_filehdr (fd, &file_hdr, 0, 0))) { if (data) perror ("invalid audio data"); else perror ("invalid audio file"); return 1; } audio_flush_play (audio_fd); if (!initialized_device_p || (0 != audio_cmp_hdr (&dev_hdr, &file_hdr))) { Audio_hdr new_hdr; new_hdr = file_hdr; reset_device_p = 1; initialized_device_p = 1; if (AUDIO_SUCCESS != audio_set_play_config (audio_fd, &new_hdr)) { char buf1 [100], buf2 [100], buf3 [250]; audio_enc_to_str (&file_hdr, buf1); audio_enc_to_str (&new_hdr, buf2); sprintf (buf3, "wanted %s, got %s", buf1, buf2); warn (buf3); return 1; } } if (volume < 0 || volume > 100) { char buf [255]; sprintf (buf, "volume must be between 0 and 100 (not %d)", volume); warn (buf); return 1; } { /* set the volume; scale it to 0.0 - 1.0 */ double V = (volume / 100.0); audio_get_play_gain (audio_fd, &old_volume); reset_volume_p = 1; audio_set_play_gain (audio_fd, &V); } return 0; #endif }