?
Solved

A Couple Questions in One!

Posted on 2003-03-14
14
Medium Priority
?
188 Views
Last Modified: 2010-04-01
I have a few questions that I would like to be answered:

1.)  Is there a way to make sound in Visual C++ and if so, is there some sort of guide anywhere that would show me what to put in my program to play certain notes, and another follow up question, is it possibly to play more than one note at once or put pauses between notes so i can make an actual song?

-Wow.  That was a mouthfull.-

2.)  Is there anywhere that I could download Visual C++ so that I could work on projects at my house and not just at school?

Thanks

Mark
0
Comment
Question by:simpsons17371
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
  • +2
14 Comments
 
LVL 8

Expert Comment

by:Exceter
ID: 8141487
>> Is there anywhere that I could download Visual C++ so that I could work on projects at my house and not just at school?

I'm afraid that would be a VERY illegal activity and it is therefore, a direct violation of the EE membership agreement.

Exceter
0
 
LVL 2

Expert Comment

by:DarthNemesis
ID: 8141525
There's a version of Visual packaged with some textbooks called the Introductory Edition; it allows you to run programs through the compiler but not to generate executable files, and is legal to use at home. I don't know if you could find it online, but it's possible that your school may have received it. Only your teacher would know.
0
 
LVL 8

Expert Comment

by:Exceter
ID: 8141549
>> There's a version of Visual packaged with some textbooks called the Introductory Edition; it allows you to run programs through the compiler
>> but not to generate executable files

Actually, it does allow you to build executable files. It simply pops up a little window stating the this program was compiled using the Introductory Edition and that it is illegal to distribute files generated with it. I know because that is what I use. It comes packaged with deitel and deitel's C++ How to program,

http://www.amazon.com/exec/obidos/tg/detail/-/0130384747/qid=1047707574/sr=8-1/ref=sr_8_1/002-3204003-0972054?v=glance&s=books&n=507846#product-details

Exceter
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:DarthNemesis
ID: 8141567
As for sounds, you have two options: either play sounds through the sound card, or beeps through the PC speaker. Either way, this site appears to have a plethora of examples:
http://www.synchrondata.com/pheaven/www/area25.htm#sub2
If you follow the link to Programmers Heaven, you can search for the actual files:
http://www.programmersheaven.com/search/advsearch.asp?SearchMode=1&SearchTxt1=pc+speaker
0
 

Expert Comment

by:Riham
ID: 8141809
As for sounds, u can check the following SDK function BOOL PlaySound(
  LPCSTR pszSound,  
  HMODULE hmod,    
  DWORD fdwSound    
);

the first paramater will be your file name, the second "NULL" the third will be your flags.

SND_ASYNC The sound is played asynchronously and PlaySound returns immediately after beginning the sound. To terminate an asynchronously played waveform sound, call PlaySound with pszSound set to NULL.

SND_FILENAME The pszSound parameter is a filename.

SND_LOOP The sound plays repeatedly until PlaySound is called again with the pszSound parameter set to NULL. You must also specify the SND_ASYNC flag to indicate an asynchronous sound event.

SND_NODEFAULT No default sound event is used. If the sound cannot be found, PlaySound returns silently without playing the default sound.

SND_NOSTOP The specified sound event will yield to another sound event that is already playing. If a sound cannot be played because the resource needed to generate that sound is busy playing another sound, the function immediately returns FALSE without playing the requested sound.
If this flag is not specified, PlaySound attempts to stop the currently playing sound so that the device can be used to play the new sound.
 
SND_PURGE Sounds are to be stopped for the calling task. If pszSound is not NULL, all instances of the specified sound are stopped. If pszSound is NULL, all sounds that are playing on behalf of the calling task are stopped.
You must also specify the instance handle to stop

SND_SYNC Synchronous playback of a sound event. PlaySound returns after the sound event completes.
0
 
LVL 12

Accepted Solution

by:
Salte earned 120 total points
ID: 8142032
first off,

There's no support for sound in C++. The point is that this question is not a question about language it is a question about platform.

