I am trying to change the pitch of a wave file while mouse entering a JButton. the problem is the JButton object doesn't support the SAMPLE_RATE control. what can I do to change the pitch?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
I am trying to change the pitch of a wave file while mouse entering a JButton. the problem is the JButton object doesn't support the SAMPLE_RATE control. what can I do to change the pitch?
Andrea, www.andbin.net — SCJP 5 (91%) – SCWCD 5 (94%)
Useful links for Java beginners – My new project Java Examples on Google Code
I am trying to play a wave file when the mouse enters different JButton objects. on the MouseEntered events I call this function:
public void playSound(String fileName) { audioInputStream = null; File soundFile; soundFile = new File(fileName); SourceDataLine auline = null; if (!soundFile.exists()) { System.err.println("Wave file not found: " + soundFile); return; } try { audioInputStream = AudioSystem.getAudioInputStream(soundFile); } catch (UnsupportedAudioFileException e1) { e1.printStackTrace(); return; } catch (IOException e1) { e1.printStackTrace(); return; } AudioFormat format = audioInputStream.getFormat(); DataLine.Info info = new DataLine.Info(SourceDataLine.class, format); try { auline = (SourceDataLine) AudioSystem.getLine(info); auline.open(format); } catch (LineUnavailableException e) { e.printStackTrace(); return; } catch (Exception e) { e.printStackTrace(); return; } //////////////////////// here I would like to change the pitch of the sound/////////////////////////////////////////////////////////////////////////// auline.start(); int nBytesRead = 0; byte[] abData = new byte[EXTERNAL_BUFFER_SIZE]; try { while (nBytesRead != -1) { nBytesRead = audioInputStream.read(abData, 0, abData.length); if (nBytesRead >= 0) auline.write(abData, 0, nBytesRead); } } catch (IOException e) { e.printStackTrace(); return; } finally { auline.drain(); auline.close(); auline = null; try { audioInputStream.close(); } catch (IOException e) { e.printStackTrace(); } } }
I tried using: (auline.isControlSupported(FloatControl.Type.SAMPL E_RATE)) but I the control is not supported.
thank you!
Please edit your post and wrap your code with code tags:
[code=java]
YOUR CODE HERE
[/code]
to get highlighting and preserve formatting.
If you don't understand my answer, don't ignore it, ask a question.