20 Jun '13 - 06:19 *
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: Playing a file stops my button hints from working  (Read 758 times)
Graham1
Posts: 35


« on: 5 Aug '12 - 17:53 »
Reply with quoteQuote

OK, so I'll run this in a separate post.

When I am playing a file, the hints on my buttons stop working, Stop or pause the file an the hints are displayed again.

Any ideas as to why this should be?

Graham
Logged
Chris
Posts: 1507


« Reply #1 on: 5 Aug '12 - 18:03 »
Reply with quoteQuote

Hi
I did here a quick test (icl a active Spectrum) all Button Hints will working fine.
Look like something in your code is wrong.
So we must see a part of your sourcecode.
By the way are you using callbacks??And are you updating Gui Stuff inside the callbacks?
Chris
Logged
Graham1
Posts: 35


« Reply #2 on: 6 Aug '12 - 09:49 »
Reply with quoteQuote

The only callbacks I use are for detecting the end of the file. I removed those and it made no difference.

But here is another strange effect which may provide a clue.

I start the application and hover the mouse over a button, the Hint appears. I now play a file and the only hint that works is the one I just hovered the mouse over. Stop the file playing and all the Hints work again. It appears that the only Hint that works while a file is playing is the last one I looked at before playing the file.

To play a file I basically do the following:

begin
  local_chan := GetAudioFileHandle (audio_filename);

  if local_chan > 0 then
    BASS_ChannelPlay(local_chan,FALSE);
end;

function GetAudioFileHandle (f_name : String) : HSTREAM;
var
  l_chan : HSTREAM;
  l_ext : String;

begin
  if FileExists (f_name) then
  begin
    l_ext := AnsiUppercase (ExtractFileExt (f_name));

    if l_ext = FLAC_EXT_STR then
      l_chan := BASS_FLAC_StreamCreateFile(FALSE,PChar(f_name),0,0,0 or BASS_UNICODE)
    else
      if l_ext = WMA_EXT_STR then
        l_chan := BASS_WMA_StreamCreateFile(FALSE,PChar(f_name),0,0,0 or BASS_UNICODE)
      else
        if l_ext = WV_EXT_STR then
          l_chan := BASS_WV_StreamCreateFile(FALSE,PChar(f_name),0,0,0 or BASS_UNICODE)
        else
          l_chan := BASS_StreamCreateFile(FALSE,PChar(f_name),0,0,0 or BASS_UNICODE);

  end
  else
  begin
    l_chan := 0;
  end;

  Result := l_chan;
end; //GetAudioFileHandle
Logged
Chris
Posts: 1507


« Reply #3 on: 6 Aug '12 - 10:19 »
Reply with quoteQuote

Hi
Looks like you are working with delphi XE/Xe2
from the ground up this code can produce errors!
should be
function GetAudioFileHandle (f_name : String) : HSTREAM;
var
  l_chan : HSTREAM;
  l_ext : String;
begin
  if FileExists (f_name) then
  begin
    l_ext := AnsiUppercase (ExtractFileExt (f_name));
    l_chan := BASS_StreamCreateFile(FALSE,PChar(f_name),0,0,0 or BASS_UNICODE);
    if  l_chan =0 then
      l_chan := BASS_FLAC_StreamCreateFile(FALSE,PChar(f_name),0,0,0 or BASS_UNICODE)
   else if l_chan = 0 then
      l_chan := BASS_WMA_StreamCreateFile(FALSE,PChar(f_name),0,0,0 or BASS_UNICODE)
   else if l_chan = 0 then
      l_chan := BASS_WV_StreamCreateFile(FALSE,PChar(f_name),0,0,0 or BASS_UNICODE);
     Result := l_chan;
  end;



Why do you not work with the Plugin Stuff ??
In you code you will only check the extension what is if one user have renamed a e.g mp3 to flac??
A better way is to check the Handle.
(take a look in the Delphi Plugins Demo).
But about your Problem are you using specialy Delphi Components?
So I can`t here reproduce here your error!
Chris

 
« Last Edit: 6 Aug '12 - 11:10 by Chris » Logged
Graham1
Posts: 35


« Reply #4 on: 6 Aug '12 - 10:27 »
Reply with quoteQuote

I am using the LMD ElPack components for buttons, however I have tried it with standard Delphi TButton, TBitBtn and TSpeedBtn. All produce the same effect. I shall try and knock up a small demo program using only Delphi buttons.

And yes I am using XE2.

Graham
Logged
Chris
Posts: 1507


« Reply #5 on: 6 Aug '12 - 11:12 »
Reply with quoteQuote

Make a small demo and upload it here in the forum so i can take test it self.
Chris
Logged
Graham1
Posts: 35


« Reply #6 on: 6 Aug '12 - 14:04 »
Reply with quoteQuote

OK, so this is the problem. When I start to play a file, I want to monitor the audio level, and display it in the form of a varying size panel.
I have a timer that runs at a 100mS interval. In the Timer event I call BASS_ChannelGetLevel to get a snapshot of the current audio level.

It is this call that is causing the problem. I am calling it too fast. If I slow the timer down to an interval of 600mS then I have no problem with the Hints.

So is there a better way to get the audio level of a file that is playing?
Logged
Graham1
Posts: 35


« Reply #7 on: 6 Aug '12 - 14:19 »
Reply with quoteQuote

Should I be using one of the callback functions for this?
Logged
Chris
Posts: 1507


« Reply #8 on: 6 Aug '12 - 17:28 »
Reply with quoteQuote

Do you mean you want to display the level like in a VU-Meter?or as a Spectrum?

by the way I`m display here VU-Meter AND a Spectrum (in a 25 ms Timer) without Problems in the other Canvas Stuff...e.g Hints.
I thing there is something wrong in your timer Call ...
Make a demo and load the source here so i can look whats going wrong.
Chris
Logged
Graham1
Posts: 35


