Line
Link Here
|
0 |
-- madplay-0.15.2b/audio_alsa.c |
0 |
++ madplay-0.15.2b-alsaapi/audio_alsa.c |
Lines 28-35
Link Here
|
28 |
|
28 |
|
29 |
#include <errno.h> |
29 |
#include <errno.h> |
30 |
|
30 |
|
31 |
#define ALSA_PCM_OLD_HW_PARAMS_API |
|
|
32 |
#define ALSA_PCM_OLD_SW_PARAMS_API |
33 |
#include <alsa/asoundlib.h> |
31 |
#include <alsa/asoundlib.h> |
34 |
|
32 |
|
35 |
#include <mad.h> |
33 |
#include <mad.h> |
Lines 44-58
int channels = -1;
Link Here
|
44 |
int bitdepth = -1; |
42 |
int bitdepth = -1; |
45 |
int sample_size = -1; |
43 |
int sample_size = -1; |
46 |
|
44 |
|
47 |
int buffer_time = 500000; |
45 |
unsigned int buffer_time= 500000; |
48 |
int period_time = 100000; |
46 |
unsigned int period_time= 100000; |
49 |
char *defaultdev = "plughw:0,0"; |
47 |
char *defaultdev = "plughw:0,0"; |
50 |
|
48 |
|
51 |
snd_pcm_hw_params_t *alsa_hwparams; |
49 |
snd_pcm_hw_params_t *alsa_hwparams; |
52 |
snd_pcm_sw_params_t *alsa_swparams; |
50 |
snd_pcm_sw_params_t *alsa_swparams; |
53 |
|
51 |
|
54 |
snd_pcm_sframes_t buffer_size; |
52 |
snd_pcm_uframes_t buffer_size; |
55 |
snd_pcm_sframes_t period_size; |
53 |
snd_pcm_uframes_t period_size; |
56 |
|
54 |
|
57 |
snd_pcm_format_t alsa_format = -1; |
55 |
snd_pcm_format_t alsa_format = -1; |
58 |
snd_pcm_access_t alsa_access = SND_PCM_ACCESS_MMAP_INTERLEAVED; |
56 |
snd_pcm_access_t alsa_access = SND_PCM_ACCESS_MMAP_INTERLEAVED; |
Lines 67-73
int set_hwparams(snd_pcm_t *handle,
Link Here
|
67 |
snd_pcm_access_t access) |
65 |
snd_pcm_access_t access) |
68 |
{ |
66 |
{ |
69 |
int err, dir; |
67 |
int err, dir; |
70 |
|
68 |
unsigned int rwval; |
|
|
69 |
|
71 |
/* choose all parameters */ |
70 |
/* choose all parameters */ |
72 |
err = snd_pcm_hw_params_any(handle,params); |
71 |
err = snd_pcm_hw_params_any(handle,params); |
73 |
if (err < 0) { |
72 |
if (err < 0) { |
Lines 87-115
int set_hwparams(snd_pcm_t *handle,
Link Here
|
87 |
return err; |
86 |
return err; |
88 |
} |
87 |
} |
89 |
/* set the stream rate */ |
88 |
/* set the stream rate */ |
90 |
err = snd_pcm_hw_params_set_rate_near(handle, params, rate, 0); |
89 |
rwval = rate; |
|
|
90 |
err = snd_pcm_hw_params_set_rate_near(handle, params, &rwval, 0); |
91 |
if (err < 0) { |
91 |
if (err < 0) { |
92 |
printf("Rate %iHz not available for playback: %s\n", rate, snd_strerror(err)); |
92 |
printf("Rate %iHz not available for playback: %s\n", rate, snd_strerror(err)); |
93 |
return err; |
93 |
return err; |
94 |
} |
94 |
} |
95 |
if (err != rate) { |
95 |
if (rwval != rate) { |
96 |
printf("Rate doesn't match (requested %iHz, get %iHz)\n", rate, err); |
96 |
printf("Rate doesn't match (requested %iHz, get %iHz)\n", rate, rwval); |
97 |
return -EINVAL; |
97 |
return -EINVAL; |
98 |
} |
98 |
} |
|
|
99 |
else { |
100 |
rate = rwval; |
101 |
} |
99 |
/* set buffer time */ |
102 |
/* set buffer time */ |
100 |
err = snd_pcm_hw_params_set_buffer_time_near(handle, params, buffer_time, &dir); |
103 |
err = snd_pcm_hw_params_set_buffer_time_near(handle, params, &buffer_time, &dir); |
101 |
if (err < 0) { |
104 |
if (err < 0) { |
102 |
printf("Unable to set buffer time %i for playback: %s\n", buffer_time, snd_strerror(err)); |
105 |
printf("Unable to set buffer time %i for playback: %s\n", buffer_time, snd_strerror(err)); |
103 |
return err; |
106 |
return err; |
104 |
} |
107 |
} |
105 |
buffer_size = snd_pcm_hw_params_get_buffer_size(params); |
108 |
err = snd_pcm_hw_params_get_buffer_size(params, &buffer_size); |
|
|
109 |
if (err < 0) { |
110 |
printf("Unable to get buffer size %i for playback: %s\n", buffer_size, snd_strerror(err)); |
111 |
return err; |
112 |
} |
106 |
/* set period time */ |
113 |
/* set period time */ |
107 |
err = snd_pcm_hw_params_set_period_time_near(handle, params, period_time, &dir); |
114 |
err = snd_pcm_hw_params_set_period_time_near(handle, params, &period_time, &dir); |
108 |
if (err < 0) { |
115 |
if (err < 0) { |
109 |
printf("Unable to set period time %i for playback: %s\n", period_time, snd_strerror(err)); |
116 |
printf("Unable to set period time %i for playback: %s\n", period_time, snd_strerror(err)); |
110 |
return err; |
117 |
return err; |
111 |
} |
118 |
} |
112 |
period_size = snd_pcm_hw_params_get_period_size(params, &dir); |
119 |
err = snd_pcm_hw_params_get_period_size(params, &period_size, &dir); |
|
|
120 |
if (err < 0) { |
121 |
printf("Unable to get period size %i for playback: %s\n", period_size, snd_strerror(err)); |
122 |
return err; |
123 |
} |
113 |
/* write the parameters to device */ |
124 |
/* write the parameters to device */ |
114 |
err = snd_pcm_hw_params(handle, params); |
125 |
err = snd_pcm_hw_params(handle, params); |
115 |
if (err < 0) { |
126 |
if (err < 0) { |