i'm new xcode , objc , i'm having trouble playing multiple audio files through multiple avaudioplayers.
in theory app simple, takes cars rpm , load values , plays sound based on values.
so, have 13 sound samples range of rpm values. code figures out volume , rate should played @ replicate correct engine sounds in app - note playing @ same time, it's volume , rate controls how sound.
so, figure out volumes , rates (this snippet) :
if ((rpm > 4989) && (rpm < 5339)) { av1pitch = 0.0f; av2pitch = 0.0f; av3pitch = 0.0f; av4pitch = 0.0f; av5pitch = 0.0f; av6pitch = 0.0f; av7pitch = 0.0f; av8pitch = 0.0f; av9pitch = rpm / 4989.0f; av10pitch = rpm / 5338.0f; av11pitch = 0.0f; av12pitch = 0.0f; av13pitch = 0.0f; av1volume = 0.0f; av2volume = 0.0f; av3volume = 0.0f; av4volume = 0.0f; av5volume = 0.0f; av6volume = 0.0f; av7volume = 0.0f; av8volume = 0.0f; av9volume = av9pitch - 1.0f; av10volume = 1.0f - av9volume; av11volume = 0.0f; av12volume = 0.0f; av13volume = 0.0f; }
then go through 13 avaudioplayers , set players volume , rate :
if (audioplayer2000.isplaying) { //already playing, ready volume / pitch adjustments audioplayer2000.volume = av2volume; audioplayer2000.rate = av2pitch; } else{ //nothing playing - play file nsurl *url = [nsurl fileurlwithpath:[nsstring stringwithformat:@"%@/1052.wav", [[nsbundle mainbundle] resourcepath]]]; nserror *error; //nsdata *songfile2 = [[nsdata alloc] initwithcontentsofurl:url options:nsdatareadingmappedifsafe error:&error]; audioplayer2000 = [[avaudioplayer alloc] initwithcontentsofurl:url error:&error]; //audioplayer2000 = [[avaudioplayer alloc] initwithdata:songfile2 error:&error]; audioplayer2000.numberofloops = -1; audioplayer2000.enablerate = yes; audioplayer2000.rate = av2pitch; audioplayer2000.volume = av2volume; if (audioplayer2000 == nil) { nslog([error description]); } else{ [audioplayer2000 play]; } }
this works ok whilst playing 1 file, change rpm value should playing file, of sounds stop no matter rpm value is.
the way i've found stop call setcurrenttime on players - results in 'jittery' playback.
i thought might arc playing up, created properties players.
am missing fundamental here? or not taking right approach?
Comments
Post a Comment