diff options
author | Max Kellermann <max@duempel.org> | 2013-02-04 14:29:15 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-02-04 14:30:16 +0100 |
commit | e06dd129ddabfad12162302f9a1c4293ce459a2d (patch) | |
tree | 53fa5da16a028ec8872ee6305ab3d51250010689 | |
parent | 00baddcd9ece2f79b407d57a79902aa495cf6f88 (diff) | |
download | mpd-e06dd129ddabfad12162302f9a1c4293ce459a2d.tar.gz mpd-e06dd129ddabfad12162302f9a1c4293ce459a2d.tar.xz mpd-e06dd129ddabfad12162302f9a1c4293ce459a2d.zip |
output/alsa: move code to alsa_write_silence()
Diffstat (limited to '')
-rw-r--r-- | src/output/AlsaOutputPlugin.cxx | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/output/AlsaOutputPlugin.cxx b/src/output/AlsaOutputPlugin.cxx index b4c8d938b..c50b97c13 100644 --- a/src/output/AlsaOutputPlugin.cxx +++ b/src/output/AlsaOutputPlugin.cxx @@ -682,6 +682,28 @@ alsa_open(struct audio_output *ao, struct audio_format *audio_format, GError **e return true; } +/** + * Write silence to the ALSA device. + */ +static void +alsa_write_silence(AlsaOutput *ad, snd_pcm_uframes_t nframes) +{ + size_t nbytes = nframes * ad->out_frame_size; + void *buffer = g_malloc(nbytes); + snd_pcm_hw_params_t *params; + snd_pcm_format_t format; + unsigned channels; + + snd_pcm_hw_params_alloca(¶ms); + snd_pcm_hw_params_current(ad->pcm, params); + snd_pcm_hw_params_get_format(params, &format); + snd_pcm_hw_params_get_channels(params, &channels); + + snd_pcm_format_set_silence(format, buffer, nframes * channels); + ad->writei(ad->pcm, buffer, nframes); + g_free(buffer); +} + static int alsa_recover(AlsaOutput *ad, int err) { @@ -732,20 +754,7 @@ alsa_drain(struct audio_output *ao) period */ snd_pcm_uframes_t nframes = ad->period_frames - ad->period_position; - size_t nbytes = nframes * ad->out_frame_size; - void *buffer = g_malloc(nbytes); - snd_pcm_hw_params_t *params; - snd_pcm_format_t format; - unsigned channels; - - snd_pcm_hw_params_alloca(¶ms); - snd_pcm_hw_params_current(ad->pcm, params); - snd_pcm_hw_params_get_format(params, &format); - snd_pcm_hw_params_get_channels(params, &channels); - - snd_pcm_format_set_silence(format, buffer, nframes * channels); - ad->writei(ad->pcm, buffer, nframes); - g_free(buffer); + alsa_write_silence(ad, nframes); } snd_pcm_drain(ad->pcm); |