1 /* 2 * Copyright (c) 2023 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_SPEED_H 16 #define AUDIO_SPEED_H 17 18 #include <cstdint> 19 #include <string> 20 21 #include "sonic.h" 22 #include "audio_info.h" 23 namespace OHOS { 24 namespace AudioStandard { 25 26 class AudioSpeed { 27 public: 28 AudioSpeed(); 29 AudioSpeed(size_t rate, size_t format, size_t channels); 30 31 ~AudioSpeed(); 32 int32_t Init(); 33 int32_t LoadChangeSpeedFunc(); 34 int32_t SetSpeed(float speed); 35 float GetSpeed(); 36 37 int32_t ChangeSpeedFor8Bit(uint8_t *buffer, int32_t bufferSize, 38 std::unique_ptr<uint8_t []> &outBuffer, int32_t &outBufferSize); 39 int32_t ChangeSpeedFor16Bit(uint8_t *buffer, int32_t bufferSize, 40 std::unique_ptr<uint8_t []> &outBuffer, int32_t &outBufferSize); 41 int32_t ChangeSpeedFor24Bit(uint8_t *buffer, int32_t bufferSize, 42 std::unique_ptr<uint8_t []> &outBuffer, int32_t &outBufferSize); 43 int32_t ChangeSpeedFor32Bit(uint8_t *buffer, int32_t bufferSize, 44 std::unique_ptr<uint8_t []> &outBuffer, int32_t &outBufferSize); 45 int32_t ChangeSpeedForFloat(float *buffer, int32_t bufferSize, float* outBuffer, int32_t &outBufferSize); 46 47 std::function<int32_t(uint8_t *, int32_t, std::unique_ptr<uint8_t []>&, int32_t&)> ChangeSpeedFunc; 48 49 int32_t ChangeSpeed(uint8_t *buffer, int32_t bufferSize, 50 std::unique_ptr<uint8_t []> &outBuffer, int32_t &outBufferSize); 51 private: 52 float speed_ = 0.0f; 53 size_t rate_; 54 size_t format_; 55 56 std::unique_ptr<uint8_t[]> speedBuffer_ = nullptr; 57 int32_t speedBufferSize_ = 0; 58 AudioStreamParams streamParam_; 59 size_t formatSize_ = 1; 60 size_t channels_ = 2; 61 sonicStream sonicStream_ = nullptr; 62 }; 63 } // namespace AudioStandard 64 } // namespace OHOS 65 #endif // AUDIO_SPEED_H