CFanatic

Go Back   CFanatic > Programming > C++ Programming

Join CFanatic Forum Now

Playing Sound In C++ topic posted under C++ Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 03-25-2010, 07:47 PM
Member
 
Join Date: Feb 2010
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
techme is on a distinguished road
| More
Exclamation Playing Sound In C++

I would like to make a program that would allow the user to make music based on various inputs, including numbers.

All my serching of the help system of c++ builder left me with no results on how to play a single sound, or how to tell the computer in one command (preferably) to play this instrument, this pitch, this duration and possibly some other parameters.

As far as I remember some older computers and languages used to have a PLAY command which looked something like this: PLAY(x,y,z etc).

Is something like that possible in C++? Searching the net it seems that the answer might be in calling a windows API to do that. But which API? Can anyone show me an example, some links or leads?

thanks,

mosnik

PS I do not speak here of making professional music, but not of using standard BEEP function either...
Reply With Quote
  #2  
Old 03-25-2010, 07:49 PM
Member
 
Join Date: Feb 2010
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
inspiration is on a distinguished road
| More
Re: Playing Sound In C++

Hi,

I think that a long, long, long time ago you could "play" certain frequencies through the PC speaker or serial line, but it was terrible sounding and YOU had to "tune" the interface.

Today I think it would be a lot easier to learn to use the API for the MIDI chip on your sound card. There is lots of music in midi files already on the internet.
Reply With Quote
  #3  
Old 03-25-2010, 07:49 PM
Member
 
Join Date: Feb 2010
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
techme is on a distinguished road
| More
Re: Playing Sound In C++

thanks for the leads, I will try around but something tells me that this is going to be a difficult task since direct manipulation of midi is a very specialised field, as fas as I know.
Reply With Quote
  #4  
Old 03-25-2010, 07:50 PM
pankaj.sea's Avatar
Super Moderator
 
Join Date: Sep 2009
Location: Serampore
Posts: 132
Thanks: 0
Thanked 2 Times in 2 Posts
pankaj.sea is on a distinguished road
| More
Re: Playing Sound In C++

The documentation for Windows audio can be found at this link:

http://msdn2.microsoft.com/en-us/library/aa830466.aspx

I've not done any audio/video programming for Windows so I can't offer any help about how to do it, but this info should at least get you started.
Reply With Quote
  #5  
Old 03-25-2010, 07:51 PM
Member
 
Join Date: Feb 2010
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
techme is on a distinguished road
| More
Re: Playing Sound In C++

Thanks for the lead, I followed it and got a bit scared of the size of the material! Anyway, for some time I will be studying it to see if I will be able to use it.



Thanks again,
Reply With Quote
  #6  
Old 03-25-2010, 07:52 PM
Member
 
Join Date: Feb 2010
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
creative is on a distinguished road
| More
Re: Playing Sound In C++

hello techme,
i have answer to your question

There is one way which i know .YOu have to use a manipulator for it i.e. \a.

cout<<"Beep sound \a";

With the use og \a you can hear a sound YOu can give as many \a you want
Reply With Quote
  #7  
Old 03-25-2010, 07:53 PM
Senior Member
 
Join Date: Feb 2010
Posts: 102
Thanks: 0
Thanked 0 Times in 0 Posts
meyup is on a distinguished road
| More
Re: Playing Sound In C++

I've been playing around with beep - I know you said more than beep, not not professional -- so I think this may work; using beep(freq, time) you can set the frequency and length of time the beep is set - this gives limited control but it's easy.

Cheers,
Code:
#include <iostream.h>
#include <windows.h>

void scale(void)
{ Beep(523,400); // 523 hertz (C5) for 400 milliseconds
 Beep(587,400);
 Beep(659,400);
 Beep(698,400);
 Beep(784,400);
 Beep(698,400);
 Beep(659,400);
 Beep(587,400);
 Beep(523,400);
}


int main()
{
 
 scale();
 cout << "Scale completed.\n";
  
 return 0;
}
Reply With Quote
  #8  
Old 04-11-2010, 12:16 PM
Junior Member
 
Join Date: Mar 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
davidk is on a distinguished road
| More
Re: Playing Sound In C++

If you are looking for really good stuff of how to deal with sound, consider Microsoft DirectSound. Please get DirectX sdk (use google to find it), install it and see examples of how to use DirectSound.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 01:44 AM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board