- /* Device parameters apparently depend on each other in undocumented
- ways (not to imply that there is any real documentation). Be
- careful when reordering the calls below. */
- if (sd->sample_size > 0
- && ioctl (sd->fd, SNDCTL_DSP_SAMPLESIZE, &sd->sample_size) < 0)
- sound_perror ("Setting sample size");
-
- if (sd->bps > 0
- && ioctl (sd->fd, SNDCTL_DSP_SPEED, &sd->bps) < 0)
- sound_perror ("Setting speed");
-
- if (sd->sample_rate > 0
- && ioctl (sd->fd, SOUND_PCM_WRITE_RATE, &sd->sample_rate) < 0)
- sound_perror ("Setting sample rate");
-
- requested = sd->format;
- if (ioctl (sd->fd, SNDCTL_DSP_SETFMT, &sd->format) < 0)
- sound_perror ("Setting format");
- else if (requested != sd->format)
- error ("Setting format");
-
- if (sd->channels > 1
- && ioctl (sd->fd, SNDCTL_DSP_STEREO, &sd->channels) < 0)
- sound_perror ("Setting channels");
-
- if (sd->volume > 0
- && ioctl (sd->fd, SOUND_MIXER_WRITE_PCM, &sd->volume) < 0)
- sound_perror ("Setting volume");
+ /* On GNU/Linux, it seems that the device driver doesn't like to be
+ interrupted by a signal. Block the ones we know to cause
+ troubles. */
+ turn_on_atimers (0);
+#ifdef SIGIO
+ sigblock (sigmask (SIGIO));
+#endif
+
+ val = sd->format;
+ if (ioctl (sd->fd, SNDCTL_DSP_SETFMT, &sd->format) < 0
+ || val != sd->format)
+ sound_perror ("Could not set sound format");
+
+ val = sd->channels != 1;
+ if (ioctl (sd->fd, SNDCTL_DSP_STEREO, &val) < 0
+ || val != (sd->channels != 1))
+ sound_perror ("Could not set stereo/mono");
+
+ /* I think bps and sampling_rate are the same, but who knows.
+ Check this. and use SND_DSP_SPEED for both. */
+ if (sd->sample_rate > 0)
+ {
+ val = sd->sample_rate;
+ if (ioctl (sd->fd, SNDCTL_DSP_SPEED, &sd->sample_rate) < 0)
+ sound_perror ("Could not set sound speed");
+ else if (val != sd->sample_rate)
+ sound_warning ("Could not set sample rate");
+ }
+
+ if (sd->volume > 0)
+ {
+ int volume = sd->volume & 0xff;
+ volume |= volume << 8;
+ /* This may fail if there is no mixer. Ignore the failure. */
+ ioctl (sd->fd, SOUND_MIXER_WRITE_PCM, &volume);
+ }
+
+ turn_on_atimers (1);
+#ifdef SIGIO
+ sigunblock (sigmask (SIGIO));
+#endif