int getLayer3ScaleFactors1()

in pedalboard/juce_overrides/juce_PatchedMP3AudioFormat.cpp [2714:2787]


  int getLayer3ScaleFactors1(int *scf,
                             const Layer3SideInfo::Info &granule) noexcept {
    static const uint8 lengths[2][16] = {
        {0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4},
        {0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3}};

    int numBits;
    const int num0 = lengths[0][granule.scaleFactorCompression];
    const int num1 = lengths[1][granule.scaleFactorCompression];

    if (granule.blockType == 2) {
      int i = 18;
      numBits = (num0 + num1) * 18;

      if (granule.mixedBlockFlag) {
        for (int j = 8; --j >= 0;)
          *scf++ = (int)getBitsUnchecked(num0);
        numBits -= num0;
        i = 9;
      }

      for (; --i >= 0;)
        *scf++ = (int)getBitsUnchecked(num0);
      for (i = 18; --i >= 0;)
        *scf++ = (int)getBitsUnchecked(num1);

      *scf++ = 0;
      *scf++ = 0;
      *scf++ = 0;
    } else {
      const int scfsi = granule.scfsi;

      if (scfsi < 0) {
        for (int i = 11; --i >= 0;)
          *scf++ = (int)getBitsUnchecked(num0);
        for (int j = 10; --j >= 0;)
          *scf++ = (int)getBitsUnchecked(num1);
        numBits = (num0 + num1) * 10 + num0;
      } else {
        numBits = 0;
        if ((scfsi & 8) == 0) {
          for (int i = 6; --i >= 0;)
            *scf++ = (int)getBitsUnchecked(num0);
          numBits += num0 * 6;
        } else
          scf += 6;

        if ((scfsi & 4) == 0) {
          for (int i = 5; --i >= 0;)
            *scf++ = (int)getBitsUnchecked(num0);
          numBits += num0 * 5;
        } else
          scf += 5;

        if ((scfsi & 2) == 0) {
          for (int i = 5; --i >= 0;)
            *scf++ = (int)getBitsUnchecked(num1);
          numBits += num1 * 5;
        } else
          scf += 5;

        if ((scfsi & 1) == 0) {
          for (int i = 5; --i >= 0;)
            *scf++ = (int)getBitsUnchecked(num1);
          numBits += num1 * 5;
        } else
          scf += 5;
      }

      *scf = 0;
    }

    return numBits;
  }