CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/android/jni/OpenSLContext.h
Views: 1401
1
#pragma once
2
3
#include <SLES/OpenSLES.h>
4
#include <SLES/OpenSLES_Android.h>
5
6
#include "AndroidAudio.h"
7
8
class OpenSLContext : public AudioContext {
9
public:
10
OpenSLContext(AndroidAudioCallback cb, int framesPerBuffer, int sampleRate);
11
12
bool Init() override;
13
bool AudioRecord_Start(int sampleRate) override;
14
bool AudioRecord_Stop() override;
15
16
~OpenSLContext();
17
18
private:
19
bool CheckResult(SLresult result, const char *str);
20
static bool CheckResultStatic(SLresult result, const char *str);
21
22
// Should be no reason to need more than two buffers, but make it clear in the code.
23
enum {
24
NUM_BUFFERS = 2,
25
};
26
27
// engine interfaces
28
SLObjectItf engineObject = nullptr;
29
SLEngineItf engineEngine = nullptr;
30
SLObjectItf outputMixObject = nullptr;
31
32
// audio recorder interfaces
33
SLObjectItf recorderObject = nullptr;
34
SLRecordItf recorderRecord = nullptr;
35
SLAndroidSimpleBufferQueueItf recorderBufferQueue = nullptr;
36
37
int recordBufferSize = 0;
38
short *recordBuffer[NUM_BUFFERS]{};
39
int activeRecordBuffer = 0;
40
41
static void bqRecorderCallback(SLAndroidSimpleBufferQueueItf bq, void *context);
42
43
// buffer queue player interfaces
44
SLObjectItf bqPlayerObject = nullptr;
45
SLPlayItf bqPlayerPlay = nullptr;
46
SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue = nullptr;
47
SLVolumeItf bqPlayerVolume = nullptr;
48
49
// Double buffering.
50
short *buffer[NUM_BUFFERS]{};
51
int curBuffer = 0;
52
53
static void bqPlayerCallbackWrap(SLAndroidSimpleBufferQueueItf bq, void *context);
54
void BqPlayerCallback(SLAndroidSimpleBufferQueueItf bq);
55
};
56
57