Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sound in C++ apps

Status
Not open for further replies.

cloudy

ISP
Jul 14, 1999
17
US
<br>
<br>
Cloudy here again...my friend also asks if I might find him some<br>
information on Sound in C++ apps. Here is what he has written me....<br>
<br>
I've been having a hard time getting sound into a C++ ".cpp" file working <br>
correctly. Can you show me a sample source code for something that<br>
makes <br>
just one little sound. I'm missing one portion, I know, but once I find that <br>
portion I'll be set to do the rest of the project. I understand the delay <br>
and other properties of that portion, but I'm missing what goes outside<br>
that <br>
command.<br>
<br>
Could anyone out there give some tips, or some source code for<br>
generating sounds in C++ apps? Thanx :)
 
p.s. He also asked for a source for changing font colors??
 
Hi Cloudy!<br>
<br>
Take a look at the mci functions in the multimedia platform sdk. You will have to do some setup calls first, to see if the user's PC has audio capabilities, etc.<br>
<br>
So, for a .wav file, you'd do something like:<br>
<br>
#include &lt;windows.h&gt;<br>
<br>
int main(void) {<br>
<br>
PSZ lpszFileName = "c:\\winnt\\media\\ding.wav";<br>
char lpszCmd[512];<br>
<br>
wsprintf(lpszCmd, "open %s type waveaudio alias wave wait", lpszFileName);<br>
mciSendString(lpszCmd, NULL, 0, 0);<br>
<br>
wsprintf(lpszCmd, "play wave wait");<br>
mciSendString(lpszCmd, NULL, 0, 0);<br>
<br>
wsprintf(lpszCmd, "close wave");<br>
mciSendString(lpszCmd, NULL, 0, 0);<br>
}<br>
<br>
Hope this helps some. BTW, you have to link with winmm.lib.<br>
<br>
Chip H.<br>

 
Chip,<br>
<br>
I haven't a clue about most of what you're talking about, but I'll pass this along to my friend. I dont even know if he's using Unix or Microsoft for his C++. He neglected to tell me. Thanx a heap though.<br>
<br>
Cloudy
 
Since I replied earlier, I've played around with the sound APIs. A better way than what I said earlier, is to use the PlaySound() Win32 call. The mci functions spawn a separate thread on each call, and they take a comparatively long time before the sound starts to play. The PlaySound() function is much quicker.<br>
<br>
You still have to link with winmm.lib to call PlaySound().<br>
<br>
Chip H.<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top