blob: e719d91db48009379979805e61cb86526f7059d0 [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>
26#include <flowgraph/ClipToRange.h>
Robert Wud7400832021-12-04 01:11:19 +000027#include <flowgraph/MonoBlend.h>
Phil Burk0127c1b2018-03-29 13:48:06 -070028#include <flowgraph/MonoToMultiConverter.h>
29#include <flowgraph/RampLinear.h>
30
31class AAudioFlowGraph {
32public:
33 /** Connect several modules together to convert from source to sink.
34 * This should only be called once for each instance.
35 *
36 * @param sourceFormat
37 * @param sourceChannelCount
38 * @param sinkFormat
39 * @param sinkChannelCount
40 * @return
41 */
42 aaudio_result_t configure(audio_format_t sourceFormat,
43 int32_t sourceChannelCount,
44 audio_format_t sinkFormat,
Robert Wud7400832021-12-04 01:11:19 +000045 int32_t sinkChannelCount,
46 bool useMonoBlend);
Phil Burk0127c1b2018-03-29 13:48:06 -070047
48 void process(const void *source, void *destination, int32_t numFrames);
49
50 /**
51 * @param volume between 0.0 and 1.0
52 */
53 void setTargetVolume(float volume);
54
55 void setRampLengthInFrames(int32_t numFrames);
56
57private:
Robert Wu057f0832021-12-03 20:41:07 +000058 std::unique_ptr<flowgraph::FlowGraphSourceBuffered> mSource;
Robert Wud7400832021-12-04 01:11:19 +000059 std::unique_ptr<flowgraph::MonoBlend> mMonoBlend;
Robert Wu057f0832021-12-03 20:41:07 +000060 std::unique_ptr<flowgraph::RampLinear> mVolumeRamp;
61 std::unique_ptr<flowgraph::ClipToRange> mClipper;
62 std::unique_ptr<flowgraph::MonoToMultiConverter> mChannelConverter;
63 std::unique_ptr<flowgraph::FlowGraphSink> mSink;
Phil Burk0127c1b2018-03-29 13:48:06 -070064};
65
66
67#endif //ANDROID_AAUDIO_FLOW_GRAPH_H