Package javax.sound.sampled

Examples of javax.sound.sampled.FloatControl


                e3.printStackTrace();
            }
       
            if(clip.isControlSupported(FloatControl.Type.MASTER_GAIN))
            {
                FloatControl flc = (FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN);
                float volume = Preferences.getInteger("sound","volume",0);
                if (volume >flc.getMaximum())
                {
                    volume=flc.getMaximum();
                }
         
                flc.setValue(volume);
            }
         
            //clip.setFramePosition(0);
            clip.start()
            try
View Full Code Here


public class FloatControlTest extends TestCase {

    public void testFloatControl() {

        FloatControl control = new MyControl(FloatControl.Type.MASTER_GAIN, 1f,
                10f, 3f, 4, 5f, "units", "minLabel", "midLabel", "maxLabel");

        assertEquals(FloatControl.Type.MASTER_GAIN, control.getType());
        assertEquals(1f, control.getMinimum());
        assertEquals(10f, control.getMaximum());
        assertEquals("units", control.getUnits());
        assertEquals("minLabel", control.getMinLabel());
        assertEquals("midLabel", control.getMidLabel());
        assertEquals("maxLabel", control.getMaxLabel());
        assertEquals(3f, control.getPrecision());
        assertEquals(4, control.getUpdatePeriod());

        assertEquals(5f, control.getValue());
        control.setValue(9f);
        assertEquals(9f, control.getValue());
        control.shift(9f, 4f, 5);
        assertEquals(4f, control.getValue());
        assertEquals(
                "Master Gain with current value: 4.0 units (range: 1.0 - 10.0)",
                control.toString());

        try {
            control.setValue(15f);
            fail("No expected IllegalArgumentException");
        } catch (IllegalArgumentException expected) {
        }

        control = new MyControl(FloatControl.Type.SAMPLE_RATE, 1f, 10f, 3f, 4,
                5f, "units");
        assertEquals(FloatControl.Type.SAMPLE_RATE, control.getType());
        assertEquals(1f, control.getMinimum());
        assertEquals(10f, control.getMaximum());
        assertEquals("units", control.getUnits());
        assertEquals("", control.getMinLabel());
        assertEquals("", control.getMidLabel());
        assertEquals("", control.getMaxLabel());
        assertEquals(3f, control.getPrecision());
        assertEquals(4, control.getUpdatePeriod());
        assertEquals(5f, control.getValue());
        assertEquals(
                "Sample Rate with current value: 5.0 units (range: 1.0 - 10.0)",
                control.toString());

    }
View Full Code Here

     * @param line the line to set the volume on
     * @param vol the volume (range 0 to 1)
     */
    private void setVolume(Clip clip, float vol) {
        if (clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
            FloatControl volumeControl =
                (FloatControl) clip.getControl (FloatControl.Type.MASTER_GAIN);
            float range = volumeControl.getMaximum() -
            volumeControl.getMinimum();
            volumeControl.setValue(vol * range + volumeControl.getMinimum());
        }
    }
View Full Code Here

            InputStream bufferedIn = new BufferedInputStream(audiosrc);
            AudioInputStream ai = AudioSystem.getAudioInputStream(bufferedIn);
            clip.open(ai);
           
            //volume control
            FloatControl control = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
            //reduce volume by 30 dec
            control.setValue(-20.0f);
           
            clip.start();
           
          } catch (Exception e) {
            System.err.println(e.getMessage());
View Full Code Here

  }
 
  private float gain;
  public void toggleSound() {
    if (clip != null) {     
      FloatControl volume = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
      volume.getValue();
      if (soundOn) {
        gain = volume.getValue();
        volume.setValue(-80);
      } else if (!soundOn) {
        volume.setValue(gain);
      }
    }
    soundOn = !soundOn;
    this.repaint();
  }
