Apply D47639 to test sound.
---
Below is a benchmark for `AFMT_FLOAT` operations in `pcm_sample_read()` and `pcm_sample_write()`. The results are in cycles, and are measured by adding 2 `rdtscp()` calls in `pcm_sample_read()` and `pcm_sample_write()` respectively - one at the start and one at the end, and calculating the difference.
The test program is a simple loopback program that reads and writes zeroes 512 times:
```
#include <sys/soundcard.h>
#include <err.h>
#include <fcntl.h>
#include <unistd.h>
int
main(int argc, char *argv[])
{
uint32_t sample;
int fd, fmt, chans, rate, n;
if ((fd = open(argv[1], O_RDWR)) < 0)
err(1, "open(%s)", argv[1]);
chans = 1;
if (ioctl(fd, SNDCTL_DSP_CHANNELS, &chans) < 0)
err(1, "ioctl(SNDCTL_DSP_CHANNELS)");
fmt = AFMT_S16_LE;
if (ioctl(fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
err(1, "ioctl(SNDCTL_DSP_SETFMT)");
rate = 48000;
if (ioctl(fd, SNDCTL_DSP_SPEED, &rate) < 0)
err(1, "ioctl(SNDCTL_DSP_SPEED)");
for (n = 512; n--;) {
sample = 0;
if (read(fd, &sample, sizeof(sample)) < 0)
err(1, "read");
if (write(fd, &sample, sizeof(sample)) < 0)
err(1, "write");
}
close(fd);
}
```
The sound card used is a Focusrite Scarlett Solo (`snd_uaudio(4)`), with VCHANs disabled to simplify the test.
| function | cycles |
| `pcm_sample_read(AFMT_S32_LE)` | 330.806 |
| `pcm_sample_write(AFMT_S32_LE)` | 183.298 |
| `pcm_sample_read(AFMT_F32_LE)` | 3246.6 |
| `pcm_sample_write(AFMT_F32_LE)` | 1893.8 |
The `AFMT_FLOAT` operations seem to be ~10x more expensive.