Phil Burk | 0127c1b | 2018-03-29 13:48:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ANDROID_AAUDIO_FLOW_GRAPH_H |
| 18 | #define ANDROID_AAUDIO_FLOW_GRAPH_H |
| 19 | |
| 20 | #include <memory> |
| 21 | #include <stdint.h> |
| 22 | #include <sys/types.h> |
| 23 | #include <system/audio.h> |
| 24 | |
| 25 | #include <aaudio/AAudio.h> |
Robert Wu | 8393bed | 2021-12-08 02:08:48 +0000 | [diff] [blame^] | 26 | #include <audio_utils/Balance.h> |
Phil Burk | 0127c1b | 2018-03-29 13:48:06 -0700 | [diff] [blame] | 27 | #include <flowgraph/ClipToRange.h> |
Robert Wu | 8393bed | 2021-12-08 02:08:48 +0000 | [diff] [blame^] | 28 | #include <flowgraph/ManyToMultiConverter.h> |
Robert Wu | d740083 | 2021-12-04 01:11:19 +0000 | [diff] [blame] | 29 | #include <flowgraph/MonoBlend.h> |
Phil Burk | 0127c1b | 2018-03-29 13:48:06 -0700 | [diff] [blame] | 30 | #include <flowgraph/MonoToMultiConverter.h> |
Robert Wu | 8393bed | 2021-12-08 02:08:48 +0000 | [diff] [blame^] | 31 | #include <flowgraph/MultiToManyConverter.h> |
Phil Burk | 0127c1b | 2018-03-29 13:48:06 -0700 | [diff] [blame] | 32 | #include <flowgraph/RampLinear.h> |
| 33 | |
| 34 | class AAudioFlowGraph { |
| 35 | public: |
| 36 | /** Connect several modules together to convert from source to sink. |
| 37 | * This should only be called once for each instance. |
| 38 | * |
| 39 | * @param sourceFormat |
| 40 | * @param sourceChannelCount |
| 41 | * @param sinkFormat |
| 42 | * @param sinkChannelCount |
Robert Wu | 8393bed | 2021-12-08 02:08:48 +0000 | [diff] [blame^] | 43 | * @param useMonoBlend |
| 44 | * @param audioBalance |
| 45 | * @param channelMask |
Phil Burk | 0127c1b | 2018-03-29 13:48:06 -0700 | [diff] [blame] | 46 | * @return |
| 47 | */ |
| 48 | aaudio_result_t configure(audio_format_t sourceFormat, |
| 49 | int32_t sourceChannelCount, |
| 50 | audio_format_t sinkFormat, |
Robert Wu | d740083 | 2021-12-04 01:11:19 +0000 | [diff] [blame] | 51 | int32_t sinkChannelCount, |
Robert Wu | 8393bed | 2021-12-08 02:08:48 +0000 | [diff] [blame^] | 52 | bool useMonoBlend, |
| 53 | float audioBalance); |
Phil Burk | 0127c1b | 2018-03-29 13:48:06 -0700 | [diff] [blame] | 54 | |
| 55 | void process(const void *source, void *destination, int32_t numFrames); |
| 56 | |
| 57 | /** |
| 58 | * @param volume between 0.0 and 1.0 |
| 59 | */ |
| 60 | void setTargetVolume(float volume); |
| 61 | |
Robert Wu | 8393bed | 2021-12-08 02:08:48 +0000 | [diff] [blame^] | 62 | /** |
| 63 | * @param audioBalance between -1.0 and 1.0 |
| 64 | */ |
| 65 | void setAudioBalance(float audioBalance); |
| 66 | |
| 67 | /** |
| 68 | * @param numFrames to slowly adjust for volume changes |
| 69 | */ |
Phil Burk | 0127c1b | 2018-03-29 13:48:06 -0700 | [diff] [blame] | 70 | void setRampLengthInFrames(int32_t numFrames); |
| 71 | |
| 72 | private: |
Robert Wu | 057f083 | 2021-12-03 20:41:07 +0000 | [diff] [blame] | 73 | std::unique_ptr<flowgraph::FlowGraphSourceBuffered> mSource; |
Robert Wu | d740083 | 2021-12-04 01:11:19 +0000 | [diff] [blame] | 74 | std::unique_ptr<flowgraph::MonoBlend> mMonoBlend; |
Robert Wu | 057f083 | 2021-12-03 20:41:07 +0000 | [diff] [blame] | 75 | std::unique_ptr<flowgraph::ClipToRange> mClipper; |
| 76 | std::unique_ptr<flowgraph::MonoToMultiConverter> mChannelConverter; |
Robert Wu | 8393bed | 2021-12-08 02:08:48 +0000 | [diff] [blame^] | 77 | std::unique_ptr<flowgraph::ManyToMultiConverter> mManyToMultiConverter; |
| 78 | std::unique_ptr<flowgraph::MultiToManyConverter> mMultiToManyConverter; |
| 79 | std::vector<std::unique_ptr<flowgraph::RampLinear>> mVolumeRamps; |
| 80 | std::vector<float> mPanningVolumes; |
| 81 | float mTargetVolume = 1.0f; |
| 82 | android::audio_utils::Balance mBalance; |
Robert Wu | 057f083 | 2021-12-03 20:41:07 +0000 | [diff] [blame] | 83 | std::unique_ptr<flowgraph::FlowGraphSink> mSink; |
Phil Burk | 0127c1b | 2018-03-29 13:48:06 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | |
| 87 | #endif //ANDROID_AAUDIO_FLOW_GRAPH_H |