code: private static int calculateFrameLength(int layer, int bitRate, int sampleRate, int padding) {
          if (layer == AudioFrame.LAYER_1) {
              return (12 * bitRate / sampleRate + padding) * 4;
          } else {
              return 144 * bitRate / sampleRate + padding;
          }
      }
docs: Calculates the length of an MPEG frame based on the given parameters.
  
  @param layer
  the layer
  @param bitRate
  the bit rate
  @param sampleRate
  the sample rate
  @param padding
  the padding flag
  @return the length of the frame in bytes