iphone - How to play combined sound as if emanating from a crowd of sound-producing objects -
consider have 100 instances of "squeaker" class. each "squeaker" object capable of individually emitting squeak sound. each squeaker entity uses same .mp3 resource. when squeakers presented on screen (for example little characters), want them squeak @ approximately (but not exactly) same time combined squeaks heard crowd of squeakers.
targeting ios, approach (and audio/sound framework) recommend? has done before? code samples?
it might best build "laugh track", use audio editor combine multiple squeaks 1 mp3 file, play in loop (this file , should longer single squeak).
by trying render 100 sounds separate sound-playing instances of whatever, you'd running same sort of voice , latency problems encountered developers of software synthesizers. maintaining voice count of 100 overall latency of less 25 milliseconds or difficult on modern pc, , more difficult (or impossible) on iphone/ipad.
generally speaking, voice , latency represent fundamental engineering tradeoff: it's easy have low-latency synthesis engine on mobile device, can achieved small number of voices (i.e. distinct concurrent sounds). conversely (like own software synthesis engine), can have engine can handle infinite number of voices, high latency (on order of many seconds).
update: generating own sounds programmatically excellent idea. can relatively in iphone using avaudioplayer class. normally, class initialized using initwithurl method, used load audio data file.
in case, want instead use initwithdata method. pass nsdata object here, block of bytes. in case, want block of bytes in-memory wav file, consist of 44-byte header followed array of 2-byte integers, represents actual sample data.
you set values in header (stuff sample rate, bits per sample, number of channels etc.) , calculate sample values using whatever algorithm like. simple sin wave thing start with, produce boring tone. more interesting sound (and 1 might close you're looking for) called "chirp" - short sin-wave-based sound, frequency of sin wave changes high frequency low frequency during sound's playback.
sorry, have tons of audio code c# , java, nothing yet iphone. i've added here google this. need figure out 2 things: 1) how use avaudioplayer using initwithdata, , file format of wav file.
Comments
Post a Comment