2 * OpenAL cross platform audio library
3 * Copyright (C) 1999-2007 by authors.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 * Or go to http://www.gnu.org/copyleft/lgpl.html
33 #include <alsa/asoundlib.h>
38 snd_pcm_format_t format
;
52 static void *alsa_handle
;
53 #define MAKE_FUNC(f) static typeof(f) * p##f
54 MAKE_FUNC(snd_strerror
);
55 MAKE_FUNC(snd_pcm_open
);
56 MAKE_FUNC(snd_pcm_close
);
57 MAKE_FUNC(snd_pcm_nonblock
);
58 MAKE_FUNC(snd_pcm_frames_to_bytes
);
59 MAKE_FUNC(snd_pcm_hw_params_malloc
);
60 MAKE_FUNC(snd_pcm_hw_params_free
);
61 MAKE_FUNC(snd_pcm_hw_params_any
);
62 MAKE_FUNC(snd_pcm_hw_params_set_access
);
63 MAKE_FUNC(snd_pcm_hw_params_set_format
);
64 MAKE_FUNC(snd_pcm_hw_params_set_channels
);
65 MAKE_FUNC(snd_pcm_hw_params_set_periods_near
);
66 MAKE_FUNC(snd_pcm_hw_params_set_rate_near
);
67 MAKE_FUNC(snd_pcm_hw_params_set_rate
);
68 MAKE_FUNC(snd_pcm_hw_params_set_buffer_size_near
);
69 MAKE_FUNC(snd_pcm_hw_params_set_buffer_size_min
);
70 MAKE_FUNC(snd_pcm_hw_params_get_access
);
71 MAKE_FUNC(snd_pcm_hw_params
);
72 MAKE_FUNC(snd_pcm_prepare
);
73 MAKE_FUNC(snd_pcm_start
);
74 MAKE_FUNC(snd_pcm_resume
);
75 MAKE_FUNC(snd_pcm_state
);
76 MAKE_FUNC(snd_pcm_avail_update
);
77 MAKE_FUNC(snd_pcm_areas_silence
);
78 MAKE_FUNC(snd_pcm_mmap_begin
);
79 MAKE_FUNC(snd_pcm_mmap_commit
);
80 MAKE_FUNC(snd_pcm_writei
);
81 MAKE_FUNC(snd_pcm_drain
);
82 MAKE_FUNC(snd_pcm_info_malloc
);
83 MAKE_FUNC(snd_pcm_info_free
);
84 MAKE_FUNC(snd_pcm_info_set_device
);
85 MAKE_FUNC(snd_pcm_info_set_subdevice
);
86 MAKE_FUNC(snd_pcm_info_set_stream
);
87 MAKE_FUNC(snd_pcm_info_get_name
);
88 MAKE_FUNC(snd_ctl_pcm_next_device
);
89 MAKE_FUNC(snd_ctl_pcm_info
);
90 MAKE_FUNC(snd_ctl_open
);
91 MAKE_FUNC(snd_ctl_close
);
92 MAKE_FUNC(snd_ctl_card_info_malloc
);
93 MAKE_FUNC(snd_ctl_card_info_free
);
94 MAKE_FUNC(snd_ctl_card_info
);
95 MAKE_FUNC(snd_ctl_card_info_get_name
);
96 MAKE_FUNC(snd_card_next
);
99 #define MAX_DEVICES 16
100 #define MAX_ALL_DEVICES 32
102 static DevMap allDevNameMap
[MAX_ALL_DEVICES
];
103 static ALCchar
*alsaDeviceList
[MAX_DEVICES
];
104 static ALCchar
*alsaCaptureDeviceList
[MAX_DEVICES
];
106 static int xrun_recovery(snd_pcm_t
*handle
, int err
)
110 err
= psnd_pcm_prepare(handle
);
112 AL_PRINT("prepare failed: %s\n", psnd_strerror(err
));
114 else if (err
== -ESTRPIPE
)
116 while ((err
= psnd_pcm_resume(handle
)) == -EAGAIN
)
117 Sleep(1); /* wait until the suspend flag is released */
120 err
= psnd_pcm_prepare(handle
);
122 AL_PRINT("prepare failed: %s\n", psnd_strerror(err
));
129 static ALuint
ALSAProc(ALvoid
*ptr
)
131 ALCdevice
*pDevice
= (ALCdevice
*)ptr
;
132 alsa_data
*data
= (alsa_data
*)pDevice
->ExtraData
;
133 const snd_pcm_channel_area_t
*areas
= NULL
;
134 snd_pcm_sframes_t avail
, commitres
;
135 snd_pcm_uframes_t offset
, frames
;
140 while(!data
->killNow
)
142 snd_pcm_state_t state
= psnd_pcm_state(data
->pcmHandle
);
143 if(state
== SND_PCM_STATE_XRUN
)
145 err
= xrun_recovery(data
->pcmHandle
, -EPIPE
);
148 AL_PRINT("XRUN recovery failed: %s\n", psnd_strerror(err
));
152 else if (state
== SND_PCM_STATE_SUSPENDED
)
154 err
= xrun_recovery(data
->pcmHandle
, -ESTRPIPE
);
157 AL_PRINT("SUSPEND recovery failed: %s\n", psnd_strerror(err
));
162 avail
= psnd_pcm_avail_update(data
->pcmHandle
);
165 err
= xrun_recovery(data
->pcmHandle
, avail
);
168 AL_PRINT("available update failed: %s\n", psnd_strerror(err
));
173 // make sure there's frames to process
176 if(state
!= SND_PCM_STATE_RUNNING
)
178 err
= psnd_pcm_start(data
->pcmHandle
);
181 err
= xrun_recovery(data
->pcmHandle
, err
);
184 AL_PRINT("start failed: %s\n", psnd_strerror(err
));
193 // it is possible that contiguous areas are smaller, thus we use a loop
198 err
= psnd_pcm_mmap_begin(data
->pcmHandle
, &areas
, &offset
, &frames
);
201 err
= xrun_recovery(data
->pcmHandle
, err
);
203 AL_PRINT("mmap begin error: %s\n", psnd_strerror(err
));
207 SuspendContext(NULL
);
208 WritePtr
= (char*)areas
->addr
+ (offset
* areas
->step
/ 8);
209 WriteCnt
= psnd_pcm_frames_to_bytes(data
->pcmHandle
, frames
);
210 aluMixData(pDevice
->Context
, WritePtr
, WriteCnt
, pDevice
->Format
);
211 ProcessContext(NULL
);
213 commitres
= psnd_pcm_mmap_commit(data
->pcmHandle
, offset
, frames
);
214 if (commitres
< 0 || (commitres
-frames
) != 0)
216 AL_PRINT("mmap commit error: %s\n",
217 psnd_strerror(commitres
>= 0 ? -EPIPE
: commitres
));
228 static ALuint
ALSANoMMapProc(ALvoid
*ptr
)
230 ALCdevice
*pDevice
= (ALCdevice
*)ptr
;
231 alsa_data
*data
= (alsa_data
*)pDevice
->ExtraData
;
232 snd_pcm_sframes_t avail
;
235 while(!data
->killNow
)
237 SuspendContext(NULL
);
238 aluMixData(pDevice
->Context
, data
->buffer
, data
->size
, pDevice
->Format
);
239 ProcessContext(NULL
);
241 WritePtr
= data
->buffer
;
242 avail
= (snd_pcm_uframes_t
)data
->size
/ psnd_pcm_frames_to_bytes(data
->pcmHandle
, 1);
245 int ret
= psnd_pcm_writei(data
->pcmHandle
, WritePtr
, avail
);
252 ret
= psnd_pcm_resume(data
->pcmHandle
);
253 } while(ret
== -EAGAIN
);
260 WritePtr
+= psnd_pcm_frames_to_bytes(data
->pcmHandle
, ret
);
267 ret
= psnd_pcm_prepare(data
->pcmHandle
);
277 static void fill_silence(snd_pcm_t
*pcmHandle
, snd_pcm_format_t alsaFormat
, int channels
)
279 const snd_pcm_channel_area_t
*areas
= NULL
;
280 snd_pcm_sframes_t avail
, commitres
;
281 snd_pcm_uframes_t offset
, frames
;
284 avail
= psnd_pcm_avail_update(pcmHandle
);
287 AL_PRINT("available update failed: %s\n", psnd_strerror(avail
));
291 // it is possible that contiguous areas are smaller, thus we use a loop
296 err
= psnd_pcm_mmap_begin(pcmHandle
, &areas
, &offset
, &frames
);
299 AL_PRINT("mmap begin error: %s\n", psnd_strerror(err
));
303 psnd_pcm_areas_silence(areas
, offset
, channels
, frames
, alsaFormat
);
305 commitres
= psnd_pcm_mmap_commit(pcmHandle
, offset
, frames
);
306 if (commitres
< 0 || (commitres
-frames
) != 0)
308 AL_PRINT("mmap commit error: %s\n",
309 psnd_strerror(commitres
>= 0 ? -EPIPE
: commitres
));
317 static ALCboolean
alsa_open_playback(ALCdevice
*device
, const ALCchar
*deviceName
)
319 snd_pcm_uframes_t bufferSizeInFrames
;
320 snd_pcm_hw_params_t
*p
= NULL
;
321 snd_pcm_access_t access
;
322 unsigned int periods
;
331 strncpy(driver
, GetConfigValue("alsa", "device", "default"), sizeof(driver
)-1);
332 driver
[sizeof(driver
)-1] = 0;
337 for(idx
= 0;idx
< MAX_ALL_DEVICES
;idx
++)
339 if(allDevNameMap
[idx
].name
&&
340 strcmp(deviceName
, allDevNameMap
[idx
].name
) == 0)
342 device
->szDeviceName
= allDevNameMap
[idx
].name
;
344 sprintf(driver
, "hw:%d,%d", allDevNameMap
[idx
].card
, allDevNameMap
[idx
].dev
);
348 for(idx
= 0;idx
< MAX_DEVICES
;idx
++)
350 if(alsaDeviceList
[idx
] &&
351 strcmp(deviceName
, alsaDeviceList
[idx
]) == 0)
353 device
->szDeviceName
= alsaDeviceList
[idx
];
355 sprintf(driver
, "hw:%zd,0", idx
-1);
362 device
->szDeviceName
= alsaDeviceList
[0];
365 data
= (alsa_data
*)calloc(1, sizeof(alsa_data
));
367 i
= psnd_pcm_open(&data
->pcmHandle
, driver
, SND_PCM_STREAM_PLAYBACK
, SND_PCM_NONBLOCK
);
371 i
= psnd_pcm_open(&data
->pcmHandle
, driver
, SND_PCM_STREAM_PLAYBACK
, SND_PCM_NONBLOCK
);
375 i
= psnd_pcm_nonblock(data
->pcmHandle
, 0);
377 psnd_pcm_close(data
->pcmHandle
);
382 AL_PRINT("Could not open playback device '%s': %s\n", driver
, psnd_strerror(i
));
386 switch(aluBytesFromFormat(device
->Format
))
389 data
->format
= SND_PCM_FORMAT_U8
;
392 data
->format
= SND_PCM_FORMAT_S16
;
395 data
->format
= SND_PCM_FORMAT_UNKNOWN
;
396 AL_PRINT("Unknown format?! %x\n", device
->Format
);
399 periods
= GetConfigValueInt("alsa", "periods", 4);
400 if((int)periods
<= 0)
402 bufferSizeInFrames
= device
->UpdateFreq
/ periods
;
404 psnd_pcm_hw_params_malloc(&p
);
405 #define ok(func, str) (i=(func),((i<0)?(err=(str)),0:1))
406 /* start with the largest configuration space possible */
407 if(!(ok(psnd_pcm_hw_params_any(data
->pcmHandle
, p
), "any") &&
408 /* set interleaved access */
409 (ok(psnd_pcm_hw_params_set_access(data
->pcmHandle
, p
, SND_PCM_ACCESS_MMAP_INTERLEAVED
), "set access") ||
410 ok(psnd_pcm_hw_params_set_access(data
->pcmHandle
, p
, SND_PCM_ACCESS_RW_INTERLEAVED
), "set access")) &&
411 /* set format (implicitly sets sample bits) */
412 ok(psnd_pcm_hw_params_set_format(data
->pcmHandle
, p
, data
->format
), "set format") &&
413 /* set channels (implicitly sets frame bits) */
414 ok(psnd_pcm_hw_params_set_channels(data
->pcmHandle
, p
, device
->Channels
), "set channels") &&
415 /* set periods (implicitly constrains period/buffer parameters) */
416 ok(psnd_pcm_hw_params_set_periods_near(data
->pcmHandle
, p
, &periods
, NULL
), "set periods near") &&
417 /* set rate (implicitly constrains period/buffer parameters) */
418 ok(psnd_pcm_hw_params_set_rate_near(data
->pcmHandle
, p
, &device
->Frequency
, NULL
), "set rate near") &&
419 /* set buffer size in frame units (implicitly sets period size/bytes/time and buffer time/bytes) */
420 ok(psnd_pcm_hw_params_set_buffer_size_near(data
->pcmHandle
, p
, &bufferSizeInFrames
), "set buffer size near") &&
421 /* install and prepare hardware configuration */
422 ok(psnd_pcm_hw_params(data
->pcmHandle
, p
), "set params")))
424 AL_PRINT("%s failed: %s\n", err
, psnd_strerror(i
));
425 psnd_pcm_hw_params_free(p
);
426 psnd_pcm_close(data
->pcmHandle
);
432 if((i
=psnd_pcm_hw_params_get_access(p
, &access
)) < 0)
434 AL_PRINT("get_access failed: %s\n", psnd_strerror(i
));
435 psnd_pcm_hw_params_free(p
);
436 psnd_pcm_close(data
->pcmHandle
);
441 psnd_pcm_hw_params_free(p
);
443 device
->MaxNoOfSources
= 256;
444 device
->UpdateFreq
= bufferSizeInFrames
;
446 data
->size
= psnd_pcm_frames_to_bytes(data
->pcmHandle
, device
->UpdateFreq
);
447 if(access
== SND_PCM_ACCESS_RW_INTERLEAVED
)
449 data
->buffer
= malloc(data
->size
);
452 AL_PRINT("buffer malloc failed\n");
453 psnd_pcm_close(data
->pcmHandle
);
460 i
= psnd_pcm_prepare(data
->pcmHandle
);
463 AL_PRINT("prepare error: %s\n", psnd_strerror(i
));
464 psnd_pcm_close(data
->pcmHandle
);
470 fill_silence(data
->pcmHandle
, data
->format
, device
->Channels
);
472 i
= psnd_pcm_start(data
->pcmHandle
);
475 AL_PRINT("start error: %s\n", psnd_strerror(i
));
476 psnd_pcm_close(data
->pcmHandle
);
483 device
->ExtraData
= data
;
484 if(access
== SND_PCM_ACCESS_RW_INTERLEAVED
)
485 data
->thread
= StartThread(ALSANoMMapProc
, device
);
487 data
->thread
= StartThread(ALSAProc
, device
);
488 if(data
->thread
== NULL
)
490 psnd_pcm_close(data
->pcmHandle
);
491 device
->ExtraData
= NULL
;
500 static void alsa_close_playback(ALCdevice
*device
)
502 alsa_data
*data
= (alsa_data
*)device
->ExtraData
;
504 StopThread(data
->thread
);
505 psnd_pcm_close(data
->pcmHandle
);
509 device
->ExtraData
= NULL
;
513 static ALCboolean
alsa_open_capture(ALCdevice
*pDevice
, const ALCchar
*deviceName
, ALCuint frequency
, ALCenum format
, ALCsizei SampleSize
)
515 snd_pcm_format_t alsaFormat
;
516 snd_pcm_hw_params_t
*p
;
517 unsigned int periods
= 4;
518 snd_pcm_uframes_t bufferSizeInFrames
;
527 strncpy(driver
, GetConfigValue("alsa", "capture", "default"), sizeof(driver
)-1);
528 driver
[sizeof(driver
)-1] = 0;
533 for(idx
= 0;idx
< MAX_DEVICES
;idx
++)
535 if(alsaCaptureDeviceList
[idx
] &&
536 strcmp(deviceName
, alsaCaptureDeviceList
[idx
]) == 0)
538 pDevice
->szDeviceName
= alsaCaptureDeviceList
[idx
];
540 sprintf(driver
, "hw:%zd,0", idx
-1);
547 pDevice
->szDeviceName
= alsaCaptureDeviceList
[0];
550 data
= (alsa_data
*)calloc(1, sizeof(alsa_data
));
552 i
= psnd_pcm_open(&data
->pcmHandle
, driver
, SND_PCM_STREAM_CAPTURE
, SND_PCM_NONBLOCK
);
556 i
= psnd_pcm_open(&data
->pcmHandle
, driver
, SND_PCM_STREAM_CAPTURE
, SND_PCM_NONBLOCK
);
560 i
= psnd_pcm_nonblock(data
->pcmHandle
, 0);
562 psnd_pcm_close(data
->pcmHandle
);
567 AL_PRINT("Could not open capture device '%s': %s\n", driver
, psnd_strerror(i
));
571 switch(aluBytesFromFormat(format
))
574 alsaFormat
= SND_PCM_FORMAT_U8
;
577 alsaFormat
= SND_PCM_FORMAT_S16
;
580 alsaFormat
= SND_PCM_FORMAT_UNKNOWN
;
581 AL_PRINT("Unknown format?! %x\n", format
);
584 bufferSizeInFrames
= SampleSize
/ periods
;
586 psnd_pcm_hw_params_malloc(&p
);
587 #define ok(func, str) (i=(func),((i<0)?(err=(str)),0:1))
588 /* start with the largest configuration space possible */
589 if(!(ok(psnd_pcm_hw_params_any(data
->pcmHandle
, p
), "any") &&
590 /* set interleaved access */
591 ok(psnd_pcm_hw_params_set_access(data
->pcmHandle
, p
, SND_PCM_ACCESS_MMAP_INTERLEAVED
), "set access") &&
592 /* set format (implicitly sets sample bits) */
593 ok(psnd_pcm_hw_params_set_format(data
->pcmHandle
, p
, alsaFormat
), "set format") &&
594 /* set channels (implicitly sets frame bits) */
595 ok(psnd_pcm_hw_params_set_channels(data
->pcmHandle
, p
, pDevice
->Channels
), "set channels") &&
596 /* set periods (implicitly constrains period/buffer parameters) */
597 ok(psnd_pcm_hw_params_set_periods_near(data
->pcmHandle
, p
, &periods
, NULL
), "set periods near") &&
598 /* set rate (implicitly constrains period/buffer parameters) */
599 ok(psnd_pcm_hw_params_set_rate(data
->pcmHandle
, p
, frequency
, 0), "set rate") &&
600 /* set buffer size in frame units (implicitly sets period size/bytes/time and buffer time/bytes) */
601 ok(psnd_pcm_hw_params_set_buffer_size_min(data
->pcmHandle
, p
, &bufferSizeInFrames
), "set buffer size min") &&
602 /* install and prepare hardware configuration */
603 ok(psnd_pcm_hw_params(data
->pcmHandle
, p
), "set params")))
605 AL_PRINT("%s failed: %s\n", err
, psnd_strerror(i
));
606 psnd_pcm_hw_params_free(p
);
607 psnd_pcm_close(data
->pcmHandle
);
612 psnd_pcm_hw_params_free(p
);
614 i
= psnd_pcm_prepare(data
->pcmHandle
);
617 AL_PRINT("prepare error: %s\n", psnd_strerror(i
));
618 psnd_pcm_close(data
->pcmHandle
);
623 pDevice
->ExtraData
= data
;
627 static void alsa_close_capture(ALCdevice
*pDevice
)
629 alsa_data
*data
= (alsa_data
*)pDevice
->ExtraData
;
630 psnd_pcm_close(data
->pcmHandle
);
633 pDevice
->ExtraData
= NULL
;
636 static void alsa_start_capture(ALCdevice
*pDevice
)
638 alsa_data
*data
= (alsa_data
*)pDevice
->ExtraData
;
639 psnd_pcm_start(data
->pcmHandle
);
642 static void alsa_stop_capture(ALCdevice
*pDevice
)
644 alsa_data
*data
= (alsa_data
*)pDevice
->ExtraData
;
645 psnd_pcm_drain(data
->pcmHandle
);
648 static void alsa_capture_samples(ALCdevice
*pDevice
, ALCvoid
*pBuffer
, ALCuint lSamples
)
650 alsa_data
*data
= (alsa_data
*)pDevice
->ExtraData
;
651 const snd_pcm_channel_area_t
*areas
= NULL
;
652 snd_pcm_sframes_t frames
, commitres
;
653 snd_pcm_uframes_t size
, offset
;
656 frames
= psnd_pcm_avail_update(data
->pcmHandle
);
659 err
= xrun_recovery(data
->pcmHandle
, frames
);
661 AL_PRINT("available update failed: %s\n", psnd_strerror(err
));
663 frames
= psnd_pcm_avail_update(data
->pcmHandle
);
665 if (frames
< (snd_pcm_sframes_t
)lSamples
)
667 SetALCError(ALC_INVALID_VALUE
);
671 // it is possible that contiguous areas are smaller, thus we use a loop
678 err
= psnd_pcm_mmap_begin(data
->pcmHandle
, &areas
, &offset
, &size
);
681 err
= xrun_recovery(data
->pcmHandle
, err
);
684 AL_PRINT("mmap begin error: %s\n", psnd_strerror(err
));
690 Pointer
= (char*)areas
->addr
+ (offset
* areas
->step
/ 8);
691 Count
= size
* pDevice
->FrameSize
;
693 memcpy(pBuffer
, Pointer
, Count
);
694 pBuffer
= (char*)pBuffer
+ Count
;
696 commitres
= psnd_pcm_mmap_commit(data
->pcmHandle
, offset
, size
);
697 if (commitres
< 0 || (commitres
-size
) != 0)
699 AL_PRINT("mmap commit error: %s\n",
700 psnd_strerror(commitres
>= 0 ? -EPIPE
: commitres
));
708 static ALCuint
alsa_available_samples(ALCdevice
*pDevice
)
710 alsa_data
*data
= (alsa_data
*)pDevice
->ExtraData
;
711 snd_pcm_sframes_t frames
= psnd_pcm_avail_update(data
->pcmHandle
);
714 int err
= xrun_recovery(data
->pcmHandle
, frames
);
716 AL_PRINT("available update failed: %s\n", psnd_strerror(err
));
718 frames
= psnd_pcm_avail_update(data
->pcmHandle
);
719 if(frames
< 0) /* ew.. */
720 SetALCError(ALC_INVALID_DEVICE
);
722 return max(frames
, 0);
726 BackendFuncs alsa_funcs
= {
733 alsa_capture_samples
,
734 alsa_available_samples
737 void alc_alsa_init(BackendFuncs
*func_list
)
740 int card
, err
, dev
, idx
= 1;
741 snd_ctl_card_info_t
*info
;
742 snd_pcm_info_t
*pcminfo
;
743 snd_pcm_stream_t stream
= SND_PCM_STREAM_PLAYBACK
;
747 *func_list
= alsa_funcs
;
750 alsa_handle
= dlopen("libasound.so.2", RTLD_NOW
);
755 #define LOAD_FUNC(f) do { \
756 p##f = (typeof(f)*)dlsym(alsa_handle, #f); \
757 if((str=dlerror()) != NULL) \
759 dlclose(alsa_handle); \
760 alsa_handle = NULL; \
761 AL_PRINT("Could not load %s from libasound.so.2: %s\n", #f, str); \
767 alsa_handle
= 0xDEADBEEF;
768 #define LOAD_FUNC(f) p##f = f
771 LOAD_FUNC(snd_strerror
);
772 LOAD_FUNC(snd_pcm_open
);
773 LOAD_FUNC(snd_pcm_close
);
774 LOAD_FUNC(snd_pcm_nonblock
);
775 LOAD_FUNC(snd_pcm_frames_to_bytes
);
776 LOAD_FUNC(snd_pcm_hw_params_malloc
);
777 LOAD_FUNC(snd_pcm_hw_params_free
);
778 LOAD_FUNC(snd_pcm_hw_params_any
);
779 LOAD_FUNC(snd_pcm_hw_params_set_access
);
780 LOAD_FUNC(snd_pcm_hw_params_set_format
);
781 LOAD_FUNC(snd_pcm_hw_params_set_channels
);
782 LOAD_FUNC(snd_pcm_hw_params_set_periods_near
);
783 LOAD_FUNC(snd_pcm_hw_params_set_rate_near
);
784 LOAD_FUNC(snd_pcm_hw_params_set_rate
);
785 LOAD_FUNC(snd_pcm_hw_params_set_buffer_size_near
);
786 LOAD_FUNC(snd_pcm_hw_params_set_buffer_size_min
);
787 LOAD_FUNC(snd_pcm_hw_params_get_access
);
788 LOAD_FUNC(snd_pcm_hw_params
);
789 LOAD_FUNC(snd_pcm_prepare
);
790 LOAD_FUNC(snd_pcm_start
);
791 LOAD_FUNC(snd_pcm_resume
);
792 LOAD_FUNC(snd_pcm_state
);
793 LOAD_FUNC(snd_pcm_avail_update
);
794 LOAD_FUNC(snd_pcm_areas_silence
);
795 LOAD_FUNC(snd_pcm_mmap_begin
);
796 LOAD_FUNC(snd_pcm_mmap_commit
);
797 LOAD_FUNC(snd_pcm_writei
);
798 LOAD_FUNC(snd_pcm_drain
);
800 LOAD_FUNC(snd_pcm_info_malloc
);
801 LOAD_FUNC(snd_pcm_info_free
);
802 LOAD_FUNC(snd_pcm_info_set_device
);
803 LOAD_FUNC(snd_pcm_info_set_subdevice
);
804 LOAD_FUNC(snd_pcm_info_set_stream
);
805 LOAD_FUNC(snd_pcm_info_get_name
);
806 LOAD_FUNC(snd_ctl_pcm_next_device
);
807 LOAD_FUNC(snd_ctl_pcm_info
);
808 LOAD_FUNC(snd_ctl_open
);
809 LOAD_FUNC(snd_ctl_close
);
810 LOAD_FUNC(snd_ctl_card_info_malloc
);
811 LOAD_FUNC(snd_ctl_card_info_free
);
812 LOAD_FUNC(snd_ctl_card_info
);
813 LOAD_FUNC(snd_ctl_card_info_get_name
);
814 LOAD_FUNC(snd_card_next
);
818 psnd_ctl_card_info_malloc(&info
);
819 psnd_pcm_info_malloc(&pcminfo
);
822 if(psnd_card_next(&card
) < 0 || card
< 0)
823 AL_PRINT("no playback cards found...\n");
826 alsaDeviceList
[0] = AppendDeviceList("ALSA Software on default");
827 allDevNameMap
[0].name
= AppendAllDeviceList("ALSA Software on default");
831 sprintf(name
, "hw:%d", card
);
832 if ((err
= psnd_ctl_open(&handle
, name
, 0)) < 0) {
833 AL_PRINT("control open (%i): %s\n", card
, psnd_strerror(err
));
836 if ((err
= psnd_ctl_card_info(handle
, info
)) < 0) {
837 AL_PRINT("control hardware info (%i): %s\n", card
, psnd_strerror(err
));
838 psnd_ctl_close(handle
);
841 if(card
< MAX_DEVICES
-1) {
842 snprintf(name
, sizeof(name
), "ALSA Software on %s",
843 psnd_ctl_card_info_get_name(info
));
844 alsaDeviceList
[card
+1] = AppendDeviceList(name
);
848 while (idx
< MAX_ALL_DEVICES
) {
849 const char *cname
, *dname
;
851 if (psnd_ctl_pcm_next_device(handle
, &dev
)<0)
852 AL_PRINT("snd_ctl_pcm_next_device failed\n");
855 psnd_pcm_info_set_device(pcminfo
, dev
);
856 psnd_pcm_info_set_subdevice(pcminfo
, 0);
857 psnd_pcm_info_set_stream(pcminfo
, stream
);
858 if ((err
= psnd_ctl_pcm_info(handle
, pcminfo
)) < 0) {
860 AL_PRINT("control digital audio info (%i): %s\n", card
, psnd_strerror(err
));
864 cname
= psnd_ctl_card_info_get_name(info
);
865 dname
= psnd_pcm_info_get_name(pcminfo
);
866 snprintf(name
, sizeof(name
), "ALSA Software on %s [%s]",
868 allDevNameMap
[idx
].name
= AppendAllDeviceList(name
);
869 allDevNameMap
[idx
].card
= card
;
870 allDevNameMap
[idx
].dev
= dev
;
873 psnd_ctl_close(handle
);
875 if(psnd_card_next(&card
) < 0) {
876 AL_PRINT("snd_card_next failed\n");
882 stream
= SND_PCM_STREAM_CAPTURE
;
885 if(psnd_card_next(&card
) < 0 || card
< 0) {
886 AL_PRINT("no capture cards found...\n");
887 psnd_pcm_info_free(pcminfo
);
888 psnd_ctl_card_info_free(info
);
892 alsaCaptureDeviceList
[0] = AppendCaptureDeviceList("ALSA Capture on default");
895 sprintf(name
, "hw:%d", card
);
897 if ((err
= psnd_ctl_open(&handle
, name
, 0)) < 0) {
898 AL_PRINT("control open (%i): %s\n", card
, psnd_strerror(err
));
900 if (err
>= 0 && (err
= psnd_ctl_card_info(handle
, info
)) < 0) {
901 AL_PRINT("control hardware info (%i): %s\n", card
, psnd_strerror(err
));
903 else if (err
>= 0 && card
< MAX_DEVICES
-1)
905 snprintf(name
, sizeof(name
), "ALSA Capture on %s",
906 psnd_ctl_card_info_get_name(info
));
907 alsaCaptureDeviceList
[card
+1] = AppendCaptureDeviceList(name
);
909 if(handle
) psnd_ctl_close(handle
);
910 if(psnd_card_next(&card
) < 0) {
911 AL_PRINT("snd_card_next failed\n");
915 psnd_pcm_info_free(pcminfo
);
916 psnd_ctl_card_info_free(info
);