multimedia timer suddenly hangs ...

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

multimedia timer suddenly hangs ...

Postby stef » September 18th, 2008, 12:51 pm

hi Kambiz,

I've a program that playbacks a selected region in a wav-file.
During playback, I display the sound as a graph
and a cursor is walking over the curve to indicate the current position.

For displaying the cursor, I used a multimediatimer,
set to interval / resolution = 100 / 100.
The first time the program works well.
If I repeat the sound, after one or more times, the timer seems to hang completely.
Changing to interval / resolution = 100 / 10, hangs the timer already in the first playback of the sound.

I've replaced the timer with the default D7-timer with an interval of 100 ms (windows XP), for the rest I changed nothing,
and the program runs without any problems.

Didn't I set the interval / resolution not correct,
or did I something else wrong,
or is it a bug ?

The strange thing is that I can set breakpoints in the drawing procedure,
and yes it still stops there, even if the display seems to hang.
So it looks like the multimedia timer and the redraw procedure bites each other.

Below is my draw procedure:
With the default timer, I also don't need the draw_busy flag and the canvas.refresh. These variables were introduced to see if they would solve the problems with multi-media timer.

If it helps to have the complete code,
I possible can make a small demo program,
let me know.


thanks,
Stef Mientki

Code: Select all
procedure TForm5.Draw_Cursor ( x : integer ) ;
(*******************************************************************************
*******************************************************************************)
begin
  if draw_busy then exit;
  draw_busy := True;

  x := round ( 1.0 * x / display_compression );
  if x <> prev_cursor then
  begin
    with image1.Canvas do
    begin
      Pen.mode  := pmxor;
      pen.color := color2xor ( clfuchsia );

      //erase old line
      if prev_cursor >= 0 then
      begin
        moveto ( prev_cursor, 0 );
        lineto ( prev_cursor, height-1 );
      end ;

      //draw new line
      moveto ( x, 0 );
      lineto ( x, height-1 );

      prev_cursor := x ;
    end;
    image1.Canvas.Refresh;
  end;
  draw_busy:=False;
end;
stef
Active Member
Active Member
 
Posts: 18
Joined: July 15th, 2007, 1:35 pm

Postby Kambiz » September 19th, 2008, 11:06 am

1. The resolution property defines the tolerance of the timer. In other world, the it means the timer event occurs sometime between Interval-Resolution and Interval+Resolution. Therefore setting both to same value has not a good practice.

2. TMultimediaTimer is a threaded timer and the event occurs in a separate thread other than the main VCL thread. Because of that your code should be thread safe, which is not. For example, you have to lock the convas before drawing on it. Also, checking and setting draw_busy should be in a critical section.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 5 guests

cron