From f00ad397c405b6b0ee869361d375389fbcec81eb Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Fri, 8 Dec 2023 08:26:12 +0000 Subject: [PATCH] Audio frequency rotary vibration-22 Signed-off-by: hellohyh001 Change-Id: Ife8a35bb67f18e8d9f4af95456872103f320a2b0 --- bundle.json | 4 +- frameworks/js/napi/BUILD.gn | 10 +++- frameworks/js/napi/src/sensor_js.cpp | 18 ++++++ utils/common/BUILD.gn | 6 ++ vibration_convert/core/BUILD.gn | 59 +++++++++++++++++++ .../conversion/src/conversion_fft.cpp | 2 +- .../conversion/src/conversion_mfcc.cpp | 2 +- .../core/algorithm/conversion/src/fft.cpp | 2 +- .../src/frequency_estimation.cpp | 2 +- .../src/intensity_processor.cpp | 2 +- .../core/algorithm/onset/src/onset.cpp | 2 +- .../algorithm/peak_finder/src/peak_finder.cpp | 2 +- .../core/native/src/audio_parsing.cpp | 4 +- .../src/generate_vibration_json_file.cpp | 2 +- .../native/src/vibration_convert_core.cpp | 2 +- vibration_convert/core/native/test/BUILD.gn | 59 +++++++++++++++++++ .../test/unittest/generate_json_test.cpp | 2 +- .../core/utils/include/audio_utils.h | 2 +- .../core/utils/src/audio_utils.cpp | 2 +- vibration_convert/core/utils/src/utils.cpp | 2 +- .../js/include/vibrator_convert_napi_utils.h | 2 +- 21 files changed, 170 insertions(+), 18 deletions(-) create mode 100644 vibration_convert/core/BUILD.gn create mode 100644 vibration_convert/core/native/test/BUILD.gn diff --git a/bundle.json b/bundle.json index c07c2ce8..2e1a9ed1 100755 --- a/bundle.json +++ b/bundle.json @@ -32,7 +32,9 @@ "samgr", "eventhandler" ], - "third_party": [] + "third_party": [ + "jsoncpp" + ] }, "build": { "group_type": { diff --git a/frameworks/js/napi/BUILD.gn b/frameworks/js/napi/BUILD.gn index 06fa4b15..44224e0a 100644 --- a/frameworks/js/napi/BUILD.gn +++ b/frameworks/js/napi/BUILD.gn @@ -22,12 +22,16 @@ ohos_shared_library("libsensor") { "$SUBSYSTEM_DIR/utils/common/include", "//third_party/libuv/include", "//third_party/node/src", + "$SUBSYSTEM_DIR/vibration_convert/core/native/include", + "$SUBSYSTEM_DIR/vibration_convert/interfaces/js/include", ] defines = [ "APP_LOG_TAG = \"sensorJs\"", "LOG_DOMAIN = 0xD002700", ] sources = [ + "$SUBSYSTEM_DIR/vibration_convert/interfaces/js/src/vibrator_convert_js.cpp", + "$SUBSYSTEM_DIR/vibration_convert/interfaces/js/src/vibrator_convert_napi_utils.cpp", "src/sensor_js.cpp", "src/sensor_napi_error.cpp", "src/sensor_napi_utils.cpp", @@ -39,7 +43,11 @@ ohos_shared_library("libsensor") { cfi_cross_dso = true debug = false } - deps = [ "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native" ] + deps = [ + "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", + "${SUBSYSTEM_DIR}/utils/common:libsensor_utils", + "${SUBSYSTEM_DIR}/vibration_convert/core:vibrationconvert_native", + ] external_deps = [ "c_utils:utils", "hilog:libhilog", diff --git a/frameworks/js/napi/src/sensor_js.cpp b/frameworks/js/napi/src/sensor_js.cpp index 5b55d98e..b6de7e71 100644 --- a/frameworks/js/napi/src/sensor_js.cpp +++ b/frameworks/js/napi/src/sensor_js.cpp @@ -29,6 +29,7 @@ #include "sensor_napi_error.h" #include "sensor_napi_utils.h" #include "sensor_system_js.h" +#include "vibrator_convert_js.h" namespace OHOS { namespace Sensors { @@ -1265,8 +1266,24 @@ static napi_value CreateEnumSensorAccuracy(napi_env env, napi_value exports) return exports; } +static napi_value CreateVibratorConvertClass(napi_env env, napi_value exports) +{ + napi_property_descriptor clzDes[] = { + DECLARE_NAPI_FUNCTION("getAudioAttribute", VibratorConvert::GetAudioAttribute), + DECLARE_NAPI_FUNCTION("audioToHaptic", VibratorConvert::ConvertAudioToHaptic), + DECLARE_NAPI_FUNCTION("getAudioData", VibratorConvert::GetAudioData), + }; + napi_value cons { nullptr }; + CHKCP((napi_define_class(env, "VibratorConvert", NAPI_AUTO_LENGTH, VibratorConvert::ConvertAudioToHapticConstructor, + nullptr, sizeof(clzDes) / sizeof(napi_property_descriptor), clzDes, &cons) == napi_ok), "napi_define_class fail"); + CHKCP((napi_set_named_property(env, exports, "VibratorConvert", cons) == napi_ok), "napi_set_named_property fail"); + return exports; +} + static napi_value Init(napi_env env, napi_value exports) { + napi_value instance = VibratorConvert::CreateInstance(env); + CHKPP(instance); napi_property_descriptor desc[] = { DECLARE_NAPI_FUNCTION("on", On), DECLARE_NAPI_FUNCTION("once", Once), @@ -1319,6 +1336,7 @@ static napi_value Init(napi_env env, napi_value exports) }; CHKNRP(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(napi_property_descriptor), desc), "napi_define_properties"); + CHKCP(CreateVibratorConvertClass(env, exports), "Create vibrator convert class fail"); CHKCP(CreateEnumSensorType(env, exports), "Create enum sensor type fail"); CHKCP(CreateEnumSensorId(env, exports), "Create enum sensor id fail"); CHKCP(CreateEnumSensorAccuracy(env, exports), "Create enum sensor accuracy fail"); diff --git a/utils/common/BUILD.gn b/utils/common/BUILD.gn index 2e67dc0a..4bef6b3d 100644 --- a/utils/common/BUILD.gn +++ b/utils/common/BUILD.gn @@ -14,6 +14,10 @@ import("//build/ohos.gni") import("./../../sensor.gni") +config("libsensor_utils_public_config") { + include_dirs = [ "include" ] +} + ohos_shared_library("libsensor_utils") { sources = [ "src/active_info.cpp", @@ -38,6 +42,8 @@ ohos_shared_library("libsensor_utils") { "$SUBSYSTEM_DIR/utils/common/include", ] + public_configs = [ ":libsensor_utils_public_config" ] + external_deps = [ "access_token:libaccesstoken_sdk", "access_token:libprivacy_sdk", diff --git a/vibration_convert/core/BUILD.gn b/vibration_convert/core/BUILD.gn new file mode 100644 index 00000000..27578fae --- /dev/null +++ b/vibration_convert/core/BUILD.gn @@ -0,0 +1,59 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/sensors/sensor/sensor.gni") +import("//build/ohos.gni") + +############################################## +ohos_shared_library("vibrationconvert_native") { + sources = [ + "algorithm/conversion/src/conversion_fft.cpp", + "algorithm/conversion/src/conversion_filter.cpp", + "algorithm/conversion/src/conversion_mfcc.cpp", + "algorithm/conversion/src/fft.cpp", + "algorithm/frequency_estimation/src/frequency_estimation.cpp", + "algorithm/intensity_processor/src/intensity_processor.cpp", + "algorithm/onset/src/onset.cpp", + "algorithm/peak_finder/src/peak_finder.cpp", + "native/src/audio_parsing.cpp", + "native/src/generate_vibration_json_file.cpp", + "native/src/vibration_convert_core.cpp", + "utils/src/audio_utils.cpp", + "utils/src/utils.cpp", + ] + + include_dirs = [ + "native/include", + "algorithm/conversion/include", + "algorithm/frequency_estimation/include", + "algorithm/intensity_processor/include", + "algorithm/onset/include", + "algorithm/peak_finder/include", + "utils/include", + "//third_party/jsoncpp/include", + "$SUBSYSTEM_DIR/vibration_convert/interfaces/native/include", + "$SUBSYSTEM_DIR/utils/common/include", + "$SUBSYSTEM_DIR/utils/include", + ] + deps = [ + "$SUBSYSTEM_DIR/utils/common:libsensor_utils", + "//third_party/jsoncpp:jsoncpp", + ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] + part_name = "sensor" + subsystem_name = "sensors" +} diff --git a/vibration_convert/core/algorithm/conversion/src/conversion_fft.cpp b/vibration_convert/core/algorithm/conversion/src/conversion_fft.cpp index 92939717..c931227b 100644 --- a/vibration_convert/core/algorithm/conversion/src/conversion_fft.cpp +++ b/vibration_convert/core/algorithm/conversion/src/conversion_fft.cpp @@ -15,8 +15,8 @@ #include "conversion_fft.h" +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" #include "utils.h" namespace OHOS { diff --git a/vibration_convert/core/algorithm/conversion/src/conversion_mfcc.cpp b/vibration_convert/core/algorithm/conversion/src/conversion_mfcc.cpp index 72691f40..a4ed864f 100644 --- a/vibration_convert/core/algorithm/conversion/src/conversion_mfcc.cpp +++ b/vibration_convert/core/algorithm/conversion/src/conversion_mfcc.cpp @@ -16,8 +16,8 @@ #include "conversion_mfcc.h" #include "audio_utils.h" +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" #include "utils.h" namespace OHOS { diff --git a/vibration_convert/core/algorithm/conversion/src/fft.cpp b/vibration_convert/core/algorithm/conversion/src/fft.cpp index f57c6609..7b5fed0c 100644 --- a/vibration_convert/core/algorithm/conversion/src/fft.cpp +++ b/vibration_convert/core/algorithm/conversion/src/fft.cpp @@ -21,8 +21,8 @@ #include #include +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" namespace OHOS { namespace Sensors { 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 e2020d00..82830a85 100644 --- a/vibration_convert/core/algorithm/frequency_estimation/src/frequency_estimation.cpp +++ b/vibration_convert/core/algorithm/frequency_estimation/src/frequency_estimation.cpp @@ -19,8 +19,8 @@ #include #include +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" namespace OHOS { namespace Sensors { diff --git a/vibration_convert/core/algorithm/intensity_processor/src/intensity_processor.cpp b/vibration_convert/core/algorithm/intensity_processor/src/intensity_processor.cpp index 406f825d..982cf90c 100644 --- a/vibration_convert/core/algorithm/intensity_processor/src/intensity_processor.cpp +++ b/vibration_convert/core/algorithm/intensity_processor/src/intensity_processor.cpp @@ -16,8 +16,8 @@ #include "intensity_processor.h" #include "audio_utils.h" +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" namespace OHOS { namespace Sensors { diff --git a/vibration_convert/core/algorithm/onset/src/onset.cpp b/vibration_convert/core/algorithm/onset/src/onset.cpp index 5f0d9a3a..16ab2403 100644 --- a/vibration_convert/core/algorithm/onset/src/onset.cpp +++ b/vibration_convert/core/algorithm/onset/src/onset.cpp @@ -21,8 +21,8 @@ #include "conversion_fft.h" #include "conversion_mfcc.h" +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" #include "utils.h" namespace OHOS { 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 b9e0023a..72869210 100644 --- a/vibration_convert/core/algorithm/peak_finder/src/peak_finder.cpp +++ b/vibration_convert/core/algorithm/peak_finder/src/peak_finder.cpp @@ -19,8 +19,8 @@ #include #include +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" #include "utils.h" namespace OHOS { diff --git a/vibration_convert/core/native/src/audio_parsing.cpp b/vibration_convert/core/native/src/audio_parsing.cpp index 1dc57ff0..3717ffaa 100644 --- a/vibration_convert/core/native/src/audio_parsing.cpp +++ b/vibration_convert/core/native/src/audio_parsing.cpp @@ -25,15 +25,15 @@ #include #include "generate_vibration_json_file.h" +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" #include "vibration_convert_core.h" #include "vibration_convert_type.h" namespace OHOS { namespace Sensors { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, Sensors::SENSOR_LOG_DOMAIN, "AudioParsing"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, Sensors::SENSOR_LOG_DOMAIN, "AudioParsing" }; constexpr int32_t MIN_SAMPLE_COUNT = 4096; constexpr uint32_t AUDIO_DATA_CONVERSION_FACTOR = INT32_MAX; constexpr int32_t AUDIO_DATA_MAX_NUMBER = 100000; diff --git a/vibration_convert/core/native/src/generate_vibration_json_file.cpp b/vibration_convert/core/native/src/generate_vibration_json_file.cpp index 6135a008..40f82ca2 100644 --- a/vibration_convert/core/native/src/generate_vibration_json_file.cpp +++ b/vibration_convert/core/native/src/generate_vibration_json_file.cpp @@ -21,8 +21,8 @@ #include "json/json.h" +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" namespace OHOS { namespace Sensors { diff --git a/vibration_convert/core/native/src/vibration_convert_core.cpp b/vibration_convert/core/native/src/vibration_convert_core.cpp index dc08e3cf..a229bdf0 100644 --- a/vibration_convert/core/native/src/vibration_convert_core.cpp +++ b/vibration_convert/core/native/src/vibration_convert_core.cpp @@ -17,8 +17,8 @@ #include #include "generate_vibration_json_file.h" +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" #include "vibration_convert_core.h" namespace OHOS { diff --git a/vibration_convert/core/native/test/BUILD.gn b/vibration_convert/core/native/test/BUILD.gn new file mode 100644 index 00000000..eb5770ad --- /dev/null +++ b/vibration_convert/core/native/test/BUILD.gn @@ -0,0 +1,59 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/sensors/sensor/sensor.gni") +import("//build/test.gni") + +module_output_path = "sensors/sensor/vibration_convert/interfaces" + +###########################GenerateJsonFileTest########################### +ohos_unittest("GenerateJsonFileTest") { + module_out_path = module_output_path + + sources = [ "unittest/generate_json_test.cpp" ] + + include_dirs = [ + "$SUBSYSTEM_DIR/utils/include", + "$SUBSYSTEM_DIR/vibration_convert/interfaces/native/include", + "$SUBSYSTEM_DIR/vibration_convert/core/native/include", + "$SUBSYSTEM_DIR/vibration_convert/core/algorithm/conversion/include", + "$SUBSYSTEM_DIR/vibration_convert/core/algorithm/frequency_estimation/include", + "$SUBSYSTEM_DIR/vibration_convert/core/algorithm/intensity_processor/include", + "$SUBSYSTEM_DIR/vibration_convert/core/algorithm/onset/include", + "$SUBSYSTEM_DIR/vibration_convert/core/algorithm/peak_finder/include", + "$SUBSYSTEM_DIR/utils/common/include", + "$SUBSYSTEM_DIR/vibration_convert/core/utils/include", + ] + + deps = [ + "$SUBSYSTEM_DIR/utils:sensor_utils_target", + "$SUBSYSTEM_DIR/utils/common:libsensor_utils", + "$SUBSYSTEM_DIR/vibration_convert/core:vibrationconvert_native", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + ] +} + +###########################end########################### +group("unittest") { + testonly = true + deps = [ ":GenerateJsonFileTest" ] +} diff --git a/vibration_convert/core/native/test/unittest/generate_json_test.cpp b/vibration_convert/core/native/test/unittest/generate_json_test.cpp index 88735acb..cc74eec9 100644 --- a/vibration_convert/core/native/test/unittest/generate_json_test.cpp +++ b/vibration_convert/core/native/test/unittest/generate_json_test.cpp @@ -20,8 +20,8 @@ #include "audio_utils.h" #include "data.h" #include "generate_vibration_json_file.h" +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" #include "utils.h" #include "vibration_convert_core.h" #include "vibration_convert_type.h" diff --git a/vibration_convert/core/utils/include/audio_utils.h b/vibration_convert/core/utils/include/audio_utils.h index 57e3f681..9f54425c 100644 --- a/vibration_convert/core/utils/include/audio_utils.h +++ b/vibration_convert/core/utils/include/audio_utils.h @@ -104,4 +104,4 @@ public: }; } // namespace Sensors } // namespace OHOS -#endif \ No newline at end of file +#endif // AUDIO_UTILS_H \ No newline at end of file diff --git a/vibration_convert/core/utils/src/audio_utils.cpp b/vibration_convert/core/utils/src/audio_utils.cpp index 428c816a..dc071b40 100644 --- a/vibration_convert/core/utils/src/audio_utils.cpp +++ b/vibration_convert/core/utils/src/audio_utils.cpp @@ -14,7 +14,7 @@ */ #include "audio_utils.h" -#include "sensors_errors.h" +#include "sensor_errors.h" namespace OHOS { namespace Sensors { diff --git a/vibration_convert/core/utils/src/utils.cpp b/vibration_convert/core/utils/src/utils.cpp index 275218cc..36d3f39e 100644 --- a/vibration_convert/core/utils/src/utils.cpp +++ b/vibration_convert/core/utils/src/utils.cpp @@ -25,8 +25,8 @@ #include +#include "sensor_errors.h" #include "sensor_log.h" -#include "sensors_errors.h" namespace OHOS { namespace Sensors { diff --git a/vibration_convert/interfaces/js/include/vibrator_convert_napi_utils.h b/vibration_convert/interfaces/js/include/vibrator_convert_napi_utils.h index 81129bc8..d5eb94c3 100644 --- a/vibration_convert/interfaces/js/include/vibrator_convert_napi_utils.h +++ b/vibration_convert/interfaces/js/include/vibrator_convert_napi_utils.h @@ -26,7 +26,7 @@ #include "napi/native_node_api.h" #include "refbase.h" -#include "sensors_errors.h" +#include "sensor_errors.h" #include "vibration_convert_type.h" namespace OHOS { -- Gitee