Package javax.sound.sampled

Examples of javax.sound.sampled.AudioFormat


    // need to chain the format conversions together.
    if (!AudioSystem.isConversionSupported(ais.getFormat(), decodedFormat))
    {
      if (ais.getFormat().getChannels() != decodedFormat.getChannels())
      {
        AudioFormat newFormat = new AudioFormat(ais.getFormat()
            .getEncoding(), decodedFormat.getSampleRate(),
            decodedFormat.getSampleSizeInBits(), ais.getFormat()
                .getChannels(), decodedFormat.getFrameSize(),
            decodedFormat.getFrameRate(), decodedFormat
                .isBigEndian());

        ais = AudioSystem.getAudioInputStream(newFormat, ais);
      }

      if (ais.getFormat().getSampleRate() != decodedFormat
          .getSampleRate())
      {
        AudioFormat newFormat = new AudioFormat(ais.getFormat()
            .getEncoding(), decodedFormat.getSampleRate(),
            decodedFormat.getSampleSizeInBits(), decodedFormat
                .getChannels(), decodedFormat.getFrameSize(),
            decodedFormat.getFrameRate(), decodedFormat
                .isBigEndian());
View Full Code Here


    return ais.getFrameLength();
  }

  public long skipSamples(long nframes) throws IOException
  {
    AudioFormat format = ais.getFormat();
    int bytesPerFrame = format.getFrameSize() / format.getChannels();
    return ais.skip(nframes * bytesPerFrame) / bytesPerFrame;
  }
View Full Code Here

  // stereo, the channels will be interleaved with each other in the
  // double stream, as in the byte stream. offset is the offset (in
  // samples) into audioData.
  private void bytes2doubles(byte[] audioBytes, double[] audioData, int offset)
  {
    AudioFormat format = ais.getFormat();
    if (format.getSampleSizeInBits() == 16)
    {
      if (format.isBigEndian())
      {
        for (int i = 0; i < audioData.length - offset; i++)
        {
          /* First byte is MSB (high order) */
          int MSB = (int) audioBytes[2 * i];
          /* Second byte is LSB (low order) */
          int LSB = (int) audioBytes[2 * i + 1];
          audioData[offset + i] = ((double) (MSB << 8 | (255 & LSB))) / 32768.0;
        }
      }
      else
      {
        for (int i = 0; i < audioData.length - offset; i++)
        {
          /* First byte is LSB (low order) */
          int LSB = (int) audioBytes[2 * i];
          /* Second byte is MSB (high order) */
          int MSB = (int) audioBytes[2 * i + 1];
          audioData[offset + i] = ((double) (MSB << 8 | (255 & LSB))) / 32768.0;
        }
      }
    }
    else if (format.getSampleSizeInBits() == 8)
    {
      // int nlengthInSamples = audioBytes.length;
      if (format.getEncoding().toString().startsWith("PCM_SIGN"))
      {
        for (int i = 0; i < audioBytes.length - offset; i++)
          audioData[offset + i] = audioBytes[i] / 128.0;
      }
      else
View Full Code Here

         {
           //set this file as read already
           edl.haveReadFile = true;
          
           //create the output format here
           AudioFormat outputFormat = new AudioFormat(44100, MEAPUtil.bitsPerSamp, 2, MEAPUtil.signed, MEAPUtil.bigEndian);
          
           try
           {
           //see which file we should be playing here
           String fileName = playOriginal ? BasePanel.inputSoundFileNameFull : BasePanel.outputSoundFileNameFull;
View Full Code Here

          shouldContinuePlaying = false;
        }
      });
     
      // configure the audio input and output lines
      AudioFormat inputAudioFormat = new AudioFormat(
          SAMPLE_RATE, 16, NUM_OUTPUT_CHANNELS, true, true);
      AudioFormat outputAudioFormat = new AudioFormat(
          SAMPLE_RATE, 16, NUM_INPUT_CHANNELS, true, true);
      DataLine.Info inputLineInfo = new DataLine.Info(TargetDataLine.class, inputAudioFormat);
      DataLine.Info outputLineInfo = new DataLine.Info(SourceDataLine.class, outputAudioFormat);
     
      short[] inputBuffer = new short[BLOCK_SIZE * NUM_INPUT_CHANNELS];
 
View Full Code Here

        private final SourceDataLine dataLine;

        public JavaSoundDirectAudioPlayerComponent(String format, int rate, int channels) throws Exception {
            super(format, rate, channels);
            this.audioFormat = new AudioFormat(rate, SAMPLE_BITS, channels, true, false);
            this.info = new Info(SourceDataLine.class, audioFormat);
            this.dataLine = (SourceDataLine)AudioSystem.getLine(info);
        }
View Full Code Here

  }

  protected AudioFormat getAudioFormat() {
    if (audioFormat == null) {
      Decoder decoder = getDecoder();
      audioFormat = new AudioFormat(decoder.getOutputFrequency(),
          16,
          decoder.getOutputChannels(),
          true,
          false);
    }
View Full Code Here

    }
    return audioFormat;
  }

  protected DataLine.Info getSourceLineInfo() {
    AudioFormat fmt = getAudioFormat();
    DataLine.Info info = new DataLine.Info(SourceDataLine.class, fmt);
    return info;
  }
View Full Code Here

    float sampleRate = 8000.0F;
    int sampleSizeInBits = 16;
    int channels = 1;
    boolean signed = true;
    boolean bigEndian = false;
    return new AudioFormat(sampleRate, sampleSizeInBits, channels, signed, bigEndian);
  }
View Full Code Here

    boolean signed = true;

    boolean bigEndian = false;

    return new AudioFormat(sampleRate, sampleSizeInBits, channels, signed, bigEndian);
  }
View Full Code Here

TOP

Related Classes of javax.sound.sampled.AudioFormat

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.