working beep method in java.

Reply

Join Date: Nov 2008
Posts: 33
Reputation: AlbertPi is an unknown quantity at this point 
Solved Threads: 2
AlbertPi AlbertPi is offline Offline
Light Poster

working beep method in java.

 
0
  #1
Nov 19th, 2008
The following method "sound" works on my PC and it sounds a beep. I am using java 1.5
and Jdeveopler 10.1.3.4 on Windows XP/SP2.

import javax.sound.sampled.*;

public void handleBeep(ReturnEvent returnEvent)
{

try {
sound(2000,150);
} catch (LineUnavailableException lue) {
System.out.println(lue);
}
}


public static void sound(int hz,int msecs) throws LineUnavailableException {
byte[] buf = new byte[msecs*8];

for (int i=0; i<buf.length; i++) {
double angle = i / (8000.0 / hz) * 2.0 * Math.PI;
buf[i] = (byte)(Math.sin(angle) * 80.0);
}

AudioFormat af = new AudioFormat(8000f,8,1,true,false);
SourceDataLine sdl = AudioSystem.getSourceDataLine(af);
sdl.open(af);
sdl.start();
sdl.write(buf,0,buf.length);
sdl.drain();
sdl.close();
}
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 3,584
Reputation: jasimp has a spectacular aura about jasimp has a spectacular aura about jasimp has a spectacular aura about 
Solved Threads: 51
Featured Poster
jasimp's Avatar
jasimp jasimp is offline Offline
Senior Poster

Re: working beep method in java.

 
0
  #2
Nov 19th, 2008
I'm sorry but are you asking for help? If not, congratulations on getting your beep method to work. If you are asking for help, what is your question?
"Argyou not with the hand you are dealt in cards or life." ---- Wizard and Glass
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,433
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 507
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: working beep method in java.

 
0
  #3
Nov 19th, 2008
Drive-by code snippet.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 3,584
Reputation: jasimp has a spectacular aura about jasimp has a spectacular aura about jasimp has a spectacular aura about 
Solved Threads: 51
Featured Poster
jasimp's Avatar
jasimp jasimp is offline Offline
Senior Poster

Re: working beep method in java.

 
0
  #4
Nov 19th, 2008
Great, I have drive-by code snippets, drive-by flu shots, I think I'm set for life
"Argyou not with the hand you are dealt in cards or life." ---- Wizard and Glass
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: working beep method in java.

 
0
  #5
Nov 20th, 2008
Originally Posted by Ezzaral View Post
Drive-by code snippet.
that's what you get in 'tha H00d'
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 33
Reputation: AlbertPi is an unknown quantity at this point 
Solved Threads: 2
AlbertPi AlbertPi is offline Offline
Light Poster

Re: working beep method in java.

 
0
  #6
Nov 20th, 2008
Originally Posted by jasimp View Post
I'm sorry but are you asking for help? If not, congratulations on getting your beep method to work. If you are asking for help, what is your question?
I have no issue running this method on my PC, but i have an issue running this on Unix/Weblogic server. I got error message. See below:
" No line matching interface SourceDataLine supporting format PCM_SIGNED 8000.0 Hz, 8 bit, mono, 1 bytes/frame, is supported." from Unix (Sun). Any thought ? Thanks.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC