Page 1 of 1

Posted: Tue Jan 28, 2003 8:41 pm
by BackupUser
Restored from previous forum. Originally posted by ricardo.

Hi,

Maybe some one already has some code to read mp3 header info.

I was trying to use some dll but it crashes.

The structure in which i receive the info has some string * 20, etc.
And if i try to make the PB structure with .b[20] when i run it it crashes.

The german comments are not mine, was on the original VB code:

Code: Select all

Structure mpgstruct
    ValidHeader .w  ; 0=ungültiger Header, 1=gültiger Header
    MpegID .w       ; 0=reserviert, 1=MPEG 1.0, 2=MPEG 2.0, 3=MPEG 2.5
    Layer .w        ; 0=unbekannt, 1=Layer 1, 2=Layer 2, 3=Layer 3
    CRC .w          ; 0=nein, 1=ja
    Bitrate .w      ; 0=reserviert, >0=Bitrate in kbit/s
    Samplerate .l      ; Samplerate in Hz
    Padding .w      ; 0=nein, 1=ja
    Private .w      ; 0=nein, 1=ja
    Stereomode .w   ; 0=Stereo, 1=Joint Stereo, 2=Zweikanal, 3=Mono
    ExtendedMode .w ; Werte von 0-3
    Copyright .w    ; 0=nein, 1=ja
    Original .w     ; 0=nein, 1=ja
    Emphasis .w     ; 0=keine, 1=50/15ms, 2=unbekannt, 3=CCITT j.17
    Duration .l        ; Gesamtspielzeit in Sekunden z.B. 210 Sekunden
    Minutes .w      ; Spielzeit in Minuten        z.B.   3 Minuten
    Seconds .w      ; Spielzeit in Sekunden       z.B.  30 Sekunden
    HeaderPos .l       ; Anfangsposition des Headers
    Framelength .l     ; Framelänge
    FrameCount .l      ; Anzahl Frames
    FileSize .l        ; Filelänge in Bytes
    VBR .w          ; 0=kein VBR, 1=VBR (variable Bitrate z.B.Xing)
    ID3V1Header .w  ; 0=kein Header, 1=ID3V1.0 Header, 2=ID3V1.1 Header
    ID3V2Header .w  ; 0=kein ID3V2 Header, 1=ID3V2 Header vorhanden
    ID3V2Pos .l        ; Anfangsposition des ID3v2-Headers
    Lyrics .w       ; 0=kein Lyrics3-Tag, 1=Lyrics3 Vers.1.0 vorhanden, 2=Lyrics3 Vers.2.0 vorhanden
    LyricsPos .l       ; Anfangsposition des Lyrics3-Tag (zeigt auf "LYRICSBEGIN")
    ; Nun kommen die ID3v1 Informationen mit Space aufgefüllt!
    ; eventuell gelesene Null-Byte-Zeichen ( CHR$(0) ) wurden durch Space ersetzt!
    Title .b[30]   ; Titel
    Artist .b[30]   ; Interpret
    Album .b[30]    ; Album
    Year .b[4]     ; Jahr
    Comment .b[30]  ; Kommentar
    Genre .b[30]    ; Musik-Genre als Text ( unterstützt Winamp-Genres)
    GenreID .w      ; Genre-Index, -1 = kein Genre, 0 - 148
    TrackNr .w      ; Track-Nr ( nur bei ID3V1.1 )

EndStructure

mpg.mpgstruct

File$ = "c:\windows\escritorio\PoliceCorto.mp3"

If OpenLibrary(0, "MP3reader.dll") 
   *F = IsFunction(0, "Mp3FileInfo")
  If *F
    If CallFunctionFast(*F,File$,@mpg)
      MessageRequester("Info",Str(mpg/Bitrate),0)
    Else
      MessageRequester("FAIL","",0)
    EndIf
  EndIf
  CloseLibrary(0)
EndIf
End
I try to substitute the .b[20] just by a string but crashes too.

The dll could be found at http://www.toengi.de


Best Regards

Ricardo

Dont cry for me Argentina...

Posted: Tue Jan 28, 2003 10:03 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.

I've read in the manual that you must use .s[20], not .b[20], why don't give it a try?

El_Choni

Posted: Tue Jan 28, 2003 10:11 pm
by BackupUser
Restored from previous forum. Originally posted by freak.

El_Choni:

.s[20] would store 20 Pointers to 20 different Strings in the Structure. Do you think that this is right?
I don't think, a MP3 can have 20 Titles :)

.b[20] should be right. There must be some other reason for it to crash.

Timo

Posted: Tue Jan 28, 2003 11:15 pm
by BackupUser
Restored from previous forum. Originally posted by benny.

Hi,

maybe this thread from the german forum helps you. Although it is in german the code-bits could be helpful for you.

http://www.shadow-studios.net/phpBB/vie ... php?t=1525

Greetz, benny!

Posted: Tue Jan 28, 2003 11:21 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.

You talk about .b[20] when everywhere in the structure the code says .b[30] which is right? And could you post the VB structure so we can verify that the translation to PB is correct?

Posted: Wed Jan 29, 2003 12:27 am
by BackupUser
Restored from previous forum. Originally posted by El_Choni.

shouldn't mpg/Bitrate be mpg\Bitrate?