On any platform that support sound and also support a C++ compiler there is also most likely support for sound for that C++ compiler for that platform.

In Windows there's DirectX which gives you total access to sound card. If you want only the PC speaker the OS also have - or had - some support for that. YOu can still access the PC speaker by sending codes to it. It might be a problem though that in Win2000 or WinXP or WinNT you are not allowed to do IN and OUT but I do believe there is a PC speaker driver that you can use to communicate with it and send tones.

In Linux on PC both sound cards and the PC speaker are available through drivers so by sending commands to drivers you can get sound on your computer.

In non PC computers there's also often either a sound card or a simple speaker or both which can be accessed through sending commands to a driver.

How you send commands to a driver is also platform specific, under Unix/Linux/FreeBSD etc you do that by the system call ioctl(). Under windows you can do it using the Win32 function call DeviceIoControl(). Other systems have similar manners to send commands to drivers.

Your question is very much platform specific and it therefore also follows that your other questions cannot be answered either. If you can play two or more notes at the same time depends on the platform. If you have only a simple speaker you cannot do that but with a soundcard you typically can.

Also, using a speaker you can make it sound as if you play two or more notes at the same time. It requires ingenious use of the speaker and the ability to rapidly sending it a bunch of commands in a sequence. If you make it alternate between two frequencies very fast it will sound as if it is playing two separate notes at the same time to a human ear.

Also, assuming that people who ask platform specific questions to a forum which isn't platform specific are people who use PC and windows (a likely assumption - most people who use other systems are usually aware of what is platform specific and what isn't - for some reason PC users are surprisingly often not aware of such a distinction). I can assume you're using windows and in that case the answers to your questions is:

Use DirectX if you want full control of the soundcard. This is what games and multi media software uses.

Use simple Win32 functions if you want simple control to play system sounds or beeps.

Use PC speaker if you want the speaker to sound. On WinNT, Win2000 or WinXP you need to use a driver since you can't do IN and OUT instructions directly. Use DeviceIoControl to send commands to the driver.

Hope this answers your question.

Alf
0
 
LVL 1

Author Comment

by:simpsons17371
ID: 8144825
so i guess that clears everything up...thanks guys!!!
0
 
LVL 1

Author Comment

by:simpsons17371
ID: 8146552
i went and i got Microsoft Visual C++ and i installed it on my computer but when i did that i tried to write just a simple program and run it...but ever time i do that it says:

Compiling...
Error spawning cl.exe

what does that mean and how can i fix it, i have tried everything
0
 
LVL 2

Expert Comment

by:DarthNemesis
ID: 8146798
This question has been asked before - here's a link to it:
http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_10228022.html

Microsoft also has some advice concerning it:
http://support.microsoft.com/default.aspx?scid=KB;en-us;q188720

From what I read it may come down to reinstalling Visual C++, so have that CD ready (assuming you did obtain a legal copy... o¿ô ).
0
 
LVL 2

Expert Comment

by:DarthNemesis
ID: 8146800
The site apparently doesn't like my ascii values... oh well, disregard the last word.
0
 
LVL 1

Author Comment

by:simpsons17371
ID: 8149059
i did get the version legally if u are implying that i didnt... that is why i asked if there was a way to get it without paying, noticing there was none, i went and bought it that day

those sites didnt do much for me but thanks anyway, i will uninstall and then re-install and get back to all of you guys

Mark
0
 
LVL 2

Expert Comment

by:DarthNemesis
ID: 8149089
Okay, okay, sorry for implying anything. =)

Anyway, hope reinstalling will work out.
0
 
LVL 1

Author Comment

by:simpsons17371
ID: 8149296
yeah so do i... i m starting the process like right now because i felt like eating dinner first, if it doesnt work i m gonna ask my teacher if he knows anything about it.

Mark
0
 
LVL 1

Author Comment

by:simpsons17371
ID: 8149420
Oh my God it worked!!!!!!!!!!!!! I am so happy it took me a long time to do it but it finally works.

Thank you for the help I am most grateful.

If I have anymore problems I will probably post them here, I dont have enough points to post another question...lol

Mark
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question