Differenze tra le versioni di "Estrarre alcune informazioni di un file audio WAV con le funzioni esterne del API di SDL2"

Da Gambas-it.org - Wikipedia.
Riga 1: Riga 1:
 
Con alcune funzioni esterne del API del sistema SDL2 è possibile estrarre alcune informazioni da un file audio di formato WAV.
 
Con alcune funzioni esterne del API del sistema SDL2 è possibile estrarre alcune informazioni da un file audio di formato WAV.
  
E' necessario avere installata nel sistema e richiamare nel programma Gambas la libreria dinamica condivisa: "''libSDL2-2.0.so.0.10.0''"
+
E' necessario avere installata nel sistema e richiamare nel programma Gambas la libreria dinamica condivisa: "''libSDL2-2.0.so.0.10.0'' "
 
 
  
 
Mostriamo un semplice esempio:
 
Mostriamo un semplice esempio:
Riga 49: Riga 48:
 
   Dim ausp As New SDL_AudioSpec   
 
   Dim ausp As New SDL_AudioSpec   
 
    
 
    
  percorso = "<FONT Color=gray>''/percorso/del/file.wav''</font>"
+
  percorso = "<FONT Color=gray>''/percorso/del/file.wav''</font>"
 
    
 
    
 
  <FONT Color=gray>' ''Inizializza la libreria SDL2:''</font>"
 
  <FONT Color=gray>' ''Inizializza la libreria SDL2:''</font>"
  i = SDL_Init(SDL_INIT_AUDIO)
+
  i = SDL_Init(SDL_INIT_AUDIO)
  If i < 0 Then Error.Raise("Impossibile inizializzare la libreria SDL2: " & SDL_GetError())
+
  If i < 0 Then Error.Raise("Impossibile inizializzare la libreria SDL2: " & SDL_GetError())
 
    
 
    
  rwops = SDL_RWFromFile(percorso, "rb")
+
  rwops = SDL_RWFromFile(percorso, "rb")
 
    
 
    
  SDL_LoadWAV_RW(rwops, 1, ausp, VarPtr(buf), VarPtr(lun))
+
  SDL_LoadWAV_RW(rwops, 1, ausp, VarPtr(buf), VarPtr(lun))
 
    
 
    
  Print "File audio:        "; percorso
+
  Print "File audio:        "; percorso
  Print "Dati audio grezzi: "; lun; " byte"
+
  Print "Dati audio grezzi: "; lun; " byte"
  With ausp
+
  With ausp
    Print "Frequenza:        "; .freq; " hertz"
+
    Print "Frequenza:        "; .freq; " hertz"
    Print "Canali:            "; .channels
+
    Print "Canali:            "; .channels
    Print "Buffer audio:      "; .samples; " byte"
+
    Print "Buffer audio:      "; .samples; " byte"
    For i = 15 To 0 Step -1
+
    For i = 15 To 0 Step -1
      If (Shl(1, i) And .format) > 0 Then
+
      If (Shl(1, i) And .format) > 0 Then
        Select Case 2 ^ i
+
        Select Case 2 ^ i
          Case 8
+
          Case 8
            s &= "8-bit"
+
            s &= "8-bit"
          Case 16
+
          Case 16
            s &= "16-bit"
+
            s &= "16-bit"
          Case 32
+
          Case 32
            s &= "32-bit"
+
            s &= "32-bit"
          Case 256
+
          Case 256
            s &= "Float "
+
            s &= "Float "
          Case 4096
+
          Case 4096
            s &= "BigEndian "
+
            s &= "BigEndian "
          Case 32768
+
          Case 32768
            s &= "Signed "
+
            s &= "Signed "
        End Select
+
        End Select
      Endif
+
      Endif
    Next
+
    Next
    Print "Formato audio:    "; s
+
    Print "Formato audio:    "; s
  End With
+
  End With
 
    
 
    
  SDL_Quit()
+
  SDL_Quit()
 
    
 
    
 
  '''End'''
 
  '''End'''

Versione delle 17:49, 25 nov 2021

Con alcune funzioni esterne del API del sistema SDL2 è possibile estrarre alcune informazioni da un file audio di formato WAV.

E' necessario avere installata nel sistema e richiamare nel programma Gambas la libreria dinamica condivisa: "libSDL2-2.0.so.0.10.0 "

Mostriamo un semplice esempio:

Library "libSDL2-2.0:0.10.0"

Private Const SDL_INIT_AUDIO As Integer = 16

Public Struct SDL_AudioSpec
  freq As Integer
  format As Short
  channels As Byte
  silence As Byte
  samples As Short
  padding As Short
  size As Integer
  callback As Pointer
  userdata As Pointer
End Struct

' int SDL_Init(Uint32 flags)
' Initialize the SDL library.
Private Extern SDL_Init(flags As Integer) As Integer

' const char* SDL_GetError(void)
' Retrieve a message about the last error that occurred.
Private Extern SDL_GetError() As String

' SDL_RWops * SDL_RWFromFile(const char *file, const char *mode)
' Create SDL_RWops structures from various data streams.
Private Extern SDL_RWFromFile(SDLfile As String, mode As String) As Pointer

' SDL_AudioSpec * SDL_LoadWAV_RW(SDL_RWops * src, int freesrc, SDL_AudioSpec * spec, Uint8 ** audio_buf, Uint32 * audio_len)
' Loads a WAVE from the data source.
Private Extern SDL_LoadWAV_RW(src As Pointer, freesrc As Integer, spec As SDL_AudioSpec, audio_buf As Pointer, audio_len As Pointer) As SDL_AudioSpec

' void SDL_Quit(void)
' Clean up all initialized subsystems.
Private Extern SDL_Quit()


Public Sub Main()

 Dim percorso, s As String
 Dim i, buf, lun As Integer
 Dim rwops As Pointer
 Dim ausp As New SDL_AudioSpec   
  
 percorso = "/percorso/del/file.wav"
  
' Inizializza la libreria SDL2:"
 i = SDL_Init(SDL_INIT_AUDIO)
 If i < 0 Then Error.Raise("Impossibile inizializzare la libreria SDL2: " & SDL_GetError())
  
 rwops = SDL_RWFromFile(percorso, "rb")
  
 SDL_LoadWAV_RW(rwops, 1, ausp, VarPtr(buf), VarPtr(lun))
  
 Print "File audio:        "; percorso
 Print "Dati audio grezzi: "; lun; " byte"
 With ausp
   Print "Frequenza:         "; .freq; " hertz"
   Print "Canali:            "; .channels
   Print "Buffer audio:      "; .samples; " byte"
   For i = 15 To 0 Step -1
     If (Shl(1, i) And .format) > 0 Then
       Select Case 2 ^ i
         Case 8
           s &= "8-bit"
         Case 16
           s &= "16-bit"
         Case 32
           s &= "32-bit"
         Case 256
           s &= "Float "
         Case 4096
           s &= "BigEndian "
         Case 32768
           s &= "Signed "
       End Select
     Endif
   Next
   Print "Formato audio:     "; s
 End With
  
 SDL_Quit()
  
End