Add adaptive haptics scaling to external vibrations
Converting the usage of haptic intensity, which only covers the scale
level, to HapticScale which includes both scale level and adaptive
haptics scale.
Bug: 305957324
Test: N/A
Change-Id: Ib3a5b83e20707207affbbe6dbc0586669ae4841b
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 767c502..aaf4923 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -2901,7 +2901,7 @@
// Unlock due to VibratorService will lock for this call and will
// call Tracks.mute/unmute which also require thread's lock.
mutex().unlock();
- const os::HapticScale intensity = afutils::onExternalVibrationStart(
+ const os::HapticScale hapticScale = afutils::onExternalVibrationStart(
track->getExternalVibration());
std::optional<media::AudioVibratorInfo> vibratorInfo;
{
@@ -2911,7 +2911,7 @@
vibratorInfo = std::move(mAfThreadCallback->getDefaultVibratorInfo_l());
}
mutex().lock();
- track->setHapticIntensity(intensity);
+ track->setHapticScale(hapticScale);
if (vibratorInfo) {
track->setHapticMaxAmplitude(vibratorInfo->maxAmplitude);
}
@@ -2927,7 +2927,8 @@
// Set haptic intensity for effect
if (chain != nullptr) {
- chain->setHapticIntensity_l(track->id(), intensity);
+ // TODO(b/324559333): Add adaptive haptics scaling support for the HapticGenerator.
+ chain->setHapticScale_l(track->id(), hapticScale);
}
}
@@ -4810,7 +4811,7 @@
// When the track is stop, set the haptic intensity as MUTE
// for the HapticGenerator effect.
if (chain != nullptr) {
- chain->setHapticIntensity_l(track->id(), os::HapticScale::MUTE);
+ chain->setHapticScale_l(track->id(), os::HapticScale::mute());
}
}
@@ -5170,7 +5171,7 @@
// audio to FastMixer
fastTrack->mFormat = mFormat; // mPipeSink format for audio to FastMixer
fastTrack->mHapticPlaybackEnabled = mHapticChannelMask != AUDIO_CHANNEL_NONE;
- fastTrack->mHapticIntensity = os::HapticScale::NONE;
+ fastTrack->mHapticScale = {/*level=*/os::HapticLevel::NONE };
fastTrack->mHapticMaxAmplitude = NAN;
fastTrack->mGeneration++;
state->mFastTracksGen++;
@@ -5728,7 +5729,7 @@
fastTrack->mChannelMask = track->channelMask();
fastTrack->mFormat = track->format();
fastTrack->mHapticPlaybackEnabled = track->getHapticPlaybackEnabled();
- fastTrack->mHapticIntensity = track->getHapticIntensity();
+ fastTrack->mHapticScale = track->getHapticScale();
fastTrack->mHapticMaxAmplitude = track->getHapticMaxAmplitude();
fastTrack->mGeneration++;
state->mTrackMask |= 1 << j;
@@ -6089,10 +6090,11 @@
trackId,
AudioMixer::TRACK,
AudioMixer::HAPTIC_ENABLED, (void *)(uintptr_t)track->getHapticPlaybackEnabled());
+ const os::HapticScale hapticScale = track->getHapticScale();
mAudioMixer->setParameter(
- trackId,
- AudioMixer::TRACK,
- AudioMixer::HAPTIC_INTENSITY, (void *)(uintptr_t)track->getHapticIntensity());
+ trackId,
+ AudioMixer::TRACK,
+ AudioMixer::HAPTIC_SCALE, (void *)&hapticScale);
const float hapticMaxAmplitude = track->getHapticMaxAmplitude();
mAudioMixer->setParameter(
trackId,