Skip to content

Commit

Permalink
sdl2_audio: fill buffer with silence if nothing to play
Browse files Browse the repository at this point in the history
  • Loading branch information
Cpasjuste committed May 8, 2022
1 parent 6cdbc9d commit 0dd322c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion libcross2d
15 changes: 11 additions & 4 deletions pnes/sources/uiEmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,25 @@ void audio_deinit() {
}

void audio_queue() {
if (uiEmu->getAudio() != nullptr) {
if (uiEmu->getAudio()) {
#if 0
printf("play: samples: %i, queued: %i, capacity: %i\n",
uiEmu->getAudio()->getSamples(),
uiEmu->getAudio()->getSampleBufferQueued(),
uiEmu->getAudio()->getSampleBufferCapacity());
#endif
uiEmu->getAudio()->play(audio_buffer, uiEmu->getAudio()->getSamples(), nst_pal());
}
}

void audio_pause() {
if (uiEmu->getAudio() != nullptr) {
if (uiEmu->getAudio()) {
uiEmu->getAudio()->pause(1);
}
}

void audio_unpause() {
if (uiEmu->getAudio() != nullptr) {
if (uiEmu->getAudio()) {
uiEmu->getAudio()->pause(0);
}
}
Expand All @@ -171,7 +177,7 @@ void audio_set_params(Sound::Output *soundoutput) {

Audio *aud = uiEmu->getAudio();

if (aud != nullptr) {
if (aud) {
// Set audio parameters
Sound sound(emulator);

Expand All @@ -184,6 +190,7 @@ void audio_set_params(Sound::Output *soundoutput) {
audio_adj_volume();

audio_buffer = malloc(aud->getSamplesSize());
memset(audio_buffer, 0, aud->getSamplesSize());
soundoutput->samples[0] = audio_buffer;
soundoutput->length[0] = (unsigned int) aud->getSamples();
soundoutput->samples[1] = nullptr;
Expand Down

0 comments on commit 0dd322c

Please sign in to comment.