From 5f244ea91d0f72c0287b24f796dabf90316e29bc Mon Sep 17 00:00:00 2001 From: "hezhiqiang19@huawei.com" Date: Fri, 19 Jul 2024 13:54:30 +0000 Subject: [PATCH] add volume tool for c call Signed-off-by: hezhiqiang19@huawei.com Change-Id: I80f4464a370b8223ef49300ab607c572cc0bb963 --- .../native/pulseaudio/modules/hdi/BUILD.gn | 2 ++ .../native/pulseaudio/modules/hdi/hdi_sink.c | 1 + .../common/include/volume_tools_c.h | 36 +++++++++++++++++++ .../audio_service/common/src/volume_tools.cpp | 23 +++++++++++- 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 services/audio_service/common/include/volume_tools_c.h diff --git a/frameworks/native/pulseaudio/modules/hdi/BUILD.gn b/frameworks/native/pulseaudio/modules/hdi/BUILD.gn index c3e1bc8437..5a3ea76ba9 100644 --- a/frameworks/native/pulseaudio/modules/hdi/BUILD.gn +++ b/frameworks/native/pulseaudio/modules/hdi/BUILD.gn @@ -36,6 +36,7 @@ config("hdi_config") { "../../../audioeffect/include", "../../../playbackcapturer/include", "../../../../../interfaces/inner_api/native/audiocommon/include", + "../../../../../services/audio_service/common/include", ] cflags = [ @@ -69,6 +70,7 @@ ohos_shared_library("module-hdi-sink") { ] deps = [ + "../../../../../services/audio_service:audio_common", "../../../audioeffect:audio_effect", "../../../audioschedule:audio_schedule", "../../../audioutils:audio_utils", diff --git a/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c b/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c index 5c684cf899..a8a9b3d0a9 100644 --- a/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c +++ b/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c @@ -48,6 +48,7 @@ #include "audio_schedule.h" #include "audio_utils_c.h" #include "audio_hdiadapter_info.h" +#include "volume_tools_c.h" #include "renderer_sink_adapter.h" #include "audio_effect_chain_adapter.h" #include "playback_capturer_adapter.h" diff --git a/services/audio_service/common/include/volume_tools_c.h b/services/audio_service/common/include/volume_tools_c.h new file mode 100644 index 0000000000..637d2d9b03 --- /dev/null +++ b/services/audio_service/common/include/volume_tools_c.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 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. + */ + +#ifndef VOLUME_TOOLS_C_H +#define VOLUME_TOOLS_C_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct AudioRawFormat { + uint32_t format; // should be same with AudioStandard::AudioSampleFormat in audio_stream_info.h + uint32_t channels; // should be same with AudioStandard::AudioChannel in audio_stream_info.h +} AudioRawFormat; + +int32_t ProcessVol(uint8_t *buffer, size_t length, AudioRawFormat rawformat, float volStart, float volEnd); + +#ifdef __cplusplus +} +#endif + +#endif // VOLUME_TOOLS_C_H \ No newline at end of file diff --git a/services/audio_service/common/src/volume_tools.cpp b/services/audio_service/common/src/volume_tools.cpp index 4ded653774..eddd216a22 100644 --- a/services/audio_service/common/src/volume_tools.cpp +++ b/services/audio_service/common/src/volume_tools.cpp @@ -16,6 +16,7 @@ #define LOG_TAG "VolumeTools" #include "volume_tools.h" +#include "volume_tools_c.h" #include "audio_errors.h" #include "audio_log.h" @@ -219,4 +220,24 @@ int32_t VolumeTools::Process(const BufferDesc &buffer, AudioSampleFormat format, return SUCCESS; } } // namespace AudioStandard -} // namespace OHOS \ No newline at end of file +} // namespace OHOS + +#ifdef __cplusplus +extern "C" { +#endif +using namespace OHOS::AudioStandard; + +int32_t ProcessVol(uint8_t *buffer, size_t length, AudioRawFormat rawformat, float volStart, float volEnd) +{ + BufferDesc desc = {0}; + desc.buffer = buffer; + desc.bufLength = length; + desc.dataLength = length; + ChannelVolumes mapVols = VolumeTools::GetChannelVolumes(static_cast(rawformat.channels), volStart, + volEnd); + return VolumeTools::Process(desc, static_cast(rawformat.format), mapVols); +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file -- Gitee