Differenze tra le versioni di "Estrarre informazioni e TAG da un file OggVorbis con le sole funzioni di Gambas"

Da Gambas-it.org - Wikipedia.
(Creata pagina con 'E' possibile estrarre informazioni generali e TAG da un file OggVorbis con le sole funzioni di Gambas. Un possibile codice è il seguente: '''Public''' Sub Main() Dim...')
 
Riga 25: Riga 25:
 
   Print "Frequenza di campionamento = hz "; info[0]
 
   Print "Frequenza di campionamento = hz "; info[0]
 
   Print "Canali = "; info[1]
 
   Print "Canali = "; info[1]
 +
  Print "Bitrate nominale = "; info[2]; " kbps"
 
    
 
    
 +
 
   ordo.add(InStr(s, "TITLE="))   
 
   ordo.add(InStr(s, "TITLE="))   
 
   ordo.add(InStr(s, "VERSION="))   
 
   ordo.add(InStr(s, "VERSION="))   
Riga 102: Riga 104:
 
    
 
    
 
   Dim j As Byte
 
   Dim j As Byte
   Dim fr$ As String
+
   Dim fr$, br$ As String
 
   Dim info$ As New String[]
 
   Dim info$ As New String[]
 
    
 
    
 
    
 
    
 +
<FONT color=gray>' ''Estrae la frequenza di campionamento:''</font>
 
     For j = 43 To 41 Step -1
 
     For j = 43 To 41 Step -1
 
       fr$ &= Hex(Asc(Mid(sf, j, 1)), 2)
 
       fr$ &= Hex(Asc(Mid(sf, j, 1)), 2)
Riga 112: Riga 115:
 
     info$.Add(Val("&" & fr$))
 
     info$.Add(Val("&" & fr$))
 
      
 
      
 +
<FONT color=gray>' ''Estrae il numero di canali d'uscita:''</font>
 
     info$.Add(CStr(Asc(Mid(sf, 40, 1))))
 
     info$.Add(CStr(Asc(Mid(sf, 40, 1))))
 +
 +
<FONT color=gray>' ''Estrae il bitrate nominale:''</font>
 +
    For j = 51 To 49 Step -1
 +
      br$ &= Hex(Asc(Mid(sf, j, 1)), 2)
 +
    Next
 +
   
 +
    info$.Add(CStr(Val("&" & br$) \ 1000))
 
      
 
      
 
     Return info$
 
     Return info$

Versione delle 14:05, 19 feb 2014

E' possibile estrarre informazioni generali e TAG da un file OggVorbis con le sole funzioni di Gambas.

Un possibile codice è il seguente:

Public Sub Main()  
 
 Dim percorsoFile, s, tag As String
 Dim info As String[]  
 Dim ordo As New Integer[]  
 Dim j, rm, k As Integer  
 Dim agg As Byte = 24  
 
 
  percorsoFile = "/percorso/del/file.ogg"  
  
  s = File.Load(percorsoFile)  
    
' Verifica se effettivamente è un file .ogg:  
  If Left(s, 4) <> "OggS" Then Error.Raise("Attenzione ! Il file caricato non è un file OGG !")  
    
  Print "File audio ogg: '"; File.Name(percorsoFile); "'"  
  Print "\nDimensione: "; Len(s); " byte"  

' Estrae informazioni generali (frequenza di campionamento e canali) sul file:
  info = EstraeInfo(s)
  Print "Frequenza di campionamento = hz "; info[0]
  Print "Canali = "; info[1]
  Print "Bitrate nominale = "; info[2]; " kbps"
  

  ordo.add(InStr(s, "TITLE="))  
  ordo.add(InStr(s, "VERSION="))  
  ordo.add(InStr(s, "ALBUM="))  
  ordo.add(InStr(s, "TRACKNUMBER="))  
  ordo.add(InStr(s, "ARTIST="))  
  ordo.add(InStr(s, "PERFORMER="))  
  ordo.add(InStr(s, "COPYRIGHT="))  
  ordo.add(InStr(s, "LICENSE="))  
  ordo.add(InStr(s, "ORGANIZATION="))  
  ordo.add(InStr(s, "DESCRIPTION="))  
  ordo.add(InStr(s, "GENRE="))  
  ordo.add(InStr(s, "DATE="))  
  ordo.add(InStr(s, "LOCATION="))  
  ordo.add(InStr(s, "CONTACT="))  
  ordo.add(InStr(s, "COMMENT="))  
  ordo.add(InStr(s, "ISRC="))  
 
  While j < ordo.Count  
    If ordo[j] = 0 Then  
      ordo.Remove(j)  
      Inc rm  
      Dec j  
    Endif  
    Inc j  
  Wend  
 
  ordo.Sort()  
    
  Print "\n  == T A G =="  
 
  If ordo.Count > 0 Then        ' Se è presente almeno un TAG
    
    If Mid(s, ordo[ordo.Max], 12) = "TRACKNUMBER=" Then agg = 15
    
    For j = 0 To ordo.Max  
 
    k = ordo[j]  
 
    While k < ordo[ordo.max] + agg  
        
      If j < ordo.Max Then  
' Verifica che il carattere ASCII sia una lettera o un numero oppure un segno di punteggiatura:
        If (k < ordo[j + 1]) And ((IsLetter(Mid(s, k, 1))) Or (IsDigit(Mid(s, k, 1))) Or (IsPunct(Mid(s, k, 1)))) Then  
          tag &= Mid(s, k, 1)  
        Else  
          tag &= " "  
        Endif  
      Else  
' Verifica che il carattere ASCII sia una lettera o un numero oppure un segno di punteggiatura:
        If ((IsLetter(Mid(s, k, 1))) Or (IsDigit(Mid(s, k, 1))) Or (IsPunct(Mid(s, k, 1)))) Then  
          tag &= Mid(s, k, 1)  
        Else  
          tag &= " "  
        Endif  
 
      Endif  
        
      Inc k  
 
    Wend  
 
    Print tag  
    tag = Null  
      
  Next  
    
  Else  
    Print "Assenti !"  
  Endif  
 
End


Private Function EstraeInfo(sf As String) As String[]
 
 Dim j As Byte
 Dim fr$, br$ As String
 Dim info$ As New String[]
 
 
' Estrae la frequenza di campionamento:
   For j = 43 To 41 Step -1
     fr$ &= Hex(Asc(Mid(sf, j, 1)), 2)
   Next
 
   info$.Add(Val("&" & fr$))
   
' Estrae il numero di canali d'uscita:
   info$.Add(CStr(Asc(Mid(sf, 40, 1))))

' Estrae il bitrate nominale:
   For j = 51 To 49 Step -1
     br$ &= Hex(Asc(Mid(sf, j, 1)), 2)
   Next
   
   info$.Add(CStr(Val("&" & br$) \ 1000))
   
   Return info$

End


Riferimenti

[1] Vorbis I specification