There was a possibility that this process could result in
snd_pcm_writei() getting stuck because the frame count is not being
clamped to the buffer size properly.
When WASAPI reports `AUDCLNT_E_DEVICE_INVALIDATED` miniaudio will
attempt to reinitialize the device and continue processing. Prior to
this commit the reinit process would use NULL as the device ID which
is incorrect when an explicit device was requested.
With this commit the reinit process will correctly pass in the ID of the
device that it was initialized with. In practice, this will mean the
device will be put into an errored state if it is unplugged.
This makes it so period sizes are a power of 2, which in turns makes it
so the value set by `snd_pcm_sw_params_set_avail_min()` is also a power
of 2. This is inline with a suggestion by the ALSA documentation, and
seems to have an actual positive impact in practice with my testing as
well.
In order to get detailed information about a device, that is supported
formats, channels and sample rates, the PCM needs to be opened. This
can fail sometimes, in which case enumeration would previously just not
enumerate the device.
This is OK, but it creates issues. The first is that the enumerated
devices will not be consistent with what's reported by `aplay`. The
other is that when a hardware device is opened, iteration will not
include that device because it'll be opened in exclusive mode. This
creates a practical issue when trying to get the name of an already
opened device.
This commit makes it so that these devices will still be enumerated,
only they'll be missing detailed format, channels and rate information.
* A start threshold is no longer used meaning an explicit call to
snd_pcm_start() is required, which was happening already anyway.
* The stop threshold is no longer used.
* Stopping the playback side of device now drains it.
* Starting a device will now pre-fill the playback side with silence
before starting it which should hopefully avoid an immediate xrun.