blob: 602c17f2457d329e5c4caeaa91f32e293978faf2 [file] [log] [blame]
Phil Burk0127c1b2018-03-29 13:48:06 -07001/*
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 Wu8393bed2021-12-08 02:08:48 +000026#include <audio_utils/Balance.h>
Phil Burk0127c1b2018-03-29 13:48:06 -070027#include <flowgraph/ClipToRange.h>
Robert Wu8393bed2021-12-08 02:08:48 +000028#include <flowgraph/ManyToMultiConverter.h>
Robert Wud7400832021-12-04 01:11:19 +000029#include <flowgraph/MonoBlend.h>
Phil Burk0127c1b2018-03-29 13:48:06 -070030#include <flowgraph/MonoToMultiConverter.h>
Robert Wu8393bed2021-12-08 02:08:48 +000031#include <flowgraph/MultiToManyConverter.h>
Phil Burk0127c1b2018-03-29 13:48:06 -070032#include <flowgraph/RampLinear.h>
33
34class AAudioFlowGraph {
35public:
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 Wu8393bed2021-12-08 02:08:48 +000043 * @param useMonoBlend
44 * @param audioBalance
45 * @param channelMask
Robert Wub7e30fa2021-12-09 01:00:16 +000046 * @param isExclusive
Phil Burk0127c1b2018-03-29 13:48:06 -070047 * @return
48 */
49 aaudio_result_t configure(audio_format_t sourceFormat,
50 int32_t sourceChannelCount,
51 audio_format_t sinkFormat,
Robert Wud7400832021-12-04 01:11:19 +000052 int32_t sinkChannelCount,
Robert Wu8393bed2021-12-08 02:08:48 +000053 bool useMonoBlend,
Robert Wub7e30fa2021-12-09 01:00:16 +000054 float audioBalance,
55 bool isExclusive);
Phil Burk0127c1b2018-03-29 13:48:06 -070056
57 void process(const void *source, void *destination, int32_t numFrames);
58
59 /**
60 * @param volume between 0.0 and 1.0
61 */
62 void setTargetVolume(float volume);
63
Robert Wu8393bed2021-12-08 02:08:48 +000064 /**
65 * @param audioBalance between -1.0 and 1.0
66 */
67 void setAudioBalance(float audioBalance);
68
69 /**
70 * @param numFrames to slowly adjust for volume changes
71 */
Phil Burk0127c1b2018-03-29 13:48:06 -070072 void setRampLengthInFrames(int32_t numFrames);
73
74private:
Robert Wuedc850a2022-04-05 16:47:03 +000075 std::unique_ptr<FLOWGRAPH_OUTER_NAMESPACE::flowgraph::FlowGraphSourceBuffered> mSource;
76 std::unique_ptr<FLOWGRAPH_OUTER_NAMESPACE::flowgraph::MonoBlend> mMonoBlend;
77 std::unique_ptr<FLOWGRAPH_OUTER_NAMESPACE::flowgraph::ClipToRange> mClipper;
78 std::unique_ptr<FLOWGRAPH_OUTER_NAMESPACE::flowgraph::MonoToMultiConverter> mChannelConverter;
79 std::unique_ptr<FLOWGRAPH_OUTER_NAMESPACE::flowgraph::ManyToMultiConverter>
80 mManyToMultiConverter;
81 std::unique_ptr<FLOWGRAPH_OUTER_NAMESPACE::flowgraph::MultiToManyConverter>
82 mMultiToManyConverter;
83 std::vector<std::unique_ptr<FLOWGRAPH_OUTER_NAMESPACE::flowgraph::RampLinear>> mVolumeRamps;
84 std::vector<float> mPanningVolumes;
85 float mTargetVolume = 1.0f;
86 android::audio_utils::Balance mBalance;
87 std::unique_ptr<FLOWGRAPH_OUTER_NAMESPACE::flowgraph::FlowGraphSink> mSink;
Phil Burk0127c1b2018-03-29 13:48:06 -070088};
89
90
91#endif //ANDROID_AAUDIO_FLOW_GRAPH_H