11#if GRAPH_UNIT_TESTS_SAMPLECONVERSION
13namespace tracktion {
inline namespace graph
19 SampleConversionTests()
20 :
juce::UnitTest (
"SampleConversion",
"tracktion_graph")
24 void runTest()
override
26 constexpr double sampleRate = 44100.0;
29 beginTest (
"Sample to time and back");
31 for (int64_t i = 0; i <
int64_t (sampleRate) * 2; ++i)
34 auto sample = timeToSample (time, sampleRate);
37 expect (
false,
juce::String (
"Sample to time and back not equal s1=S1, t=TIME, s2=S2")
38 .replace (
"S1", STR (i)).replace (
"TIME", STR (time)).replace (
"S2", STR (sample)));
42 beginTest (
"Time to samples and back");
44 constexpr double startTime = 0.0;
45 constexpr double endTime = 2.0;
49 for (
double t = startTime; t < endTime; t += increment)
51 auto sample = timeToSample (t, sampleRate);
55 expect (
false,
juce::String (
"Time to sample and back not equal t1=TIME1, s=S1 t=TIME2")
56 .replace (
"TIME1", STR (t)).replace (
"S1", STR (sample)).replace (
"TIME2", STR (time)));
62static SampleConversionTests sampleConversionTests;
bool isWithin(Type a, Type b, Type tolerance) noexcept
constexpr double sampleToTime(IntType samplePosition, double sampleRate)
Converts an integer sample number to a time in seconds.