summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJaroslav Kysela <perex@perex.cz>2020-05-03 20:07:29 +0200
committerJaroslav Kysela <perex@perex.cz>2020-05-03 20:07:55 +0200
commit21e2fc3857b842e8b47f77da785248edbaa69f5f (patch)
tree54a4d345a260bc037919d0129d49b0a0d8346dab /test
parent29041c522071172af2c6bf086b3a0c19510a6660 (diff)
downloadalsa-lib-21e2fc3857b842e8b47f77da785248edbaa69f5f.tar.gz
test: pcm_min - add snd_pcm_drain() call and indentation fixes
Fixes: https://github.com/alsa-project/alsa-lib/issues/46 Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Diffstat (limited to 'test')
-rw-r--r--test/pcm_min.c50
1 files changed, 26 insertions, 24 deletions
diff --git a/test/pcm_min.c b/test/pcm_min.c
index 7462a45f..4c120b4c 100644
--- a/test/pcm_min.c
+++ b/test/pcm_min.c
@@ -5,47 +5,49 @@
#include "../include/asoundlib.h"
static char *device = "default"; /* playback device */
-
-snd_output_t *output = NULL;
unsigned char buffer[16*1024]; /* some random data */
int main(void)
{
- int err;
- unsigned int i;
- snd_pcm_t *handle;
- snd_pcm_sframes_t frames;
+ int err;
+ unsigned int i;
+ snd_pcm_t *handle;
+ snd_pcm_sframes_t frames;
- for (i = 0; i < sizeof(buffer); i++)
- buffer[i] = random() & 0xff;
+ for (i = 0; i < sizeof(buffer); i++)
+ buffer[i] = random() & 0xff;
if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
printf("Playback open error: %s\n", snd_strerror(err));
exit(EXIT_FAILURE);
}
if ((err = snd_pcm_set_params(handle,
- SND_PCM_FORMAT_U8,
- SND_PCM_ACCESS_RW_INTERLEAVED,
- 1,
- 48000,
- 1,
- 500000)) < 0) { /* 0.5sec */
+ SND_PCM_FORMAT_U8,
+ SND_PCM_ACCESS_RW_INTERLEAVED,
+ 1,
+ 48000,
+ 1,
+ 500000)) < 0) { /* 0.5sec */
printf("Playback open error: %s\n", snd_strerror(err));
exit(EXIT_FAILURE);
}
for (i = 0; i < 16; i++) {
- frames = snd_pcm_writei(handle, buffer, sizeof(buffer));
- if (frames < 0)
- frames = snd_pcm_recover(handle, frames, 0);
- if (frames < 0) {
- printf("snd_pcm_writei failed: %s\n", snd_strerror(frames));
- break;
- }
- if (frames > 0 && frames < (long)sizeof(buffer))
- printf("Short write (expected %li, wrote %li)\n", (long)sizeof(buffer), frames);
- }
+ frames = snd_pcm_writei(handle, buffer, sizeof(buffer));
+ if (frames < 0)
+ frames = snd_pcm_recover(handle, frames, 0);
+ if (frames < 0) {
+ printf("snd_pcm_writei failed: %s\n", snd_strerror(frames));
+ break;
+ }
+ if (frames > 0 && frames < (long)sizeof(buffer))
+ printf("Short write (expected %li, wrote %li)\n", (long)sizeof(buffer), frames);
+ }
+ /* pass the remaining samples, otherwise they're dropped in close */
+ err = snd_pcm_drain(handle);
+ if (err < 0)
+ printf("snd_pcm_drain failed: %s\n", snd_strerror(err));
snd_pcm_close(handle);
return 0;
}