@@ -175,35 +175,48 @@ TEST_F (LinkwitzRileyFilterTests, LR8ProcessSampleDoesNotCrash)
175175TEST_F (LinkwitzRileyFilterTests, ComplementaryResponse)
176176{
177177 LinkwitzRiley2Filter<float > filter (1000.0 );
178+ filter.setSampleRate (sampleRate);
179+ filter.reset ();
178180
179- // Test that low + high outputs sum to approximately unity at crossover frequency
181+ // Now do the actual test
180182 float lowLeft, lowRight, highLeft, highRight;
181- float sumLeft = 0 .0f , sumRight = 0 .0f ;
182183
183- // Process sine wave at crossover frequency
184+ // Let the filter settle by processing some samples first
185+ for (int i = 0 ; i < blockSize; ++i)
186+ filter.processSample (sineTestLeft[i], sineTestRight[i], lowLeft, lowRight, highLeft, highRight);
187+
188+ // Test that low + high outputs sum to approximately unity at crossover frequency
189+ std::vector<float > summedLeft (blockSize);
190+ std::vector<float > summedRight (blockSize);
191+
192+ // Process sine wave at crossover frequency (second pass for steady state)
184193 for (int i = 0 ; i < blockSize; ++i)
185194 {
186195 filter.processSample (sineTestLeft[i], sineTestRight[i], lowLeft, lowRight, highLeft, highRight);
187- sumLeft += ( lowLeft + highLeft) * (lowLeft + highLeft) ;
188- sumRight += ( lowRight + highRight) * (lowRight + highRight) ;
196+ summedLeft[i] = lowLeft + highLeft;
197+ summedRight[i] = lowRight + highRight;
189198 }
190199
191- // RMS of sum should be close to RMS of input
200+ // Calculate RMS of summed outputs
201+ float sumRmsLeft = 0 .0f , sumRmsRight = 0 .0f ;
192202 float inputRmsLeft = 0 .0f , inputRmsRight = 0 .0f ;
203+
193204 for (int i = 0 ; i < blockSize; ++i)
194205 {
206+ sumRmsLeft += summedLeft[i] * summedLeft[i];
207+ sumRmsRight += summedRight[i] * summedRight[i];
195208 inputRmsLeft += sineTestLeft[i] * sineTestLeft[i];
196209 inputRmsRight += sineTestRight[i] * sineTestRight[i];
197210 }
198211
199- sumLeft = std::sqrt (sumLeft / blockSize);
200- sumRight = std::sqrt (sumRight / blockSize);
212+ sumRmsLeft = std::sqrt (sumRmsLeft / blockSize);
213+ sumRmsRight = std::sqrt (sumRmsRight / blockSize);
201214 inputRmsLeft = std::sqrt (inputRmsLeft / blockSize);
202215 inputRmsRight = std::sqrt (inputRmsRight / blockSize);
203216
204217 // Allow for some tolerance due to filter transient and numerical precision
205- EXPECT_NEAR (sumLeft , inputRmsLeft, 0 .1f );
206- EXPECT_NEAR (sumRight , inputRmsRight, 0 .1f );
218+ EXPECT_NEAR (sumRmsLeft , inputRmsLeft, 0 .1f );
219+ EXPECT_NEAR (sumRmsRight , inputRmsRight, 0 .1f );
207220}
208221
209222TEST_F (LinkwitzRileyFilterTests, ResetClearsState)
0 commit comments