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

#include <WavMirAudioReader.h>

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

Public Member Functions

 WavMirAudioReader (const std::string &filename, std::optional< double > timeLimit={})
 
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 std::vector< float > mSamples
 
const double mSampleRate = 0.
 

Detailed Description

Definition at line 21 of file WavMirAudioReader.h.

Constructor & Destructor Documentation

◆ WavMirAudioReader()

MIR::WavMirAudioReader::WavMirAudioReader ( const std::string &  filename,
std::optional< double >  timeLimit = {} 
)

Definition at line 21 of file WavMirAudioReader.cpp.

23{
24 AudioFileInfo info;
25 std::vector<std::vector<float>> samples;
26 if (!AudioFileIO::Read(filename, samples, info))
27 throw std::runtime_error(std::string { "Failed to read " } + filename);
28
29 const_cast<double&>(mSampleRate) = info.sampleRate;
30 const auto limit = timeLimit.has_value() ?
31 static_cast<long long>(*timeLimit * info.sampleRate) :
32 std::numeric_limits<long long>::max();
33 auto& mutableSamples = const_cast<std::vector<float>&>(mSamples);
34 const auto numFrames = std::min<long long>(info.numFrames, limit);
35 mutableSamples.resize(numFrames);
36 if (info.numChannels == 2)
37 for (size_t i = 0; i < numFrames; ++i)
38 mutableSamples[i] = (samples[0][i] + samples[1][i]) / 2.f;
39 else
41 samples[0].begin(), samples[0].begin() + numFrames,
42 mutableSamples.begin());
43}
const std::vector< float > mSamples
const char * begin(const char *str) noexcept
Definition: StringUtils.h:101
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40

References details::begin(), staffpad::vo::copy(), mSampleRate, and mSamples.

Here is the call graph for this function:

Member Function Documentation

◆ GetNumSamples()

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

Implements MIR::MirAudioReader.

Definition at line 50 of file WavMirAudioReader.cpp.

51{
52 return mSamples.size();
53}

References mSamples.

◆ GetSampleRate()

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

Implements MIR::MirAudioReader.

Definition at line 45 of file WavMirAudioReader.cpp.

46{
47 return mSampleRate;
48}

References mSampleRate.

◆ ReadFloats()

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

Implements MIR::MirAudioReader.

Definition at line 55 of file WavMirAudioReader.cpp.

57{
58 assert(start >= 0);
59 assert(start + numFrames <= mSamples.size());
61 mSamples.begin() + start, mSamples.begin() + start + numFrames, buffer);
62}

References staffpad::vo::copy(), and mSamples.

Here is the call graph for this function:

Member Data Documentation

◆ mSampleRate

const double MIR::WavMirAudioReader::mSampleRate = 0.
private

Definition at line 34 of file WavMirAudioReader.h.

Referenced by GetSampleRate(), and WavMirAudioReader().

◆ mSamples

const std::vector<float> MIR::WavMirAudioReader::mSamples
private

Definition at line 33 of file WavMirAudioReader.h.

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


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