Page 1 of 1
TMutimediaTimer and TStockAudio

Posted:
May 12th, 2012, 4:56 am
by Mike Warren
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?
Re: TMutimediaTimer and TStockAudio

Posted:
May 12th, 2012, 9:24 pm
by Kambiz
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.
Re: TMutimediaTimer and TStockAudio

Posted:
May 12th, 2012, 10:56 pm
by Mike Warren
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.
Re: TMutimediaTimer and TStockAudio

Posted:
May 12th, 2012, 11:04 pm
by Mike Warren
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.
Re: TMutimediaTimer and TStockAudio

Posted:
May 13th, 2012, 1:31 pm
by Mike Warren
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.
Re: TMutimediaTimer and TStockAudio

Posted:
May 14th, 2012, 12:58 am
by Mike Warren
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?
Re: TMutimediaTimer and TStockAudio

Posted:
May 15th, 2012, 7:36 pm
by Kambiz
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!
Re: TMutimediaTimer and TStockAudio

Posted:
May 15th, 2012, 9:44 pm
by Mike Warren
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.
Re: TMutimediaTimer and TStockAudio

Posted:
May 15th, 2012, 11:42 pm
by dec
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.
Re: TMutimediaTimer and TStockAudio

Posted:
May 18th, 2012, 3:40 am
by Mike Warren
Thanks for the suggestion. It makes no difference. The file I want to use is only 9KB anyway.
Re: TMutimediaTimer and TStockAudio

Posted:
May 19th, 2012, 3:40 am
by mathgod
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
Re: TMutimediaTimer and TStockAudio

Posted:
May 19th, 2012, 4:40 am
by Mike Warren
Thanks mathgod, I'll give that a try.