private void EnsureAudioStreamSetup(AudioBuffer buffer)
        {
            uint bufferSampleCount = (uint)GetSampleCount(buffer);
            bool needAudioSetup    = _outputStream == 0 ||
                                     (bufferSampleCount >= Constants.TargetSampleCount && bufferSampleCount < _sampleCount);

            if (needAudioSetup)
            {
                _sampleCount = Math.Max(Constants.TargetSampleCount, bufferSampleCount);

                uint newOutputStream = SDL2HardwareDeviceDriver.OpenStream(RequestedSampleFormat, RequestedSampleRate, RequestedChannelCount, _sampleCount, _callbackDelegate);

                if (newOutputStream == 0)
                {
                    // No stream in place, this is unexpected.
                    throw new InvalidOperationException($"OpenStream failed with error: \"{SDL_GetError()}\"");
                }
                else
                {
                    if (_outputStream != 0)
                    {
                        SDL_CloseAudioDevice(_outputStream);
                    }

                    _outputStream = newOutputStream;

                    SDL_PauseAudioDevice(_outputStream, _started ? 0 : 1);

                    Logger.Info?.Print(LogClass.Audio, $"New audio stream setup with a target sample count of {_sampleCount}");
                }
            }
        }