# HG changeset patch # User joyping # Date 1060970544 0 # Node ID abdb28a904c841c38b922c45059e55df0183a1ff # Parent 085c10cf912c388c2e309f7f4b5023a6fd1667f1 no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov , removed braindeaded startup message diff -r 085c10cf912c -r abdb28a904c8 libao2/ao_alsa1x.c --- a/libao2/ao_alsa1x.c Fri Aug 15 16:36:32 2003 +0000 +++ b/libao2/ao_alsa1x.c Fri Aug 15 18:02:24 2003 +0000 @@ -208,8 +208,7 @@ snd_pcm_info_t *alsa_info; char *str_block_mode; int device_set = 0; - - printf("alsa-init: testing and bugreports are welcome.\n"); + printf("alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz, channels, audio_out_format_name(format)); @@ -286,7 +285,6 @@ default: break; } - bytes_per_sample = ao_data.bps / ao_data.samplerate; if (ao_subdevice) { //start parsing ao_subdevice, ugly and not thread safe! @@ -337,7 +335,25 @@ } } } - } //end parsing ao_subdevice + } else { //end parsing ao_subdevice + /* in any case for multichannel playback we should select + * appropriate device + */ + char devstr[128]; + + switch (channels) { + case 4: + strcpy(devstr, "surround40"); + alsa_device = devstr; + break; + case 6: + strcpy(devstr, "surround51"); + alsa_device = devstr; + break; + default: + } + } + /* switch for spdif * sets opening sequence for SPDIF @@ -377,7 +393,7 @@ default: fprintf(stderr, "%d channels are not supported\n", channels); - return(0); + exit (0); } alsa_device = devstr; @@ -544,6 +560,21 @@ printf("alsa-init: unable to set access type: %s\n", snd_strerror(err)); return (0); } + + /* workaround for nonsupported formats + sets default format to S16_LE if the given formats aren't supported */ + if ((err = snd_pcm_hw_params_test_format(alsa_handler, alsa_hwparams, + alsa_format)) < 0) + { + printf("alsa-init: format %s are not supported by hardware, trying default\n", + audio_out_format_name(format)); + alsa_format = SND_PCM_FORMAT_S16_LE; + ao_data.format = AFMT_S16_LE; + ao_data.bps = channels * rate_hz * 2; + } + + bytes_per_sample = ao_data.bps / ao_data.samplerate; //it should be here + if ((err = snd_pcm_hw_params_set_format(alsa_handler, alsa_hwparams, alsa_format)) < 0) @@ -916,7 +947,7 @@ printf("alsa-play: write error %s", snd_strerror(res)); return 0; } - return res < 0 ? (int)res : len; + return res < 0 ? (int)res : len - len % bytes_per_sample; } /* mmap-mode mainly based on descriptions by Joshua Haberman diff -r 085c10cf912c -r abdb28a904c8 libao2/ao_alsa9.c --- a/libao2/ao_alsa9.c Fri Aug 15 16:36:32 2003 +0000 +++ b/libao2/ao_alsa9.c Fri Aug 15 18:02:24 2003 +0000 @@ -208,8 +208,7 @@ snd_pcm_info_t *alsa_info; char *str_block_mode; int device_set = 0; - - printf("alsa-init: testing and bugreports are welcome.\n"); + printf("alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz, channels, audio_out_format_name(format)); @@ -286,7 +285,6 @@ default: break; } - bytes_per_sample = ao_data.bps / ao_data.samplerate; if (ao_subdevice) { //start parsing ao_subdevice, ugly and not thread safe! @@ -337,7 +335,25 @@ } } } - } //end parsing ao_subdevice + } else { //end parsing ao_subdevice + /* in any case for multichannel playback we should select + * appropriate device + */ + char devstr[128]; + + switch (channels) { + case 4: + strcpy(devstr, "surround40"); + alsa_device = devstr; + break; + case 6: + strcpy(devstr, "surround51"); + alsa_device = devstr; + break; + default: + } + } + /* switch for spdif * sets opening sequence for SPDIF @@ -377,7 +393,7 @@ default: fprintf(stderr, "%d channels are not supported\n", channels); - return(0); + exit (0); } alsa_device = devstr; @@ -544,6 +560,21 @@ printf("alsa-init: unable to set access type: %s\n", snd_strerror(err)); return (0); } + + /* workaround for nonsupported formats + sets default format to S16_LE if the given formats aren't supported */ + if ((err = snd_pcm_hw_params_test_format(alsa_handler, alsa_hwparams, + alsa_format)) < 0) + { + printf("alsa-init: format %s are not supported by hardware, trying default\n", + audio_out_format_name(format)); + alsa_format = SND_PCM_FORMAT_S16_LE; + ao_data.format = AFMT_S16_LE; + ao_data.bps = channels * rate_hz * 2; + } + + bytes_per_sample = ao_data.bps / ao_data.samplerate; //it should be here + if ((err = snd_pcm_hw_params_set_format(alsa_handler, alsa_hwparams, alsa_format)) < 0) @@ -916,7 +947,7 @@ printf("alsa-play: write error %s", snd_strerror(res)); return 0; } - return res < 0 ? (int)res : len; + return res < 0 ? (int)res : len - len % bytes_per_sample; } /* mmap-mode mainly based on descriptions by Joshua Haberman