Author Topic: Why the peak is incorrect when BASS_ChannelGetData  (Read 194 times)

tongjiang.chu

  • Guest
Hi,

When i try to decode a wave file by BASS_ChannelGetData. I found that the peak value is different when i select different length.
Ex,
the BASS_CHANNELINFO.freq of wave file is 44100Hz.

chan := BASS_StreamCreateFile(False, PAnsiChar(WavName), 0, 0, BASS_STREAM_DECODE);

I can get the correct peak value when i use
BASS_ChannelGetData(chan, @fft, BASS_DATA_FFT1024);  //peak value = 0.8

but when i use
BASS_ChannelGetData(chan, @fft, BASS_DATA_FFT4096)
the peak value just is 0.57

use
BASS_ChannelGetData(chan, @fft, BASS_DATA_FFT8192)
the peak value just is 0.29

use
BASS_ChannelGetData(chan, @fft, BASS_DATA_FFT16384)
the peak value just is 0.14

Seems that the value will decrease with the increase of the decoding length.
Who can let me know why??

Many thanks

Ian @ un4seen

  • Administrator
  • Posts: 20612
Re: Why the peak is incorrect when BASS_ChannelGetData
« Reply #1 on: 26 Jan '18 - 17:30 »
What is the length of the WAV file? Perhaps it is shorter than the FFT? If so, this update should help:

   www.un4seen.com/stuff/bass.zip

tongjiang.chu

  • Guest
Re: Why the peak is incorrect when BASS_ChannelGetData
« Reply #2 on: 27 Jan '18 - 05:09 »
What is the length of the WAV file? Perhaps it is shorter than the FFT? If so, this update should help:

   www.un4seen.com/stuff/bass.zip


Hi, Ian,

Actually i want to get the peak value for every 0.02 s. Here is my codes, would you please help me to see if they are correct?
Many thanks

  chan := BASS_StreamCreateFile(False, PAnsiChar(WavName), 0, 0, BASS_STREAM_DECODE);
  if chan < BASS_ERROR_ENDED then
  begin
    Log('Open Failed');
    Exit;
  end;
  try
    BASS_ChannelGetInfo(chan, WavInfo);
    Log('Sampling Rate :' + #9 + FloatToStr(WavInfo.freq));
    Log('Channels :' + #9 + FloatToStr(WavInfo.chans));

    TotalTime := BASS_ChannelBytes2Seconds(chan, BASS_ChannelGetLength(chan, BASS_POS_BYTE));
    Log('Duration :' + #9 + IntToStr(Trunc(TotalTime*1000)) + ' ms');
    TolQty := Trunc(TotalTime*50);
    tlen := BASS_ChannelSeconds2Bytes(chan, 0.02);
    tLevel := 0;
    for y := 0 to TolQty - 1 do
    begin
      BASS_ChannelSetPosition(chan, tlen*y, BASS_POS_BYTE);

      BASS_ChannelGetData(chan, @fft, BASS_DATA_FLOAT or 44100);
      dbTop := 0;
       for x := 0 to length(fft) - 1 do
      begin
        WriteLn(logs, IntToStr(x) + ' ' + FormatFloat('0.000000', fft
  • ));

        if fft
  • > dbTop then

        begin
          dbTop := fft
  • ;

        end;
      end;

tongjiang.chu

  • Guest
Re: Why the peak is incorrect when BASS_ChannelGetData
« Reply #3 on: 27 Jan '18 - 05:13 »
What is the length of the WAV file? Perhaps it is shorter than the FFT? If so, this update should help:

   www.un4seen.com/stuff/bass.zip

Sorry, i attached incorrect codes just now, please see the codes as below

//==================
chan := BASS_StreamCreateFile(False, PAnsiChar(WavName), 0, 0, BASS_STREAM_DECODE);
  if chan < BASS_ERROR_ENDED then
  begin
    Log('Open Failed');
    Exit;
  end;
  try
    BASS_ChannelGetInfo(chan, WavInfo);
    Log('Sampling Rate :' + #9 + FloatToStr(WavInfo.freq));
    Log('Channels :' + #9 + FloatToStr(WavInfo.chans));

    TotalTime := BASS_ChannelBytes2Seconds(chan, BASS_ChannelGetLength(chan, BASS_POS_BYTE));
    Log('Duration :' + #9 + IntToStr(Trunc(TotalTime*1000)) + ' ms');
    TolQty := Trunc(TotalTime*50);
    tlen := BASS_ChannelSeconds2Bytes(chan, 0.02);
    tLevel := 0;
    for y := 0 to TolQty - 1 do
    begin
      BASS_ChannelSetPosition(chan, tlen*y, BASS_POS_BYTE);

      BASS_ChannelGetData(chan, @fft, BASS_DATA_FFT16384);
      dbTop := 0;
       for x := 0 to length(fft) - 1 do
      begin
        WriteLn(logs, IntToStr(x) + ' ' + FormatFloat('0.000000', fft
  • ));


        if fft
  • > dbTop then


        begin
          dbTop := fft
  • ;


        end;
      end;

Ian @ un4seen

  • Administrator
  • Posts: 20612
Re: Why the peak is incorrect when BASS_ChannelGetData
« Reply #4 on: 29 Jan '18 - 14:56 »
Please upload the WAV file in question to have a look at here:

   ftp.un4seen.com/incoming/

tongjiang.chu

  • Guest
Re: Why the peak is incorrect when BASS_ChannelGetData
« Reply #5 on: 30 Jan '18 - 01:45 »
Please upload the WAV file in question to have a look at here:

   ftp.un4seen.com/incoming/

Hi Ian,

I have uploaded the file named "TestingWav.wav" to the ftp, thanks

Ian @ un4seen

  • Administrator
  • Posts: 20612
Re: Why the peak is incorrect when BASS_ChannelGetData
« Reply #6 on: 30 Jan '18 - 17:44 »
It looks like the issue there is that the sweeping tone in the WAV file only stays in a particular frequency bin for a fraction of the FFT length, and that fraction becomes smaller as the FFT length increases. If you make the tone stay at particular frequencies for a period of time, then you should see the same magnitudes (equal to the waveform's amplitude) with all FFT lengths.