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
8
9namespace hart
10{
11
12/// @brief Contains audio-related artefacts useful for analysis by matchers
13/// @details Designed to be used to retreive various audio-related artefacts
14/// for audio analysis, such as input and output audio buffers, spectra, and
15/// possibly some others.
16///
17/// All derivative artefacts, such as Spectra, are calculated on demand and
18/// then cached. Everything is read only.
19///
20/// Designed as a lightweight object, so it's totally okay to copy it.
21/// @tparam Type of samples of the audio buffers, typicalle `float` or `double`
22template <typename SampleType>
24{
25public:
26 /// @brief Creates an instance of analysis context
27 /// @details You probably have no reason to instantiate this class yourself,
28 /// it's meand to be created by the AudioTestBuilder only.
30 const AudioBuffer<SampleType>& inputAudio,
31 const AudioBuffer<SampleType>& outputAudio
32 ):
33 m_inputAudio (inputAudio),
34 m_outputAudio (outputAudio),
35 m_cache (std::make_shared<Cache>())
36 {
37 }
38
39 /// @brief Returns a buffer with input audio
40 const AudioBuffer<SampleType>& inputAudio() const
41 {
42 return m_inputAudio;
43 }
44
45 /// @brief Returns a buffer with output audio
46 const AudioBuffer<SampleType>& outputAudio() const
47 {
48 return m_outputAudio;
49 }
50
51 /// @brief Returns a spectrum of the input audio
52 const Spectrum& inputSpectrum() const
53 {
54 if (m_cache->inputSpectrum == nullptr)
55 m_cache->inputSpectrum = std::make_shared<Spectrum> (m_inputAudio);
56
57 return *m_cache->inputSpectrum;
58 }
59
60 /// @brief Returns a spectrum of the output audio
61 const Spectrum& outputSpectrum() const
62 {
63 if (m_cache->outputSpectrum == nullptr)
64 m_cache->outputSpectrum = std::make_shared<Spectrum> (m_outputAudio);
65
66 return *m_cache->outputSpectrum;
67 }
68
69 /// @brief Returns an impulse response of the output audio vs input audio
70 const ImpulseResponse<SampleType>& impulseResponse() const
71 {
72 if (m_cache->impulseResponse == nullptr)
73 {
74 m_cache->impulseResponse = std::make_shared<ImpulseResponse<SampleType>> (
75 m_inputAudio,
76 m_outputAudio
77 );
78 }
79
80 return *m_cache->impulseResponse;
81 }
82
83private:
84 struct Cache
85 {
86 mutable std::shared_ptr<Spectrum> inputSpectrum = nullptr;
87 mutable std::shared_ptr<Spectrum> outputSpectrum = nullptr;
88 mutable std::shared_ptr<ImpulseResponse<SampleType>> impulseResponse = nullptr;
89 };
90
91 const AudioBuffer<SampleType>& m_inputAudio;
92 const AudioBuffer<SampleType>& m_outputAudio;
93
94 std::shared_ptr<Cache> m_cache;
95};
96
97} // 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 ImpulseResponse< SampleType > & impulseResponse() const
Returns an impulse response of the output audio vs input audio.
const Spectrum & inputSpectrum() const
Returns a spectrum of the input audio.
Container for representing an impulse response (IR)
Frequency-domain representation of a multi-channel audio signal.