diff options
Diffstat (limited to 'audio/out')
-rw-r--r-- | audio/out/ao.c | 12 | ||||
-rw-r--r-- | audio/out/ao.h | 2 | ||||
-rw-r--r-- | audio/out/ao_alsa.c | 8 | ||||
-rw-r--r-- | audio/out/ao_oss.c | 11 |
4 files changed, 20 insertions, 13 deletions
diff --git a/audio/out/ao.c b/audio/out/ao.c index 88f0b2223d..55db34becb 100644 --- a/audio/out/ao.c +++ b/audio/out/ao.c @@ -250,6 +250,18 @@ void ao_resume(struct ao *ao) ao->driver->resume(ao); } +int ao_play_silence(struct ao *ao, int samples) +{ + if (samples <= 0 || AF_FORMAT_IS_SPECIAL(ao->format)) + return 0; + int s = ao->channels.num * (af_fmt2bits(ao->format) / 8); + char *p = talloc_size(NULL, samples * s); + af_fill_silence(p, samples * s, ao->format); + int r = ao_play(ao, p, samples * s, 0); + talloc_free(p); + return r; +} + bool ao_chmap_sel_adjust(struct ao *ao, const struct mp_chmap_sel *s, struct mp_chmap *map) { diff --git a/audio/out/ao.h b/audio/out/ao.h index c6ad5455d2..159a6adc0f 100644 --- a/audio/out/ao.h +++ b/audio/out/ao.h @@ -103,6 +103,8 @@ void ao_reset(struct ao *ao); void ao_pause(struct ao *ao); void ao_resume(struct ao *ao); +int ao_play_silence(struct ao *ao, int samples); + bool ao_chmap_sel_adjust(struct ao *ao, const struct mp_chmap_sel *s, struct mp_chmap *map); bool ao_chmap_sel_get_def(struct ao *ao, const struct mp_chmap_sel *s, diff --git a/audio/out/ao_alsa.c b/audio/out/ao_alsa.c index bdfd8fae76..5816ee5f5f 100644 --- a/audio/out/ao_alsa.c +++ b/audio/out/ao_alsa.c @@ -78,7 +78,6 @@ struct priv { } while (0) static float get_delay(struct ao *ao); -static int play(struct ao *ao, void *data, int len, int flags); static void uninit(struct ao *ao, bool immed); static void alsa_error_handler(const char *file, int line, const char *function, @@ -612,11 +611,8 @@ static void audio_resume(struct ao *ao) MP_VERBOSE(ao, "resume not supported by hardware\n"); err = snd_pcm_prepare(p->alsa); CHECK_ALSA_ERROR("pcm prepare error"); - if (p->prepause_frames) { - void *silence = calloc(p->prepause_frames, p->bytes_per_sample); - play(ao, silence, p->prepause_frames * p->bytes_per_sample, 0); - free(silence); - } + if (p->prepause_frames) + ao_play_silence(ao, p->prepause_frames); } alsa_error: ; diff --git a/audio/out/ao_oss.c b/audio/out/ao_oss.c index 556f3c25c9..db9847851d 100644 --- a/audio/out/ao_oss.c +++ b/audio/out/ao_oss.c @@ -508,16 +508,13 @@ static int play(struct ao *ao, void *data, int len, int flags) static void audio_resume(struct ao *ao) { struct priv *p = ao->priv; - int fillcnt; #ifndef SNDCTL_DSP_RESET reset(ao); #endif - fillcnt = get_space(ao) - p->prepause_space; - if (fillcnt > 0 && !(ao->format & AF_FORMAT_SPECIAL_MASK)) { - void *silence = calloc(fillcnt, 1); - play(ao, silence, fillcnt, 0); - free(silence); - } + int fillframes = (get_space(ao) - p->prepause_space) / + (af_fmt2bits(ao->format) / 8 * ao->channels.num); + if (fillframes > 0) + ao_play_silence(ao, fillframes); } // return: delay in seconds between first and last sample in buffer |