diff options
Diffstat (limited to 'firmware/target')
-rw-r--r-- | firmware/target/hosted/pcm-alsa.c | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/firmware/target/hosted/pcm-alsa.c b/firmware/target/hosted/pcm-alsa.c index 02cb34ea5b..b78993dd0a 100644 --- a/firmware/target/hosted/pcm-alsa.c +++ b/firmware/target/hosted/pcm-alsa.c | |||
@@ -91,7 +91,7 @@ static int set_hwparams(snd_pcm_t *handle, unsigned sample_rate) | |||
91 | unsigned int rrate; | 91 | unsigned int rrate; |
92 | int err; | 92 | int err; |
93 | snd_pcm_hw_params_t *params; | 93 | snd_pcm_hw_params_t *params; |
94 | snd_pcm_hw_params_alloca(¶ms); | 94 | snd_pcm_hw_params_malloc(¶ms); |
95 | 95 | ||
96 | 96 | ||
97 | /* choose all parameters */ | 97 | /* choose all parameters */ |
@@ -99,28 +99,28 @@ static int set_hwparams(snd_pcm_t *handle, unsigned sample_rate) | |||
99 | if (err < 0) | 99 | if (err < 0) |
100 | { | 100 | { |
101 | printf("Broken configuration for playback: no configurations available: %s\n", snd_strerror(err)); | 101 | printf("Broken configuration for playback: no configurations available: %s\n", snd_strerror(err)); |
102 | return err; | 102 | goto error; |
103 | } | 103 | } |
104 | /* set the interleaved read/write format */ | 104 | /* set the interleaved read/write format */ |
105 | err = snd_pcm_hw_params_set_access(handle, params, access_); | 105 | err = snd_pcm_hw_params_set_access(handle, params, access_); |
106 | if (err < 0) | 106 | if (err < 0) |
107 | { | 107 | { |
108 | printf("Access type not available for playback: %s\n", snd_strerror(err)); | 108 | printf("Access type not available for playback: %s\n", snd_strerror(err)); |
109 | return err; | 109 | goto error; |
110 | } | 110 | } |
111 | /* set the sample format */ | 111 | /* set the sample format */ |
112 | err = snd_pcm_hw_params_set_format(handle, params, format); | 112 | err = snd_pcm_hw_params_set_format(handle, params, format); |
113 | if (err < 0) | 113 | if (err < 0) |
114 | { | 114 | { |
115 | printf("Sample format not available for playback: %s\n", snd_strerror(err)); | 115 | printf("Sample format not available for playback: %s\n", snd_strerror(err)); |
116 | return err; | 116 | goto error; |
117 | } | 117 | } |
118 | /* set the count of channels */ | 118 | /* set the count of channels */ |
119 | err = snd_pcm_hw_params_set_channels(handle, params, channels); | 119 | err = snd_pcm_hw_params_set_channels(handle, params, channels); |
120 | if (err < 0) | 120 | if (err < 0) |
121 | { | 121 | { |
122 | printf("Channels count (%i) not available for playbacks: %s\n", channels, snd_strerror(err)); | 122 | printf("Channels count (%i) not available for playbacks: %s\n", channels, snd_strerror(err)); |
123 | return err; | 123 | goto error; |
124 | } | 124 | } |
125 | /* set the stream rate */ | 125 | /* set the stream rate */ |
126 | rrate = sample_rate; | 126 | rrate = sample_rate; |
@@ -128,28 +128,29 @@ static int set_hwparams(snd_pcm_t *handle, unsigned sample_rate) | |||
128 | if (err < 0) | 128 | if (err < 0) |
129 | { | 129 | { |
130 | printf("Rate %iHz not available for playback: %s\n", rate, snd_strerror(err)); | 130 | printf("Rate %iHz not available for playback: %s\n", rate, snd_strerror(err)); |
131 | return err; | 131 | goto error; |
132 | } | 132 | } |
133 | if (rrate != sample_rate) | 133 | if (rrate != sample_rate) |
134 | { | 134 | { |
135 | printf("Rate doesn't match (requested %iHz, get %iHz)\n", sample_rate, err); | 135 | printf("Rate doesn't match (requested %iHz, get %iHz)\n", sample_rate, err); |
136 | return -EINVAL; | 136 | err = -EINVAL; |
137 | goto error; | ||
137 | } | 138 | } |
138 | 139 | ||
139 | /* set the buffer size */ | 140 | /* set the buffer size */ |
140 | err = snd_pcm_hw_params_set_buffer_size_near(handle, params, &buffer_size); | 141 | err = snd_pcm_hw_params_set_buffer_size_near(handle, params, &buffer_size); |
141 | if (err < 0) | 142 | if (err < 0) |
142 | { | 143 | { |
143 | printf("Unable to set buffer size %i for playback: %s\n", buffer_size, snd_strerror(err)); | 144 | printf("Unable to set buffer size %ld for playback: %s\n", buffer_size, snd_strerror(err)); |
144 | return err; | 145 | goto error; |
145 | } | 146 | } |
146 | 147 | ||
147 | /* set the period size */ | 148 | /* set the period size */ |
148 | err = snd_pcm_hw_params_set_period_size_near (handle, params, &period_size, NULL); | 149 | err = snd_pcm_hw_params_set_period_size_near (handle, params, &period_size, NULL); |
149 | if (err < 0) | 150 | if (err < 0) |
150 | { | 151 | { |
151 | printf("Unable to set period size %i for playback: %s\n", period_size, snd_strerror(err)); | 152 | printf("Unable to set period size %ld for playback: %s\n", period_size, snd_strerror(err)); |
152 | return err; | 153 | goto error; |
153 | } | 154 | } |
154 | if (!frames) | 155 | if (!frames) |
155 | frames = malloc(period_size * channels * sizeof(short)); | 156 | frames = malloc(period_size * channels * sizeof(short)); |
@@ -159,9 +160,13 @@ static int set_hwparams(snd_pcm_t *handle, unsigned sample_rate) | |||
159 | if (err < 0) | 160 | if (err < 0) |
160 | { | 161 | { |
161 | printf("Unable to set hw params for playback: %s\n", snd_strerror(err)); | 162 | printf("Unable to set hw params for playback: %s\n", snd_strerror(err)); |
162 | return err; | 163 | goto error; |
163 | } | 164 | } |
164 | return 0; | 165 | |
166 | err = 0; /* success */ | ||
167 | error: | ||
168 | snd_pcm_hw_params_free(params); | ||
169 | return err; | ||
165 | } | 170 | } |
166 | 171 | ||
167 | /* Set sw params: playback start threshold and low buffer watermark */ | 172 | /* Set sw params: playback start threshold and low buffer watermark */ |
@@ -170,37 +175,41 @@ static int set_swparams(snd_pcm_t *handle) | |||
170 | int err; | 175 | int err; |
171 | 176 | ||
172 | snd_pcm_sw_params_t *swparams; | 177 | snd_pcm_sw_params_t *swparams; |
173 | snd_pcm_sw_params_alloca(&swparams); | 178 | snd_pcm_sw_params_malloc(&swparams); |
174 | 179 | ||
175 | /* get the current swparams */ | 180 | /* get the current swparams */ |
176 | err = snd_pcm_sw_params_current(handle, swparams); | 181 | err = snd_pcm_sw_params_current(handle, swparams); |
177 | if (err < 0) | 182 | if (err < 0) |
178 | { | 183 | { |
179 | printf("Unable to determine current swparams for playback: %s\n", snd_strerror(err)); | 184 | printf("Unable to determine current swparams for playback: %s\n", snd_strerror(err)); |
180 | return err; | 185 | goto error; |
181 | } | 186 | } |
182 | /* start the transfer when the buffer is haalmost full */ | 187 | /* start the transfer when the buffer is haalmost full */ |
183 | err = snd_pcm_sw_params_set_start_threshold(handle, swparams, buffer_size / 2); | 188 | err = snd_pcm_sw_params_set_start_threshold(handle, swparams, buffer_size / 2); |
184 | if (err < 0) | 189 | if (err < 0) |
185 | { | 190 | { |
186 | printf("Unable to set start threshold mode for playback: %s\n", snd_strerror(err)); | 191 | printf("Unable to set start threshold mode for playback: %s\n", snd_strerror(err)); |
187 | return err; | 192 | goto error; |
188 | } | 193 | } |
189 | /* allow the transfer when at least period_size samples can be processed */ | 194 | /* allow the transfer when at least period_size samples can be processed */ |
190 | err = snd_pcm_sw_params_set_avail_min(handle, swparams, period_size); | 195 | err = snd_pcm_sw_params_set_avail_min(handle, swparams, period_size); |
191 | if (err < 0) | 196 | if (err < 0) |
192 | { | 197 | { |
193 | printf("Unable to set avail min for playback: %s\n", snd_strerror(err)); | 198 | printf("Unable to set avail min for playback: %s\n", snd_strerror(err)); |
194 | return err; | 199 | goto error; |
195 | } | 200 | } |
196 | /* write the parameters to the playback device */ | 201 | /* write the parameters to the playback device */ |
197 | err = snd_pcm_sw_params(handle, swparams); | 202 | err = snd_pcm_sw_params(handle, swparams); |
198 | if (err < 0) | 203 | if (err < 0) |
199 | { | 204 | { |
200 | printf("Unable to set sw params for playback: %s\n", snd_strerror(err)); | 205 | printf("Unable to set sw params for playback: %s\n", snd_strerror(err)); |
201 | return err; | 206 | goto error; |
202 | } | 207 | } |
203 | return 0; | 208 | |
209 | err = 0; /* success */ | ||
210 | error: | ||
211 | snd_pcm_sw_params_free(swparams); | ||
212 | return err; | ||
204 | } | 213 | } |
205 | 214 | ||
206 | /* copy pcm samples to a spare buffer, suitable for snd_pcm_writei() */ | 215 | /* copy pcm samples to a spare buffer, suitable for snd_pcm_writei() */ |