Saturday, 24 December 2016

How to play sound in C/C++ language using CodeBlock IDE

Playing  sound in C/C++ language is very interesting.

So, I am back with a code that plays a sound using C/C++ language in CodeBlocks IDE.This is a little code and here we go .........


#include<conio.h>
#include<windows.h>
int main()
{

    Beep(100,500);

    getche();

    return 0;

}

Now ,thats all we have to do to complete this task.And its time to explain the Code.

Explanation:-

Beep() is a function that is used to emit sounds of certain frequency .There are two parameters in this function.The first one is the frequency of the sound and the other one is the duration to play that sound .The most important thing about this function is that it belongs to the header file windows.h .
So to do these all you have to include windows.h header file.You can use this function in both the lnaguages C/C++.Now , we talk about the return value of this function .

Returns 0 if the function does not succeed.

Returns non-zero value if it succeed.

Beep(frequency as integer,duration in miliseconds)



 

No comments:

Post a Comment