ALSA: pcm: Simplify snd_pcm_playback_silence()
Use the existing silence helper codes for simplification. Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
5c7264cfbb
commit
a9cd29e799
@ -44,6 +44,9 @@
|
|||||||
#define trace_hw_ptr_error(substream, reason)
|
#define trace_hw_ptr_error(substream, reason)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static int fill_silence_frames(struct snd_pcm_substream *substream,
|
||||||
|
snd_pcm_uframes_t off, snd_pcm_uframes_t frames);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* fill ring buffer with silence
|
* fill ring buffer with silence
|
||||||
* runtime->silence_start: starting pointer to silence area
|
* runtime->silence_start: starting pointer to silence area
|
||||||
@ -57,7 +60,6 @@ void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_ufram
|
|||||||
{
|
{
|
||||||
struct snd_pcm_runtime *runtime = substream->runtime;
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
||||||
snd_pcm_uframes_t frames, ofs, transfer;
|
snd_pcm_uframes_t frames, ofs, transfer;
|
||||||
char *hwbuf;
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (runtime->silence_size < runtime->boundary) {
|
if (runtime->silence_size < runtime->boundary) {
|
||||||
@ -111,35 +113,8 @@ void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_ufram
|
|||||||
ofs = runtime->silence_start % runtime->buffer_size;
|
ofs = runtime->silence_start % runtime->buffer_size;
|
||||||
while (frames > 0) {
|
while (frames > 0) {
|
||||||
transfer = ofs + frames > runtime->buffer_size ? runtime->buffer_size - ofs : frames;
|
transfer = ofs + frames > runtime->buffer_size ? runtime->buffer_size - ofs : frames;
|
||||||
if (runtime->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED ||
|
err = fill_silence_frames(substream, ofs, transfer);
|
||||||
runtime->access == SNDRV_PCM_ACCESS_MMAP_INTERLEAVED) {
|
snd_BUG_ON(err < 0);
|
||||||
if (substream->ops->fill_silence) {
|
|
||||||
err = substream->ops->fill_silence(substream, 0,
|
|
||||||
frames_to_bytes(runtime, ofs),
|
|
||||||
frames_to_bytes(runtime, transfer));
|
|
||||||
snd_BUG_ON(err < 0);
|
|
||||||
} else {
|
|
||||||
hwbuf = runtime->dma_area + frames_to_bytes(runtime, ofs);
|
|
||||||
snd_pcm_format_set_silence(runtime->format, hwbuf, transfer * runtime->channels);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
unsigned int c;
|
|
||||||
unsigned int channels = runtime->channels;
|
|
||||||
if (substream->ops->fill_silence) {
|
|
||||||
for (c = 0; c < channels; ++c) {
|
|
||||||
err = substream->ops->fill_silence(substream, c,
|
|
||||||
samples_to_bytes(runtime, ofs),
|
|
||||||
samples_to_bytes(runtime, transfer));
|
|
||||||
snd_BUG_ON(err < 0);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
size_t dma_csize = runtime->dma_bytes / channels;
|
|
||||||
for (c = 0; c < channels; ++c) {
|
|
||||||
hwbuf = runtime->dma_area + (c * dma_csize) + samples_to_bytes(runtime, ofs);
|
|
||||||
snd_pcm_format_set_silence(runtime->format, hwbuf, transfer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
runtime->silence_filled += transfer;
|
runtime->silence_filled += transfer;
|
||||||
frames -= transfer;
|
frames -= transfer;
|
||||||
ofs = 0;
|
ofs = 0;
|
||||||
@ -2103,6 +2078,21 @@ static int noninterleaved_copy(struct snd_pcm_substream *substream,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* fill silence on the given buffer position;
|
||||||
|
* called from snd_pcm_playback_silence()
|
||||||
|
*/
|
||||||
|
static int fill_silence_frames(struct snd_pcm_substream *substream,
|
||||||
|
snd_pcm_uframes_t off, snd_pcm_uframes_t frames)
|
||||||
|
{
|
||||||
|
if (substream->runtime->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED ||
|
||||||
|
substream->runtime->access == SNDRV_PCM_ACCESS_MMAP_INTERLEAVED)
|
||||||
|
return interleaved_copy(substream, off, NULL, 0, frames,
|
||||||
|
fill_silence);
|
||||||
|
else
|
||||||
|
return noninterleaved_copy(substream, off, NULL, 0, frames,
|
||||||
|
fill_silence);
|
||||||
|
}
|
||||||
|
|
||||||
/* sanity-check for read/write methods */
|
/* sanity-check for read/write methods */
|
||||||
static int pcm_sanity_check(struct snd_pcm_substream *substream)
|
static int pcm_sanity_check(struct snd_pcm_substream *substream)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user