forked from mcanthony/audioIO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SuperpoweredAndroidAudioIO.h
83 lines (68 loc) · 3.58 KB
/
SuperpoweredAndroidAudioIO.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
Copyright 2015 Superpowered Inc.
http://www.superpowered.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef Header_SuperpoweredAndroidAudioIO
#define Header_SuperpoweredAndroidAudioIO
struct SuperpoweredAndroidAudioIOInternals;
/**
@brief This is the prototype of an audio processing callback function.
If the application requires both audio input and audio output, this callback is called once (there is no separate audio input and audio output callback). Audio input is available in audioIO, and the application should change it's contents for audio output.
@param clientdata A custom pointer your callback receives.
@param audioIO 16-bit stereo interleaved audio input and/or output.
@param numberOfSamples The number of samples received and/or requested.
@param samplerate The current sample rate in Hz.
*/
typedef bool (*audioProcessingCallback) (void *clientdata, short int *audioIO, int numberOfSamples, int samplerate);
/**
@brief Easy handling of OpenSL ES audio input and/or output.
*/
class SuperpoweredAndroidAudioIO {
public:
/**
@brief Creates an audio I/O instance. Audio input and/or output immediately starts after calling this.
@param samplerate The requested sample rate in Hz.
@param buffersize The requested buffer size (number of samples).
@param enableInput Enable audio input.
@param enableOutput Enable audio output.
@param callback The audio processing callback function to call periodically.
@param clientdata A custom pointer the callback receives.
@param inputStreamType OpenSL ES stream type, such as SL_ANDROID_RECORDING_PRESET_GENERIC. -1 means default. SLES/OpenSLES_AndroidConfiguration.h has them.
@param outputStreamType OpenSL ES stream type, such as SL_ANDROID_STREAM_MEDIA or SL_ANDROID_STREAM_VOICE. -1 means default. SLES/OpenSLES_AndroidConfiguration.h has them.
@param latencySamples How many samples to have in the internal fifo buffer minimum. Works only when both input and output are enabled. Might help if you have many dropouts.
*/
SuperpoweredAndroidAudioIO(int samplerate, int buffersize, bool enableInput, bool enableOutput, audioProcessingCallback callback, void *clientdata, int inputStreamType = -1, int outputStreamType = -1, int latencySamples = 0);
~SuperpoweredAndroidAudioIO();
/*
@brief Call this in the main activity's onResume() method.
Calling this is important if you'd like to save battery. When there is no audio playing and the app goes to the background, it will automatically stop audio input and/or output.
*/
void onForeground();
/*
@brief Call this in the main activity's onPause() method.
Calling this is important if you'd like to save battery. When there is no audio playing and the app goes to the background, it will automatically stop audio input and/or output.
*/
void onBackground();
/*
@brief Starts audio input and/or output.
*/
void start();
/*
@brief Stops audio input and/or output.
*/
void stop();
private:
SuperpoweredAndroidAudioIOInternals *internals;
SuperpoweredAndroidAudioIO(const SuperpoweredAndroidAudioIO&);
SuperpoweredAndroidAudioIO& operator=(const SuperpoweredAndroidAudioIO&);
};
#endif