Valhalla Legends Archive

Programming => General Programming => Topic started by: Tazo on May 10, 2003, 06:06 AM

Title: Playing Sounds out of the HD [VB] or [C++]
Post by: Tazo on May 10, 2003, 06:06 AM
How do you play sounds (different beeps) out of the HD in vb or c++? I
've seen many programs do it, and I think it's very neat and would be nice to have it on my program. Thanks!
Title: Re:Playing Sounds out of the HD [VB] or [C++]
Post by: Yoni on May 10, 2003, 08:24 AM
Ehh?? Hard drives are supposed to keep silent... If they make strange noises, that's a very bad sign ;)

If you meant the PC speaker instead of HD, you can do it in WinNT using the Beep function (kernel32.dll). But note that many users find these beeps annoying - use them only where appropriate.
Title: Re:Playing Sounds out of the HD [VB] or [C++]
Post by: Arta on May 10, 2003, 01:03 PM
I think he means playing wav files.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/mmfunc_9uxw.asp
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/mmfunc_9uxw.asp)

Example:


PlaySound("c:\mysound.wav", NULL, SND_ASYNC);


Query: Do you also need to specify SND_FILENAME? I never have in the past but MSDN implies that you do.
Title: Re:Playing Sounds out of the HD [VB] or [C++]
Post by: Yoni on May 10, 2003, 01:13 PM
Quote from: Arta[vL] on May 10, 2003, 01:03 PM
Query: Do you also need to specify SND_FILENAME? I never have in the past but MSDN implies that you do.
Yes... But it might work without it.
Title: Re:Playing Sounds out of the HD [VB] or [C++]
Post by: Tazo on May 11, 2003, 07:11 AM
Yes, I meant different 'beeps'. All (most)  old dos games use this, they use beeps as the sound. How can I get a different toned beep than just 'beep'?
Title: Re:Playing Sounds out of the HD [VB] or [C++]
Post by: K on May 11, 2003, 09:13 AM
Like Yoni, said, use the Beep API.

BOOL Beep(
 DWORD dwFreq,
 DWORD dwDuration
);

Bearing in mind that it wont work well or at all on any non-NT based platforms.
dwFreq :Frequency of the sound, in hertz. (0x25 through 0x7FFF).
Windows Me/98/95:  The Beep function ignores this parameter.

dwDuration: Duration of the sound, in milliseconds.
Windows Me/98/95:  The Beep function ignores this parameter.
Title: Re:Playing Sounds out of the HD [VB] or [C++]
Post by: Yoni on May 11, 2003, 02:50 PM
Quote from: K on May 11, 2003, 09:13 AM
Bearing in mind that it wont work well or at all on any non-NT based platforms.
At all. It will just play the default Windows sound.
Title: Re:Playing Sounds out of the HD [VB] or [C++]
Post by: Mesiah / haiseM on May 12, 2003, 08:53 PM


Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long

How to use this:

Dim X%
X% = Beep(1500, 300)



This will make the analogue speaker in your computer (used for bios errors and startup confirmations) beep at the specified frequency, for a specified amount of time.