1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef AUDIO_PRORESAMPLER_H 16 #define AUDIO_PRORESAMPLER_H 17 18 #include "resampler.h" 19 #include "audio_proresampler_process.h" 20 #include <vector> 21 #include <string> 22 namespace OHOS { 23 namespace AudioStandard { 24 namespace HPAE { 25 class ProResampler : public Resampler { 26 public: 27 ProResampler(uint32_t inRate, uint32_t outRate, uint32_t channels, uint32_t quality); 28 ~ProResampler() override; 29 // disable deep copy, enable move semantics to manage memory allocated by C malloc 30 ProResampler(const ProResampler &) = delete; 31 ProResampler &operator=(const ProResampler &) = delete; 32 ProResampler(ProResampler &&) noexcept; 33 ProResampler &operator=(ProResampler &&) noexcept; 34 void Reset() override; 35 int32_t Process(const float *inBuffer, uint32_t inFrameSize, float *outBuffer, uint32_t outFrameSize) 36 override; 37 int32_t UpdateRates(uint32_t inRate, uint32_t outRate) override; 38 int32_t UpdateChannels(uint32_t channels) override; 39 uint32_t GetInRate() const override; 40 uint32_t GetOutRate() const override; 41 uint32_t GetChannels() const override; 42 uint32_t GetQuality() const; 43 private: 44 int32_t Process11025SampleRate(const float *inBuffer, uint32_t inFrameSize, float *outBuffer, 45 uint32_t outFrameSize); 46 int32_t ProcessOtherSampleRate(const float *inBuffer, uint32_t inFrameSize, float *outBuffer, 47 uint32_t outFrameSize); 48 std::string ErrCodeToString(int32_t errCode); 49 std::vector<float> buf11025_; 50 uint32_t buf11025Index_ = 0; 51 uint32_t inRate_; 52 uint32_t outRate_; 53 uint32_t channels_; 54 uint32_t quality_; 55 uint32_t expectedOutFrameLen_; 56 uint32_t expectedInFrameLen_; 57 SingleStagePolyphaseResamplerState* state_ = nullptr; 58 }; 59 } // HPAE 60 } // AudioStandard 61 } // OHOS 62 #endif