Package javax.sound.sampled

Examples of javax.sound.sampled.AudioFormat


  private void listenSound(long songId, boolean isMatching)
      throws LineUnavailableException, IOException,
      UnsupportedAudioFileException {

    AudioFormat formatTmp = null;
    TargetDataLine lineTmp = null;
    String filePath = fileTextField.getText();
    AudioInputStream din = null;
    AudioInputStream outDin = null;
    PCM2PCMConversionProvider conversionProvider = new PCM2PCMConversionProvider();
    boolean isMicrophone = false;

    if (filePath == null || filePath.equals("") || isMatching) {

      formatTmp = getFormat(); // Fill AudioFormat with the wanted
                    // settings
      DataLine.Info info = new DataLine.Info(TargetDataLine.class,
          formatTmp);
      lineTmp = (TargetDataLine) AudioSystem.getLine(info);
      isMicrophone = true;
    } else {
      AudioInputStream in;

      if (filePath.contains("http")) {
        URL url = new URL(filePath);
        in = AudioSystem.getAudioInputStream(url);
      } else {
        File file = new File(filePath);
        in = AudioSystem.getAudioInputStream(file);
      }

      AudioFormat baseFormat = in.getFormat();

      System.out.println(baseFormat.toString());

      AudioFormat decodedFormat = new AudioFormat(
          AudioFormat.Encoding.PCM_SIGNED,
          baseFormat.getSampleRate(), 16, baseFormat.getChannels(),
          baseFormat.getChannels() * 2, baseFormat.getSampleRate(),
          false);

      din = AudioSystem.getAudioInputStream(decodedFormat, in);

      if (!conversionProvider.isConversionSupported(getFormat(),
          decodedFormat)) {
        System.out.println("Conversion is not supported");
      }

      System.out.println(decodedFormat.toString());

      outDin = conversionProvider.getAudioInputStream(getFormat(), din);
      formatTmp = decodedFormat;

      DataLine.Info info = new DataLine.Info(TargetDataLine.class,
          formatTmp);
      lineTmp = (TargetDataLine) AudioSystem.getLine(info);
    }

    final AudioFormat format = formatTmp;
    final TargetDataLine line = lineTmp;
    final boolean isMicro = isMicrophone;
    final AudioInputStream outDinSound = outDin;

    if (isMicro) {
View Full Code Here


        } catch (IOException ioe) {
            ioe.printStackTrace();
        }

        if (audioInputStream != null) {
            AudioFormat format = audioInputStream.getFormat();
            DataLine.Info   info = new DataLine.Info(Clip.class, format,
                                             AudioSystem.NOT_SPECIFIED);
            try {
                audioClip = (Clip) AudioSystem.getLine(info);
                audioClip.addLineListener(this);
View Full Code Here

            // Add JavaSound properties.
            if (m_audioFileFormat.getByteLength() > 0) properties.put("audio.length.bytes", new Integer(m_audioFileFormat.getByteLength()));
            if (m_audioFileFormat.getFrameLength() > 0) properties.put("audio.length.frames", new Integer(m_audioFileFormat.getFrameLength()));
            if (m_audioFileFormat.getType() != null) properties.put("audio.type", (m_audioFileFormat.getType().toString()));
            // Audio format.
            AudioFormat audioFormat = m_audioFileFormat.getFormat();
            if (audioFormat.getFrameRate() > 0) properties.put("audio.framerate.fps", new Float(audioFormat.getFrameRate()));
            if (audioFormat.getFrameSize() > 0) properties.put("audio.framesize.bytes", new Integer(audioFormat.getFrameSize()));
            if (audioFormat.getSampleRate() > 0) properties.put("audio.samplerate.hz", new Float(audioFormat.getSampleRate()));
            if (audioFormat.getSampleSizeInBits() > 0) properties.put("audio.samplesize.bits", new Integer(audioFormat.getSampleSizeInBits()));
            if (audioFormat.getChannels() > 0) properties.put("audio.channels", new Integer(audioFormat.getChannels()));
            if (audioFormat instanceof TAudioFormat)
            {
                // Tritonus SPI compliant audio format.
                Map addproperties = ((TAudioFormat) audioFormat).properties();
                properties.putAll(addproperties);
View Full Code Here

        {
            openLine();
        }
        else
        {
            AudioFormat lineAudioFormat = m_line.getFormat();
            AudioFormat audioInputStreamFormat = m_audioInputStream == null ? null : m_audioInputStream.getFormat();
            if (!lineAudioFormat.equals(audioInputStreamFormat))
            {
                m_line.close();
                openLine();
            }
View Full Code Here

    protected void createLine() throws LineUnavailableException
    {
        log.info("Create Line");
        if (m_line == null)
        {
            AudioFormat sourceFormat = m_audioInputStream.getFormat();
            log.info("Create Line : Source format : " + sourceFormat.toString());
            int nSampleSizeInBits = sourceFormat.getSampleSizeInBits();
            if (nSampleSizeInBits <= 0) nSampleSizeInBits = 16;
            if ((sourceFormat.getEncoding() == AudioFormat.Encoding.ULAW) || (sourceFormat.getEncoding() == AudioFormat.Encoding.ALAW)) nSampleSizeInBits = 16;
            if (nSampleSizeInBits != 8) nSampleSizeInBits = 16;
            AudioFormat targetFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, sourceFormat.getSampleRate(), nSampleSizeInBits, sourceFormat.getChannels(), sourceFormat.getChannels() * (nSampleSizeInBits / 8), sourceFormat.getSampleRate(), false);
            log.info("Create Line : Target format: " + targetFormat);
            // Keep a reference on encoded stream to progress notification.
            m_encodedaudioInputStream = m_audioInputStream;
            try
            {
                // Get total length in bytes of the encoded stream.
                encodedLength = m_encodedaudioInputStream.available();
            }
            catch (IOException e)
            {
                log.error("Cannot get m_encodedaudioInputStream.available()", e);
            }
            // Create decoded stream.
            m_audioInputStream = AudioSystem.getAudioInputStream(targetFormat, m_audioInputStream);
            AudioFormat audioFormat = m_audioInputStream.getFormat();
            DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat, AudioSystem.NOT_SPECIFIED);
            Mixer mixer = getMixer(m_mixerName);
            if (mixer != null)
            {
                log.info("Mixer : "+mixer.getMixerInfo().toString());
View Full Code Here

            if ((id3v1[0] == 'T') && (id3v1[1] == 'A') && (id3v1[2] == 'G'))
            {
                parseID3v1Frames(id3v1, aff_properties);
            }
        }
        AudioFormat format = new MpegAudioFormat(encoding, (float) nFrequency, AudioSystem.NOT_SPECIFIED // SampleSizeInBits - The size of a sample
                , nChannels // Channels - The number of channels
                , -1 // The number of bytes in each frame
                , FrameRate // FrameRate - The number of frames played or recorded per second
                , true, af_properties);
        return new MpegAudioFileFormat(MpegFileFormatType.MP3, format, nTotalFrames, mLength, aff_properties);
View Full Code Here

     */
    protected void openLine() throws LineUnavailableException
    {
        if (m_line != null)
        {
            AudioFormat audioFormat = m_audioInputStream.getFormat();
            int buffersize = lineBufferSize;
            if (buffersize <= 0) buffersize = m_line.getBufferSize();
            m_lineCurrentBufferSize = buffersize;
            m_line.open(audioFormat, buffersize);
            log.info("Open Line : BufferSize=" + buffersize);
View Full Code Here

    }

    public static Map getPropriedades(File file) {
        try {
            AudioFormat af = AudioSystem.getAudioFileFormat(file).getFormat();
            Map addproperties = ((TAudioFormat) af).properties();
            return addproperties;
        } catch (UnsupportedAudioFileException ex) {
            Logger.getLogger(MusicaS.class.getName()).log(Level.SEVERE, null, ex);
            return null;
View Full Code Here

        File file = new File(filename);
        // Get AudioInputStream from given file.
        AudioInputStream in = AudioSystem.getAudioInputStream(file);
        AudioInputStream din = null;
        if (in != null) {
            AudioFormat baseFormat = in.getFormat();
            System.out.println(in.getFormat());
            AudioFormat decodedFormat = new AudioFormat(
                    AudioFormat.Encoding.PCM_SIGNED,
                    baseFormat.getSampleRate(),
                    16,
                    baseFormat.getChannels(),
                    baseFormat.getChannels() * 2,
 
View Full Code Here

    if (out != null) out.println("Audio Type : "+aff.getType());
    AudioInputStream in= AudioSystem.getAudioInputStream(file);
    AudioInputStream din = null;
    if (in != null)
    {
      AudioFormat baseFormat = in.getFormat();
      if (out != null) out.println("Source Format : "+baseFormat.toString());
      AudioFormat  decodedFormat = new AudioFormat(
        AudioFormat.Encoding.PCM_SIGNED,
        baseFormat.getSampleRate(),
        16,
        baseFormat.getChannels(),
        baseFormat.getChannels() * 2,
        baseFormat.getSampleRate(),
        false);
      if (out != null) out.println("Target Format : "+decodedFormat.toString());
      din = AudioSystem.getAudioInputStream(decodedFormat, in);
      if (din instanceof PropertiesContainer)
      {
      assertTrue("PropertiesContainer : OK",true);
      }
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.