From 9c3af3b44ec69698668a2cfcc6ee2957c7e0cd8c Mon Sep 17 00:00:00 2001 From: bailu1992 Date: Fri, 23 Feb 2024 18:30:20 +0800 Subject: [PATCH] =?UTF-8?q?4.1release=E5=88=86=E6=94=AF=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bailu1992 --- frameworks/native/src/native_sensor.cpp | 4 ++++ .../interface/src/sensor_hdi_connection.cpp | 2 +- services/src/sensor_dump.cpp | 4 ++-- .../getactivesensorinfos_fuzzer.cpp | 6 +++++- .../register_fuzzer/register_fuzzer.cpp | 6 +++++- .../resumesensors_fuzzer.cpp | 6 +++++- .../suspendsensors_fuzzer.cpp | 6 +++++- .../unregister_fuzzer/unregister_fuzzer.cpp | 6 +++++- utils/common/src/permission_util.cpp | 4 ++-- .../conversion/include/conversion_fft.h | 4 ++-- .../core/algorithm/conversion/include/fft.h | 3 ++- .../conversion/src/conversion_fft.cpp | 2 +- .../conversion/src/conversion_filter.cpp | 3 ++- .../src/frequency_estimation.cpp | 8 ++++--- .../core/algorithm/onset/include/onset.h | 3 ++- .../core/algorithm/onset/src/onset.cpp | 2 +- .../peak_finder/include/peak_finder.h | 21 ++++++++++++------- .../algorithm/peak_finder/src/peak_finder.cpp | 14 ++++++------- .../native/include/vibration_convert_core.h | 10 +++++---- .../core/native/src/audio_parsing.cpp | 6 ++++-- .../native/src/vibration_convert_core.cpp | 17 +++++++++------ vibration_convert/core/utils/include/utils.h | 16 +++++++++----- vibration_convert/core/utils/src/utils.cpp | 6 +++--- .../interfaces/js/src/vibrator_convert_js.cpp | 4 ++-- .../js/src/vibrator_convert_napi_utils.cpp | 6 ++++-- 25 files changed, 110 insertions(+), 59 deletions(-) diff --git a/frameworks/native/src/native_sensor.cpp b/frameworks/native/src/native_sensor.cpp index bd27c5f4..75023c2b 100644 --- a/frameworks/native/src/native_sensor.cpp +++ b/frameworks/native/src/native_sensor.cpp @@ -76,6 +76,10 @@ Sensor_Result OH_Sensor_GetInfos(Sensor_Info **sensors, uint32_t *count) Sensor_Info **OH_Sensor_CreateInfos(uint32_t count) { + if (count == 0) { + SEN_HILOGD("count is zero"); + return nullptr; + } auto sensors = new Sensor_Info *[count]; for (uint32_t i = 0; i < count; ++i) { sensors[i] = new Sensor_Info(); diff --git a/services/hdi_connection/interface/src/sensor_hdi_connection.cpp b/services/hdi_connection/interface/src/sensor_hdi_connection.cpp index 37e07270..f095b16a 100644 --- a/services/hdi_connection/interface/src/sensor_hdi_connection.cpp +++ b/services/hdi_connection/interface/src/sensor_hdi_connection.cpp @@ -52,7 +52,7 @@ int32_t SensorHdiConnection::ConnectHdi() int32_t ret = ConnectHdiService(); if (ret != ERR_OK) { SEN_HILOGE("Connect hdi service failed, try to connect compatible connection, ret:%{public}d", ret); -#ifdef BUILD_VARIANT_ENG +#ifdef BUILD_VARIANT_ENG iSensorHdiConnection_ = std::make_unique(); ret = ConnectHdiService(); if (ret != ERR_OK) { diff --git a/services/src/sensor_dump.cpp b/services/src/sensor_dump.cpp index 01feacb2..15d75440 100644 --- a/services/src/sensor_dump.cpp +++ b/services/src/sensor_dump.cpp @@ -190,7 +190,7 @@ void SensorDump::DumpHelp(int32_t fd) dprintf(fd, " -l, --list: dump the sensor list\n"); dprintf(fd, " -c, --channel: dump the sensor data channel info\n"); dprintf(fd, " -o, --open: dump the opening sensors\n"); -#ifdef BUILD_VARIANT_ENG +#ifdef BUILD_VARIANT_ENG dprintf(fd, " -d, --data: dump the last 10 packages sensor data\n"); #endif // BUILD_VARIANT_ENG } @@ -251,7 +251,7 @@ bool SensorDump::DumpOpeningSensor(int32_t fd, const std::vector &sensor return true; } -#ifdef BUILD_VARIANT_ENG +#ifdef BUILD_VARIANT_ENG bool SensorDump::DumpSensorData(int32_t fd, ClientInfo &clientInfo) { dprintf(fd, "Last 10 packages sensor data:\n"); diff --git a/test/fuzztest/interfaces/getactivesensorinfos_fuzzer/getactivesensorinfos_fuzzer.cpp b/test/fuzztest/interfaces/getactivesensorinfos_fuzzer/getactivesensorinfos_fuzzer.cpp index 57d545e6..4f12f5b0 100644 --- a/test/fuzztest/interfaces/getactivesensorinfos_fuzzer/getactivesensorinfos_fuzzer.cpp +++ b/test/fuzztest/interfaces/getactivesensorinfos_fuzzer/getactivesensorinfos_fuzzer.cpp @@ -43,7 +43,11 @@ void GetObject(const uint8_t *data, size_t size, T &object) if (objectSize > size) { return; } - memcpy_s(&object, objectSize, data, objectSize); + errno_t ret = memcpy_s(&object, objectSize, data, objectSize); + if (ret != EOK) { + SEN_HILOGE("Copy data failed"); + return; + } } void SetUpTestCase() diff --git a/test/fuzztest/interfaces/register_fuzzer/register_fuzzer.cpp b/test/fuzztest/interfaces/register_fuzzer/register_fuzzer.cpp index 22fd4928..59dd4f8b 100644 --- a/test/fuzztest/interfaces/register_fuzzer/register_fuzzer.cpp +++ b/test/fuzztest/interfaces/register_fuzzer/register_fuzzer.cpp @@ -43,7 +43,11 @@ void GetObject(const uint8_t *data, size_t size, T &object) if (objectSize > size) { return; } - memcpy_s(&object, objectSize, data, objectSize); + errno_t ret = memcpy_s(&object, objectSize, data, objectSize); + if (ret != EOK) { + SEN_HILOGE("Copy data failed"); + return; + } } void SetUpTestCase() diff --git a/test/fuzztest/interfaces/resumesensors_fuzzer/resumesensors_fuzzer.cpp b/test/fuzztest/interfaces/resumesensors_fuzzer/resumesensors_fuzzer.cpp index a924edb5..0529cedf 100644 --- a/test/fuzztest/interfaces/resumesensors_fuzzer/resumesensors_fuzzer.cpp +++ b/test/fuzztest/interfaces/resumesensors_fuzzer/resumesensors_fuzzer.cpp @@ -42,7 +42,11 @@ void GetObject(const uint8_t *data, size_t size, T &object) if (objectSize > size) { return; } - memcpy_s(&object, objectSize, data, objectSize); + errno_t ret = memcpy_s(&object, objectSize, data, objectSize); + if (ret != EOK) { + SEN_HILOGE("Copy data failed"); + return; + } } void SetUpTestCase() diff --git a/test/fuzztest/interfaces/suspendsensors_fuzzer/suspendsensors_fuzzer.cpp b/test/fuzztest/interfaces/suspendsensors_fuzzer/suspendsensors_fuzzer.cpp index 8e459440..f560bf9a 100644 --- a/test/fuzztest/interfaces/suspendsensors_fuzzer/suspendsensors_fuzzer.cpp +++ b/test/fuzztest/interfaces/suspendsensors_fuzzer/suspendsensors_fuzzer.cpp @@ -42,7 +42,11 @@ void GetObject(const uint8_t *data, size_t size, T &object) if (objectSize > size) { return; } - memcpy_s(&object, objectSize, data, objectSize); + errno_t ret = memcpy_s(&object, objectSize, data, objectSize); + if (ret != EOK) { + SEN_HILOGE("Copy data failed"); + return; + } } void SetUpTestCase() diff --git a/test/fuzztest/interfaces/unregister_fuzzer/unregister_fuzzer.cpp b/test/fuzztest/interfaces/unregister_fuzzer/unregister_fuzzer.cpp index 86cdfb7f..2ca1a08d 100644 --- a/test/fuzztest/interfaces/unregister_fuzzer/unregister_fuzzer.cpp +++ b/test/fuzztest/interfaces/unregister_fuzzer/unregister_fuzzer.cpp @@ -43,7 +43,11 @@ void GetObject(const uint8_t *data, size_t size, T &object) if (objectSize > size) { return; } - memcpy_s(&object, objectSize, data, objectSize); + errno_t ret = memcpy_s(&object, objectSize, data, objectSize); + if (ret != EOK) { + SEN_HILOGE("Copy data failed"); + return; + } } void SetUpTestCase() diff --git a/utils/common/src/permission_util.cpp b/utils/common/src/permission_util.cpp index b8424a24..6dccb3f5 100644 --- a/utils/common/src/permission_util.cpp +++ b/utils/common/src/permission_util.cpp @@ -58,8 +58,8 @@ void PermissionUtil::AddPermissionRecord(AccessTokenID tokenID, const std::strin int32_t failCount = status ? 0 : 1; int32_t ret = PrivacyKit::AddPermissionUsedRecord(tokenID, permissionName, successCount, failCount); if (ret != 0) { - SEN_HILOGE("AddPermissionUsedRecord fail, permissionName:%{public}s, successCount:%{public}d, failCount:%{public}d", - permissionName.c_str(), successCount, failCount); + SEN_HILOGE("AddPermissionUsedRecord fail, permissionName:%{public}s, successCount:%{public}d,\ + failCount:%{public}d", permissionName.c_str(), successCount, failCount); } } diff --git a/vibration_convert/core/algorithm/conversion/include/conversion_fft.h b/vibration_convert/core/algorithm/conversion/include/conversion_fft.h index 49f3ee2f..14db4179 100644 --- a/vibration_convert/core/algorithm/conversion/include/conversion_fft.h +++ b/vibration_convert/core/algorithm/conversion/include/conversion_fft.h @@ -300,11 +300,11 @@ private: float averageFrequencyIncrement_ { 0.0F }; // the root-of-two multiplier between averaging bin frequencies /** An array of averages - the energy across the pitch spectrum */ std::shared_ptr averages_ { nullptr }; // the actual averages - std::shared_ptr peaks_ { nullptr }; // peaks of the averages, aka "maxAverages" in other implementations + std::shared_ptr peaks_ { nullptr }; // peaks of the averages, aka "maxAverages" in other implementations std::shared_ptr peakHoldTimes_ { nullptr }; // how long to hold THIS peak meter? decay if == 0 int32_t peakHoldTime_ { 0 }; // how long do we hold peaks? (in fft frames) float peakDecayRate_ { 0.0F }; // how quickly the peaks decay: 0f=instantly .. 1f=not at all - std::shared_ptr spe2avg_ { nullptr }; // the mapping between spectrum[] indices and averages[] indices + std::shared_ptr spe2avg_ { nullptr }; // the mapping between spectrum[] indices and averages[] indices // the fft's log equalizer() is no longer of any use (it would be nonsense to log scale // the spectrum values into log-sized average bins) so here's a quick-and-dirty linear // equalizer instead: diff --git a/vibration_convert/core/algorithm/conversion/include/fft.h b/vibration_convert/core/algorithm/conversion/include/fft.h index 958392d3..6d314370 100644 --- a/vibration_convert/core/algorithm/conversion/include/fft.h +++ b/vibration_convert/core/algorithm/conversion/include/fft.h @@ -37,7 +37,8 @@ struct FftParaAndResult { std::vector imagOut; FftParaAndResult() = default; - explicit FftParaAndResult(int32_t size) { + explicit FftParaAndResult(int32_t size) + { numSamples = size; realIn.resize(size, 0.0F); imagIn.resize(size, 0.0F); diff --git a/vibration_convert/core/algorithm/conversion/src/conversion_fft.cpp b/vibration_convert/core/algorithm/conversion/src/conversion_fft.cpp index 4ef39a0a..9b81d913 100644 --- a/vibration_convert/core/algorithm/conversion/src/conversion_fft.cpp +++ b/vibration_convert/core/algorithm/conversion/src/conversion_fft.cpp @@ -34,7 +34,7 @@ int32_t ConversionFFT::Init(const FFTInputPara &fftPara) if ((fftPara.sampleRate <= 0) || (fftPara.fftSize <= 0 || !(IsPowerOfTwo(static_cast(fftPara.fftSize)))) || (fftPara.hopSize <= 0 || !(IsPowerOfTwo(static_cast(fftPara.hopSize))))) { - SEN_HILOGE("sampleRate:%{public}d,fftSize:%{public}d,hopSize:%{public}d",fftPara.sampleRate, + SEN_HILOGE("sampleRate:%{public}d,fftSize:%{public}d,hopSize:%{public}d", fftPara.sampleRate, fftPara.fftSize, fftPara.hopSize); return Sensors::PARAMETER_ERROR; } diff --git a/vibration_convert/core/algorithm/conversion/src/conversion_filter.cpp b/vibration_convert/core/algorithm/conversion/src/conversion_filter.cpp index 261a9528..faffaff8 100644 --- a/vibration_convert/core/algorithm/conversion/src/conversion_filter.cpp +++ b/vibration_convert/core/algorithm/conversion/src/conversion_filter.cpp @@ -99,7 +99,8 @@ double ConversionFilter::FilterHighResonant(double input, double cutoff, double SEN_HILOGE("pole_ should not be 1.0"); return 0.0; } - double r = (sqrt(2.0) * sqrt(-pow((pole_ - 1.0), F_THREE)) + resonance * (pole_ - 1.0)) / (resonance * (pole_ - 1.0)); + double r = (sqrt(2.0) * sqrt(-pow((pole_ - 1.0), F_THREE)) + resonance * (pole_ - 1.0)) / (resonance * + (pole_ - 1.0)); speed_ = speed_ + (input - pos_) * filterCoefficient_; pos_ = pos_ + speed_; speed_ = speed_ * r; diff --git a/vibration_convert/core/algorithm/frequency_estimation/src/frequency_estimation.cpp b/vibration_convert/core/algorithm/frequency_estimation/src/frequency_estimation.cpp index f9b562a9..06bef208 100644 --- a/vibration_convert/core/algorithm/frequency_estimation/src/frequency_estimation.cpp +++ b/vibration_convert/core/algorithm/frequency_estimation/src/frequency_estimation.cpp @@ -44,8 +44,9 @@ double FrequencyEstimation::Mean(const std::vector &data) return (sumValue / data.size()); } -void FrequencyEstimation::FreqPostProcess(const std::vector &frequencyHz, const std::vector &voiceSegmentFlag, - const std::vector &rmseIntensityNorm, std::vector &freqNorm) +void FrequencyEstimation::FreqPostProcess(const std::vector &frequencyHz, + const std::vector &voiceSegmentFlag, const std::vector &rmseIntensityNorm, + std::vector &freqNorm) { // Processing of effective values for filling in mute positions. std::vector hzTrims; @@ -70,7 +71,8 @@ void FrequencyEstimation::FreqPostProcess(const std::vector &frequencyHz } } -std::vector FrequencyEstimation::GetZeroCrossingRate(const std::vector &data, int32_t frmLength, int32_t hopLength) +std::vector FrequencyEstimation::GetZeroCrossingRate(const std::vector &data, int32_t frmLength, + int32_t hopLength) { if (data.empty() || frmLength <= hopLength) { SEN_HILOGE("data is empty or frmLength is less than hopLength"); diff --git a/vibration_convert/core/algorithm/onset/include/onset.h b/vibration_convert/core/algorithm/onset/include/onset.h index e4ad6ad1..d390a8cb 100644 --- a/vibration_convert/core/algorithm/onset/include/onset.h +++ b/vibration_convert/core/algorithm/onset/include/onset.h @@ -35,7 +35,8 @@ struct OnsetInfo { std::vector envelopes; std::vector idxs; std::vector times; - void Clear() { + void Clear() + { backTrackFlag = false; envelopes.clear(); idxs.clear(); diff --git a/vibration_convert/core/algorithm/onset/src/onset.cpp b/vibration_convert/core/algorithm/onset/src/onset.cpp index 1d6d07a5..33871cdb 100644 --- a/vibration_convert/core/algorithm/onset/src/onset.cpp +++ b/vibration_convert/core/algorithm/onset/src/onset.cpp @@ -180,7 +180,7 @@ int32_t Onset::CheckOnset(const std::vector &data, int32_t nFft, int32_t if ((data.size() < ONSET_HOP_LEN) || (nFft == 0) || (hopLength == 0)) { SEN_HILOGE("Invalid parameter, data:%{public}zu, nFft:%{public}d, hopLength:%{public}d", data.size(), nFft, hopLength); - return Sensors::PARAMETER_ERROR;; + return Sensors::PARAMETER_ERROR; } std::vector magnitudes; int32_t sfftFrmCount; diff --git a/vibration_convert/core/algorithm/peak_finder/include/peak_finder.h b/vibration_convert/core/algorithm/peak_finder/include/peak_finder.h index 811f54e2..dda87b86 100644 --- a/vibration_convert/core/algorithm/peak_finder/include/peak_finder.h +++ b/vibration_convert/core/algorithm/peak_finder/include/peak_finder.h @@ -93,7 +93,8 @@ struct DownwardTrendInfo { double ducyCycle { 0.0 }; DownwardTrendInfo() = default; - DownwardTrendInfo(bool isDecay, double drop, double cycle) { + DownwardTrendInfo(bool isDecay, double drop, double cycle) + { isRapidlyDecay = isDecay; dropHeight = drop; ducyCycle = cycle; @@ -108,7 +109,8 @@ public: * 2. Like heartbeat. wav, the secondary peak point is not from the lowest point and must be removed * * @param envelope Envelope curve of the peak point to be searched. - * @param peakThreshold If the peak drop is less than 'peakThreshold', it is considered not the peak. Value range 0~1.0. + * @param peakThreshold If the peak drop is less than 'peakThreshold', it is considered not the peak. Value range + * 0~1.0. * @return Return the index of peaks. */ std::vector DetectPeak(const std::vector &envelope, double peakThreshold); @@ -140,11 +142,14 @@ private: double lowerAmp, MountainPosition &mountainPosition); bool FindPeakBoundary(const std::vector &data, int32_t peakPlace, double threshold, BothSidesOfPeak &bothSides); - std::vector PeakFilterMinRange(const std::vector &data, std::vector &peaks, int32_t minSampleCount); - std::vector FilterLowPeak(const std::vector &envelope, const std::vector &peaks, double removeRatio); - std::vector SplitVoiceSlienceRange(int32_t dataSize,const std::vector &envelopeStart, + std::vector PeakFilterMinRange(const std::vector &data, std::vector &peaks, + int32_t minSampleCount); + std::vector FilterLowPeak(const std::vector &envelope, const std::vector &peaks, + double removeRatio); + std::vector SplitVoiceSlienceRange(int32_t dataSize, const std::vector &envelopeStart, const std::vector &envelopeLast); - std::vector FilterSecondaryPeak(const std::vector &envelope, const std::vector &peaks, double lowerAmp); + std::vector FilterSecondaryPeak(const std::vector &envelope, const std::vector &peaks, + double lowerAmp); int32_t DeletePeaks(const std::vector &envelope, int32_t startPos, int32_t endPos, MountainPosition &mountainPosition, int32_t &index); int32_t DetectValley(const std::vector &envelope, int32_t startPos, int32_t endPos, @@ -170,8 +175,8 @@ private: * @param lastPos Last positions. * @param envelopeList Output continuous Long or Short Envelope Results. */ - void SplitLongShortEnvelope(int32_t dataSize, const std::vector &firstPos, const std::vector &lastPos, - EnvelopeSegmentInfo &envelopeList); + void SplitLongShortEnvelope(int32_t dataSize, const std::vector &firstPos, + const std::vector &lastPos, EnvelopeSegmentInfo &envelopeList); int32_t GetIsolatedEnvelope(const std::vector &data, const std::vector &peaks, double lowerAmp, IsolatedEnvelopeInfo &isolatedEnvelopeInfo); // Descending energy diff --git a/vibration_convert/core/algorithm/peak_finder/src/peak_finder.cpp b/vibration_convert/core/algorithm/peak_finder/src/peak_finder.cpp index 6dd3e397..e421d220 100644 --- a/vibration_convert/core/algorithm/peak_finder/src/peak_finder.cpp +++ b/vibration_convert/core/algorithm/peak_finder/src/peak_finder.cpp @@ -79,7 +79,7 @@ std::vector PeakFinder::GetVoiceFlag(const std::vector &data, cons } lowerAmp = *max_element(peakAmp.begin(), peakAmp.end()) * INTERSITY_BOUNDARY_POINT; if (peakAmp.size() > 2) { - lowerAmp = peakAmp[static_cast(peakAmp.size() * INTERSITY_NUMBER_BOUNDARY_POINT )]; + lowerAmp = peakAmp[static_cast(peakAmp.size() * INTERSITY_NUMBER_BOUNDARY_POINT)]; } std::vector triangularEnvelope(data.size(), 0.0); for (size_t i = 0; i < data.size(); i++) { @@ -129,7 +129,7 @@ std::vector PeakFinder::SplitVoiceSlienceRange(int32_t dataSize, const std vioceFlag[boundary] = true; } } - for (int32_t i = 0; i < dataSize; ) { + for (int32_t i = 0; i < dataSize;) { if (vioceFlag[i]) { int32_t j = i / hopLength_; segmentFlag[j] = true; @@ -436,7 +436,7 @@ std::vector PeakFinder::DetectPeak(const std::vector &envelope, } std::vector gradientEnvelope; for (size_t i = 0; i < (envelope.size() - 1); i++) { - gradientEnvelope.push_back(envelope[i+1] - envelope[i]); + gradientEnvelope.push_back(envelope[i+1] - envelope[i]); } if (gradientEnvelope.empty()) { SEN_HILOGE("gradientEnvelope is empty"); @@ -455,7 +455,7 @@ std::vector PeakFinder::DetectPeak(const std::vector &envelope, } if (peakThreshold < EPS_MIN) { for (size_t j = 0; j < (gradientEnvelope.size() - 1); j++) { - if((gradientEnvelope[j] > 0) && (gradientEnvelope[j+1] < 0)) { + if ((gradientEnvelope[j] > 0) && (gradientEnvelope[j+1] < 0)) { peaks.push_back(j+1); } } @@ -557,7 +557,7 @@ int32_t PeakFinder::GetPeakEnvelope(const std::vector &data, int32_t sam peakDetection.ampPeakTimes.push_back(peakDetection.ampPeakIdxs[i] * coef); } return Sensors::SUCCESS; - } +} // Estimating the downward trend of isolated short events. // A descent height of less than 0.03 at 100 points indicates a slow descent. @@ -656,8 +656,8 @@ void PeakFinder::SplitLongShortEnvelope(int32_t dataSize, const std::vector &data, const std::vector &peaks, double lowerAmp, - IsolatedEnvelopeInfo &isolatedEnvelopeInfo) +int32_t PeakFinder::GetIsolatedEnvelope(const std::vector &data, const std::vector &peaks, + double lowerAmp, IsolatedEnvelopeInfo &isolatedEnvelopeInfo) { std::vector triangularEnvelope(data.size(), 0.0); for (size_t i = 0; i < data.size(); i++) { diff --git a/vibration_convert/core/native/include/vibration_convert_core.h b/vibration_convert/core/native/include/vibration_convert_core.h index 2acbd671..9e2d2c46 100644 --- a/vibration_convert/core/native/include/vibration_convert_core.h +++ b/vibration_convert/core/native/include/vibration_convert_core.h @@ -62,8 +62,8 @@ struct ContinuousEvent { int32_t intensity { 0 }; int32_t frequency { 0 }; - ContinuousEvent(double time, double duration, int32_t intensity, int32_t frequency) : time(time), duration(duration), - intensity(intensity), frequency(frequency) {} + ContinuousEvent(double time, double duration, int32_t intensity, int32_t frequency) : time(time), + duration(duration), intensity(intensity), frequency(frequency) {} }; struct TransientEvent { @@ -146,7 +146,8 @@ private: void TranslateAnchorPoint(int32_t amplitudePeakPos, int32_t &litudePeakIdx, double &litudePeakTime); int32_t DetectRmsIntensity(const std::vector &datas, double rmsILowerDelta, std::vector &intensityDatas); - std::vector DetectFrequency(const std::vector &datas, const std::vector &rmseIntensityNorms); + std::vector DetectFrequency(const std::vector &datas, + const std::vector &rmseIntensityNorms); std::vector StartTimeNormalize(int32_t rmseLen); private: @@ -181,7 +182,8 @@ private: void StoreHapticEvent(); void StoreEventSequence(); void StoreEventBlock(); - void CombinateContinuousEvents(const std::vector &continuousEvents, int32_t startIdx, int32_t endIdx); + void CombinateContinuousEvents(const std::vector &continuousEvents, int32_t startIdx, + int32_t endIdx); /** * Using transient events instead of onse */ diff --git a/vibration_convert/core/native/src/audio_parsing.cpp b/vibration_convert/core/native/src/audio_parsing.cpp index 1abf1d8b..2b8d3a8c 100644 --- a/vibration_convert/core/native/src/audio_parsing.cpp +++ b/vibration_convert/core/native/src/audio_parsing.cpp @@ -180,11 +180,13 @@ int32_t AudioParsing::ConvertAudioToHaptic(const AudioSetting &audioSetting, std { CALL_LOG_ENTER; if (audioData_.audioDatas.size() < MIN_SAMPLE_COUNT) { - SEN_HILOGE("audioDatas less then MIN_SAMPLE_COUNT, audioDatas.size():%{public}zu", audioData_.audioDatas.size()); + SEN_HILOGE("audioDatas less then MIN_SAMPLE_COUNT, audioDatas.size():%{public}zu", + audioData_.audioDatas.size()); return Sensors::ERROR; } VibrationConvertCore vibrationConvertCore; - if (vibrationConvertCore.ConvertAudioToHaptic(audioSetting, audioData_.audioDatas, hapticEvents) != Sensors::SUCCESS) { + if (vibrationConvertCore.ConvertAudioToHaptic(audioSetting, audioData_.audioDatas, hapticEvents) != + Sensors::SUCCESS) { SEN_HILOGE("ConvertAudioToHaptic failed"); return Sensors::ERROR; } diff --git a/vibration_convert/core/native/src/vibration_convert_core.cpp b/vibration_convert/core/native/src/vibration_convert_core.cpp index 89d3a0e2..329f6a48 100644 --- a/vibration_convert/core/native/src/vibration_convert_core.cpp +++ b/vibration_convert/core/native/src/vibration_convert_core.cpp @@ -296,7 +296,7 @@ double VibrationConvertCore::CalcRmsLowerData(size_t dataSize, const std::vector if (newDrwIdxs.size() > 0) { for (int32_t i = 0; i < RMSE_LOWDELTA_ITERATION_TIMES; i++) { int32_t j = newDrwIdxs[0]; - lowerDelta = rmseRange * (RMSE_LOWDELTA_RATIO_HIGH - i * RMSE_LOWDELTA_RATIO_STEP ) + rmseMin; + lowerDelta = rmseRange * (RMSE_LOWDELTA_RATIO_HIGH - i * RMSE_LOWDELTA_RATIO_STEP) + rmseMin; if ((rmses[j] > lowerDelta) || (rmses[j + 1] > lowerDelta)) { break; } @@ -747,6 +747,7 @@ void VibrationConvertCore::GetUnzeroCount(const std::vector &localDatas, ++unzeroCount; } } + sfadf; unzeroDensity = static_cast(unzeroCount) / envelopeSize; } @@ -867,9 +868,11 @@ void VibrationConvertCore::OutputTransientEvents(const std::vector 0) && (std::abs(slope2 - slope1) < slopDelta)) { ++mergeCnt; ++begIdx; diff --git a/vibration_convert/core/utils/include/utils.h b/vibration_convert/core/utils/include/utils.h index 07689309..a612ad46 100644 --- a/vibration_convert/core/utils/include/utils.h +++ b/vibration_convert/core/utils/include/utils.h @@ -22,6 +22,8 @@ #include #include +#include "sensor_log.h" + namespace OHOS { namespace Sensors { namespace { @@ -47,7 +49,7 @@ constexpr double F_THREE = 3.0; constexpr double SAMPLE_IN_MS = 1000.0; constexpr double INTERSITY_BOUNDARY_POINT = 0.25; constexpr double INTERSITY_NUMBER_BOUNDARY_POINT = 0.75; -} // namespace +} // namespace enum WindowType { WND_TYPE_BARTLETT = 1, @@ -55,10 +57,10 @@ enum WindowType { WND_TYPE_HANNING = 3, }; -enum FilterMethod{ - LOW_RESONANT_FILTER = 1, - HIGH_RESONANT_FILTER = 2, - BAND_PASS_FILTER = 3, +enum FilterMethod { + LOW_RESONANT_FILTER = 1, + HIGH_RESONANT_FILTER = 2, + BAND_PASS_FILTER = 3, }; bool IsPowerOfTwo(uint32_t x); @@ -185,6 +187,10 @@ inline bool IsEqual(const T& left, const T& right) template decltype(auto) MakeSharedArray(size_t size) { + if (size == 0) { + SEN_HILOGE("size is zero"); + return nullptr; + } return std::shared_ptr(new T[size], std::default_delete()); } diff --git a/vibration_convert/core/utils/src/utils.cpp b/vibration_convert/core/utils/src/utils.cpp index 65a7d22a..ced01e71 100644 --- a/vibration_convert/core/utils/src/utils.cpp +++ b/vibration_convert/core/utils/src/utils.cpp @@ -33,11 +33,11 @@ namespace OHOS { namespace Sensors { -namespace{ +namespace { constexpr double PERCENTAGE_RANGE = 100.0; constexpr int32_t VOICE_MIN_INTENSITY_NORM = 25; constexpr size_t MAX_SIZE = 26460000; -} // namespace +} // namespace bool IsPowerOfTwo(uint32_t x) { @@ -140,7 +140,7 @@ std::vector NormalizePercentage(const std::vector &values) } std::vector norm; for (size_t i = 0; i < values.size(); i++) { - norm.push_back(static_cast(round((values[i] - minValue) / range * PERCENTAGE_RANGE ))); + norm.push_back(static_cast(round((values[i] - minValue) / range * PERCENTAGE_RANGE))); } return norm; } diff --git a/vibration_convert/interfaces/js/src/vibrator_convert_js.cpp b/vibration_convert/interfaces/js/src/vibrator_convert_js.cpp index 617dec03..b9257125 100644 --- a/vibration_convert/interfaces/js/src/vibrator_convert_js.cpp +++ b/vibration_convert/interfaces/js/src/vibrator_convert_js.cpp @@ -118,7 +118,7 @@ VibratorConvert *VibratorConvert::GetInstance(napi_env env) return nullptr; } return instance; -} +} bool VibratorConvert::ParseParameter(napi_env env, napi_value &value, RawFileDescriptor &fileDescriptor) { @@ -244,7 +244,7 @@ napi_value VibratorConvert::GetAudioData(napi_env env, napi_callback_info info) "napi_create_reference failed"); EmitHapticAsyncCallbackWork(asyncCallbackInfo); return nullptr; - } + } napi_deferred deferred = nullptr; napi_value promise = nullptr; CHKCP((napi_create_promise(env, &deferred, &promise) == napi_ok), "napi_create_promise failed"); diff --git a/vibration_convert/interfaces/js/src/vibrator_convert_napi_utils.cpp b/vibration_convert/interfaces/js/src/vibrator_convert_napi_utils.cpp index d5e86df7..8b6d5d8f 100644 --- a/vibration_convert/interfaces/js/src/vibrator_convert_napi_utils.cpp +++ b/vibration_convert/interfaces/js/src/vibrator_convert_napi_utils.cpp @@ -325,7 +325,8 @@ void EmitHapticAsyncCallbackWork(sptr asyncCallbackInfo) napi_value result[RESULT_LENGTH] = { 0 }; CHKCV((g_convertFuncList.find(asyncCallbackInfo->callbackType) != g_convertFuncList.end()), "Callback type invalid in async work"); - bool state = g_convertFuncList[asyncCallbackInfo->callbackType](env, asyncCallbackInfo, result, RESULT_LENGTH); + bool state = g_convertFuncList[asyncCallbackInfo->callbackType](env, asyncCallbackInfo, result, + RESULT_LENGTH); CHKCV(state, "Create napi data failed in async work"); napi_value callResult = nullptr; CHKCV((napi_call_function(env, nullptr, callback, 2, result, &callResult) == napi_ok), @@ -367,7 +368,8 @@ void EmitHapticPromiseWork(sptr asyncCallbackInfo) napi_value result[RESULT_LENGTH] = { 0 }; CHKCV((g_convertFuncList.find(asyncCallbackInfo->callbackType) != g_convertFuncList.end()), "Callback type invalid in promise"); - bool ret = g_convertFuncList[asyncCallbackInfo->callbackType](env, asyncCallbackInfo, result, RESULT_LENGTH); + bool ret = g_convertFuncList[asyncCallbackInfo->callbackType](env, asyncCallbackInfo, result, + RESULT_LENGTH); CHKCV(ret, "Callback type invalid in promise"); if (asyncCallbackInfo->error.code != SUCCESS) { CHKCV((napi_reject_deferred(env, asyncCallbackInfo->deferred, result[0]) == napi_ok), -- Gitee