Avatar of chrislock
chrislock

asked on 

Delphi play wav file quick

Win XP
D7

I am trying to play a .Wav file out to the PC sound system to create a 'click' for an external keypad connected to the LPT port (dont ask!). For technical reasons, I cant use the PC beep system.
Apparently there are a few different ways and I am trying to find the fastest. I have made a short 'click.wav' and using the following routines.

My question is: Why is playing 'click.wav' through control panel sound properties page much faster and more consistent (no delays or jitter) than through my program below?

function LoadFile(const FileName: TFileName): string; // for sounds load into memory
begin
  with TFileStream.Create(FileName,
      fmOpenRead or fmShareDenyWrite) do begin
    try
      SetLength(Result, Size);
      Read(Pointer(Result)^, Size);
    except
      Result := '';  // Deallocates memory
      Free;
      raise;
    end;
    Free;
  end;
end;


var
ss:array[1..15] of string;


initialization
ss[1] := LoadFile(currentdir + '\data\' + 'click.wav')

I then use the following API  to play the click -


 sndPlaySound(Pointer(ss[s]), SND_MEMORY
    Or SND_NODEFAULT Or SND_ASYNC);

   
Microsoft DevelopmentMultiMedia ApplicationsDelphi

Avatar of undefined
Last Comment
MerijnB
Avatar of MerijnB
MerijnB
Flag of Netherlands image

how can ss only be 15 chars long?
Can you explain more on the jitter / inconsistency?
Avatar of chrislock
chrislock

ASKER

ss[] is an array of pointers.
I want a click of about 100mS - my click.wav plays OK on control panel and you can click the mouse rapidly on the 'play' button without missing a beat. In the program, it takes longer to execute and there appears to be a sort of overrun if the mouse is clicked rapidly.
thanks
Chris
Avatar of CodedK
CodedK
Flag of Greece image

Hi Chrislock.

I had the same problems once with a metronome program.
Download Goldwave or some other wave editor program and create a small click sound.
(22K Hz, 20ms, mono)
I embedded mine as a resource in the application.

The smaller time i could use without a glitch was 450bpm (one beep in 133msecs).
I've used 2 sound files. I've always had a problem with one of the sounds and took some time to create a small file that wouldn't had a delay.

Use Borland Resource Compiler to embed it.

Hope this helps.
Avatar of MerijnB
MerijnB
Flag of Netherlands image

Hi Chrislock.

What are the specs of these waves, can you set one (the longest one) on eestuff? Do these 'playbacks' overlap at highest speed?
Avatar of CodedK
CodedK
Flag of Greece image

Hi Chrislock.

If you want i can send you my wave file to check it with your program ... As i said try to make one small no only by size ... time too (<20msecs)
Avatar of chrislock
chrislock

ASKER

Hi again,

I've tried compilinmg the click.wav into a resource file and its even worse!
I am using an 800Mhz desktop PC, but the target is an industrial computer running at 400MHZ.
Thanks for the offer CodedK - can you send me your click.wav?
What I cant understand is why the OS ontrol panel sound properties page much faster and more consistent (no delays or jitter) than through my program? Yes - the playbacks do overlap through my program.
Have downloaded Goldwave and I'm going to try another click.wav today
Thanks,
Chris
ASKER CERTIFIED SOLUTION
Avatar of MerijnB
MerijnB
Flag of Netherlands image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of CodedK
CodedK
Flag of Greece image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of chrislock
chrislock

ASKER

Thanks for the click files. They play OK on the 400MHz machine - if you tap the keyboard at about 300mS intervals using OS ontrol panel sound properties page all clicks are heard equally spaced, but iin my .exe  they seem to stack up and you get a pile of clicks after a couple of seconds all together. Not much  use for a keyboard!
There must be something fundamental wrong with the .exe, but I cant see what!
Chris
Avatar of MerijnB
MerijnB
Flag of Netherlands image

can you post a (small version) of your app somewhere so I can take a look?
Delphi
Delphi

Delphi is the most powerful Object Pascal IDE and component library for cross-platform Native App Development with flexible Cloud services and broad IoT connectivity. It provides powerful VCL controls for Windows 10 and enables FMX development for Windows, Mac and Mobile. Delphi is your choice for ultrafast Enterprise Strong Development™. Look for increased memory for large projects, extended multi-monitor support, improved Object Inspector and much more. Delphi is 5x faster for development and deployment across multiple desktop, mobile, cloud and database platforms including 32-bit and 64-bit Windows 10.

60K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo