Il y a des commentaires en allemand car j'ai trouvé l'exemple de cette procédure sur le forum Allemand de PB. Je ne les ai pas traduit car mon niveau d'allemand est proche du zéro absolut

Code : Tout sélectionner
; http://www.ampsoft.org/data/MP3Info.pb
; 17. Mai 2003
; Andreas
Procedure ATestbit(val,bitnum)
;gibt Bitwert zureuck
Dim bit.b(8);
t1 = val / 2 : If t1*2 <> val : bit(1) = 1 : EndIf
t2 = t1 / 2 : If t2*2 <> t1 : bit(2) = 1 : EndIf
t3 = t2 / 2 : If t3*2 <> t2 : bit(3) = 1 : EndIf
t4 = t3 / 2 : If t4*2 <> t3 : bit(4) = 1 : EndIf
t5 = t4 / 2 : If t5*2 <> t4 : bit(5) = 1 : EndIf
t6 = t5 / 2 : If t6*2 <> t5 : bit(6) = 1 : EndIf
t7 = t6 / 2 : If t7*2 <> t6 : bit(7) = 1 : EndIf
t8 = t7 / 2 : If t8*2 <> t7 : bit(8) = 1 : EndIf
result = bit(bitnum)
ProcedureReturn result
EndProcedure
Procedure.w AMOD(a.w,b.w)
;gibt ganzzahligen Restwert einer Division zurück
ProcedureReturn a - ((a/b)*b)
EndProcedure
Procedure mp3_info(_file.s)
;Variables globale créées par la fonction
Global mp3_title$, mp3_artist$, mp3_album$, mp3_year$, mp3_cmt$, mp3_track$, mp3_genre$, mp3_canaux$, mp3_samplerate$, mp3_bitrate$, mp3_duration$, mp3_emphase$, mp3_original$, mp3_copyright$, mp3_extension$, mp3_padding$, mp3_err_protection$, mp3_mpg_layer$, mp3_mpg_version$, mp3_mode_Ext$, mp3_framesize$, mp3_frames$, mp3_id_version$, mp3_id_size$
;ID-Tag :
mp3_title$ = "NON DISPONIBLE" ; Le Titre
mp3_artist$ = "NON DISPONIBLE" ; L'Artiste
mp3_album$ = "NON DISPONIBLE" ; L'Album
mp3_year$ = "NON DISPONIBLE" ; L'Année
mp3_cmt$ = "NON DISPONIBLE" ; Les Commentaires
mp3_track$ = "NON DISPONIBLE" ; Le Num du Titre sur le CD
mp3_genre$ = "NON DISPONIBLE" ; Le Genre
;Informations primaires :
mp3_canaux$ = "NON DISPONIBLE" ; Canaux = "Stereo", "Joint Stereo", "Dual Chanel", "Mono"
mp3_samplerate$ = "NON DISPONIBLE" ; Taux d'échantillonnage (kHz) = "16000", "22050", "24000", "32000", "44100", "48000", "Stream-Error"
mp3_bitrate$ = "NON DISPONIBLE" ; Bitrate (kBits/s)
mp3_duration$ = "NON DISPONIBLE" ; Durée (sec)
;Informations secondaires :
mp3_emphase$ = "NON DISPONIBLE" ; Emphase = "None", "50/15 microseconds", "Dunno", "CITT j.17"
mp3_original$ = "NON DISPONIBLE" ; Original = "Yes", "No"
mp3_copyright$ = "NON DISPONIBLE" ; Copyright = "Yes", "No"
mp3_extension$ = "NON DISPONIBLE" ; Extension = "None", "Privat"
mp3_padding$ = "NON DISPONIBLE" ; Remplissage = "Yes", "No"
mp3_err_protection$ = "NON DISPONIBLE" ; Protection contre les erreurs = "On", "Off"
mp3_mpg_layer$ = "NON DISPONIBLE" ; Couche MPG = "1", "2", "3", "?"
mp3_mpg_version$ = "NON DISPONIBLE" ; Version MPG = "1", "2", "2.5", "?"
mp3_mode_Ext$ = "NON DISPONIBLE" ; Fréquence de bandes = "0", "4", "8", "12", "16"
mp3_framesize$ = "NON DISPONIBLE" ; Taille d'une frame (Octet)
mp3_frames$ = "NON DISPONIBLE" ; Nbr de frames
mp3_id_version$ = "NON DISPONIBLE" ; Version de l'ID3V2
mp3_id_size$ = "NON DISPONIBLE" ; Taille de l'ID3V2 (Octet)
resultat = 0
If ReadFile(0, _file) = 0
resultat = 1
End
EndIf
HeaderStart.l = 0
FileSeek(0)
;Header suchen
;Fängt mit $FF an, und beginnnt nach einem möglichen ID3V2-Tag!
;Da $FF im ID3V2-Tag niemals vorkommen darf einfach danach suchen !
While Asc(Chr(ReadByte())) <> $FF
HeaderStart = HeaderStart + 1
Wend
If Headerstart > 0
; D-ebug "ID3V2-Tag Trouvé !"
EndIf
;in diesen 3 Bytes stehen alle Info's
Hbyte1.b = ReadByte()
Hbyte2.b = ReadByte()
Hbyte3.b = ReadByte()
;Byte 3
Select Str(ATestbit(Hbyte3,2)) + Str(ATestbit(Hbyte3,1))
Case "00" : Emp$ = "None"
Case "01" : Emp$ = "50/15 microseconds"
Case "10" : Emp$ = "Dunno"
Case "11" : Emp$ = "CITT j.17"
EndSelect
mp3_emphasis$ = Emp$
Select Str(ATestbit(Hbyte3,3))
Case "0" : Org$ = "No"
Case "1" : Org$ = "Yes"
EndSelect
mp3_original$ = Org$
Select Str(ATestbit(Hbyte3,4))
Case "0" : Cop$ = "No"
Case "1" : Cop$ = "Yes"
EndSelect
mp3_copyright$ = Cop$
Mex$ = Str(ATestbit(Hbyte3,6))+Str(ATestbit(Hbyte3,5))
Select Str(ATestbit(Hbyte3,8))+Str(ATestbit(Hbyte3,7))
Case "00" : Cha$ = "Stereo"
Case "01" : Cha$ = "Joint Stereo"
Case "10" : Cha$ = "Dual Chanel"
Case "11" : Cha$ = "Mono"
EndSelect
mp3_channels$ = Cha$
;Byte 2
Select Str(ATestbit(Hbyte2,1))
Case "0" : Ext$ = "None"
Case "1" : Ext$ = "Privat"
EndSelect
mp3_extension$ = Ext$
Select Str(ATestbit(Hbyte2,2))
Case "0" : Pad$ = "Yes"
Case "1" : Pad$ = "No"
EndSelect
mp3_padding$ = Pad$
Sam$ = Str(ATestbit(Hbyte2,4))+Str(ATestbit(Hbyte2,3))
Btr$ = Str(ATestbit(Hbyte2,8))+Str(ATestbit(Hbyte2,7))+Str(ATestbit(Hbyte2,6))+Str(ATestbit(Hbyte2,5))
;Byte 1
Select Str(ATestbit(Hbyte1,1))
Case "0" : Err$ = "On"
Case "1" : Err$ = "Off"
EndSelect
mp3_err_protection$ = Err$
Select Str(ATestbit(Hbyte1,3)) + Str(ATestbit(Hbyte1,2))
Case "00" : Layer$ = "?"
Case "01" : Layer$ = "3"
Case "10" : Layer$ = "2"
Case "11" : Layer$ = "1"
EndSelect
mp3_mpg_layer$ = Layer$
Select Str(ATestbit(Hbyte1,5)) + Str(ATestbit(Hbyte1,4))
Case "00" : Mpgversion$ = "2.5"
Case "01" : Mpgversion$ = "?"
Case "10" : Mpgversion$ = "2"
Case "11" : Mpgversion$ = "1"
EndSelect
mp3_mpg_version$ = Mpgversion$
Select Mpgversion$
Case "1"
Select Sam$
Case "00" : SampleRate$ = "44100"
Case "01" : SampleRate$ = "48000"
Case "10" : SampleRate$ = "32000"
Case "11" : SampleRate$ = "Stream-Error"
EndSelect
Case "2"
Select Sam$
Case "00" : SampleRate$ = "22050"
Case "01" : SampleRate$ = "24000"
Case "10" : SampleRate$ = "16000"
Case "11" : SampleRate$ = "Stream-Error"
EndSelect
EndSelect
mp3_samplerate$ = SampleRate$
Select Mpgversion$
Case "1"
Select Mex$
Case "00" : ModeExt$ = "4"
Case "01" : ModeExt$ = "8"
Case "10" : ModeExt$ = "12"
Case "11" : ModeExt$ = "16"
EndSelect
Case "2"
Select Mex$
Case "00" : ModeExt$ = "0"
Case "01" : ModeExt$ = "4"
Case "10" : ModeExt$ = "8"
Case "11" : ModeExt$ = "16"
EndSelect
EndSelect
mp3_mode_Ext$ = ModeExt$
;Bitraten-Tabellen
V1L1$ = "32,64,96,128,160,192,224,256,288,320,353,384,416,448,-1"
V1L2$ = "32,48,56,64,80,96,112,128,160,192,224,256,320,384,-1"
V1L3$ = "32,40,48,56,64,80,96,112,128,160,192,224,256,320,-1"
V2L1$ = "32,64,96,128,160,192,224,256,288,320,352,384,416,448,-1"
V2L2$ = "32,48,56,64,80,96,112,128,160,192,224,256,320,384,-1"
V2L3$ = "8,16,24,32,64,80,56,64,128,160,112,128,256,320,-1"
Liste$ ="0001,0010,0011,0100,0101,0110,0111,1000,1001,1010,1011,1100,1101,1110,1111"
If (Layer$ = "1") And (Mpgversion$ = "1")
Bitrate$ = StringField(V1L1$,((FindString(Liste$,Btr$,0)-1)/4)-1,",")
EndIf
If (Layer$ = "2") And (Mpgversion$ = "1")
Bitrate$ = StringField(V1L2$,((FindString(Liste$,Btr$,0)-1)/4)-1,",")
EndIf
If (Layer$ = "3") And (Mpgversion$ = "1")
Bitrate$ = StringField(V1L3$,((FindString(Liste$,Btr$,0)-1)/4)-1,",")
EndIf
If (Layer$ = "1") And (Mpgversion$ = "2")
Bitrate$ = StringField(V2L1$,((FindString(Liste$,Btr$,0)-1)/4)-1,",")
EndIf
If (Layer$ = "2") And (Mpgversion$ = "2")
Bitrate$ = StringField(V2L2$,((FindString(Liste$,Btr$,0)-1)/4)-1,",")
EndIf
If (Layer$ = "3") And (Mpgversion$ = "2")
Bitrate$ = StringField(V2L3$,((FindString(Liste$,Btr$,0)-1)/4)-1,",")
EndIf
mp3_bitrate$ = Bitrate$
;rechnen
If SampleRate$ ="Stream-Error"
resultat = 3
CloseFile(0)
End
EndIf
If Val(Bitrate$) > 0 And Val(SampleRate$) > 0
Sek.l = Int(Lof() * 8) / (Val(Bitrate$) *1000)
EndIf
mp3_duration$ = Str(Sek)
;Min = Sek/60
;Seks = AMOD(Sek,60)
;D-ebug "Time : "+Str(Sek/60)+":"+Str(AMOD(Sek,60))+" min"
Framesize.l = 144 * (Val(Bitrate$)*1000) / Val(Samplerate$) + Val(Pad$)
mp3_framesize$ = Str(Framesize)
If FrameSize > 0
Frames.l = (Lof()-128-Headerstart) / (Framesize)
EndIf
mp3_frames$ = Str(Frames)
;ID3V1-Tag auslesen , die letzten 128 Bytes der Datei
FileSeek(Lof()-128)
AllocateMemory(0,128,0)
ReadData(MemoryID(),128)
Tags$ = PeekS(MemoryID(),3)
If tags$ = "TAG"
;D-ebug PeekS(MemoryID(),3);TAG-Kennung
mp3_title$ = PeekS(MemoryID()+3,30)
mp3_artist$ = PeekS(MemoryID()+33,30)
mp3_album$ = PeekS(MemoryID()+63,30)
mp3_year$ = PeekS(MemoryID()+93,4)
mp3_cmt$ = PeekS(MemoryID()+97,29)
mp3_track$ = Str(PeekB(MemoryID()+126))
Restore Genre
For x = 0 To PeekB(MemoryID()+127)
Read Genre$
Next x
mp3_genre$ = Genre$
EndIf
FreeMemory(0)
;ID3V2-Tag auslesen! Variable Länge am Anfang der Datei.
;Das Ganze ist leider nicht ganz so einfach, da
;im Prinzip jedes Programm,das TAG's einfuegen kann,
;reinschreiben kann was es will !
;Es gibt zwar einige Vorgaben, aber das reicht bei weitem nicht aus !
;Alle nicht bekannten Frame-Formate werden mit "unbekannt"
;gekennzeichnet !
If Headerstart > 0
FileSeek(0);zum Anfang
;die ersten 10 Bytes einlesen
Dim bytes.b(9)
For x = 0 To 9 : Bytes(x) = ReadByte() : Next x
ID3Ident$ = Chr(Bytes(0))+Chr(Bytes(1))+Chr(Bytes(2))
;D-ebug ID3Ident$
ID3Version.l = Bytes(3)
ID3SubVersion.l = Bytes(4)
ID3Flags.l = Bytes(5)
mp3_id_version$ = Str(ID3Version)+"."+Str(ID3SubVersion)
;D-ebug ID3Flags
;die nächsten 4 Bytes sind die Längenangabe
;brauchen wir nicht da die Länge schon
;bekannt ist (Headerstart-1)
mp3_id_size$ = Str(Headerstart-1)
;Extendet Header vorhanden ?
;Ist der Header vorhanden verschieben sich die
;Frames um 6 Bytes nach hinten
ExtHeader.l = ATestbit(Bytes(5),6)
;D-ebug ExtHeader
;Frames auslesen
If Extheader > 0 : FrameStart = 16 : Else : FrameStart = 10 : EndIf
;unterschiedliche Behandlung der Versionen
;Versionen 3.x und 4.x bearbeiten
If ID3Version = 3 Or ID3Version = 4
DescriptPlus = 11
Repeat
FileSeek(FrameStart);zum Anfang
FrameID$ = Chr(ReadByte())+Chr(ReadByte())+Chr(ReadByte())+Chr(ReadByte())
;D-ebug FrameID$
FrameSize = ReadByte()*256*8*8
FrameSize + ReadByte()*256*8
FrameSize + ReadByte()*256
FrameSize + ReadByte()
DescriptionStart = FrameStart + DescriptPlus
If FrameSize <> 0 ; sonst Überlauf
FileSeek(DescriptionStart)
AllocateMemory(0,FrameSize,0)
ReadData(MemoryID(),FrameSize)
;Winamp schreibt da komisches Zeug rein
;wahrscheinlich einen Sprachbezeichner
;den brauchen wir nicht, also weg damit
Frame$ = PeekS(MemoryID(),FrameSize-1)
If FrameID$ = "COMM";Sprachbezeichner 3 Zeichen und NULLByte
Frame$ = PeekS(MemoryID()+4,FrameSize-1)
EndIf
If FrameId$ = "WXXX";Link fängt mit NULLByte an
Frame$ = PeekS(MemoryID()+1,FrameSize-1)
EndIf
FreeMemory(0)
Select FrameID$
Case "PCNT" : Framename$ = "Play Counter:"+Frame$
Case "TRCK" : Framename$ = "Track:"+Frame$
Case "TENC" : Framename$ = "Encoded von:"+Frame$
Case "WXXX" : Framename$ = "Link:"+Frame$
Case "TCOP" : Framename$ = "Copyright (c):"+Frame$
Case "TOPE" : Framename$ = "Ursprünglicher Künstler:"+Frame$
Case "TCOM" : Framename$ = "Composer:"+Frame$
Case "TCON" : Framename$ = "Genre:"+Frame$
Case "COMM" : Framename$ = "Kommentar:"+Frame$
Case "TYER" : Framename$ = "Jahr:"+Frame$
Case "TALB" : Framename$ = "Album:"+Frame$
Case "TPE1" : Framename$ = "Künstler:"+Frame$
Case "TIT2" : Framename$ = "Titel:"+Frame$
Case "TLAN" : Framename$ = "Sprache:"+Frame$
Case "TLEN" : Framename$ = "Länge:"+Frame$
Case "TMED" : Framename$ = "Medientyp:"+Frame$
Case "TPUB" : Framename$ = "Publisher:"+Frame$
Case "TSSE" : Framename$ = "Decoding-Software:"+Frame$
;Default : Framename$ = "unbekanntes Frame-Format:"+Frame$
EndSelect
;If Frame$ <> "" : Debug Framename$ : EndIf
EndIf
FrameStart + DescriptPlus + FrameSize -1
Until FrameID$ = "" Or FrameID$ = "3DI";NULL Oder Footer
EndIf
;Version 2.x bearbeiten
If ID3Version = 2
DescriptPlus = 6
FrameSize = 0
FrameStart = 10
Repeat
FileSeek(FrameStart);zum Anfang
FrameID$ = Chr(ReadByte())+Chr(ReadByte())+Chr(ReadByte())
FrameSize = 0
FrameSize + Asc(Chr(ReadByte()))*256*8
FrameSize + Asc(Chr(ReadByte()))*256
FrameSize + Asc(Chr(ReadByte()))
ReadByte()
If FrameSize > 0;sonst Überlauf
AllocateMemory(0,FrameSize-1,0)
ReadData(MemoryID(),FrameSize-1)
;Sprachbezeichner ausfiltern
Frame$ = PeekS(MemoryID(),Framesize-1)
For i = 1 To 4
If Mid(Frame$,i,1) = Chr(0)
Frame$ = PeekS(MemoryID()+4,Framesize-1)
EndIf
Next i
;Frame$ = PeekS(MemoryID(),FrameSize-1)
FreeMemory(0)
Select FrameID$
Case "TRK" : Framename$ = "Track:"+Frame$
Case "TEN" : Framename$ = "Encoded von:"+Frame$
Case "TCR" : Framename$ = "Copyright (c):"+Frame$
Case "TOA" : Framename$ = "Ursprünglicher Künstler:"+Frame$
Case "TCM" : Framename$ = "Composer:"+Frame$
Case "TCO" : Framename$ = "Genre:"+Frame$
Case "COM" : Framename$ = "Kommentar:"+Frame$
Case "TYE" : Framename$ = "Jahr:"+Frame$
Case "TAL" : Framename$ = "Album:"+Frame$
Case "TP1" : Framename$ = "Künstler:"+Frame$
Case "TT2" : Framename$ = "Titel:"+Frame$
Case "TLA" : Framename$ = "Sprache:"+Frame$
Case "TMT" : Framename$ = "Medientyp:"+Frame$
Case "TSS" : Framename$ = "Decoding-Software:"+Frame$
Default : Framename$ = "unbekanntes Frame-Format:"+Frame$
EndSelect
;If Frame$ <> "" : Debug Framename$ : EndIf
EndIf
FrameStart + Framesize + DescriptPlus
Until Framesize = 0
EndIf
EndIf
CloseFile(0)
ProcedureReturn resultat ; 0=IDtag trouvé, 1=Fichier non trouvé, 2=IDtag non trouvé, 3=Format de fichier défectueux !
EndProcedure
DataSection
Genre:
Data.s "Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", "Hip-Hop", "Jazz", "Metal"
Data.s "New Age", "Oldies", "Other", "Pop", "R&B", "Rap", "Reggae", "Rock", "Techno", "Industrial", "Alternative"
Data.s "Ska", "Death Metal", "Pranks", "Soundtrack", "Euro-Techno", "Ambient", "Trip-Hop", "Vocal", "Jazz Funk"
Data.s "Fusion", "Trance", "Classical", "Instrumental", "Acid", "House", "Game", "Sound Clip", "Gospel", "Noise"
Data.s "AlternRock", "Bass", "Soul", "Punk", "Space", "Meditative", "Instrumental Pop", "Instrumental Rock", "Ethnic"
Data.s "Gothic", "Darkwave", "Techno -Industrial", "Electronic", "Pop-Folk", "Eurodance", "Dream", "Southern Rock"
Data.s "Comedy", "Cult", "Gangsta", "Top 40", "Christian Rap", "Pop/Funk", "Jungle", "Native American", "Cabaret"
Data.s "New Wave", "Psychadelic", "Rave", "Showtunes", "TriGenreiler", "Lo-Fi", "Tribal", "Acid Punk", "Acid Jazz"
Data.s "Polka", "Retro", "MusiciGenrel", "Rock & Roll", "Hard Rock", "Folk", "Folk-Rock", "National Folk", "Swing"
Data.s "Fast Fusion", "Bebob", "Latin", "Revival", "Celtic", "Bluegrass", "Avantgarde", "Gothic Rock", "Progressive Rock"
Data.s "Psychedelic Rock", "Symphonic Rock", "Slow Rock", "Big Band", "Chorus", "Easy Listening", "Acoustic", "Humour"
Data.s "Speech", "Chanson", "Opera", "Chamber Music", "Sonata", "Symphony", "Booty Bass", "Primus", "Porn Groove", "Satire"
Data.s "Slow Jam", "Club", "Tango", "Samba", "Folklore", "Ballad", "Power Ballad", "Rhythmic Soul", "Freestyle", "Duet"
Data.s "Punk Rock", "Drum Solo", "A Capella", "Euro-House", "Dance Hall", "Goa", "Drum & Bass", "Club-House", "Hardcore"
Data.s "Terror", "Indie", "BritPop", "Negerpunk", "Polsk Punk", "Beat", "Christian Gangsta Rap", "Heavy Metal", "Black Metal"
Data.s "Crossover", "Contemporary Christian", "Christian Rock", "Merengue", "Salsa", "Thrash Metal", "Anime", "JPop", "Synthpop"
EndDataSection
