iOS: Reduce CPU consumption for audio, adjust sync.

Still is clicking...
This commit is contained in:
Unknown W. Brackets 2013-03-16 14:00:41 -07:00
parent 947f838165
commit e8ac8d49b6
3 changed files with 24 additions and 6 deletions

View File

@ -273,5 +273,5 @@ int __AudioMix(short *outstereo, int numFrames)
// DEBUG_LOG(HLE, "No underrun, mixed %i samples fine", numFrames);
}
section.unlock();
return numFrames;
return underrun;
}

View File

@ -149,6 +149,13 @@ void NativeMix(short *audio, int num_samples)
}
}
int NativeMixCount(short *audio, int num_samples)
{
if (g_mixer)
return g_mixer->Mix(audio, num_samples);
return 0;
}
void NativeGetAppInfo(std::string *app_dir_name, std::string *app_nice_name, bool *landscape)
{
*app_nice_name = "PPSSPP";

View File

@ -16,10 +16,10 @@
static volatile BOOL done = 0;
#define SAMPLE_SIZE 44100/6
#define SAMPLE_SIZE 44100
static short stream[SAMPLE_SIZE];
void NativeMix(short *audio, int num_samples);
int NativeMixCount(short *audio, int num_samples);
@interface AudioEngine ()
@ -122,15 +122,26 @@ void NativeMix(short *audio, int num_samples);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
while (!done)
{
size_t frames_ready;
if (![self playing])
frames_ready = NativeMixCount(stream, SAMPLE_SIZE / 2);
else
frames_ready = 0;
if (frames_ready > 0)
{
NativeMix(stream, SAMPLE_SIZE/2);
const size_t bytes_ready = frames_ready * sizeof(short) * 2;
alSourcei(source, AL_BUFFER, 0);
alBufferData(buffer, AL_FORMAT_STEREO16, stream, SAMPLE_SIZE, 44100);
alBufferData(buffer, AL_FORMAT_STEREO16, stream, bytes_ready, 44100);
alSourcei(source, AL_BUFFER, buffer);
alSourcePlay(source);
// TODO: Maybe this could get behind?
usleep((1000000 * frames_ready) / 44100);
}
else
usleep(100);
pthread_yield_np();
}
});
}