Differenze tra le versioni di "Sapere con le funzioni esterne di ALSA quali schede audio sono installate nel computer"
Da Gambas-it.org - Wikipedia.
(Creata pagina con 'Alcune funzioni esterne del API di ALSA consentono di sapere quante e quali sono le schede audio presenti nel proprio computer. Il seguente applicativo elenca semplicemente ...') |
|||
Riga 78: | Riga 78: | ||
Wend | Wend | ||
− | <FONT color=gray>' ''Va in chiusura liberando memoria precedentemente allocata:''</font> | + | <FONT color=gray>' ''Va in chiusura liberando la memoria precedentemente allocata:''</font> |
snd_config_update_free_global() | snd_config_update_free_global() | ||
'''End''' | '''End''' |
Versione delle 04:44, 28 mag 2014
Alcune funzioni esterne del API di ALSA consentono di sapere quante e quali sono le schede audio presenti nel proprio computer.
Il seguente applicativo 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 While True ' Ottiene il numero della scheda audio successiva. ' Se "numSchede" = -1, 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)) If numSchede < 0 Then Break ' Si apre l'interfaccia di controllo di questa scheda. ' Viene specificato solo il numero della Scheda, ma nessun dispositivo audio né alcun sub-dispositivo: stringa = "hw:" & numSchede err = snd_ctl_open(VarPtr(schedHandle), stringa, 0) If err < 0 Then Error.Raise("Impossibile aprire la scheda " & numSchede & ":" & snd_strerror(err)) 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 Error.Raise("Impossibile ottenere informazioni per la scheda audio: " & numSchede & " " & snd_strerror(err)) Else Print "Scheda audio "; numSchede; " = "; snd_ctl_card_info_get_name(schedInfo) Endif ' Al termine chiude l'interfaccia di controllo della scheda audio: snd_ctl_close(schedHandle) Wend ' Va in chiusura liberando la memoria precedentemente allocata: snd_config_update_free_global() End