We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,852 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Putting an audio in a C++ program

My professor told me to put an audio in my program but he did not taught me how to. please help me because i do not have any idea on how to do this thing. i know that you guys are experties so please help me.. tnx alot.. :)

7
Contributors
11
Replies
2 Weeks
Discussion Span
1 Year Ago
Last Updated
12
Views
Question
Answered
franmaez_0716
Newbie Poster
9 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Depending on your OS, you probably have a simple "play this audio file" system call available.

There are also a variety of third-party multimedia libraries that provide a more flexible audio API, for example, SDL.

If you have some time to play with it, you might also consider OpenAL.

gusano79
Practically a Master Poster
666 posts since May 2004
Reputation Points: 193
Solved Threads: 107
Skill Endorsements: 6

..sorry but i can't get your point maybe because i'm just a beginner.. anyway.. what i want to know is that.. what code should i type to put a sound in my codes (simple c++ program).. tnx for the reply..

franmaez_0716
Newbie Poster
9 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Are you running Windows, Mac, or Linux?

If Windows, are you using Visual Studio, NetBeans, Eclipse, Dev-C++ or Turbo C++?

DeanMSands3
Posting Whiz
310 posts since Jan 2012
Reputation Points: 80
Solved Threads: 42
Skill Endorsements: 1

Here's a link for MS-Windows (and it won't matter which 32-bit compiler you use. It won't work with Turbo C or Turbo C++)

Ancient Dragon
Achieved Level 70
Team Colleague
32,116 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,575
Skill Endorsements: 69

Try this
I hope this helped

Karlwakim
Junior Poster in Training
94 posts since Dec 2011
Reputation Points: 27
Solved Threads: 2
Skill Endorsements: 0

Thank you for the link.. the samples are working but i used karlwakim's link for it allow mp3 files.. but i have 1 error..

c:\users\user\documents\kisses\cs102l\sramble rumble\scramble rumble.cpp(5) : fatal error C1083: Cannot open include file: 'irrKlang.h': No such file or directory

the samples given is working but when i've already put the code in my program.. it does not work..
please help me to fix my problem..

by the way.. this is my code..

#include<iostream>
#include<string>
#include<windows.h>
#include <conio.h>
#include <irrKlang.h>

using namespace std;
using namespace irrklang;

