mirror of https://github.com/mgba-emu/mgba.git
GB, GBA Audio: Refactor stream code to do less when no stream is present
This commit is contained in:
parent
3f54bcbc87
commit
2bce03023b
|
@ -822,25 +822,26 @@ static void _sample(struct mTiming* timing, void* user, uint32_t cyclesLate) {
|
|||
GBAudioSample(audio, mTimingCurrentTime(audio->timing));
|
||||
|
||||
mCoreSyncLockAudio(audio->p->sync);
|
||||
unsigned produced;
|
||||
mAudioBufferWrite(&audio->buffer, (int16_t*) audio->currentSamples, GB_MAX_SAMPLES);
|
||||
if (audio->p->stream && audio->p->stream->postAudioFrame) {
|
||||
int i;
|
||||
for (i = 0; i < GB_MAX_SAMPLES; ++i) {
|
||||
audio->p->stream->postAudioFrame(audio->p->stream, audio->currentSamples[i].left,audio->currentSamples[i].right);
|
||||
if (audio->p->stream) {
|
||||
if (audio->p->stream->postAudioFrame) {
|
||||
int i;
|
||||
for (i = 0; i < GB_MAX_SAMPLES; ++i) {
|
||||
audio->p->stream->postAudioFrame(audio->p->stream, audio->currentSamples[i].left,audio->currentSamples[i].right);
|
||||
}
|
||||
}
|
||||
if (audio->p->stream->postAudioBuffer) {
|
||||
unsigned produced = mAudioBufferAvailable(&audio->buffer);
|
||||
bool wait = produced >= audio->samples;
|
||||
if (wait) {
|
||||
audio->p->stream->postAudioBuffer(audio->p->stream, &audio->buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
produced = mAudioBufferAvailable(&audio->buffer);
|
||||
bool wait = produced >= audio->samples;
|
||||
if (!mCoreSyncProduceAudio(audio->p->sync, &audio->buffer)) {
|
||||
// Interrupted
|
||||
audio->p->earlyExit = true;
|
||||
}
|
||||
|
||||
if (wait && audio->p->stream && audio->p->stream->postAudioBuffer) {
|
||||
audio->p->stream->postAudioBuffer(audio->p->stream, &audio->buffer);
|
||||
}
|
||||
mTimingSchedule(timing, &audio->sampleEvent, audio->sampleInterval * audio->timingFactor - cyclesLate);
|
||||
}
|
||||
|
||||
|
|
|
@ -392,25 +392,27 @@ static void _sample(struct mTiming* timing, void* user, uint32_t cyclesLate) {
|
|||
memset(audio->chB.samples, audio->chB.samples[samples - 1], sizeof(audio->chB.samples));
|
||||
|
||||
mCoreSyncLockAudio(audio->p->sync);
|
||||
unsigned produced;
|
||||
mAudioBufferWrite(&audio->psg.buffer, (int16_t*) audio->currentSamples, samples);
|
||||
if (audio->p->stream && audio->p->stream->postAudioFrame) {
|
||||
int i;
|
||||
for (i = 0; i < samples; ++i) {
|
||||
audio->p->stream->postAudioFrame(audio->p->stream, audio->currentSamples[i].left,audio->currentSamples[i].right);
|
||||
if (audio->p->stream) {
|
||||
if (audio->p->stream->postAudioFrame) {
|
||||
int i;
|
||||
for (i = 0; i < samples; ++i) {
|
||||
audio->p->stream->postAudioFrame(audio->p->stream, audio->currentSamples[i].left,audio->currentSamples[i].right);
|
||||
}
|
||||
}
|
||||
if (audio->p->stream->postAudioBuffer) {
|
||||
unsigned produced = mAudioBufferAvailable(&audio->psg.buffer);
|
||||
bool wait = produced >= audio->samples;
|
||||
if (wait) {
|
||||
audio->p->stream->postAudioBuffer(audio->p->stream, &audio->psg.buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
produced = mAudioBufferAvailable(&audio->psg.buffer);
|
||||
bool wait = produced >= audio->samples;
|
||||
if (!mCoreSyncProduceAudio(audio->p->sync, &audio->psg.buffer)) {
|
||||
// Interrupted
|
||||
audio->p->earlyExit = true;
|
||||
}
|
||||
|
||||
if (wait && audio->p->stream && audio->p->stream->postAudioBuffer) {
|
||||
audio->p->stream->postAudioBuffer(audio->p->stream, &audio->psg.buffer);
|
||||
}
|
||||
|
||||
mTimingSchedule(timing, &audio->sampleEvent, SAMPLE_INTERVAL - cyclesLate);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue