From 57681f33ce7cf560923c8d6777502e96adc93bcf Mon Sep 17 00:00:00 2001 From: zyx0106 Date: Fri, 9 May 2025 17:38:12 +0800 Subject: [PATCH 1/9] add channels Signed-off-by: zyx0106 --- .../channel_converter/src/down_mixer.cpp | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/services/audio_engine/plugin/channel_converter/src/down_mixer.cpp b/services/audio_engine/plugin/channel_converter/src/down_mixer.cpp index 3ac3f1500b..09a05605dc 100644 --- a/services/audio_engine/plugin/channel_converter/src/down_mixer.cpp +++ b/services/audio_engine/plugin/channel_converter/src/down_mixer.cpp @@ -78,8 +78,8 @@ static constexpr uint64_t MASK_LFE = LOW_FREQUENCY | LOW_FREQUENCY_2; static uint32_t BitCounts(uint64_t bits); -static bool IsValidChLayout(AudioChannelLayout &chLayout, uint32_t chCounts); -static AudioChannelLayout SetDefaultChannelLayout(AudioChannel channels); +static bool IsValidChLayout(uint64_t &chLayout, uint32_t chCounts); +static uint64_t SetDefaultChannelLayout(AudioChannel channels); // 改成默认构造 DownMixer::DownMixer() @@ -92,8 +92,8 @@ int32_t DownMixer::SetParam(AudioChannelInfo inChannelInfo, AudioChannelInfo out uint32_t formatSize, bool mixLfe) { ResetSelf(); - inLayout_ = inChannelInfo.channelLayout; - outLayout_ = outChannelInfo.channelLayout; + inLayout_ = (uint64_t)inChannelInfo.channelLayout; + outLayout_ = (uint64_t)outChannelInfo.channelLayout; inChannels_ = inChannelInfo.numChannels; outChannels_ = outChannelInfo.numChannels; mixLfe_ = mixLfe; @@ -1050,7 +1050,7 @@ static uint32_t BitCounts(uint64_t bits) return num; } -static bool IsValidChLayout(AudioChannelLayout &chLayout, uint32_t chCounts) +static bool IsValidChLayout(uint64_t &chLayout, uint32_t chCounts) { if (chCounts < MONO || chCounts > CHANNEL_16) { return false; @@ -1061,7 +1061,7 @@ static bool IsValidChLayout(AudioChannelLayout &chLayout, uint32_t chCounts) return true; } -static AudioChannelLayout SetDefaultChannelLayout(AudioChannel channels) +static uint64_t SetDefaultChannelLayout(AudioChannel channels) { if (channels < MONO || channels > CHANNEL_16) { return CH_LAYOUT_UNKNOWN; @@ -1083,12 +1083,20 @@ static AudioChannelLayout SetDefaultChannelLayout(AudioChannel channels) return CH_LAYOUT_6POINT1; case CHANNEL_8: return CH_LAYOUT_5POINT1POINT2; + case CHANNEL_9: + return CH_LAYOUT_5POINT1POINT2 | TOP_FRONT_CENTER; case CHANNEL_10: return CH_LAYOUT_7POINT1POINT2; + case CHANNEL_11: + return CH_LAYOUT_7POINT1POINT2 | TOP_FRONT_CENTER; case CHANNEL_12: return CH_LAYOUT_7POINT1POINT4; + case CHANNEL_13: + return CH_LAYOUT_7POINT1POINT4 | TOP_FRONT_CENTER; case CHANNEL_14: return CH_LAYOUT_9POINT1POINT4; + case CHANNEL_15: + return CH_LAYOUT_9POINT1POINT4 | TOP_FRONT_CENTER; case CHANNEL_16: return CH_LAYOUT_9POINT1POINT6; default: -- Gitee From 6d5ae3787522808a57cd7613e426316dc9fe9edf Mon Sep 17 00:00:00 2001 From: zyx0106 Date: Fri, 9 May 2025 18:31:21 +0800 Subject: [PATCH 2/9] add adapt more channels Signed-off-by: zyx0106 --- .../channel_converter/include/down_mixer.h | 4 +- .../server/src/hpae_renderer_stream_impl.cpp | 40 +------------------ 2 files changed, 3 insertions(+), 41 deletions(-) diff --git a/services/audio_engine/plugin/channel_converter/include/down_mixer.h b/services/audio_engine/plugin/channel_converter/include/down_mixer.h index 63c13350f5..7fbdf22e5a 100644 --- a/services/audio_engine/plugin/channel_converter/include/down_mixer.h +++ b/services/audio_engine/plugin/channel_converter/include/down_mixer.h @@ -46,9 +46,9 @@ public: uint32_t formatSize, bool mixLfe); void Reset(); private: - AudioChannelLayout inLayout_ = CH_LAYOUT_UNKNOWN; + uint64_t inLayout_ = (uint64_t)CH_LAYOUT_UNKNOWN; uint32_t inChannels_ = 0; - AudioChannelLayout outLayout_ = CH_LAYOUT_UNKNOWN; + uint64_t outLayout_ = (uint64_t)CH_LAYOUT_UNKNOWN; uint32_t outChannels_ = 0; uint32_t formatSize_ = INVALID_WIDTH; // work format, for now only supports float std::vector> downMixTable_; diff --git a/services/audio_service/server/src/hpae_renderer_stream_impl.cpp b/services/audio_service/server/src/hpae_renderer_stream_impl.cpp index a7f3f4ddd5..1af7e5c806 100644 --- a/services/audio_service/server/src/hpae_renderer_stream_impl.cpp +++ b/services/audio_service/server/src/hpae_renderer_stream_impl.cpp @@ -39,7 +39,6 @@ namespace AudioStandard { const int32_t MIN_BUFFER_SIZE = 2; const int32_t FRAME_LEN_10MS = 2; const int32_t TENMS_PER_SEC = 100; -static AudioChannelLayout SetDefaultChannelLayout(AudioChannel channels); static std::shared_ptr GetRenderSinkInstance(std::string deviceClass, std::string deviceNetId); HpaeRendererStreamImpl::HpaeRendererStreamImpl(AudioProcessConfig processConfig) { @@ -59,9 +58,7 @@ int32_t HpaeRendererStreamImpl::InitParams(const std::string &deviceName) streamInfo.channels = processConfig_.streamInfo.channels; streamInfo.samplingRate = processConfig_.streamInfo.samplingRate; streamInfo.format = processConfig_.streamInfo.format; - if (processConfig_.streamInfo.channelLayout == CH_LAYOUT_UNKNOWN) { - streamInfo.channelLayout = SetDefaultChannelLayout(streamInfo.channels); - } + streamInfo.channelLayout = processConfig_.streamInfo.channelLayout; streamInfo.frameLen = spanSizeInFrame_; streamInfo.sessionId = processConfig_.originalSessionId; streamInfo.streamType = processConfig_.streamType; @@ -447,41 +444,6 @@ int32_t HpaeRendererStreamImpl::SetClientVolume(float clientVolume) return SUCCESS; } -static AudioChannelLayout SetDefaultChannelLayout(AudioChannel channels) -{ - if (channels < MONO || channels > CHANNEL_16) { - return CH_LAYOUT_UNKNOWN; - } - switch (channels) { - case MONO: - return CH_LAYOUT_MONO; - case STEREO: - return CH_LAYOUT_STEREO; - case CHANNEL_3: - return CH_LAYOUT_SURROUND; - case CHANNEL_4: - return CH_LAYOUT_3POINT1; - case CHANNEL_5: - return CH_LAYOUT_4POINT1; - case CHANNEL_6: - return CH_LAYOUT_5POINT1; - case CHANNEL_7: - return CH_LAYOUT_6POINT1; - case CHANNEL_8: - return CH_LAYOUT_5POINT1POINT2; - case CHANNEL_10: - return CH_LAYOUT_7POINT1POINT2; - case CHANNEL_12: - return CH_LAYOUT_7POINT1POINT4; - case CHANNEL_14: - return CH_LAYOUT_9POINT1POINT4; - case CHANNEL_16: - return CH_LAYOUT_9POINT1POINT6; - default: - return CH_LAYOUT_UNKNOWN; - } -} - static std::shared_ptr GetRenderSinkInstance(std::string deviceClass, std::string deviceNetId) { uint32_t renderId = HDI_INVALID_ID; -- Gitee From 8e673ea9bc134890ea73bf742f3d95104e820fcf Mon Sep 17 00:00:00 2001 From: zyx0106 Date: Mon, 12 May 2025 17:05:58 +0800 Subject: [PATCH 3/9] add more channelLayout definition Signed-off-by: zyx0106 --- .../audiocommon/include/audio_stream_info.h | 8 ++++++++ .../channel_converter/include/down_mixer.h | 4 ++-- .../channel_converter/src/down_mixer.cpp | 20 +++++++++---------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/interfaces/inner_api/native/audiocommon/include/audio_stream_info.h b/interfaces/inner_api/native/audiocommon/include/audio_stream_info.h index e4ba244f56..6ae1961c04 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_stream_info.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_stream_info.h @@ -411,15 +411,23 @@ enum AudioChannelLayout: uint64_t { CH_LAYOUT_5POINT1POINT2 = CH_LAYOUT_5POINT1 | TOP_SIDE_LEFT | TOP_SIDE_RIGHT, CH_LAYOUT_7POINT1_WIDE = CH_LAYOUT_5POINT1 | FRONT_LEFT_OF_CENTER | FRONT_RIGHT_OF_CENTER, CH_LAYOUT_7POINT1_WIDE_BACK = CH_LAYOUT_5POINT1_BACK | FRONT_LEFT_OF_CENTER | FRONT_RIGHT_OF_CENTER, + /** Channel Count: 9*/ + CH_LAYOUT_CHANNEL9 = CH_LAYOUT_5POINT1POINT2 | TOP_FRONT_CENTER, /** Channel count: 10*/ CH_LAYOUT_5POINT1POINT4 = CH_LAYOUT_5POINT1 | TOP_FRONT_LEFT | TOP_FRONT_RIGHT | TOP_BACK_LEFT |TOP_BACK_RIGHT, CH_LAYOUT_7POINT1POINT2 = CH_LAYOUT_7POINT1 | TOP_SIDE_LEFT | TOP_SIDE_RIGHT, + /** Channel count 11*/ + CH_LAYOUT_CHANNEL11 = CH_LAYOUT_7POINT1POINT2 | TOP_FRONT_CENTER, /** Channel count: 12*/ CH_LAYOUT_7POINT1POINT4 = CH_LAYOUT_7POINT1 | TOP_FRONT_LEFT | TOP_FRONT_RIGHT | TOP_BACK_LEFT | TOP_BACK_RIGHT, CH_LAYOUT_10POINT2 = FRONT_LEFT | FRONT_RIGHT | FRONT_CENTER | TOP_FRONT_LEFT | TOP_FRONT_RIGHT | BACK_LEFT | BACK_RIGHT | BACK_CENTER | SIDE_LEFT | SIDE_RIGHT | WIDE_LEFT | WIDE_RIGHT, + /* Channel count 13*/ + CH_LAYOUT_CHANNEL13 = CH_LAYOUT_7POINT1POINT4 | TOP_FRONT_CENTER, /** Channel count: 14*/ CH_LAYOUT_9POINT1POINT4 = CH_LAYOUT_7POINT1POINT4 | WIDE_LEFT | WIDE_RIGHT, + /** Channel count: 15*/ + CH_LAYOUT_CHANNEL15 = CH_LAYOUT_9POINT1POINT4 | TOP_FRONT_CENTER, /** Channel count: 16*/ CH_LAYOUT_9POINT1POINT6 = CH_LAYOUT_9POINT1POINT4 | TOP_SIDE_LEFT | TOP_SIDE_RIGHT, CH_LAYOUT_HEXADECAGONAL = CH_LAYOUT_OCTAGONAL | WIDE_LEFT | WIDE_RIGHT | TOP_BACK_LEFT | TOP_BACK_RIGHT diff --git a/services/audio_engine/plugin/channel_converter/include/down_mixer.h b/services/audio_engine/plugin/channel_converter/include/down_mixer.h index 7fbdf22e5a..63c13350f5 100644 --- a/services/audio_engine/plugin/channel_converter/include/down_mixer.h +++ b/services/audio_engine/plugin/channel_converter/include/down_mixer.h @@ -46,9 +46,9 @@ public: uint32_t formatSize, bool mixLfe); void Reset(); private: - uint64_t inLayout_ = (uint64_t)CH_LAYOUT_UNKNOWN; + AudioChannelLayout inLayout_ = CH_LAYOUT_UNKNOWN; uint32_t inChannels_ = 0; - uint64_t outLayout_ = (uint64_t)CH_LAYOUT_UNKNOWN; + AudioChannelLayout outLayout_ = CH_LAYOUT_UNKNOWN; uint32_t outChannels_ = 0; uint32_t formatSize_ = INVALID_WIDTH; // work format, for now only supports float std::vector> downMixTable_; diff --git a/services/audio_engine/plugin/channel_converter/src/down_mixer.cpp b/services/audio_engine/plugin/channel_converter/src/down_mixer.cpp index 09a05605dc..2bffb41987 100644 --- a/services/audio_engine/plugin/channel_converter/src/down_mixer.cpp +++ b/services/audio_engine/plugin/channel_converter/src/down_mixer.cpp @@ -78,8 +78,8 @@ static constexpr uint64_t MASK_LFE = LOW_FREQUENCY | LOW_FREQUENCY_2; static uint32_t BitCounts(uint64_t bits); -static bool IsValidChLayout(uint64_t &chLayout, uint32_t chCounts); -static uint64_t SetDefaultChannelLayout(AudioChannel channels); +static bool IsValidChLayout(AudioChannelLayout &chLayout, uint32_t chCounts); +static AudioChannelLayout SetDefaultChannelLayout(AudioChannel channels); // 改成默认构造 DownMixer::DownMixer() @@ -92,8 +92,8 @@ int32_t DownMixer::SetParam(AudioChannelInfo inChannelInfo, AudioChannelInfo out uint32_t formatSize, bool mixLfe) { ResetSelf(); - inLayout_ = (uint64_t)inChannelInfo.channelLayout; - outLayout_ = (uint64_t)outChannelInfo.channelLayout; + inLayout_ = inChannelInfo.channelLayout; + outLayout_ = outChannelInfo.channelLayout; inChannels_ = inChannelInfo.numChannels; outChannels_ = outChannelInfo.numChannels; mixLfe_ = mixLfe; @@ -1050,7 +1050,7 @@ static uint32_t BitCounts(uint64_t bits) return num; } -static bool IsValidChLayout(uint64_t &chLayout, uint32_t chCounts) +static bool IsValidChLayout(AudioChannelLayout &chLayout, uint32_t chCounts) { if (chCounts < MONO || chCounts > CHANNEL_16) { return false; @@ -1061,7 +1061,7 @@ static bool IsValidChLayout(uint64_t &chLayout, uint32_t chCounts) return true; } -static uint64_t SetDefaultChannelLayout(AudioChannel channels) +static AudioChannelLayout SetDefaultChannelLayout(AudioChannel channels) { if (channels < MONO || channels > CHANNEL_16) { return CH_LAYOUT_UNKNOWN; @@ -1084,19 +1084,19 @@ static uint64_t SetDefaultChannelLayout(AudioChannel channels) case CHANNEL_8: return CH_LAYOUT_5POINT1POINT2; case CHANNEL_9: - return CH_LAYOUT_5POINT1POINT2 | TOP_FRONT_CENTER; + return CH_LAYOUT_CHANNEL9; case CHANNEL_10: return CH_LAYOUT_7POINT1POINT2; case CHANNEL_11: - return CH_LAYOUT_7POINT1POINT2 | TOP_FRONT_CENTER; + return CH_LAYOUT_CHANNEL11; case CHANNEL_12: return CH_LAYOUT_7POINT1POINT4; case CHANNEL_13: - return CH_LAYOUT_7POINT1POINT4 | TOP_FRONT_CENTER; + return CH_LAYOUT_CHANNEL13; case CHANNEL_14: return CH_LAYOUT_9POINT1POINT4; case CHANNEL_15: - return CH_LAYOUT_9POINT1POINT4 | TOP_FRONT_CENTER; + return CH_LAYOUT_CHANNEL15; case CHANNEL_16: return CH_LAYOUT_9POINT1POINT6; default: -- Gitee From a3c9c383c7d857d21ff61b1fbfa337382c69781f Mon Sep 17 00:00:00 2001 From: zyx0106 Date: Tue, 13 May 2025 11:50:30 +0800 Subject: [PATCH 4/9] use HOA as 9channels layout Signed-off-by: zyx0106 --- .../audiocommon/include/audio_stream_info.h | 8 ------ .../channel_converter/include/down_mixer.h | 1 + .../channel_converter/src/down_mixer.cpp | 27 +++++++++++-------- .../proresampler/audio_proresampler.cpp | 9 +++++-- services/audio_service/BUILD.gn | 5 ++++ .../common/include/limiter/audio_limiter.h | 2 ++ .../common/src/limiter/audio_limiter.cpp | 15 ++++++++++- .../server/src/hpae_renderer_stream_impl.cpp | 4 +++ 8 files changed, 49 insertions(+), 22 deletions(-) diff --git a/interfaces/inner_api/native/audiocommon/include/audio_stream_info.h b/interfaces/inner_api/native/audiocommon/include/audio_stream_info.h index 6ae1961c04..e4ba244f56 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_stream_info.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_stream_info.h @@ -411,23 +411,15 @@ enum AudioChannelLayout: uint64_t { CH_LAYOUT_5POINT1POINT2 = CH_LAYOUT_5POINT1 | TOP_SIDE_LEFT | TOP_SIDE_RIGHT, CH_LAYOUT_7POINT1_WIDE = CH_LAYOUT_5POINT1 | FRONT_LEFT_OF_CENTER | FRONT_RIGHT_OF_CENTER, CH_LAYOUT_7POINT1_WIDE_BACK = CH_LAYOUT_5POINT1_BACK | FRONT_LEFT_OF_CENTER | FRONT_RIGHT_OF_CENTER, - /** Channel Count: 9*/ - CH_LAYOUT_CHANNEL9 = CH_LAYOUT_5POINT1POINT2 | TOP_FRONT_CENTER, /** Channel count: 10*/ CH_LAYOUT_5POINT1POINT4 = CH_LAYOUT_5POINT1 | TOP_FRONT_LEFT | TOP_FRONT_RIGHT | TOP_BACK_LEFT |TOP_BACK_RIGHT, CH_LAYOUT_7POINT1POINT2 = CH_LAYOUT_7POINT1 | TOP_SIDE_LEFT | TOP_SIDE_RIGHT, - /** Channel count 11*/ - CH_LAYOUT_CHANNEL11 = CH_LAYOUT_7POINT1POINT2 | TOP_FRONT_CENTER, /** Channel count: 12*/ CH_LAYOUT_7POINT1POINT4 = CH_LAYOUT_7POINT1 | TOP_FRONT_LEFT | TOP_FRONT_RIGHT | TOP_BACK_LEFT | TOP_BACK_RIGHT, CH_LAYOUT_10POINT2 = FRONT_LEFT | FRONT_RIGHT | FRONT_CENTER | TOP_FRONT_LEFT | TOP_FRONT_RIGHT | BACK_LEFT | BACK_RIGHT | BACK_CENTER | SIDE_LEFT | SIDE_RIGHT | WIDE_LEFT | WIDE_RIGHT, - /* Channel count 13*/ - CH_LAYOUT_CHANNEL13 = CH_LAYOUT_7POINT1POINT4 | TOP_FRONT_CENTER, /** Channel count: 14*/ CH_LAYOUT_9POINT1POINT4 = CH_LAYOUT_7POINT1POINT4 | WIDE_LEFT | WIDE_RIGHT, - /** Channel count: 15*/ - CH_LAYOUT_CHANNEL15 = CH_LAYOUT_9POINT1POINT4 | TOP_FRONT_CENTER, /** Channel count: 16*/ CH_LAYOUT_9POINT1POINT6 = CH_LAYOUT_9POINT1POINT4 | TOP_SIDE_LEFT | TOP_SIDE_RIGHT, CH_LAYOUT_HEXADECAGONAL = CH_LAYOUT_OCTAGONAL | WIDE_LEFT | WIDE_RIGHT | TOP_BACK_LEFT | TOP_BACK_RIGHT diff --git a/services/audio_engine/plugin/channel_converter/include/down_mixer.h b/services/audio_engine/plugin/channel_converter/include/down_mixer.h index 63c13350f5..2faa46befd 100644 --- a/services/audio_engine/plugin/channel_converter/include/down_mixer.h +++ b/services/audio_engine/plugin/channel_converter/include/down_mixer.h @@ -45,6 +45,7 @@ public: int32_t SetParam(AudioChannelInfo inChannelInfo_, AudioChannelInfo outChannelInfo_, uint32_t formatSize, bool mixLfe); void Reset(); + static AudioChannelLayout SetDefaultChannelLayout(AudioChannel channels); private: AudioChannelLayout inLayout_ = CH_LAYOUT_UNKNOWN; uint32_t inChannels_ = 0; diff --git a/services/audio_engine/plugin/channel_converter/src/down_mixer.cpp b/services/audio_engine/plugin/channel_converter/src/down_mixer.cpp index 2bffb41987..b98c792056 100644 --- a/services/audio_engine/plugin/channel_converter/src/down_mixer.cpp +++ b/services/audio_engine/plugin/channel_converter/src/down_mixer.cpp @@ -77,9 +77,13 @@ static constexpr uint64_t MASK_BOTTOM = BOTTOM_FRONT_CENTER static constexpr uint64_t MASK_LFE = LOW_FREQUENCY | LOW_FREQUENCY_2; +static const uint64_t MASK_HOA = + CH_LAYOUT_HOA_ORDER1_ACN_N3D | CH_LAYOUT_HOA_ORDER1_ACN_SN3D | CH_LAYOUT_HOA_ORDER1_FUMA | + CH_LAYOUT_HOA_ORDER2_ACN_N3D | CH_LAYOUT_HOA_ORDER2_ACN_SN3D | CH_LAYOUT_HOA_ORDER2_FUMA | + CH_LAYOUT_HOA_ORDER3_ACN_N3D | CH_LAYOUT_HOA_ORDER3_ACN_SN3D | CH_LAYOUT_HOA_ORDER3_FUMA; + static uint32_t BitCounts(uint64_t bits); static bool IsValidChLayout(AudioChannelLayout &chLayout, uint32_t chCounts); -static AudioChannelLayout SetDefaultChannelLayout(AudioChannel channels); // 改成默认构造 DownMixer::DownMixer() @@ -129,7 +133,14 @@ int32_t DownMixer::Process(uint32_t frameLen, float* in, uint32_t inLen, float* expectInLen, inLen, expectOutLen, outLen); return DMIX_ERR_ALLOC_FAILED; } - AUDIO_DEBUG_LOG("Downmixing: frameLen: %{public}d,", frameLen); + // For HOA, copy the first channel into all output channels + if (inLayout_ & MASK_HOA) { + for (uint32_t i = 0; i < frameLen; i++) { + for (uint32_t c = 0; c < outChannels_; c++) { + out[outChannels_ * i + c] = in[inChannels_ * i]; + } + } + } float a; for (; frameLen > 0; frameLen--) { for (uint32_t i = 0; i < outChannels_; i++) { @@ -1056,12 +1067,12 @@ static bool IsValidChLayout(AudioChannelLayout &chLayout, uint32_t chCounts) return false; } if (chLayout == CH_LAYOUT_UNKNOWN || BitCounts(chLayout) != chCounts) { - chLayout = SetDefaultChannelLayout((AudioChannel)chCounts); + chLayout = DownMixer::SetDefaultChannelLayout((AudioChannel)chCounts); } return true; } -static AudioChannelLayout SetDefaultChannelLayout(AudioChannel channels) +AudioChannelLayout DownMixer::SetDefaultChannelLayout(AudioChannel channels) { if (channels < MONO || channels > CHANNEL_16) { return CH_LAYOUT_UNKNOWN; @@ -1084,19 +1095,13 @@ static AudioChannelLayout SetDefaultChannelLayout(AudioChannel channels) case CHANNEL_8: return CH_LAYOUT_5POINT1POINT2; case CHANNEL_9: - return CH_LAYOUT_CHANNEL9; + return CH_LAYOUT_HOA_ORDER2_ACN_N3D; case CHANNEL_10: return CH_LAYOUT_7POINT1POINT2; - case CHANNEL_11: - return CH_LAYOUT_CHANNEL11; case CHANNEL_12: return CH_LAYOUT_7POINT1POINT4; - case CHANNEL_13: - return CH_LAYOUT_CHANNEL13; case CHANNEL_14: return CH_LAYOUT_9POINT1POINT4; - case CHANNEL_15: - return CH_LAYOUT_CHANNEL15; case CHANNEL_16: return CH_LAYOUT_9POINT1POINT6; default: diff --git a/services/audio_engine/plugin/resample/proresampler/audio_proresampler.cpp b/services/audio_engine/plugin/resample/proresampler/audio_proresampler.cpp index 99d0e0b33b..3ed64c1ccd 100644 --- a/services/audio_engine/plugin/resample/proresampler/audio_proresampler.cpp +++ b/services/audio_engine/plugin/resample/proresampler/audio_proresampler.cpp @@ -49,8 +49,13 @@ int32_t ProResampler::Process(const float *inBuffer, uint32_t *inFrameSize, floa AUDIO_WARNING_LOG("ProResampler process failed with error %{public}s", ErrCodeToString(ret).c_str()); } uint32_t fillZeroSize = expectedOutFrameSize - *outFrameSize > 0 ? expectedOutFrameSize - *outFrameSize : 0; - ret += memset_s(outBuffer, expectedOutFrameSize * channels_ * sizeof(float), 0, - fillZeroSize * channels_ * sizeof(float)); + for (uint32_t i = 0; i < fillZeroSize; i++) { + for (uint32_t c = 0; c < channels_; c++) { + outBuffer[channels_ * i + c] = tmpOutBuf[c]; + } + } + // ret += memset_s(outBuffer, expectedOutFrameSize * channels_ * sizeof(float), 0, + // fillZeroSize * channels_ * sizeof(float)); ret += memcpy_s(outBuffer + fillZeroSize * channels_, (expectedOutFrameSize - fillZeroSize) * channels_ * sizeof(float), tmpOutBuf.data(), *outFrameSize * channels_ * sizeof(float)); diff --git a/services/audio_service/BUILD.gn b/services/audio_service/BUILD.gn index f93bd2aaff..477ef3f861 100644 --- a/services/audio_service/BUILD.gn +++ b/services/audio_service/BUILD.gn @@ -396,6 +396,10 @@ audio_ohos_library("audio_process_service") { } configs = [ ":audio_service_config" ] + + include_dirs = [ + "../../services/audio_engine/plugin/channel_converter/include", + ] deps = [ ":audio_common", @@ -405,6 +409,7 @@ audio_ohos_library("audio_process_service") { "../../frameworks/native/audioutils:audio_utils", "../../frameworks/native/hdiadapter_new:hdiadapter_new", "../audio_engine:audio_engine_manager", + "../audio_engine:audio_engine_plugins", "../audio_policy:audio_foundation", ] diff --git a/services/audio_service/common/include/limiter/audio_limiter.h b/services/audio_service/common/include/limiter/audio_limiter.h index 249bf3a8c6..c4e323e1c1 100644 --- a/services/audio_service/common/include/limiter/audio_limiter.h +++ b/services/audio_service/common/include/limiter/audio_limiter.h @@ -45,6 +45,8 @@ private: float gainAttack_; float gainRelease_; float *bufHis_; + uint32_t sampleRate_; + uint32_t channels_; FILE *dumpFileInput_ = nullptr; FILE *dumpFileOutput_ = nullptr; std::string dumpFileNameIn_ = ""; diff --git a/services/audio_service/common/src/limiter/audio_limiter.cpp b/services/audio_service/common/src/limiter/audio_limiter.cpp index a2a371a7bf..e3aeb904da 100644 --- a/services/audio_service/common/src/limiter/audio_limiter.cpp +++ b/services/audio_service/common/src/limiter/audio_limiter.cpp @@ -83,7 +83,8 @@ int32_t AudioLimiter::SetConfig(int32_t maxRequest, int32_t biteSize, int32_t sa maxRequest, biteSize, sampleRate, channels, algoFrameLen_, latency_); bufHis_ = new (std::nothrow) float[algoFrameLen_](); CHECK_AND_RETURN_RET_LOG(bufHis_ != nullptr, ERROR, "allocate limit algorithm buffer failed"); - + sampleRate_ = sampleRate; + channels_ = channels; dumpFileNameIn_ = std::to_string(sinkIndex_) + "_limiter_in_" + GetTime() + "_" + std::to_string(sampleRate) + "_" + std::to_string(channels) + "_" + std::to_string(format_) + ".pcm"; DumpFileUtil::OpenDumpFile(DumpFileUtil::DUMP_SERVER_PARA, dumpFileNameIn_, &dumpFileInput_); @@ -99,6 +100,18 @@ int32_t AudioLimiter::Process(int32_t frameLen, float *inBuffer, float *outBuffe CHECK_AND_RETURN_RET_LOG(algoFrameLen_ * PROC_COUNT == frameLen, ERROR, "error, algoFrameLen_ = %{public}d, frameLen = %{public}d", algoFrameLen_, frameLen); int32_t ptrIndex = 0; + if (dumpFileInput_ == nullptr) { + dumpFileNameIn_ = std::to_string(sinkIndex_) + "_limiter_in_" + GetTime() + "_" + + std::to_string(sampleRate_) + "_" + std::to_string(channels_) + "_" + std::to_string(format_) + ".pcm"; + DumpFileUtil::OpenDumpFile(DumpFileUtil::DUMP_SERVER_PARA, dumpFileNameIn_, &dumpFileInput_); + AUDIO_DEBUG_LOG("Reopen dump file: %{public}s", dumpFileNameIn_.c_str()); + } + if (dumpFileOutput_ == nullptr) { + dumpFileNameOut_ = std::to_string(sinkIndex_) + "_limiter_out_" + GetTime() + "_" + + std::to_string(sampleRate_) + "_" + std::to_string(channels_) + "_" + std::to_string(format_) + ".pcm"; + DumpFileUtil::OpenDumpFile(DumpFileUtil::DUMP_SERVER_PARA, dumpFileNameOut_, &dumpFileOutput_); + AUDIO_DEBUG_LOG("Reopen dump file: %{public}s", dumpFileNameOut_.c_str()); + } DumpFileUtil::WriteDumpFile(dumpFileInput_, static_cast(inBuffer), frameLen * sizeof(float)); for (int32_t i = 0; i < PROC_COUNT; i++) { ProcessAlgo(algoFrameLen_, inBuffer + ptrIndex, outBuffer + ptrIndex); diff --git a/services/audio_service/server/src/hpae_renderer_stream_impl.cpp b/services/audio_service/server/src/hpae_renderer_stream_impl.cpp index 1af7e5c806..71ca638712 100644 --- a/services/audio_service/server/src/hpae_renderer_stream_impl.cpp +++ b/services/audio_service/server/src/hpae_renderer_stream_impl.cpp @@ -31,6 +31,7 @@ #include "i_hpae_manager.h" #include "audio_stream_info.h" #include "audio_effect_map.h" +#include "down_mixer.h" using namespace OHOS::AudioStandard::HPAE; namespace OHOS { @@ -59,6 +60,9 @@ int32_t HpaeRendererStreamImpl::InitParams(const std::string &deviceName) streamInfo.samplingRate = processConfig_.streamInfo.samplingRate; streamInfo.format = processConfig_.streamInfo.format; streamInfo.channelLayout = processConfig_.streamInfo.channelLayout; + if (channelLayout == CH_LAYOUT_UNKNOWN) { + channelLayout = DownMixer::SetDefaultChannelLayout((AudioChannel)streamInfo.channels); + } streamInfo.frameLen = spanSizeInFrame_; streamInfo.sessionId = processConfig_.originalSessionId; streamInfo.streamType = processConfig_.streamType; -- Gitee From 494057f4462a37c33302cfd4105e08efa186bede Mon Sep 17 00:00:00 2001 From: zyx0106 Date: Tue, 13 May 2025 14:41:37 +0800 Subject: [PATCH 5/9] fix bug Signed-off-by: zyx0106 --- .../audio_engine/plugin/channel_converter/src/down_mixer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/audio_engine/plugin/channel_converter/src/down_mixer.cpp b/services/audio_engine/plugin/channel_converter/src/down_mixer.cpp index b98c792056..a82bf22292 100644 --- a/services/audio_engine/plugin/channel_converter/src/down_mixer.cpp +++ b/services/audio_engine/plugin/channel_converter/src/down_mixer.cpp @@ -140,6 +140,7 @@ int32_t DownMixer::Process(uint32_t frameLen, float* in, uint32_t inLen, float* out[outChannels_ * i + c] = in[inChannels_ * i]; } } + return DMIX_ERR_SUCCESS; } float a; for (; frameLen > 0; frameLen--) { -- Gitee From bed0c5f93a4d3ae19b26f9ff9d1f8df5749a73db Mon Sep 17 00:00:00 2001 From: zyx0106 Date: Tue, 13 May 2025 14:45:15 +0800 Subject: [PATCH 6/9] delete comments Signed-off-by: zyx0106 --- .../plugin/resample/proresampler/audio_proresampler.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/services/audio_engine/plugin/resample/proresampler/audio_proresampler.cpp b/services/audio_engine/plugin/resample/proresampler/audio_proresampler.cpp index 3ed64c1ccd..a67177386d 100644 --- a/services/audio_engine/plugin/resample/proresampler/audio_proresampler.cpp +++ b/services/audio_engine/plugin/resample/proresampler/audio_proresampler.cpp @@ -54,8 +54,6 @@ int32_t ProResampler::Process(const float *inBuffer, uint32_t *inFrameSize, floa outBuffer[channels_ * i + c] = tmpOutBuf[c]; } } - // ret += memset_s(outBuffer, expectedOutFrameSize * channels_ * sizeof(float), 0, - // fillZeroSize * channels_ * sizeof(float)); ret += memcpy_s(outBuffer + fillZeroSize * channels_, (expectedOutFrameSize - fillZeroSize) * channels_ * sizeof(float), tmpOutBuf.data(), *outFrameSize * channels_ * sizeof(float)); -- Gitee From 73be9726ebcbe5b37189a2cb5e306940bb5ff750 Mon Sep 17 00:00:00 2001 From: zyx0106 Date: Tue, 13 May 2025 17:39:25 +0800 Subject: [PATCH 7/9] fix compile bug Signed-off-by: zyx0106 --- .../audio_service/server/src/hpae_renderer_stream_impl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/audio_service/server/src/hpae_renderer_stream_impl.cpp b/services/audio_service/server/src/hpae_renderer_stream_impl.cpp index 71ca638712..eb32290c0f 100644 --- a/services/audio_service/server/src/hpae_renderer_stream_impl.cpp +++ b/services/audio_service/server/src/hpae_renderer_stream_impl.cpp @@ -60,8 +60,8 @@ int32_t HpaeRendererStreamImpl::InitParams(const std::string &deviceName) streamInfo.samplingRate = processConfig_.streamInfo.samplingRate; streamInfo.format = processConfig_.streamInfo.format; streamInfo.channelLayout = processConfig_.streamInfo.channelLayout; - if (channelLayout == CH_LAYOUT_UNKNOWN) { - channelLayout = DownMixer::SetDefaultChannelLayout((AudioChannel)streamInfo.channels); + if (streamInfo.channelLayout == CH_LAYOUT_UNKNOWN) { + streamInfo.channelLayout = DownMixer::SetDefaultChannelLayout((AudioChannel)streamInfo.channels); } streamInfo.frameLen = spanSizeInFrame_; streamInfo.sessionId = processConfig_.originalSessionId; -- Gitee From 9b16d010625e106632a3c44cfadbfa94596bb157 Mon Sep 17 00:00:00 2001 From: zyx0106 Date: Tue, 13 May 2025 20:05:12 +0800 Subject: [PATCH 8/9] fix related UT Signed-off-by: zyx0106 --- services/audio_service/test/unittest/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/services/audio_service/test/unittest/BUILD.gn b/services/audio_service/test/unittest/BUILD.gn index 076dd0189c..16e76c7a1a 100644 --- a/services/audio_service/test/unittest/BUILD.gn +++ b/services/audio_service/test/unittest/BUILD.gn @@ -768,6 +768,7 @@ ohos_unittest("capturer_in_server_unit_test") { "../../../../frameworks/native/audiopolicy/include", "../../../../frameworks/native/audioinnercall/include", "../../../../frameworks/native/audioinnercall/include", + "../../../../services/audio_engine/plugin/channel_converter/include", "../../../../services/audio_service/client/include", "../../../../services/audio_service/common/include", "../../../../services/audio_service/common/include/dfx", -- Gitee From 9c9c97540d97bde68c72f7825f4ea8b800994b4c Mon Sep 17 00:00:00 2001 From: zyx0106 Date: Wed, 14 May 2025 09:21:04 +0800 Subject: [PATCH 9/9] fix tdd compile bug Signed-off-by: zyx0106 --- services/audio_service/test/unittest/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/services/audio_service/test/unittest/BUILD.gn b/services/audio_service/test/unittest/BUILD.gn index 16e76c7a1a..6315d84bfd 100644 --- a/services/audio_service/test/unittest/BUILD.gn +++ b/services/audio_service/test/unittest/BUILD.gn @@ -818,6 +818,7 @@ ohos_unittest("capturer_in_server_unit_test") { "../../../../frameworks/native/audioutils:audio_utils", "../../../../frameworks/native/hdiadapter_new:hdiadapter_new", "../../../../services/audio_engine:audio_engine_manager", + "../../../../services/audio_engine:audio_engine_plugins", "../../../../services/audio_policy:audio_policy_client", "../../../../services/audio_policy:audio_policy_service", "../../../../services/audio_service:audio_client", -- Gitee