AudioFlinger: compute MEL values on framework level
The MelReporter is responsible for starting the MEL calculation for
different audio streams. For now we only print the values in dumpsys.
Test: dumpsys media.audio_flinger
Bug: 252776298
Change-Id: Ic5757bac23844358cb4c886b3eaf2fd2e9ffbf40
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 60ba0f3..3766709 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -17,7 +17,7 @@
#define LOG_TAG "AudioFlinger"
-//#define LOG_NDEBUG 0
+// #define LOG_NDEBUG 0
#define ATRACE_TAG ATRACE_TAG_AUDIO
#include "Configuration.h"
@@ -44,6 +44,7 @@
#include <private/media/AudioTrackShared.h>
#include <private/android_filesystem_config.h>
#include <audio_utils/Balance.h>
+#include <audio_utils/MelProcessor.h>
#include <audio_utils/Metadata.h>
#include <audio_utils/channels.h>
#include <audio_utils/mono_blend.h>
@@ -3333,6 +3334,7 @@
}
ssize_t framesWritten = mNormalSink->write((char *)mSinkBuffer + offset, count);
ATRACE_END();
+
if (framesWritten > 0) {
bytesWritten = framesWritten * mFrameSize;
#ifdef TEE_SINK
@@ -3341,6 +3343,11 @@
} else {
bytesWritten = framesWritten;
}
+
+ auto processor = mMelProcessor.load();
+ if (processor) {
+ processor->process((char *)mSinkBuffer + offset, bytesWritten);
+ }
// otherwise use the HAL / AudioStreamOut directly
} else {
// Direct output and offload threads
@@ -3377,6 +3384,21 @@
return bytesWritten;
}
+void AudioFlinger::PlaybackThread::startMelComputation(const sp<
+ audio_utils::MelProcessor::MelCallback>& callback)
+{
+ ALOGV("%s: creating new mel processor for thread %d", __func__, id());
+ mMelProcessor = sp<audio_utils::MelProcessor>::make(mSampleRate,
+ mChannelCount,
+ mFormat,
+ callback);
+}
+
+void AudioFlinger::PlaybackThread::stopMelComputation() {
+ ALOGV("%s: stopping mel processor for thread %d", __func__, id());
+ mMelProcessor = nullptr;
+}
+
void AudioFlinger::PlaybackThread::threadLoop_drain()
{
bool supportsDrain = false;