Wie liest man den ohne ID3-Tag (also nur Mp3-Header-Frames) die korrekten Werte aus ?
Bei CBR (konstanter Bitrate) müsste doch die Bitrate immer konstant sein, oder ?
Code: Alles auswählen
Macro FillArray(name, count, items)
For i=1 To CountString(items,",")+1
name(count, i-1)=Val(StringField(items,i,","))
Next
EndMacro
Procedure Testbit(val,bitnum)
;gibt Bitwert zurück
Global 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 ReadMp3(fname.s)
Protected cbyte.c = 0, tbyte.c = 255, tbit.s, fpos.q = 0, start.b = #False
Protected fhpos.i = 0
Protected mpegversion.i, layer.i, protectbit.i, bitrate.i, frequency.i
Protected Dim brt.i(1, 15) ;BitRateTable
Protected Dim ft.i(1, 3) ;FrequencyTable
FillArray(brt, 0, "0,32,40,48,56,64,80,96,112,128,160,192,224,256,320,-1")
FillArray(brt, 1, "0,8,16,24,32,64,80,56,64,128,160,112,128,256,320,-1")
FillArray(ft, 0, "22050,24000,16000,0")
FillArray(ft, 1, "44100,48000,32000,0")
If ReadFile(0, fname, #PB_Ascii)
StepFrame:
Repeat
cbyte = ReadCharacter(0, #PB_Ascii)
;Debug cbyte
;Laaangsam und mit Fragezeichen
tbit = "%"+Str(Testbit(cbyte, 1))+Str(Testbit(cbyte, 2))+Str(Testbit(cbyte, 3))+Str(Testbit(cbyte, 4))+Str(Testbit(cbyte, 5))+Str(Testbit(cbyte, 6))+Str(Testbit(cbyte, 7))+Str(Testbit(cbyte, 8))
If Val(tbit) = 255
;Sync
cbyte = ReadCharacter(0, #PB_Ascii)
tbit = "%"+Str(Testbit(cbyte, 1))+Str(Testbit(cbyte, 2))+Str(Testbit(cbyte, 3))
If Val(tbit) = 7
start = #True
EndIf
EndIf
Until start = #True
;Frameheader
fpos = Loc(0)
fpos - 2
fhpos = fpos
Debug "1. Frame bei: "+Str(fhpos)
;MPEG-Version
If Testbit(cbyte, 4) = 1 And Testbit(cbyte, 5) = 1
Debug "MPEG 1 "
mpegversion = 1
ElseIf Testbit(cbyte, 4) = 0 And Testbit(cbyte, 5) = 1
Debug "MPEG 2 "
mpegversion = 0
EndIf
;Layer
If Testbit(cbyte, 6) = 1 And Testbit(cbyte, 7) = 0
Debug "Layer III"
layer = 3
ElseIf Testbit(cbyte, 6) = 0 And Testbit(cbyte, 7) = 1
Debug "Layer II"
layer = 2
ElseIf Testbit(cbyte, 6) = 1 And Testbit(cbyte, 7) = 1
Debug "Layer I"
layer = 1
EndIf
Debug "Layer: "+ Str(layer)
If layer > 3
Debug "Keine gültige Mp3-Datei!"
EndIf
;CRC Prüfung
protectbit = Testbit(cbyte, 8)
If protectbit
Debug "CRC: No"
Else
Debug "CRC: Yes"
EndIf
;Nächstes Byte
cbyte = ReadCharacter(0, #PB_Ascii)
;Bitrate
tbit = "%"+Str(Testbit(cbyte, 1)) + Str(Testbit(cbyte, 2)) + Str(Testbit(cbyte, 3)) + Str(Testbit(cbyte, 4))
If layer > 0 And layer <= 3
bitrate = brt(mpegversion, Val(tbit))
EndIf
Debug "Bitrate: "+Str(bitrate)
;Frequenz
tbit = "%"+Str(Testbit(cbyte, 5))+Str(Testbit(cbyte, 6))
If layer > 0 And layer <= 3
frequency = ft(mpegversion, Val(tbit))
EndIf
Debug "Frequenz: "+Str(frequency)
;Nächste 2 Bytes
cbyte = ReadCharacter(0, #PB_Ascii)
cbyte = ReadCharacter(0, #PB_Ascii)
;Suche den nächsten Frame-Header
start = #False
; If Not Eof(0)
; Goto StepFrame
; EndIf
CloseFile(0)
EndIf
EndProcedure
media.s = OpenFileRequester("Mp3 Suche!", "*.mp3", "Mp3|*.mp3", 0)
ReadMp3(media)