Skip to content

Commit

Permalink
fix playback sound on Windows after SDL upgrade
Browse files Browse the repository at this point in the history
SDL in the Windows build was upgraded from version 2.0.5 to version
2.28.1 to fix a bug where sound is not follow changes to the default
output device in Windows

https://forum.shotcut.org/t/sound-into-headphones/33298
https://forum.shotcut.org/t/help-shotcut-wont-switch-audio-playback-
devices/22038
https://forum.shotcut.org/t/audio-output-does-not-change-with-computer-
on-windows/14549
https://forum.shotcut.org/t/shotcut-will-not-play-audio-through-
bluetooth-headphones/11112

SDL version 2.0.6 fixes this but also introduced the default driver
"wasapi" that creates a buzzing or crackling sound when the system is
configured for 5.1. It also plays stereo as multi-channel stereo like
many surround receivers offer but even when the receiver is not
configured as such! "directsound" fixes those issues, but a different
kind of distortion appears after changing output devices. "winmm" fixes
that, but it does not work when opened with more than 2 channels. What a
mess.
  • Loading branch information
ddennedy committed Jul 7, 2023
1 parent ca66bb9 commit 8a9f844
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/mainwindow.cpp
Expand Up @@ -1577,6 +1577,11 @@ bool MainWindow::open(QString url, const Mlt::Properties *properties, bool play)
mlt_properties_inherit(MLT.producer()->get_properties(), props->get_properties());
m_player->setPauseAfterOpen(!play || !MLT.isClip());

#if defined(Q_OS_WIN)
if (!::qEnvironmentVariableIsSet("SDL_AUDIODRIVER")) {
::qputenv("SDL_AUDIODRIVER", MLT.audioChannels() > 2 ? "directsound" : "winmm");
}
#endif
setAudioChannels(MLT.audioChannels());
if (url.endsWith(".mlt") || url.endsWith(".xml")) {
setVideoModeMenu();
Expand Down Expand Up @@ -3206,7 +3211,7 @@ void MainWindow::on_actionProgressive_triggered(bool checked)

void MainWindow::changeAudioChannels(bool checked, int channels)
{
if ( checked ) {
if (checked) {
Settings.setPlayerAudioChannels(channels);
setAudioChannels(Settings.playerAudioChannels());
}
Expand Down

0 comments on commit 8a9f844

Please sign in to comment.