473,394 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Producing Sound wit C++

2
I am programming a simple piano program that I input the duration and frequency of a note into an array of integers for examination. I want to play that 'TUNE' to verify that there are no errors in the melody before running the main examination function of the program.

If anyone could help me with a snippet of code top produce the sound on the system speaker (pitch) for a specific amount of time (duration), I would be most grateful.

I'm using Dev C++ in a windows XP platform, but would appreciate generic code that can be used on any platform.

Thanks in advance,
Jim
Jul 7 '07 #1
3 4723
weaknessforcats
9,208 Expert Mod 8TB
I don't know that things can be portable but if you can get your note in a .wav file you can call PlaySound() with the file name.
Jul 7 '07 #2
Jim,
In order to play a sound on your internal speak running windows you can do the following:
#include <windows.h>// which is the WinApi header file
int main ( ){
Beep(x,y);
return 0;}

where x = hertz and y = time duration in milliseconds.

Im not sure if windows.h is on all systems, i use dev-c++ and know that the header can be found.
Hope this helps,
-Matt
Jul 10 '07 #3
mohsin
19
Jim,
In order to play a sound on your internal speak running windows you can do the following:
#include <windows.h>// which is the WinApi header file
int main ( ){
Beep(x,y);
return 0;}

where x = hertz and y = time duration in milliseconds.

Im not sure if windows.h is on all systems, i use dev-c++ and know that the header can be found.
Hope this helps,
-Matt
if u r using turbo c++ compiler then y dont u use
# include <dos.h>
void main ()
{
sound (7);
delay (1000);
nosound();
}
i dont know if ur PC emit 7 hz frequency
Jul 10 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Marco Krechting | last post by:
Hi All, I have a database with the timer function set to warn the user that arecord is due to expire. Is there a Win API that I can use so a loud warning will go off. Not this simpel beep in...
4
by: Robert Gravereaux | last post by:
I'm putting together a C# .Net forms project on win2k. The application requires some sort of horn sound. I've never implemented any audio in .Net, so I'm not sure how best to accomplish this. ...
1
by: Lam | last post by:
how can I play sound file in a .aspx page written in C#? I try to use the code like the following. But whenI call the play function play("sound.wav", this.SND_ASYNC) my computer give out "be"...
4
by: Larry Serflaten | last post by:
I'm adding a bit of sound to a simple game I've got going, and I want to have several sounds on at the same time, so I go looking to use the MCISendString commands and find they CRASH MY COMPUTER...
4
by: garyusenet | last post by:
Hi. I am trying to learn about array lists, and found an example on MSDN. I tried to compile it but it's not producing any output. I can't see why. Any ideas? Here is what I did. 1....
6
by: =?Utf-8?B?VmVybm9uIFBlcHBlcnM=?= | last post by:
I have an application that is designed for using with a bar code scanner. I want the user to know that the scan was complete and the data was entered, so I am playing a system sound after data...
7
by: thamizh.veriyan | last post by:
Hi, I am new to this community. I have a doubt regarding trap representations. I read in IBM's website that something like this is legal: int main(){ int x=3; {
4
by: kid joe | last post by:
Hello I've got interested in learning some basic sound programming bits in C... mainly I want to know how to go about accessing the sound devices - reading from them mainly - in windows and...
8
by: chromis | last post by:
Hi, I've been struggling to get sounds to work with attachSound when the sounds are stored in a swf loaded into another swf. I came across a post on a forum which supposedly explains how to to do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.