Audacity 3.2.0
DecimatingMirAudioReader.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 DecimatingMirAudioReader.cpp
7
8 Matthieu Hodgkinson
9
10**********************************************************************/
12
13#include <cmath>
14#include <vector>
15
16namespace MIR
17{
19 : mReader { reader }
20 , mDecimationFactor {
21 // Input rate divided by this integer will be as close as possible to
22 // 24kHz and not greater.
23 static_cast<int>(std::ceil(reader.GetSampleRate() / 24000.))
24 }
25{
26}
27
29{
31}
32
34{
35 // Return the floor
37}
38
40 float* decimated, long long decimatedStart, size_t numDecimatedFrames) const
41{
42 const auto numFrames = numDecimatedFrames * mDecimationFactor;
43 if (mBuffer.size() < numFrames)
44 mBuffer.resize(numFrames);
45 const auto start = decimatedStart * mDecimationFactor;
46 mReader.ReadFloats(mBuffer.data(), start, numFrames);
47 for (auto i = 0; i < numDecimatedFrames; ++i)
48 decimated[i] = mBuffer[i * mDecimationFactor];
49}
50} // namespace MIR
long long GetNumSamples() const override
void ReadFloats(float *buffer, long long start, size_t numFrames) const override
DecimatingMirAudioReader(const MirAudioReader &reader)
virtual void ReadFloats(float *buffer, long long where, size_t numFrames) const =0
virtual long long GetNumSamples() const =0
virtual double GetSampleRate() const =0
STL namespace.