Reputation: 524
How can I play uncompressed wav files in delphi?
I mean reading the wav file byte by byte and sending the data directly to the speaker.
I have searched the internet and found some functions for playing sound for a specified period of time. for example: myplaysoundfunc(1200, 100)
. this will play a sound of 1200Hz for 100 milliseconds.
But playing a wav file is more complicated. I have problem with Samples per second
and bits per samples
.
Upvotes: 0
Views: 3205
Reputation: 24086
You don't need any components or external libraries for this.
Full application sourcecode, taken from http://rosettacode.org/wiki/Play_recorded_sounds#Delphi :
{$APPTYPE CONSOLE}
program PlayRecordedSounds;
uses MMSystem;
begin
sndPlaySound('SoundFile.wav', SND_NODEFAULT OR SND_ASYNC);
end.
With these parameters the sound plays on the background while your app keeps running.
If you use SND_SYNC
instead of SND_ASYNC
, your application waits for the sound to finish before continuing.
You can also let the sound loop if you add SND_LOOP
.
This procedure stops sounds that you've previously played, unless you add SND_NOSTOP
. That way, the old sound keeps playing.
Notes:
Upvotes: 2