Search code examples
operating-system

How can I change '\a' sound?


#include<iostream>
#include<conio.h>
#include<windows.h>
using namespace std;
int main()
{
    while(getch()!=27){
        cout << "\a\n";
        Sleep(500);
    }
    return 0;
}

I heard I could change '\a' alert sound. It's echoing sound now, but i wanna change it. How can I?

More question : Is way to change the sound all different to each development environment?

P.S. I'm using Code::Blocks now


Solution

  • Yes, you can do that, you may use Beep() from windows.h as shown:

    #include <windows.h>
    
    int main(void) {
        Beep(500, 500);
    
        return 0;
    }
    

    The relationship between the number and frequency is directly proportional, i.e.

    • Less frequency (like 400, 400) - less sound for 400 ms (0.4s)
    • More frequency (like 1000, 1000) - more sound for 1000 ms (1s)

    Edit: There's no correct method to alter the bell sound. It's totally up to the opearting system. The only way you can use the Beep() to generate some different frequencies which do sound different than a normal beep produced by \a escape sequence.