如何发挥组合声音仿佛从声音产生物体人群发出 [英] How to play combined sound as if emanating from a crowd of sound-producing objects

查看:152
本文介绍了如何发挥组合声音仿佛从声音产生物体人群发出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想想看,我有细小发声类的100个实例。每个细小发声的对象能分别发出吱呀声。每个细小发声实体使用相同的.mp3资源。当所有的squeakers都在屏幕上psented一起$ P $(例如,作为小字符),我想他们都在大约吱(但不完全)的同时,使他们联合尖叫声,听到一起squeakers的人群。

Consider that I have 100 instances of a "squeaker" class. Each "squeaker" object is capable of individually emitting a squeak sound. Each squeaker entity uses the same .mp3 resource. When all the squeakers are presented together on screen (for example as little characters), I want them all to squeak at approximately (but not exactly) the same time so that their combined squeaks are heard together as a crowd of squeakers.

定位的iOS,你有什么建议的方法(和音频/音框架)?有没有人这样做呢? code样?

Targeting iOS, what approach (and audio/sound framework) do you recommend? Has anyone done this before? Code samples?

推荐答案

这可能是最好的建设这个像笑轨道,在您使用的音频编辑器将多个尖叫声组合成一个MP3文件,你再播放在一个循环(该文件可以而且应该比单个吱长得多)。

It might be best to build this like a "laugh track", where you use an audio editor to combine multiple squeaks into one MP3 file, which you then play in a loop (this file could and should be much longer than a single squeak).

通过尝试来呈现100作为声音的任何单独的声音扮演的情况下,你会运行到同一类的声音和软件合成器的开发者遇到的延迟问题的。保持100语音计数小于25毫秒左右的总延迟难以现代PC上做的,更加困难(或不可能)在iPhone / iPad的事情。

By trying to render 100 sounds as separate sound-playing instances of whatever, you'd be running into the same sort of voice and latency problems encountered by developers of software synthesizers. Maintaining a voice count of 100 with an overall latency of less than 25 milliseconds or so is difficult to do on a modern PC, and much more difficult (or impossible) to do on an iPhone/iPad.

一般而言,语音和延迟重新present一个基本工程折衷:它相当容易有一个移动设备上的低延迟合成引擎,但是这只能在极少数的声音来实现(即不同的并发的声音)。相反(像我自己的软件合成引擎),你可以有,可以处理声音的有效无限数量的发动机,但有一个非常高的延迟(许多秒级)。

Generally speaking, voice and latency represent a fundamental engineering tradeoff: it's fairly easy to have a low-latency synthesis engine on a mobile device, but this can only be achieved with a very small number of voices (i.e. distinct concurrent sounds). Conversely (like my own software synthesis engine), you can have an engine that can handle an effectively infinite number of voices, but with a very high latency (on the order of many seconds).

更新:生成您自己的声音编程是一个极好的主意。您可以使用 AVAudioPlayer 类iPhone做到这一点相对容易。通常情况下,这个类是利用其 initWithURL 方法,它是用来从文件中加载音频数据初始化。

Update: generating your own sounds programmatically is an excellent idea. You can do this relatively easily in iPhone using the AVAudioPlayer class. Normally, this class is initialized using its initWithURL method, which is used to load audio data from a file.

在你的情况,你要改为使用 initWithData 方法。在这里,您传递一个的NSData 对象,这基本上是一个字节的块。在这种情况下,你想要的字节块是一个内存WAV文件,其中将包括一个44字节的头后面的2个字节的整数,从而重新presents实际样本数据的数组。

In your case, you want to instead use the initWithData method. You pass an NSData object here, which is basically just a block of bytes. In this case, you want the block of bytes to be an in-memory WAV file, which will consist of a 44-byte header followed by an array of 2-byte integers, which represents the actual sample data.

您在标题(的东西,如采样率,采样位数,信道数等)所设置的值,然后使用你喜欢的算法计算的样本值。一个简单的波入手一件好事,但这将只是生产一个无聊的基调。更有趣的声音(和一个可能是接近你要找的内容)被称为啁啾 - 这基本上是一个做空为主罪波的声音,但高频率的正弦波的频率发生变化声音的播放过程中低频。

You set the values in the header (stuff like sample rate, bits per sample, number of channels etc.) and then calculate the sample values using whatever algorithm you like. A simple sin wave is a good thing to start with, but this will just produce a boring tone. A more interesting sound (and one that might be close to what you're looking for) is called a "chirp" - this is basically a short sin-wave-based sound, but the frequency of the sin wave changes from high frequency to low frequency during the sound's playback.

对不起,我有大量的音频code对C#和Java,但没有还没有为iPhone。希望我在这里加入将帮助你谷歌这一点。你基本上只需要弄清楚两件事情:1)如何使用 AVAudioPlayer 使用 initWithData ,以及文件格式WAV文件。

Sorry, I have tons of audio code for C# and Java, but nothing yet for the iPhone. Hopefully what I've added here will help you google for this. You basically just need to figure out two things: 1) how to use AVAudioPlayer using initWithData, and the file format of a WAV file.

这篇关于如何发挥组合声音仿佛从声音产生物体人群发出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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