Autor Beitrag
Jogigonzo
Hält's aus hier
Beiträge: 1

Win 2000

BeitragVerfasst: Fr 14.10.05 21:50 
Hallo, wie kann ich den Startpunkt (Zeit) einer MP3 herausfinden. Also wo wirklich der erste Ton kommt und nicht (wenn vorhanden) die Stille des Liedes.


Moderiert von user profile iconChristian S.: Topic aus VCL (Visual Component Library) verschoben am Fr 14.10.2005 um 23:55
Flocke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54

Win 2000, Win XP, Win 2003, Linux
Delphi 2006 Prof.
BeitragVerfasst: Fr 14.10.05 21:56 
Das hängt stark von der Library bzw. den Tools ab, die du verwendest. Rein theoretisch solltest du die MP3-Datei in PCM umwandeln, also in richtige Samples, und dann mit einem bestimmten Schwellenwert vergleichen, weil man ein minimales Rauschen eigentlich immer hat.
Wishmaster
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34



BeitragVerfasst: Di 18.10.05 00:56 
Wen du mit der Bass.dll Arbeitest dann versuche mall folgenden Code! Getestet mit Bass.dll v2.1 ich weis nicht ob es auch mit Bass.dll v2.2 funzt.
Ich hoffe ich konnte dir weiter helfen.

Das ist nur für 16bit, 32Bit(BASS_SAMPLE_FLOAT) hat andre Parameter!

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
  private
    Start_Point    :   DWORD;
    End_Point     :   DWORD;



Procedure TAudioEngine.Get_SilenceLength_16Bit(FileName: string; threshold: Integer; var StartPoint, EndPoint: DWORD);
var
  a, b: Integer;
  pos, count, chan: DWORD;
  buf16: array[0..50000] of Smallint; 
  flags : DWORD;
begin
   count := 0;
   flags:=  BASS_STREAM_DECODE;

   chan:= (BASS_StreamCreateFile(FALSE, PChar(FileName), 0, 0,  flags));
        if (chan = 0) then
   chan:= (BASS_CD_StreamCreateFile(PChar(FileName), flags));
        if (chan = 0) then
   chan:= (BASS_FLAC_StreamCreateFile(False, PChar(FileName), 0, 0, flags));
        if (Channel_Song = 0) then
   chan:= (BASS_WMA_StreamCreateFile(False, PChar(FileName), 0, 0, flags));
        if (chan = 0) then
   chan:= (BASS_APE_StreamCreateFile(PChar(FileName), flags));
        if (chan = 0) then
   chan:= (BASS_MPC_StreamCreateFile(PChar(FileName), flags));
        if (chan = 0) then
   chan:= (BASS_WV_StreamCreateFile(PChar(FileName),  flags));
        if (chan = 0) then
   chan:= (BASS_OFR_StreamCreateFile(PChar(FileName), flags));
        if (chan = 0) then
   chan:= (BASS_LA_StreamCreateFile(PChar(FileName),  flags));
        if (chan = 0) then
   chan:= (BASS_AAC_StreamCreateFile(PChar(FileName), flags));
        if (chan = 0) then
   chan:= (BASS_MP4_StreamCreateFile(PChar(FileName), flags));

   
  if chan = 0 then
    Exit;

  while Bass_ChannelIsActive(chan) <> 0 do
   begin
    b := BASS_ChannelGetData(chan, @buf16, 20000);
    b := b div 2;
    a := 0;
    while (a < b) and (Abs(buf16[a]) <= threshold) do
      a := a + 1;
    count := count + (a * 2);
    if (a < b) then
     begin
      while (a <> 0) and (Abs(buf16[a]) > (threshold div 4)) do
       begin
        a := a - 1;
        count := count - 2;
      end;
      Break;
    end;
  end;
  StartPoint := count;  // Start-Point ready

  pos := BASS_StreamGetLength(chan);
  while (pos > count) do
   begin
    if pos < 100000 then
      pos := 0
    else
      pos := pos - 100000;
    BASS_ChannelSetPosition(chan, pos);
    b := BASS_ChannelGetData(chan, @buf16, 100000);
    b := b div 2;
    a := b;
    while (a > 0) and (Abs(buf16[a - 1]) <= (threshold div 2)) do
       a := a - 1;
    if a > 0 then
     begin
      count := pos + (a * 4);
      Break;
    end;
  end;
  EndPoint := Count;   // End-Point ready
  BASS_StreamFree(chan);
end;



Procedure Load_File(FileName : String)
begin


   //  Read  Silence Length
  if FRemoveSilence then
    begin
     if Use_Floatingpoint then
        Get_SilenceLength_32Bit(Pchar(FileName), 500, Start_Point, End_Point)
      else
        Get_SilenceLength_16Bit(Pchar(FileName), 500, Start_Point, End_Point);
    end;



procedure SongEndSync(SyncHandle : HSYNC; Channel, data, user : DWORD); stdcall;
var pos : Qword;
begin
 with AudioPlayer do
  begin
   BASS_ChannelStop(Channel_Song);
   Player_State:= ENGINE_SONG_END;
 end;
end;



procedure TAudioEngine.Play();
begin


    if BASS_ChannelPlay(Channel_Song, true) then
      begin



   if FRemoveSilence then
    begin
      BASS_ChannelRemoveSync(Channel_Song, SyncEnd);
      BASS_ChannelSetPosition(Channel_Song, Start_Point);
      SyncEnd:= BASS_ChannelSetSync(Channel_Song, BASS_SYNC_POS or BASS_SYNC_MIXTIME, End_Point, @SongEndSync, 0);
    end
  else



BASS_MP3_SETPOS Enable pin-point accurate seeking (to the exact byte) on the MP3/MP2/MP1 stream. This also increases the time taken to create the stream, due to the entire file being pre-scanned for the seek points.
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Di 18.10.05 01:44 
oder einfach nach dem mp3 frame header suchen-
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
// code aus kolacmwaveplayer.pas von thaddy de koning - www.thaddy.com
    try
      getmem(buf, bufSize); // buf: PbyteArray
      repeat
        FDataStart:=FSource.Position; // Fsource: TFileStream , FdataStart: integer
        j:=FSource.Read(buf^, bufSize);
        for i:=0 to j-5 do
          if (buf^[i] = $FF) and
             (buf^[i+1] and $F0 = $F0) and
             (buf^[i+1] and 6 <> 0) and
  // retnyg: additional check for bad bitrate index
  // (caused div by zero with an $FFFFFFFF frame, found in a musicmatch made mp3
  // -  do they want to crash the other players ? ;)
             (buf^[i+2] and $F0 <> $F0) and
             (buf^[i+2] and $F0 <> 0)
              then
             //OK, it looks like frame we are looking for
             begin
               frame:=PDWORD(longint(buf)+i)^;
               FDataStart:=FDataStart+i;
               j:=0;
               break;
             end;
        if j<>0 then FSource.Seek(-3, spCurrent);
      until j = 0;
    finally
      if buf<>nil then freemem(buf);
    end;