User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 426,882 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,291 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 6674 | Replies: 5
Reply
Join Date: Oct 2004
Posts: 22
Reputation: kakilang is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kakilang's Avatar
kakilang kakilang is offline Offline
Newbie Poster

How to code a program that can play sound

  #1  
Oct 27th, 2004
below is the simple source code

#include <iostream>
using namespace std;

int main()
{
cout<<"Hello"<<endl;
system("pause");
return 0;
}??

how to let program play some music when the program
print the word "Hello"??
Let's say the song file name is "hello.mpg".
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Posts: 6,330
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 28
Solved Threads: 458
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: How to code a program that can play sound

  #2  
Oct 27th, 2004
#include <stdmagic>

using namespace std;

int main()
{
  magically_do_something_platform_and_implementation_specific(PLAY_MUSIC, "hello.mpg");
}
By the way, what OS and compiler are you using? :rolleyes:
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Join Date: Oct 2004
Posts: 22
Reputation: kakilang is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kakilang's Avatar
kakilang kakilang is offline Offline
Newbie Poster

Re: How to code a program that can play sound

  #3  
Oct 27th, 2004
i use windows xp and dev c++ 4.9.9.0 compiler
Reply With Quote  
Join Date: Oct 2004
Location: Mojave Desert
Posts: 2,472
Reputation: vegaseat will become famous soon enough vegaseat will become famous soon enough 
Rep Power: 10
Solved Threads: 176
Moderator
vegaseat's Avatar
vegaseat vegaseat is online now Online
Kickbutt Moderator

Re: How to code a program that can play sound

  #4  
Oct 27th, 2004
Not quite ZZ Top but it's a start!
The Windows Api has a little thing called Beep(), try it ...

// simple sounds via Beep(frequency_hrz, duration_ms)

#include <iostream>
#include <windows.h>   // WinApi header file

using namespace std;

int main(int argc, char *argv[])
{
  Beep(523.2511,500);  // 523.2511 hertz (C5) for 500 milliseconds
  Beep(587.3295,500);
  Beep(659.2551,500);
  Beep(698.4565,500);
  Beep(783.9909,500);
  
  cin.get(); // wait
  return 0;
}
There are nicer things like sound(), that use the sound chip and midi voices. A little tough for C++. If you want to test it, get BCX free from:

http://www.rjpcomputing.com/programm.../devsuite.html

get used to BCXDX and learn to fly with sound and graphics! There are lots of sample files. This goes beyond the usual boring calculator and employee database stuff! You are still learning C/C++ though.
May 'the Google' be with you!
Reply With Quote  
Join Date: Oct 2004
Posts: 22
Reputation: kakilang is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kakilang's Avatar
kakilang kakilang is offline Offline
Newbie Poster

Re: How to code a program that can play sound

  #5  
Oct 28th, 2004
thx Vegaseat the program successdfully run and the beep sound is funny
Reply With Quote  
Join Date: Oct 2004
Posts: 22
Reputation: kakilang is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kakilang's Avatar
kakilang kakilang is offline Offline
Newbie Poster

Re: How to code a program that can play sound

  #6  
Oct 28th, 2004
Vegaseat do u know how to link the music or sound like "Hello.mpg"

when the compiler executed until cout<<"Hello"<<endl; and play some sound or music
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 10:33 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC