Skip to content

Commit

Permalink
Fix SDL2 audio driver on latest SDL version
Browse files Browse the repository at this point in the history
  • Loading branch information
XITRIX committed Oct 7, 2024
1 parent 6c22f38 commit 0bb1788
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ jobs:
runs-on: ubuntu-latest

container:
image: docker://devkitpro/devkita64:20240120
# image: docker://devkitpro/devkita64:20240120 // Before SDL broken audio
image: docker://devkitpro/devkita64:latest

steps:
- name: Check out repository
Expand Down
12 changes: 6 additions & 6 deletions app/src/streaming/audio/SDLAudioRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ int SDLAudioRenderer::init(int audio_configuration,
want.freq = opus_config->sampleRate;
want.format = AUDIO_S16LSB;
want.channels = opus_config->channelCount;
want.samples = std::max(480, opus_config->samplesPerFrame); //1024;
want.samples = 4096;// std::max(480, opus_config->samplesPerFrame); //1024;

dev =
SDL_OpenAudioDevice(nullptr, 0, &want, &have, SDL_AUDIO_ALLOW_ANY_CHANGE);
SDL_OpenAudioDevice(nullptr, 0, &want, &have, 0);
if (dev == 0) {
printf("Failed to open audio: %s\n", SDL_GetError());
brls::Logger::error("Failed to open audio: %s\n", SDL_GetError());
return -1;
} else {
if (have.format != want.format) // we let this one thing change.
printf("We didn't get requested audio format.\n");
brls::Logger::error("We didn't get requested audio format.\n");
SDL_PauseAudioDevice(dev, 0); // start audio playing.
}

Expand Down Expand Up @@ -83,9 +83,9 @@ void SDLAudioRenderer::decode_and_play_sample(char* sample_data,
i = (short) std::min(SHRT_MAX, std::max(SHRT_MIN, scale));
}

if (SDL_GetQueuedAudioSize(dev) > 16000) {
if (SDL_GetQueuedAudioSize(dev) > 28000) {
// clear audio queue to avoid big audio delay
// average values are close to 16000 bytes
// average values are close to 28000 bytes
SDL_ClearQueuedAudio(this->dev);
}

Expand Down
15 changes: 8 additions & 7 deletions app/src/streaming/ffmpeg/FFmpegVideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,20 @@ int FFmpegVideoDecoder::setup(int video_format, int width, int height,

// Need to align Switch frame to 256, need to de reviewed
#if defined(__SWITCH__) && !defined(BOREALIS_USE_DEKO3D)
int err = av_frame_get_buffer(m_frames[i], 256);
// int err = av_frame_get_buffer(m_frames[i], 256);
int err = av_frame_get_buffer(m_frames[i], 0);
if (err < 0) {
char errs[64];
brls::Logger::error("FFmpeg: Couldn't allocate frame buffer: {}", av_make_error_string(errs, 64, err));
return -1;
}

for (int j = 0; j < 2; j++) {
uintptr_t ptr = (uintptr_t)m_frames[i]->data[j];
uintptr_t dst = (((ptr)+(256)-1)&~((256)-1));
uintptr_t gap = dst - ptr;
m_frames[i]->data[j] += gap;
}
// for (int j = 0; j < 2; j++) {
// uintptr_t ptr = (uintptr_t)m_frames[i]->data[j];
// uintptr_t dst = (((ptr)+(256)-1)&~((256)-1));
// uintptr_t gap = dst - ptr;
// m_frames[i]->data[j] += gap;
// }
#endif
}

Expand Down

0 comments on commit 0bb1788

Please sign in to comment.