Skip to content

Commit

Permalink
Unit tests failed with the copy operation as the pointer is used.
Browse files Browse the repository at this point in the history
Reverted back to providing the pointer to the coefficients.
Added a unit test to check if the coeffs are properly returned.
  • Loading branch information
berndporr committed Dec 18, 2024
1 parent 9285fcd commit ead398f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 2 additions & 5 deletions iir/Cascade.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ namespace Iir {
struct IIR_EXPORT Storage
{
Storage() = delete;
Storage(const int maxNumBiquads, const Biquad* const biquadArray) : maxStages(maxNumBiquads), stageArray(new Biquad[maxNumBiquads]) {
std::copy(biquadArray,biquadArray+maxNumBiquads,stageArray);
}
~Storage() { delete [] stageArray; }
Storage(const int maxNumBiquads, Biquad* const biquadArray) : maxStages(maxNumBiquads), stageArray(biquadArray) {}
const int maxStages = 0;
Biquad* const stageArray = nullptr;
};
Expand Down Expand Up @@ -169,7 +166,7 @@ namespace Iir {
/**
* Returns the coefficients of the entire Biquad chain
**/
const Cascade::Storage getCascadeStorage() const
const Cascade::Storage getCascadeStorage()
{
const Cascade::Storage s(MaxStages, m_stages);
return s;
Expand Down
10 changes: 10 additions & 0 deletions test/custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ int main (int,char**)

Iir::Custom::SOSCascade<2> f(coeff);

auto coeffRet = f.getCascadeStorage();
for(int i = 0; i < 2; i++) {
assert_print(coeffRet.stageArray[i].m_a0 == coeff[i][3],"m_a0 mismatch.\n");
assert_print(coeffRet.stageArray[i].m_a1 == coeff[i][4],"m_a1 mismatch.\n");
assert_print(coeffRet.stageArray[i].m_a2 == coeff[i][5],"m_a2 mismatch.\n");
assert_print(coeffRet.stageArray[i].m_b0 == coeff[i][3],"m_b0 mismatch.\n");
assert_print(coeffRet.stageArray[i].m_b1 == coeff[i][4],"m_b1 mismatch.\n");
assert_print(coeffRet.stageArray[i].m_b2 == coeff[i][5],"m_b2 mismatch.\n");
}

double b = 0;
double b2 = 0;
for(int i=0;i<10000;i++)
Expand Down

0 comments on commit ead398f

Please sign in to comment.