diff options
Diffstat (limited to 'audio/paaudio.c')
-rw-r--r-- | audio/paaudio.c | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/audio/paaudio.c b/audio/paaudio.c index 9cf685d30..fb4510e42 100644 --- a/audio/paaudio.c +++ b/audio/paaudio.c @@ -33,13 +33,11 @@ typedef struct { static struct { int samples; - int divisor; char *server; char *sink; char *source; } conf = { - .samples = 1024, - .divisor = 2, + .samples = 4096, }; static void GCC_FMT_ATTR (2, 3) qpa_logerr (int err, const char *fmt, ...) @@ -57,9 +55,6 @@ static void *qpa_thread_out (void *arg) { PAVoiceOut *pa = arg; HWVoiceOut *hw = &pa->hw; - int threshold; - - threshold = conf.divisor ? hw->samples / conf.divisor : 0; if (audio_pt_lock (&pa->pt, AUDIO_FUNC)) { return NULL; @@ -73,7 +68,7 @@ static void *qpa_thread_out (void *arg) goto exit; } - if (pa->live > threshold) { + if (pa->live > 0) { break; } @@ -82,8 +77,8 @@ static void *qpa_thread_out (void *arg) } } - decr = to_mix = pa->live; - rpos = hw->rpos; + decr = to_mix = audio_MIN (pa->live, conf.samples >> 2); + rpos = pa->rpos; if (audio_pt_unlock (&pa->pt, AUDIO_FUNC)) { return NULL; @@ -110,8 +105,8 @@ static void *qpa_thread_out (void *arg) return NULL; } - pa->live = 0; pa->rpos = rpos; + pa->live -= decr; pa->decr += decr; } @@ -152,9 +147,6 @@ static void *qpa_thread_in (void *arg) { PAVoiceIn *pa = arg; HWVoiceIn *hw = &pa->hw; - int threshold; - - threshold = conf.divisor ? hw->samples / conf.divisor : 0; if (audio_pt_lock (&pa->pt, AUDIO_FUNC)) { return NULL; @@ -168,7 +160,7 @@ static void *qpa_thread_in (void *arg) goto exit; } - if (pa->dead > threshold) { + if (pa->dead > 0) { break; } @@ -177,8 +169,8 @@ static void *qpa_thread_in (void *arg) } } - incr = to_grab = pa->dead; - wpos = hw->wpos; + incr = to_grab = audio_MIN (pa->dead, conf.samples >> 2); + wpos = pa->wpos; if (audio_pt_unlock (&pa->pt, AUDIO_FUNC)) { return NULL; @@ -295,6 +287,7 @@ static int qpa_init_out (HWVoiceOut *hw, struct audsettings *as) { int error; static pa_sample_spec ss; + static pa_buffer_attr ba; struct audsettings obt_as = *as; PAVoiceOut *pa = (PAVoiceOut *) hw; @@ -302,6 +295,15 @@ static int qpa_init_out (HWVoiceOut *hw, struct audsettings *as) ss.channels = as->nchannels; ss.rate = as->freq; + /* + * qemu audio tick runs at 250 Hz (by default), so processing + * data chunks worth 4 ms of sound should be a good fit. + */ + ba.tlength = pa_usec_to_bytes (4 * 1000, &ss); + ba.minreq = pa_usec_to_bytes (2 * 1000, &ss); + ba.maxlength = -1; + ba.prebuf = -1; + obt_as.fmt = pa_to_audfmt (ss.format, &obt_as.endianness); pa->s = pa_simple_new ( @@ -312,7 +314,7 @@ static int qpa_init_out (HWVoiceOut *hw, struct audsettings *as) "pcm.playback", &ss, NULL, /* channel map */ - NULL, /* buffering attributes */ + &ba, /* buffering attributes */ &error ); if (!pa->s) { @@ -323,6 +325,7 @@ static int qpa_init_out (HWVoiceOut *hw, struct audsettings *as) audio_pcm_init_info (&hw->info, &obt_as); hw->samples = conf.samples; pa->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift); + pa->rpos = hw->rpos; if (!pa->pcm_buf) { dolog ("Could not allocate buffer (%d bytes)\n", hw->samples << hw->info.shift); @@ -377,6 +380,7 @@ static int qpa_init_in (HWVoiceIn *hw, struct audsettings *as) audio_pcm_init_info (&hw->info, &obt_as); hw->samples = conf.samples; pa->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift); + pa->wpos = hw->wpos; if (!pa->pcm_buf) { dolog ("Could not allocate buffer (%d bytes)\n", hw->samples << hw->info.shift); @@ -472,12 +476,6 @@ struct audio_option qpa_options[] = { .descr = "buffer size in samples" }, { - .name = "DIVISOR", - .tag = AUD_OPT_INT, - .valp = &conf.divisor, - .descr = "threshold divisor" - }, - { .name = "SERVER", .tag = AUD_OPT_STR, .valp = &conf.server, |