Re: [LIP] Sound function

Arun Venkataswamy <[email protected]>
Newsgroups gmane.user-groups.linux.india.programmers
Message-ID <[email protected]>
Hi,

You can write your own funtions to program the PIT and get sound of the speaker.
info can be found at 

http://www.arl.wustl.edu/~lockwood/class/cs306/class-resources/gpe/speaker.txt.html

The following C code does that job.

void speaker(int freq)
{
unsigned short counter;
unsigned char temp;

	//Speaker port
	if (ioperm(0x61, 1, 1)) 
	{
 		perror("ioperm(speaker_port)"); 
   		return;
    }  
    //PIT Control port
	if (ioperm(0x43, 1, 1))   
 	{
  		perror("ioperm(PIT_port)"); 
    	return;
 	}
 	
 	//PIT Channel 2
	if (ioperm(0x42, 1, 1)) 
 	{
  		perror("ioperm(PIT_port)"); 
		return;
  	} 
  	
	counter = 0x1234DD / freq;
	outb(0xb6,0x43);
	outb(counter%256,0x42);
	outb(counter/256,0x42);
	temp = inb(0x61);
	outb(temp|3,0x61);
	ioperm(0x61, 1, 0);
	ioperm(0x43, 1, 0);
	ioperm(0x42, 1, 0);

}

void speaker_off(void)
{
unsigned char temp;

	//Speaker port
	if (ioperm(0x61, 1, 1)) 
 	{
  		perror("ioperm(speaker_port)"); 
    	return;
 	}  
	temp = inb(0x61);
	outb(temp&0xfc,0x61);
	ioperm(0x61, 1, 0);

}

BUT you should have permissions to access the ioports. You can run
that code as root.


Regards,
V.Arun






On Mon, 8 Nov 2004 09:43:47 +0530 (IST), H S Rai <[email protected]> wrote:
> Is there some function in C++ (GCC) to generate sound of particular
> frequency (for internal PC speaker) like:
> 
>        sound(frequency); // Generate sound of frequency
> 
> Thanks in advance,
> 
> --
> H.S.Rai    http://www.grex.org/~hsrai | Registered Linux User # 223684
> http://counter.li.org/cgi-bin/runscript/display-person.cgi?user=223684
> 
> :
> ####[ GNU/Linux One Stanza Tip (LOST) ]#######################
> 
> Sub : Knowing contents of .tbz files                 LOST #358
> 
> Knowing the contents of a .tbz file is a one step process:
> $tar -tyvf filename.tbz | less
> A .tbz file is essentially a bzipped-tarball (.tar.bz) file.
> 
> ####[bish (at) nde.vsnl.net.in]###############################
> :
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by:
> Sybase ASE Linux Express Edition - download now for FREE
> LinuxWorld Reader's Choice Award Winner for best database on Linux.
> http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
> _______________________________________________
> linux-india-programmers mailing list
> linux-india-programmers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/linux-india-programmers
> 


-- 

Arun Venkataswamy


-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.