comparison src/sound.c @ 71892:248ccc534803

* sound.c (alsa_init): Call snd_pcm_close after successful snd_pcm_open.
author Jan Djärv <jan.h.d@swipnet.se>
date Fri, 14 Jul 2006 09:47:45 +0000
parents 7510757f449b
children a7c077b29617 8a8e69664178
comparison
equal deleted inserted replaced
71891:54ec937ab5e4 71892:248ccc534803
988 static void 988 static void
989 alsa_configure (sd) 989 alsa_configure (sd)
990 struct sound_device *sd; 990 struct sound_device *sd;
991 { 991 {
992 int val, err, dir; 992 int val, err, dir;
993 unsigned uval;
993 struct alsa_params *p = (struct alsa_params *) sd->data; 994 struct alsa_params *p = (struct alsa_params *) sd->data;
994 snd_pcm_uframes_t buffer_size; 995 snd_pcm_uframes_t buffer_size;
995 996
996 xassert (p->handle != 0); 997 xassert (p->handle != 0);
997 998
1015 val = sd->format; 1016 val = sd->format;
1016 err = snd_pcm_hw_params_set_format (p->handle, p->hwparams, val); 1017 err = snd_pcm_hw_params_set_format (p->handle, p->hwparams, val);
1017 if (err < 0) 1018 if (err < 0)
1018 alsa_sound_perror ("Could not set sound format", err); 1019 alsa_sound_perror ("Could not set sound format", err);
1019 1020
1020 val = sd->sample_rate; 1021 uval = sd->sample_rate;
1021 err = snd_pcm_hw_params_set_rate_near (p->handle, p->hwparams, &val, 0); 1022 err = snd_pcm_hw_params_set_rate_near (p->handle, p->hwparams, &uval, 0);
1022 if (err < 0) 1023 if (err < 0)
1023 alsa_sound_perror ("Could not set sample rate", err); 1024 alsa_sound_perror ("Could not set sample rate", err);
1024 1025
1025 val = sd->channels; 1026 val = sd->channels;
1026 err = snd_pcm_hw_params_set_channels (p->handle, p->hwparams, val); 1027 err = snd_pcm_hw_params_set_channels (p->handle, p->hwparams, val);
1121 snd_pcm_hw_params_free (p->hwparams); 1122 snd_pcm_hw_params_free (p->hwparams);
1122 if (p->swparams) 1123 if (p->swparams)
1123 snd_pcm_sw_params_free (p->swparams); 1124 snd_pcm_sw_params_free (p->swparams);
1124 if (p->handle) 1125 if (p->handle)
1125 { 1126 {
1126 snd_pcm_drain(p->handle); 1127 snd_pcm_drain (p->handle);
1127 snd_pcm_close (p->handle); 1128 snd_pcm_close (p->handle);
1128 } 1129 }
1129 free (p); 1130 free (p);
1130 } 1131 }
1131 } 1132 }
1267 1268
1268 snd_lib_error_set_handler ((snd_lib_error_handler_t) snd_error_quiet); 1269 snd_lib_error_set_handler ((snd_lib_error_handler_t) snd_error_quiet);
1269 err = snd_pcm_open (&handle, file, SND_PCM_STREAM_PLAYBACK, 0); 1270 err = snd_pcm_open (&handle, file, SND_PCM_STREAM_PLAYBACK, 0);
1270 snd_lib_error_set_handler (NULL); 1271 snd_lib_error_set_handler (NULL);
1271 if (err < 0) 1272 if (err < 0)
1272 return 0; 1273 return 0;
1274 snd_pcm_close (handle);
1273 1275
1274 sd->fd = -1; 1276 sd->fd = -1;
1275 sd->open = alsa_open; 1277 sd->open = alsa_open;
1276 sd->close = alsa_close; 1278 sd->close = alsa_close;
1277 sd->configure = alsa_configure; 1279 sd->configure = alsa_configure;