Skip to content

Commit

Permalink
Simplify init function, add defaults for latency offset and buffer si…
Browse files Browse the repository at this point in the history
…ze. Remove redundant timer stuff from audio_dummy.c.
  • Loading branch information
mikebrady committed Jun 1, 2015
1 parent e91cdda commit 54250f7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
6 changes: 5 additions & 1 deletion audio_ao.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,18 @@ static void help(void) {
);
}

static int init(int argc, char **argv, config_t *cfgp) {
static int init(int argc, char **argv) {
ao_initialize();
int driver = ao_default_driver_id();
ao_option *ao_opts = NULL;

optind = 1; // optind=0 is equivalent to optind=1 plus special behaviour
argv--; // so we shift the arguments to satisfy getopt()
argc++;

config.audio_backend_buffer_desired_length = 44100; // one second.
config.audio_backend_latency_offset = 0;

// some platforms apparently require optreset = 1; - which?
int opt;
char *mid;
Expand Down
20 changes: 3 additions & 17 deletions audio_dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
int Fs;
long long starttime, samples_played;

static int init(int argc, char **argv, config_t *cfgp) {
static int init(int argc, char **argv) {
return 0;
}

Expand All @@ -43,28 +43,14 @@ static void start(int sample_rate) {
Fs = sample_rate;
starttime = 0;
samples_played = 0;
printf("dummy audio output started at Fs=%d Hz\n", sample_rate);
debug(1,"dummy audio output started at Fs=%d Hz\n", sample_rate);
}

static void play(short buf[], int samples) {
struct timeval tv;

// this is all a bit expensive but it's long-term stable.
gettimeofday(&tv, NULL);

long long nowtime = tv.tv_usec + 1e6*tv.tv_sec;

if (!starttime)
starttime = nowtime;

samples_played += samples;

long long finishtime = starttime + samples_played * 1e6 / Fs;
usleep(finishtime - nowtime);
}

static void stop(void) {
printf("dummy audio stopped\n");
debug(1,"dummy audio stopped\n");
}

static void help(void) {
Expand Down
8 changes: 5 additions & 3 deletions audio_pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ static void stop(void) {
close(fd);
}

static int init(int argc, char **argv, config_t *cfgp) {
static int init(int argc, char **argv) {
config.audio_backend_buffer_desired_length = 44100; // one second.
config.audio_backend_latency_offset = 0;

if (cfgp!=NULL) {
if (config.cfg!=NULL) {
/* Get the Output Pipename. */
const char *str;
if(config_lookup_string(cfgp, "pipe.name", &str)) {
if(config_lookup_string(config.cfg, "pipe.name", &str)) {
pipename = (char*)str;
}
}
Expand Down
6 changes: 5 additions & 1 deletion audio_pulse.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ static void help(void) {
);
}

static int init(int argc, char **argv, config_t *cfgp) {
static int init(int argc, char **argv) {

pulse_options.apname = config.apname;

config.audio_backend_buffer_desired_length = 44100; // one second.
config.audio_backend_latency_offset = 0;

optind = 1; // optind=0 is equivalent to optind=1 plus special behaviour
argv--; // so we shift the arguments to satisfy getopt()
Expand Down
5 changes: 4 additions & 1 deletion audio_sndio.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
static struct sio_hdl *sio;
static struct sio_par par;

static int init(int argc, char **argv, config_t *cfgp) {
static int init(int argc, char **argv) {
sio = sio_open(SIO_DEVANY, SIO_PLAY, 0);
if (!sio)
die("sndio: cannot connect to sound server");
Expand All @@ -40,6 +40,9 @@ static int init(int argc, char **argv, config_t *cfgp) {
die("sndio: failed to set audio parameters");
if (!sio_getpar(sio, &par))
die("sndio: failed to get audio parameters");

config.audio_backend_buffer_desired_length = 44100; // one second.
config.audio_backend_latency_offset = 0;

return 0;
}
Expand Down

0 comments on commit 54250f7

Please sign in to comment.