Skip to content

Commit

Permalink
Merge pull request #11502 from daschuer/analyzerwavefromtest_3
Browse files Browse the repository at this point in the history
Fidlib Unit-Tests
  • Loading branch information
Swiftb0y authored Apr 24, 2023
2 parents 2b15819 + 7b272a1 commit 0c323df
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/engine/filters/enginefilteriir.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ class EngineFilterIIR : public EngineFilterIIRBase {
char* desc;
FidFilter* filt = fid_design(spec_d, sampleRate, freq0, freq1, adj, &desc);
int delay = fid_calc_delay(filt);
qDebug() << QString().fromLatin1(desc) << "delay:" << delay;
qDebug() << QString().fromLatin1(desc);
qDebug() << spec_d << "delay:" << delay;
double resp0, phase0;
resp0 = fid_response_pha(filt, freq0 / sampleRate, &phase0);
qDebug() << "freq0:" << freq0 << resp0 << phase0;
Expand All @@ -126,16 +127,16 @@ class EngineFilterIIR : public EngineFilterIIRBase {
}
double resp2, phase2;
resp2 = fid_response_pha(filt, freq0 / sampleRate / 2, &phase2);
qDebug() << "freq2:" << freq0 / 2 << resp2 << phase0;
qDebug() << "freq2:" << freq0 / 2 << resp2 << phase2;
double resp3, phase3;
resp3 = fid_response_pha(filt, freq0 / sampleRate * 2, &phase3);
qDebug() << "freq3:" << freq0 * 2 << resp3 << phase0;
qDebug() << "freq3:" << freq0 * 2 << resp3 << phase3;
double resp4, phase4;
resp4 = fid_response_pha(filt, freq0 / sampleRate / 2.2, &phase4);
qDebug() << "freq4:" << freq0 / 2.2 << resp2 << phase0;
qDebug() << "freq4:" << freq0 / 2.2 << resp4 << phase4;
double resp5, phase5;
resp5 = fid_response_pha(filt, freq0 / sampleRate * 2.2, &phase5);
qDebug() << "freq5:" << freq0 * 2.2 << resp3 << phase0;
qDebug() << "freq5:" << freq0 * 2.2 << resp5 << phase5;
free(filt);
#endif
}
Expand Down Expand Up @@ -191,7 +192,8 @@ class EngineFilterIIR : public EngineFilterIIRBase {
FidFilter* filt = fid_cat(1, filt1, filt2, NULL);
int delay = fid_calc_delay(filt);
qDebug() << QString().fromLatin1(desc1) << "X"
<< QString().fromLatin1(desc2) << "delay:" << delay;
<< QString().fromLatin1(desc2);
qDebug() << spec1 << "X" << spec2 << "delay:" << delay;
double resp0, phase0;
resp0 = fid_response_pha(filt, freq01 / sampleRate, &phase0);
qDebug() << "freq01:" << freq01 << resp0 << phase0;
Expand All @@ -209,16 +211,16 @@ class EngineFilterIIR : public EngineFilterIIRBase {
}
double resp2, phase2;
resp2 = fid_response_pha(filt, freq01 / sampleRate / 2, &phase2);
qDebug() << "freq2:" << freq01 / 2 << resp2 << phase0;
qDebug() << "freq2:" << freq01 / 2 << resp2 << phase2;
double resp3, phase3;
resp3 = fid_response_pha(filt, freq01 / sampleRate * 2, &phase3);
qDebug() << "freq3:" << freq01 * 2 << resp3 << phase0;
qDebug() << "freq3:" << freq01 * 2 << resp3 << phase3;
double resp4, phase4;
resp4 = fid_response_pha(filt, freq01 / sampleRate / 2.2, &phase4);
qDebug() << "freq4:" << freq01 / 2.2 << resp2 << phase0;
qDebug() << "freq4:" << freq01 / 2.2 << resp4 << phase4;
double resp5, phase5;
resp5 = fid_response_pha(filt, freq01 / sampleRate * 2.2, &phase5);
qDebug() << "freq5:" << freq01 * 2.2 << resp3 << phase0;
qDebug() << "freq5:" << freq01 * 2.2 << resp5 << phase5;
free(filt);
#endif
}
Expand Down
33 changes: 33 additions & 0 deletions src/test/enginefilterbiquadtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,37 @@ TEST_F(EngineFilterBiquadTest, fidspecLengthIsLongEnough) {
ASSERT_TRUE(FIDSPEC_LENGTH > strlen("LsBq/1.2200000000/-12.0000000000"));
}

TEST_F(EngineFilterBiquadTest, analysisPkBq) {
char spec_d[FIDSPEC_LENGTH];
format_fidspec(spec_d, sizeof(spec_d), "PkBq/%.10f/%.10f", 1.75, 0.0);

char* pDesc = nullptr;
FidFilter* filt = fid_design(spec_d, 44100, 1000, 0, 0, &pDesc);
EXPECT_NE(pDesc, nullptr);
int delay = fid_calc_delay(filt);
EXPECT_EQ(delay, 0);

double resp0 = 0.0;
double phase0 = 1.0;
resp0 = fid_response_pha(filt, 1000 / 44100, &phase0);
EXPECT_DOUBLE_EQ(resp0, 1.0);
EXPECT_DOUBLE_EQ(phase0, 0.0);
free(filt);
}

TEST_F(EngineFilterBiquadTest, analysisLpBe4) {
char* pDesc = nullptr;
FidFilter* filt = fid_design("LpBe4", 44100, 600, 0, 0, &pDesc);
EXPECT_NE(pDesc, nullptr);
int delay = fid_calc_delay(filt);
EXPECT_EQ(delay, 24);

double resp0 = 0.0;
double phase0 = 1.0;
resp0 = fid_response_pha(filt, 600 / 44100, &phase0);
EXPECT_DOUBLE_EQ(resp0, 1.0);
EXPECT_DOUBLE_EQ(phase0, 0.0);
free(filt);
}

} // namespace

0 comments on commit 0c323df

Please sign in to comment.