#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include int main (); void alsa_open (); // START OF PROGRAMS // // M A I N // int main () { alsa_open (); return 0; } /*------------------------------------------------------------------------------ ** Linux alsa functions for playing a sound. */ void alsa_open () { //char *default_device = "default" ; char *device = "plughw:0,0" ; int err ; snd_pcm_t *alsa_dev = NULL ; snd_pcm_hw_params_t *hw_params ; err = snd_pcm_open (&alsa_dev, device, SND_PCM_STREAM_PLAYBACK, 0); if (err < 0) { fprintf (stderr, "cannot open audio device \"%s\" (%s)\n", device, snd_strerror (err)) ; goto catch_error ; } ; err = snd_pcm_hw_params_malloc (&hw_params); if (err < 0) { fprintf (stderr, "cannot allocate hardware parameter structure (%s)\n", snd_strerror (err)) ; goto catch_error ; } ; err = snd_pcm_hw_params_any (alsa_dev, hw_params); if (err < 0) { fprintf (stderr, "cannot initialize hardware parameter structure (%s)\n", snd_strerror (err)) ; goto catch_error ; } ; err = snd_pcm_hw_params_set_access (alsa_dev, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED); if (err < 0) { fprintf (stderr, "cannot set access type (%s)\n", snd_strerror (err)) ; goto catch_error ; } ; int iformat; fprintf (stderr, "Value of last format %lu\n", (unsigned long) SND_PCM_FORMAT_LAST) ; for (iformat = 0; iformat <= SND_PCM_FORMAT_LAST; iformat++) { err = snd_pcm_hw_params_test_format (alsa_dev, hw_params, iformat); if (err < 0) fprintf (stderr, "test of sample format %lu failed (%s)\n", (unsigned long) iformat, snd_strerror (err)) ; } err = snd_pcm_hw_params_set_format (alsa_dev, hw_params, SND_PCM_FORMAT_FLOAT64); if (err < 0) { fprintf (stderr, "cannot set sample format %lu (%s)\n", (unsigned long) SND_PCM_FORMAT_FLOAT64, snd_strerror (err)) ; goto catch_error ; } ; snd_pcm_format_t fval; snd_pcm_hw_params_get_format (hw_params, &fval); fprintf (stderr, "Format (%lu)\n", (unsigned long) fval); if ((unsigned long) fval != (unsigned long) SND_PCM_FORMAT_FLOAT64) fprintf (stderr, "Format (%lu) differs from requested (%lu)\n", (unsigned long) fval, (unsigned long) SND_PCM_FORMAT_FLOAT64); snd_pcm_close (alsa_dev) ; catch_error : if (err < 0 && alsa_dev != NULL) { snd_pcm_close (alsa_dev) ; } ; }