Thread: Producing Beep Sound with C++

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    1

    Exclamation Producing Beep Sound with C++

    Hello everyone,

    Just wondering, I read from a C++ book, that there is this special character:

    \a

    which the book said it will produce a beep sound. Being curious,
    I fired up my Microsoft VC++ and tried like this:

    cout << "\a\a\a\a\" << endl;

    in which I hope the computer will beep several times, but it didn't.

    So my question is, can this character
    really produce a beep sound?
    If yes, how would we use it in the C++ program?


    Cheers
    Ronald

    ps: I also noticed in the book, there is this ASCII character
    ^G (BEL) --> is this the same thing as above?

    FYI
    ===
    OS : Windows XP
    Compiler : Microsoft Visual C++ 6.0

  2. #2
    Registered User
    Join Date
    Dec 2003
    Posts
    92
    ....but this is giving multiple beeps in my system.

    Code:
    #include<iostream>
    
    using namespace std;
    
    int main()
    
    {
    int k =0;
    
    while(k<10)
    {
    
    	cout<<'\a'<<endl;
    
    	k++;
    }
    
    }

    you need to flush the stream . either use "endl" or use "flush".
    blue_gene

  3. #3
    Caffienated jinx's Avatar
    Join Date
    Oct 2001
    Posts
    234
    try removing the quotes

    Code:
    cout << \a \a \a \a << endl;
    or something. Personally I've never used this in c++ (or even heard of this); The only command I know for this is "beep" in BASIC...
    Weeel, itss aboot tieme wee goo back too Canada, eeehy boyss.

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    20
    You may have one of the newer computers that do not have a pc speaker hooked up. Open the case and look to see if there is a single speaker on the case that is connected to your motherboard.

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Use the Beep() API function, control the pitch and duration that way.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    it's supposed to be in quotes... it's just a mobo beep... not really anythign interesting... and if you put several together they beep so fast you can barely hear the pauses in between... at least on my system...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    20
    Then you need to use other functions to slow down the process of beeping. You can get real fancy with timers but you probably only need a simple pause between each beep.

  8. #8
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    if you are under windows XP, you can set the volume of the beeper on your puter in the volume control. You might have it muted, causing you not to hear the sounds. Just double click your volume control and make sure the "PC Speaker" isn't muted and that the volume is all the way up.

    note-
    and for making beep sounds, use the Beep function, found in windows.h i believe....

    Beep(frequency, duration);

    so Beep(1000,500); would play a beep at pitch 1000 for half a second 500/1000 milliseconds.

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > in which I hope the computer will beep several times, but it didn't.
    But did it beep at all?

    cout << '\a\a'
    is only likely to produce a slightly longer beep than
    cout << '\a'

    If you want distinct beeps, then you're going to have to use a loop, and insert a delay between each one.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. alert beep sound
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 02-14-2006, 02:24 PM
  2. Low latency sound effects
    By VirtualAce in forum Game Programming
    Replies: 0
    Last Post: 12-21-2004, 01:58 AM
  3. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  4. DirectSound - multiple sounds
    By Magos in forum Game Programming
    Replies: 9
    Last Post: 03-03-2004, 04:33 PM
  5. sounds?
    By BODYBUILDNERD in forum C++ Programming
    Replies: 6
    Last Post: 12-06-2002, 03:34 PM