Author Topic: Silence Detection with DELPHI  (Read 179 times)

johnvantelli

  • Posts: 97
Silence Detection with DELPHI
« on: 18 Oct '24 - 18:05 »
hi everybody
I'm trying to translate in delphi the Silence detection code I've found in this forum
with no results

this is my code:

Code: [Select]
function TSong.DetectStartingPosition: QWORD;
var
  buf: array [0 .. 299999] of SmallInt;
  count: DWORD;
  a, b: integer;
  thres: SmallInt;
begin
  thres := 400;
  count := 0;
  while BASS_ChannelIsActive(fStream) <> 0 do
  begin
    b := BASS_ChannelGetData(fStream, @buf, SizeOf(buf));
    b := b div 2;
    a := 0;

    while (a < b) and (Abs(buf[a]) <= thres) do
      inc(a);

    count := count + a * 2;

    if a < b then
    begin
      while (a > 0) and (Abs(buf[a - 1]) > thres div 4) do
      begin
        Dec(a);
        count := count - 2;
      end;
      Break;
    end;
  end;

  result := count;

end;

the problem is that the returned value is always 0.
is there anyone that have a simple delphi code to post for me to get a cue point position?

Thanks

johnvantelli

  • Posts: 97
Re: SOLVED - Silence Detection with DELPHI
« Reply #1 on: 19 Oct '24 - 16:20 »
(self) SOLVED...
this is my code

Code: [Select]
function DetectStartingPosition: QWORD;
var
  buf: array [0 .. 4999] of single;
  count, totalSamples: QWORD;
  a, b: integer;
  thres: single;
  streamLength: QWORD;

begin

  FillChar(buf, SizeOf(buf), 0);
  thres := 0.005;
  count := 0;

  streamLength := self.duration;
  totalSamples := streamLength div 4;

  while (BASS_ChannelIsActive(fStream) <> 0) and (count < totalSamples) do
  begin
    b := BASS_ChannelGetData(fStream, @buf, SizeOf(buf));
    b := b div SizeOf(single);
    a := 0;

    while (a < b) and (Abs(buf[a]) <= thres) do
      inc(a);

    count := count + a * SizeOf(single);

    if a < b then
    begin
      while (a > 0) and (Abs(buf[a - 1]) > thres / 4) do
      begin
        Dec(a);
        count := count - SizeOf(single);
      end;
      Break;
    end;
  end;

  result := count;
end;