Files
ppsspp/android/jni/AndroidAudio.h
T
Henrik RydgårdandClaude Opus 5.5 6cf4872e78 Android: Hand microphone input over on the CPU thread, like the other hosts
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>
2026-10-10 18:49:21 +02:00

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);