Audacity 3.2.0
Public Member Functions | Private Attributes | List of all members
MIR::DecimatingMirAudioReader Class Reference

Our MIR operations do not need the full 44.1 or 48kHz resolution typical of audio files. It may change in the future, if we start looking at chromagrams for example, but for now even a certain amount of aliasing isn't an issue. In fact, for onset detection, it may even be beneficial, since it preserves a trace of the highest frequency components by folding them down below the nyquist. Thus we can decimate the audio signal to a certain extent. This is fast and easy to implement, meanwhile reducing dramatically the amount of data and operations. More...

#include <DecimatingMirAudioReader.h>

Inheritance diagram for MIR::DecimatingMirAudioReader:
[legend]
Collaboration diagram for MIR::DecimatingMirAudioReader:
[legend]

Public Member Functions

 DecimatingMirAudioReader (const MirAudioReader &reader)
 
double GetSampleRate () const override
 
long long GetNumSamples () const override
 
void ReadFloats (float *buffer, long long start, size_t numFrames) const override
 
- Public Member Functions inherited from MIR::MirAudioReader
virtual double GetSampleRate () const =0
 
virtual long long GetNumSamples () const =0
 
virtual void ReadFloats (float *buffer, long long where, size_t numFrames) const =0
 
double GetDuration () const
 
virtual ~MirAudioReader ()=default
 

Private Attributes

const MirAudioReadermReader
 
const int mDecimationFactor
 
std::vector< float > mBuffer
 

Detailed Description

Our MIR operations do not need the full 44.1 or 48kHz resolution typical of audio files. It may change in the future, if we start looking at chromagrams for example, but for now even a certain amount of aliasing isn't an issue. In fact, for onset detection, it may even be beneficial, since it preserves a trace of the highest frequency components by folding them down below the nyquist. Thus we can decimate the audio signal to a certain extent. This is fast and easy to implement, meanwhile reducing dramatically the amount of data and operations.

Definition at line 29 of file DecimatingMirAudioReader.h.

Constructor & Destructor Documentation

◆ DecimatingMirAudioReader()

MIR::DecimatingMirAudioReader::DecimatingMirAudioReader ( const MirAudioReader reader)
explicit

Definition at line 18 of file DecimatingMirAudioReader.cpp.

19 : mReader { reader }
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}

Member Function Documentation

◆ GetNumSamples()

long long MIR::DecimatingMirAudioReader::GetNumSamples ( ) const
overridevirtual

Implements MIR::MirAudioReader.

Definition at line 33 of file DecimatingMirAudioReader.cpp.

34{
35 // Return the floor
37}
virtual long long GetNumSamples() const =0

References MIR::MirAudioReader::GetNumSamples(), mDecimationFactor, and mReader.

Here is the call graph for this function:

◆ GetSampleRate()

double MIR::DecimatingMirAudioReader::GetSampleRate ( ) const
overridevirtual

Implements MIR::MirAudioReader.

Definition at line 28 of file DecimatingMirAudioReader.cpp.

29{
31}
virtual double GetSampleRate() const =0

References MIR::MirAudioReader::GetSampleRate(), mDecimationFactor, and mReader.

Here is the call graph for this function:

◆ ReadFloats()

void MIR::DecimatingMirAudioReader::ReadFloats ( float *  buffer,
long long  start,
size_t  numFrames 
) const
overridevirtual

Implements MIR::MirAudioReader.

Definition at line 39 of file DecimatingMirAudioReader.cpp.

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}
virtual void ReadFloats(float *buffer, long long where, size_t numFrames) const =0

References mBuffer, mDecimationFactor, mReader, and MIR::MirAudioReader::ReadFloats().

Here is the call graph for this function:

Member Data Documentation

◆ mBuffer

std::vector<float> MIR::DecimatingMirAudioReader::mBuffer
mutableprivate

Definition at line 42 of file DecimatingMirAudioReader.h.

Referenced by ReadFloats().

◆ mDecimationFactor

const int MIR::DecimatingMirAudioReader::mDecimationFactor
private

Definition at line 41 of file DecimatingMirAudioReader.h.

Referenced by GetNumSamples(), GetSampleRate(), and ReadFloats().

◆ mReader

const MirAudioReader& MIR::DecimatingMirAudioReader::mReader
private

Definition at line 40 of file DecimatingMirAudioReader.h.

Referenced by GetNumSamples(), GetSampleRate(), and ReadFloats().


The documentation for this class was generated from the following files: