Computing.Net > Forums > Programming > Piano programming in C

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Piano programming in C

Reply to Message Icon

Name: Pankaj Barua
Date: January 28, 2009 at 00:12:42 Pacific
OS: Windows XP
CPU/Ram: Pentium 4
Product: Intel / Xyz
Subcategory: C/C++
Comment:

I want to develop a ‘Piano’ using C/C++/VBasic. But, I can not generate sound. I will be very grateful if anyone suggest me ‘how can I generate a sound of a required frequency & amplitude?’ such as ‘sa’ or ‘re’, etc. Actually, is there any function in C/C++/VBasic which has minimum two input arguments for select frequency and amplitude of a sound?

I am anxiously waiting for kind co-operation.



Sponsored Link
Ads by Google

Response Number 1
Name: lamprea
Date: February 8, 2009 at 10:42:19 Pacific
Reply:

I had the very same problem, luckily I found a
solution. Although I am still learning c++!

Here is an example:

#include "iostream.h"
#include "windows.h"

using namespace std;


int main()
{
Beep(440,100);//This is note A
Beep(495,100);//B
Beep(528,100);//C
Beep(594,100);//D
Beep(660,100);//E
Beep(704,100);//F
Beep(783,100);//G
Sleep(1000);//Pauses the program for 1 second
}

Overview--

The 'Beep(,);' function will sound a frequency in
hertz.

In the 'Beep(100,100);' function their are 2 numbers,
the first number is the frequency. And the second
number is the time it lasts in milliseconds. So 1000 milliseconds will be 1 second.

The frequency in hertz is 1(really high pitched) to
about a few thousand (really low).

NOTE-
The noise that will sound will come from inside the
computers case, from the computers pizo-electric
speaker on its motherboard.(not all computers have
one, I think). You can't change the volume(I think).
This Beep function was is still used, normally as your
computer tuns on it will beep!


0
Reply to Message Icon

Related Posts

See More


DOS - Replace Environment... Need help with backup bat...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Piano programming in C

Piano Program in C++ www.computing.net/answers/programming/piano-program-in-c/14182.html

beginners programming in c www.computing.net/answers/programming/beginners-programming-in-c/11037.html

Programming in C www.computing.net/answers/programming/programming-in-c/7343.html