HART  0.2.0
High level Audio Regression and Testing
Loading...
Searching...
No Matches
hart_analysis_context.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4
7
8namespace hart
9{
10
11/// @brief Contains audio-related artefacts useful for analysis by matchers
12/// @details Designed to be used to retreive various audio-related artefacts
13/// for audio analysis, such as input and output audio buffers, spectra, and
14/// possibly some others.
15///
16/// All derivative artefacts, such as Spectra, are calculated on demand and
17/// then cached. Everything is read only.
18///
19/// Designed as a lightweight object, so it's totally okay to copy it.
20/// @tparam Type of samples of the audio buffers, typicalle `float` or `double`
21template <typename SampleType>
23{
24public:
25 /// @brief Creates an instance of analysis context
26 /// @details You probably have no reason to instantiate this class yourself,
27 /// it's meand to be created by the AudioTestBuilder only.
29 const AudioBuffer<SampleType>& inputAudio,
30 const AudioBuffer<SampleType>& outputAudio
31 ):
32 m_inputAudio (inputAudio),
33 m_outputAudio (outputAudio),
34 m_cache (std::make_shared<Cache>())
35 {
36 }
37
38 /// @brief Returns a buffer with input audio
39 const AudioBuffer<SampleType>& inputAudio() const
40 {
41 return m_inputAudio;
42 }
43
44 /// @brief Returns a buffer with output audio
45 const AudioBuffer<SampleType>& outputAudio() const
46 {
47 return m_outputAudio;
48 }
49
50 /// @brief Returns a spectrum of the input audio
51 const Spectrum& inputSpectrum() const
52 {
53 if (m_cache->inputSpectrum == nullptr)
54 m_cache->inputSpectrum = std::make_shared<Spectrum> (m_inputAudio);
55
56 return *m_cache->inputSpectrum;
57 }
58
59 /// @brief Returns a spectrum of the output audio
60 const Spectrum& outputSpectrum() const
61 {
62 if (m_cache->outputSpectrum == nullptr)
63 m_cache->outputSpectrum = std::make_shared<Spectrum> (m_outputAudio);
64
65 return *m_cache->outputSpectrum;
66 }
67
68private:
69 struct Cache
70 {
71 mutable std::shared_ptr<Spectrum> inputSpectrum = nullptr;
72 mutable std::shared_ptr<Spectrum> outputSpectrum = nullptr;
73 };
74
75 const AudioBuffer<SampleType>& m_inputAudio;
76 const AudioBuffer<SampleType>& m_outputAudio;
77
78 std::shared_ptr<Cache> m_cache;
79};
80
81} // namespace hart
Contains audio-related artefacts useful for analysis by matchers.
const AudioBuffer< SampleType > & inputAudio() const
Returns a buffer with input audio.
const AudioBuffer< SampleType > & outputAudio() const
Returns a buffer with output audio.
const Spectrum & outputSpectrum() const
Returns a spectrum of the output audio.
AnalysisContext(const AudioBuffer< SampleType > &inputAudio, const AudioBuffer< SampleType > &outputAudio)
Creates an instance of analysis context.
const Spectrum & inputSpectrum() const
Returns a spectrum of the input audio.
Container for audio data.
Frequency-domain representation of a multi-channel audio signal.