From d725630b5f5817287d44cb31c3c7b9d815c187db Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 29 Nov 2017 21:30:10 +0100 Subject: audio: add audio softvol processing to AO This does what af_volume used to do. Since we couldn't relicense it, just rewrite it. Since we don't have a new filter mechanism yet, and the libavfilter is too inconvenient, do applying the volume gain in ao.c directly. This is done before handling the audio data to the driver. Since push.c runs a separate thread, and pull.c is called asynchronously from the audio driver's thread, the volume value needs to be synchronized. There's no existing central mutex, so do some shit with atomics. Since there's no atomic_float type predefined (which is at least needed when using the legacy wrapper), do some nonsense about reinterpret casting the float value to an int for the purpose of atomic access. Not sure if using memcpy() is undefined behavior, but for now I don't care. The advantage of not using a filter is lower complexity (no filter auto insertion), and lower latency (gain processing is done after our internal audio buffer of at least 200ms). Disavdantages include inability to use native volume control _before_ other filters with custom filter chains, and the need to add new processing for each new sample type. Since this doesn't reuse any of the old GPL code, nor does indirectly rely on it, volume and replaygain handling now works in LGPL mode. How to process the gain is inspired by libavfilter's af_volume (LGPL). In particular, we use exactly the same rounding, and we quantize processing for integer sample types by 256 steps. Some of libavfilter's copyright may or may not apply, but I think not, and it's the same license anyway. --- Copyright | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Copyright') diff --git a/Copyright b/Copyright index fc918c4be6..57b7a75cd9 100644 --- a/Copyright +++ b/Copyright @@ -34,8 +34,8 @@ a LGPL mode to mpv, MPlayer code had to be relicensed from GPLv2+ to LGPLv2.1+ by asking the MPlayer authors for permission. Since permission could not be obtained from everyone, LGPL mode disables the following features, some of them quite central: -- no audio filtering, which breaks: --volume, --af, replaygain, pitch - correction, fine control about downmix/upmix/resampling behavior +- no audio filtering, which breaks: --af, pitch correction, fine control over + downmix/upmix/resampling behavior - Linux X11 video output - BSD audio output via OSS - NVIDIA/Linux hardware decoding (vdpau, although nvdec usually works) -- cgit v1.2.3