Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



C++ code for playing sound

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 10-06-2011
Member
 
Join Date: May 2011
Posts: 59
C++ code for playing sound
  

I am new to the programming world and I have a hell lot of interest in it. I have tried lots and lots of things with C. And now I have switched on to the C++. I am a student and want to develop my career as a developer. But am here with one small issue. I want to develop a code which can play some sound when something happens. For example when a word hello is printed the sound should buzz on its own.

Reply With Quote
  #2  
Old 10-06-2011
Member
 
Join Date: May 2009
Posts: 620
Re: C++ code for playing sound

Yes that?s the spirit you should keep on doing new new things this will help you a lot. Try new things only will help you to learn. Remember that to stand in the crowd who knows the programming is easy but to stand out of the crowd and say that I can play with programming is much better. This will earn you as much as you want. Companies will hire you and will pay you as much as you want. But the only thing is that you should be able and capable of it. The answer to your question is Use PlaySound() function in you code. It will contain the oath to your sound file. And you should use .wav file for the music.
Reply With Quote
  #3  
Old 10-06-2011
Member
 
Join Date: May 2009
Posts: 503
Re: C++ code for playing sound

If you are a windows user then you should have a better look on the BCX. It is used with the C++ compiler and you can use it easily. You should learn these all things because most of the education systems don?t teach these sorts of things so you will shine in the market and there will be more demand for you instead of them. There are things like sound() you can use them in your code.
Reply With Quote
  #4  
Old 10-06-2011
Member
 
Join Date: May 2009
Posts: 533
Re: C++ code for playing sound

Yes that?s interesting. I am impressed that you want to learn new things on your own. I will try to help you out in getting the knowledge about some important things. If I want than I can provide you the readymade code, but this will not help you to learn the new things. So I will lend you with some hints only and try it yourself so that it helps you in increasing your knowledge. Initially you should use only the simple beeps that are already present. Use Beep() function in this you have to give two arguments that is frequency (in hrz) and other is the time duration that is in mille seconds. And second thing you need to add a WinApi header to your code.
Reply With Quote
  #5  
Old 10-06-2011
Member
 
Join Date: May 2009
Posts: 525
Re: C++ code for playing sound

// code that plays the sound.
#include <iostream>
#include <windows.h> // this header file is needed
using namespace std;

int main(int ac, char *av[])
{
Beep(523.2511,300); // 523.2511 hertz (C5) for 300 milliseconds
Beep(587.3295,300);
Beep(659.2551,300);
Beep(698.4565,300);
cin.get();
return 0; // return type
}
Reply With Quote
  #6  
Old 10-06-2011
Member
 
Join Date: Apr 2009
Posts: 567
Re: C++ code for playing sound

#include<windows.h>
#include<iostream>
int main(char ac)
{

cout << "Play my sound please !" << ;
Sleep(20);
PlaySound(TEXT("mysound.wav"), NULL, SND_FILENAME);
system("pause");
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "C++ code for playing sound"
Thread Thread Starter Forum Replies Last Post
VLC not playing sound in Opensuse11.2 Tamonashh Windows Software 3 20-11-2010 11:04 PM
No Sound while playing FEAR Christia Video Games 5 14-09-2010 12:18 PM
Video Files not playing sound Kadrin Windows Software 10 10-12-2009 09:20 AM
Cannot hear sound playing mms Ghajini Portable Devices 3 03-09-2009 09:47 AM


All times are GMT +5.5. The time now is 08:42 PM.