From 56ee6207c1524ddc4c444c6e48e05eb34105985a Mon Sep 17 00:00:00 2001 From: Isabella Gottardi Date: Wed, 12 May 2021 08:27:15 +0100 Subject: MLECO-1858: Documentation update * Removing `_` in front of private functions and member Signed-off-by: Isabella Gottardi Change-Id: I5a5d652f9647ebb16d2d2bd16ab980e73f7be3cf --- source/use_case/ad/include/AdMelSpectrogram.hpp | 2 +- source/use_case/ad/include/AdModel.hpp | 2 +- source/use_case/ad/include/AdPostProcessing.hpp | 2 +- source/use_case/ad/include/MelSpectrogram.hpp | 61 ++++++------- source/use_case/ad/src/AdModel.cc | 14 +-- source/use_case/ad/src/MelSpectrogram.cc | 114 ++++++++++++------------ source/use_case/ad/src/UseCaseHandler.cc | 13 +-- 7 files changed, 105 insertions(+), 103 deletions(-) (limited to 'source/use_case/ad') diff --git a/source/use_case/ad/include/AdMelSpectrogram.hpp b/source/use_case/ad/include/AdMelSpectrogram.hpp index 30a77c1..05c5bfc 100644 --- a/source/use_case/ad/include/AdMelSpectrogram.hpp +++ b/source/use_case/ad/include/AdMelSpectrogram.hpp @@ -69,7 +69,7 @@ namespace audio { * energies to logarithmic scale. The difference from * default behaviour is that the power is converted to dB * and subsequently clamped. - * @param[in/out] melEnergies - 1D vector of Mel energies + * @param[in,out] melEnergies - 1D vector of Mel energies **/ virtual void ConvertToLogarithmicScale(std::vector& melEnergies) override; diff --git a/source/use_case/ad/include/AdModel.hpp b/source/use_case/ad/include/AdModel.hpp index bbdf91c..8d914c4 100644 --- a/source/use_case/ad/include/AdModel.hpp +++ b/source/use_case/ad/include/AdModel.hpp @@ -44,7 +44,7 @@ namespace app { static constexpr int ms_maxOpCnt = 6; /* A mutable op resolver instance */ - tflite::MicroMutableOpResolver _m_opResolver; + tflite::MicroMutableOpResolver m_opResolver; }; } /* namespace app */ diff --git a/source/use_case/ad/include/AdPostProcessing.hpp b/source/use_case/ad/include/AdPostProcessing.hpp index f3b35a1..7eaec84 100644 --- a/source/use_case/ad/include/AdPostProcessing.hpp +++ b/source/use_case/ad/include/AdPostProcessing.hpp @@ -38,7 +38,7 @@ namespace app { /** @brief Given a wav file name return AD model output index. * @param[in] wavFileName Audio WAV filename. - * File name should be in format __XX_.wav + * File name should be in format anything_goes_XX_here.wav * where XX is the machine ID e.g. 00, 02, 04 or 06 * @return AD model output index as 8 bit integer. **/ diff --git a/source/use_case/ad/include/MelSpectrogram.hpp b/source/use_case/ad/include/MelSpectrogram.hpp index 22b5d29..d3ea3f7 100644 --- a/source/use_case/ad/include/MelSpectrogram.hpp +++ b/source/use_case/ad/include/MelSpectrogram.hpp @@ -65,16 +65,16 @@ namespace audio { /** * @brief Extract Mel Spectrogram for one single small frame of * audio data e.g. 640 samples. - * @param[in] audioData - Vector of audio samples to calculate + * @param[in] audioData Vector of audio samples to calculate * features for. - * @param[in] trainingMean - Value to subtract from the the computed mel spectrogram, default 0. + * @param[in] trainingMean Value to subtract from the the computed mel spectrogram, default 0. * @return Vector of extracted Mel Spectrogram features. **/ std::vector ComputeMelSpec(const std::vector& audioData, float trainingMean = 0); /** * @brief Constructor - * @param[in] params - Mel Spectrogram parameters + * @param[in] params Mel Spectrogram parameters */ explicit MelSpectrogram(const MelSpecParams& params); @@ -87,10 +87,11 @@ namespace audio { /** * @brief Extract Mel Spectrogram features and quantise for one single small * frame of audio data e.g. 640 samples. - * @param[in] audioData - Vector of audio samples to calculate + * @param[in] audioData Vector of audio samples to calculate * features for. - * @param[in] quantScale - quantisation scale. - * @param[in] quantOffset - quantisation offset + * @param[in] quantScale quantisation scale. + * @param[in] quantOffset quantisation offset. + * @param[in] trainingMean training mean. * @return Vector of extracted quantised Mel Spectrogram features. **/ template @@ -103,12 +104,12 @@ namespace audio { float minVal = std::numeric_limits::min(); float maxVal = std::numeric_limits::max(); - std::vector melSpecOut(this->_m_params.m_numFbankBins); - const size_t numFbankBins = this->_m_params.m_numFbankBins; + std::vector melSpecOut(this->m_params.m_numFbankBins); + const size_t numFbankBins = this->m_params.m_numFbankBins; /* Quantize to T. */ for (size_t k = 0; k < numFbankBins; ++k) { - auto quantizedEnergy = std::round(((this->_m_melEnergies[k]) / quantScale) + quantOffset); + auto quantizedEnergy = std::round(((this->m_melEnergies[k]) / quantScale) + quantOffset); melSpecOut[k] = static_cast(std::min(std::max(quantizedEnergy, minVal), maxVal)); } @@ -124,9 +125,9 @@ namespace audio { protected: /** * @brief Project input frequency to Mel Scale. - * @param[in] freq - input frequency in floating point - * @param[in] useHTKmethod - bool to signal if HTK method is to be - * used for calculation + * @param[in] freq input frequency in floating point + * @param[in] useHTKMethod bool to signal if HTK method is to be + * used for calculation * @return Mel transformed frequency in floating point **/ static float MelScale(const float freq, @@ -135,9 +136,9 @@ namespace audio { /** * @brief Inverse Mel transform - convert MEL warped frequency * back to normal frequency - * @param[in] freq - Mel frequency in floating point - * @param[in] useHTKmethod - bool to signal if HTK method is to be - * used for calculation + * @param[in] melFreq Mel frequency in floating point + * @param[in] useHTKMethod bool to signal if HTK method is to be + * used for calculation * @return Real world frequency in floating point **/ static float InverseMelScale(const float melFreq, @@ -168,7 +169,7 @@ namespace audio { /** * @brief Converts the Mel energies for logarithmic scale - * @param[in/out] melEnergies - 1D vector of Mel energies + * @param[in,out] melEnergies 1D vector of Mel energies **/ virtual void ConvertToLogarithmicScale(std::vector& melEnergies); @@ -176,10 +177,10 @@ namespace audio { * @brief Given the low and high Mel values, get the normaliser * for weights to be applied when populating the filter * bank. - * @param[in] leftMel - low Mel frequency value - * @param[in] rightMel - high Mel frequency value - * @param[in] useHTKMethod - bool to signal if HTK method is to be - * used for calculation + * @param[in] leftMel low Mel frequency value + * @param[in] rightMel high Mel frequency value + * @param[in] useHTKMethod bool to signal if HTK method is to be + * used for calculation * @return Return float value to be applied * when populating the filter bank. */ @@ -189,16 +190,16 @@ namespace audio { const bool useHTKMethod); private: - MelSpecParams _m_params; - std::vector _m_frame; - std::vector _m_buffer; - std::vector _m_melEnergies; - std::vector _m_windowFunc; - std::vector> _m_melFilterBank; - std::vector _m_filterBankFilterFirst; - std::vector _m_filterBankFilterLast; - bool _m_filterBankInitialised; - arm::app::math::FftInstance _m_fftInstance; + MelSpecParams m_params; + std::vector m_frame; + std::vector m_buffer; + std::vector m_melEnergies; + std::vector m_windowFunc; + std::vector> m_melFilterBank; + std::vector m_filterBankFilterFirst; + std::vector m_filterBankFilterLast; + bool m_filterBankInitialised; + arm::app::math::FftInstance m_fftInstance; /** * @brief Initialises the filter banks. diff --git a/source/use_case/ad/src/AdModel.cc b/source/use_case/ad/src/AdModel.cc index 148bc98..82ad822 100644 --- a/source/use_case/ad/src/AdModel.cc +++ b/source/use_case/ad/src/AdModel.cc @@ -20,19 +20,19 @@ const tflite::MicroOpResolver& arm::app::AdModel::GetOpResolver() { - return this->_m_opResolver; + return this->m_opResolver; } bool arm::app::AdModel::EnlistOperations() { - this->_m_opResolver.AddAveragePool2D(); - this->_m_opResolver.AddConv2D(); - this->_m_opResolver.AddDepthwiseConv2D(); - this->_m_opResolver.AddRelu6(); - this->_m_opResolver.AddReshape(); + this->m_opResolver.AddAveragePool2D(); + this->m_opResolver.AddConv2D(); + this->m_opResolver.AddDepthwiseConv2D(); + this->m_opResolver.AddRelu6(); + this->m_opResolver.AddReshape(); #if defined(ARM_NPU) - if (kTfLiteOk == this->_m_opResolver.AddEthosU()) { + if (kTfLiteOk == this->m_opResolver.AddEthosU()) { info("Added %s support to op resolver\n", tflite::GetString_ETHOSU()); } else { diff --git a/source/use_case/ad/src/MelSpectrogram.cc b/source/use_case/ad/src/MelSpectrogram.cc index f1752e1..fa7714a 100644 --- a/source/use_case/ad/src/MelSpectrogram.cc +++ b/source/use_case/ad/src/MelSpectrogram.cc @@ -61,27 +61,27 @@ namespace audio { } MelSpectrogram::MelSpectrogram(const MelSpecParams& params): - _m_params(params), - _m_filterBankInitialised(false) + m_params(params), + m_filterBankInitialised(false) { - this->_m_buffer = std::vector( - this->_m_params.m_frameLenPadded, 0.0); - this->_m_frame = std::vector( - this->_m_params.m_frameLenPadded, 0.0); - this->_m_melEnergies = std::vector( - this->_m_params.m_numFbankBins, 0.0); + this->m_buffer = std::vector( + this->m_params.m_frameLenPadded, 0.0); + this->m_frame = std::vector( + this->m_params.m_frameLenPadded, 0.0); + this->m_melEnergies = std::vector( + this->m_params.m_numFbankBins, 0.0); - this->_m_windowFunc = std::vector(this->_m_params.m_frameLen); - const auto multiplier = static_cast(2 * M_PI / this->_m_params.m_frameLen); + this->m_windowFunc = std::vector(this->m_params.m_frameLen); + const auto multiplier = static_cast(2 * M_PI / this->m_params.m_frameLen); /* Create window function. */ - for (size_t i = 0; i < this->_m_params.m_frameLen; ++i) { - this->_m_windowFunc[i] = (0.5 - (0.5 * + for (size_t i = 0; i < this->m_params.m_frameLen; ++i) { + this->m_windowFunc[i] = (0.5 - (0.5 * math::MathUtils::CosineF32(static_cast(i) * multiplier))); } - math::MathUtils::FftInitF32(this->_m_params.m_frameLenPadded, this->_m_fftInstance); - debug("Instantiated Mel Spectrogram object: %s\n", this->_m_params.Str().c_str()); + math::MathUtils::FftInitF32(this->m_params.m_frameLenPadded, this->m_fftInstance); + debug("Instantiated Mel Spectrogram object: %s\n", this->m_params.Str().c_str()); } void MelSpectrogram::Init() @@ -161,20 +161,20 @@ namespace audio { void MelSpectrogram::ConvertToPowerSpectrum() { - const uint32_t halfDim = this->_m_buffer.size() / 2; + const uint32_t halfDim = this->m_buffer.size() / 2; /* Handle this special case. */ - float firstEnergy = this->_m_buffer[0] * this->_m_buffer[0]; - float lastEnergy = this->_m_buffer[1] * this->_m_buffer[1]; + float firstEnergy = this->m_buffer[0] * this->m_buffer[0]; + float lastEnergy = this->m_buffer[1] * this->m_buffer[1]; math::MathUtils::ComplexMagnitudeSquaredF32( - this->_m_buffer.data(), - this->_m_buffer.size(), - this->_m_buffer.data(), - this->_m_buffer.size()/2); + this->m_buffer.data(), + this->m_buffer.size(), + this->m_buffer.data(), + this->m_buffer.size()/2); - this->_m_buffer[0] = firstEnergy; - this->_m_buffer[halfDim] = lastEnergy; + this->m_buffer[0] = firstEnergy; + this->m_buffer[halfDim] = lastEnergy; } float MelSpectrogram::GetMelFilterBankNormaliser( @@ -193,14 +193,14 @@ namespace audio { void MelSpectrogram::InitMelFilterBank() { if (!this->IsMelFilterBankInited()) { - this->_m_melFilterBank = this->CreateMelFilterBank(); - this->_m_filterBankInitialised = true; + this->m_melFilterBank = this->CreateMelFilterBank(); + this->m_filterBankInitialised = true; } } bool MelSpectrogram::IsMelFilterBankInited() const { - return this->_m_filterBankInitialised; + return this->m_filterBankInitialised; } std::vector MelSpectrogram::ComputeMelSpec(const std::vector& audioData, float trainingMean) @@ -209,64 +209,64 @@ namespace audio { /* TensorFlow way of normalizing .wav data to (-1, 1). */ constexpr float normaliser = 1.0/(1<<15); - for (size_t i = 0; i < this->_m_params.m_frameLen; ++i) { - this->_m_frame[i] = static_cast(audioData[i]) * normaliser; + for (size_t i = 0; i < this->m_params.m_frameLen; ++i) { + this->m_frame[i] = static_cast(audioData[i]) * normaliser; } /* Apply window function to input frame. */ - for(size_t i = 0; i < this->_m_params.m_frameLen; ++i) { - this->_m_frame[i] *= this->_m_windowFunc[i]; + for(size_t i = 0; i < this->m_params.m_frameLen; ++i) { + this->m_frame[i] *= this->m_windowFunc[i]; } /* Set remaining frame values to 0. */ - std::fill(this->_m_frame.begin() + this->_m_params.m_frameLen,this->_m_frame.end(), 0); + std::fill(this->m_frame.begin() + this->m_params.m_frameLen,this->m_frame.end(), 0); /* Compute FFT. */ - math::MathUtils::FftF32(this->_m_frame, this->_m_buffer, this->_m_fftInstance); + math::MathUtils::FftF32(this->m_frame, this->m_buffer, this->m_fftInstance); /* Convert to power spectrum. */ this->ConvertToPowerSpectrum(); /* Apply mel filterbanks. */ - if (!this->ApplyMelFilterBank(this->_m_buffer, - this->_m_melFilterBank, - this->_m_filterBankFilterFirst, - this->_m_filterBankFilterLast, - this->_m_melEnergies)) { + if (!this->ApplyMelFilterBank(this->m_buffer, + this->m_melFilterBank, + this->m_filterBankFilterFirst, + this->m_filterBankFilterLast, + this->m_melEnergies)) { printf_err("Failed to apply MEL filter banks\n"); } /* Convert to logarithmic scale */ - this->ConvertToLogarithmicScale(this->_m_melEnergies); + this->ConvertToLogarithmicScale(this->m_melEnergies); /* Perform mean subtraction. */ - for (auto& energy:this->_m_melEnergies) { + for (auto& energy:this->m_melEnergies) { energy -= trainingMean; } - return this->_m_melEnergies; + return this->m_melEnergies; } std::vector> MelSpectrogram::CreateMelFilterBank() { - size_t numFftBins = this->_m_params.m_frameLenPadded / 2; - float fftBinWidth = static_cast(this->_m_params.m_samplingFreq) / this->_m_params.m_frameLenPadded; + size_t numFftBins = this->m_params.m_frameLenPadded / 2; + float fftBinWidth = static_cast(this->m_params.m_samplingFreq) / this->m_params.m_frameLenPadded; - float melLowFreq = MelSpectrogram::MelScale(this->_m_params.m_melLoFreq, - this->_m_params.m_useHtkMethod); - float melHighFreq = MelSpectrogram::MelScale(this->_m_params.m_melHiFreq, - this->_m_params.m_useHtkMethod); - float melFreqDelta = (melHighFreq - melLowFreq) / (this->_m_params.m_numFbankBins + 1); + float melLowFreq = MelSpectrogram::MelScale(this->m_params.m_melLoFreq, + this->m_params.m_useHtkMethod); + float melHighFreq = MelSpectrogram::MelScale(this->m_params.m_melHiFreq, + this->m_params.m_useHtkMethod); + float melFreqDelta = (melHighFreq - melLowFreq) / (this->m_params.m_numFbankBins + 1); std::vector thisBin = std::vector(numFftBins); std::vector> melFilterBank( - this->_m_params.m_numFbankBins); - this->_m_filterBankFilterFirst = - std::vector(this->_m_params.m_numFbankBins); - this->_m_filterBankFilterLast = - std::vector(this->_m_params.m_numFbankBins); + this->m_params.m_numFbankBins); + this->m_filterBankFilterFirst = + std::vector(this->m_params.m_numFbankBins); + this->m_filterBankFilterLast = + std::vector(this->m_params.m_numFbankBins); - for (size_t bin = 0; bin < this->_m_params.m_numFbankBins; bin++) { + for (size_t bin = 0; bin < this->m_params.m_numFbankBins; bin++) { float leftMel = melLowFreq + bin * melFreqDelta; float centerMel = melLowFreq + (bin + 1) * melFreqDelta; float rightMel = melLowFreq + (bin + 2) * melFreqDelta; @@ -274,11 +274,11 @@ namespace audio { uint32_t firstIndex = 0; uint32_t lastIndex = 0; bool firstIndexFound = false; - const float normaliser = this->GetMelFilterBankNormaliser(leftMel, rightMel, this->_m_params.m_useHtkMethod); + const float normaliser = this->GetMelFilterBankNormaliser(leftMel, rightMel, this->m_params.m_useHtkMethod); for (size_t i = 0; i < numFftBins; ++i) { float freq = (fftBinWidth * i); /* Center freq of this fft bin. */ - float mel = MelSpectrogram::MelScale(freq, this->_m_params.m_useHtkMethod); + float mel = MelSpectrogram::MelScale(freq, this->m_params.m_useHtkMethod); thisBin[i] = 0.0; if (mel > leftMel && mel < rightMel) { @@ -298,8 +298,8 @@ namespace audio { } } - this->_m_filterBankFilterFirst[bin] = firstIndex; - this->_m_filterBankFilterLast[bin] = lastIndex; + this->m_filterBankFilterFirst[bin] = firstIndex; + this->m_filterBankFilterLast[bin] = lastIndex; /* Copy the part we care about. */ for (uint32_t i = firstIndex; i <= lastIndex; ++i) { diff --git a/source/use_case/ad/src/UseCaseHandler.cc b/source/use_case/ad/src/UseCaseHandler.cc index 233b0f4..ec35156 100644 --- a/source/use_case/ad/src/UseCaseHandler.cc +++ b/source/use_case/ad/src/UseCaseHandler.cc @@ -30,13 +30,13 @@ namespace app { /** * @brief Helper function to increment current audio clip index - * @param[in/out] ctx pointer to the application context object + * @param[in,out] ctx pointer to the application context object **/ static void IncrementAppCtxClipIdx(ApplicationContext& ctx); /** * @brief Helper function to set the audio clip index - * @param[in/out] ctx pointer to the application context object + * @param[in,out] ctx pointer to the application context object * @param[in] idx value to be set * @return true if index is set, false otherwise **/ @@ -47,7 +47,7 @@ namespace app { * object. * @param[in] platform reference to the hal platform object * @param[in] result average sum of classification results - * @param[in] threhsold if larger than this value we have an anomaly + * @param[in] threshold if larger than this value we have an anomaly * @return true if successful, false otherwise **/ static bool PresentInferenceResult(hal_platform& platform, float result, float threshold); @@ -61,9 +61,10 @@ namespace app { * * Warning: mfcc calculator provided as input must have the same life scope as returned function. * - * @param[in] mfcc MFCC feature calculator. - * @param[in/out] inputTensor Input tensor pointer to store calculated features. - * @param[i] cacheSize Size of the feture vectors cache (number of feature vectors). + * @param[in] melSpec MFCC feature calculator. + * @param[in,out] inputTensor Input tensor pointer to store calculated features. + * @param[in] cacheSize Size of the feture vectors cache (number of feature vectors). + * @param[in] trainingMean Training mean. * @return function function to be called providing audio sample and sliding window index. */ static std::function&, int, bool, size_t, size_t)> -- cgit v1.2.1