Repository: skyline-emu/skyline
File: app/src/main/cpp/skyline/input/npad_device.cpp (C++)

Code before:
        jlong currentTime{}; //!< The accumulated time passed by adding up all the periods prior to the current vibration cycle
        size_t index{};
        for (; index < timings.size(); index++) {
            jlong cyclePeriod{}; //!< The length of this cycle, calculated as the largest period with the same amplitude
            size_t bandStartCount{}; //!< The amount of bands that start their vibration cycles in this time slot

            for (size_t vibrationIndex{}; vibrationIndex < vibrations.size(); vibrationIndex++) {
                // Iterate over every band to calculate the amplitude for this time slot
                VibrationInfo &vibration{vibrations[vibrationIndex]};
                if (currentTime <= vibration.start) {
                    // If the time to start has arrived then start the vibration
                    vibration.end = vibration.start + vibration.period;
                    currentAmplitude += vibration.amplitude;
                    auto vibrationPeriodLeft{vibration.end - currentTime};
                    cyclePeriod = cyclePeriod ? std::min(vibrationPeriodLeft, cyclePeriod) : vibrationPeriodLeft;

                    bandStartCount++;
                } else if (currentTime <= vibration.end) {
                    // If the time to end the vibration has arrived then end it
                    vibration.start = vibration.end + vibration.period;
                    currentAmplitude -= vibration.amplitude;
                    auto vibrationPeriodLeft{vibration.start - currentTime};
                    cyclePeriod = cyclePeriod ? std::min(vibrationPeriodLeft, cyclePeriod) : vibrationPeriodLeft;
                }
            }

            if (index && bandStartCount == vibrations.size())
                break; // If all bands start again at this point then we can end the pattern here and just loop over the pattern

            currentTime += cyclePeriod;
            timings[index] = cyclePeriod;

            amplitudes[index] = std::min(currentAmplitude, AmplitudeMax);
        }

        jvm->VibrateDevice(deviceIndex, span(timings.begin(), timings.begin() + index), span(amplitudes.begin(), amplitudes.begin() + index));
    }

    void VibrateDevice(const std::shared_ptr<JvmManager> &jvm, i8 index, const NpadVibrationValue &value) {
        std::array<VibrationInfo, 2> vibrations{
            VibrationInfo{value.frequencyLow, value.amplitudeLow * (AmplitudeMax / 2)},
            VibrationInfo{value.frequencyHigh, value.amplitudeHigh * (AmplitudeMax / 2)},
        };
        VibrateDevice(jvm, index, vibrations);
    }

    void NpadDevice::Vibrate(const NpadVibrationValue &left, const NpadVibrationValue &right) {
        if (vibrationLeft == left && vibrationRight && (*vibrationRight) == right)
            return;

        vibrationLeft = left;

Review comment (suggestion):
```suggestion
        NpadSixAxisState *sixAxisState{sensor == MotionId::right ? &sixAxisStateRight : &sixAxisStateLeft};
```

Code after:
                case NpadAxisId::RX:
                    controllerState.rightY = value;
                    controllerState.buttons.rightStickUp = controllerState.rightY >= threshold;
                    controllerState.buttons.rightStickDown = controllerState.rightY <= -threshold;

                    defaultState.rightX = value;
                    defaultState.buttons.rightStickLeft = defaultState.rightX <= -threshold;
                    defaultState.buttons.rightStickRight = defaultState.rightX >= threshold;
                    break;
                case NpadAxisId::RY:
                    controllerState.rightX = -value;
                    controllerState.buttons.rightStickLeft = controllerState.rightX <= -threshold;
                    controllerState.buttons.rightStickRight = controllerState.rightX >= threshold;

                    defaultState.rightY = value;
                    defaultState.buttons.rightStickUp = defaultState.rightY >= threshold;
                    defaultState.buttons.rightStickDown = defaultState.rightY <= -threshold;
                    break;
            }
        }
    }

    void NpadDevice::SetMotionValue(MotionId sensor, MotionSensorState *value) {
        if (!connectionState.connected)
            return;

        NpadSixAxisState *sixAxisState{sensor == MotionId::Right? &sixAxisStateRight : &sixAxisStateLeft};

        sixAxisState->accelerometer.x = value->accelerometer[0];
        sixAxisState->accelerometer.y = value->accelerometer[1];
        sixAxisState->accelerometer.z = value->accelerometer[2];

        sixAxisState->gyroscope.x = value->gyroscope[0];
        sixAxisState->gyroscope.y = value->gyroscope[1];
        sixAxisState->gyroscope.z = value->gyroscope[2];

        float deltaTime{static_cast<float>(value->deltaTimestamp) / 1000000000.0f};
        sixAxisState->rotation.x += value->gyroscope[0] * deltaTime;
        sixAxisState->rotation.y += value->gyroscope[1] * deltaTime;
        sixAxisState->rotation.z += value->gyroscope[2] * deltaTime;

        sixAxisState->orientation[0].x = value->orientationMatrix[0];
        sixAxisState->orientation[0].y = value->orientationMatrix[1];
        sixAxisState->orientation[0].z = value->orientationMatrix[2];
        sixAxisState->orientation[1].x = value->orientationMatrix[3];
        sixAxisState->orientation[1].y = value->orientationMatrix[4];
        sixAxisState->orientation[1].z = value->orientationMatrix[5];
        sixAxisState->orientation[2].x = value->orientationMatrix[6];
        sixAxisState->orientation[2].y = value->orientationMatrix[7];
        sixAxisState->orientation[2].z = value->orientationMatrix[8];