Modify the buffer size according to the framecounts
Bug: 305866207
Test: atest VtsHalDownmixTargetTest
atest VtsHalLoudnessEnhancerTargetTest
Change-Id: I448875e7d79ac766a882cc3a958fb54ef76265ce
diff --git a/audio/aidl/vts/VtsHalDownmixTargetTest.cpp b/audio/aidl/vts/VtsHalDownmixTargetTest.cpp
index 844a340..a1491e6 100644
--- a/audio/aidl/vts/VtsHalDownmixTargetTest.cpp
+++ b/audio/aidl/vts/VtsHalDownmixTargetTest.cpp
@@ -96,8 +96,7 @@
Parameter::Specific specific = getDefaultParamSpecific();
Parameter::Common common = EffectHelper::createParamCommon(
0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
- kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */,
- inputChannelLayout,
+ kFrameCount /* iFrameCount */, kFrameCount /* oFrameCount */, inputChannelLayout,
AudioChannelLayout::make<AudioChannelLayout::layoutMask>(
AudioChannelLayout::LAYOUT_STEREO));
ASSERT_NO_FATAL_FAILURE(open(mEffect, common, specific, &mOpenEffectReturn, EX_NONE));
@@ -139,14 +138,14 @@
}
void setDataTestParams(int32_t layoutType) {
- mInputBuffer.resize(kBufferSize);
-
// Get the number of channels used
mInputChannelCount = getChannelCount(
AudioChannelLayout::make<AudioChannelLayout::layoutMask>(layoutType));
+ mInputBufferSize = kFrameCount * mInputChannelCount;
+ mInputBuffer.resize(mInputBufferSize);
// In case of downmix, output is always configured to stereo layout.
- mOutputBufferSize = (mInputBuffer.size() / mInputChannelCount) * kOutputChannelCount;
+ mOutputBufferSize = kFrameCount * kOutputChannelCount;
mOutputBuffer.resize(mOutputBufferSize);
}
@@ -173,7 +172,12 @@
return true;
}
- static constexpr long kInputFrameCount = 100, kOutputFrameCount = 100;
+ static const long kFrameCount = 256;
+ static constexpr float kMaxDownmixSample = 1;
+ static constexpr int kOutputChannelCount = 2;
+ // Mask for layouts greater than MAX_INPUT_CHANNELS_SUPPORTED
+ static constexpr int32_t kMaxChannelMask =
+ ~((1 << ChannelMix<AUDIO_CHANNEL_OUT_STEREO>::MAX_INPUT_CHANNELS_SUPPORTED) - 1);
std::shared_ptr<IFactory> mFactory;
Descriptor mDescriptor;
std::shared_ptr<IEffect> mEffect;
@@ -183,12 +187,7 @@
std::vector<float> mOutputBuffer;
size_t mInputChannelCount;
size_t mOutputBufferSize;
- static constexpr size_t kBufferSize = 128;
- static constexpr float kMaxDownmixSample = 1;
- static constexpr int kOutputChannelCount = 2;
- // Mask for layouts greater than MAX_INPUT_CHANNELS_SUPPORTED
- static constexpr int32_t kMaxChannelMask =
- ~((1 << ChannelMix<AUDIO_CHANNEL_OUT_STEREO>::MAX_INPUT_CHANNELS_SUPPORTED) - 1);
+ size_t mInputBufferSize;
};
/**
@@ -401,9 +400,9 @@
void TearDown() override { TearDownDownmix(); }
void validateOutput() {
- ASSERT_EQ(kBufferSize, mInputBuffer.size());
- ASSERT_GE(kBufferSize, mOutputBufferSize);
- for (size_t i = 0, j = 0; i < kBufferSize && j < mOutputBufferSize;
+ ASSERT_EQ(mInputBufferSize, mInputBuffer.size());
+ ASSERT_GE(mInputBufferSize, mOutputBufferSize);
+ for (size_t i = 0, j = 0; i < mInputBufferSize && j < mOutputBufferSize;
i += mInputChannelCount, j += kOutputChannelCount) {
ASSERT_EQ(mOutputBuffer[j], mInputBuffer[i]);
ASSERT_EQ(mOutputBuffer[j + 1], mInputBuffer[i + 1]);
diff --git a/audio/aidl/vts/VtsHalLoudnessEnhancerTargetTest.cpp b/audio/aidl/vts/VtsHalLoudnessEnhancerTargetTest.cpp
index 3c72dfa..1fe8beb 100644
--- a/audio/aidl/vts/VtsHalLoudnessEnhancerTargetTest.cpp
+++ b/audio/aidl/vts/VtsHalLoudnessEnhancerTargetTest.cpp
@@ -23,6 +23,7 @@
using namespace android;
+using aidl::android::hardware::audio::common::getChannelCount;
using aidl::android::hardware::audio::effect::Descriptor;
using aidl::android::hardware::audio::effect::getEffectTypeUuidLoudnessEnhancer;
using aidl::android::hardware::audio::effect::IEffect;
@@ -50,7 +51,7 @@
Parameter::Specific specific = getDefaultParamSpecific();
Parameter::Common common = createParamCommon(
0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
- kInputFrameCount /* iFrameCount */, kOutputFrameCount /* oFrameCount */);
+ kFrameCount /* iFrameCount */, kFrameCount /* oFrameCount */);
ASSERT_NO_FATAL_FAILURE(open(mEffect, common, specific, &mOpenEffectReturn, EX_NONE));
ASSERT_NE(nullptr, mEffect);
mVersion = EffectFactoryHelper::getHalVersion(mFactory);
@@ -110,7 +111,7 @@
<< "\ngetParam:" << getParam.toString();
}
- static const long kInputFrameCount = 0x100, kOutputFrameCount = 0x100;
+ static const long kFrameCount = 256;
IEffect::OpenEffectReturn mOpenEffectReturn;
std::shared_ptr<IFactory> mFactory;
std::shared_ptr<IEffect> mEffect;
@@ -153,8 +154,12 @@
public:
LoudnessEnhancerDataTest() {
std::tie(mFactory, mDescriptor) = GetParam();
+ mBufferSize = kFrameCount *
+ getChannelCount(AudioChannelLayout::make<AudioChannelLayout::layoutMask>(
+ AudioChannelLayout::LAYOUT_STEREO));
generateInputBuffer();
- mOutputBuffer.resize(kBufferSize);
+
+ mOutputBuffer.resize(mBufferSize);
}
void SetUp() override {
@@ -174,7 +179,7 @@
// Fill inputBuffer with random values between -kMaxAudioSample to kMaxAudioSample
void generateInputBuffer() {
- for (size_t i = 0; i < kBufferSize; i++) {
+ for (size_t i = 0; i < mBufferSize; i++) {
mInputBuffer.push_back(((static_cast<float>(std::rand()) / RAND_MAX) * 2 - 1) *
kMaxAudioSample);
}
@@ -215,7 +220,7 @@
}
void assertSequentialGains(const std::vector<int>& gainValues, bool isIncreasing) {
- std::vector<float> baseOutput(kBufferSize);
+ std::vector<float> baseOutput(mBufferSize);
// Process a reference output buffer with 0 gain which gives compressed input values
binder_exception_t expected;
@@ -252,7 +257,7 @@
std::vector<float> mInputBuffer;
std::vector<float> mOutputBuffer;
- static constexpr float kBufferSize = 128;
+ size_t mBufferSize;
};
TEST_P(LoudnessEnhancerDataTest, IncreasingGains) {