int main(int argc, const char** argv)
{
	// start the sound engine with default parameters
  ISoundEngine* engine = createIrrKlangDevice();

  if (!engine)
    return 0; // error starting up the engine
 
  // play some sound stream, looped
  engine->play2D("somefile.mp3", true);

  char i = 0;
  std::cin >> i; // wait for user to press some key

  engine->drop(); // delete engine
	const int a=5, b=5, c=5, d=5;
		string aword[a]={"valentines","internet","computer", "blanket", "mango"};
		string xword[a]={"veailtnnes","iteennrt","coemtupr", "blaknet", "mngao"};
		string bword[b]={"interfere", "necessary", "decision", "download", "official"};
		string yword[b]={"rfrtnieee", "nrsscyeea", "donsieci", "dloodwan", "oiialcff"};
		string cword[c]={"simultaneously", "successive", "equipments", "direction", "sphygmomanometer"};
		string zword[c]={"ylsuintlmsaeou", "uevsscceis", "steunmiepq", "ntcrdieio", "amermpegotsmnyho"};
		string j;

	int menu;
	int level;
	int point1=0;
	int point2=0;
	int p=0;
	int ctr=0;

	cout<<"\n\n\n\n\n\n\n\n\n\t\t\t\tInitializing";
	cout<<"\n\n\t\t\t\t    .";
	Sleep(350);
	cout<<".";
	Sleep(350);
	cout<<".";
	Sleep(350);

	system("cls");

	cout<<"\n\n\n\n\n\n\n\n\n\t\t\t\tInitializing";
	cout<<"\n\n\t\t\t\t    .";
	Sleep(350);
	cout<<".";
	Sleep(350);
	cout<<".";
	Sleep(350);

	system("cls");



	a:	
		cout<<"\n\n\n\n";
		Sleep(150);

		cout<<"\t#####  #####  #####      #      #      #  #####  #      #####"<<endl;
		Sleep(150);
		cout<<"\t#      #      #   #     # #     ##    ##  #   #  #      #    "<<endl;
		Sleep(150);
		cout<<"\t#####  #      #####    #   #    # #  # #  #####  #      #### "<<endl;
		Sleep(150);
		cout<<"\t    #  #      # #     #######   #  ##  #  #   #  #      #    "<<endl;
		Sleep(150);
		cout<<"\t    #  #      #  #   #       #  #      #  #   #  #      #    "<<endl;
		Sleep(150);
		cout<<"\t#####  #####  #   # #         # #      #  #####  #####  #####"<<endl;
		Sleep(250);

		cout<<"\n"<<endl;
		Sleep(250);

		cout<<"\t         #####  #   #  #      #  #####  #      ##### "<<endl;
		Sleep(150);
		cout<<"\t         #   #  #   #  ##    ##  #   #  #      #     "<<endl;
		Sleep(150);
		cout<<"\t         #####  #   #  # #  # #  #####  #      ####  "<<endl;
		Sleep(150);
		cout<<"\t         # #    #   #  #  ##  #  #   #  #      #     "<<endl;
		Sleep(150);
		cout<<"\t         #  #   #   #  #      #  #   #  #      #     "<<endl;
		Sleep(150);
		cout<<"\t         #   #  #####  #      #  #####  #####  ##### "<<endl;
		Sleep(250);

		system("cls");

		Sleep(150);
		cout<<"\n\n\n\n";
		cout<<"\t#####  #####  #####      #      #      #  #####  #      #####"<<endl;
		cout<<"\t#      #      #   #     # #     ##    ##  #   #  #      #    "<<endl;
		cout<<"\t#####  #      #####    #   #    # #  # #  #####  #      #### "<<endl;
		cout<<"\t    #  #      # #     #######   #  ##  #  #   #  #      #    "<<endl;
		cout<<"\t    #  #      #  #   #       #  #      #  #   #  #      #    "<<endl;
		cout<<"\t#####  #####  #   # #         # #      #  #####  #####  #####"<<endl;

		cout<<"\n"<<endl;

		cout<<"\t         #####  #   #  #      #  #####  #      ##### "<<endl;
		cout<<"\t         #   #  #   #  ##    ##  #   #  #      #     "<<endl;
		cout<<"\t         #####  #   #  # #  # #  #####  #      ####  "<<endl;
		cout<<"\t         # #    #   #  #  ##  #  #   #  #      #     "<<endl;
		cout<<"\t         #  #   #   #  #      #  #   #  #      #     "<<endl;
		cout<<"\t         #   #  #####  #      #  #####  #####  ##### "<<endl;

		Sleep(450);
		cout<<"\n\n\n\t\t\t    Press any key to play." << endl;

		
		getch();
		system("cls");



	b:

		system("cls");

		cout<<"\n\n\n\n\n\n\n\n\n\t\t\t\t Main Menu"<<endl;
		cout<<"\n\t\t\t\t [1]Play"<<endl;
		cout<<"\t\t\t\t [2]Exit"<<endl;
		cin>>menu;

		system("cls");

			if(menu==1)
			{
				goto c;
			}

			else if(menu==2)
			{
				exit(0);
			}

			else
			{
				cout<<"\n\n\n\n\n\n\n\n\n\n\n\t\t\t\tInvalid Selection"<<endl;
				cout<<"\t\t\t\tPlease Try Again!"<<endl;

				getch();
				system("cls");
				goto b;
			}


	c:

		cout<<"\n\n\n\n\n\n\n\n\n\t\t\t Select Difficulty Level"<<endl;
		cout<<"\n\t\t\t\t [1]Easy"<<endl;
		cout<<"\t\t\t\t [2]Normal"<<endl;
		cout<<"\t\t\t\t [3]Hard"<<endl;
		cout<<"\t\t\t\t [4]Main Menu"<<endl;
		cin>>level;

		system("cls");

			switch(level)
			{
			case 1: cout<<"\n\n\t\t\t\t| Easy Level |"<<endl; 
					Sleep(500);
					cout<<"\nAre you ready? [ENTER]"<<endl;

					getch();
			goto d; break;

			case 2: cout<<"\n\n\t\t\t\t| Normal Level |"<<endl; 
					Sleep(500);
					cout<<"\nAre you ready? [ENTER]"<<endl;

					getch();
			goto d; break;

			case 3: cout<<"\n\n\t\t\t\t| Hard Level |"<<endl; 
					Sleep(500);
					cout<<"\nAre you ready? [ENTER]"<<endl;

					getch();
			goto d; break;

			case 4: goto b; break;

			default:
			cout<<"\n\n\n\n\n\n\n\n\n\n\n\t\t\t\tInvalid Selection"<<endl;
			cout<<"\t\t\t\tPlease Try Again!"<<endl; break;
			}

		getch();
		system("cls");

		goto c;


	d:
		if(level==1)
		{
			for(int i=0;i<a;i++)
			{
			cout<<"\n  "<<xword[i]<<endl;
			cout<<"  ";
			cin>>j;

			ctr++;
				if(j==aword[i])
				{
				cout<<"\n"<<endl;
				cout<<"   "<<i+1<<" "<<"Point(s)"<<endl; 

				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"<<endl; Sleep(100);
				
				
				Sleep(500);
				}
				
				else
				{
				cout<<"\nWrong"<<endl;
				cout<<"   "<<i-0<<" "<<"Point(s)"<<endl;

				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"<<endl; Sleep(100);

				Sleep(500);
				}

			}
		}



		else if(level==2)
		{
			for(int i=0;i<b;i++)
			{
			cout<<"\n  "<<yword[i]<<endl;
			cout<<"  ";
			cin>>j;

			ctr++;
				if(j==bword[i])
				{
				cout<<"\n"<<endl;
				cout<<"   "<<i+1<<" "<<"Point(s)"<<endl;		
				
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"<<endl; Sleep(100);
				
				
				Sleep(500);
				}

				else
				{
				cout<<"\nWrong"<<endl;
				cout<<"   "<<i-0<<" "<<"Point(s)"<<endl;
			
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"<<endl; Sleep(100);
				
				
				Sleep(500);
				}

			}
		}



		else if(level==3)
		{
			for(int i=0;i<a;i++)
			{
			cout<<"\n  "<<zword[i]<<endl;
			cout<<"  ";
			cin>>j;

			ctr++;
				if(j==cword[i])
				{
				cout<<"\n";
				cout<<"   "<<i+1<<" "<<"Point(s)"<<endl; 
							
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"<<endl; Sleep(100);
				
				
				Sleep(500);
				}
				else
				{
				cout<<"\nWrong"<<endl;
				cout<<"   "<<i-0<<" "<<"Point(s)"<<endl;
						
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"; Sleep(100);
				cout<<"-"<<endl; Sleep(100);
				
				
				Sleep(500);
				}

			}
		}


return 0;
}

