Link to home
Start Free TrialLog in
Avatar of Smokintbird
Smokintbird

asked on

MM control too slow...

I'm working on a program that currently has the Multimedia Control to make a half second "beep" sound.  there are so many things going on in the program at the time of execution, that it takes about 2 seconds to play the wav file...

I'm looking for a lighter control, a FREEWARE control or another different way of playing a WAV file that will solve the problem.

if you need more info, just say so...
Avatar of inthedark
inthedark
Flag of United Kingdom of Great Britain and Northern Ireland image

Your problem may be that you have a slow third party sound system on your machine.

What happens when you use:

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

See:

http://216.26.161.91/vbapi/ref/p/playsound.html

Paste this into a form then run.

Click on the form to run.

You may need to edit the wav file name:

"C:\winnt\media\tada.WAV" to something on your system.

Option Explicit

'Zero or more of the following flags specifying what lpszName refers to and how to play the sound:
Const SND_ALIAS = &H10000 'lpszName is a string identifying the name of the system event sound to play.
Const SND_ALIAS_ID = &H110000 'lpszName is a string identifying the name of the predefined sound identifier to play.
Const SND_APPLICATION = &H80 'lpszName is a string identifying the application-specific event association sound to play.
Const SND_ASYNC = &H1 'Play the sound asynchronously -- return immediately after beginning to play the sound and have it play in the background.
Const SND_FILENAME = &H20000 'lpszName is a string identifying the filename of the .wav file to play.
Const SND_LOOP = &H8 'Continue looping the sound until this function is called again ordering the looped playback to stop. SND_ASYNC must also be specified.
Const SND_MEMORY = &H4 'lpszName is a numeric pointer refering to the memory address of the image of the waveform sound loaded into RAM.
Const SND_NODEFAULT = &H2 'If the specified sound cannot be found, terminate the function with failure instead of playing the SystemDefault sound. If this flag is not specified, the SystemDefault sound will play if the specified sound cannot be located and the function will return with success.
Const SND_NOSTOP = &H10 'If a sound is already playing, do not prematurely stop that sound from playing and instead return with failure. If this flag is not specified, the playing sound will be terminated and the sound specified by the function will play instead.
Const SND_NOWAIT = &H2000 'If a sound is already playing, do not wait for the currently playing sound to stop and instead return with failure.
Const SND_PURGE = &H40 'Stop playback of any waveform sound. lpszName must be an empty string.
Const SND_RESOURCE = &H4004 'lpszName is the numeric resource identifier of the sound stored in an application. hModule must be specified as that application's module handle.
Const SND_SYNC = &H0 'Play the sound synchronously -- do not return until the sound has finished playing.

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, _
    ByVal hModule As Long, ByVal dwFlags As Long) As Long

Private Sub Form_Click()
Dim retval, ti
ti = Timer
retval = PlaySound("C:\winnt\media\tada.WAV", 0, SND_FILENAME Or SND_ASYNC Or SND_NODEFAULT)
MsgBox "It took " + Format(ti - Timer, "0.000") + " seconds"

End Sub


Private Sub Form_Unload(Cancel As Integer)
Dim retval
retval = PlaySound("", 0, SND_PURGE Or SND_NODEFAULT)  ' stop playback
End Sub


You must call when your form/app quits:

retval = PlaySound("", 0, SND_PURGE Or SND_NODEFAULT)  ' stop playback

If you try to qut while a sound is playing you get a GP Fault.

ASKER CERTIFIED SOLUTION
Avatar of inthedark
inthedark
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Smokintbird
Smokintbird

ASKER

worth the points...   the API works great, once I figured it all out...