Solved

MM control too slow...

Posted on 2002-05-20
5
190 Views
Last Modified: 2008-01-09
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
Comment
Question by:Smokintbird
  • 4
5 Comments
 
LVL 17

Expert Comment

by:inthedark
ID: 7023251
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
 
LVL 17

Expert Comment

by:inthedark
ID: 7023272
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
 
LVL 17

Expert Comment

by:inthedark
ID: 7023274
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
 
LVL 17

Accepted Solution

by:
inthedark earned 300 total points
ID: 7023379
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
 
LVL 1

Author Comment

by:Smokintbird
ID: 7030802
worth the points...   the API works great, once I figured it all out...
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now