|
@@ -0,0 +1,173 @@
|
|
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.
|
|
4
|
+
|
|
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
|
|
7
|
+@@ -28,31 +28,30 @@
|
|
8
|
+
|
|
9
|
+ #include <errno.h>
|
|
10
|
+
|
|
11
|
+-#define ALSA_PCM_OLD_HW_PARAMS_API
|
|
12
|
+-#define ALSA_PCM_OLD_SW_PARAMS_API
|
|
13
|
+ #include <alsa/asoundlib.h>
|
|
14
|
+
|
|
15
|
+ #include <mad.h>
|
|
16
|
+
|
|
17
|
+ #include "audio.h"
|
|
18
|
+
|
|
19
|
+-char *buf = NULL;
|
|
20
|
+-int paused = 0;
|
|
21
|
++#define BUFFER_TIME_MAX 500000
|
|
22
|
+
|
|
23
|
+-int rate = -1;
|
|
24
|
+-int channels = -1;
|
|
25
|
+-int bitdepth = -1;
|
|
26
|
+-int sample_size = -1;
|
|
27
|
+-
|
|
28
|
+-int buffer_time = 500000;
|
|
29
|
+-int period_time = 100000;
|
|
30
|
+-char *defaultdev = "plughw:0,0";
|
|
31
|
++unsigned char *buf = NULL;
|
|
32
|
++int paused = 0;
|
|
33
|
++
|
|
34
|
++unsigned int rate = 0;
|
|
35
|
++unsigned int channels = -1;
|
|
36
|
++unsigned int bitdepth = -1;
|
|
37
|
++unsigned int sample_size = -1;
|
|
38
|
++
|
|
39
|
++unsigned int buffer_time;
|
|
40
|
++unsigned int period_time;
|
|
41
|
++char *defaultdev = "plughw:0,0";
|
|
42
|
+
|
|
43
|
+ snd_pcm_hw_params_t *alsa_hwparams;
|
|
44
|
+ snd_pcm_sw_params_t *alsa_swparams;
|
|
45
|
+
|
|
46
|
+-snd_pcm_sframes_t buffer_size;
|
|
47
|
+-snd_pcm_sframes_t period_size;
|
|
48
|
++snd_pcm_uframes_t buffer_size;
|
|
49
|
+
|
|
50
|
+ snd_pcm_format_t alsa_format = -1;
|
|
51
|
+ snd_pcm_access_t alsa_access = SND_PCM_ACCESS_MMAP_INTERLEAVED;
|
|
52
|
+@@ -66,14 +65,20 @@
|
|
53
|
+ snd_pcm_hw_params_t *params,
|
|
54
|
+ snd_pcm_access_t access)
|
|
55
|
+ {
|
|
56
|
+- int err, dir;
|
|
57
|
+-
|
|
58
|
++ int err;
|
|
59
|
++
|
|
60
|
+ /* choose all parameters */
|
|
61
|
+ err = snd_pcm_hw_params_any(handle,params);
|
|
62
|
+ if (err < 0) {
|
|
63
|
+ printf("Access type not available for playback: %s\n", snd_strerror(err));
|
|
64
|
+ return err;
|
|
65
|
+ }
|
|
66
|
++ /* set the access type */
|
|
67
|
++ err = snd_pcm_hw_params_set_access(handle, params, alsa_access);
|
|
68
|
++ if (err < 0) {
|
|
69
|
++ printf("Sample format not available for playback: %s\n", snd_strerror(err));
|
|
70
|
++ return err;
|
|
71
|
++ }
|
|
72
|
+ /* set the sample format */
|
|
73
|
+ err = snd_pcm_hw_params_set_format(handle, params, alsa_format);
|
|
74
|
+ if (err < 0) {
|
|
75
|
+@@ -87,29 +92,38 @@
|
|
76
|
+ return err;
|
|
77
|
+ }
|
|
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);
|
|
81
|
+ if (err < 0) {
|
|
82
|
+ printf("Rate %iHz not available for playback: %s\n", rate, snd_strerror(err));
|
|
83
|
+ return err;
|
|
84
|
+ }
|
|
85
|
+- if (err != rate) {
|
|
86
|
+- printf("Rate doesn't match (requested %iHz, get %iHz)\n", rate, err);
|
|
87
|
+- return -EINVAL;
|
|
88
|
+- }
|
|
89
|
++ err = snd_pcm_hw_params_get_buffer_time_max(params, &buffer_time, NULL);
|
|
90
|
++ if (err < 0) {
|
|
91
|
++ printf("Unable to retrieve buffer time: %s\n", snd_strerror(err));
|
|
92
|
++ return err;
|
|
93
|
++ }
|
|
94
|
++ if (buffer_time > BUFFER_TIME_MAX)
|
|
95
|
++ buffer_time = BUFFER_TIME_MAX;
|
|
96
|
+ /* set buffer time */
|
|
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);
|
|
99
|
+ if (err < 0) {
|
|
100
|
+ printf("Unable to set buffer time %i for playback: %s\n", buffer_time, snd_strerror(err));
|
|
101
|
+ return err;
|
|
102
|
+ }
|
|
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);
|
|
109
|
+ if (err < 0) {
|
|
110
|
+ printf("Unable to set period time %i for playback: %s\n", period_time, snd_strerror(err));
|
|
111
|
+ return err;
|
|
112
|
+ }
|
|
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);
|
|
116
|
++ if (err < 0) {
|
|
117
|
++ printf("Unable to retrieve buffer size: %s\n", snd_strerror(err));
|
|
118
|
++ return err;
|
|
119
|
++ }
|
|
120
|
+ /* write the parameters to device */
|
|
121
|
+ err = snd_pcm_hw_params(handle, params);
|
|
122
|
+ if (err < 0) {
|
|
123
|
+@@ -123,6 +137,7 @@
|
|
124
|
+ int set_swparams(snd_pcm_t *handle,
|
|
125
|
+ snd_pcm_sw_params_t *params)
|
|
126
|
+ {
|
|
127
|
++ unsigned int start_threshold;
|
|
128
|
+ int err;
|
|
129
|
+
|
|
130
|
+ /* get current swparams */
|
|
131
|
+@@ -136,13 +151,7 @@
|
|
132
|
+ if (err < 0) {
|
|
133
|
+ printf("Unable to set start threshold mode for playback: %s\n", snd_strerror(err));
|
|
134
|
+ return err;
|
|
135
|
+- }
|
|
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);
|
|
138
|
+- if (err < 0) {
|
|
139
|
+- printf("Unable to set avail min for playback: %s\n", snd_strerror(err));
|
|
140
|
+- return err;
|
|
141
|
+- }
|
|
142
|
++ }
|
|
143
|
+ /* align all transfers to 1 samples */
|
|
144
|
+ err = snd_pcm_sw_params_set_xfer_align(handle, params, 1);
|
|
145
|
+ if (err < 0) {
|
|
146
|
+@@ -190,7 +199,7 @@
|
|
147
|
+ rate = config->speed;
|
|
148
|
+
|
|
149
|
+ if ( bitdepth == 0 )
|
|
150
|
+- config->precision = bitdepth = 32;
|
|
151
|
++ config->precision = bitdepth = 16;
|
|
152
|
+
|
|
153
|
+ switch (bitdepth)
|
|
154
|
+ {
|
|
155
|
+@@ -241,7 +250,7 @@
|
|
156
|
+ return -1;
|
|
157
|
+ }
|
|
158
|
+
|
|
159
|
+- buf = malloc(buffer_size);
|
|
160
|
++ buf = malloc(buffer_size * sample_size);
|
|
161
|
+ if (buf == NULL) {
|
|
162
|
+ audio_error="unable to allocate output buffer table";
|
|
163
|
+ return -1;
|
|
164
|
+@@ -279,7 +288,7 @@
|
|
165
|
+ int play(struct audio_play *play)
|
|
166
|
+ {
|
|
167
|
+ int err, len;
|
|
168
|
+- char *ptr;
|
|
169
|
++ unsigned char *ptr;
|
|
170
|
+
|
|
171
|
+ ptr = buf;
|
|
172
|
+ len = play->nsamples;
|
|
173
|
+
|