Software PCM mixing

The PCM software mixer allows for multiple application streams to concurrently play to a single hardware device by mixing the audio samples of all of the application streams together. The PCM software mixer directly overlays the hardware PCM device created by the deva-ctrl-* DLL. If enabled, a PCM software mixer capture device gives you the mixed audio stream from the PCM software mixer as a reference audio stream/signal. You can't capture from the PCM software mixer reference if the PCM software mixer isn't actively mixing audio streams. The PCM software mixer is automatically instantiated for each PCM playback device, unless the -o disable_sw_mixer option is provided.

A separate PCM device won't be created for the PCM software mixer, instead the PCM software mixer overlays the hardware device. Because of this, you don't have access to the hardware directly. If you enable PCM software mixer reference streams by setting the appropriate options in the audio configuration file, a new PCM capture device is created, the reference is the index that will be 1 greater that the software mixer. Capturing from the PCM software mixer reference device will give you the mixed audio stream from the application mixer stage. You cannot capture from the PCM software mixer reference if the PCM software mixer is not actively mixing audio streams.

If the PCM software mixer has not been disabled, requests are always automatically routed to the PCM software mixer. The functionality is enabled in the hardware device entry. It's important to note that a PCM Software mixer is always created for you, even if the hardware has multiple hardware subchannels. Even with only one stream, the CPU is used more than if the hardware device were used.

If playback is using the PCM software mixer, it's important that you know that the client application's fragment size can be any multiple of the PCM software mixer fragment size. If the PCM software mixer's fragment size is 4K, then the application's fragment can be a multiple of 4K. Here's how you calculate the fragment size for the client application or PCM software mixer:
fragment size (1024 samples per voice (channels) in this case) x 2 bytes per sample (16-bit)
                         x 2 channels
                         = 4096 bytes
Tip: If you Audio component BuildID 237—June 29, 2017 (7.0.237.S201706290957) or a later update installed, the following applies:

When your subchannel goes through the software mixer ("sw_mixer") and you paused the audio stream (call snd_pcm_*_pause()), snd_pcm_*_pause() call blocks until the software mixer completes ramping down the volume to zero. Only after the volume ramps down to zero does the subchannel transition to the PAUSED state. It's important to note that if you don't use a software mixer, no ramping occurs.

Tip: If you have Audio component BuildID 387—October 2, 2017 (7.0.387.S201710021920) or a later update installed, the following applies:

The PCM software mixer operates on 16-bit PCM data. When mixing multiple audio streams, there's a possibility that the accumulated audio data can overflow and may need to be clamped to a minimum/maximum of 16-bit values. This clamping causes distortion, which is more noticeable the more the signal has overflowed into an out-of-bounds region. The degree and frequency of the overflow increases with the number of audio streams that are concurrently mixed.

To avoid the distortion, a predictive limiter (sw_mixer_limiter) can be enabled on the accumulated mixer output that uses a one millisecond delay to look ahead and observe the impending amplitude of the output audio signal. Using that information, it calculates an attenuation that reduces the signal below the PCM limit. If the output signal is below the limit, the attenuation is gradually released back to zero. This provides a much smoother signal response than direct clamping, and allows many audio streams to be mixed concurrently without any noticeable audible distortion.

The use of a limiter is recommended on target systems where multiple audio streams are played concurrently and where audio streams use the full 16-bit PCM range. If there's normally only one audio stream playing or the audio streams that are being mixed have low amplitude, then the limiter isn't required. It's important to note that the playback output incurs a one millisecond delay if the limiter is enabled. For more information, see the sw_mixer_limiter configuration options.