View Full Code Here

  public static void printControl(Control memberControl) {
    if (memberControl instanceof BooleanControl) {
      BooleanControl bc = (BooleanControl) memberControl;
      System.out.println(bc + ": " + bc.getValue());
    } else if (memberControl instanceof FloatControl) {
      FloatControl fc = (FloatControl) memberControl;
      System.out.println(fc + ": " + fc.getValue());

    } else if (memberControl instanceof EnumControl) {
      EnumControl ec = (EnumControl) memberControl;
      System.out.println(ec + ": " + ec.getValue());
    } else if (memberControl instanceof CompoundControl) {
View Full Code Here

                            {
                                port.open();
                            }
                            if (port.isControlSupported(FloatControl.Type.VOLUME))
                            {
                                FloatControl volumeControl = (FloatControl) port.getControl(FloatControl.Type.VOLUME);
                                float min = volumeControl.getMinimum();
                                float max = volumeControl.getMaximum();
                                float current = volumeControl.getValue();
                                double percent = 100.0 * (current - min) / (max - min);
//                                System.out.println("Current Volume is " + percent + "%.");
    // setting to 50%
                                float v = (max - min) / 2.0f + min;
                                v = (((max - min)/100)*vol) +min;
                                volumeControl.setValue(v);
                            }

                        } finally
                        {
                            if (openPortNeeded && port.isOpen())
View Full Code Here

                        Control[]  aControls = port.getControls();
                        for (int t = 0; t < aControls.length; t++)
                        {
                            if (aControls[t] instanceof FloatControl)
                            {
                                FloatControl control = (FloatControl) aControls[t];
                                Control.Type type = control.getType();
                                String strControlName = type.toString();
                                if (!isVolumne(control)) continue;
//System.out.println("Control direct: " +  strControlName);
//
                                FloatControl volumeControl = (FloatControl) control;
                                float min = volumeControl.getMinimum();
                                float max = volumeControl.getMaximum();
                                float current = volumeControl.getValue();
                                double percent = 100.0 * (current - min) / (max - min);
                                // System.out.println("Current Volume is " + percent + "%.");
                                volumeSet = true;
    // setting to 50%
                                float v = (max - min) / 2.0f + min;
                                v = (((max - min)/100)*vol) +min;
                                volumeControl.setValue(v);
                            }
                            if (aControls[t] instanceof CompoundControl)
                            {
                                CompoundControl control = (CompoundControl) aControls[t];

                                String strControlName = control.getType().toString();
//System.out.println("Control compound: " +  strControlName);
                                Control[] subControls = control.getMemberControls();
                                for (int s = 0; s < subControls.length; s++)
                                {
                                    Control con = subControls[s];
                                    if (con instanceof FloatControl)
                                    {
                                        FloatControl subCon = (FloatControl)con;
                                        String strControlSubName = subCon.getType().toString();
                                        if (!isVolumne(subCon)) continue;
//System.out.println("Control sub: " +  strControlSubName);
//



                                        FloatControl volumeControl = (FloatControl) subCon;
                                        float min = volumeControl.getMinimum();
                                        float max = volumeControl.getMaximum();
                                        float current = volumeControl.getValue();
                                        double percent = 100.0 * (current - min) / (max - min);
                                        // System.out.println("Current Volume is " + percent + "%.");
            // setting to 50%
                                        float v = (max - min) / 2.0f + min;
                                        v = (((max - min)/100)*vol) +min;
                                        volumeControl.setValue(v);

                                        volumeSet = true;
                                    }
                                }

View Full Code Here

                            Line line;
                            try
                            {
                                line = m.getLine(li);
                                Control[] c = line.getControls();
                                FloatControl volume= (FloatControl) line.getControl(FloatControl.Type.MASTER_GAIN);                                
                                float max = volume.getMaximum();
                                float min = volume.getMinimum();
                                float dist = max-min;
                               
                                float v = dist /100 *vol;

                                volume.setValue(min+v);
                            }
                            catch (Throwable ex)
                            {
                                Logger.getLogger(Audio.class.getName()).log(Level.SEVERE, null, ex);
                            }
View Full Code Here

  public static void printControl(Control memberControl) {
    if (memberControl instanceof BooleanControl) {
      BooleanControl bc = (BooleanControl) memberControl;
      System.out.println(bc + ": " + bc.getValue());
    } else if (memberControl instanceof FloatControl) {
      FloatControl fc = (FloatControl) memberControl;
      System.out.println(fc + ": " + fc.getValue());

    } else if (memberControl instanceof EnumControl) {
      EnumControl ec = (EnumControl) memberControl;
      System.out.println(ec + ": " + ec.getValue());
    } else if (memberControl instanceof CompoundControl) {
View Full Code Here

TOP

Related Classes of javax.sound.sampled.FloatControl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.