thanks for the help..

franmaez_0716
Newbie Poster
9 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

did you download the appropriate header files?

zeroliken
Nearly a Posting Virtuoso
1,346 posts since Nov 2011
Reputation Points: 214
Solved Threads: 205
Skill Endorsements: 14

#include <irrKlang.h> should be #include "irrKlang.h" ??

if the file lives in your project not in CC it should almost definatley be in quotes instead of angle brackets.

Kanoisa
Posting Whiz in Training
225 posts since Jul 2008
Reputation Points: 62
Solved Threads: 28
Skill Endorsements: 0

yes i've downloaded the irrklang header files and the samples are working.. i've also tried replacing brackets with quotes but still the error is the same..

franmaez_0716
Newbie Poster
9 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

So then are the headders where your project expects them?

The files being on your computer is not enough, the compiler and linker need to know where the files live, the easy test is to first try copying the headder file into your projects directory in the same folder as main.cpp, Then the compiler should find it for sure.

Kanoisa
Posting Whiz in Training
225 posts since Jul 2008
Reputation Points: 62
Solved Threads: 28
Skill Endorsements: 0

..thank you for helping me..:)

franmaez_0716
Newbie Poster
9 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by Kanoisa, gusano79, Ancient Dragon and 3 others

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0948 seconds using 2.71MB