YAACC - UPNP Client and Server
Loading...
Searching...
No Matches
de.yaacc.multiroom.feed.PcmFormatConverter Class Reference

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...

Collaboration diagram for de.yaacc.multiroom.feed.PcmFormatConverter:
Collaboration graph

Public Member Functions

 PcmFormatConverter (PcmEncoding encoding, int channels)
 
boolean isPassThrough ()
 True when the input already is 16 bit stereo: the bytes are copied as they are.
 
int inputFrameBytes ()
 Bytes of one input frame.
 
int outputBytesFor (int inputBytes)
 The size of the output for inputBytes bytes of input (whole frames).
 
int convert (byte[] in, int inOffset, int inLength, byte[] out, int outOffset)
 Converts whole frames.
 

Static Public Member Functions

static boolean isSupported (int channels)
 True for 1 to MAX_INPUT_CHANNELS channels.
 

Static Public Attributes

static final int OUTPUT_CHANNELS = 2
 The converter always produces stereo.
 
static final int MAX_INPUT_CHANNELS = 8
 The most input channels it folds down.
 
static final int OUTPUT_FRAME_BYTES = 4
 Bytes of one output frame: two 16 bit samples.
 

Detailed Description

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).

Constructor & Destructor Documentation

◆ PcmFormatConverter()

de.yaacc.multiroom.feed.PcmFormatConverter.PcmFormatConverter ( PcmEncoding encoding,
int channels )
Parameters
encodingthe encoding of the input
channelsthe channels of the input, 1 to MAX_INPUT_CHANNELS
Exceptions
IllegalArgumentExceptionfor an unsupported channel count
Here is the call graph for this function:

Member Function Documentation

◆ convert()

int de.yaacc.multiroom.feed.PcmFormatConverter.convert ( byte[] in,
int inOffset,
int inLength,
byte[] out,
int outOffset )

Converts whole frames.

Returns
the number of bytes written to out
Exceptions
IllegalArgumentExceptionwhen inLength is not a multiple of the frame size, or a range lies outside its array (nothing is written then)

The documentation for this class was generated from the following file: