map

minimalist audio player
git clone https://git.porkepik.fr/map
Log | Files | Refs | README | LICENSE

commit 021ebddb542a45331491fb1c18a7f37b5c73a8d8
parent 72e9b1d40e51b0e692957174d1da7df7021376cf
Author: Thomas Philippe <dev@porkepik.fr>
Date:   Mon,  7 Sep 2020 15:34:09 +0200

add sndio format check

Diffstat:
Mmap.c | 7+++++--
Msndio.c | 9+++++++++
Mterm.c | 8+++-----
3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/map.c b/map.c @@ -1,6 +1,8 @@ /* TODO * - add cli args to set seek_sec and default_vol * - fix samples playing when quitting while paused + * - add directory name + * - better error checking */ #include <dirent.h> @@ -32,7 +34,7 @@ struct track { /* term.c */ int write_term(const char *, ...); int init_term(void); -int end_term(void); +void end_term(void); int get_term_size(int *, int *); void clear_term(void); void set_cursor(int, int); @@ -399,13 +401,14 @@ main(int argc, char **argv) qsort(tracks, ntracks, sizeof(*tracks), trackcmp); init_term(); + atexit(end_term); if (sndio_init(volume) < 0) errx(1, "Could not initialize sndio.\n"); play(); sndio_close(); - end_term(); + clear_term(); for (i = 0; i < ntracks; i++) { free(tracks[i]->filename); free(tracks[i]->name); diff --git a/sndio.c b/sndio.c @@ -1,3 +1,4 @@ +#include <err.h> #include <stdio.h> #include <sndio.h> @@ -53,6 +54,14 @@ sndio_open(int bits, int rate, int channels) if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par)) goto err0; + if (par.bits != bits) + errx(1, "could not set proper precision"); + if (par.pchan != channels) + errx(1, "could not set proper number of channels"); + if (par.rate != rate) + errx(1, "could not set proper rate"); + if (par.sig != 1 || par.le != SIO_LE_NATIVE) + errx(1, "could not set proper format"); if (!sio_start(hdl)) goto err0; diff --git a/term.c b/term.c @@ -52,13 +52,11 @@ init_term(void) return 0; } -int +void end_term(void) { - if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_term) == -1) - return -1; - write_term("\x1b[2J\x1b[H\x1b[?25h"); - return 0; + tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_term); + write_term("\x1b[?25h"); } void