Audacity 3.2.0
TatumQuantizationFitVisualization.cpp
Go to the documentation of this file.
1#include "MirFakes.h"
2#include "MirTestUtils.h"
4#include "WavMirAudioReader.h"
5
6#include <catch2/catch.hpp>
7#include <fstream>
8
9namespace MIR
10{
11TEST_CASE("TatumQuantizationFitVisualization")
12{
13 // This test produces python files containing data. Besides being useful for
14 // debugging, after you have run this, you can run
15 // `visualize_debug_output.py` to visualize the working of the algorithm, or
16 // `visualize_post-processed_STFT.py` to visualize the STFT used to produce
17 // the ODF.
18
19 if (!runLocally)
20 return;
21
22 const auto wavFile =
23 std::string { CMAKE_CURRENT_SOURCE_DIR } +
24 "/benchmarking-dataset/loops/Acoustic Loop Lucaz Collab 116BPM.wav.mp3";
25 const WavMirAudioReader audio { wavFile };
27 const auto result = GetMusicalMeterFromSignal(
28 audio, FalsePositiveTolerance::Lenient, nullptr, &debugOutput);
29
30 std::ofstream debug_output_module {
31 std::string(CMAKE_CURRENT_SOURCE_DIR) +
32 "/TatumQuantizationFitVisualization/debug_output.py"
33 };
34 debug_output_module << "wavFile = \"" << wavFile << "\"\n";
35 debug_output_module << "odfSr = " << debugOutput.odfSr << "\n";
36 debug_output_module << "audioFileDuration = "
37 << debugOutput.audioFileDuration << "\n";
38 debug_output_module << "score = " << debugOutput.score << "\n";
39 debug_output_module << "tatumRate = "
40 << 60. * debugOutput.tatumQuantization.numDivisions /
41 debugOutput.audioFileDuration
42 << "\n";
43 debug_output_module << "bpm = " << (result.has_value() ? result->bpm : 0.)
44 << "\n";
45 debug_output_module << "lag = " << debugOutput.tatumQuantization.lag << "\n";
46 debug_output_module << "odf_peak_indices = [";
47 std::for_each(
48 debugOutput.odfPeakIndices.begin(), debugOutput.odfPeakIndices.end(),
49 [&](int i) { debug_output_module << i << ","; });
50 debug_output_module << "]\n";
51 PrintPythonVector(debug_output_module, debugOutput.odf, "odf");
52 PrintPythonVector(debug_output_module, debugOutput.rawOdf, "rawOdf");
54 debug_output_module, debugOutput.movingAverage, "movingAverage");
56 debug_output_module, debugOutput.odfAutoCorr, "odfAutoCorr");
58 debug_output_module, debugOutput.odfAutoCorrPeakIndices,
59 "odfAutoCorrPeakIndices");
60
61 std::ofstream stft_log_module {
62 std::string { CMAKE_CURRENT_SOURCE_DIR } +
63 "/TatumQuantizationFitVisualization/stft_log.py"
64 };
65 stft_log_module << "wavFile = \"" << wavFile << "\"\n";
66 stft_log_module << "sampleRate = " << audio.GetSampleRate() << "\n";
67 stft_log_module << "frameRate = " << debugOutput.odfSr << "\n";
68 stft_log_module << "stft = [";
69 std::for_each(
70 debugOutput.postProcessedStft.begin(),
71 debugOutput.postProcessedStft.end(), [&](const auto& row) {
72 stft_log_module << "[";
73 std::for_each(row.begin(), row.end(), [&](float x) {
74 stft_log_module << x << ",";
75 });
76 stft_log_module << "],";
77 });
78 stft_log_module << "]\n";
79}
80} // namespace MIR
MockedAudio audio
void PrintPythonVector(std::ofstream &ofs, const std::vector< T > &v, const char *name)
Definition: MirTestUtils.h:133
std::optional< MusicalMeter > GetMusicalMeterFromSignal(const MirAudioReader &audio, FalsePositiveTolerance tolerance, const std::function< void(double)> &progressCallback, QuantizationFitDebugOutput *debugOutput)
TEST_CASE("GetBpmFromFilename")
static constexpr auto runLocally
Definition: MirTestUtils.h:29
std::vector< float > odf
Definition: MirTypes.h:145
OnsetQuantization tatumQuantization
Definition: MirTypes.h:138
std::vector< float > odfAutoCorr
Definition: MirTypes.h:149
std::vector< float > rawOdf
Definition: MirTypes.h:143
std::vector< int > odfPeakIndices
Definition: MirTypes.h:148
std::vector< float > movingAverage
Definition: MirTypes.h:144
std::vector< PffftFloatVector > postProcessedStft
Definition: MirTypes.h:142
std::vector< int > odfAutoCorrPeakIndices
Definition: MirTypes.h:150