Audacity 3.2.0
MirTestUtils.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 MirTestUtils.cpp
7
8 Matthieu Hodgkinson
9
10**********************************************************************/
11#include "MirTestUtils.h"
12
13#define USE_FILESYSTEM (__has_include(<filesystem>) && _WIN32)
14
15#if USE_FILESYSTEM
16# include <filesystem>
17#endif
18
19#include <array>
20#include <cmath>
21#include <iomanip>
22#include <iostream>
23
24namespace MIR
25{
26void ProgressBar(int width, int percent)
27{
28 int progress = (width * percent) / 100;
29 std::cout << "[";
30 for (int i = 0; i < width; ++i)
31 if (i < progress)
32 std::cout << "=";
33 else
34 std::cout << " ";
35 std::cout << "] " << std::setw(3) << percent << "%\r";
36 std::cout.flush();
37}
38
39OctaveError GetOctaveError(double expected, double actual)
40{
41 constexpr std::array<double, 5> factors { 1., 2., .5, 3., 1. / 3 };
42 std::vector<OctaveError> octaveErrors;
43 std::transform(
44 factors.begin(), factors.end(), std::back_inserter(octaveErrors),
45 [&](double factor) {
46 const auto remainder = std::log2(factor * actual / expected);
47 return OctaveError { factor, remainder };
48 });
49 return *std::min_element(
50 octaveErrors.begin(), octaveErrors.end(),
51 [](const auto& a, const auto& b) {
52 return std::abs(a.remainder) < std::abs(b.remainder);
53 });
54}
55} // namespace MIR
OctaveError GetOctaveError(double expected, double actual)
Gets the tempo detection octave error, as defined in section 5. of Schreiber, H., Urbano,...
void ProgressBar(int width, int percent)