Differenze tra le versioni di "Conoscere con le funzioni esterne di ALSA i dispositivi audio presenti nel sistema"
Da Gambas-it.org - Wikipedia.
(Creata pagina con 'Alcune funzioni esterne del API di ALSA consentono di conoscere quali sono le porte di entrata e di uscita dell'audio digitale delle schede audio presenti nel proprio sistema....') |
|||
Riga 3: | Riga 3: | ||
Mostriamo di segtuito qualche esempio: | Mostriamo di segtuito qualche esempio: | ||
− | Private Const SND_PCM_STREAM_PLAYBACK As Byte = 0 | + | Private Const SND_PCM_STREAM_PLAYBACK As Byte = 0 <FONT color=gray>' ''Playback stream''</font> |
Private Const ENOENT As Byte = 2 | Private Const ENOENT As Byte = 2 | ||
Private handlCtl As Pointer | Private handlCtl As Pointer | ||
Riga 10: | Riga 10: | ||
Library "libasound:2" | Library "libasound:2" | ||
− | ' int snd_card_next(int *card) | + | <FONT color=gray>' ''int snd_card_next(int *card)'' |
− | ' Try to determine the next card. | + | ' ''Try to determine the next card.''</font> |
Private Extern snd_card_next(cardI As Pointer) As Integer | Private Extern snd_card_next(cardI As Pointer) As Integer | ||
− | ' const char* snd_pcm_stream_name(snd_pcm_stream_t stream) | + | <FONT color=gray>' ''const char* snd_pcm_stream_name(snd_pcm_stream_t stream)'' |
− | ' Get name of PCM stream type | + | ' ''Get name of PCM stream type''</font> |
Private Extern snd_pcm_stream_name(streamI As Byte) As String | Private Extern snd_pcm_stream_name(streamI As Byte) As String | ||
− | ' int snd_ctl_open(snd_ctl_t **ctl, const char *name, int mode) | + | <FONT color=gray>' ''int snd_ctl_open(snd_ctl_t **ctl, const char *name, int mode)'' |
− | ' Opens a CTL. | + | ' ''Opens a CTL.''</font> |
Private Extern snd_ctl_open(ctlP As Pointer, name As String, mode As Integer) As Integer | Private Extern snd_ctl_open(ctlP As Pointer, name As String, mode As Integer) As Integer | ||
− | ' snd_ctl_card_info_malloc(ptr) | + | <FONT color=gray>' ''snd_ctl_card_info_malloc(ptr)'' |
− | ' Allocate an invalid snd_ctl_card_info_t using standard malloc | + | ' ''Allocate an invalid snd_ctl_card_info_t using standard malloc''</font> |
Private Extern snd_ctl_card_info_malloc(ptr As Pointer) | Private Extern snd_ctl_card_info_malloc(ptr As Pointer) | ||
− | ' int snd_ctl_card_info(snd_ctl_t *ctl, snd_ctl_card_info_t *info) | + | <FONT color=gray>' ''int snd_ctl_card_info(snd_ctl_t *ctl, snd_ctl_card_info_t *info) |
− | ' Get card related information. | + | ' ''Get card related information.''</font> |
Private Extern snd_ctl_card_info(ctlP As Pointer, infoP As Pointer) As Integer | Private Extern snd_ctl_card_info(ctlP As Pointer, infoP As Pointer) As Integer | ||
− | ' void snd_ctl_close(snd_ctl_t *ctl) | + | <FONT color=gray>' ''void snd_ctl_close(snd_ctl_t *ctl) |
− | ' | + | ' ''Closes a ctl.''</font> |
Private Extern snd_ctl_close(ctlP As Pointer) | Private Extern snd_ctl_close(ctlP As Pointer) | ||
− | ' int snd_ctl_pcm_next_device(snd_ctl_t *ctl, int *device) | + | <FONT color=gray>' ''int snd_ctl_pcm_next_device(snd_ctl_t *ctl, int *device) |
− | ' Get Next PCM device number. | + | ' ''Get Next PCM device number.''</font> |
Private Extern snd_ctl_pcm_next_device(ctlP As Pointer, device As Pointer) As Integer | Private Extern snd_ctl_pcm_next_device(ctlP As Pointer, device As Pointer) As Integer | ||
− | ' int snd_pcm_info_malloc(snd_pcm_info_t ** ptr) | + | <FONT color=gray>' ''int snd_pcm_info_malloc(snd_pcm_info_t ** ptr) |
− | ' Allocate an invalid snd_pcm_info_t using standard malloc | + | ' ''Allocate an invalid snd_pcm_info_t using standard malloc.''</font> |
Private Extern snd_pcm_info_malloc(ptr As Pointer) As Integer | Private Extern snd_pcm_info_malloc(ptr As Pointer) As Integer | ||
− | ' void snd_pcm_info_set_device (snd_pcm_info_t *obj, unsigned int val) | + | <FONT color=gray>' ''void snd_pcm_info_set_device (snd_pcm_info_t *obj, unsigned int val) |
− | ' Set wanted device inside a PCM info container | + | ' ''Set wanted device inside a PCM info container.''</font> |
Private Extern snd_pcm_info_set_device(pcminfoP As Pointer, ValI As Integer) | Private Extern snd_pcm_info_set_device(pcminfoP As Pointer, ValI As Integer) | ||
− | ' void snd_pcm_info_set_subdevice(snd_pcm_info_t *obj, unsigned int val) | + | <FONT color=gray>' ''void snd_pcm_info_set_subdevice(snd_pcm_info_t *obj, unsigned int val) |
− | ' Set wanted subdevice inside a PCM info container | + | ' ''Set wanted subdevice inside a PCM info container.''</font> |
Private Extern snd_pcm_info_set_subdevice(pcminfoP As Pointer, ValI As Integer) | Private Extern snd_pcm_info_set_subdevice(pcminfoP As Pointer, ValI As Integer) | ||
− | ' void snd_pcm_info_set_stream(snd_pcm_info_t *obj, snd_pcm_stream_t val) | + | <FONT color=gray>' ''void snd_pcm_info_set_stream(snd_pcm_info_t *obj, snd_pcm_stream_t val) |
− | ' Set wanted stream inside a PCM info container | + | ' ''Set wanted stream inside a PCM info container.''</font> |
Private Extern snd_pcm_info_set_stream(pcminfoP As Pointer, valInt As Integer) | Private Extern snd_pcm_info_set_stream(pcminfoP As Pointer, valInt As Integer) | ||
− | ' int snd_ctl_pcm_info (snd_ctl_t *ctl, snd_pcm_info_t *info) | + | <FONT color=gray>' ''int snd_ctl_pcm_info (snd_ctl_t *ctl, snd_pcm_info_t *info) |
− | ' Get info about a PCM device. | + | ' ''Get info about a PCM device.''</font> |
Private Extern snd_ctl_pcm_info(ctlP As Pointer, pcminfoP As Pointer) As Integer | Private Extern snd_ctl_pcm_info(ctlP As Pointer, pcminfoP As Pointer) As Integer | ||
− | ' const char * snd_ctl_card_info_get_id (const snd_ctl_card_info_t *obj) | + | <FONT color=gray>' ''const char * snd_ctl_card_info_get_id (const snd_ctl_card_info_t *obj) |
− | ' Get card identifier From a CTL card info. | + | ' ''Get card identifier From a CTL card info.''</font> |
Private Extern snd_ctl_card_info_get_id(infoP As Pointer) As String | Private Extern snd_ctl_card_info_get_id(infoP As Pointer) As String | ||
− | ' const char * snd_ctl_card_info_get_name (const snd_ctl_card_info_t *obj) | + | <FONT color=gray>' ''const char * snd_ctl_card_info_get_name (const snd_ctl_card_info_t *obj) |
− | ' Get card name From a CTL card info. | + | ' ''Get card name From a CTL card info.''</font> |
Private Extern snd_ctl_card_info_get_name(infoP As Pointer) As String | Private Extern snd_ctl_card_info_get_name(infoP As Pointer) As String | ||
− | ' const char* snd_pcm_info_get_id(const snd_pcm_info_t * obj) | + | <FONT color=gray>' ''const char* snd_pcm_info_get_id(const snd_pcm_info_t * obj) |
− | ' Get id from a PCM info container. | + | ' ''Get id from a PCM info container.''</font> |
Private Extern snd_pcm_info_get_id(pcminfoP As Pointer) As String | Private Extern snd_pcm_info_get_id(pcminfoP As Pointer) As String | ||
− | ' const char* snd_pcm_info_get_name (const snd_pcm_info_t * obj) | + | <FONT color=gray>' ''const char* snd_pcm_info_get_name (const snd_pcm_info_t * obj) |
− | ' Get name From a PCM info container. | + | ' ''Get name From a PCM info container.''</font> |
Private Extern snd_pcm_info_get_name(pcminfoP As Pointer) As String | Private Extern snd_pcm_info_get_name(pcminfoP As Pointer) As String | ||
− | ' unsigned int snd_pcm_info_get_subdevices_count (const snd_pcm_info_t *obj) | + | <FONT color=gray>' ''unsigned int snd_pcm_info_get_subdevices_count (const snd_pcm_info_t *obj) |
− | ' Get subdevices count From a PCM info container. | + | ' ''Get subdevices count From a PCM info container.''</font> |
Private Extern snd_pcm_info_get_subdevices_count(pcminfoP As Pointer) As Integer | Private Extern snd_pcm_info_get_subdevices_count(pcminfoP As Pointer) As Integer | ||
− | ' unsigned int snd_pcm_info_get_subdevices_avail (const snd_pcm_info_t *obj) | + | <FONT color=gray>' ''unsigned int snd_pcm_info_get_subdevices_avail (const snd_pcm_info_t *obj) |
− | ' Get available subdevices count From a PCM info container. | + | ' ''Get available subdevices count From a PCM info container.''</font> |
Private Extern snd_pcm_info_get_subdevices_avail(pcminfoP As Pointer) As Integer | Private Extern snd_pcm_info_get_subdevices_avail(pcminfoP As Pointer) As Integer | ||
− | ' const char * snd_pcm_info_get_subdevice_name (const snd_pcm_info_t *obj) | + | <FONT color=gray>' ''const char * snd_pcm_info_get_subdevice_name (const snd_pcm_info_t *obj) |
− | ' Get subdevice name From a PCM info container. | + | ' ''Get subdevice name From a PCM info container.''</font> |
Private Extern snd_pcm_info_get_subdevice_name(pcminfoP As Pointer) As String | Private Extern snd_pcm_info_get_subdevice_name(pcminfoP As Pointer) As String | ||
− | ' const char * snd_strerror (int errnum) | + | <FONT color=gray>' ''const char * snd_strerror (int errnum) |
− | ' Returns the message For an Error code. | + | ' ''Returns the message For an Error code.''</font> |
Private Extern snd_strerror(errore As Integer) As String | Private Extern snd_strerror(errore As Integer) As String | ||
− | '''Public''' Sub | + | '''Public''' Sub Main() |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Dim info, pcminfo As Pointer | Dim info, pcminfo As Pointer | ||
Dim card, dev, count, avail, idx, err As Integer | Dim card, dev, count, avail, idx, err As Integer | ||
Riga 118: | Riga 105: | ||
If (snd_card_next(VarPtr(card)) < 0) Or (card < 0) Then Error.Raise("Nessuna scheda audio trovata !") | If (snd_card_next(VarPtr(card)) < 0) Or (card < 0) Then Error.Raise("Nessuna scheda audio trovata !") | ||
− | + | Print "******* LISTA DEI DISPOSITIVI HARDWARE DI RIPRODUZIONE AUDIO *******" | |
− | |||
− | |||
snd_pcm_stream_name(SND_PCM_STREAM_PLAYBACK) | snd_pcm_stream_name(SND_PCM_STREAM_PLAYBACK) | ||
Riga 160: | Riga 145: | ||
If err < 0 Then | If err < 0 Then | ||
− | If err <> - ENOENT Then Error | + | If err <> - ENOENT Then Error("Informazione sull'audio digitale del controllo: " & card & " " & snd_strerror(err)) |
Continue | Continue | ||
Endif | Endif | ||
− | ''''''''''''' | + | <FONT color=gray>'''''''''''''</font> |
+ | |||
card_id = snd_ctl_card_info_get_id(info) | card_id = snd_ctl_card_info_get_id(info) | ||
Riga 173: | Riga 159: | ||
pcm_name = snd_pcm_info_get_name(pcminfo) | pcm_name = snd_pcm_info_get_name(pcminfo) | ||
− | + | Print "_______________________________________________________________________________________\n" | |
− | + | Print "DISPOSITIVO AUDIO: "; name; " "; card_id; " ["; card_name; "] Device: "; dev; " "; pcm_id; " ["; pcm_name; "]\n" | |
− | |||
− | |||
− | |||
− | |||
− | |||
count = snd_pcm_info_get_subdevices_count(pcminfo) | count = snd_pcm_info_get_subdevices_count(pcminfo) | ||
Riga 185: | Riga 166: | ||
avail = snd_pcm_info_get_subdevices_avail(pcminfo) | avail = snd_pcm_info_get_subdevices_avail(pcminfo) | ||
− | + | Print "Subdevices: "; avail; "/"; count; Chr(10) | |
− | |||
− | |||
− | |||
For idx = 0 To count - 1 | For idx = 0 To count - 1 | ||
Riga 194: | Riga 172: | ||
err = snd_ctl_pcm_info(handlCtl, pcminfo) | err = snd_ctl_pcm_info(handlCtl, pcminfo) | ||
If err < 0 Then | If err < 0 Then | ||
− | Error.Raise(" | + | Error.Raise("Errore nella Riproduzione audio digitale del controllo: " & card & " " & snd_strerror(err)) |
Else | Else | ||
subdevice_name = snd_pcm_info_get_subdevice_name(pcminfo) | subdevice_name = snd_pcm_info_get_subdevice_name(pcminfo) | ||
− | + | Print "Subdevice: #"; idx; ": "; subdevice_name | |
− | |||
− | |||
Endif | Endif | ||
Next | Next | ||
Riga 208: | Riga 184: | ||
next_card: | next_card: | ||
If snd_card_next(VarPtr(card)) < 0 Then | If snd_card_next(VarPtr(card)) < 0 Then | ||
− | Error("Errore in 'next_card' !") | + | Error.Raise("Errore in 'next_card' !") |
Break | Break | ||
Endif | Endif | ||
Riga 214: | Riga 190: | ||
'''End''' | '''End''' | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Versione delle 09:15, 28 mag 2014
Alcune funzioni esterne del API di ALSA consentono di conoscere quali sono le porte di entrata e di uscita dell'audio digitale delle schede audio presenti nel proprio sistema.
Mostriamo di segtuito qualche esempio:
Private Const SND_PCM_STREAM_PLAYBACK As Byte = 0 ' Playback stream Private Const ENOENT As Byte = 2 Private handlCtl As Pointer Library "libasound:2" ' int snd_card_next(int *card) ' Try to determine the next card. Private Extern snd_card_next(cardI As Pointer) As Integer ' const char* snd_pcm_stream_name(snd_pcm_stream_t stream) ' Get name of PCM stream type Private Extern snd_pcm_stream_name(streamI As Byte) As String ' int snd_ctl_open(snd_ctl_t **ctl, const char *name, int mode) ' Opens a CTL. Private Extern snd_ctl_open(ctlP As Pointer, name As String, mode As Integer) As Integer ' snd_ctl_card_info_malloc(ptr) ' Allocate an invalid snd_ctl_card_info_t using standard malloc Private Extern snd_ctl_card_info_malloc(ptr As Pointer) ' int snd_ctl_card_info(snd_ctl_t *ctl, snd_ctl_card_info_t *info) ' Get card related information. Private Extern snd_ctl_card_info(ctlP As Pointer, infoP As Pointer) As Integer ' void snd_ctl_close(snd_ctl_t *ctl) ' Closes a ctl. Private Extern snd_ctl_close(ctlP As Pointer) ' int snd_ctl_pcm_next_device(snd_ctl_t *ctl, int *device) ' Get Next PCM device number. Private Extern snd_ctl_pcm_next_device(ctlP As Pointer, device As Pointer) As Integer ' int snd_pcm_info_malloc(snd_pcm_info_t ** ptr) ' Allocate an invalid snd_pcm_info_t using standard malloc. Private Extern snd_pcm_info_malloc(ptr As Pointer) As Integer ' void snd_pcm_info_set_device (snd_pcm_info_t *obj, unsigned int val) ' Set wanted device inside a PCM info container. Private Extern snd_pcm_info_set_device(pcminfoP As Pointer, ValI As Integer) ' void snd_pcm_info_set_subdevice(snd_pcm_info_t *obj, unsigned int val) ' Set wanted subdevice inside a PCM info container. Private Extern snd_pcm_info_set_subdevice(pcminfoP As Pointer, ValI As Integer) ' void snd_pcm_info_set_stream(snd_pcm_info_t *obj, snd_pcm_stream_t val) ' Set wanted stream inside a PCM info container. Private Extern snd_pcm_info_set_stream(pcminfoP As Pointer, valInt As Integer) ' int snd_ctl_pcm_info (snd_ctl_t *ctl, snd_pcm_info_t *info) ' Get info about a PCM device. Private Extern snd_ctl_pcm_info(ctlP As Pointer, pcminfoP As Pointer) As Integer ' const char * snd_ctl_card_info_get_id (const snd_ctl_card_info_t *obj) ' Get card identifier From a CTL card info. Private Extern snd_ctl_card_info_get_id(infoP As Pointer) As String ' const char * snd_ctl_card_info_get_name (const snd_ctl_card_info_t *obj) ' Get card name From a CTL card info. Private Extern snd_ctl_card_info_get_name(infoP As Pointer) As String ' const char* snd_pcm_info_get_id(const snd_pcm_info_t * obj) ' Get id from a PCM info container. Private Extern snd_pcm_info_get_id(pcminfoP As Pointer) As String ' const char* snd_pcm_info_get_name (const snd_pcm_info_t * obj) ' Get name From a PCM info container. Private Extern snd_pcm_info_get_name(pcminfoP As Pointer) As String ' unsigned int snd_pcm_info_get_subdevices_count (const snd_pcm_info_t *obj) ' Get subdevices count From a PCM info container. Private Extern snd_pcm_info_get_subdevices_count(pcminfoP As Pointer) As Integer ' unsigned int snd_pcm_info_get_subdevices_avail (const snd_pcm_info_t *obj) ' Get available subdevices count From a PCM info container. Private Extern snd_pcm_info_get_subdevices_avail(pcminfoP As Pointer) As Integer ' const char * snd_pcm_info_get_subdevice_name (const snd_pcm_info_t *obj) ' Get subdevice name From a PCM info container. Private Extern snd_pcm_info_get_subdevice_name(pcminfoP As Pointer) As String ' const char * snd_strerror (int errnum) ' Returns the message For an Error code. Private Extern snd_strerror(errore As Integer) As String Public Sub Main() Dim info, pcminfo As Pointer Dim card, dev, count, avail, idx, err As Integer Dim name, card_id, card_name, pcm_id, pcm_name, subdevice_name As String snd_ctl_card_info_malloc(VarPtr(info)) snd_pcm_info_malloc(VarPtr(pcminfo)) card = -1 If (snd_card_next(VarPtr(card)) < 0) Or (card < 0) Then Error.Raise("Nessuna scheda audio trovata !") Print "******* LISTA DEI DISPOSITIVI HARDWARE DI RIPRODUZIONE AUDIO *******" snd_pcm_stream_name(SND_PCM_STREAM_PLAYBACK) While card >= 0 name = "hw:" & card err = snd_ctl_open(VarPtr(handlCtl), name, 0) If err < 0 Then Error("Errore nell'apertura del Controllo: " & card & ":" & snd_strerror(err)) Goto next_card Endif err = snd_ctl_card_info(handlCtl, info) If err < 0 Then Error("Informazione sull'hardware del controllo: " & card & ":" & snd_strerror(err)) snd_ctl_close(handlCtl) Goto next_card Endif dev = -1 While True If snd_ctl_pcm_next_device(handlCtl, VarPtr(dev)) < 0 Then Error.Raise("Errore alla funzione 'snd_ctl_pcm_next_device' !") If dev < 0 Then Break snd_pcm_info_set_device(pcminfo, dev) snd_pcm_info_set_subdevice(pcminfo, 0) snd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_PLAYBACK) err = snd_ctl_pcm_info(handlCtl, pcminfo) If err < 0 Then If err <> - ENOENT Then Error("Informazione sull'audio digitale del controllo: " & card & " " & snd_strerror(err)) Continue Endif '''''''' card_id = snd_ctl_card_info_get_id(info) card_name = snd_ctl_card_info_get_name(info) pcm_id = snd_pcm_info_get_id(pcminfo) pcm_name = snd_pcm_info_get_name(pcminfo) Print "_______________________________________________________________________________________\n" Print "DISPOSITIVO AUDIO: "; name; " "; card_id; " ["; card_name; "] Device: "; dev; " "; pcm_id; " ["; pcm_name; "]\n" count = snd_pcm_info_get_subdevices_count(pcminfo) avail = snd_pcm_info_get_subdevices_avail(pcminfo) Print "Subdevices: "; avail; "/"; count; Chr(10) For idx = 0 To count - 1 snd_pcm_info_set_subdevice(pcminfo, idx) err = snd_ctl_pcm_info(handlCtl, pcminfo) If err < 0 Then Error.Raise("Errore nella Riproduzione audio digitale del controllo: " & card & " " & snd_strerror(err)) Else subdevice_name = snd_pcm_info_get_subdevice_name(pcminfo) Print "Subdevice: #"; idx; ": "; subdevice_name Endif Next Wend snd_ctl_close(handlCtl) next_card: If snd_card_next(VarPtr(card)) < 0 Then Error.Raise("Errore in 'next_card' !") Break Endif Wend End