TMutimediaTimer and TStockAudio

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

TMutimediaTimer and TStockAudio

Postby Mike Warren » May 12th, 2012, 4:56 am

Using D7, Win7

I'm attempting to use the Wave Audio Package to create a very simple metronome in my program. All I need to do is produce a regular click sound
I was hoping I could just hook together a TMutimediaTimer to a TStockAudioPlayer and TWaveStorage.

If I use a normal TTimer, it works (badly), but when I switch to a TMultimediaTimer I get a crash with the CPU window:

application-defined exception (code 0x0eedfade) at 0x75439617.

I'm guessing this is a mutithreading issue.

Should I be able to do something this simple, or is this going to be a complicated job?
Mike Warren
Active Member
Active Member
 
Posts: 8
Joined: May 12th, 2012, 4:38 am

Re: TMutimediaTimer and TStockAudio

Postby Kambiz » May 12th, 2012, 9:24 pm

The code in the event handler of TMultimediaTimer should be short to execute quickly. Otherwise when a new timer event triggers, the old one is still running.
As another solution, you can prevent triggering of new the events while the old one is not done.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: TMutimediaTimer and TStockAudio

Postby Mike Warren » May 12th, 2012, 10:56 pm

So that's not expected behavior? This is the simplest of test programs. All component properties are at their defaults. The stored wav file is 0.10 sec, 22050kHz, 16 bit Stereo. This is the total code:

Code: Select all
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, mmSystem, WaveUtils, WaveStorage, StdCtrls, WaveTimer, WaveIO,
  WaveOut, WavePlayers;

type
  TForm1 = class(TForm)
    WaveStorage1: TWaveStorage;
    StockAudioPlayer1: TStockAudioPlayer;
    MultimediaTimer1: TMultimediaTimer;
    CheckBox1: TCheckBox;
    procedure CheckBox1Click(Sender: TObject);
    procedure MultimediaTimer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  MultimediaTimer1.Enabled := CheckBox1.Checked;
end;

procedure TForm1.MultimediaTimer1Timer(Sender: TObject);
begin
  StockAudioPlayer1.PlayStock(0);
end;

end.
Mike Warren
Active Member
Active Member
 
Posts: 8
Joined: May 12th, 2012, 4:38 am

Re: TMutimediaTimer and TStockAudio

Postby Mike Warren » May 12th, 2012, 11:04 pm

Forgot to mention; if I swap to a standard TTimer, I get a click each second, but this is not accurate enough for use as a metronome.

And if I replace StockAudioPlayer1.PlayStock(0); with Beep; it also works fine.
Mike Warren
Active Member
Active Member
 
Posts: 8
Joined: May 12th, 2012, 4:38 am

Re: TMutimediaTimer and TStockAudio

Postby Mike Warren » May 13th, 2012, 1:31 pm

Setting Async to True seems to have fixed it, although I don't understand why there would be a problem with an interval of 1000mS and a wave file 100mS long.
Mike Warren
Active Member
Active Member
 
Posts: 8
Joined: May 12th, 2012, 4:38 am

Re: TMutimediaTimer and TStockAudio

Postby Mike Warren » May 14th, 2012, 12:58 am

Hmm, looks like TMultimediaTimer is still not accurate enough for use as a metronome. I get timing inconsistencies, much like I do with every other method I've tried. I see FineMetronomne apparently uses this component library. I wonder how they are able to achieve such great accuracy?
Mike Warren
Active Member
Active Member
 
Posts: 8
Joined: May 12th, 2012, 4:38 am

Re: TMutimediaTimer and TStockAudio

Postby Kambiz » May 15th, 2012, 7:36 pm

Try to use different buffer length (decrease this) and count (increase this). Maybe by finding a suitable parameter you can decrease the load on timer event and have a better resolution. Speaking of resolution, you can also decrease the resolution of the timer component. Good luck!
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: TMutimediaTimer and TStockAudio

Postby Mike Warren » May 15th, 2012, 9:44 pm

Thanks Kambiz. I've already played extensively with the buffers and resolution without enough improvement. I might get a bit cheeky and send an email to the creator of FineMetronome. I don't expect they will want to tell me, even though my program is not competing with theirs, but it's worth a try.
Mike Warren
Active Member
Active Member
 
Posts: 8
Joined: May 12th, 2012, 4:38 am

Re: TMutimediaTimer and TStockAudio

Postby dec » May 15th, 2012, 11:42 pm

Hi there,

This maybe stupid, but, can you try with a WAVE file with a less quality? Of course maintaining a good sound, but reducing the actual quality.
dec
Senior Member
Senior Member
 
Posts: 56
Joined: July 17th, 2011, 12:33 am

Re: TMutimediaTimer and TStockAudio

Postby Mike Warren » May 18th, 2012, 3:40 am

Thanks for the suggestion. It makes no difference. The file I want to use is only 9KB anyway.
Mike Warren
Active Member
Active Member
 
Posts: 8
Joined: May 12th, 2012, 4:38 am

Re: TMutimediaTimer and TStockAudio

Postby mathgod » May 19th, 2012, 3:40 am

I worked on a project that incurred bizarre behavior due to TTimer. I replaced the standard TTimer in the project with the TTimer in GT Component Pack and resolved the problem. Their web site appears to have disappeared but the latest pack (1.0.70) can be downloaded from softpedia.com.

http://www.softpedia.com/get/Programmin ... Pack.shtml
User avatar
mathgod
Junior Member
Junior Member
 
Posts: 35
Joined: December 15th, 2007, 4:36 pm
Location: Middle of New Mexico, USA

Re: TMutimediaTimer and TStockAudio

Postby Mike Warren » May 19th, 2012, 4:40 am

Thanks mathgod, I'll give that a try.
Mike Warren
Active Member
Active Member
 
Posts: 8
Joined: May 12th, 2012, 4:38 am


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: Bing [Bot] and 4 guests

cron