unique, ad-free, freemium downloads

27 December 2017

How to Add Sound to your C Program (without any library)

You may have wondered to embed sound into your console application written in C. While there are many other old methods like the method that plays sound via dos.h library, this post simply about producing sound via \a's and looping them to produce some particular sequences of sound.


Again, this is only one of the possible ways, and not the only one; I'll be posting other methods soon.


Create a function that produces sound, (herein named soundsys()).


void soundsys(){
    for (int f1=0; f1<60; f1++){
        int s=200;
        if (f1%5 == 0)
            s=300;
        if (f1%10 == 0)
            s=500;
        printf("\a");
        Sleep(s);
    }
}

Calling this function anywhere in your program will produce a sequence of error sounds.

No comments:

Post a Comment