-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.h
56 lines (44 loc) · 1.4 KB
/
Utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//---------------------------------------------------------------------------
#ifndef UtilsH
#define UtilsH
#include <System.hpp>
#include <vector>
#include <cmath>
#include <utility>
#include <iterator>
#include <algorithm>
namespace PitchDet {
using WaveInDevsCont = std::vector<String>;
[[nodiscard]] extern WaveInDevsCont GetWaveInDevices();
extern void AppendWaveInDevices( TStrings& DeviceNames );
[[nodiscard]] inline float dBToValue( float Value )
{
return std::pow( 10.0F, Value / 20.0F );
}
//---------------------------------------------------------------------------
[[nodiscard]] inline float ValueTodB( float Value )
{
static constexpr float Neg300dBValue = 1e-15F;
return 20.0F * std::log10( std::max( Value, Neg300dBValue ) );
}
//---------------------------------------------------------------------------
template<typename I, typename T>
auto DiscretizeValueOnSortedRange( I Begin, I End, T const & Value )
-> std::pair<int,T>
{
auto It = std::lower_bound( Begin, End, Value );
if ( It != End ) {
if ( It != Begin && *It != Value ) {
--It;
}
return { static_cast<int>( std::distance( Begin, It ) ), *It };
}
else if ( It != Begin ) {
--It;
return { static_cast<int>( std::distance( Begin, It ) ), *It };
}
return { -1, Value };
}
//---------------------------------------------------------------------------
}
#endif