Exemplo n.º 1
0
 @Override
 public boolean equals(Object obj) {
   if (obj instanceof AudioFormat) {
     AudioFormat format = (AudioFormat) obj;
     if (format.getCodec() != getCodec()) {
       return false;
     }
     if (format.getContainer() != getContainer()) {
       return false;
     }
     if (format.isBigEndian() != isBigEndian()) {
       return false;
     }
     if (format.getBitDepth() != getBitDepth()) {
       return false;
     }
     if (format.getBitRate() != getBitRate()) {
       return false;
     }
     if (format.getFrequency() != getFrequency()) {
       return false;
     }
     return true;
   }
   return super.equals(obj);
 }
Exemplo n.º 2
0
  private void getAudioData() {

    if (format.getSampleSizeInBits() == 16) {
      nlengthInSamples = audioBytes.length / 2;
      audioData = new int[nlengthInSamples];
      if (format.isBigEndian()) {
        for (int i = 0; i < nlengthInSamples; 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[i] = MSB << 8 | (255 & LSB);
        }
      } else {
        for (int i = 0; i < nlengthInSamples; 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[i] = MSB << 8 | (255 & LSB);
        }
      }
    } else {
      if (format.getSampleSizeInBits() == 8) {
        nlengthInSamples = audioBytes.length;
        audioData = new int[nlengthInSamples];
        if (format.getEncoding().toString().startsWith("PCM_SIGN")) {
          for (int i = 0; i < audioBytes.length; i++) {
            audioData[i] = audioBytes[i];
          }
        } else {
          for (int i = 0; i < audioBytes.length; i++) {
            audioData[i] = audioBytes[i] - 128;
          }
        }
      }
    }
  }
Exemplo n.º 3
0
 /**
  * Determines if the passed AudioFormat is compatable with this AudioFormat.
  *
  * <p>This AudioFormat is compatible with the passed AudioFormat if both have the same value for
  * all non-null members of this instance.
  */
 boolean isCompatible(AudioFormat audioFormat) {
   if (audioFormat == null) {
     return false;
   }
   if ((null != getContainer()) && (getContainer() != audioFormat.getContainer())) {
     return false;
   }
   if ((null != getCodec()) && (getCodec() != audioFormat.getCodec())) {
     return false;
   }
   if ((null != isBigEndian()) && (isBigEndian() != audioFormat.isBigEndian())) {
     return false;
   }
   if ((null != getBitDepth()) && (getBitDepth() != audioFormat.getBitDepth())) {
     return false;
   }
   if ((null != getBitRate()) && (getBitRate() != audioFormat.getBitRate())) {
     return false;
   }
   if ((null != getFrequency()) && (getFrequency() != audioFormat.getFrequency())) {
     return false;
   }
   return true;
 }