mirror of https://github.com/ericonr/sndio.git
link the .so file with -lasound, otherwise we get the
wrong alsa library
This commit is contained in:
parent
8e25c4c95f
commit
8e920de252
|
@ -105,7 +105,7 @@ issetugid.o strlcat.o strlcpy.o strtonum.o
|
||||||
${CC} ${CFLAGS} ${SO_CFLAGS} ${INCLUDE} ${DEFS} -o $@ -c $<
|
${CC} ${CFLAGS} ${SO_CFLAGS} ${INCLUDE} ${DEFS} -o $@ -c $<
|
||||||
|
|
||||||
libsndio.so.${MAJ}.${MIN}: ${OBJS}
|
libsndio.so.${MAJ}.${MIN}: ${OBJS}
|
||||||
${CC} ${LDFLAGS} ${SO_CFLAGS} ${SO_LDFLAGS} -o libsndio.so.${MAJ}.${MIN} ${OBJS}
|
${CC} ${LDFLAGS} ${SO_CFLAGS} ${SO_LDFLAGS} -o libsndio.so.${MAJ}.${MIN} ${OBJS} ${LDADD}
|
||||||
|
|
||||||
libsndio.so.${MAJ}:
|
libsndio.so.${MAJ}:
|
||||||
ln -sf libsndio.so.${MAJ}.${MIN} libsndio.so.${MAJ}
|
ln -sf libsndio.so.${MAJ}.${MIN} libsndio.so.${MAJ}
|
||||||
|
|
|
@ -20,9 +20,6 @@
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <alsa/asoundlib.h>
|
|
||||||
#include <alsa/pcm.h>
|
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
@ -32,12 +29,14 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <values.h>
|
#include <values.h>
|
||||||
|
#include <alsa/asoundlib.h>
|
||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "sio_priv.h"
|
#include "sio_priv.h"
|
||||||
#include "bsd-compat.h"
|
#include "bsd-compat.h"
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
static snd_output_t *output = NULL;
|
||||||
#define DALSA(str, err) fprintf(stderr, "%s: %s\n", str, snd_strerror(err))
|
#define DALSA(str, err) fprintf(stderr, "%s: %s\n", str, snd_strerror(err))
|
||||||
#else
|
#else
|
||||||
#define DALSA(str, err) do {} while (0)
|
#define DALSA(str, err) do {} while (0)
|
||||||
|
@ -307,6 +306,12 @@ sio_alsa_open(const char *str, unsigned mode, int nbio)
|
||||||
return NULL;
|
return NULL;
|
||||||
sio_create(&hdl->sio, &sio_alsa_ops, mode, nbio);
|
sio_create(&hdl->sio, &sio_alsa_ops, mode, nbio);
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
err = snd_output_stdio_attach(&output, stderr, 0);
|
||||||
|
if (err < 0)
|
||||||
|
DALSA("attach to stderr", err);
|
||||||
|
#endif
|
||||||
|
|
||||||
snprintf(path, sizeof(path), "hw:%s", str);
|
snprintf(path, sizeof(path), "hw:%s", str);
|
||||||
if (mode & SIO_PLAY) {
|
if (mode & SIO_PLAY) {
|
||||||
err = snd_pcm_open(&hdl->out_pcm, path,
|
err = snd_pcm_open(&hdl->out_pcm, path,
|
||||||
|
@ -529,6 +534,11 @@ sio_alsa_setpar(struct sio_hdl *sh, struct sio_par *par)
|
||||||
hdl->sio.eof = 1;
|
hdl->sio.eof = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
err = snd_pcm_hw_params_set_rate_resample(hdl->out_pcm, hdl->out_hwp, 0);
|
||||||
|
if (err < 0) {
|
||||||
|
printf("Resampling setup failed for playback: %s\n", snd_strerror(err));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
err = snd_pcm_hw_params_set_access(hdl->out_pcm,
|
err = snd_pcm_hw_params_set_access(hdl->out_pcm,
|
||||||
hdl->out_hwp, SND_PCM_ACCESS_RW_INTERLEAVED);
|
hdl->out_hwp, SND_PCM_ACCESS_RW_INTERLEAVED);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
|
@ -561,8 +571,8 @@ sio_alsa_setpar(struct sio_hdl *sh, struct sio_par *par)
|
||||||
hdl->sio.eof = 1;
|
hdl->sio.eof = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
err = snd_pcm_hw_params_set_access(hdl->out_pcm,
|
err = snd_pcm_hw_params_set_access(hdl->in_pcm,
|
||||||
hdl->out_hwp, SND_PCM_ACCESS_RW_INTERLEAVED);
|
hdl->in_hwp, SND_PCM_ACCESS_RW_INTERLEAVED);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
DALSA("couldn't set rec access", err);
|
DALSA("couldn't set rec access", err);
|
||||||
hdl->sio.eof = 1;
|
hdl->sio.eof = 1;
|
||||||
|
@ -591,7 +601,6 @@ sio_alsa_setpar(struct sio_hdl *sh, struct sio_par *par)
|
||||||
}
|
}
|
||||||
if (!sio_alsa_fmttopar(hdl, ofmt, &hdl->par))
|
if (!sio_alsa_fmttopar(hdl, ofmt, &hdl->par))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* set rate
|
* set rate
|
||||||
*/
|
*/
|
||||||
|
@ -682,7 +691,6 @@ sio_alsa_setpar(struct sio_hdl *sh, struct sio_par *par)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
DPRINTF("sio_alsa_setpar: trying bufsz = %u, round = %u\n", bufsz, round);
|
DPRINTF("sio_alsa_setpar: trying bufsz = %u, round = %u\n", bufsz, round);
|
||||||
|
|
||||||
obufsz = bufsz;
|
obufsz = bufsz;
|
||||||
if (hdl->sio.mode & SIO_PLAY) {
|
if (hdl->sio.mode & SIO_PLAY) {
|
||||||
err = snd_pcm_hw_params_set_buffer_size_near(hdl->out_pcm,
|
err = snd_pcm_hw_params_set_buffer_size_near(hdl->out_pcm,
|
||||||
|
@ -692,7 +700,7 @@ sio_alsa_setpar(struct sio_hdl *sh, struct sio_par *par)
|
||||||
hdl->sio.eof = 1;
|
hdl->sio.eof = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
DPRINTF("sio_alsa_setpar: obufsz: ok\n");
|
DPRINTF("sio_alsa_setpar: obufsz: %u, ok\n", obufsz);
|
||||||
}
|
}
|
||||||
ibufsz = obufsz;
|
ibufsz = obufsz;
|
||||||
if (hdl->sio.mode & SIO_REC) {
|
if (hdl->sio.mode & SIO_REC) {
|
||||||
|
@ -722,7 +730,7 @@ sio_alsa_setpar(struct sio_hdl *sh, struct sio_par *par)
|
||||||
hdl->sio.eof = 1;
|
hdl->sio.eof = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
DPRINTF("sio_alsa_setpar: onfr: ok\n");
|
DPRINTF("sio_alsa_setpar: onfr: %u, ok\n", onfr);
|
||||||
}
|
}
|
||||||
infr = onfr;
|
infr = onfr;
|
||||||
if (hdl->sio.mode & SIO_REC) {
|
if (hdl->sio.mode & SIO_REC) {
|
||||||
|
@ -742,12 +750,10 @@ sio_alsa_setpar(struct sio_hdl *sh, struct sio_par *par)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
hdl->par.round = onfr;
|
hdl->par.round = onfr;
|
||||||
|
|
||||||
DPRINTF("sio_alsa_setpar: got bufsz = %u, round = %u\n",
|
DPRINTF("sio_alsa_setpar: got bufsz = %u, round = %u\n",
|
||||||
hdl->par.bufsz, hdl->par.round);
|
hdl->par.bufsz, hdl->par.round);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* commit hardware params */
|
/* commit hardware params */
|
||||||
|
|
||||||
if (hdl->sio.mode & SIO_PLAY) {
|
if (hdl->sio.mode & SIO_PLAY) {
|
||||||
|
@ -758,6 +764,7 @@ sio_alsa_setpar(struct sio_hdl *sh, struct sio_par *par)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
DPRINTF("sio_alsa_setpar: out_hwp: ok\n");
|
DPRINTF("sio_alsa_setpar: out_hwp: ok\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
if (hdl->sio.mode & SIO_REC) {
|
if (hdl->sio.mode & SIO_REC) {
|
||||||
err = snd_pcm_hw_params(hdl->in_pcm, hdl->in_hwp);
|
err = snd_pcm_hw_params(hdl->in_pcm, hdl->in_hwp);
|
||||||
|
@ -915,8 +922,8 @@ sio_alsa_autostart(struct sio_alsa_hdl *hdl)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DPRINTF("sio_alsa_autostart: bad state");
|
DPRINTF("sio_alsa_autostart: bad state");
|
||||||
hdl->sio.eof = 1;
|
//hdl->sio.eof = 1;
|
||||||
return 0;
|
//return 0;
|
||||||
}
|
}
|
||||||
DPRINTF("sio_alsa_autostart: started\n");
|
DPRINTF("sio_alsa_autostart: started\n");
|
||||||
sio_onmove_cb(&hdl->sio, 0);
|
sio_onmove_cb(&hdl->sio, 0);
|
||||||
|
@ -1003,13 +1010,19 @@ sio_alsa_pollfd(struct sio_hdl *sh, struct pollfd *pfd, int events)
|
||||||
struct sio_alsa_hdl *hdl = (struct sio_alsa_hdl *)sh;
|
struct sio_alsa_hdl *hdl = (struct sio_alsa_hdl *)sh;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
DPRINTF("sio_alsa_pollfd: count = %d\n",
|
DPRINTF("sio_alsa_pollfd: count = %d, nfds = %d\n",
|
||||||
snd_pcm_poll_descriptors_count(hdl->out_pcm));
|
snd_pcm_poll_descriptors_count(hdl->out_pcm),
|
||||||
|
hdl->nfds);
|
||||||
|
|
||||||
memset(pfd, 0, sizeof(struct pollfd) * hdl->nfds);
|
memset(pfd, 0, sizeof(struct pollfd) * hdl->nfds);
|
||||||
if (hdl->sio.mode & SIO_PLAY) {
|
if (hdl->sio.mode & SIO_PLAY) {
|
||||||
hdl->onfds = snd_pcm_poll_descriptors(hdl->out_pcm,
|
hdl->onfds = snd_pcm_poll_descriptors(hdl->out_pcm,
|
||||||
pfd, hdl->nfds);
|
pfd, hdl->nfds);
|
||||||
|
if (hdl->onfds < 0) {
|
||||||
|
DALSA("poll descriptors", hdl->onfds);
|
||||||
|
hdl->sio.eof = 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
hdl->onfds = 0;
|
hdl->onfds = 0;
|
||||||
if (hdl->sio.mode & SIO_REC) {
|
if (hdl->sio.mode & SIO_REC) {
|
||||||
|
@ -1033,9 +1046,12 @@ sio_alsa_revents(struct sio_hdl *sh, struct pollfd *pfd)
|
||||||
snd_pcm_state_t istate, ostate;
|
snd_pcm_state_t istate, ostate;
|
||||||
int hw_ptr, nfds;
|
int hw_ptr, nfds;
|
||||||
unsigned short revents, all_revents;
|
unsigned short revents, all_revents;
|
||||||
int err;
|
int i, err;
|
||||||
|
|
||||||
DPRINTF("sio_alsa_revents:\n");
|
for (i = 0; i < hdl->onfds + hdl->infds; i++) {
|
||||||
|
DPRINTF("sio_alsa_revents: pfds[%d].events = %x\n",
|
||||||
|
i, pfd[i].revents);
|
||||||
|
}
|
||||||
|
|
||||||
all_revents = nfds = 0;
|
all_revents = nfds = 0;
|
||||||
if (hdl->sio.mode & SIO_PLAY) {
|
if (hdl->sio.mode & SIO_PLAY) {
|
||||||
|
@ -1074,8 +1090,6 @@ sio_alsa_revents(struct sio_hdl *sh, struct pollfd *pfd)
|
||||||
}
|
}
|
||||||
revents = all_revents;
|
revents = all_revents;
|
||||||
DPRINTF("sio_alsa_revents: revents = %x\n", revents);
|
DPRINTF("sio_alsa_revents: revents = %x\n", revents);
|
||||||
|
|
||||||
#if 0
|
|
||||||
if ((revents & POLLOUT) && (hdl->sio.mode & SIO_PLAY) &&
|
if ((revents & POLLOUT) && (hdl->sio.mode & SIO_PLAY) &&
|
||||||
(ostate == SND_PCM_STATE_RUNNING ||
|
(ostate == SND_PCM_STATE_RUNNING ||
|
||||||
ostate == SND_PCM_STATE_PREPARED)) {
|
ostate == SND_PCM_STATE_PREPARED)) {
|
||||||
|
@ -1142,7 +1156,6 @@ sio_alsa_revents(struct sio_hdl *sh, struct pollfd *pfd)
|
||||||
if ((hdl->sio.mode & SIO_REC) && !sio_alsa_rdrop(hdl))
|
if ((hdl->sio.mode & SIO_REC) && !sio_alsa_rdrop(hdl))
|
||||||
revents &= ~POLLIN;
|
revents &= ~POLLIN;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return revents;
|
return revents;
|
||||||
}
|
}
|
||||||
#endif /* defined USE_ALSA */
|
#endif /* defined USE_ALSA */
|
||||||
|
|
Loading…
Reference in New Issue