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>
26 #include <flowgraph/ClipToRange.h>
27 #include <flowgraph/MonoToMultiConverter.h>
28 #include <flowgraph/RampLinear.h>
29 
30 class AAudioFlowGraph {
31 public:
32     /** Connect several modules together to convert from source to sink.
33      * This should only be called once for each instance.
34      *
35      * @param sourceFormat
36      * @param sourceChannelCount
37      * @param sinkFormat
38      * @param sinkChannelCount
39      * @return
40      */
41     aaudio_result_t configure(audio_format_t sourceFormat,
42                               int32_t sourceChannelCount,
43                               audio_format_t sinkFormat,
44                               int32_t sinkChannelCount);
45 
46     void process(const void *source, void *destination, int32_t numFrames);
47 
48     /**
49      * @param volume between 0.0 and 1.0
50      */
51     void setTargetVolume(float volume);
52 
53     void setRampLengthInFrames(int32_t numFrames);
54 
55 private:
56     std::unique_ptr<flowgraph::AudioSource>          mSource;
57     std::unique_ptr<flowgraph::RampLinear>           mVolumeRamp;
58     std::unique_ptr<flowgraph::ClipToRange>          mClipper;
59     std::unique_ptr<flowgraph::MonoToMultiConverter> mChannelConverter;
60     std::unique_ptr<flowgraph::AudioSink>            mSink;
61 };
62 
63 
64 #endif //ANDROID_AAUDIO_FLOW_GRAPH_H
65