Einzelnen Beitrag anzeigen

Wishmaster

Registriert seit: 14. Sep 2002
Ort: Steinbach, MB, Canada
301 Beiträge
 
Delphi XE2 Architect
 
#5

Re: Stille aus Wave-Dateien entfernen?

  Alt 19. Jun 2009, 12:32
Hi


Delphi-Quellcode:
function Channel_Get_SilenceLength_16Bit(FileName : String; Pinpoint : Boolean; Threshold : QWORD; var StartPoint, EndPoint : DWORD) : Bool; stdcall;
var
  a, b: Integer;
  pos, count, chan: DWORD;
  buf16: array[0..50000] of Smallint; // 100% OK.
  flag : DWORD;
begin
   result:= false;
   count := 0;
   flag:= BASS_STREAM_DECODE; //BASS_STREAM_DECODE or BASS_STREAM_AUTOFREE

     if Pinpoint then
       flag:= flag or BASS_STREAM_PRESCAN;

     Chan:= BASS_StreamCreateFile(FALSE, PChar(FileName), 0, 0, Flag);
  if Chan = 0 then
     Chan:= BASS_MusicLoad(False, PChar(FileName), 0, 0, Flag or BASS_MUSIC_NOSAMPLE, 0);
  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_ChannelGetLength(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_MusicFree(Chan);
 BASS_StreamFree(Chan);
 Result:= true;
end;


function Channel_Get_SilenceLength_32Bit(FileName : String; Pinpoint : Boolean; Threshold : QWORD; var StartPoint, EndPoint : DWORD) : boolean; stdcall;
var
  a, b: Integer;
  pos, count, chan: DWORD;
  buf32: array[0..50000] of Float; //Single
  flag : DWORD;
begin
   Result:= false;

   Flag:= BASS_STREAM_DECODE or BASS_SAMPLE_FLOAT;

  if Pinpoint then
   Flag:= Flag or BASS_STREAM_PRESCAN;


     Chan:= (BASS_StreamCreateFile(FALSE, PChar(FileName), 0, 0, Flag));
  if Chan = 0 then
     Chan:= BASS_MusicLoad(False, PChar(FileName), 0, 0, Flag or BASS_MUSIC_NOSAMPLE, 0);
  if Chan = 0 then
    Exit;

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

    pos := BASS_ChannelGetLength(chan);
  while (pos > count) do
   begin
    if pos < 100000 then
      pos := 0
    else
      pos := pos - 100000;
      BASS_ChannelSetPosition(chan, pos);
      b := BASS_ChannelGetData(chan, @buf32, 100000);
      b := b div 4; // 16Bit = 2 | 32Bit = 4
      a := b;
    while (a > 0) and (Abs(buf32[a - 1]) <= (Threshold div 2) / 32768) do
      a := a -1;
    if a > 0 then
     begin
      count := pos + (a * 8); //8=2
      Break;
    end;
  end;
  EndPoint := Count; // End-Point ready
  BASS_MusicFree(Chan);
  BASS_StreamFree(chan);
  Result:= true;
end;
  Mit Zitat antworten Zitat