1 Switch madplay to the new API. This is done thanks to a patch written
2 by Micha Nelissen <micha@neli.hopto.org> and available at
3 http://article.gmane.org/gmane.comp.audio.mad.devel/729.
5 --- madplay-0.15.2b/audio_alsa.c 2008-10-18 15:10:16.000000000 +0200
6 +++ madplay-0.15.2b/audio_alsa.c.new 2008-10-18 15:03:27.000000000 +0200
11 -#define ALSA_PCM_OLD_HW_PARAMS_API
12 -#define ALSA_PCM_OLD_SW_PARAMS_API
13 #include <alsa/asoundlib.h>
21 +#define BUFFER_TIME_MAX 500000
26 -int sample_size = -1;
28 -int buffer_time = 500000;
29 -int period_time = 100000;
30 -char *defaultdev = "plughw:0,0";
31 +unsigned char *buf = NULL;
34 +unsigned int rate = 0;
35 +unsigned int channels = -1;
36 +unsigned int bitdepth = -1;
37 +unsigned int sample_size = -1;
39 +unsigned int buffer_time;
40 +unsigned int period_time;
41 +char *defaultdev = "plughw:0,0";
43 snd_pcm_hw_params_t *alsa_hwparams;
44 snd_pcm_sw_params_t *alsa_swparams;
46 -snd_pcm_sframes_t buffer_size;
47 -snd_pcm_sframes_t period_size;
48 +snd_pcm_uframes_t buffer_size;
50 snd_pcm_format_t alsa_format = -1;
51 snd_pcm_access_t alsa_access = SND_PCM_ACCESS_MMAP_INTERLEAVED;
53 snd_pcm_hw_params_t *params,
54 snd_pcm_access_t access)
60 /* choose all parameters */
61 err = snd_pcm_hw_params_any(handle,params);
63 printf("Access type not available for playback: %s\n", snd_strerror(err));
66 + /* set the access type */
67 + err = snd_pcm_hw_params_set_access(handle, params, alsa_access);
69 + printf("Sample format not available for playback: %s\n", snd_strerror(err));
72 /* set the sample format */
73 err = snd_pcm_hw_params_set_format(handle, params, alsa_format);
78 /* set the stream rate */
79 - err = snd_pcm_hw_params_set_rate_near(handle, params, rate, 0);
80 + err = snd_pcm_hw_params_set_rate(handle, params, rate, 0);
82 printf("Rate %iHz not available for playback: %s\n", rate, snd_strerror(err));
86 - printf("Rate doesn't match (requested %iHz, get %iHz)\n", rate, err);
89 + err = snd_pcm_hw_params_get_buffer_time_max(params, &buffer_time, NULL);
91 + printf("Unable to retrieve buffer time: %s\n", snd_strerror(err));
94 + if (buffer_time > BUFFER_TIME_MAX)
95 + buffer_time = BUFFER_TIME_MAX;
97 - err = snd_pcm_hw_params_set_buffer_time_near(handle, params, buffer_time, &dir);
98 + err = snd_pcm_hw_params_set_buffer_time_near(handle, params, &buffer_time, 0);
100 printf("Unable to set buffer time %i for playback: %s\n", buffer_time, snd_strerror(err));
103 - buffer_size = snd_pcm_hw_params_get_buffer_size(params);
104 + if (period_time * 4 > buffer_time)
105 + period_time = buffer_time / 4;
106 /* set period time */
107 - err = snd_pcm_hw_params_set_period_time_near(handle, params, period_time, &dir);
108 + err = snd_pcm_hw_params_set_period_time_near(handle, params, &period_time, NULL);
110 printf("Unable to set period time %i for playback: %s\n", period_time, snd_strerror(err));
113 - period_size = snd_pcm_hw_params_get_period_size(params, &dir);
114 + /* retrieve buffer size */
115 + err = snd_pcm_hw_params_get_buffer_size(params, &buffer_size);
117 + printf("Unable to retrieve buffer size: %s\n", snd_strerror(err));
120 /* write the parameters to device */
121 err = snd_pcm_hw_params(handle, params);
124 int set_swparams(snd_pcm_t *handle,
125 snd_pcm_sw_params_t *params)
127 + unsigned int start_threshold;
130 /* get current swparams */
133 printf("Unable to set start threshold mode for playback: %s\n", snd_strerror(err));
136 - /* allow transfer when at least period_size samples can be processed */
137 - err = snd_pcm_sw_params_set_avail_min(handle, params, period_size);
139 - printf("Unable to set avail min for playback: %s\n", snd_strerror(err));
143 /* align all transfers to 1 samples */
144 err = snd_pcm_sw_params_set_xfer_align(handle, params, 1);
147 rate = config->speed;
150 - config->precision = bitdepth = 32;
151 + config->precision = bitdepth = 16;
159 - buf = malloc(buffer_size);
160 + buf = malloc(buffer_size * sample_size);
162 audio_error="unable to allocate output buffer table";
165 int play(struct audio_play *play)
169 + unsigned char *ptr;
172 len = play->nsamples;