Examples of AudioFormat


Examples of javax.media.format.AudioFormat

 
  public Encoder()
  {
    super();
    this.inputFormats = new Format[] {
        new AudioFormat(AudioFormat.LINEAR, -1.0, 16, 1, -1, AudioFormat.SIGNED, 16, -1.0, Format.byteArray)
        };
   
  }
View Full Code Here

Examples of javax.media.format.AudioFormat

   
      if (!(input instanceof AudioFormat))
      {  logger.warning(this.getClass().getSimpleName() + ".getSupportedOutputFormats: input format does not match, returning format array of {null} for " + input); // this can cause an NPE in JMF if it ever happens.
        return new Format[] {null};
      }
      final AudioFormat inputCast = (AudioFormat) input;
      if (!inputCast.getEncoding().equals(AudioFormat.LINEAR) ||
        (inputCast.getSampleSizeInBits() != 16 && inputCast.getSampleSizeInBits() != Format.NOT_SPECIFIED) ||
        (inputCast.getChannels() != 1 && inputCast.getChannels() != Format.NOT_SPECIFIED) ||
        (inputCast.getSigned() != AudioFormat.SIGNED && inputCast.getSigned() != Format.NOT_SPECIFIED) ||
        (inputCast.getFrameSizeInBits() != 16 && inputCast.getFrameSizeInBits() != Format.NOT_SPECIFIED) ||
        (inputCast.getDataType() != null && inputCast.getDataType() != Format.byteArray)
        )
      { 
        logger.warning(this.getClass().getSimpleName() + ".getSupportedOutputFormats: input format does not match, returning format array of {null} for " + input); // this can cause an NPE in JMF if it ever happens.
        return new Format[] {null};
      }
      final AudioFormat result = new AudioFormat(AudioFormat.ALAW, inputCast.getSampleRate(), 8,
          1, inputCast.getEndian(), AudioFormat.SIGNED, 8,
          inputCast.getFrameRate(), Format.byteArray);

      return new Format[] {result};
    }
View Full Code Here

Examples of javax.media.format.AudioFormat

    }
  }

  public void testEqualsMatches_AudioFormat()
  {
    final AudioFormat f1 =  new AudioFormat(AudioFormat.DOLBYAC3, 2.0, 1, 2, 3, 4, 5, 6.0, Format.byteArray);

    // AudioFormat - equal and match:
    {
      final AudioFormat[] f2s = new AudioFormat[]{
          new AudioFormat(AudioFormat.DOLBYAC3, 2.0, 1, 2, 3, 4, 5, 6.0, Format.byteArray),
            (AudioFormat) f1.clone(),
            (AudioFormat) f1.intersects(f1)
      };
      for (int i = 0; i < f2s.length; ++i)
      {
        AudioFormat f2 = f2s[i];
        assertTrue(f1.equals(f2));
        assertTrue(f1.matches(f2));
        assertTrue(f2.equals(f1));
        assertTrue(f2.matches(f1));
      }
    }
   
    // AudioFormat - not equal and not match:
    {
     
      final AudioFormat[] f2s = new AudioFormat[]{
          new AudioFormat(AudioFormat.ALAW, 2.0, 1, 2, 3, 4, 5, 6.0, Format.byteArray),
          new AudioFormat(AudioFormat.DOLBYAC3, 3.0, 1, 2, 3, 4, 5, 6.0, Format.byteArray),
          new AudioFormat(AudioFormat.DOLBYAC3, 2.0, 11, 2, 3, 4, 5, 6.0, Format.byteArray),
          new AudioFormat(AudioFormat.DOLBYAC3, 2.0, 1, 12, 3, 4, 5, 6.0, Format.byteArray),
          new AudioFormat(AudioFormat.DOLBYAC3, 2.0, 1, 2, 13, 4, 5, 6.0, Format.byteArray),
          new AudioFormat(AudioFormat.DOLBYAC3, 2.0, 1, 2, 3, 14, 5, 6.0, Format.byteArray),
          new AudioFormat(AudioFormat.DOLBYAC3, 2.0, 1, 2, 3, 4, 15, 6.0, Format.byteArray),
          new AudioFormat(AudioFormat.DOLBYAC3, 2.0, 1, 2, 3, 4, 5, 16.0, Format.byteArray),
          new AudioFormat(AudioFormat.DOLBYAC3, 2.0, 1, 2, 3, 4, 5, 6.0, Format.intArray),
                 
      };
      for (int i = 0; i < f2s.length; ++i)
      {
        AudioFormat f2 = f2s[i];
        //System.out.println(f2);
        assertFalse(f1.equals(f2));
        assertFalse(f1.matches(f2));
        assertFalse(f2.equals(f1));
        assertFalse(f2.matches(f1));
      }
    }

    // AudioFormat - not equal but match:
    {
     
      final AudioFormat[] f2s = new AudioFormat[]{
          new AudioFormat(null, 2.0, 1, 2, 3, 4, 5, 6.0, Format.byteArray),
          new AudioFormat(AudioFormat.DOLBYAC3, Format.NOT_SPECIFIED, 1, 2, 3, 4, 5, 6.0, Format.byteArray),
          new AudioFormat(AudioFormat.DOLBYAC3, 2.0, Format.NOT_SPECIFIED, 2, 3, 4, 5, 6.0, Format.byteArray),
          new AudioFormat(AudioFormat.DOLBYAC3, 2.0, 1, Format.NOT_SPECIFIED, 3, 4, 5, 6.0, Format.byteArray),
          new AudioFormat(AudioFormat.DOLBYAC3, 2.0, 1, 2, Format.NOT_SPECIFIED, 4, 5, 6.0, Format.byteArray),
          new AudioFormat(AudioFormat.DOLBYAC3, 2.0, 1, 2, 3, Format.NOT_SPECIFIED, 5, 6.0, Format.byteArray),
          new AudioFormat(AudioFormat.DOLBYAC3, 2.0, 1, 2, 3, 4, Format.NOT_SPECIFIED, 6.0, Format.byteArray),
          new AudioFormat(AudioFormat.DOLBYAC3, 2.0, 1, 2, 3, 4, 5, Format.NOT_SPECIFIED, Format.byteArray),
          new AudioFormat(AudioFormat.DOLBYAC3, 2.0, 1, 2, 3, 4, 5, 6.0, null),
                   
      };
      for (int i = 0; i < f2s.length; ++i)
      {
        AudioFormat f2 = f2s[i];
        //System.out.println(f2);
        assertFalse(f1.equals(f2));
        assertTrue(f1.matches(f2));
        assertFalse(f2.equals(f1));
        assertTrue(f2.matches(f1));
      }
    }
  }
