Package javax.sound.sampled

Examples of javax.sound.sampled.AudioInputStream$TargetDataLineInputStream


public class WaveMedia implements Media {
  protected Clip clip;

  public WaveMedia(InputStream is) throws Exception {
    AudioInputStream ais = AudioSystem.getAudioInputStream(is);
    DataLine.Info info = new DataLine.Info(Clip.class, ais.getFormat());
    clip = (Clip) AudioSystem.getLine(info);
    try {
      clip.open(ais);
    } catch(LineUnavailableException e) {
      System.err.println("Audio not working.");
View Full Code Here


    if (!soundFile.exists()) {
      System.err.println("Wave file not found: " + filename);
      return;
    }
    AudioInputStream audioInputStream = null;
    try {
      audioInputStream = AudioSystem.getAudioInputStream(soundFile);
    } catch (UnsupportedAudioFileException e1) {
      e1.printStackTrace();
      return;
    } catch (IOException e1) {
      e1.printStackTrace();
      return;
    }
    AudioFormat format = audioInputStream.getFormat();
    SourceDataLine auline = null;
    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;
    }
    if (auline.isControlSupported(FloatControl.Type.PAN)) {
      FloatControl pan = (FloatControl) auline
          .getControl(FloatControl.Type.PAN);
      if (curPosition == Position.RIGHT)
        pan.setValue(1.0f);
      else if (curPosition == Position.LEFT)
        pan.setValue(-1.0f);
    }
    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();
View Full Code Here

        if (!soundFile.exists()) {
            System.err.println("Wave file not found: " + filename);
            return;
        }

        AudioInputStream audioInputStream = null;
        try {
            audioInputStream = AudioSystem.getAudioInputStream(soundFile);
        } catch (UnsupportedAudioFileException e1) {
            e1.printStackTrace();
            return;
        } catch (IOException e1) {
            e1.printStackTrace();
            return;
        }

        AudioFormat format = audioInputStream.getFormat();
        SourceDataLine auline = null;
        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;
        }

