static int sndio_stream_set_volume(cubeb_stream *s, float volume) { DPR("sndio_stream_set_volume(%f)\n", volume); pthread_mutex_lock(&s->mtx); sio_setvol(s->hdl, SIO_MAXVOL * volume); pthread_mutex_unlock(&s->mtx); return CUBEB_OK; }
static void op_set_volume (int left, int right) { /* Ignore balance control, so use unattenuated channel. */ pthread_mutex_lock (&mutex); volume = left > right ? left : right; if (hdl != NULL) sio_setvol (hdl, volume * SIO_MAXVOL / XMMS_MAXVOL); pthread_mutex_unlock (&mutex); }
static int sndio_mixer_set_volume(int l, int r) { sndio_volume = l > r ? l : r; if (hdl == NULL) return -OP_ERROR_NOT_INITIALIZED; if (!sio_setvol(hdl, sndio_volume)) return -OP_ERROR_INTERNAL; return OP_ERROR_SUCCESS; }
/* * misc parameters (volume, etc...) */ static int control(struct ao *ao, enum aocontrol cmd, void *arg) { struct priv *p = ao->priv; ao_control_vol_t *vol = arg; switch (cmd) { case AOCONTROL_GET_VOLUME: if (!p->havevol) return CONTROL_FALSE; vol->left = vol->right = p->vol * 100 / SIO_MAXVOL; break; case AOCONTROL_SET_VOLUME: if (!p->havevol) return CONTROL_FALSE; sio_setvol(p->hdl, vol->left * SIO_MAXVOL / 100); break; default: return CONTROL_UNKNOWN; } return CONTROL_OK; }
int main(int argc, char **argv) { int ch; int tty; struct sio_hdl *hdl; struct termios tio; struct pollfd pfd[2]; char cmd; ssize_t n, len; /* * defaults parameters */ sio_initpar(&par); par.sig = 1; par.bits = 16; par.pchan = 2; par.rate = 44100; if (isatty(STDIN_FILENO)) { fprintf(stderr, "stdin can't be a tty\n"); exit(1); } tty = open("/dev/tty", O_RDWR); if (tty < 0) { perror("/dev/tty"); exit(1); } if (tcgetattr(tty, &tio) < 0) { perror("tcsetattr"); exit(1); } tio.c_lflag &= ~ICANON; tio.c_lflag &= ~ECHO; tio.c_cc[VMIN] = 1; tio.c_cc[VTIME] = 0; if (tcsetattr(tty, TCSAFLUSH, &tio) < 0) { perror("tcsetattr"); exit(1); } while ((ch = getopt(argc, argv, "r:c:e:b:x:")) != -1) { switch(ch) { case 'r': if (sscanf(optarg, "%u", &par.rate) != 1) { fprintf(stderr, "%s: bad rate\n", optarg); exit(1); } break; case 'c': if (sscanf(optarg, "%u", &par.pchan) != 1) { fprintf(stderr, "%s: bad channels\n", optarg); exit(1); } break; case 'e': if (!sio_strtoenc(&par, optarg)) { fprintf(stderr, "%s: bad encoding\n", optarg); exit(1); } break; default: usage(); exit(1); break; } } hdl = sio_open(SIO_DEVANY, SIO_PLAY, 0); if (hdl == NULL) { fprintf(stderr, "sio_open() failed\n"); exit(1); } if (!sio_setpar(hdl, &par)) { fprintf(stderr, "sio_setpar() failed\n"); exit(1); } if (!sio_onvol(hdl, onvol, NULL)) fprintf(stderr, "warning: no volume knob on this device\n"); fprintf(stderr, "use ``+'' and ``-'' to adjust the volume\n"); if (!sio_start(hdl)) { fprintf(stderr, "sio_start() failed\n"); exit(1); } for (;;) { pfd[0].fd = tty; pfd[0].events = POLLIN; sio_pollfd(hdl, &pfd[1], POLLOUT); if (poll(pfd, 2, -1) < 0) { perror("poll"); exit(1); } if (pfd[0].revents & POLLIN) { if (read(tty, &cmd, 1) < 0) { perror("read(tty)"); exit(1); } switch (cmd) { case '+': if (vol < SIO_MAXVOL) { vol++; sio_setvol(hdl, vol); } break; case '-': if (vol > 0) { vol--; sio_setvol(hdl, vol); } break; } } if (sio_revents(hdl, &pfd[1]) & POLLOUT) { len = read(STDIN_FILENO, buf, BUFSZ); if (len < 0) { perror("stdin"); exit(1); } if (len == 0) break; n = sio_write(hdl, buf, len); if (n == 0) { fprintf(stderr, "sio_write: failed\n"); exit(1); } } } sio_close(hdl); return 0; }
static void volume(double vol) { unsigned int v = vol * SIO_MAXVOL; sio_setvol(sio, v); }