mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-06-09 04:21:38 +12:00
Optimize audio output a bit
This commit is contained in:
parent
53746e0511
commit
921250bcd2
4 changed files with 113 additions and 124 deletions
|
@ -92,15 +92,6 @@ void MiniAudioDevice::init(Samples& samples, bool safe) {
|
|||
auto self = reinterpret_cast<MiniAudioDevice*>(device->pUserData);
|
||||
s16* output = reinterpret_cast<ma_int16*>(out);
|
||||
|
||||
// Wait until there's enough samples to pop
|
||||
while (self->samples->size() < frameCount * channelCount) {
|
||||
printf("Waiting\n");
|
||||
// If audio output is disabled from the emulator thread, make sure that this callback will return and not hang
|
||||
if (!self->running) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
self->samples->pop(output, frameCount * channelCount);
|
||||
};
|
||||
|
||||
|
|
|
@ -6,10 +6,6 @@
|
|||
#include "services/dsp.hpp"
|
||||
|
||||
using namespace Audio;
|
||||
static constexpr u32 sampleRate = 32768;
|
||||
static constexpr u32 duration = 30;
|
||||
static s16 samples[sampleRate * duration * 2];
|
||||
static uint sampleIndex = 0;
|
||||
|
||||
struct Dsp1 {
|
||||
// All sizes are in bytes unless otherwise specified
|
||||
|
@ -115,6 +111,8 @@ void TeakraDSP::reset() {
|
|||
running = false;
|
||||
loaded = false;
|
||||
signalledData = signalledSemaphore = false;
|
||||
|
||||
audioFrameIndex = 0;
|
||||
}
|
||||
|
||||
void TeakraDSP::setAudioEnabled(bool enable) {
|
||||
|
@ -124,10 +122,14 @@ void TeakraDSP::setAudioEnabled(bool enable) {
|
|||
// Set the appropriate audio callback for Teakra
|
||||
if (audioEnabled) {
|
||||
teakra.SetAudioCallback([=](std::array<s16, 2> sample) {
|
||||
// Wait until we can push our samples
|
||||
while (sampleBuffer.size() + 2 > sampleBuffer.Capacity()) {
|
||||
audioFrame[audioFrameIndex++] = sample[0];
|
||||
audioFrame[audioFrameIndex++] = sample[1];
|
||||
|
||||
// Push our samples at the end of an audio frame
|
||||
if (audioFrameIndex >= audioFrame.size()) {
|
||||
audioFrameIndex -= audioFrame.size();
|
||||
sampleBuffer.push(audioFrame.data(), audioFrame.size());
|
||||
}
|
||||
sampleBuffer.push(sample.data(), 2);
|
||||
});
|
||||
} else {
|
||||
teakra.SetAudioCallback([=](std::array<s16, 2> sample) { /* Do nothing */ });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue