mp3 a jej header - lazarus (delphi)

Programovacie jazyky, rady, poradňa...
paralen
Light Star
Light Star
Príspevky: 267
Registrovaný: 02 máj 2006, 15:15

mp3 a jej header - lazarus (delphi)

Príspevok od používateľa paralen »

Zdravim
Potrebujem z mp3 suboru vycitat bitrate. Snazim sa ho citat z hlavicky, ktora ma 32 bitov a ten udaj o bitrate by mal byt na pozicii 15-12(cize 4bity) podla toho tu http://www.datavoyage.com/mpgscript/mpeghdr.htm

Zatial som napisal toto :

Kód: Vybrať všetko

var fmp3: TFileStream;
    i:integer;    
    Buffer:array[1..32] of char;
    bitrate:string;
begin
  try
   fmp3:=TFileStream.Create(mp3File, fmOpenRead); 
   fmp3.Seek(0,fsfrombeginning);
   fmp3.Read(Buffer, SizeOf(Buffer));
  finally
    fmp3.free;
  end;

   for i:=15 downto 12 do
     begin
     Bitrate:=bitrate+ inttostr(ord(Buffer[i]));
     end;
   showmessage(Bitrate);
Ako z tohto cisla "bitrate" dostanem tie 4 bity , tj napr. 1100 atd...
Alebo co robim zle? A ako sa k tomu bitrate dostat ?
audiotrack
VIP
VIP
Používateľov profilový obrázok
Príspevky: 25958
Registrovaný: 09 sep 2005, 18:39
Kontaktovať používateľa:

Príspevok od používateľa audiotrack »

nebude to také jednoduché ako si myslíš, lebo to záleží aj od layeru a mpeg verzie. Ďalšia vec je že to zle čítaš, skús s tým narábať ako s klasickým súborom (otvoriť cez reset) a čítať pomocou blockread. Ak chceš, niekde to mám naprogramované a môžem ti to sem hodiť
paralen
Light Star
Light Star
Príspevky: 267
Registrovaný: 02 máj 2006, 15:15

Príspevok od používateľa paralen »

jasne ked mozes hod to sem, budem rad :)
audiotrack
VIP
VIP
Používateľov profilový obrázok
Príspevky: 25958
Registrovaný: 09 sep 2005, 18:39
Kontaktovať používateľa:

Príspevok od používateľa audiotrack »

je to ako komponenta a nie teda nejaká procedúra, ale dokážeš z toho vyzistiť čo ti treba:

Kód: Vybrať všetko

{Copyright (C) 2002 by TRIDENT-Soft
Diese Komponente ermittelt MPEG-Version, Layer,
Bitrate und Frequenz in Hz von MP3-Dateien.
 FileName     : Dateiname
 function Get : liest die Daten (liefert 0 zurück, wenn erfolgreich)
}
unit MP3Info;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TMP3Info = class(TComponent)
  private
    DN : String;
    procedure SetDN(S:String);
    { Private-Deklarationen }
  protected
    { Protected-Deklarationen }
  public
    Layer,
    MPEGVer   : Byte;
    Frequency,
    Bitrate   : Word;
    { Public-Deklarationen }
  published
    { Published-Deklarationen}
    function Get:Byte;
    property Filename : String read DN write SetDN;
  end;

procedure Register;

implementation
const
bitraten:array[1..2,1..3,1..14] of word =
              (((32,64,96,128,160,192,224,256,288,320,352,384,416,448),
              (32,48,56,64,80,96,112,128,160,192,224,256,320,384),
              (32,40,48,56,64,80,96,112,128,160,192,224,256,320)),
              ((32,48,56,64,80,96,112,128,144,160,176,192,224,256),
              (8,16,24,32,40,48,56,64,80,96,112,128,144,160),
              (8,16,24,32,40,48,56,64,80,96,112,128,144,160)));
freq    :array[1..2,0..2] of word =((44100,48000,32000),(22050,24000,16000));

procedure TMP3Info.SetDN(S:String);
begin
  DN:=S;
end;

function TMP3Info.Get:Byte;
var
 f:file;
 s1,s2,s3,x:byte;
