Simplify init function, add defaults for latency offset and buffer size. Remove redundant timer stuff from audio_dummy.c.
This commit is contained in:
+5
-1
@@ -42,7 +42,7 @@ 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;
|
||||
@@ -50,6 +50,10 @@ static int init(int argc, char **argv, config_t *cfgp) {
|
||||
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;
|
||||
|
||||
+3
-17
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+5
-3
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -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()
|
||||
|
||||
+4
-1
@@ -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");
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user