Solved

MM control too slow...

Posted on 2002-05-20
5
196 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month5 days, 21 hours left to enroll

627 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