音频文件末尾音量逐渐减弱
你好,
我正在做一个处理音频文件的 iPhone 应用程序。应用程序还包含一个音频转换器,因此我可以在我的 /Documents 文件夹中拥有任何音频格式的文件。
我想要的是通过降低末尾的音量并在文件开头淡入来实现平滑的音频文件结尾。
我该怎么做? (只是指出一个方向。一个框架、函数、方法)
我可以使用所有 Apple 音频框架,无论是高级框架还是低级框架。 我什至可以在转换文件时访问音频缓冲区。
提前致谢。
注意:播放时我不需要音频淡入/淡出功能。我需要这个功能已经写在音频文件中。
HI,
I am doing an iphone application that works with audio files. Application also contains an audio converter, so I can potentially have a file of any audio format in my /Documents folder.
What I want is to implement a smooth audio file ending by reducing volume level at the end and fading it in at the beginning of the file.
How can I do that? (just point a direction. a framework, function, method)
I can use all Apple audio frameworks, both high level and low level ones.
I can even access audio buffers while file is being converted.
Thanks in advance.
NOTE: I do not need audio Fade in/out feature while PLAYING it. I need this feature already written in audio file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您正在处理不同的格式,因此最好的选择是在转换数据时在样本级别应用淡入淡出。
如果您离线进行转换,那么您已经知道文件中的样本数量,因此您可以正常处理
X - B
样本(其中X
是总数样本数,B
是淡入淡出持续时间):然后,对于最后一个
B
样本,您可以执行如下操作:这将是线性< /em> 淡出斜坡,所以如果你想要一些更奇特的东西,那么,那就去吧。 ;) 基本上,进行线性淡入淡出的公式是
y = m * x + b
(还记得代数课吗?),在这种情况下你的斜率是1 / B
,y 偏移量为 1.0,这是您要应用的最大音量增益(即无增益)。如果您正在进行实时转换,那么您将需要将
B
样本保留在环形缓冲区中,然后在处理结束时应用上述算法。Because you are dealing with different formats, your best bet here is to apply the fade at the sample level when you are converting the data.
If you are doing the conversion offline, then you already know the number of samples in the file, so you can process
X - B
samples normally (whereX
is the total number of samples andB
is the fade duration):Then, for the last
B
samples, you'd do something like this:That would be for a linear fade slope, so if you want something fancier, well, then go knock yourself out. ;) Basically, the formula for doing a linear fade is
y = m * x + b
(remember algebra class?), where your slope in this case is1 / B
, and the y offset is 1.0, which is the maximum volume gain you want to apply (ie, no gain).If you are doing the conversion in realtime, then you will need to keep
B
samples in a ringbuffer, and then apply the above algorithm when you reach the end of processing.