Turns PCM of any supported encoding and channel count into 16 bit little-endian stereo, the sample format of the Snapcast stream (PcmFormat#SNAPCAST_DEFAULT) apart from the rate.
More...
Turns PCM of any supported encoding and channel count into 16 bit little-endian stereo, the sample format of the Snapcast stream (PcmFormat#SNAPCAST_DEFAULT) apart from the rate.
The sample rate is not touched: a rate conversion is done by the Media3 SonicAudioProcessor in front of the tap (see PcmTapAudioProcessor); this class is the part that is plain Java and runs in a JVM test.
-
16 bit stereo passes through bit for bit.
-
Mono is copied to both sides. More than two channels are folded down (see below), never clipped by the sum.
-
8 bit (unsigned), 24 bit, 32 bit and float are converted to 16 bit with rounding (half up) and clipping at -32768 and 32767; NaN becomes silence.
Fold-down. The channel order is the one of Android and WAV: 3 = FL FR FC, 4 = FL FR BL BR, 5 = FL FR FC BL BR, 6 = FL FR FC LFE BL BR, 7 = FL FR FC LFE BL BR BC (5.1 plus a back centre, as Media3 1.11.1 maps seven channels), 8 = FL FR FC LFE BL BR SL SR. The front channel counts with 1, the centre, the back centre and every surround channel with 0.7071 (-3 dB) on the side they belong to (the back centre on both), the LFE is dropped. Each side is divided by the sum of its weights, so equal full-scale channels give exactly full scale and the fold-down can not overflow; the price is that a signal on the front left alone is about 7.7 dB quieter at 5.1 (the same normalisation FFmpeg uses by default).
Instances keep a scratch array and are not thread safe; use one per thread (the playback thread of the tap).