Audacity 3.2.0
StftFrameProviderTests.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 StftFrameProviderTests.cpp
7
8 Matthieu Hodgkinson
9
10**********************************************************************/
11#include "MirTypes.h"
12#include "MirUtils.h"
13#include "StftFrameProvider.h"
14
15#include <catch2/catch.hpp>
16
17namespace MIR
18{
19namespace
20{
22{
23public:
24 const long long numSamples;
25
26 TestMirAudioReader(long long numSamples)
27 : numSamples { numSamples }
28 {
29 }
30 double GetSampleRate() const override
31 {
32 return 44100;
33 };
34 long long GetNumSamples() const override
35 {
36 return numSamples;
37 };
38 void
39 ReadFloats(float* buffer, long long where, size_t numFrames) const override
40 {
41 REQUIRE(where >= 0);
42 REQUIRE(where + numFrames <= numSamples);
43 };
44};
45} // namespace
46TEST_CASE("StftFrameProvider")
47{
48 SECTION("handles empty files")
49 {
50 StftFrameProvider sut { TestMirAudioReader { 0 } };
51 PffftFloatVector frame;
52 REQUIRE(!sut.GetNextFrame(frame));
53 }
54 SECTION("handles very short files")
55 {
56 StftFrameProvider sut { TestMirAudioReader { 1 } };
57 PffftFloatVector frame;
58 REQUIRE(!sut.GetNextFrame(frame));
59 }
60 SECTION("has power-of-two number of frames")
61 {
62 StftFrameProvider sut { TestMirAudioReader { 123456 } };
63 REQUIRE(IsPowOfTwo(sut.GetNumFrames()));
64 }
65 SECTION("respects MirAudioReader boundaries")
66 {
67 TestMirAudioReader reader { 123456 };
68 StftFrameProvider sut { reader };
69 PffftFloatVector frame;
70 while (sut.GetNextFrame(frame))
71 ;
72 }
73}
74} // namespace MIR
void ReadFloats(float *buffer, long long where, size_t numFrames) const override
TEST_CASE("GetBpmFromFilename")
constexpr auto IsPowOfTwo(int x)
Definition: MirUtils.h:28
A vector of floats guaranteeing alignment as demanded by pffft.