Skip to content

Commit

Permalink
Working through CI errors; this commit will be squashed
Browse files Browse the repository at this point in the history
  • Loading branch information
sp1ff committed Mar 2, 2024
1 parent ac82572 commit f35b281
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/output/plugins/visualization/SoundAnalysis.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class SoundAnalysis {

/// # of samples to be used in each analysis
size_t num_samples;
/// # of Fourier coefficients computed by FFTW (should be (num_samples /
/// # 2) + 1)
/* # of Fourier coefficients computed by FFTW (should be
(num_samples / 2) + 1) */
size_t out_samples;
std::shared_ptr<SoundInfoCache> pcache;
AudioFormat audio_format;
Expand Down
42 changes: 26 additions & 16 deletions test/TestVisualization.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ TEST(VisualizationTest, Waveform)
\code
In[5]:= Fourier[{1/2,1/2,1/2,-3/2,1/2}, FourierParameters -> {1,-1}]
Out[5]= {0.5 +0. I,1.61803 -1.17557 I,-0.618034+1.90211 I,-0.618034-1.90211 I,1.61803 +1.17557 I}
Out[5]= {0.5 +0. I, 1.61803 -1.17557 I, -0.618034+1.90211 I, -0.618034-1.90211 I, 1.61803 +1.17557 I}
\endcode
*
Expand Down Expand Up @@ -588,7 +588,7 @@ TEST(VisualizationTest, Waveform)
\code
In[6]:= Fourier[{1/4,1/4,1/4,1/4,1/4}, FourierParameters -> {1,-1}]
Out[6]= {1.25,5.55112*10^-17,5.55112*10^-17,5.55112*10^-17,5.55112*10^-17}
Out[6]= {1.25, 5.55112*10^-17, 5.55112*10^-17, 5.55112*10^-17, 5.55112*10^-17}
\endcode
*
Expand Down Expand Up @@ -630,7 +630,7 @@ TEST(VisualizationTest, TrivialDft)
EXPECT_EQ(d, seconds(5));

// For each channel, we'll get back five Fourier coefficients, corresponding
// to the frequencies 0Hz, 1/5Hz, 2/5, 3/5 & 4/5. Let's pick cuttoffs that
// to the frequencies 0Hz, 1/5Hz, 2/5, 3/5 & 4/5. Let's pick cutoffs that
// will discard the highest & the lowest, just for testing purposes.
SoundAnalysisParameters params { 5, 0.25, 0.75 };
SoundAnalysis analysis(params, pcache);
Expand All @@ -651,6 +651,7 @@ TEST(VisualizationTest, TrivialDft)
EXPECT_FLOAT_EQ(coeffs[1][1], -1.1755705045849462583374119092781);
EXPECT_FLOAT_EQ(coeffs[2][0], -0.61803398874989484820458683436564);
EXPECT_FLOAT_EQ(coeffs[2][1], 1.9021130325903071442328786667588);

EXPECT_FLOAT_EQ(coeffs[3][0], 1.25);
EXPECT_FLOAT_EQ(coeffs[3][1], 0.0);
EXPECT_FLOAT_EQ(coeffs[4][0], 0.0);
Expand Down Expand Up @@ -684,7 +685,7 @@ TEST(VisualizationTest, TrivialDft)

// waveforms:
// chan 0: 0.5, 0.5 0.5 -1.5, 0.5
// chan 1: 0.25 0.25 0.25, 0.25, 0.25
// chan 1: 0.25 0.25 0.25 0.25, 0.25

// coeffs:
// chan 0: (1.6180339887498948482045868343656, -1.1755705045849462583374119092781), (-0.61803398874989484820458683436564, 1.9021130325903071442328786667588) (-0.61803398874989484820458683436564, 1.9021130325903071442328786667588)
Expand All @@ -694,13 +695,23 @@ TEST(VisualizationTest, TrivialDft)
// chan 0: 2, 2, 2
// chan 1: 0, 0, 0

std::byte buf[153];
std::byte *p1 = analysis.SerializeSoundInfoFramePayload(buf);
std::byte *p0 = buf;
std::byte buf[153 + 8]; // 4 bytes before & 4 bytes after
std::fill(buf, buf + 153 + 8, std::byte{0xef});
std::byte *p1 = analysis.SerializeSoundInfoFramePayload(buf + 4);
std::byte *p0 = buf + 4;
EXPECT_EQ(p1, p0 + 153);
EXPECT_EQ(buf[0], std::byte{0xef});
EXPECT_EQ(buf[1], std::byte{0xef});
EXPECT_EQ(buf[2], std::byte{0xef});
EXPECT_EQ(buf[3], std::byte{0xef});

EXPECT_EQ(buf[157], std::byte{0xef});
EXPECT_EQ(buf[158], std::byte{0xef});
EXPECT_EQ(buf[159], std::byte{0xef});
EXPECT_EQ(buf[160], std::byte{0xef});

EXPECT_EQ(FromBE16(*(uint16_t*)p0), 5); p0 += 2; // num_samp := 5
EXPECT_EQ(*p0, (std::byte)2); p0 += 1; // num_chan := 2
EXPECT_EQ(*p0, (std::byte)2); p0 += 1; // num_chan := 2
EXPECT_EQ(FromBE16(*(uint16_t*)p0), 1); p0 += 2; // sample_rate := 1

// waveform, channel 0
Expand Down Expand Up @@ -741,7 +752,7 @@ TEST(VisualizationTest, TrivialDft)
// Ubuntu, at least), the tests pass with a fairly tight threshold
// (1.0e-43f). However, to get the tests to pass on MacOS, we need to
// loosen this considerably (different hardware on the Github action
// runners, perhaps?)
// runners, perhaps).
const float ZERO_THRESH = 1.0e-18f;

// coefficients, channel 1
Expand All @@ -750,18 +761,17 @@ TEST(VisualizationTest, TrivialDft)
EXPECT_NEAR(float_at(p0, 2), 0.0, ZERO_THRESH);
EXPECT_NEAR(float_at(p0, 3), 0.0, ZERO_THRESH);
EXPECT_NEAR(float_at(p0, 4), 0.0, ZERO_THRESH);
EXPECT_NEAR(float_at(p0, 5), 0.0, ZERO_THRESH);
EXPECT_NEAR(float_at(p0, 5), 0.0, ZERO_THRESH); // p0[5] is -2
p0 += 24;

// coefficients, channel 2
EXPECT_NEAR(float_at(p0, 0), 2.0, ZERO_THRESH);
EXPECT_NEAR(float_at(p0, 1), 2.0, ZERO_THRESH);
EXPECT_NEAR(float_at(p0, 2), 2.0, ZERO_THRESH);
p0 += 12;

EXPECT_NEAR(float_at(p0, 0), 0.0, ZERO_THRESH);
EXPECT_NEAR(float_at(p0, 1), 0.0, ZERO_THRESH);
EXPECT_NEAR(float_at(p0, 2), 0.0, ZERO_THRESH);
p0 += 12;
EXPECT_NEAR(float_at(p0, 3), 0.0, ZERO_THRESH);
EXPECT_NEAR(float_at(p0, 4), 0.0, ZERO_THRESH);
EXPECT_NEAR(float_at(p0, 5), 0.0, ZERO_THRESH); // p0[2] is 2
p0 += 24;

// bass/mids/trebs

Expand Down

0 comments on commit f35b281

Please sign in to comment.