音频文件末尾音量逐渐减弱

发布于 2024-10-01 22:18:32 字数 318 浏览 2 评论 0原文

你好,

我正在做一个处理音频文件的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

意中人 2024-10-08 22:18:32

由于您正在处理不同的格式,因此最好的选择是在转换数据时在样本级别应用淡入淡出。

如果您离线进行转换,那么您已经知道文件中的样本数量,因此您可以正常处理 X - B 样本(其中 X 是总数样本数,B 是淡入淡出持续时间):

int i = 0;
for(i = 0; i < X - B; i++) {
  sampleToBeConverted[i] = inputSample[i]
}

然后,对于最后一个 B 样本,您可以执行如下操作:

for(int j = 0; j < B; j++, i++) {
  sampleToBeConverted[i] = inputSample[i] * (1.0 - (j / 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 (where X is the total number of samples and B is the fade duration):

int i = 0;
for(i = 0; i < X - B; i++) {
  sampleToBeConverted[i] = inputSample[i]
}

Then, for the last B samples, you'd do something like this:

for(int j = 0; j < B; j++, i++) {
  sampleToBeConverted[i] = inputSample[i] * (1.0 - (j / B));
}

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 is 1 / 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文