View Full Code Here

Examples of javax.media.format.AudioFormat

        return "GSM Packetizer";
    }

    public Packetizer() {
        super();
        this.inputFormats = new Format[]{new AudioFormat(AudioFormat.GSM, 8000, 8, 1, -1, AudioFormat.SIGNED, 264, -1.0, Format.byteArray)};

    }
View Full Code Here

Examples of javax.media.format.AudioFormat

        else {
            if (!(input instanceof AudioFormat)) {
                logger.warning(this.getClass().getSimpleName() + ".getSupportedOutputFormats: input format does not match, returning format array of {null} for " + input); // this can cause an NPE in JMF if it ever happens.
                return new Format[]{null};
            }
            final AudioFormat inputCast = (AudioFormat) input;
            if (!inputCast.getEncoding().equals(AudioFormat.GSM) ||
                    (inputCast.getSampleSizeInBits() != 8 && inputCast.getSampleSizeInBits() != Format.NOT_SPECIFIED) ||
                    (inputCast.getChannels() != 1 && inputCast.getChannels() != Format.NOT_SPECIFIED) ||
                    (inputCast.getFrameSizeInBits() != 264 && inputCast.getFrameSizeInBits() != Format.NOT_SPECIFIED)
                    ) {
                logger.warning(this.getClass().getSimpleName() + ".getSupportedOutputFormats: input format does not match, returning format array of {null} for " + input); // this can cause an NPE in JMF if it ever happens.
                return new Format[]{null};
            }
            final AudioFormat result = new AudioFormat(AudioFormat.GSM_RTP, inputCast.getSampleRate(), 8,
                    1, inputCast.getEndian(), inputCast.getSigned(), 264,
                    inputCast.getFrameRate(), inputCast.getDataType());

            return new Format[]{result};
        }
View Full Code Here

