Mercurial > emacs
comparison src/sound.c @ 34354:db2901e01b72
(vox_configure): Change order of ioctls. Don't
set SNDCTL_DSP_SPEED from bps, don't set SNDCTL_DSP_SAMPLESIZE.
Ignore errors when changing volume.
(vox_close): Don't reset the device.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Thu, 07 Dec 2000 22:08:26 +0000 |
parents | cb2b0d1799db |
children | b9fdde642b13 |
comparison
equal
deleted
inserted
replaced
34353:e477bbc45459 | 34354:db2901e01b72 |
---|---|
758 | 758 |
759 static void | 759 static void |
760 vox_configure (sd) | 760 vox_configure (sd) |
761 struct sound_device *sd; | 761 struct sound_device *sd; |
762 { | 762 { |
763 int requested; | 763 int val; |
764 | 764 |
765 xassert (sd->fd >= 0); | 765 xassert (sd->fd >= 0); |
766 | 766 |
767 /* Device parameters apparently depend on each other in undocumented | 767 val = sd->format; |
768 ways (not to imply that there is any real documentation). Be | 768 if (ioctl (sd->fd, SNDCTL_DSP_SETFMT, &sd->format) < 0 |
769 careful when reordering the calls below. */ | 769 || val != sd->format) |
770 if (sd->sample_size > 0 | 770 sound_perror ("Set sound format"); |
771 && ioctl (sd->fd, SNDCTL_DSP_SAMPLESIZE, &sd->sample_size) < 0) | 771 |
772 sound_perror ("Setting sample size"); | 772 val = sd->channels != 1; |
773 | 773 if (ioctl (sd->fd, SNDCTL_DSP_STEREO, &val) < 0 |
774 if (sd->bps > 0 | 774 || val != (sd->channels != 1)) |
775 && ioctl (sd->fd, SNDCTL_DSP_SPEED, &sd->bps) < 0) | 775 sound_perror ("Set stereo/mono"); |
776 sound_perror ("Setting speed"); | 776 |
777 | 777 /* I think bps and sampling_rate are the same, but who knows. |
778 if (sd->sample_rate > 0 | 778 Check this. and use SND_DSP_SPEED for both. */ |
779 && ioctl (sd->fd, SOUND_PCM_WRITE_RATE, &sd->sample_rate) < 0) | 779 if (sd->sample_rate > 0) |
780 sound_perror ("Setting sample rate"); | 780 { |
781 | 781 val = sd->sample_rate; |
782 requested = sd->format; | 782 if (ioctl (sd->fd, SNDCTL_DSP_SPEED, &sd->sample_rate) < 0 |
783 if (ioctl (sd->fd, SNDCTL_DSP_SETFMT, &sd->format) < 0) | 783 || val != sd->sample_rate) |
784 sound_perror ("Setting format"); | 784 sound_perror ("Set sound speed"); |
785 else if (requested != sd->format) | 785 } |
786 error ("Setting format"); | |
787 | |
788 if (sd->channels > 1 | |
789 && ioctl (sd->fd, SNDCTL_DSP_STEREO, &sd->channels) < 0) | |
790 sound_perror ("Setting channels"); | |
791 | 786 |
792 if (sd->volume > 0) | 787 if (sd->volume > 0) |
793 { | 788 { |
794 int volume = sd->volume & 0xff; | 789 int volume = sd->volume & 0xff; |
795 volume |= volume << 8; | 790 volume |= volume << 8; |
796 if (ioctl (sd->fd, SOUND_MIXER_WRITE_PCM, &volume) < 0) | 791 /* This may fail if there is no mixer. Ignore the failure. */ |
797 sound_perror ("Setting volume"); | 792 ioctl (sd->fd, SOUND_MIXER_WRITE_PCM, &volume); |
798 } | 793 } |
799 } | 794 } |
800 | 795 |
801 | 796 |
802 /* Close device SD if it is open. */ | 797 /* Close device SD if it is open. */ |
807 { | 802 { |
808 if (sd->fd >= 0) | 803 if (sd->fd >= 0) |
809 { | 804 { |
810 /* Flush sound data, and reset the device. */ | 805 /* Flush sound data, and reset the device. */ |
811 ioctl (sd->fd, SNDCTL_DSP_SYNC, NULL); | 806 ioctl (sd->fd, SNDCTL_DSP_SYNC, NULL); |
812 ioctl (sd->fd, SNDCTL_DSP_RESET, NULL); | |
813 | 807 |
814 /* Close the device. */ | 808 /* Close the device. */ |
815 emacs_close (sd->fd); | 809 emacs_close (sd->fd); |
816 sd->fd = -1; | 810 sd->fd = -1; |
817 } | 811 } |