以编程方式增加音频样本数组的音高 [英] Programmatically increase the pitch of an array of audio samples

查看:17
本文介绍了以编程方式增加音频样本数组的音高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

音频计算界的各位好心人,

我有一组代表录音的样本.假设在 44100Hz 时为 5 秒.我将如何以更高的音调播放?并且可以动态增加和减少音高吗?比如让音高慢慢增加到两倍的速度,然后再降低.

换句话说,我想录制并播放它,就好像它被 d.j.划伤"一样.

伪代码总是受欢迎的.我将用 C 语言编写它.

谢谢,

<小时>

编辑 1

请允许我澄清一下我的意图.我想将播放保持在 44100Hz,因此我需要在播放前处理样本.这也是因为我想将音调增加的音频与以正常速率运行的音频混合.

用另一种方式表达,也许我需要以某种方式在相同数量的样本上缩小音频?那样回放的时候声音会比较快?

<小时>

编辑 2

另外,我想自己做这件事.请不要使用库(除非你觉得我可以挑选代码并找到一些有趣的东西).

<小时>

编辑 3

一段用 C 语言编写的示例代码,它接受 2 个参数(样本数组和音高因子),然后返回一个新音频数组,那就太棒了!

<小时>

PS 我已经开始悬赏这不是因为我认为已经给出的答案无效.我只是认为获得有关该主题的更多反馈会很好.

<小时><小时>

赏金奖

老实说,我希望我可以将赏金分配给几个不同的答案,因为我认为这些答案非常有用.特别感谢 Daniel 向我传递了一些代码,AShelly 和 Hotpaw2 提供了如此详细的回复.

最终虽然我使用了 另一个 SO 问题 由 datageist 引用,因此该奖项授予了他.

再次感谢大家!

解决方案

看看 Nosredna 对这个(非常相似)SO 问题的回答中的大象"论文:怎么做您对重新采样的音频数据进行双三次(或其他非线性)插值?

从第 37 页开始提供示例实现,作为参考,AShelly 的答案对应于线性插值(在同一页面上).稍微调整一下,论文中的任何其他公式都可以插入到该框架中.

要评估给定插值方法的质量(并了解使用更便宜"方案的潜在问题),请查看此页面:

http://www.discodsp.com/highlife/aliasing/

对于比您可能想要处理的更多理论(使用源代码),这也是一个很好的参考:

https://ccrma.stanford.edu/~jos/resample/

Hello kind people of the audio computing world,

I have an array of samples that respresent a recording. Let us say that it is 5 seconds at 44100Hz. How would I play this back at an increased pitch? And is it possible to increase and decrease the pitch dynamically? Like have the pitch slowly increase to double the speed and then back down.

In other words I want to take a recording and play it back as if it is being 'scratched' by a d.j.

Pseudocode is always welcomed. I will be writing this up in C.

Thanks,


EDIT 1

Allow me to clarify my intentions. I want to keep the playback at 44100Hz and so therefore I need to manipulate the samples before playback. This is also because I would want to mix the audio that has an increased pitch with audio that is running at a normal rate.

Expressed in another way, maybe I need to shrink the audio over the same number of samples somehow? That way when it is played back it will sound faster?


EDIT 2

Also, I would like to do this myself. No libraries please (unless you feel I could pick through the code and find something interesting).


EDIT 3

A sample piece of code written in C that takes 2 arguments (array of samples and pitch factor) and then returns an array of the new audio would be fantastic!


PS I've started a bounty on this not because I don't think the answers already given aren't valid. I just thought it would be good to get more feedback on the subject.



AWARD OF BOUNTY

Honestly I wish I could distribute the bounty over several different answers as they were quite a few that I thought were super helpful. Special shoutout to Daniel for passing me some code and AShelly and Hotpaw2 for putting in such detailed responses.

Ultimately though I used an answer from another SO question referenced by datageist and so the award goes to him.

Thanks again everyone!

解决方案

Take a look at the "Elephant" paper in Nosredna's answer to this (very similar) SO question: How do you do bicubic (or other non-linear) interpolation of re-sampled audio data?

Sample implementations are provided starting on page 37, and for reference, AShelly's answer corresponds to linear interpolation (on that same page). With a little tweaking, any of the other formulas in the paper could be plugged into that framework.

For evaluating the quality of a given interpolation method (and understanding the potential problems with using "cheaper" schemes), take a look at this page:

http://www.discodsp.com/highlife/aliasing/

For more theory than you probably want to deal with (with source code), this is a good reference as well:

https://ccrma.stanford.edu/~jos/resample/

这篇关于以编程方式增加音频样本数组的音高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