24 May '13 - 09:32 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: NormalizeDSP not work flag BASS_SAMPLE_FLOAT ??  (Read 673 times)
Salvo
Posts: 41


« on: 23 May '12 - 16:55 »
Reply with quoteQuote

Quote
function TfEncode.GetPeak(Channel: DWORD): Float;
var
  i, d: Integer;
  Peak:Float;
  buf: Array[0..50000] of Float;
begin
  Peak:= 0;
  while   (BASS_ChannelIsActive(Channel) <> 0) do begin
    d:= BASS_ChannelGetData(Channel, @buf, SizeOf(buf));
    d:= d div 4;
    for   i:= 0 to d-1 do
      if (peak < Abs(buf)) then peak:= Abs(buf);
  end;
  Result:= Peak;
end;

procedure NormalizeDSP(Handle: HDSP; Channel: DWORD; Data: Pointer; Length: DWORD; Peak: DWORD); Stdcall;
var
  d: ^Float;
  i: Integer;
begin
  d := Data;
  for i := 0 to (Length div 4) -1 do begin
    d^ := d^ / peak;
    Inc(d);
  end;
end;

...
//This code is for 32-Bit Floating Point:
{ Main - ScanPeak for normalize: }
EnChan:= BASS_StreamCreateFile(False, PChar('temp.mp3'), 0, 0, (BASS_SAMPLE_FLOAT or BASS_STREAM_DECODE));
Peak:= GetPeak(EnChan);

BASS_ChannelSetPosition(EnChan, 0, BASS_POS_BYTE);
Normdsp:= BASS_ChannelSetDSP(EnChan, @NormalizeDSP, Pointer(Peak), 0);
EncHandle:= BASS_Encode_Start(EnChan, PChar(CmdStr), (BASS_ENCODE_FP_32BIT or BASS_ENCODE_AUTOFREE), nil, nil);
BASS_ChannelPlay(EnChan, False);
while BASS_ChannelIsActive(EnChan) <> 0 do begin
  Bytes:= BASS_ChannelGetData(EnChan, @Buf, SizeOf(Buf));
  Progress.Position:= ((100 * BASS_ChannelGetPosition(EnChan, BASS_POS_BYTE)) div BASS_ChannelGetLength(EnChan, BASS_POS_BYTE));
  Application.ProcessMessages;
end;
BASS_ChannelRemoveDSP(EnChan, Normdsp);
BASS_StreamFree(EnChan);



is not work, why ??
Thank
Salvo
Logged
Ian @ un4seen
Administrator
Posts: 15270


« Reply #1 on: 23 May '12 - 17:52 »
Reply with quoteQuote

procedure NormalizeDSP(Handle: HDSP; Channel: DWORD; Data: Pointer; Length: DWORD; Peak: DWORD); Stdcall;

This looks like a problem. Your peak level is floating-point, so the "Peak" parameter should be too. Actually, it should really be a pointer (as that is what a DSPPROC is defined to have), and you can then cast it to a floating-point value in the function body.
Logged
Salvo
Posts: 41


« Reply #2 on: 23 May '12 - 18:49 »
Reply with quoteQuote

I did not understand your answer.
You can make a correct example or give me a piece of working code?
Salvo
Logged
Ian @ un4seen
Administrator
Posts: 15270


« Reply #3 on: 24 May '12 - 15:03 »
Reply with quoteQuote

I'm not a Delphi user myself, so I'm not entirely sure what it should look like there, but perhaps something like this...

procedure NormalizeDSP(Handle: HDSP; Channel: DWORD; Data: Pointer; Length: DWORD; user: Pointer); Stdcall;
var
  Peak: Float;
  d: ^Float;
  i: Integer;
begin
  Peak := Float(user);
...
Logged
Salvo
Posts: 41


« Reply #4 on: 25 May '12 - 08:42 »
Reply with quoteQuote

I'm not a Delphi user myself, so I'm not entirely sure what it should look like there, but perhaps something like this...

procedure NormalizeDSP(Handle: HDSP; Channel: DWORD; Data: Pointer; Length: DWORD; user: Pointer); Stdcall;
var
  Peak: Float;
  d: ^Float;
  i: Integer;
begin
  Peak := Float(user);
...
thank
Salvo
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines