干货,记一次解决录音杂音问题
嵌入式Linux
共 2957字,需浏览 6分钟
·
2021-01-22 23:26
之前音频相关的文章
1、问题
2、排查过程
3、解决
snd_pcm_capture_ioctl1()
->snd_pcm_lib_read()
-->snd_pcm_lib_read_transfer()
diff --git a/kernel-4.4/include/sound/pcm.h b/kernel-4.4/include/sound/pcm.h
old mode 100644
new mode 100755
index b0be092799..ecaca74273
--- a/kernel-4.4/include/sound/pcm.h
+++ b/kernel-4.4/include/sound/pcm.h
@@ -460,6 +460,7 @@ struct snd_pcm_substream {
/* -- assigned files -- */
void *file;
int ref_count;
+ int once_f;/*weiqifa modify*/
atomic_t mmap_count;
unsigned int f_flags;
void (*pcm_release)(struct snd_pcm_substream *);
diff --git a/kernel-4.4/sound/core/pcm_lib.c b/kernel-4.4/sound/core/pcm_lib.c
old mode 100644
new mode 100755
index 17e69848d3..8a057f1445
--- a/kernel-4.4/sound/core/pcm_lib.c
+++ b/kernel-4.4/sound/core/pcm_lib.c
@@ -2220,6 +2220,11 @@ static int snd_pcm_lib_read_transfer(struct snd_pcm_substream *substream,
return err;
} else {
char *hwbuf = runtime->dma_area + frames_to_bytes(runtime, hwoff);
+ if(substream->once_f < 1)
+ {
+ memset(hwbuf,0,frames_to_bytes(runtime, frames));
+ substream->once_f++;
+ }
if (copy_to_user(buf, hwbuf, frames_to_bytes(runtime, frames)))
return -EFAULT;
}
diff --git a/kernel-4.4/sound/core/pcm_native.c b/kernel-4.4/sound/core/pcm_native.c
old mode 100644
new mode 100755
index 3de88974ee..0ead670a38
--- a/kernel-4.4/sound/core/pcm_native.c
+++ b/kernel-4.4/sound/core/pcm_native.c
@@ -2229,6 +2229,7 @@ static void pcm_release_private(struct snd_pcm_substream *substream)
void snd_pcm_release_substream(struct snd_pcm_substream *substream)
{
+ substream->once_f = 0;
substream->ref_count--;
if (substream->ref_count > 0)
return;
@@ -2277,6 +2278,7 @@ int snd_pcm_open_substream(struct snd_pcm *pcm, int stream,
goto error;
substream->hw_opened = 1;
+ substream->once_f = 0;
err = snd_pcm_hw_constraints_complete(substream);
if (err < 0) {
评论