Differenze tra le versioni di "Sapere con le funzioni esterne di ALSA quali schede audio sono installate nel computer"
Da Gambas-it.org - Wikipedia.
(2 versioni intermedie di uno stesso utente non sono mostrate) | |||
Riga 1: | Riga 1: | ||
Alcune funzioni esterne del API di ALSA consentono di sapere quante e quali sono le schede audio presenti nel proprio computer. | Alcune funzioni esterne del API di ALSA consentono di sapere quante e quali sono le schede audio presenti nel proprio computer. | ||
− | + | Il seguente codice elenca semplicemente i nomi di tutte le schede audio installate: | |
− | Il seguente | ||
Library "libasound:2.0.0" | Library "libasound:2.0.0" | ||
Riga 38: | Riga 37: | ||
− | + | Public Sub Main() | |
Dim err As Integer | Dim err As Integer | ||
Riga 53: | Riga 52: | ||
stringa = "hw:" & numSchede | stringa = "hw:" & numSchede | ||
err = snd_ctl_open(VarPtr(schedHandle), stringa, 0) | err = snd_ctl_open(VarPtr(schedHandle), stringa, 0) | ||
− | If err < 0 Then Error.Raise("Impossibile aprire la scheda " & numSchede & ":" & snd_strerror(err)) | + | If err < 0 Then |
+ | Chiusura(schedHandle) | ||
+ | Error.Raise("Impossibile aprire la scheda " & numSchede & ":" & snd_strerror(err)) | ||
+ | Endif | ||
snd_ctl_card_info_malloc(VarPtr(schedInfo)) | snd_ctl_card_info_malloc(VarPtr(schedInfo)) | ||
Riga 59: | Riga 61: | ||
err = snd_ctl_card_info(schedHandle, schedInfo) | err = snd_ctl_card_info(schedHandle, schedInfo) | ||
If err < 0 Then | If err < 0 Then | ||
+ | Chiusura(schedHandle) | ||
Error.Raise("Impossibile ottenere informazioni per la scheda audio: " & numSchede & " " & snd_strerror(err)) | Error.Raise("Impossibile ottenere informazioni per la scheda audio: " & numSchede & " " & snd_strerror(err)) | ||
Else | Else | ||
− | Print " | + | Print "\e[0mScheda audio "; numSchede; " = \e[1m"; snd_ctl_card_info_get_name(schedInfo) |
Endif | Endif | ||
err = snd_card_next(VarPtr(numSchede)) | err = snd_card_next(VarPtr(numSchede)) | ||
− | If err < 0 Then Error.Raise("Impossibile ottenere il numero della scheda successiva: ", snd_strerror(err)) | + | If err < 0 Then |
+ | Chiusura(schedHandle) | ||
+ | Error.Raise("Impossibile ottenere il numero della scheda successiva: ", snd_strerror(err)) | ||
+ | Endif | ||
Until numSchede < 0 | Until numSchede < 0 | ||
+ | |||
+ | Chiusura(schedHandle) | ||
+ | |||
+ | End | ||
+ | |||
+ | |||
+ | Private Procedure Chiusura(han as Pointer) | ||
<FONT color=gray>' ''Al termine chiude l'interfaccia di controllo della scheda audio e libera la memoria precedentemente allocata:''</font> | <FONT color=gray>' ''Al termine chiude l'interfaccia di controllo della scheda audio e libera la memoria precedentemente allocata:''</font> | ||
− | snd_ctl_close( | + | snd_ctl_close(han) |
snd_config_update_free_global() | snd_config_update_free_global() | ||
− | + | ||
− | + | End |
Versione attuale delle 12:25, 13 gen 2024
Alcune funzioni esterne del API di ALSA consentono di sapere quante e quali sono le schede audio presenti nel proprio computer.
Il seguente codice elenca semplicemente i nomi di tutte le schede audio installate:
Library "libasound:2.0.0" ' int snd_card_next(int *card) ' Try to determine the next card. Private Extern snd_card_next(cardP As Pointer) As Integer ' const char* snd_strerror(int errnum) ' Returns the message for an error code. Private Extern snd_strerror(errnum As Integer) As String ' int snd_ctl_open(snd_ctl_t **ctl, const char *name, int mode) ' Opens a CTL. Private Extern snd_ctl_open(ctl 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(ctl As Pointer, info As Pointer) As Integer ' 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(obj As Pointer) As String ' int snd_ctl_close(snd_ctl_t * ctl) ' Close CTL handle. Private Extern snd_ctl_close(ctl As Pointer) As Integer ' int snd_config_update_free_global(void) ' Frees the global configuration tree in snd_config. Private Extern snd_config_update_free_global() As Integer Public Sub Main() Dim err As Integer Dim numSchede As Short = -1 Dim stringa As String Dim schedHandle, schedInfo As Pointer ' Ottiene il numero della scheda audio successiva. ' Se "numSchede" == 0, allora ALSA recupera la prima scheda: err = snd_card_next(VarPtr(numSchede)) If err < 0 Then Error.Raise("Impossibile ottenere il numero della scheda successiva: ", snd_strerror(err)) Repeat stringa = "hw:" & numSchede err = snd_ctl_open(VarPtr(schedHandle), stringa, 0) If err < 0 Then Chiusura(schedHandle) Error.Raise("Impossibile aprire la scheda " & numSchede & ":" & snd_strerror(err)) Endif snd_ctl_card_info_malloc(VarPtr(schedInfo)) ' Dice ad ALSA di compilare "snd_ctl_card_info_t" con informazioni sulla corrente scheda audio individuata: err = snd_ctl_card_info(schedHandle, schedInfo) If err < 0 Then Chiusura(schedHandle) Error.Raise("Impossibile ottenere informazioni per la scheda audio: " & numSchede & " " & snd_strerror(err)) Else Print "\e[0mScheda audio "; numSchede; " = \e[1m"; snd_ctl_card_info_get_name(schedInfo) Endif err = snd_card_next(VarPtr(numSchede)) If err < 0 Then Chiusura(schedHandle) Error.Raise("Impossibile ottenere il numero della scheda successiva: ", snd_strerror(err)) Endif Until numSchede < 0 Chiusura(schedHandle) End Private Procedure Chiusura(han as Pointer) ' Al termine chiude l'interfaccia di controllo della scheda audio e libera la memoria precedentemente allocata: snd_ctl_close(han) snd_config_update_free_global() End