2012-07-07 20:58:27 +00:00
|
|
|
#pragma once
|
|
|
|
|
2012-07-07 22:17:59 +00:00
|
|
|
#include <string>
|
2021-06-14 22:23:45 +00:00
|
|
|
#include <mutex>
|
2012-07-08 11:23:30 +00:00
|
|
|
|
2023-03-24 12:59:27 +00:00
|
|
|
typedef int (*AndroidAudioCallback)(short *buffer, int numSamples, int sampleRateHz);
|
2020-07-28 12:22:50 +00:00
|
|
|
|
|
|
|
class AudioContext {
|
|
|
|
public:
|
|
|
|
AudioContext(AndroidAudioCallback cb, int _FramesPerBuffer, int _SampleRate);
|
|
|
|
virtual bool Init() { return false; }
|
2021-06-14 22:23:45 +00:00
|
|
|
virtual bool AudioRecord_Start(int sampleRate) { return false; };
|
|
|
|
virtual bool AudioRecord_Stop() { return false; };
|
|
|
|
|
2023-03-24 12:59:27 +00:00
|
|
|
int SampleRate() const { return sampleRate; }
|
|
|
|
|
2020-07-28 12:22:50 +00:00
|
|
|
virtual ~AudioContext() {}
|
|
|
|
|
|
|
|
protected:
|
2021-06-16 05:28:32 +00:00
|
|
|
void SetErrorString(const std::string &error);
|
2020-07-28 12:22:50 +00:00
|
|
|
AndroidAudioCallback audioCallback;
|
|
|
|
|
|
|
|
int framesPerBuffer;
|
|
|
|
int sampleRate;
|
2021-06-14 22:23:45 +00:00
|
|
|
std::mutex errorMutex_;
|
2020-07-28 12:22:50 +00:00
|
|
|
};
|
|
|
|
|
2017-08-01 13:28:45 +00:00
|
|
|
struct AndroidAudioState;
|
|
|
|
|
2021-06-14 22:23:45 +00:00
|
|
|
// TODO: Get rid of this unnecessary wrapper layer from the old .so days
|
|
|
|
|
2013-06-19 12:27:13 +00:00
|
|
|
// It's okay for optimalFramesPerBuffer and optimalSampleRate to be 0. Defaults will be used.
|
2019-09-17 21:26:42 +00:00
|
|
|
AndroidAudioState *AndroidAudio_Init(AndroidAudioCallback cb, int optimalFramesPerBuffer, int optimalSampleRate);
|
2020-10-24 09:03:43 +00:00
|
|
|
bool AndroidAudio_Recording_SetSampleRate(AndroidAudioState *state, int sampleRate);
|
|
|
|
bool AndroidAudio_Recording_Start(AndroidAudioState *state);
|
2019-08-06 12:20:10 +00:00
|
|
|
bool AndroidAudio_Recording_Stop(AndroidAudioState *state);
|
2020-10-24 10:36:24 +00:00
|
|
|
bool AndroidAudio_Recording_State(AndroidAudioState *state);
|
2017-08-01 13:28:45 +00:00
|
|
|
bool AndroidAudio_Pause(AndroidAudioState *state);
|
|
|
|
bool AndroidAudio_Resume(AndroidAudioState *state);
|
|
|
|
bool AndroidAudio_Shutdown(AndroidAudioState *state);
|
2021-06-14 22:23:45 +00:00
|
|
|
const std::string AndroidAudio_GetErrorString(AndroidAudioState *state);
|