4

How can my program play a beep? Also Is it possible to play a sound with frequency and duration?

Gio
  • 41
  • 1
  • 2
  • [toot](http://github.com/vareille/toot) is a cross-platform C file and command line tool that try to call several sound generators to produce the beep – renataflow Nov 11 '17 at 06:32

3 Answers3

0

This is for windows. For Mac check this post.

#include <iostream> 
#include <windows.h> // WinApi header 

using namespace std; 

int main() 
{ 
Beep(523,500); // 523 hertz (C5) for 500 milliseconds 
Beep(587,500); 
Beep(659,500); 
Beep(698,500); 
Beep(784,500); 

cin.get(); // wait 
return 0;     
}
Community
  • 1
  • 1
Elzo Valugi
  • 27,240
  • 15
  • 95
  • 114
0

There's NSBeep() in AppKit.

0
#include <stdio.h>

int main(void)
{
  putchar('\a');
  return 0;
}
Paul R
  • 208,748
  • 37
  • 389
  • 560