diff --git a/frameworks/native/src/native_sensor.cpp b/frameworks/native/src/native_sensor.cpp index bd27c5f461ec4b85595e951b361cc669264f4328..75023c2b027c5f34d455d852effbd82ed10ace73 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 37e07270b3efdf38acbc1263967b14421e7ef45d..f095b16a5e42ec89fbabc9a09c1fa52576d6133d 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 01feacb2f67d36ec778f5f1ed9bc29605921028c..15d754401adeff6208caff6e3dc9a130c9af6638 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 57d545e6eb12fd609aa0290c912a44aad585c1c2..4f12f5b0f918cc8dd693f586de6a631b597b8bb2 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 22fd492873706604a45c5f20ecbd0e5bad35ccf2..59dd4f8b005eb4162376d750c65560b5378dc953 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 a924edb5eafa5e34df48fa34039b42115fb4e56f..0529cedf1c71d81abd9db46f8bcc761cda28c53f 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 8e459440905af86c4ca3d89a3c4caf71442ec40f..f560bf9a490c8526194b92a3df47f5816175ec16 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 86cdfb7fb219defa04ea3a76a54154ffa131896d..2ca1a08dd048e8bfe5e2e49cdb82f0cf72747770 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 b8424a247a3c4679d835b2b9977c6505f12ad113..6dccb3f51874d60ee0b000fc6bed3ddb71d86f27 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 49f3ee2f16deff1cd58c31c2bf3be0b132484632..14db417929fba50313eab1893e69daec87a0aae1 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 958392d389b2dfe3b3b6ba1311c6f14caf15c98b..6d31437093618e553e2d0ec67aa5b7e0d430e720 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 4ef39a0aa4b70e0e8c2cddc4d34dd0025568d48a..9b81d9131741886a9bc344da98c4303206567794 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 261a95284afd4df761362aca84e7cd93a296e894..faffaff8c028af155dd2d365447932c9761e2c18 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 f9b562a96d447901ad3088e2a615649af7ae97ff..06bef208016276ce25591dd721e531e8dcbe0c85 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 e4ad6ad1213836997b4db7cf6ec9e61139a3b650..d390a8cbb2bc919d412dfdd1241164b3d673e351 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 1d6d07a5f21037cbb00a5852c24ec8615dcef0fc..33871cdb4a614d6703cebc392840aa116dd38fed 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 811f54e2a37cfee1d113c1a573531056a53a9aaf..dda87b861c395774fcb21e8c9e73228779ce476e 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 6dd3e397383238b4c572816ddb38165a17bc4645..e421d220bd6339afb1eee0be5b6cf0daf8cdcf37 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 2acbd671482ccf33eea2579ea4fec694a3ef03d0..9e2d2c46386b53f001df67943c1f8be240167f58 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 1abf1d8bbaa776ffcd05cd27d8125c6e8dfb0340..2b8d3a8c8d7d2a3952fcab747943a0bbcfeee14a 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 89d3a0e2fb11f43700f01a65b982fe88f8967fa9..329f6a4851de8cb488c1b8d93d94f4f1fea8d31c 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 07689309dbbdb69263aa8f7964c13fa343b1778b..a612ad4620df33cbd70cfc7f14bcd2c65bbb564b 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 65a7d22a10a3f0b3572b37822601ff4d5ffeebf3..ced01e712478dda750df2c31fca46d839031289a 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 617dec03aa0d9e5e34a7bc296f00716a9f975025..b9257125e5f372ee103c544f87c5b84c41abf441 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 d5e86df79dfea935d2c0ba05c1cea19b1263463f..8b6d5d8fcfdb9a2b2b6adee61f29ee085d4e430c 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),