« Reply #9 on: 6 Aug '12 - 20:36 »
Reply with quoteQuote

Yes, it is just displaying some bars like a VU meter. If I comment out the line that calls BASS_ChannelGetLevel, the hints work. So in you program are you calling BASS_ChanneGetLevel in your 25mS timer?
Logged
Chris
Posts: 1507


« Reply #10 on: 6 Aug '12 - 21:26 »
Reply with quoteQuote

yes
Here an little example .
In this example are 3 Timers.
The MainTimer (TTimer) with 33 ms.(who will updating the Bass_ChannelgetLevel and Bass_ChannelGetdata Calls)
And in the 2 VUMeter Components (That is displaying the Level) there is inside a Winapi Timer to displaying the Peak(25ms)
Chris

* spectrum.rar (647.89 KB - downloaded 6 times.)
« Last Edit: 6 Aug '12 - 22:33 by Chris » Logged
Graham1
Posts: 35


« Reply #11 on: 7 Aug '12 - 11:29 »
Reply with quoteQuote

I have now found that it is nothing to do with how often I call BASS_ChannelGetLevel, but is to do with what I do after. I convert it to a Log level, 20Log10 seems to be the culprit.

In your demo are you displaying the volume level as linear data direct from theBASS_ChannelGetLevel call?
Logged
Chris
Posts: 1507


« Reply #12 on: 7 Aug '12 - 11:37 »
Reply with quoteQuote

yes

var
 decay :SmallInt;

procedure TForm3.ComboBox1Change(Sender: TObject);
begin
  decay := strtointdef(combobox1.Items[combobox1.ItemIndex],1)*300;
end;

procedure TForm3.GetLevel;
begin
  Level := BASS_ChannelGetLevel(Channel);
  levl := levl - decay;
  if (levl < 0) then
    levl := 0;
  levr := levr - decay;
  if (levr < 0) then
    levr := 0;
  if (Level <> DW_ERROR) then
  begin
    if (levl < LOWORD(Level)) then
      levl := LOWORD(Level);
    if (levr < HIWORD(Level)) then
      levr := HIWORD(Level);
  end;
  ledmeter1.Position := levl div 327;
  ledmeter2.Position := levr div 327;
end;
« Last Edit: 7 Aug '12 - 11:40 by Chris » Logged
Graham1
Posts: 35


« Reply #13 on: 7 Aug '12 - 11:57 »
Reply with quoteQuote

Well this is mode wierd now. If I display the level as a linear measurement, (like you do) I dont have a problem. If I convert to a log value then I do. I am now even running the whole volume measurement thing in a separate low priority thread. I have measured how long the Log calculations take and it is insignificant.
It is as if the Log calculation is holding up the Hints. If I put 600mS between the Log calculations then the Hints are OK.
As this is not really a BASS problem I might continue this in a Delphi forum.

Graham
Logged
Graham1
Posts: 35


« Reply #14 on: 7 Aug '12 - 12:08 »
Reply with quoteQuote

I take that last comment back. If I do everything except actually play the file, then the Hints will work.

So it now appears to be a strange interaction between playing a file and doing a Log10 calculation.

Is it time to retire, I must be going mad.
Logged
Chris
Posts: 1507


« Reply #15 on: 7 Aug '12 - 12:53 »
Reply with quoteQuote

I have tested here with converting to log and display no Problem!!

try this log function

function LinToDB(Volume: integer; Base: integer = 100): integer;
begin
  if (Volume = 0) then
    Result := -50
  else
    Result := round(Log10(abs(Volume) / Max(base, 1)) * 20);
end;
Logged
Graham1
Posts: 35


« Reply #16 on: 7 Aug '12 - 15:28 »
Reply with quoteQuote

I have now written a test program to get to the bottom of this. As you might expect it works perfectly.

Investigating continues.
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines