Using sdl-mixer-1.2.12p5's playmus on OpenBSD 6.9 to play this mp3 file, 
https://github.com/angband/angband/blob/master/lib/sounds/pls_tone_blurk.mp3?raw=true
 , hangs.  Some more details about the hang can be found in this message to the 
sm...@icculus.org mailing list, 
http://icculus.org/pipermail/smpeg/2021-May/000194.html .

The patch in that message is wrong.  As far as I can tell, the problem is with 
the calculation of the number of samples and was introduced by changes in 
patch-audio_MPEGaudio_cpp.  Since the sound file is monaural, 
audio/mpegtoraw.cpp's MPEGaudio::load_header() will initialize MPEGaudio's 
member, forcetostereoflag, to true (because MPEGaudio's stereo was set to true 
in MPEGaudio::initialize()).  With patch-audio_MPEGaudio_cpp and compiling 
without DISABLE_SDL_CONVERSIONS set, the computation for the number of samples 
doesn't account for the doubling of the number of samples because 
forcetostereoflag is true.  This patch to MPEGaudio.cpp corrects that (computed 
relative to the 0.4.4 sources; also attached as a file):

--- old/audio/MPEGaudio.cpp     2001-04-04 13:42:40.000000000 -0700
+++ new/audio/MPEGaudio.cpp     2021-05-24 09:09:56.000000000 -0700
@@ -98,7 +98,7 @@
 #else
     wanted->format = AUDIO_S16MSB;
 #endif
-    if ( outputstereo ) {
+    if ( outputstereo || forcetostereoflag ) {
         wanted->channels = 2;
     } else {
         wanted->channels = 1;
@@ -116,7 +116,7 @@
     if ( actual->channels == 1 && outputstereo ) {
         forcetomonoflag = true;
     }
-    if ( actual->channels == 2 && !outputstereo ) {
+    if ( actual->channels == 2 && !outputstereo && !forcetostereoflag ) {
         forcetostereoflag = true;
         samplesperframe *= 2;
     }

(i.e. outputstereo indicates whether the processing in audio/filter{,_2}.cpp 
produces stereo output; forcetostereoflag indicates whether a post processing 
step in audio/mpegtoraw.cpp will duplicate the data).

Applying that patch and linking the changed smpeg into sdl-mixer lets playmus 
play all the monaural sound files, 
https://github.com/angband/angband/tree/master/lib/sounds , from Angband.  It 
also resolves a long-standing bug, 
https://github.com/angband/angband/issues/4037 , where Angband's use of 
sdl-mixer caused the game to hang when run on OpenBSD.
diff -Naur old/audio/MPEGaudio.cpp new/audio/MPEGaudio.cpp
--- old/audio/MPEGaudio.cpp     2001-04-04 13:42:40.000000000 -0700
+++ new/audio/MPEGaudio.cpp     2021-05-24 09:09:56.000000000 -0700
@@ -98,7 +98,7 @@
 #else
     wanted->format = AUDIO_S16MSB;
 #endif
-    if ( outputstereo ) {
+    if ( outputstereo || forcetostereoflag ) {
         wanted->channels = 2;
     } else {
         wanted->channels = 1;
@@ -116,7 +116,7 @@
     if ( actual->channels == 1 && outputstereo ) {
         forcetomonoflag = true;
     }
-    if ( actual->channels == 2 && !outputstereo ) {
+    if ( actual->channels == 2 && !outputstereo && !forcetostereoflag ) {
         forcetostereoflag = true;
         samplesperframe *= 2;
     }

Reply via email to