1 /*
2  * Copyright (C) 2016 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 _AUDIORECORDER_H_
18 #define _AUDIORECORDER_H_
19 
20 #include <SLES/OpenSLES.h>
21 #include <SLES/OpenSLES_Android.h>
22 
23 namespace ndkaudio {
24 
25 class AudioSink;
26 
27 class AudioRecorder {
28  public:
29     AudioRecorder();
30     ~AudioRecorder();
31 
32     void Open(int numChannels, AudioSink* sink);
33     void Close();
34 
35     void RealizeRecorder();
36     void RealizeRoutingProxy();
37 
38     void Start();
39     void Stop();
40 
isRecording()41     inline bool isRecording() {
42         return recording_;
43     }
getSink()44     inline AudioSink* getSink() {
45         return sink_;
46     }
47 
getConfigItf()48     SLAndroidConfigurationItf getConfigItf() {
49         return configItf_;
50     }
51 
52     // public, but don't call directly (called by the OSLES callback)
53     SLresult enqueBuffer();
54 
GetNumBufferSamples()55     int GetNumBufferSamples() {
56         return numBufferSamples_;
57     }
58     float* GetRecordBuffer();
59 
60  private:
61     AudioSink* sink_;
62     bool recording_;
63 
64     int sampleRate_;
65     int numChannels_;
66 
67     int numBufferSamples_;
68 
69     // OpenSL ES stuff
70     // - Engine
71     SLObjectItf engineObj_;
72     SLEngineItf engineItf_;
73 
74     // - Recorder
75     SLObjectItf recorderObj_;
76     SLRecordItf recorderItf_;
77     SLAndroidSimpleBufferQueueItf recBuffQueueItf_;
78     SLAndroidConfigurationItf configItf_;
79 };
80 
81 } // namespace ndkaudio
82 
83 #endif // _AUDIORECORDER_H_
84