Examples of javax.media.format.AudioFormat

   
    list.add(f.getEncoding().toUpperCase());
   
    if (f instanceof AudioFormat)
    {
      final AudioFormat af = (AudioFormat) f;
      list.add(intToStr((int) af.getSampleRate()));
      list.add(intToStr(af.getSampleSizeInBits()));
     
      list.add(intToStr(af.getChannels()));
      list.add(endianToStr(af.getEndian()));
      list.add(signedToStr(af.getSigned()));
      list.add(intToStr(af.getFrameSizeInBits()));
      list.add(intToStr((int) af.getFrameRate()));
      if (af.getDataType() != null && af.getDataType() != Format.byteArray)
        list.add(dataTypeToStr(af.getDataType()));
     

     
    }
    else if (f instanceof VideoFormat)
View Full Code Here

Examples of javax.sound.sampled.AudioFormat

        //{
          if (first)
          {
            first = false;
            System.out.println("frequency: "+decoder.getOutputFrequency() + ", channels: " + decoder.getOutputChannels());
            startOutput(new AudioFormat(decoder.getOutputFrequency(), 16, decoder.getOutputChannels(), true, false));
          }
          line.write(output.getBuffer(), 0, length);
          bitstream.closeFrame();
          header = bitstream.readFrame();
          //System.out.println("Mem:"+(rt.totalMemory() - rt.freeMemory())+"/"+rt.totalMemory());
View Full Code Here

Examples of javax.sound.sampled.AudioFormat

        return sequencer;
      } else {
        final AudioInputStream ais = AudioSystem.getAudioInputStream(new File(
            fileName));

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

        if(AudioSystem.isLineSupported(info)) {
          final SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);

          line.open(format);
          line.start();

          new Thread("Reminder audio playing") {
            private boolean stopped;
            @Override
            public void run() {
              byte[] myData = new byte[1024 * format.getFrameSize()];
              int numBytesToRead = myData.length;
              int numBytesRead = 0;
              int total = 0;
              int totalToRead = (int) (format.getFrameSize() * ais.getFrameLength());
              stopped = false;

              line.addLineListener(new LineListener() {
                public void update(LineEvent event) {
                  if(line != null && !line.isRunning()) {
View Full Code Here

Examples of javax.sound.sampled.AudioFormat

   * @param ais AudioInputStream to read from
   * @return WaveData containing data, or null if a failure occured
   */
  public static WaveData create(AudioInputStream ais) {
    //get format of data
    AudioFormat audioformat = ais.getFormat();

    // get channels
    int channels = 0;
    if (audioformat.getChannels() == 1) {
      if (audioformat.getSampleSizeInBits() == 8) {
        channels = AL10.AL_FORMAT_MONO8;
      } else if (audioformat.getSampleSizeInBits() == 16) {
        channels = AL10.AL_FORMAT_MONO16;
      } else {
        assert false : "Illegal sample size";
      }
    } else if (audioformat.getChannels() == 2) {
      if (audioformat.getSampleSizeInBits() == 8) {
        channels = AL10.AL_FORMAT_STEREO8;
      } else if (audioformat.getSampleSizeInBits() == 16) {
        channels = AL10.AL_FORMAT_STEREO16;
      } else {
        assert false : "Illegal sample size";
      }
    } else {
      assert false : "Only mono or stereo is supported";
    }

    //read data into buffer
    ByteBuffer buffer = null;
    try {
      int available = ais.available();
      if(available <= 0) {
        available = ais.getFormat().getChannels() * (int) ais.getFrameLength() * ais.getFormat().getSampleSizeInBits() / 8;
      }
      byte[] buf = new byte[ais.available()];
      int read = 0, total = 0;
      while ((read = ais.read(buf, total, buf.length - total)) != -1
        && total < buf.length) {
        total += read;
      }
      buffer = convertAudioBytes(buf, audioformat.getSampleSizeInBits() == 16);
    } catch (IOException ioe) {
      return null;
    }


    //create our result
    WaveData wavedata =
      new WaveData(buffer, channels, (int) audioformat.getSampleRate());

    //close stream
    try {
      ais.close();
    } catch (IOException ioe) {
View Full Code Here

Examples of javax.sound.sampled.AudioFormat

         * information about the format of the audio data. These information
         * include the sampling frequency, the number of channels and the size
         * of the samples. These information are needed to ask Java Sound for a
         * suitable output line for this audio file.
         */
        AudioFormat audioFormat = audioInputStream.getFormat();

        /*
         * Asking for a line is a rather tricky thing. We have to construct an
         * Info object that specifies the desired properties for the line.
         * First, we have to say which kind of line we want. The possibilities
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.