diff options
author | Andy Hung <hunga@google.com> | 2024-03-08 23:30:36 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2024-03-08 23:30:36 +0000 |
commit | f88488c1535fa682a8526a7d2a56a6802fd68790 (patch) | |
tree | b17da102fa5d542962f86e313a92d006bda12fd3 | |
parent | 8e7c06cddadbda23547e60b40a000dcfe6a62df4 (diff) | |
parent | aa7f441d06e5895d05269b08a7e8b494fb0c61eb (diff) | |
download | media-f88488c1535fa682a8526a7d2a56a6802fd68790.tar.gz |
Merge changes I2c97098d,I64bdf857 into main
* changes:
PowerLog: Balance memory for multiple levels
PowerLog: Allow second level multiresolution
-rw-r--r-- | audio_utils/include/audio_utils/PowerLog.h | 5 | ||||
-rw-r--r-- | audio_utils/tests/powerlog_tests.cpp | 88 |
2 files changed, 91 insertions, 2 deletions
diff --git a/audio_utils/include/audio_utils/PowerLog.h b/audio_utils/include/audio_utils/PowerLog.h index 105f3b3d..30317068 100644 --- a/audio_utils/include/audio_utils/PowerLog.h +++ b/audio_utils/include/audio_utils/PowerLog.h @@ -105,7 +105,7 @@ public: audio_format_t format, size_t entries, size_t framesPerEntry, - size_t levels = 1) + size_t levels = 2) : mChannelCount(channelCount) , mFormat(format) , mSampleRate(sampleRate) @@ -116,7 +116,8 @@ public: size_t scale = 1; for (size_t i = 0; i < levels; ++i) { v[i] = std::make_shared<PowerLogBase>( - sampleRate, channelCount, format, entries, framesPerEntry * scale); + sampleRate, channelCount, format, + entries / levels, framesPerEntry * scale); scale *= 20; // each level's entry is 20x the temporal width of the prior. } return v; diff --git a/audio_utils/tests/powerlog_tests.cpp b/audio_utils/tests/powerlog_tests.cpp index 1c43b180..2303ee1e 100644 --- a/audio_utils/tests/powerlog_tests.cpp +++ b/audio_utils/tests/powerlog_tests.cpp @@ -18,6 +18,8 @@ #define LOG_TAG "audio_utils_powerlog_tests" #include <audio_utils/PowerLog.h> + +#include <audio_utils/clock.h> #include <gtest/gtest.h> #include <iostream> #include <log/log.h> @@ -105,6 +107,92 @@ Signal power history: */ } +TEST(audio_utils_powerlog, basic_level_2) { + const uint32_t kSampleRate = 48000; + auto plog = std::make_unique<PowerLog>( + kSampleRate /* sampleRate */, + 1 /* channelCount */, + AUDIO_FORMAT_PCM_16_BIT, + 200 /* entries */, + 1 /* framesPerEntry */, + 2 /* levels */); + + // header + EXPECT_EQ((size_t)2, countNewLines(plog->dumpToString())); + + const int16_t zero = 0; + const int16_t half = 0x4000; + const std::vector<int16_t> ary(60, 0x1000); + + plog->log(&half, 1 /* frame */, 0 /* nowNs */); + plog->log(&half, 1 /* frame */, 1 * NANOS_PER_SECOND / kSampleRate); + plog->log(&half, 1 /* frame */, 2 * NANOS_PER_SECOND / kSampleRate); + plog->log(ary.data(), ary.size(), 30 * NANOS_PER_SECOND / kSampleRate); + + EXPECT_EQ((size_t)10, countNewLines(plog->dumpToString( + "" /* prefix */, 0 /* lines */, 0 /* limitNs */, false /* logPlot */))); + + // add logplot + EXPECT_EQ((size_t)28, countNewLines(plog->dumpToString())); + + plog->log(&zero, 1 /* frame */, 100 * NANOS_PER_SECOND / kSampleRate); + // zero termination doesn't change this. + EXPECT_EQ((size_t)28, countNewLines(plog->dumpToString())); + + // but adding next line does. + plog->log(&half, 1 /* frame */, 101 * NANOS_PER_SECOND / kSampleRate); + EXPECT_EQ((size_t)29, countNewLines(plog->dumpToString())); + + // truncating on lines (this does not include the logplot). + EXPECT_EQ((size_t)22, countNewLines(plog->dumpToString( + "" /* prefix */, 4 /* lines */))); + + // truncating on time as well. + EXPECT_EQ((size_t)29, countNewLines(plog->dumpToString( + "" /* prefix */, 0 /* lines */, 2 /* limitNs */))); + // truncating on different time limit. + EXPECT_EQ((size_t)29, countNewLines(plog->dumpToString( + "" /* prefix */, 0 /* lines */, 3 /* limitNs */))); + + // truncating on a larger line count (this doesn't include the logplot). + EXPECT_EQ((size_t)21, countNewLines(plog->dumpToString( + "" /* prefix */, 3 /* lines */, 2 /* limitNs */))); + + plog->dump(0 /* fd (stdout) */); + + // The output below depends on the local time zone. + // The indentation below is exact, check alignment. + /* +Signal power history (resolution: 0.4 ms): + 12-31 16:00:00.000: [ -14.3 -18.1 -18.1 -18.1 +Signal power history (resolution: 0.0 ms): + 12-31 16:00:00.000: [ -6.0 -6.0 -6.0 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 + 12-31 16:00:00.000: -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 + 12-31 16:00:00.000: -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 + 12-31 16:00:00.001: -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 + 12-31 16:00:00.001: -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 + 12-31 16:00:00.001: -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 -18.1 + 12-31 16:00:00.001: -18.1 -18.1 -18.1 ] sum(2.3) + 12-31 16:00:00.002: [ -6.0 + + -6.0 -|*** | + -7.0 -| | + -8.0 -| | + -9.0 -| | + -10.0 -| | + -11.0 -| | + -12.0 -| | + -13.0 -| | + -14.0 -| | + -15.0 -| | + -16.0 -| | + -17.0 -| | + -18.0 -| ************************************************************| + -19.0 -| | + |________________________________________________________________ + */ +} + TEST(audio_utils_powerlog, c) { power_log_t *power_log = power_log_create( 48000 /* sample_rate */, |