Package javax.sound.sampled

Examples of javax.sound.sampled.AudioFormat


                metadata.set(Metadata.CONTENT_TYPE, "audio/basic");
            } else if (type == Type.WAVE) {
                metadata.set(Metadata.CONTENT_TYPE, "audio/x-wav");
            }

            AudioFormat audioFormat = fileFormat.getFormat();
            int channels = audioFormat.getChannels();
            if (channels != AudioSystem.NOT_SPECIFIED) {
                metadata.set("channels", String.valueOf(channels));
                // TODO: Use XMPDM.TRACKS? (see also frame rate in AudioFormat)
            }
            float rate = audioFormat.getSampleRate();
            if (rate != AudioSystem.NOT_SPECIFIED) {
                metadata.set("samplerate", String.valueOf(rate));
                metadata.set(
                        XMPDM.AUDIO_SAMPLE_RATE,
                        Integer.toString((int) rate));
            }
            int bits = audioFormat.getSampleSizeInBits();
            if (bits != AudioSystem.NOT_SPECIFIED) {
                metadata.set("bits", String.valueOf(bits));
                if (bits == 8) {
                    metadata.set(XMPDM.AUDIO_SAMPLE_TYPE, "8Int");
                } else if (bits == 16) {
                    metadata.set(XMPDM.AUDIO_SAMPLE_TYPE, "16Int");
                } else if (bits == 32) {
                    metadata.set(XMPDM.AUDIO_SAMPLE_TYPE, "32Int");
                }
            }
            metadata.set("encoding", audioFormat.getEncoding().toString());

            // Javadoc suggests that some of the following properties might
            // be available, but I had no success in finding any:

            // "duration" Long playback duration of the file in microseconds
            // "author" String name of the author of this file
            // "title" String title of this file
            // "copyright" String copyright message
            // "date" Date date of the recording or release
            // "comment" String an arbitrary text

            for (Entry<String, Object> entry : fileFormat.properties().entrySet()) {
                metadata.set(entry.getKey(), entry.getValue().toString());
            }
            for (Entry<String, Object> entry : audioFormat.properties().entrySet()) {
                metadata.set(entry.getKey(), entry.getValue().toString());
            }
        } catch (UnsupportedAudioFileException e) {
            // There is no way to know whether this exception was
            // caused by the document being corrupted or by the format
View Full Code Here


      }else if(url!=null){
        streamInput=AudioSystem.getAudioInputStream(url);
      }else{
        throw new IOException("url/source is missing!");
      }
          AudioFormat  decodedFormat = new AudioFormat(
                  AudioFormat.Encoding.PCM_SIGNED,
                  streamInput.getFormat().getSampleRate(),
                  16,
                  streamInput.getFormat().getChannels(),
                  streamInput.getFormat().getChannels() * 2,
 
View Full Code Here

            updateState();
        }
   
     private void outputOpen() throws LineUnavailableException,IOException,UnsupportedAudioFileException{
           // Linking to output
           AudioFormat   format=getTracks().get(0).getSource().getStream().getFormat();
           DataLine.Info   info;
          
           format = new AudioFormat(format.getEncoding(),format.getSampleRate(), format.getSampleSizeInBits(), format.getChannels(),format.getFrameSize(),format.getFrameRate(),format.isBigEndian());
           info = new DataLine.Info(SourceDataLine.class, format);

           // Opening output           
           output=(SourceDataLine)AudioSystem.getMixer(getMixer()).getLine(info);
           output.open(format);
View Full Code Here

     * @param sourceFormat format of the incoming data
     * @return <code>true</code> if the conversion is supported, otherwise <code>false</code>
     */
    public boolean isConversionSupported(AudioFormat targetFormat, AudioFormat sourceFormat){

        AudioFormat targetFormats[] = getTargetFormats( targetFormat.getEncoding(), sourceFormat );

        for(int i=0; i<targetFormats.length; i++) {
            if( targetFormat.matches( targetFormats[i] ) ) {
                return true;
            }
View Full Code Here

                }
            }
            insertFile.setString(3, name);

            AudioFileFormat baseFileFormat = null;
            AudioFormat baseFormat = null;
            baseFileFormat = AudioSystem.getAudioFileFormat(dir);
            if (baseFileFormat == null) {
                System.out.println("insert: SKIPPED: " + name + "(baseFileFormat == null)");
                return;
            }
            baseFormat = baseFileFormat.getFormat();
            if (baseFormat == null) {
                if (messages.length() > 0) {
                    messages += ", ";
                }
                messages += msgs.getMessage("NO_AUDIO_PROPERTIES", null);
            } else {
                Map mp3 = baseFileFormat.properties();
                Map audio = baseFormat.properties();
                if (mp3 == null) {
                    System.out.println("insert: SKIPPED: " + name + "(no baseFormat.properties()");
                    return;
                }
View Full Code Here

    }
  }

  private static void openJavaSound(IStreamCoder aAudioCoder)
  {
    AudioFormat audioFormat = new AudioFormat(aAudioCoder.getSampleRate(),
        (int)IAudioSamples.findSampleBitDepth(aAudioCoder.getSampleFormat()),
        aAudioCoder.getChannels(),
        true, /* xuggler defaults to signed 16 bit samples */
        false);
    DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
View Full Code Here

      try
      {
        // estabish the audio format, NOTE: xuggler defaults to signed 16 bit
        // samples

        AudioFormat audioFormat = new AudioFormat(audioCoder.getSampleRate(),
          (int) IAudioSamples
          .findSampleBitDepth(audioCoder.getSampleFormat()), audioCoder
          .getChannels(), true, false);
       
        // create the audio line out
View Full Code Here

      } catch (Exception e) {
        URL url = new URL(evaluateContent(instance, this.getSoundUrl()).toString());
        audioInputStream = AudioSystem.getAudioInputStream(url);
      }

      AudioFormat format = audioInputStream.getFormat();
      DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);

      auline = (SourceDataLine) AudioSystem.getLine(info);
      auline.open(format);
View Full Code Here

     * @param sourceFormat format of the incoming data
     * @return <code>true</code> if the conversion is supported, otherwise <code>false</code>
     */
    public boolean isConversionSupported(AudioFormat targetFormat, AudioFormat sourceFormat){

  AudioFormat targetFormats[] = getTargetFormats( targetFormat.getEncoding(), sourceFormat );

  for(int i=0; i<targetFormats.length; i++) {
      if( targetFormat.matches( targetFormats[i] ) ) {
    return true;
      }
View Full Code Here

    } 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);
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.