El_Choni

Posted: Wed Jan 29, 2003 2:15 am
by BackupUser
Restored from previous forum. Originally posted by ricardo.

Yes the / was wrong but it was a typo here in the forum, dosent make difference: crash anyway.
Originally posted by Pupil

You talk about .b[20] when everywhere in the structure the code says .b[30] which is right? And could you post the VB structure so we can verify that the translation to PB is correct?
I said [20] just to show what im trying to do.

The VB code needed to run the dll is so simple:

Code: Select all

' Die vorgegene Struktur-Reihenfolge NICHT verändern! 226 Bytes gross
' Die Variablen-Namen können natürlich verändert werden
Type mpgstruct
    ValidHeader As Integer  ' 0=ungültiger Header, 1=gültiger Header
    MpegID As Integer       ' 0=reserviert, 1=MPEG 1.0, 2=MPEG 2.0, 3=MPEG 2.5
    Layer As Integer        ' 0=unbekannt, 1=Layer 1, 2=Layer 2, 3=Layer 3
    CRC As Integer          ' 0=nein, 1=ja
    Bitrate As Integer      ' 0=reserviert, >0=Bitrate in kbit/s
    Samplerate As Long      ' Samplerate in Hz
    Padding As Integer      ' 0=nein, 1=ja
    Private As Integer      ' 0=nein, 1=ja
    Stereomode As Integer   ' 0=Stereo, 1=Joint Stereo, 2=Zweikanal, 3=Mono
    ExtendedMode As Integer ' Werte von 0-3
    Copyright As Integer    ' 0=nein, 1=ja
    Original As Integer     ' 0=nein, 1=ja
    Emphasis As Integer     ' 0=keine, 1=50/15ms, 2=unbekannt, 3=CCITT j.17
    Duration As Long        ' Gesamtspielzeit in Sekunden z.B. 210 Sekunden
    Minutes As Integer      ' Spielzeit in Minuten        z.B.   3 Minuten
    Seconds As Integer      ' Spielzeit in Sekunden       z.B.  30 Sekunden
    HeaderPos As Long       ' Anfangsposition des Headers
    Framelength As Long     ' Framelänge
    FrameCount As Long      ' Anzahl Frames
    FileSize As Long        ' Filelänge in Bytes
    VBR As Integer          ' 0=kein VBR, 1=VBR (variable Bitrate z.B.Xing)
    ID3V1Header As Integer  ' 0=kein Header, 1=ID3V1.0 Header, 2=ID3V1.1 Header
    ID3V2Header As Integer  ' 0=kein ID3V2 Header, 1=ID3V2 Header vorhanden
    ID3V2Pos As Long        ' Anfangsposition des ID3v2-Headers
    Lyrics As Integer       ' 0=kein Lyrics3-Tag, 1=Lyrics3 Vers.1.0 vorhanden, 2=Lyrics3 Vers.2.0 vorhanden
    LyricsPos As Long       ' Anfangsposition des Lyrics3-Tag (zeigt auf "LYRICSBEGIN")
    ' Nun kommen die ID3v1 Informationen mit Space aufgefüllt!
    ' eventuell gelesene Null-Byte-Zeichen ( CHR$(0) ) wurden durch Space ersetzt!
    Title As String * 30    ' Titel
    Artist As String * 30   ' Interpret
    Album As String * 30    ' Album
    Year As String * 4      ' Jahr
    Comment As String * 30  ' Kommentar
    Genre As String * 30    ' Musik-Genre als Text ( unterstützt Winamp-Genres)
    GenreID As Integer      ' Genre-Index, -1 = kein Genre, 0 - 148
    TrackNr As Integer      ' Track-Nr ( nur bei ID3V1.1 )
End Type
 ' Dimensionierung der Struktur zum Ansprechen
Global mpg As mpgstruct
 ' Platz für Dateiname
Global Datei As String
 ' Die Declaration des DLL-Aufrufes (Pfad evtl anpassen!)
Declare Sub Mp3FileInfo Lib "MP3READER.DLL" (ByVal FileName$, lpmpg As mpgstruct)

Mp3FileInfo Datei, mpg

But in fact i will try better to read it directly from the file

The header is this one:

Structure MpgHeader
FrameSync.b[11]
AudioVersion.b[2]
MpegLayer.b[2]
Protection.b
BitRate.b[4]
SampleRate.b[2]
Padding.b
PrivateBit.b
Channels.b[2]
Mode.b[2]
Copyright.b
Original.b
Emphasis.b[2]
EndStructure

How is the best way to read it?

Code: Select all

If ReadFile(0,File$)
  If AllocateMemory(0,32)
      MemPointer=UseMemory(0)
      FileSeek(140)
      ReadData(MemPointer, 32)      
  EndIf
CloseFile(0)
EndIf
and then trying to peek every one?

BitRate.l = Val(PeekS(MemPointer + 16,4))

Or trying to read it in the structure?

One note: Not always the first byte of the file is the first file of a header, usually there are 100 or more bytes with only ceros, then we have to find the start of the file and then read the header. I say this because if someone want to try at home could get only ceros if read at the start of the file.

Is there some ASM code to achieve this very fast?







Best Regards

Ricardo

Dont cry for me Argentina...