mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-01 02:03:47 +01:00
Android audio: Turns out the initial queue operation queued up too little data anyway (sizeof on dynamic buffer.. sigh).
Anyway like I said, none of this really seems to matter.
This commit is contained in:
1 parent
e69b71b58f
commit
f9bf1f96bd
2 files changed
+28
-21
No files matched your search
@@ -56,7 +56,9 @@ void OpenSLContext::BqPlayerCallback(SLAndroidSimpleBufferQueueItf bq) {
|
||||
ELOG("OpenSL ES: Failed to enqueue! %i %i", renderedFrames, sizeInBytes);
|
||||
}
|
||||
|
||||
curBuffer ^= 1; // Switch buffer
|
||||
curBuffer += 1; // Switch buffer
|
||||
if (curBuffer == NUM_BUFFERS)
|
||||
curBuffer = 0;
|
||||
}
|
||||
|
||||
// create the engine and output mix objects
|
||||
@@ -83,7 +85,7 @@ bool OpenSLContext::Init() {
|
||||
// The constants, such as SL_SAMPLINGRATE_44_1, are just 44100000.
|
||||
SLuint32 sr = (SLuint32)sampleRate * 1000;
|
||||
|
||||
SLDataLocator_AndroidSimpleBufferQueue loc_bufq = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2};
|
||||
SLDataLocator_AndroidSimpleBufferQueue loc_bufq = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, NUM_BUFFERS};
|
||||
SLDataFormat_PCM format_pcm = {
|
||||
SL_DATAFORMAT_PCM,
|
||||
2,
|
||||
@@ -124,21 +126,20 @@ bool OpenSLContext::Init() {
|
||||
result = (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_PLAYING);
|
||||
assert(SL_RESULT_SUCCESS == result);
|
||||
|
||||
// Enqueue two empty buffers.
|
||||
buffer[0] = new short[framesPerBuffer * 2]{};
|
||||
buffer[1] = new short[framesPerBuffer * 2]{};
|
||||
// Allocate and enqueue N empty buffers.
|
||||
for (int i = 0; i < NUM_BUFFERS; i++) {
|
||||
buffer[i] = new short[framesPerBuffer * 2]{};
|
||||
}
|
||||
|
||||
int sizeInBytes = framesPerBuffer * 2 * sizeof(short);
|
||||
for (int i = 0; i < NUM_BUFFERS; i++) {
|
||||
result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, buffer[i], sizeInBytes);
|
||||
if (SL_RESULT_SUCCESS != result) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
curBuffer = 0;
|
||||
result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, buffer[curBuffer], sizeof(buffer[curBuffer]));
|
||||
if (SL_RESULT_SUCCESS != result) {
|
||||
return false;
|
||||
}
|
||||
curBuffer ^= 1;
|
||||
result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, buffer[curBuffer], sizeof(buffer[curBuffer]));
|
||||
if (SL_RESULT_SUCCESS != result) {
|
||||
return false;
|
||||
}
|
||||
curBuffer ^= 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -177,10 +178,11 @@ OpenSLContext::~OpenSLContext() {
|
||||
engineObject = nullptr;
|
||||
engineEngine = nullptr;
|
||||
}
|
||||
delete [] buffer[0];
|
||||
delete [] buffer[1];
|
||||
buffer[0] = nullptr;
|
||||
buffer[1] = nullptr;
|
||||
|
||||
for (int i = 0; i < NUM_BUFFERS; i++) {
|
||||
delete[] buffer[i];
|
||||
buffer[i] = nullptr;
|
||||
}
|
||||
ILOG("OpenSLWrap_Shutdown - finished");
|
||||
}
|
||||
|
||||
@@ -37,10 +37,15 @@ private:
|
||||
SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue = nullptr;
|
||||
SLVolumeItf bqPlayerVolume = nullptr;
|
||||
|
||||
// Should be no reason to need more than two buffers, but make it clear in the code.
|
||||
enum {
|
||||
NUM_BUFFERS = 2,
|
||||
};
|
||||
|
||||
// Double buffering.
|
||||
short *buffer[2]{};
|
||||
short *buffer[NUM_BUFFERS]{};
|
||||
int curBuffer = 0;
|
||||
|
||||
static void bqPlayerCallbackWrap(SLAndroidSimpleBufferQueueItf bq, void *context);
|
||||
void BqPlayerCallback(SLAndroidSimpleBufferQueueItf bq);
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user