mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-15 15:30:29 +02:00
The Oboe input callback used to call Microphone::addAudioData directly, writing PSP memory from the audio thread. Now it only pushes samples into a SampleRing, and pollRecording drains it on the CPU thread. Starting and stopping still go through Java, which asks for permission. Every host with a microphone polls now, so sceUsbMic drops what only the push path needed: QueueBuf's recursive mutex, restarting the mic on a device change, and the startMic parameter nobody read. Also removes the unused System_AudioRecordingState and Microphone::isNeedInput. The Java microphone_command branch didn't return true, so every command logged "processCommand failed". Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
47 lines
1.7 KiB
C++
47 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <mutex>
|
|
|
|
typedef void (*AndroidAudioCallback)(short *buffer, int numSamples, int sampleRateHz, void *userdata);
|
|
|
|
class AudioContext {
|
|
public:
|
|
AudioContext(AndroidAudioCallback cb, int _FramesPerBuffer, int _SampleRate);
|
|
virtual bool Init() { return false; }
|
|
virtual bool AudioRecord_Start(int sampleRate) { return false; };
|
|
virtual bool AudioRecord_Stop() { return false; };
|
|
|
|
int SampleRate() const { return sampleRate; }
|
|
|
|
virtual ~AudioContext() {}
|
|
|
|
protected:
|
|
static void SetErrorString(const std::string &error);
|
|
AndroidAudioCallback audioCallback;
|
|
|
|
int framesPerBuffer;
|
|
int sampleRate;
|
|
std::mutex errorMutex_;
|
|
};
|
|
|
|
struct AndroidAudioState;
|
|
|
|
// TODO: Get rid of this unnecessary wrapper layer from the old .so days
|
|
|
|
// It's okay for optimalFramesPerBuffer and optimalSampleRate to be 0. Defaults will be used.
|
|
AndroidAudioState *AndroidAudio_Init(AndroidAudioCallback cb, int optimalFramesPerBuffer, int optimalSampleRate);
|
|
bool AndroidAudio_Recording_SetSampleRate(AndroidAudioState *state, int sampleRate);
|
|
bool AndroidAudio_Recording_Start(AndroidAudioState *state);
|
|
bool AndroidAudio_Recording_Stop(AndroidAudioState *state);
|
|
// Microphone input is buffered: the input stream pushes it, and AndroidAudio_Recording_Poll hands it
|
|
// over to Microphone::addAudioData. Poll and Clear are for the CPU thread.
|
|
void AndroidAudio_Recording_Push(const int16_t *samples, int count);
|
|
void AndroidAudio_Recording_Poll();
|
|
void AndroidAudio_Recording_Clear();
|
|
bool AndroidAudio_Pause(AndroidAudioState *state);
|
|
bool AndroidAudio_Resume(AndroidAudioState *state);
|
|
bool AndroidAudio_Shutdown(AndroidAudioState *state);
|
|
const std::string AndroidAudio_GetErrorString(AndroidAudioState *state);
|