comparison src/alsa/audio.c @ 2353:415e67d313ad

Experimental 24-bit support. Can someone test this? It doesn't work for me.
author William Pitcock <nenolod@atheme.org>
date Mon, 04 Feb 2008 01:06:03 -0600
parents 0f2ac612f318
children 9056897525e1
comparison
equal deleted inserted replaced
2352:08a7d1f7c4a5 2353:415e67d313ad
2 * Copyright (C) 2001-2003 Matthieu Sozeau <mattam@altern.org> 2 * Copyright (C) 2001-2003 Matthieu Sozeau <mattam@altern.org>
3 * Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas, 3 * Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas,
4 * Thomas Nilsson and 4Front Technologies 4 * Thomas Nilsson and 4Front Technologies
5 * Copyright (C) 1999-2006 Haavard Kvaalen 5 * Copyright (C) 1999-2006 Haavard Kvaalen
6 * Copyright (C) 2005 Takashi Iwai 6 * Copyright (C) 2005 Takashi Iwai
7 * Copyright (C) 2007 William Pitcock 7 * Copyright (C) 2007-2008 William Pitcock
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or 11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version. 12 * (at your option) any later version.
98 98
99 static const struct { 99 static const struct {
100 AFormat xmms; 100 AFormat xmms;
101 snd_pcm_format_t alsa; 101 snd_pcm_format_t alsa;
102 } format_table[] = 102 } format_table[] =
103 {{FMT_S16_LE, SND_PCM_FORMAT_S16_LE}, 103 {
104 #if 0
105 /* i don't know if we will ever do this --nenolod */
106 {FMT_S32_LE, SND_PCM_FORMAT_S32_LE},
107 {FMT_S32_BE, SND_PCM_FORMAT_S32_BE},
108 {FMT_S32_NE, SND_PCM_FORMAT_S32},
109 #endif
110 {FMT_S24_LE, SND_PCM_FORMAT_S24_LE},
111 {FMT_S24_BE, SND_PCM_FORMAT_S24_BE},
112 {FMT_S24_NE, SND_PCM_FORMAT_S24},
113 {FMT_U24_LE, SND_PCM_FORMAT_U24_LE},
114 {FMT_U24_BE, SND_PCM_FORMAT_U24_BE},
115 {FMT_U24_NE, SND_PCM_FORMAT_U24},
116 {FMT_S16_LE, SND_PCM_FORMAT_S16_LE},
104 {FMT_S16_BE, SND_PCM_FORMAT_S16_BE}, 117 {FMT_S16_BE, SND_PCM_FORMAT_S16_BE},
105 {FMT_S16_NE, SND_PCM_FORMAT_S16}, 118 {FMT_S16_NE, SND_PCM_FORMAT_S16},
106 {FMT_U16_LE, SND_PCM_FORMAT_U16_LE}, 119 {FMT_U16_LE, SND_PCM_FORMAT_U16_LE},
107 {FMT_U16_BE, SND_PCM_FORMAT_U16_BE}, 120 {FMT_U16_BE, SND_PCM_FORMAT_U16_BE},
108 {FMT_U16_NE, SND_PCM_FORMAT_U16}, 121 {FMT_U16_NE, SND_PCM_FORMAT_U16},
787 f->format = SND_PCM_FORMAT_UNKNOWN; 800 f->format = SND_PCM_FORMAT_UNKNOWN;
788 801
789 for (i = 0; i < sizeof(format_table) / sizeof(format_table[0]); i++) 802 for (i = 0; i < sizeof(format_table) / sizeof(format_table[0]); i++)
790 if (format_table[i].xmms == fmt) 803 if (format_table[i].xmms == fmt)
791 { 804 {
805 printf("match!\n");
792 f->format = format_table[i].alsa; 806 f->format = format_table[i].alsa;
793 break; 807 break;
794 } 808 }
795 809
796 /* Get rid of _NE */ 810 /* Get rid of _NE */
883 g_warning("alsa_setup(): Cannot set direct write mode: %s", 897 g_warning("alsa_setup(): Cannot set direct write mode: %s",
884 snd_strerror(err)); 898 snd_strerror(err));
885 return -1; 899 return -1;
886 } 900 }
887 901
902 /* XXX: there is no down-dithering for 24bit yet --nenolod */
888 if ((err = snd_pcm_hw_params_set_format(alsa_pcm, hwparams, outputf->format)) < 0) 903 if ((err = snd_pcm_hw_params_set_format(alsa_pcm, hwparams, outputf->format)) < 0)
889 { 904 {
890 /* 905 g_warning("alsa_setup(): Sample format not "
891 * Try if one of these format work (one of them should work 906 "available for playback: %s",
892 * on almost all soundcards) 907 snd_strerror(err));
893 */ 908 return -1;
894 snd_pcm_format_t formats[] = {SND_PCM_FORMAT_S16_LE,
895 SND_PCM_FORMAT_S16_BE,
896 SND_PCM_FORMAT_U8};
897 size_t i;
898
899 for (i = 0; i < sizeof(formats) / sizeof(formats[0]); i++)
900 {
901 if (snd_pcm_hw_params_set_format(alsa_pcm, hwparams,
902 formats[i]) == 0)
903 {
904 outputf->format = formats[i];
905 break;
906 }
907 }
908 if (outputf->format != f->format)
909 {
910 outputf->xmms_format =
911 format_from_alsa(outputf->format);
912 debug("Converting format from %d to %d",
913 f->xmms_format, outputf->xmms_format);
914 alsa_convert_func =
915 aud_convert_get_func(outputf->xmms_format,
916 f->xmms_format);
917 if (alsa_convert_func == NULL)
918 return -1;
919 }
920 else
921 {
922 g_warning("alsa_setup(): Sample format not "
923 "available for playback: %s",
924 snd_strerror(err));
925 return -1;
926 }
927 } 909 }
928 910
929 snd_pcm_hw_params_set_channels_near(alsa_pcm, hwparams, &outputf->channels); 911 snd_pcm_hw_params_set_channels_near(alsa_pcm, hwparams, &outputf->channels);
930 if (outputf->channels != f->channels) 912 if (outputf->channels != f->channels)
931 { 913 {