当前位置:网站首页>alsa播放结束时的杂音问题
alsa播放结束时的杂音问题
2022-04-22 21:22:00 【霍宏鹏】
alsa的音频输出过程
alsa播放音频的原理通过snd_pcm_writei()等函数将音频数据写到alsa的buffer中。alsa启动播放以后,alsa驱动会产生中断,每次中断从buffer中取走period个音频数据帧输出到codec。
音频最后的数据不足一个period
alsa驱动从buffer中是按照一个完整的period个数据帧取走数据的,如果取走的一个period数据中,并不都是音频数据,可能有其他脏数据,那就可能在最后一帧产生噪音。
首先关于buffer和frame的概念还不知道的请参考:
https://huohongpeng.blog.csdn.net/article/details/116235192
具体举一个例子:
一个音频文件中包含10240个frame音频数据,alsa的硬件参数中period大小设置为1024。buffer大小是5120。那么应用程序通过snd_pcm_writei()每次向buffer中写入1024个frame音频帧,写入10次就将音频文件的数据全部送入到了buffer中(如果buffer没有空间应用会阻塞),然后alsa驱动每次从buffer中取走1024个frame,取走10次,这样音频就正常播放完成了。
但是如果音频文件中包含10246个frame音频数据,输入到buffer中的音频就是10个完整的period帧和一个不完整的只包含6个frame的period帧。所以alsa驱动要取11次才能把所有数据取走,而且最后一个period取走的时候,里面只包含了6个frame数据,其他1018个都是未定义的数据,这时候1018个数据输出到codec那就是产生噪声。如果想避免这个情况,应用层就需要将1018个frame填充为静音数据,然后发送给buffer。这样播放最后一个period的时候就不会有噪声了。生成静音数据的api是snd_pcm_format_set_silence().
版权声明
本文为[霍宏鹏]所创,转载请带上原文链接,感谢
https://huohongpeng.blog.csdn.net/article/details/119669092
边栏推荐
- Use of consul
- 最新版去水印+外卖cps小程序源码
- ImportError: cannot import name ‘get_all_providers‘ from ‘onnxruntime.capi._pybind_state‘
- 2022-4-22 Leetcode 91.解码方法
- [Istio是什么?] 还不知道你就out了,一文40分钟快速理解
- jmeter资料及软件
- Return to ladder-l2-025 divide and rule (25 points)
- LeetCode-238-除自身以外数组的乘积
- Solving SCP command secret free login in shell script
- BLE---Advertisement data format & service
猜你喜欢

After five years of graduation, how to increase the monthly salary from 5K to 50W +, what core skills do you need to master?

jmeter资料及软件

Navicat for MySQL 连接 Docker中运行的Mysql出现1251- Client does not support authentication protocol 错误

jmeter视频教学课程

如何用laragon框架运行php文件
![[tool configuration] generated by designer in visual studio Solution to the problem of UI file not being updated in time](/img/71/dbb1cd07189b36ef111f166f695fc8.jpg)
[tool configuration] generated by designer in visual studio Solution to the problem of UI file not being updated in time

Development of infectious disease prediction software based on SEIR model

Qtp11 tutorial

毕业五年,如何从月薪5K涨到年薪50W+,需要掌握哪些核心技能?

QT uses windeployqt Exe packaging program
随机推荐
MySQL尚硅谷课程查缺补漏适合基础(一)
Qtp11 tutorial
input file修改样式
What is the most important part of computer hardware?
新闻速递 I MobTech通过中国信通院“安全专项评测”
How to do a good job in performance pressure measurement: design and construction of pressure measurement environment
Spark-2.4.2 compilation and installation
毕业设计第8周学习记录
LeetCode-209-长度最小的子数组
News Express I mobtech a réussi l'évaluation spéciale de la sécurité de l'Académie chinoise des communications
MySQL is still suitable for Silicon Valley courses (I)
Pytoch note57 pytoch visual network structure
The latest version of watermark + takeout CPS applet source code
cuda10.2安装torch1.9
. net core uses iasyncexceptionfilter to capture global exceptions and return information uniformly
毕业五年,如何从月薪5K涨到年薪50W+,需要掌握哪些核心技能?
R语言数据读取、清洗、一元线性回归
The last lesson of the first stage of C language: inverted string (for example: I like Beijing. Print as: Beijing. Like I)
JMeter data and software
keras逻辑回归进行贷款风险预测