|
Lines 46-52
Link Here
|
| 46 |
* get either the default device name or something the |
46 |
* get either the default device name or something the |
| 47 |
* user specified |
47 |
* user specified |
| 48 |
*/ |
48 |
*/ |
| 49 |
void get_device_name(char *retref, int retsize); |
49 |
static void get_in_device_name(char *retref, int retsize); |
|
|
50 |
static void get_out_device_name(char *retref, int retsize); |
| 50 |
|
51 |
|
| 51 |
struct alsa_info |
52 |
struct alsa_info |
| 52 |
{ |
53 |
{ |
|
Lines 58-63
Link Here
|
| 58 |
unsigned int periods; |
59 |
unsigned int periods; |
| 59 |
snd_pcm_uframes_t bufframesize; |
60 |
snd_pcm_uframes_t bufframesize; |
| 60 |
fd_set fd_set; |
61 |
fd_set fd_set; |
|
|
62 |
int setup_read, setup_write; |
| 61 |
}; |
63 |
}; |
| 62 |
|
64 |
|
| 63 |
void *release_alsa(void *handle) |
65 |
void *release_alsa(void *handle) |
|
Lines 76-92
Link Here
|
| 76 |
|
78 |
|
| 77 |
void *grab_read_alsa( void ) |
79 |
void *grab_read_alsa( void ) |
| 78 |
{ |
80 |
{ |
| 79 |
/* no capture support */ |
81 |
struct alsa_info *retval; |
| 80 |
return NULL; |
82 |
snd_pcm_t *handle; |
|
|
83 |
char card_name[256]; |
| 84 |
int err; |
| 85 |
|
| 86 |
get_in_device_name(card_name, 256); |
| 87 |
|
| 88 |
err = snd_pcm_open(&handle, card_name, SND_PCM_STREAM_CAPTURE, 0); |
| 89 |
if(err < 0) |
| 90 |
{ |
| 91 |
const char *serr = snd_strerror(err); |
| 92 |
|
| 93 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 94 |
"grab_alsa: init failed: %s\n", serr); |
| 95 |
|
| 96 |
return NULL; |
| 97 |
} |
| 98 |
|
| 99 |
retval = malloc(sizeof *retval); |
| 100 |
retval->handle = handle; |
| 101 |
retval->format = 0; |
| 102 |
retval->channels = 0; |
| 103 |
retval->speed = 0; |
| 104 |
retval->framesize = 0; |
| 105 |
retval->bufframesize= 0; |
| 106 |
retval->periods = 0; |
| 107 |
retval->setup_read = 0; |
| 108 |
retval->setup_write = 0; |
| 109 |
|
| 110 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 111 |
"grab_alsa: init ok, using %s\n", card_name); |
| 112 |
|
| 113 |
return retval; |
| 114 |
} |
| 115 |
|
| 116 |
static void get_out_device_name(char *retref, int retsize) |
| 117 |
{ |
| 118 |
Rcvar rcv; |
| 119 |
|
| 120 |
assert(retref); |
| 121 |
|
| 122 |
if (!(rcv = rc_lookup("alsa-device"))) |
| 123 |
rcv = rc_lookup("alsa-out-device"); |
| 124 |
if (rcv != NULL) |
| 125 |
{ |
| 126 |
if(rc_type(rcv) == ALRC_STRING) |
| 127 |
{ |
| 128 |
rc_tostr0(rcv, retref, retsize); |
| 129 |
return; |
| 130 |
|
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
assert((int) strlen(DEFAULT_DEVICE) < retsize); |
| 135 |
strcpy(retref, DEFAULT_DEVICE); |
| 136 |
|
| 137 |
return; |
| 81 |
} |
138 |
} |
| 82 |
|
139 |
|
| 83 |
void get_device_name(char *retref, int retsize) |
140 |
static void get_in_device_name(char *retref, int retsize) |
| 84 |
{ |
141 |
{ |
| 85 |
Rcvar rcv; |
142 |
Rcvar rcv; |
| 86 |
|
143 |
|
| 87 |
assert(retref); |
144 |
assert(retref); |
| 88 |
|
145 |
|
| 89 |
rcv = rc_lookup("alsa-device"); |
146 |
if (!(rcv = rc_lookup("alsa-in-device"))) |
|
|
147 |
rcv = rc_lookup("alsa-device"); |
| 90 |
if(rcv != NULL) |
148 |
if(rcv != NULL) |
| 91 |
{ |
149 |
{ |
| 92 |
if(rc_type(rcv) == ALRC_STRING) |
150 |
if(rc_type(rcv) == ALRC_STRING) |
|
Lines 110-118
Link Here
|
| 110 |
char card_name[256]; |
168 |
char card_name[256]; |
| 111 |
int err; |
169 |
int err; |
| 112 |
|
170 |
|
| 113 |
get_device_name(card_name, 256); |
171 |
get_out_device_name(card_name, 256); |
| 114 |
|
172 |
|
| 115 |
err = snd_pcm_open(&handle, card_name, 0, SND_PCM_STREAM_PLAYBACK); |
173 |
err = snd_pcm_open(&handle, card_name, SND_PCM_STREAM_PLAYBACK, 0); |
| 116 |
if(err < 0) |
174 |
if(err < 0) |
| 117 |
{ |
175 |
{ |
| 118 |
const char *serr = snd_strerror(err); |
176 |
const char *serr = snd_strerror(err); |
|
Lines 130-136
Link Here
|
| 130 |
retval->speed = 0; |
188 |
retval->speed = 0; |
| 131 |
retval->framesize = 0; |
189 |
retval->framesize = 0; |
| 132 |
retval->bufframesize= 0; |
190 |
retval->bufframesize= 0; |
| 133 |
retval->periods = 0; |
191 |
retval->periods = 0; |
|
|
192 |
retval->setup_read = 0; |
| 193 |
retval->setup_write = 0; |
| 134 |
|
194 |
|
| 135 |
_alBlitBuffer = alsa_blitbuffer; |
195 |
_alBlitBuffer = alsa_blitbuffer; |
| 136 |
|
196 |
|
|
Lines 140-152
Link Here
|
| 140 |
return retval; |
200 |
return retval; |
| 141 |
} |
201 |
} |
| 142 |
|
202 |
|
| 143 |
ALboolean set_read_alsa( UNUSED(void *handle), |
203 |
ALboolean set_read_alsa( void *handle, |
| 144 |
UNUSED(ALuint *bufsiz), |
204 |
ALuint *bufsiz, |
| 145 |
UNUSED(ALenum *fmt), |
205 |
ALenum *fmt, |
| 146 |
UNUSED(ALuint *speed)) |
206 |
ALuint *speed) |
| 147 |
{ |
207 |
{ |
| 148 |
/* no capture support */ |
208 |
struct alsa_info *ai = handle; |
| 149 |
return AL_FALSE; |
209 |
snd_pcm_hw_params_t *setup; |
|
|
210 |
snd_pcm_uframes_t buffer_size, period_size; |
| 211 |
snd_pcm_t *phandle = 0; |
| 212 |
int err, dir; |
| 213 |
snd_output_t *out; |
| 214 |
|
| 215 |
if( (ai == NULL) || (ai->handle == NULL) ) |
| 216 |
return AL_FALSE; |
| 217 |
|
| 218 |
|
| 219 |
if (*fmt == AL_FORMAT_QUAD8_LOKI) |
| 220 |
*fmt = AL_FORMAT_STEREO8; |
| 221 |
if (*fmt == AL_FORMAT_QUAD16_LOKI) |
| 222 |
*fmt = AL_FORMAT_STEREO16; |
| 223 |
|
| 224 |
ai->channels = (unsigned int) _al_ALCHANNELS(*fmt); |
| 225 |
ai->format = (unsigned int) AL2ALSAFMT(*fmt); |
| 226 |
ai->speed = (unsigned int) *speed; |
| 227 |
ai->framesize = (unsigned int) FRAMESIZE(ai->format, ai->channels); |
| 228 |
ai->bufframesize= (snd_pcm_uframes_t) *bufsiz / ai->framesize * 4; |
| 229 |
ai->periods = 2; |
| 230 |
|
| 231 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 232 |
"alsa info (read):\n"\ |
| 233 |
" channels: %u\n"\ |
| 234 |
" format: %u\n"\ |
| 235 |
" speed: %u\n"\ |
| 236 |
" framesize: %u\n"\ |
| 237 |
" bufframesize: %u\n"\ |
| 238 |
" periods: %u", |
| 239 |
ai->channels, ai->format, ai->speed, ai->framesize, ai->bufframesize, ai->periods); |
| 240 |
|
| 241 |
phandle = ai->handle; |
| 242 |
snd_output_stdio_attach (&out, stderr, 0); |
| 243 |
|
| 244 |
snd_pcm_hw_params_alloca(&setup); |
| 245 |
err = snd_pcm_hw_params_any(phandle, setup); |
| 246 |
if(err < 0) |
| 247 |
{ |
| 248 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 249 |
"set_read_alsa: Could not query parameters: %s",snd_strerror(err)); |
| 250 |
|
| 251 |
return AL_FALSE; |
| 252 |
} |
| 253 |
|
| 254 |
/* set the interleaved read format */ |
| 255 |
err = snd_pcm_hw_params_set_access(phandle, setup, SND_PCM_ACCESS_RW_INTERLEAVED); |
| 256 |
if (err < 0) { |
| 257 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 258 |
"set_read_alsa: Could not set access type: %s",snd_strerror(err)); |
| 259 |
return AL_FALSE; |
| 260 |
} |
| 261 |
|
| 262 |
/* set format */ |
| 263 |
err = snd_pcm_hw_params_set_format(phandle, setup, ai->format); |
| 264 |
if(err < 0) |
| 265 |
{ |
| 266 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 267 |
"set_read_alsa: could not set format: %s",snd_strerror(err)); |
| 268 |
|
| 269 |
return AL_FALSE; |
| 270 |
} |
| 271 |
|
| 272 |
|
| 273 |
/* channels */ |
| 274 |
err = snd_pcm_hw_params_set_channels(phandle, setup, ai->channels); |
| 275 |
if(err < 0) |
| 276 |
{ |
| 277 |
#if (SND_LIB_MAJOR == 0) |
| 278 |
err = snd_pcm_hw_params_get_channels(setup); |
| 279 |
#else |
| 280 |
snd_pcm_hw_params_get_channels(setup, &err); |
| 281 |
#endif |
| 282 |
|
| 283 |
if (err != (int) (ai->channels)) { |
| 284 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 285 |
"set_read_alsa: could not set channels: %s",snd_strerror(err)); |
| 286 |
|
| 287 |
return AL_FALSE; |
| 288 |
} |
| 289 |
} |
| 290 |
|
| 291 |
|
| 292 |
/* sampling rate */ |
| 293 |
err = snd_pcm_hw_params_set_rate_near(phandle, setup, &ai->speed, NULL); |
| 294 |
if(err < 0) |
| 295 |
{ |
| 296 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 297 |
"set_read_alsa: could not set speed: %s",snd_strerror(err)); |
| 298 |
|
| 299 |
return AL_FALSE; |
| 300 |
} else if (err > 0) /* err is sampling rate if > 0 */ |
| 301 |
ai->speed = (unsigned int) err; |
| 302 |
|
| 303 |
|
| 304 |
/* Set number of periods. Periods used to be called fragments. */ |
| 305 |
err = snd_pcm_hw_params_set_periods(phandle, setup, ai->periods, 0); |
| 306 |
if (err < 0) { |
| 307 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 308 |
"set_read_alsa: %s\n", snd_strerror(err)); |
| 309 |
return AL_FALSE; |
| 310 |
} |
| 311 |
|
| 312 |
snd_pcm_hw_params_dump (setup, out); |
| 313 |
err = snd_pcm_hw_params_set_buffer_size(phandle, setup, ai->bufframesize); |
| 314 |
snd_pcm_hw_params_dump (setup, out); |
| 315 |
if (err < 0) { |
| 316 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 317 |
"set_read_alsa: %s, size: %d, speed: %d\n", |
| 318 |
snd_strerror(err), ai->bufframesize, ai->speed); |
| 319 |
return AL_FALSE; |
| 320 |
} |
| 321 |
|
| 322 |
#if (SND_LIB_MAJOR == 0) |
| 323 |
buffer_size = snd_pcm_hw_params_get_buffer_size(setup); |
| 324 |
period_size = snd_pcm_hw_params_get_period_size(setup, &dir); |
| 325 |
#else |
| 326 |
snd_pcm_hw_params_get_buffer_size(setup, &buffer_size); |
| 327 |
snd_pcm_hw_params_get_period_size(setup, &period_size, &dir); |
| 328 |
#endif |
| 329 |
|
| 330 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 331 |
"set_read_alsa (info): Buffersize = %i (%i)",buffer_size, *bufsiz); |
| 332 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 333 |
"set_read_alsa (info): Periodsize = %i", period_size); |
| 334 |
|
| 335 |
err = snd_pcm_hw_params(phandle, setup); |
| 336 |
if(err < 0) |
| 337 |
{ |
| 338 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 339 |
"set_read_alsa: %s\n", snd_strerror(err)); |
| 340 |
return AL_FALSE; |
| 341 |
} |
| 342 |
|
| 343 |
err = snd_pcm_prepare(phandle); |
| 344 |
if(err < 0) |
| 345 |
{ |
| 346 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 347 |
"set_read_alsa %s\n", snd_strerror(err)); |
| 348 |
return AL_FALSE; |
| 349 |
} |
| 350 |
|
| 351 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 352 |
"set_read_alsa: handle: %p, phandle: %p\n", handle, phandle); |
| 353 |
snd_output_close (out); |
| 354 |
ai->setup_read = 1; |
| 355 |
|
| 356 |
return AL_TRUE; |
| 150 |
} |
357 |
} |
| 151 |
|
358 |
|
| 152 |
ALboolean set_write_alsa(void *handle, |
359 |
ALboolean set_write_alsa(void *handle, |
|
Lines 159-212
Link Here
|
| 159 |
snd_pcm_uframes_t buffer_size, period_size; |
366 |
snd_pcm_uframes_t buffer_size, period_size; |
| 160 |
snd_pcm_t *phandle = 0; |
367 |
snd_pcm_t *phandle = 0; |
| 161 |
int err, dir; |
368 |
int err, dir; |
|
|
369 |
snd_output_t *out; |
| 162 |
|
370 |
|
| 163 |
if( (ai == NULL) || (ai->handle == NULL) ) |
371 |
if( (ai == NULL) || (ai->handle == NULL) ) |
| 164 |
return AL_FALSE; |
372 |
return AL_FALSE; |
| 165 |
|
373 |
|
| 166 |
|
374 |
|
| 167 |
ai->channels = (unsigned int) _al_ALCHANNELS(*fmt); |
375 |
ai->channels = (unsigned int) _al_ALCHANNELS(*fmt); |
| 168 |
ai->format = (unsigned int) AL2ALSAFMT(*fmt); |
376 |
ai->format = (unsigned int) AL2ALSAFMT(*fmt); |
| 169 |
ai->speed = (unsigned int) *speed; |
377 |
ai->speed = (unsigned int) *speed; |
| 170 |
ai->framesize = (unsigned int) FRAMESIZE(ai->format, ai->channels); |
378 |
ai->framesize = (unsigned int) FRAMESIZE(ai->format, ai->channels); |
| 171 |
ai->bufframesize= (snd_pcm_uframes_t) *bufsiz / ai->framesize * 4; |
379 |
ai->bufframesize= (snd_pcm_uframes_t) *bufsiz / ai->framesize * 4; |
| 172 |
ai->periods = 2; |
380 |
ai->periods = 2; |
| 173 |
|
381 |
|
| 174 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
382 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 175 |
"alsa info:\n"\ |
383 |
"alsa info (write):\n"\ |
| 176 |
" channels: %u\n"\ |
384 |
" channels: %u\n"\ |
| 177 |
" format: %u\n"\ |
385 |
" format: %u\n"\ |
| 178 |
" speed: %u\n"\ |
386 |
" speed: %u\n"\ |
| 179 |
" framesize: %u\n"\ |
387 |
" framesize: %u\n"\ |
| 180 |
" bufframesize: %u\n"\ |
388 |
" bufframesize: %u\n"\ |
| 181 |
" periods: %u", |
389 |
" periods: %u", |
| 182 |
ai->channels, ai->format, ai->speed, ai->framesize, ai->bufframesize, ai->periods); |
390 |
ai->channels, ai->format, ai->speed, ai->framesize, ai->bufframesize, ai->periods); |
| 183 |
|
391 |
|
| 184 |
phandle = ai->handle; |
392 |
phandle = ai->handle; |
|
|
393 |
snd_output_stdio_attach (&out, stderr, 0); |
| 185 |
|
394 |
|
| 186 |
snd_pcm_hw_params_alloca(&setup); |
395 |
snd_pcm_hw_params_alloca(&setup); |
| 187 |
err = snd_pcm_hw_params_any(phandle, setup); |
396 |
err = snd_pcm_hw_params_any(phandle, setup); |
| 188 |
if(err < 0) |
397 |
if(err < 0) |
| 189 |
{ |
398 |
{ |
| 190 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
399 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 191 |
"set_write_alsa: Could not query parameters: %s",snd_strerror(err)); |
400 |
"set_write_alsa: Could not query parameters: %s",snd_strerror(err)); |
| 192 |
|
401 |
|
| 193 |
return AL_FALSE; |
402 |
return AL_FALSE; |
| 194 |
} |
403 |
} |
| 195 |
|
404 |
|
| 196 |
/* set the interleaved read format */ |
405 |
/* set the interleaved write format */ |
| 197 |
err = snd_pcm_hw_params_set_access(phandle, setup, SND_PCM_ACCESS_RW_INTERLEAVED); |
406 |
err = snd_pcm_hw_params_set_access(phandle, setup, SND_PCM_ACCESS_RW_INTERLEAVED); |
| 198 |
if (err < 0) { |
407 |
if (err < 0) { |
| 199 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
408 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 200 |
"set_write_alsa: Could not set access type: %s",snd_strerror(err)); |
409 |
"set_write_alsa: Could not set access type: %s",snd_strerror(err)); |
| 201 |
return AL_FALSE; |
410 |
return AL_FALSE; |
| 202 |
} |
411 |
} |
| 203 |
|
412 |
|
| 204 |
/* set format */ |
413 |
/* set format */ |
| 205 |
err = snd_pcm_hw_params_set_format(phandle, setup, ai->format); |
414 |
err = snd_pcm_hw_params_set_format(phandle, setup, ai->format); |
| 206 |
if(err < 0) |
415 |
if(err < 0) |
| 207 |
{ |
416 |
{ |
| 208 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
417 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 209 |
"set_write_alsa: could not set format: %s",snd_strerror(err)); |
418 |
"set_write_alsa: could not set format: %s",snd_strerror(err)); |
| 210 |
|
419 |
|
| 211 |
return AL_FALSE; |
420 |
return AL_FALSE; |
| 212 |
} |
421 |
} |
|
Lines 216-231
Link Here
|
| 216 |
err = snd_pcm_hw_params_set_channels(phandle, setup, ai->channels); |
425 |
err = snd_pcm_hw_params_set_channels(phandle, setup, ai->channels); |
| 217 |
if(err < 0) |
426 |
if(err < 0) |
| 218 |
{ |
427 |
{ |
|
|
428 |
#if (SND_LIB_MAJOR == 0) |
| 429 |
err = snd_pcm_hw_params_get_channels(setup); |
| 430 |
#else |
| 431 |
snd_pcm_hw_params_get_channels(setup, &err); |
| 432 |
#endif |
| 219 |
|
433 |
|
| 220 |
#if (SND_LIB_MAJOR == 0) |
434 |
if (err!= (int) (ai->channels)) { |
| 221 |
err = snd_pcm_hw_params_get_channels(setup); |
|
|
| 222 |
#else |
| 223 |
snd_pcm_hw_params_get_channels(setup, &err); |
| 224 |
#endif |
| 225 |
|
| 226 |
if(err!= (int) (ai->channels)) { |
| 227 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
435 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 228 |
"set_write_alsa: could not set channels: %s",snd_strerror(err)); |
436 |
"set_write_alsa: could not set channels: %s",snd_strerror(err)); |
| 229 |
|
437 |
|
| 230 |
return AL_FALSE; |
438 |
return AL_FALSE; |
| 231 |
} |
439 |
} |
|
Lines 233-283
Link Here
|
| 233 |
|
441 |
|
| 234 |
|
442 |
|
| 235 |
/* sampling rate */ |
443 |
/* sampling rate */ |
| 236 |
err = snd_pcm_hw_params_set_rate_near(phandle, setup, ai->speed, NULL); |
444 |
err = snd_pcm_hw_params_set_rate_near(phandle, setup, &ai->speed, NULL); |
| 237 |
if(err < 0) |
445 |
if(err < 0) |
| 238 |
{ |
446 |
{ |
| 239 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
447 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 240 |
"set_write_alsa: could not set speed: %s",snd_strerror(err)); |
448 |
"set_write_alsa: could not set speed: %s",snd_strerror(err)); |
| 241 |
|
449 |
|
| 242 |
return AL_FALSE; |
450 |
return AL_FALSE; |
| 243 |
} |
451 |
} else if (err > 0) /* err is sampling rate if > 0 */ |
| 244 |
/* err is sampling rate if >= 0 */ |
452 |
ai->speed = (unsigned int) err; |
| 245 |
ai->speed = (unsigned int) err; |
|
|
| 246 |
|
453 |
|
| 247 |
|
454 |
|
| 248 |
/* Set number of periods. Periods used to be called fragments. */ |
455 |
/* Set number of periods. Periods used to be called fragments. */ |
| 249 |
err = snd_pcm_hw_params_set_periods(phandle, setup, ai->periods, 0); |
456 |
err = snd_pcm_hw_params_set_periods(phandle, setup, ai->periods, 0); |
| 250 |
if (err < 0) { |
457 |
if (err < 0) { |
| 251 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
458 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 252 |
"set_write_alsa: %s\n", snd_strerror(err)); |
459 |
"set_write_alsa: %s\n", snd_strerror(err)); |
| 253 |
return AL_FALSE; |
460 |
return AL_FALSE; |
| 254 |
} |
461 |
} |
| 255 |
|
462 |
|
| 256 |
err = snd_pcm_hw_params_set_buffer_size(phandle, setup, ai->bufframesize); |
463 |
snd_pcm_hw_params_dump (setup, out); |
| 257 |
if (err < 0) { |
464 |
err = snd_pcm_hw_params_set_buffer_size(phandle, setup, ai->bufframesize); |
| 258 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
465 |
snd_pcm_hw_params_dump (setup, out); |
| 259 |
"set_write_alsa: %s\n", snd_strerror(err)); |
466 |
if (err < 0) { |
|
|
467 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 468 |
"set_write_alsa: %s, size: %d, speed: %d\n", |
| 469 |
snd_strerror(err), ai->bufframesize, ai->speed); |
| 260 |
return AL_FALSE; |
470 |
return AL_FALSE; |
| 261 |
} |
471 |
} |
|
|
472 |
|
| 473 |
#if (SND_LIB_MAJOR == 0) |
| 474 |
buffer_size = snd_pcm_hw_params_get_buffer_size(setup); |
| 475 |
period_size = snd_pcm_hw_params_get_period_size(setup, &dir); |
| 476 |
#else |
| 477 |
snd_pcm_hw_params_get_buffer_size(setup, &buffer_size); |
| 478 |
snd_pcm_hw_params_get_period_size(setup, &period_size, &dir); |
| 479 |
#endif |
| 262 |
|
480 |
|
| 263 |
#if (SND_LIB_MAJOR == 0) |
|
|
| 264 |
buffer_size = snd_pcm_hw_params_get_buffer_size(setup); |
| 265 |
period_size = snd_pcm_hw_params_get_period_size(setup, &dir); |
| 266 |
#else |
| 267 |
snd_pcm_hw_params_get_buffer_size(setup, &buffer_size); |
| 268 |
snd_pcm_hw_params_get_period_size(setup, &period_size, &dir); |
| 269 |
#endif |
| 270 |
|
| 271 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
481 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 272 |
"set_write_alsa (info): Buffersize = %i (%i)",buffer_size, *bufsiz); |
482 |
"set_write_alsa (info): Buffersize = %i (%i)",buffer_size, *bufsiz); |
| 273 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
483 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 274 |
"set_write_alsa (info): Periodsize = %i", period_size); |
484 |
"set_write_alsa (info): Periodsize = %i", period_size); |
| 275 |
|
485 |
|
| 276 |
err = snd_pcm_hw_params(phandle, setup); |
486 |
err = snd_pcm_hw_params(phandle, setup); |
| 277 |
if(err < 0) |
487 |
if(err < 0) |
| 278 |
{ |
488 |
{ |
| 279 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
489 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 280 |
"set_alsa: %s\n", snd_strerror(err)); |
490 |
"set_alsa: %s\n", snd_strerror(err)); |
| 281 |
return AL_FALSE; |
491 |
return AL_FALSE; |
| 282 |
} |
492 |
} |
| 283 |
|
493 |
|
|
Lines 285-294
Link Here
|
| 285 |
if(err < 0) |
495 |
if(err < 0) |
| 286 |
{ |
496 |
{ |
| 287 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
497 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 288 |
"set_alsa %s\n", snd_strerror(err)); |
498 |
"set_alsa %s\n", snd_strerror(err)); |
| 289 |
return AL_FALSE; |
499 |
return AL_FALSE; |
| 290 |
} |
500 |
} |
| 291 |
|
501 |
|
|
|
502 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 503 |
"set_write_alsa: handle: %p, phandle: %p\n", handle, phandle); |
| 504 |
snd_output_close (out); |
| 505 |
ai->setup_write = 1; |
| 506 |
|
| 292 |
return AL_TRUE; |
507 |
return AL_TRUE; |
| 293 |
} |
508 |
} |
| 294 |
|
509 |
|
|
Lines 300-315
Link Here
|
| 300 |
int data_len = bytes; |
515 |
int data_len = bytes; |
| 301 |
int channels = 0; |
516 |
int channels = 0; |
| 302 |
int err; |
517 |
int err; |
| 303 |
snd_pcm_uframes_t frames; |
518 |
snd_pcm_uframes_t frames; |
| 304 |
|
519 |
|
| 305 |
if((ai == NULL) || (ai->handle == NULL)) |
520 |
if((ai == NULL) || (ai->handle == NULL) || (!ai->setup_write)) |
| 306 |
{ |
521 |
{ |
| 307 |
return; |
522 |
return; |
| 308 |
} |
523 |
} |
| 309 |
|
524 |
|
| 310 |
phandle = ai->handle; |
525 |
phandle = ai->handle; |
| 311 |
channels= ai->channels; |
526 |
channels= ai->channels; |
| 312 |
frames = (snd_pcm_uframes_t) bytes / ai->framesize; |
527 |
frames = (snd_pcm_uframes_t) bytes / ai->framesize; |
| 313 |
|
528 |
|
| 314 |
while(data_len > 0) |
529 |
while(data_len > 0) |
| 315 |
{ |
530 |
{ |
|
Lines 347-352
Link Here
|
| 347 |
|
562 |
|
| 348 |
return; |
563 |
return; |
| 349 |
} |
564 |
} |
|
|
565 |
|
| 566 |
/* capture data from the audio device */ |
| 567 |
ALsizei capture_alsa(void *handle, |
| 568 |
void *capture_buffer, |
| 569 |
int bufsize) |
| 570 |
{ |
| 571 |
struct alsa_info *ai = handle; |
| 572 |
snd_pcm_t *phandle = 0; |
| 573 |
char *pdata = capture_buffer; |
| 574 |
int ret; |
| 575 |
snd_pcm_uframes_t frames; |
| 576 |
|
| 577 |
if ((ai == NULL) || (ai->handle == NULL) || (!ai->setup_read)) |
| 578 |
return 0; |
| 579 |
|
| 580 |
phandle = ai->handle; |
| 581 |
frames = (snd_pcm_uframes_t) bufsize / ai->framesize; |
| 582 |
grab: |
| 583 |
|
| 584 |
_alDebug(ALD_MAXIMUS, __FILE__, __LINE__, |
| 585 |
"set_read_alsa: handle: %p, phandle: %p\n", handle, phandle); |
| 586 |
ret = snd_pcm_readi (phandle, pdata, frames); |
| 587 |
if (ret < 0) { |
| 588 |
fprintf(stderr, "Error, overrun: %d, trying to recover.\n", ret); |
| 589 |
ret = snd_pcm_prepare(phandle); |
| 590 |
if (ret < 0) |
| 591 |
fprintf(stderr, "Unable to recover: %d\n", ret); |
| 592 |
else |
| 593 |
goto grab; |
| 594 |
return 0; |
| 595 |
} else |
| 596 |
return ret * ai->framesize; |
| 597 |
} |
| 598 |
|
| 350 |
|
599 |
|
| 351 |
static int AL2ALSAFMT(ALenum format) { |
600 |
static int AL2ALSAFMT(ALenum format) { |
| 352 |
switch(format) { |
601 |
switch(format) { |