begin
 Result:=0;
 if fileexists(dn)=false then begin Result:=1; exit; end;
 assignfile(f,DN);
 reset(f,1);
 blockread(f,s1,1);
 blockread(f,s2,1);
 blockread(f,s3,1);
 closefile(f);
 {MPEG Version}
 if s2 and 16 = 16 then mpegver:=1 else mpegver:=2;
 {Layer}
 if (s2 and 32 = 32) and (s2 and 64 <> 64) then layer:=1;
 if (s2 and 32 = 32) and (s2 and 64 =  64) then layer:=3;
 if (s2 and 32 <> 32) and (s2 and 64 = 64) then layer:=2;
 {Bitrate}
 x:=0;
 if s3 and 128 = 128 then x:=x+8;
 if s3 and  64 = 64  then x:=x+4;
 if s3 and  32 = 32  then x:=x+2;
 if s3 and  16 = 16  then x:=x+1;
 Bitrate:=bitraten[mpegver,layer,x];
 {Sample-Frequenz}
 x:=0;
 if s3 and 8 = 8 then x:=x+1;
 if s3 and 4 = 4 then x:=x+2;
 Frequency:=freq[mpegver,x];
end;

procedure Register;
begin
  RegisterComponents('Z2', [TMP3Info]);
end;

end.
paralen
Light Star
Light Star
Príspevky: 267
Registrovaný: 02 máj 2006, 15:15

Príspevok od používateľa paralen »

dik, ale zistuje mi to nejak blbo... vlozil som si to do svojej procedury takto (mam samozrejme aj deklarovane konstatny)

Kód: Vybrať všetko

 assignfile(f,mp3file);
 reset(f,1);
 blockread(f,s1,1);
 blockread(f,s2,1);
 blockread(f,s3,1);
 closefile(f);
 {MPEG Version}
 if s2 and 16 = 16 then mpegver:=1 else mpegver:=2;
 {Layer}
 if (s2 and 32 = 32) and (s2 and 64 <> 64) then layer:=1;
 if (s2 and 32 = 32) and (s2 and 64 =  64) then layer:=3;
 if (s2 and 32 <> 32) and (s2 and 64 = 64) then layer:=2;
 {Bitrate}
 x:=0;
 if s3 and 128 = 128 then x:=x+8;
 if s3 and  64 = 64  then x:=x+4;
 if s3 and  32 = 32  then x:=x+2;
 if s3 and  16 = 16  then x:=x+1;
 Bitrate:=bitraten[mpegver,layer,x];
 {Sample-Frequenz}
 x:=0;
 if s3 and 8 = 8 then x:=x+1;
 if s3 and 4 = 4 then x:=x+2;
 Frequency:=freq[mpegver,x];

 showmessage(inttostr(bitrate)); 
Skusal som iba CBR mp3jky a napr. namiesto 320 mi ukazuje 20 alebo namiesto 128 mi vypise 24 :?
chrono
VIP
VIP
Používateľov profilový obrázok
Príspevky: 7127
Registrovaný: 25 dec 2006, 15:17

Príspevok od používateľa chrono »

20 v tej tabuľke pre bitrate ani nevidím. :)
paralen
Light Star
Light Star
Príspevky: 267
Registrovaný: 02 máj 2006, 15:15

Príspevok od používateľa paralen »

:oops: blbo som videl... teraz som skusil asi 10 mp3 ... a vypisuje iba 24 :?
chrono
VIP
VIP
Používateľov profilový obrázok
Príspevky: 7127
Registrovaný: 25 dec 2006, 15:17

Príspevok od používateľa chrono »

Pravdepodobne je na začiatku toho súboru ID3 tag (a teda ho musíš preskočiť a až potom zisťovať tie údaje).
paralen
Light Star
Light Star
Príspevky: 267
Registrovaný: 02 máj 2006, 15:15

Príspevok od používateľa paralen »

Ano mas pravdu, mp3, ktore nemaju ID3 tag tak u nich to funguje.
Ach musim nejake preskocit ten ID3v2 tag, len skoda, ze ma nejak variabilnu dlzku, no nic idem studovat specifikaciu :?
Napísať odpoveď