Hi.
Can you play music in c++ in a program?
if so does anyone have any code on how it works?
Thanks
Hi.
Can you play music in c++ in a program?
if so does anyone have any code on how it works?
Thanks
Search the fourms or Google for playsound. It's a common question.
Last edited by twomers; 09-04-2006 at 08:19 AM.
Thanks i got it
just another question
i have created a sound using beeps and was wondering if i can have a count down happening at the same time as the music?
if so how will i do it
here is the code for the timer
and this is the beepsCode:cout<< "Washing...\n"; for (n=30; n>0; n--) { printf ("%d\n",n); wait (1); } cout << ("WASHING COMPLETE\n"); return 0; }
at the moment it will either play the music then countdown or countdown then play but i would like it to do both.Code:Beep(523,500); Beep(784,500); Beep(784,500); Beep(872,500); Beep(872,500); Beep(784,600); Beep(698,500);
do something like
that is just a of the top of my head suggestion, but I think it will work, of course your question was quiet vagueCode:for ( int x = 0; x != 30; ++x ) { Beep(int, int); printf("&d\n", n ); wait(1); }
I think Raigne means:
but seeing as it's the C++ board you should use cout<< n << '\n'; reallyCode:for ( int n = 0; n != 30; ++n) { Beep(int, int); printf("%d\n", n ); wait(1); }
Also, I've been meaning to ask you, why don't you use Sleep() instead of making your wait() function?
Because Sleep() is not standard while wait() potentially is.Originally Posted by twomers
Sent from my iPadŽ
cool, thanx, ill give it a go
the reason why i have not use sleep is because i dont knw how to use that command.
That sleeps for 100 mili seconds. For your example, change it to Sleep( 1000 );Code:#include <windows.h> int main( void ) { ... whatever Sleep( 100 ); ... whatever }
Whats the difference betwen Sleep and wait?
As I said, one is horribly not portable to Linux, the other is a home made function that could have been written using <ctime> functions and could potentially be standard. Why twomers still insists on suggesting it, I have no idea. There are standard alternatives.Originally Posted by l2u
Sent from my iPadŽ
The OP made the wait() function, and it's portable potential etc, Sleep() is in <windows.h>
>> Why twomers still insists on suggesting it, I have no idea.
Initially I was curious as to why the OP didn't use it, and then when he didn't know how to use it, I showed him. Plus, I see absolutely no reason in not giving alternatives to people. But I agree that there are standard alternatives. How could I not Sleep(), IMO (I mainly use windows you see), is a quicker to write
Last edited by twomers; 09-04-2006 at 11:26 AM.
just tried the code and it has to play the beep before counting down to the next number,
is it possible to get the both of them going at the same time so i have a melody whilst it is counting down because i have 20 or so beeps and i have to wait for them to finish untill it counts down 10 then again for 9 and so on till the counter gets to zero?
Ok, how long to the beeps last for? Seconds wise? You can play the beep, then wait() for ( 1 second - beep time ). Get me?
each beep last 500th of a second n got about 20
Ok then. Does your wait function only take integers?
Altertatively, you can make a timing class to time the beep function, and then subtract that number from 1 second.Code:for( limits ) { beep() wait( 0.5 ); // or wait( 1.0 - 0.5 ) cout<< "BEEP!"; }