diff --git a/frameworks/native/pulseaudio/modules/hdi/BUILD.gn b/frameworks/native/pulseaudio/modules/hdi/BUILD.gn index c3e1bc8437d4f5c6b5f36d6a9a667bf953c60618..5a3ea76ba90477efda61d91826bad64d693891b4 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 5c684cf899677b82d44027087c185e598c3d61fb..a8a9b3d0a931e81fcbe7e710f7d803ff2acc521e 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 0000000000000000000000000000000000000000..637d2d9b03ea3e3e015f67cc987f143cd5c31a96 --- /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 4ded65377496a988b3e6144391f54cf93b75ca8e..eddd216a22337da6b9545602cc1be9bc39fc16f8 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