GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 08-May-2004, 09:05
Tripod Tripod is offline
New Member
 
Join Date: Jan 2004
Posts: 8
Tripod is on a distinguished road

PC speaker monophonic music


I want to play a monophonic song through my pc speaker using C code and have found very little help on the web. Do any of you guys have any examples I could look at?

Thanks
  #2  
Old 08-May-2004, 09:35
machinated machinated is offline
Regular Member
 
Join Date: Mar 2004
Location: victoria, canada
Posts: 324
machinated has a spectacular aura aboutmachinated has a spectacular aura about
I found some code that i've had for a long time. about 4 years or so. this code used to compile perfectly under turbo c++ 3.0 compiler. But it doesn't under newer compilers. probly cuz of dos.h Neway this should give you an idea on what to do. maybe you can substitute some of those old dos functions for newer functions and make it work. This is a code that i found somewhere online a long time ago. I do not know who wrote it. So the credit goes to whoever wrote it. It is a familiar jingle but i dont know which cuz i can't get the code to compile under msvc. Good luck anyway

CPP / C++ / C Code:
#include <dos.h>
#include <conio.h>
void playsound(int note, int duration);

int main()
{
 int song[][2]={
	392,250,392,375,330,125,330,250,
	392,250,392,375,294,125,294,250,
	330,250,349,250,392,250,440,250,
	494,250,392,750,392,250,392,375,
	330,125,330,250,392,250,392,375,
	294,125,294,250,587,250,554,250,
	587,250,659,250,404,250,587,750,
	392,250,659,375,659,125,587,250,
	523,250,523,375,494,125,494,250,
	523,250,587,250,494,250,440,250,
	392,250,523,750,523,250,523,375,
	440,125,440,250,523,250,440,250,
	392,125,392,250,392,250,440,250,
	523,250,392,250,587,250,523,750,
	0,0
	};
	int x=0;
	while(song[x++][0])
	playsound(song[x][0],song[x][1]);
	delay(100);
return 0;
}

 void playsound(int note, int duration)
 {
	do{
	sound(note);
	delay(duration);
	nosound();
	}
	while(!kbhit());
 }
 
 

Recent GIDBlogHalfway done! by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:27.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.