Differenze tra le versioni di "Conoscere con le funzioni esterne di PortAudio i dispositivi audio presenti nel sistema"

Da Gambas-it.org - Wikipedia.
Riga 10: Riga 10:
 
   maxInputChannels As Integer
 
   maxInputChannels As Integer
 
   maxOutputChannels As Integer
 
   maxOutputChannels As Integer
   numSampleRates As Integer    ' Number of discrete rates, or -1 if range supported.
+
   defaultLowInputLatency As Float
   sampleRates As Float         ' Array of supported sample rates, or {min,max} if range supported.
+
  defaultLowOutputLatency As Float
   nativeSampleFormats As Long
+
   defaultHighInputLatency As Float
 +
   defaultHighOutputLatency As Float
 +
  defaultSampleRate As Float
 
  End Struct
 
  End Struct
 
   
 
   
Riga 100: Riga 102:
 
     Print "Nome = "; String@(pdi.name)
 
     Print "Nome = "; String@(pdi.name)
 
     Print "Max Entrate = "; pdi.maxInputChannels, ", Max Uscite = "; pdi.maxOutputChannels
 
     Print "Max Entrate = "; pdi.maxInputChannels, ", Max Uscite = "; pdi.maxOutputChannels
     
+
    Print "Default low input latency = "; pdi.defaultLowInputLatency
 +
    Print "Default low output latency = "; pdi.defaultLowOutputLatency
 +
    Print "Default high input latency = "; pdi.defaultHighInputLatency
 +
    Print "Default high output latency = "; pdi.defaultHighOutputLatency
 +
 
   Next
 
   Next
 
      
 
      

Versione delle 13:47, 9 lug 2014

La libreria PortAudio è una libreria per la gestione in tempo reale dei dati audio in entrata ed in uscita. Essa fa parte di un assortimento di API e librerie create per la musica e per altri media.

E' possibile con alcune funzioni esterne della libreria PortAudio conoscere i dispositivi audio presenti nel proprio sistema. Sarà necessario avere installata nel proprio sistema la libreria condivisa: libportaudio.so.2.0.0


Mostriamo di seguito un possibile codice:

Public Struct PaDeviceInfo
  structVersion As Integer
  name As Pointer
  maxInputChannels As Integer
  maxOutputChannels As Integer
  defaultLowInputLatency As Float
  defaultLowOutputLatency As Float
  defaultHighInputLatency As Float
  defaultHighOutputLatency As Float
  defaultSampleRate As Float
End Struct


Library "libportaudio:2.0.0"

Private Const paNoError As Integer = 0

' PaError Pa_Initialize(void)
' Library initialization function - call this before using PortAudio.
' This function initializes internal data structures and prepares underlying host APIs for use.
Private Extern Pa_Initialize() As Integer

' PaDeviceIndex Pa_GetDeviceCount(void)
' Retrieve the number of available devices. The number of available devices may be zero.
Private Extern Pa_GetDeviceCount() As Integer

' const PaDeviceInfo * Pa_GetDeviceInfo(PaDeviceIndex device)
' Retrieve a pointer to a PaDeviceInfo structure containing information about the specified device.
Private Extern Pa_GetDeviceInfo(device As Integer) As PaDeviceInfo

' PaDeviceIndex Pa_GetDefaultInputDevice(void)
' Retrieve the index of the default input device.
Private Extern Pa_GetDefaultInputDevice() As Integer

' PaDeviceIndex Pa_GetDefaultOutputDevice(void)
' Retrieve the index of the default output device.
Private Extern Pa_GetDefaultOutputDevice() As Integer

' PaError Pa_Terminate(void)
' Library termination function - call this when finished using PortAudio.
Private Extern Pa_Terminate() As Integer

' const char *Pa_GetErrorText(PaError errnum)
' Translates the supplied PortAudio error number into a human readable message.
Private Extern Pa_GetErrorText(errnum As Integer) As String


Public Sub Main()

 Dim err, i, j, numDevices As Integer
 Dim pdi As New PaDeviceInfo
 Dim defI, defO, ag1, ag2 As String


  err = Pa_Initialize()
  If err < 0 Then Error.Raise("Impossibile inizializzare la libreria 'PortAudio': " & Pa_GetErrorText(err))

  numDevices = Pa_GetDeviceCount()
  If numDevices < 0 Then Error.Raise("Impossibile rilevare la presenza di dispositivi audio: " & Pa_GetErrorText(err))
   
  Print "Numbero di dispositivi = "; numDevices
   
  For i = 0 To numDevices - 1
     
    defI = Null
    defO = Null
    ag1 = Null
    ag2 = Null
     
    pdi = Pa_GetDeviceInfo(i)
     
    Print "\n--------------------------------------- dispositivo #"; i
     
    j = 0
     
    If i = Pa_GetDefaultInputDevice() Then
      defI = "\n[ Default Input"
      j = 1
    Endif
    
    If i = Pa_GetDefaultOutputDevice() Then
      If j Then
        ag1 = ","
      Else
        ag1 = "["
      Endif
      defO = " Default Output"
      j = 1
    Endif
     
    If j = 1 Then ag2 = " ]"
     
    Print defI; ag1; defO; ag2
     
' Scrive i campi relativi alle informazioni di ciascun dispositivo audio rilevato:
    Print "Nome = "; String@(pdi.name)
    Print "Max Entrate = "; pdi.maxInputChannels, ", Max Uscite = "; pdi.maxOutputChannels
    Print "Default low input latency = "; pdi.defaultLowInputLatency
    Print "Default low output latency = "; pdi.defaultLowOutputLatency
    Print "Default high input latency = "; pdi.defaultHighInputLatency
    Print "Default high output latency = "; pdi.defaultHighOutputLatency

  Next
   

' Va in chiusura: 
  Pa_Terminate()

End


Riferimenti