First post, by krcroft
This patch adds decoding of Opus, FLAC, and MP3 CDDA audio tracks (in addition to the baseline Vorbis support) to the current development branch of DOSBox, without the need for SDL_Sound 1.2 or Vorbis libraries on your machine.
Revision 14 [2019-11-24]
- The patch no longer fetches and builds the Opus code internally, and instead now depends on provision of the opusfile library via pkg-config.
Install using: apt, dnf, pacman, zypper, brew, macports, and vcpkg install opusfile and autoconf-archive.
- Because changes are made to the autotools configuration, please run the follow one-time
after first patching your SVN code: ./autogen.sh, ./configure, make distclean.
Then start fresh with ./autogen.sh, ./configure.
This ensures all prior autotools generated/derived content extracted from the SVN tarball is cleaned out.
- Plays subsequent tracks if needed to satisfy the requested playback duration (commit).
This fixes Betrayal at Kronodor if using per-file tracks, such as oggs.
Issue reported by Dagar and Pr3tty F1y, and confirmed as a bug by ripsaw8080 -- thank you.
- Fixed a regression-by-omission in stereo channel-control handing.
Flagged by ripsaw8080 who also recommended using Chronicles of the Sword to test it -- thank you.
- Fixed CD-DA playback in Destruction Derby without need for special MSF handling.
Testers wanted - please see this post here.
- Simplified CD-DA code and remove several layers of intermediate-buffers (see these seven commits)
- Updated MP3 decoder to dr_mp3 version 0.5.2
- All commits above have been code-reviewed by @dreamer_, maintainer of the dosbox-staging repo -- thank you.
- Code has been merged to and the diff generated from the master branch of the dosbox-staging repo (https://github.com/dreamer/dosbox-staging)
Because of this, the patch also contains the delta of fixes in staging versus SVN (see: patch series 1, series 2, and series 3).
Revision 13.2 [2019-10-10]
- Update FLAC decoder to dr_flac version 0.12.2 released 2019-10-07
- Update MP3 decoder to dr_mp3 version 0.5.0 released 2019-10-07
- Update WAV decoder to dr_wav version 0.11.1 released 2019-10-07
- Regenerate diff against clean baseline, per build issue in rev12 reported by Yesterplay80 - thank you!
Revision 12 [2019-10-05]:
- Add support for big-endian architectures, such as PowerPC and Sun Sparc: all codecs have been tested and are working
- Add support for Sony Wave64 (.w64) tracks, as this is handled by the dr_wav codec which now replaces the prior SDL_Sound1.2-based codec
What value does this patch add over the baseline? or Ogg Vorbis ought to be enough
- for lossy compression, Opus supersedes Vorbis, which has been deprecated. Opus beats Apple's AAC and HE-AAC in ABX listening tests as well.
- for lossless compression, FLAC supersedes WAV by offering 2:1 or more compression with binary-identical output
- CPU usage and decode latency are improved versus Vorbis (no change between FLAC and WAV), so this is win-win
When it comes to preserving audio content from the golden-era of PC gaming, these games deserve the best we can offer.
I've ripped my CDROM and have WAV files ready to compress - where can I get the latest encoders?
- Windows: https://archive.mozilla.org/pub/opus/win32/op … -opus-1.3.1.zip
- macOSX: brew install opus-tools (if you don't have brew, see: http://macappstore.org/opus-tools/)
- Linux: apt/zypper/yum install opus-tools (or build from source: ogg, opus, libopusfile, and opus-tools)
- Windows: https://ftp.osuosl.org/pub/xiph/releases/flac … c-1.3.2-win.zip
- macOSX: brew install flac (if you don't have brew, see: http://macappstore.org/flac/)
- Linux: apt/zypper/yum install flac (or build from source, http://www.linuxfromscratch.org/blfs/view/svn … media/flac.html)
- Windows: Oggenc2.88 using aoTuVb6.03 (Lancer Builds) here
- macOSX: Vorbis-Tools for MacOS X using aoTuVb5.5 here
- Linux: oggenc 1.4.0 SVN + aoTuV Beta6.03 with libogg 1.2.0, FLAC 1.2.1 and Kate 0.3.8 (Static GCC 4 compile) here
- Windows: http://www.rarewares.org/mp3-lame-bundle.php
- macOSX: brew install lame (if you don't have brew, see: http://macappstore.org/lame/)
- Linux: apt/zypper/yum install lame (or build from source, http://www.linuxfromscratch.org/blfs/view/svn … media/lame.html)
What are some recommended encoding parameters I can try?
FLAC (all files):
- flac -8 --output-name="outfile" "wavfile", followed by
- metaflac --add-seekpoint=1s "flacfile"
Opus, for mono voice-only tracks:
- opusenc --speech --bitrate 24 --downmix-mono "wavfile" "outfile"
- Alone in the Dark 2, tracks 23 to 63
- Alone in the Dark 3, tracks 24 to 61
- Battle Chess Enhanced, track 22
- Big Red Racing, tracks 12 to 29, and 33 to 39
- Jones in the Fast Lane: all tracks
- Shadowcaster: all tracks
Opus, for stereo voice-only tracks:
- opusenc --speech --bitrate 36 "wavfile" "outfile"
- Action Soccer, tracks 2 to 13
- AD&D Dark Sun II Wake of the Ravager, tracks 38 and 39
- Loom: all tracks
Opus for mono non-voice tracks:
- opusenc --bitrate 54 --downmix-mono "wavfile" "outfile"
- Destruction Derby, tracks 2, and 4 to 9
- Stellar 7, tracks 4 and 5
- Zyclunt, all tracks
Opus for stereo non-voice tracks:
- opusenc --bitrate 84 "wavfile" "outfile"
How should my CUE files look?
Here's a CUE with examples for each codec:
FILE "data.iso" BINARY
TRACK 01 MODE1/2048
INDEX 01 00:00:00
FILE "track02.opus" OPUS
TRACK 02 AUDIO
INDEX 01 00:00:00
FILE "track03.flac" FLAC
TRACK 03 AUDIO
INDEX 01 00:00:00
FILE "track04.ogg" OGG
TRACK 04 AUDIO
INDEX 01 00:00:00
FILE "track05.mp3" MP3
TRACK 05 AUDIO
INDEX 01 00:00:00
What runtime improvements have been made?
- Replaces the existing audio callback routine with an efficient chunked circular-buffer audio reader
- Replaces assumptions that all audio tracks are 44.1 kHz & stereo. The mixer is now fed data at the actual compressed track's rate and channel count
- Queries the codec for track-length instead of using hundreds of iterative decimating seeks to determine track length (loading a 99-track CUE now takes 0.1 user-seconds versus 3+ seconds previously)
- Seeks are performed within the already-decoded buffer (for all codecs) instead of discarding and re-running the decode sequence
- SDL_Sound's internal buffers are now eliminated
- Only one seek is performed per-playback sequence followed by sequential decodes, similar to a physical CDROM (The baseline dosbox performs a seek for every 2352-bytes of uncompressed audio)
- The DOSBox mixer is now only active during playback sequences and fully dormant otherwise (baseline dosbox instead performs hundreds of calls/second with empty data)
- When using Opus audio tracks, and if your dosbox-SVN.conf [mixer] rate=48000, then you will (very likely) achieve sample-exact unadulterated pass-through along your entire audio chain from the decoder, to DOSBox, to your operating system's software mixer, to your sound card driver, to your sound card, to your speakers, or to your digital receiver / USB speakers/headphones / or HDMI TV/screen. This is because almost all modern hardware DACs use a native sample rate of 48000
What source-level maintenance improvements have been made?
- Eliminated external dependence on SDL_Sound and its outdated of external library dependencies -- thank you Dominus and DosFreak for recommending this approach.
- SDL_Sound, Vorbis, FLAC, Opus, and Ogg libraries are not needed on your system nor do you need to build or provide pointers to these in CFLAGS/LIBS/etc..
- All codec handling is 100% internal DOSBox's to source and "always on"
- It strips all references to SDL_Sound from configure.ac
- It strips all pre-processor #ifdef branching for SDL_Sound from the code
- For Vorbis decoding, this patch employs the single-header stb_vorbis.h instead of of libogg, libvorbis, and libvorbisfile
- For MP3 decoding, this patch employs the single-header dr_mp3.h
- For FLAC decoding, this patch employs the single-header dr_flac.h
- For WAV decoding, this patch employs the single-header dr_wav.h
- It adds src/libs/decoders, which holds the top-level opus, flac, vorbis, and wav decoders
- It adds src/libs/decoders/internal, where the master-stable branch of opus is fetched, built, and statically linked along side DOSBox's internal libraries
- Fixes all codec compiler warnings; 100% clean builds tested with gcc 4.x through 9.x
- Built and tested on Linux, MacOSX (xcode), and Windows (MinGW msys 1.0)
What about SDL_Sound 1.0.3, can't we sit back and wait for the SDL Developers to add Opus and fix its broken MP3 and FLAC decoding?
SDL Sound 1.0.3 hasn't been touched in over a decade and has many bugs and autotool issues within modern environments. The developers are unyielding on going back and fixing SDL1 libraries to accommodate issues cropping up in modern environments. For them, it's SDL2 or the highway. Example: https://forums.libsdl.org/viewtopic.php?p=45264 (that was 4 years ago, and we're still at SDL 1.2.15)
Ryan Gordon informed me he will use my Opus decoder to add Opus handling to this new SDL2-based sound libraries, however DOSBox would have to move to SDL2 to get it.
This patch brings audio-codec handling under our own control, strips it down to the bare minimum, and corrects identified deficiencies.
If and when DOSBox decides to move to SDL2, we can decide then if we want to move back to dependence on SDL2_Sound.