        if (auline.isControlSupported(FloatControl.Type.PAN)) {
            FloatControl pan = (FloatControl) auline.getControl(FloatControl.Type.PAN);
            if (curPosition == Position.RIGHT) {
                pan.setValue(1.0f);
            } else if (curPosition == Position.LEFT) {
                pan.setValue(-1.0f);
            }
        }

        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) {
View Full Code Here

        streamConfiguration.setBitsPerSample(16);
        streamConfiguration.setChannelCount(1);


        try {
            AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(inputFile);
            AudioFormat format = audioInputStream.getFormat();

            int frameSize = format.getFrameSize();

            FLACEncoder flacEncoder = new FLACEncoder();
            FLACFileOutputStream flacOutputStream = new FLACFileOutputStream(outputFile);

            flacEncoder.setStreamConfiguration(streamConfiguration);
            flacEncoder.setOutputStream(flacOutputStream);

            flacEncoder.openFLACStream();

            int[] sampleData = new int[(int) audioInputStream.getFrameLength()];
            byte[] samplesIn = new byte[frameSize];

            int i = 0;

            while (audioInputStream.read(samplesIn, 0, frameSize) != -1) {
                if (frameSize != 1) {
                    ByteBuffer bb = ByteBuffer.wrap(samplesIn);
                    bb.order(ByteOrder.LITTLE_ENDIAN);
                    short shortVal = bb.getShort();
                    sampleData[i] = shortVal;
                } else {
                    sampleData[i] = samplesIn[0];
                }

                i++;
            }

            flacEncoder.addSamples(sampleData, i);
            flacEncoder.encodeSamples(i, false);
            flacEncoder.encodeSamples(flacEncoder.samplesAvailableToEncode(), true);

            audioInputStream.close();
            flacOutputStream.close();

        } catch (Exception ex) {
            ex.printStackTrace();
        }
View Full Code Here

        for (int i = 0; i < audioStrings.length; i++) {
          if (actionKey.equals(audioStrings[i])){
            try {
              String audioFileName = (String)UIManager.get(audioStrings[i]);
              URL audioURL = Win32LookAndFeel.class.getResource(audioFileName);
              AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(audioURL.getFile()));
              AudioFormat format = audioInputStream.getFormat();
              DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
              SourceDataLine auline = (SourceDataLine) AudioSystem.getLine(info);
              auline.open(format);
              auline.start();
              int nBytesRead = 0;
              byte[] abData = new byte[524288];

              while (nBytesRead != -1) {
                nBytesRead = audioInputStream.read(abData, 0, abData.length);
                if (nBytesRead >= 0)
                  auline.write(abData, 0, nBytesRead);
              }

            } catch (UnsupportedAudioFileException e) {
View Full Code Here

        for (int i = 0; i < audioStrings.length; i++) {
          if (actionKey.equals(audioStrings[i])){
            try {
              String audioFileName = (String)UIManager.get(audioStrings[i]);
              URL audioURL = Win32LookAndFeel.class.getResource(audioFileName);
              AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(audioURL.getFile()));
              AudioFormat format = audioInputStream.getFormat();
              DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
              SourceDataLine auline = (SourceDataLine) AudioSystem.getLine(info);
              auline.open(format);
              auline.start();
              int nBytesRead = 0;
              byte[] abData = new byte[524288];

              while (nBytesRead != -1) {
                nBytesRead = audioInputStream.read(abData, 0, abData.length);
                if (nBytesRead >= 0)
                  auline.write(abData, 0, nBytesRead);
              }

            } catch (UnsupportedAudioFileException e) {
View Full Code Here

   */
  @Override
  protected void playIt() {
    try {
      // Get AudioInputStream from given file.
      AudioInputStream in = AudioSystem.getAudioInputStream(file);
      AudioInputStream din = null;
      if (in != null) {
        AudioFormat baseFormat = in.getFormat();
        AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16,
            baseFormat.getChannels(), baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false);
        // Get AudioInputStream that will be decoded by underlying
View Full Code Here

   */
  @Override
  protected void playIt() {
    try {
      // Get AudioInputStream from given file.
      AudioInputStream in = AudioSystem.getAudioInputStream(file);
      AudioInputStream din = null;
      if (in != null) {
        AudioFormat baseFormat = in.getFormat();
        AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16,
            baseFormat.getChannels(), baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false);
        // Get AudioInputStream that will be decoded by underlying
View Full Code Here

    {
      loadSoundSingleLine(sound,path);
      return;
    }
    try{
       AudioInputStream stream;
       URL loadedSound = getClass().getResource(path);
       if(loadedSound!=null)stream=AudioSystem.getAudioInputStream(loadedSound.openStream());
        else stream=AudioSystem.getAudioInputStream(new File(path));
                    
            AudioFormat format = stream.getFormat();
          
            DataLine.Info info = new DataLine.Info(
                                      Clip.class,
                                      stream.getFormat(),
                                      ((int) stream.getFrameLength() *
                                          format.getFrameSize()));

            Clip clip = (Clip) AudioSystem.getLine(info);
            clip.open(stream);
          sounds.put(sound,clip);
View Full Code Here

 
  private void loadSoundSingleLine(String sound,String path)
  {//preload sound, no clip because that doesn't work on OS/2
   
    try{
      AudioInputStream stream;
      URL loadedSound = getClass().getResource(path);
       if(loadedSound!=null)stream=AudioSystem.getAudioInputStream(new BufferedInputStream(loadedSound.openStream()));
        else stream=AudioSystem.getAudioInputStream(new File(path));
         
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      int nBufferSize = 1024 * stream.getFormat().getFrameSize();
      byte[]  abBuffer = new byte[nBufferSize];
      int nBytesRead;
      while ((nBytesRead = stream.read(abBuffer))>0 )
      {
        baos.write(abBuffer, 0, nBytesRead);
      }
      sounds.put(sound,new Object[]{stream.getFormat(),baos.toByteArray()});
    }catch (IOException e)
    {
      Popups.errorPopup(MessageFormat.format(I18N.gettext("sound.{0}_not_found"),new Object[]{sound}),I18N.gettext("sound.Sound_not_found"));
    }
    catch (UnsupportedAudioFileException e)
View Full Code Here

TOP

Related Classes of javax.sound.sampled.AudioInputStream$TargetDataLineInputStream

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.