Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

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...
0
Smokintbird
Asked:
Smokintbird
  • 4
1 Solution
 
inthedarkCommented:
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

0
 
inthedarkCommented:
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


0
 
inthedarkCommented:
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.

0
 
inthedarkCommented:
So how you play the sound depends on what processing you need to do.

If you want to continue processing this example won't work becuase it assumes you are going to stop for half a seconds and do nothing.

retval = PlaySound("C:\Sounds\scream.wav", 0, SND_FILENAME Or SND_ASYNC Or SND_NODEFAULT Or SND_LOOP)
Sleep 500  ' wait for .5 seconds while sound loops
retval = PlaySound("", 0, SND_PURGE Or SND_NODEFAULT)  ' stop playback

The other way is to fire the play sound and then keep checking the time and stop the sound after .5 seconds has past. But the problem here is that if you do an intensive thing your sound may run on.

The best and simplest thing is to crop the beep so it is just the length you need it. When you wan't the bleep:

retval = PlaySound("C:\Sounds\scream.wav", 0, SND_FILENAME Or SND_ASYNC Or SND_NODEFAULT)

This will play until end of sound.
0
 
SmokintbirdAuthor Commented:
worth the points...   the API works great, once I figured it all out...
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now