I produce something like this.
var
MasterFreq0,
PeakFreq0: FLOAT;
function GetRealBitrateFrom(FullArtist: string): Cardinal;
var
PeakBin: Integer;
Rate: FLOAT;
PeakVal: FLOAT;
FFTData0: array [0..2048] of Single;
var
AStream: HSTREAM;
A0: Integer;
begin
AStream := BASS_StreamCreateFile(False, PChar(FullArtist), 0, 0, BASS_SAMPLE_FLOAT or BASS_STREAM_PRESCAN or BASS_STREAM_DECODE or BASS_UNICODE);
BASS_ChannelGetAttribute(AStream, BASS_ATTRIB_FREQ, Rate); // get sample rate
if (BASS_ErrorGetCode > 0) then
Exit;
PeakBin := 0;
PeakVal := 0.0;
BASS_ChannelGetData(AStream, @FFTData0, BASS_DATA_FFT4096); // get FFT data (4096 sample)
for A0 := 2 to 2047 do
begin
if (Peakval < FFTData0[A0]) then // found a new peak
begin
PeakVal := FFTData0[A0];
PeakBin := A0;
end;
end;
PeakFreq0 := PeakBin * (Rate / 4096); // get frequency of peak bin
BASS_StreamFree(AStream);
end;
function GetRealBitrateFull(FullArtist: string): Cardinal;
var
PeakBin: Integer;
Rate: FLOAT;
PeakVal: FLOAT;
FFTData0: array [0..2048] of Single;
var
AStream: HSTREAM;
A0: Integer;
begin
AStream := BASS_StreamCreateFile(False, PChar(FullArtist), 0, 0, BASS_SAMPLE_FLOAT or BASS_STREAM_PRESCAN or BASS_STREAM_DECODE or BASS_UNICODE);
BASS_ChannelGetAttribute(AStream, BASS_ATTRIB_FREQ, Rate); // get sample rate
if (BASS_ErrorGetCode > 0) then
Exit;
MasterFreq0 := 0;
while BASS_ChannelIsActive(AStream) <> 0 do
begin
PeakBin := 0;
PeakVal := 0.0;
BASS_ChannelGetData(AStream, @FFTData0, BASS_DATA_FFT4096); // get FFT data (4096 sample)
for A0 := 2 to 2047 do
begin
if (Peakval < FFTData0[A0]) then // found a new peak
begin
PeakVal := FFTData0[A0];
PeakBin := A0;
end;
end;
PeakFreq0 := PeakBin * (Rate / 4096); // get frequency of peak bin
if (MasterFreq0 < PeakFreq0) then
MasterFreq0 := PeakFreq0;
end;
BASS_StreamFree(AStream);
end;
Ignore title proc 'GetRealBitrateFull' because that what i want to reaches. Not important for now.
The first is not always correct and de second is better. But there is a max. High frequency situation wilt most mp3 songs.
A0 start with 2 is better dan start whit 0 or 1.
Thank you.