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.

Results 1 to 4 of 4

Thread: Change the pitch in a jButton

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Change the pitch in a jButton

    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?


  2. #2
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Change the pitch in a jButton

    Quote Originally Posted by leviorr View Post
    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?
    Sorry but your question is totally cryptic .... a JButton, by itself has nothing to do, directly, with sound. Explain what are you using to handle sounds, what is your user interface, what that button should do.
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  3. #3
    Junior Member
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Change the pitch in a jButton

    Quote Originally Posted by andbin View Post
    Sorry but your question is totally cryptic .... a JButton, by itself has nothing to do, directly, with sound. Explain what are you using to handle sounds, what is your user interface, what that button should do.
    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!

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Change the pitch in a jButton

    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.

Similar Threads

  1. how to change DB design for a change in java
    By harry7ster in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 7th, 2013, 12:57 PM
  2. Java Help (Penny Pitch Program) Someone please write this for me?
    By shaig13 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 30th, 2013, 09:35 AM
  3. Replies: 0
    Last Post: January 12th, 2012, 03:54 PM
  4. Type Erasure -- Sales pitch?
    By 2by4 in forum Collections and Generics
    Replies: 0
    Last Post: December 10th, 2011, 06:59 AM
  5. Java Pitch Detection and Replacement?
    By Stratgtar565 in forum Java Theory & Questions
    Replies: 1
    Last Post: September 12th, 2011, 03:34 AM

Tags for this Thread