1,105,578 Community Members

Putting an audio in a C++ program

Member Avatar
franmaez_0716
Newbie Poster
9 posts since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.. :)

Member Avatar
gusano79
Practically a Posting Shark
816 posts since May 2004
Reputation Points: 203 [?]
Q&As Helped to Solve: 131 [?]
Skill Endorsements: 10 [?]
 
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.

Member Avatar
franmaez_0716
Newbie Poster
9 posts since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
1
 

..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..

Member Avatar
DeanMSands3
Posting Whiz
358 posts since Jan 2012
Reputation Points: 57 [?]
Q&As Helped to Solve: 49 [?]
Skill Endorsements: 2 [?]
 
0
 

Are you running Windows, Mac, or Linux?

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

Member Avatar
Ancient Dragon
Achieved Level 70
27,668 posts since Aug 2005
Reputation Points: 5,234 [?]
Q&As Helped to Solve: 3,040 [?]
Skill Endorsements: 115 [?]
Team Colleague
Featured
Sponsor
 
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++)

Member Avatar
Karlwakim
Junior Poster in Training
94 posts since Dec 2011
Reputation Points: 17 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
1
 

Try this
I hope this helped

Member Avatar
franmaez_0716
Newbie Poster
9 posts since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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..

Member Avatar
zeroliken
Nearly a Posting Virtuoso
1,222 posts since Nov 2011
Reputation Points: 79 [?]
Q&As Helped to Solve: 216 [?]
Skill Endorsements: 15 [?]
 
0
 

did you download the appropriate header files?

Member Avatar
Kanoisa
Posting Whiz in Training
227 posts since Jul 2008
Reputation Points: 52 [?]
Q&As Helped to Solve: 29 [?]
Skill Endorsements: 0 [?]
 
0
 

#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.

Member Avatar
franmaez_0716
Newbie Poster
9 posts since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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..

Member Avatar
Kanoisa
Posting Whiz in Training
227 posts since Jul 2008
Reputation Points: 52 [?]
Q&As Helped to Solve: 29 [?]
Skill Endorsements: 0 [?]
 
1
 

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.

Member Avatar
franmaez_0716
Newbie Poster
9 posts since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

..thank you for helping me..:)

Question Answered as of 2 Years Ago by Kanoisa, gusano79, Ancient Dragon and 3 others
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article