Results 1 to 6 of 6

Thread: C++ code for playing sound

  1. #1
    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.

  2. #2
    Join Date
    May 2009
    Posts
    637

    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.

  3. #3
    Join Date
    May 2009
    Posts
    511

    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.

  4. #4
    Join Date
    May 2009
    Posts
    543

    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.

  5. #5
    Join Date
    May 2009
    Posts
    529

    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
    }

  6. #6
    Join Date
    Apr 2009
    Posts
    569

    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");
    }

Similar Threads

  1. VLC not playing sound in Opensuse11.2
    By Tamonashh in forum Windows Software
    Replies: 3
    Last Post: 20-11-2010, 11:04 PM
  2. No Sound while playing FEAR
    By Christia in forum Video Games
    Replies: 5
    Last Post: 14-09-2010, 12:18 PM
  3. Video Files not playing sound
    By Kadrin in forum Windows Software
    Replies: 10
    Last Post: 10-12-2009, 09:20 AM
  4. Cannot hear sound playing mms
    By Ghajini in forum Portable Devices
    Replies: 3
    Last Post: 03-09-2009, 09:47 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,175,039.84835 seconds with 16 queries