draft-ietf-codec-opus.xml 377 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685
  1. <?xml version="1.0" encoding="US-ASCII"?>
  2. <!DOCTYPE rfc SYSTEM 'rfc2629.dtd'>
  3. <?rfc toc="yes" symrefs="yes" compact="yes" subcompact="no" rfcedstyle="yes"?>
  4. <rfc ipr="trust200902" submissionType="IETF" category="std" consensus="yes" number="6716">
  5. <front>
  6. <title abbrev="Interactive Audio Codec">Definition of the Opus Audio Codec</title>
  7. <author initials="JM" surname="Valin" fullname="Jean-Marc Valin">
  8. <organization>Mozilla Corporation</organization>
  9. <address>
  10. <postal>
  11. <street>650 Castro Street</street>
  12. <city>Mountain View</city>
  13. <region>CA</region>
  14. <code>94041</code>
  15. <country>USA</country>
  16. </postal>
  17. <phone>+1 650 903-0800</phone>
  18. <email>jmvalin@jmvalin.ca</email>
  19. </address>
  20. </author>
  21. <author initials="K." surname="Vos" fullname="Koen Vos">
  22. <organization>Skype Technologies S.A.</organization>
  23. <address>
  24. <postal>
  25. <street>Soder Malarstrand 43</street>
  26. <city>Stockholm</city>
  27. <region></region>
  28. <code>11825</code>
  29. <country>SE</country>
  30. </postal>
  31. <phone>+46 73 085 7619</phone>
  32. <email>koenvos74@gmail.com</email>
  33. </address>
  34. </author>
  35. <author initials="T." surname="Terriberry" fullname="Timothy B. Terriberry">
  36. <organization>Mozilla Corporation</organization>
  37. <address>
  38. <postal>
  39. <street>650 Castro Street</street>
  40. <city>Mountain View</city>
  41. <region>CA</region>
  42. <code>94041</code>
  43. <country>USA</country>
  44. </postal>
  45. <phone>+1 650 903-0800</phone>
  46. <email>tterriberry@mozilla.com</email>
  47. </address>
  48. </author>
  49. <date month="August" year="2012" />
  50. <area>General</area>
  51. <workgroup></workgroup>
  52. <!-- [rfced] Please insert any keywords (beyond those that appear in
  53. the title) for use on http://www.rfc-editor.org/rfcsearch.html. -->
  54. <keyword>voice, music, lossy compression, VOIP</keyword>
  55. <abstract>
  56. <t>
  57. This document defines the Opus interactive speech and audio codec.
  58. Opus is designed to handle a wide range of interactive audio applications,
  59. including Voice over IP, videoconferencing, in-game chat, and even live,
  60. distributed music performances.
  61. It scales from low bitrate narrowband speech at 6&nbsp;kbit/s to very high
  62. quality stereo music at 510&nbsp;kbit/s.
  63. Opus uses both Linear Prediction (LP) and the Modified Discrete Cosine
  64. Transform (MDCT) to achieve good compression of both speech and music.
  65. </t>
  66. </abstract>
  67. </front>
  68. <middle>
  69. <section anchor="introduction" title="Introduction">
  70. <t>
  71. The Opus codec is a real-time interactive audio codec designed to meet the requirements
  72. described in <xref target="REQUIREMENTS"></xref>.
  73. It is composed of a layer based on Linear Prediction (LP)&nbsp;<xref target="LPC"/>
  74. and a layer based on the Modified Discrete Cosine Transform
  75. (MDCT)&nbsp;<xref target="MDCT"/>.
  76. The main idea behind using two layers is as follows: in speech, linear prediction
  77. techniques (such as Code-Excited Linear Prediction, or CELP) code low frequencies more efficiently than transform
  78. (e.g., MDCT) domain techniques, while the situation is reversed for music and
  79. higher speech frequencies.
  80. Thus, a codec with both layers available can operate over a wider range than
  81. either one alone and can achieve better quality by combining them than by
  82. using either one individually.
  83. </t>
  84. <t>
  85. The primary normative part of this specification is provided by the source code
  86. in <xref target="ref-implementation"></xref>.
  87. Only the decoder portion of this software is normative, though a
  88. significant amount of code is shared by both the encoder and decoder.
  89. <xref target="conformance"/> provides a decoder conformance test.
  90. The decoder contains a great deal of integer and fixed-point arithmetic that
  91. needs to be performed exactly, including all rounding considerations, so any
  92. useful specification requires domain-specific symbolic language to adequately
  93. define these operations.
  94. Additionally, any
  95. conflict between the symbolic representation and the included reference
  96. implementation must be resolved. For the practical reasons of compatibility and
  97. testability, it would be advantageous to give the reference implementation
  98. priority in any disagreement. The C language is also one of the most
  99. widely understood, human-readable symbolic representations for machine
  100. behavior.
  101. For these reasons, this RFC uses the reference implementation as the sole
  102. symbolic representation of the codec.
  103. </t>
  104. <t>While the symbolic representation is unambiguous and complete, it is not
  105. always the easiest way to understand the codec's operation. For this reason,
  106. this document also describes significant parts of the codec in prose and
  107. takes the opportunity to explain the rationale behind many of the more
  108. surprising elements of the design.
  109. <!-- [rfced] We wondering whether "English" should be replaced with "prose" in
  110. the following:
  111. Section 5.3.5
  112. For this reason,
  113. this document also describes significant parts of the codec in English and
  114. takes the opportunity to explain the rationale behind many of the more
  115. surprising elements of the design.
  116. Section 6:
  117. Although this document includes an English description of the codec,
  118. should the description contradict the source code of the reference
  119. implementation, the latter shall take precedence.
  120. -->
  121. These descriptions are intended to be
  122. accurate and informative, but the limitations of common English sometimes
  123. result in ambiguity, so it is expected that the reader will always read
  124. them alongside the symbolic representation. Numerous references to the
  125. implementation are provided for this purpose. The descriptions sometimes
  126. differ from the reference in ordering or through mathematical simplification
  127. wherever such deviation makes an explanation easier to understand.
  128. For example, the right shift and left shift operations in the reference
  129. implementation are often described using division and multiplication in the text.
  130. In general, the text is focused on the "what" and "why" while the symbolic
  131. representation most clearly provides the "how".
  132. </t>
  133. <section anchor="notation" title="Notation and Conventions">
  134. <t>
  135. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
  136. "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be
  137. interpreted as described in RFC 2119 <xref target="RFC2119"></xref>.
  138. </t>
  139. <t>
  140. Various operations in the codec require bit-exact fixed-point behavior, even
  141. when writing a floating point implementation.
  142. The notation "Q&lt;n&gt;", where n is an integer, denotes the number of binary
  143. digits to the right of the decimal point in a fixed-point number.
  144. For example, a signed Q14 value in a 16-bit word can represent values from
  145. -2.0 to 1.99993896484375, inclusive.
  146. This notation is for informational purposes only.
  147. Arithmetic, when described, always operates on the underlying integer.
  148. For example, the text will explicitly indicate any shifts required after a
  149. multiplication.
  150. </t>
  151. <t>
  152. Expressions, where included in the text, follow C operator rules and
  153. precedence, with the exception that the syntax "x**y" indicates x raised to
  154. the power y.
  155. The text also makes use of the following functions.
  156. </t>
  157. <section anchor="min" toc="exclude" title="min(x,y)">
  158. <t>
  159. The smallest of two values x and y.
  160. </t>
  161. </section>
  162. <section anchor="max" toc="exclude" title="max(x,y)">
  163. <t>
  164. The largest of two values x and y.
  165. </t>
  166. </section>
  167. <section anchor="clamp" toc="exclude" title="clamp(lo,x,hi)">
  168. <!-- [rfced] Please note that we have removed puctuation from the equations
  169. included in this document, as we believe it is more clear. Please review and
  170. let us know if you have any objections. -->
  171. <figure align="center">
  172. <artwork align="center"><![CDATA[
  173. clamp(lo,x,hi) = max(lo,min(x,hi))
  174. ]]></artwork>
  175. </figure>
  176. <t>
  177. With this definition, if lo&nbsp;&gt;&nbsp;hi, then lo is returned.
  178. </t>
  179. </section>
  180. <section anchor="sign" toc="exclude" title="sign(x)">
  181. <t>
  182. The sign of x, i.e.,
  183. <figure align="center">
  184. <artwork align="center"><![CDATA[
  185. ( -1, x < 0
  186. sign(x) = < 0, x == 0
  187. ( 1, x > 0
  188. ]]></artwork>
  189. </figure>
  190. </t>
  191. </section>
  192. <section anchor="abs" toc="exclude" title="abs(x)">
  193. <t>
  194. The absolute value of x, i.e.,
  195. <figure align="center">
  196. <artwork align="center"><![CDATA[
  197. abs(x) = sign(x)*x
  198. ]]></artwork>
  199. </figure>
  200. </t>
  201. </section>
  202. <section anchor="floor" toc="exclude" title="floor(f)">
  203. <t>
  204. The largest integer z such that z &lt;= f.
  205. </t>
  206. </section>
  207. <section anchor="ceil" toc="exclude" title="ceil(f)">
  208. <t>
  209. The smallest integer z such that z &gt;= f.
  210. </t>
  211. </section>
  212. <section anchor="round" toc="exclude" title="round(f)">
  213. <t>
  214. The integer z nearest to f, with ties rounded towards negative infinity,
  215. i.e.,
  216. <figure align="center">
  217. <artwork align="center"><![CDATA[
  218. round(f) = ceil(f - 0.5)
  219. ]]></artwork>
  220. </figure>
  221. </t>
  222. </section>
  223. <section anchor="log2" toc="exclude" title="log2(f)">
  224. <t>
  225. The base-two logarithm of f.
  226. </t>
  227. </section>
  228. <section anchor="ilog" toc="exclude" title="ilog(n)">
  229. <t>
  230. The minimum number of bits required to store a positive integer n in binary, or
  231. 0 for a non-positive integer n.
  232. <figure align="center">
  233. <artwork align="center"><![CDATA[
  234. ( 0, n <= 0
  235. ilog(n) = <
  236. ( floor(log2(n))+1, n > 0
  237. ]]></artwork>
  238. </figure>
  239. Examples:
  240. <list style="symbols">
  241. <t>ilog(-1) = 0</t>
  242. <t>ilog(0) = 0</t>
  243. <t>ilog(1) = 1</t>
  244. <t>ilog(2) = 2</t>
  245. <t>ilog(3) = 2</t>
  246. <t>ilog(4) = 3</t>
  247. <t>ilog(7) = 3</t>
  248. </list>
  249. </t>
  250. </section>
  251. </section>
  252. </section>
  253. <section anchor="overview" title="Opus Codec Overview">
  254. <t>
  255. The Opus codec scales from 6&nbsp;kbit/s narrowband mono speech to 510&nbsp;kbit/s
  256. fullband stereo music, with algorithmic delays ranging from 5&nbsp;ms to
  257. 65.2&nbsp;ms.
  258. At any given time, either the LP layer, the MDCT layer, or both, may be active.
  259. It can seamlessly switch between all of its various operating modes, giving it
  260. a great deal of flexibility to adapt to varying content and network
  261. conditions without renegotiating the current session.
  262. The codec allows input and output of various audio bandwidths, defined as
  263. follows:
  264. </t>
  265. <?rfc compact="no" ?>
  266. <texttable anchor="audio-bandwidth">
  267. <ttcol>Abbreviation</ttcol>
  268. <ttcol align="right">Audio Bandwidth</ttcol>
  269. <ttcol align="right">Sample Rate (Effective)</ttcol>
  270. <c>NB (narrowband)</c> <c>4&nbsp;kHz</c> <c>8&nbsp;kHz</c>
  271. <c>MB (medium-band)</c> <c>6&nbsp;kHz</c> <c>12&nbsp;kHz</c>
  272. <c>WB (wideband)</c> <c>8&nbsp;kHz</c> <c>16&nbsp;kHz</c>
  273. <c>SWB (super-wideband)</c> <c>12&nbsp;kHz</c> <c>24&nbsp;kHz</c>
  274. <c>FB (fullband)</c> <c>20&nbsp;kHz (*)</c> <c>48&nbsp;kHz</c>
  275. </texttable>
  276. <?rfc compact="yes" ?>
  277. <t>
  278. (*) Although the sampling theorem allows a bandwidth as large as half the
  279. sampling rate, Opus never codes audio above 20&nbsp;kHz, as that is the
  280. generally accepted upper limit of human hearing.
  281. </t>
  282. <t>
  283. Opus defines super-wideband (SWB) with an effective sample rate of 24&nbsp;kHz,
  284. unlike some other audio coding standards that use 32&nbsp;kHz.
  285. This was chosen for a number of reasons.
  286. The band layout in the MDCT layer naturally allows skipping coefficients for
  287. frequencies over 12&nbsp;kHz, but does not allow cleanly dropping just those
  288. frequencies over 16&nbsp;kHz.
  289. A sample rate of 24&nbsp;kHz also makes resampling in the MDCT layer easier,
  290. as 24 evenly divides 48, and when 24&nbsp;kHz is sufficient, it can save
  291. computation in other processing, such as Acoustic Echo Cancellation (AEC).
  292. Experimental changes to the band layout to allow a 16&nbsp;kHz cutoff
  293. (32&nbsp;kHz effective sample rate) showed potential quality degradations at
  294. other sample rates, and, at typical bitrates, the number of bits saved by using
  295. such a cutoff instead of coding in fullband (FB) mode is very small.
  296. Therefore, if an application wishes to process a signal sampled at 32&nbsp;kHz,
  297. it should just use FB.
  298. </t>
  299. <t>
  300. The LP layer is based on the SILK codec
  301. <xref target="SILK"></xref>.
  302. It supports NB, MB, or WB audio and frame sizes from 10&nbsp;ms to 60&nbsp;ms,
  303. and requires an additional 5&nbsp;ms look-ahead for noise shaping estimation.
  304. A small additional delay (up to 1.5 ms) may be required for sampling rate
  305. conversion.
  306. Like Vorbis <xref target='VORBIS-WEBSITE'/> and many other modern codecs, SILK is inherently designed for
  307. variable bitrate (VBR) coding, though the encoder can also produce
  308. constant bitrate (CBR) streams.
  309. The version of SILK used in Opus is substantially modified from, and not
  310. compatible with, the stand-alone SILK codec previously deployed by Skype.
  311. This document does not serve to define that format, but those interested in the
  312. original SILK codec should see <xref target="SILK"/> instead.
  313. </t>
  314. <t>
  315. The MDCT layer is based on the Constrained-Energy Lapped Transform (CELT) codec <xref target="CELT"></xref>.
  316. It supports NB, WB, SWB, or FB audio and frame sizes from 2.5&nbsp;ms to
  317. 20&nbsp;ms, and requires an additional 2.5&nbsp;ms look-ahead due to the
  318. overlapping MDCT windows.
  319. The CELT codec is inherently designed for CBR coding, but unlike many CBR
  320. codecs, it is not limited to a set of predetermined rates.
  321. It internally allocates bits to exactly fill any given target budget, and an
  322. encoder can produce a VBR stream by varying the target on a per-frame basis.
  323. The MDCT layer is not used for speech when the audio bandwidth is WB or less,
  324. as it is not useful there.
  325. On the other hand, non-speech signals are not always adequately coded using
  326. linear prediction.
  327. Therefore, the MDCT layer should be used for music-only signals.
  328. </t>
  329. <t>
  330. A "Hybrid" mode allows the use of both layers simultaneously with a frame size
  331. of 10&nbsp;or 20&nbsp;ms and an SWB or FB audio bandwidth.
  332. The LP layer codes the low frequencies by resampling the signal down to WB.
  333. The MDCT layer follows, coding the high frequency portion of the signal.
  334. The cutoff between the two lies at 8&nbsp;kHz, the maximum WB audio bandwidth.
  335. In the MDCT layer, all bands below 8&nbsp;kHz are discarded, so there is no
  336. coding redundancy between the two layers.
  337. </t>
  338. <t>
  339. The sample rate (in contrast to the actual audio bandwidth) can be chosen
  340. independently on the encoder and decoder side, e.g., a fullband signal can be
  341. decoded as wideband, or vice versa.
  342. This approach ensures a sender and receiver can always interoperate, regardless
  343. of the capabilities of their actual audio hardware.
  344. Internally, the LP layer always operates at a sample rate of twice the audio
  345. bandwidth, up to a maximum of 16&nbsp;kHz, which it continues to use for SWB
  346. and FB.
  347. The decoder simply resamples its output to support different sample rates.
  348. The MDCT layer always operates internally at a sample rate of 48&nbsp;kHz.
  349. Since all the supported sample rates evenly divide this rate, and since the
  350. decoder may easily zero out the high frequency portion of the spectrum in
  351. the frequency domain, it can simply decimate the MDCT layer output to achieve
  352. the other supported sample rates very cheaply.
  353. </t>
  354. <t>
  355. After conversion to the common, desired output sample rate, the decoder simply
  356. adds the output from the two layers together.
  357. To compensate for the different look-ahead required by each layer, the CELT
  358. encoder input is delayed by an additional 2.7&nbsp;ms.
  359. This ensures that low frequencies and high frequencies arrive at the same time.
  360. This extra delay may be reduced by an encoder by using less look-ahead for noise
  361. shaping or using a simpler resampler in the LP layer, but this will reduce
  362. quality.
  363. However, the base 2.5&nbsp;ms look-ahead in the CELT layer cannot be reduced in
  364. the encoder because it is needed for the MDCT overlap, whose size is fixed by
  365. the decoder.
  366. </t>
  367. <t>
  368. Both layers use the same entropy coder, avoiding any waste from "padding bits"
  369. between them.
  370. The hybrid approach makes it easy to support both CBR and VBR coding.
  371. Although the LP layer is VBR, the bit allocation of the MDCT layer can produce
  372. a final stream that is CBR by using all the bits left unused by the LP layer.
  373. </t>
  374. <section title="Control Parameters">
  375. <t>
  376. The Opus codec includes a number of control parameters that can be changed dynamically during
  377. regular operation of the codec, without interrupting the audio stream from the encoder to the decoder.
  378. These parameters only affect the encoder since any impact they have on the bitstream is signaled
  379. in-band such that a decoder can decode any Opus stream without any out-of-band signaling. Any Opus
  380. implementation can add or modify these control parameters without affecting interoperability. The most
  381. important encoder control parameters in the reference encoder are listed below.
  382. </t>
  383. <section title="Bitrate" toc="exlcude">
  384. <t>
  385. Opus supports all bitrates from 6&nbsp;kbit/s to 510&nbsp;kbit/s. All other parameters being
  386. equal, higher bitrate results in higher quality. For a frame size of 20&nbsp;ms, these
  387. are the bitrate "sweet spots" for Opus in various configurations:
  388. <list style="symbols">
  389. <t>8-12 kbit/s for NB speech,</t>
  390. <t>16-20 kbit/s for WB speech,</t>
  391. <t>28-40 kbit/s for FB speech,</t>
  392. <t>48-64 kbit/s for FB mono music, and</t>
  393. <t>64-128 kbit/s for FB stereo music.</t>
  394. </list>
  395. </t>
  396. </section>
  397. <section title="Number of Channels (Mono/Stereo)" toc="exlcude">
  398. <t>
  399. Opus can transmit either mono or stereo frames within a single stream.
  400. When decoding a mono frame in a stereo decoder, the left and right channels are
  401. identical, and when decoding a stereo frame in a mono decoder, the mono output
  402. is the average of the left and right channels.
  403. In some cases, it is desirable to encode a stereo input stream in mono (e.g.,
  404. because the bitrate is too low to encode stereo with sufficient quality).
  405. The number of channels encoded can be selected in real-time, but by default the
  406. reference encoder attempts to make the best decision possible given the
  407. current bitrate.
  408. </t>
  409. </section>
  410. <section title="Audio Bandwidth" toc="exlcude">
  411. <t>
  412. The audio bandwidths supported by Opus are listed in
  413. <xref target="audio-bandwidth"/>.
  414. Just like for the number of channels, any decoder can decode audio that is encoded at
  415. any bandwidth.
  416. For example, any Opus decoder operating at 8&nbsp;kHz can decode an FB Opus
  417. frame, and any Opus decoder operating at 48&nbsp;kHz can decode an NB frame.
  418. Similarly, the reference encoder can take a 48&nbsp;kHz input signal and
  419. encode it as NB.
  420. The higher the audio bandwidth, the higher the required bitrate to achieve
  421. acceptable quality.
  422. The audio bandwidth can be explicitly specified in real-time, but, by default,
  423. the reference encoder attempts to make the best bandwidth decision possible
  424. given the current bitrate.
  425. </t>
  426. </section>
  427. <section title="Frame Duration" toc="exlcude">
  428. <t>
  429. Opus can encode frames of 2.5, 5, 10, 20, 40, or 60&nbsp;ms.
  430. It can also combine multiple frames into packets of up to 120&nbsp;ms.
  431. For real-time applications, sending fewer packets per second reduces the
  432. bitrate, since it reduces the overhead from IP, UDP, and RTP headers.
  433. However, it increases latency and sensitivity to packet losses, as losing one
  434. packet constitutes a loss of a bigger chunk of audio.
  435. Increasing the frame duration also slightly improves coding efficiency, but the
  436. gain becomes small for frame sizes above 20&nbsp;ms.
  437. For this reason, 20&nbsp;ms frames are a good choice for most applications.
  438. </t>
  439. </section>
  440. <section title="Complexity" toc="exlcude">
  441. <t>
  442. There are various aspects of the Opus encoding process where trade-offs
  443. can be made between CPU complexity and quality/bitrate. In the reference
  444. encoder, the complexity is selected using an integer from 0 to 10, where
  445. 0 is the lowest complexity and 10 is the highest. Examples of
  446. computations for which such trade-offs may occur are:
  447. <list style="symbols">
  448. <t>The order of the pitch analysis whitening filter <xref target="WHITENING"/>,</t>
  449. <t>The order of the short-term noise shaping filter,</t>
  450. <t>The number of states in delayed decision quantization of the
  451. residual signal, and</t>
  452. <t>The use of certain bitstream features such as variable time-frequency
  453. resolution and the pitch post-filter.</t>
  454. </list>
  455. </t>
  456. </section>
  457. <section title="Packet Loss Resilience" toc="exlcude">
  458. <t>
  459. Audio codecs often exploit inter-frame correlations to reduce the
  460. bitrate at a cost in error propagation: after losing one packet,
  461. several packets need to be received before the decoder is able to
  462. accurately reconstruct the speech signal. The extent to which Opus
  463. exploits inter-frame dependencies can be adjusted on the fly to
  464. choose a trade-off between bitrate and amount of error propagation.
  465. </t>
  466. </section>
  467. <section title="Forward Error Correction (FEC)" toc="exlcude">
  468. <t>
  469. Another mechanism providing robustness against packet loss is the in-band
  470. Forward Error Correction (FEC). Packets that are determined to
  471. contain perceptually important speech information, such as onsets or
  472. transients, are encoded again at a lower bitrate and this re-encoded
  473. information is added to a subsequent packet.
  474. </t>
  475. </section>
  476. <section title="Constant/Variable Bitrate" toc="exlcude">
  477. <t>
  478. Opus is more efficient when operating with variable bitrate (VBR), which is
  479. the default. When low-latency transmission is required over a relatively slow connection, then
  480. constrained VBR can also be used. This uses VBR in a way that simulates a
  481. "bit reservoir" and is equivalent to what MP3 (MPEG 1, Layer 3) and
  482. AAC (Advanced Audio Coding) call CBR (i.e., not true
  483. CBR due to the bit reservoir). In some (rare) applications, constant bitrate (CBR)
  484. is required. There are two main reasons to operate in CBR mode:
  485. <list style="symbols">
  486. <t>When the transport only supports a fixed size for each compressed frame, or</t>
  487. <t>When encryption is used for an audio stream that is either highly constrained
  488. (e.g., yes/no, recorded prompts) or highly sensitive <xref target="SRTP-VBR"></xref>.</t>
  489. </list>
  490. Bitrate may still be allowed
  491. to vary, even with sensitive data, as long as the variation is not
  492. driven by the input signal (for example, to match changing network
  493. conditions). To achieve this, an application should still run Opus
  494. in CBR mode, but change the target rate before each packet.
  495. </t>
  496. </section>
  497. <section title="Discontinuous Transmission (DTX)" toc="exlcude">
  498. <t>
  499. Discontinuous Transmission (DTX) reduces the bitrate during silence
  500. or background noise. When DTX is enabled, only one frame is encoded
  501. every 400 milliseconds.
  502. </t>
  503. </section>
  504. </section>
  505. </section>
  506. <section anchor="modes" title="Internal Framing">
  507. <t>
  508. The Opus encoder produces "packets", which are each a contiguous set of bytes
  509. meant to be transmitted as a single unit.
  510. The packets described here do not include such things as IP, UDP, or RTP
  511. headers, which are normally found in a transport-layer packet.
  512. A single packet may contain multiple audio frames, so long as they share a
  513. common set of parameters, including the operating mode, audio bandwidth, frame
  514. size, and channel count (mono vs. stereo).
  515. This section describes the possible combinations of these parameters and the
  516. internal framing used to pack multiple frames into a single packet.
  517. This framing is not self-delimiting.
  518. Instead, it assumes that a lower layer (such as UDP or RTP <xref target='RFC3550'/>
  519. or Ogg <xref target='RFC3533'/> or Matroska <xref target='MATROSKA-WEBSITE'/>)
  520. will communicate the length, in bytes, of the packet, and it uses this
  521. information to reduce the framing overhead in the packet itself.
  522. A decoder implementation MUST support the framing described in this section.
  523. An alternative, self-delimiting variant of the framing is described in
  524. <xref target="self-delimiting-framing"/>.
  525. Support for that variant is OPTIONAL.
  526. </t>
  527. <t>
  528. All bit diagrams in this document number the bits so that bit 0 is the most
  529. significant bit of the first byte, and bit 7 is the least significant.
  530. Bit 8 is thus the most significant bit of the second byte, etc.
  531. Well-formed Opus packets obey certain requirements, marked [R1] through [R7]
  532. below.
  533. These are summarized in <xref target="malformed-packets"/> along with
  534. appropriate means of handling malformed packets.
  535. </t>
  536. <section anchor="toc_byte" title="The TOC Byte">
  537. <t anchor="R1">
  538. A well-formed Opus packet MUST contain at least one byte&nbsp;[R1].
  539. This byte forms a table-of-contents (TOC) header that signals which of the
  540. various modes and configurations a given packet uses.
  541. It is composed of a configuration number, "config", a stereo flag, "s", and a
  542. frame count code, "c", arranged as illustrated in
  543. <xref target="toc_byte_fig"/>.
  544. A description of each of these fields follows.
  545. </t>
  546. <figure anchor="toc_byte_fig" title="The TOC Byte">
  547. <artwork align="center"><![CDATA[
  548. 0
  549. 0 1 2 3 4 5 6 7
  550. +-+-+-+-+-+-+-+-+
  551. | config |s| c |
  552. +-+-+-+-+-+-+-+-+
  553. ]]></artwork>
  554. </figure>
  555. <t>
  556. The top five bits of the TOC byte, labeled "config", encode one of 32 possible
  557. configurations of operating mode, audio bandwidth, and frame size.
  558. As described, the LP (SILK) layer and MDCT (CELT) layer can be combined in three possible
  559. operating modes:
  560. <list style="numbers">
  561. <t>A SILK-only mode for use in low bitrate connections with an audio bandwidth
  562. of WB or less,</t>
  563. <t>A Hybrid (SILK+CELT) mode for SWB or FB speech at medium bitrates, and</t>
  564. <t>A CELT-only mode for very low delay speech transmission as well as music
  565. transmission (NB to FB).</t>
  566. </list>
  567. The 32 possible configurations each identify which one of these operating modes
  568. the packet uses, as well as the audio bandwidth and the frame size.
  569. <xref target="config_bits"/> lists the parameters for each configuration.
  570. </t>
  571. <?rfc compact="no" ?>
  572. <texttable anchor="config_bits" title="TOC Byte Configuration Parameters">
  573. <ttcol>Configuration Number(s)</ttcol>
  574. <ttcol>Mode</ttcol>
  575. <ttcol>Bandwidth</ttcol>
  576. <ttcol>Frame Sizes</ttcol>
  577. <c>0...3</c> <c>SILK-only</c> <c>NB</c> <c>10, 20, 40, 60&nbsp;ms</c>
  578. <c>4...7</c> <c>SILK-only</c> <c>MB</c> <c>10, 20, 40, 60&nbsp;ms</c>
  579. <c>8...11</c> <c>SILK-only</c> <c>WB</c> <c>10, 20, 40, 60&nbsp;ms</c>
  580. <c>12...13</c> <c>Hybrid</c> <c>SWB</c> <c>10, 20&nbsp;ms</c>
  581. <c>14...15</c> <c>Hybrid</c> <c>FB</c> <c>10, 20&nbsp;ms</c>
  582. <c>16...19</c> <c>CELT-only</c> <c>NB</c> <c>2.5, 5, 10, 20&nbsp;ms</c>
  583. <c>20...23</c> <c>CELT-only</c> <c>WB</c> <c>2.5, 5, 10, 20&nbsp;ms</c>
  584. <c>24...27</c> <c>CELT-only</c> <c>SWB</c> <c>2.5, 5, 10, 20&nbsp;ms</c>
  585. <c>28...31</c> <c>CELT-only</c> <c>FB</c> <c>2.5, 5, 10, 20&nbsp;ms</c>
  586. </texttable>
  587. <?rfc compact="yes" ?>
  588. <t>
  589. The configuration numbers in each range (e.g., 0...3 for NB SILK-only)
  590. correspond to the various choices of frame size, in the same order.
  591. For example, configuration 0 has a 10&nbsp;ms frame size and configuration 3
  592. has a 60&nbsp;ms frame size.
  593. </t>
  594. <t>
  595. One additional bit, labeled "s", signals mono vs. stereo, with 0 indicating
  596. mono and 1 indicating stereo.
  597. </t>
  598. <t>
  599. The remaining two bits of the TOC byte, labeled "c", code the number of frames
  600. per packet (codes 0 to 3) as follows:
  601. <list style="symbols">
  602. <t>0: 1 frame in the packet</t>
  603. <t>1: 2 frames in the packet, each with equal compressed size</t>
  604. <t>2: 2 frames in the packet, with different compressed sizes</t>
  605. <t>3: an arbitrary number of frames in the packet</t>
  606. </list>
  607. This document refers to a packet as a code 0 packet, code 1 packet, etc., based on
  608. the value of "c".
  609. </t>
  610. </section>
  611. <section title="Frame Packing">
  612. <t>
  613. This section describes how frames are packed according to each possible value
  614. of "c" in the TOC byte.
  615. </t>
  616. <section anchor="frame-length-coding" title="Frame Length Coding">
  617. <t>
  618. When a packet contains multiple VBR frames (i.e., code 2 or 3), the compressed
  619. length of one or more of these frames is indicated with a one- or two-byte
  620. sequence, with the meaning of the first byte as follows:
  621. <list style="symbols">
  622. <t>0: No frame (Discontinuous Transmission (DTX) or lost packet)</t>
  623. <t>1...251: Length of the frame in bytes</t>
  624. <t>252...255: A second byte is needed. The total length is (second_byte*4)+first_byte</t>
  625. </list>
  626. </t>
  627. <t>
  628. The special length 0 indicates that no frame is available, either because it
  629. was dropped during transmission by some intermediary or because the encoder
  630. chose not to transmit it.
  631. Any Opus frame in any mode MAY have a length of 0.
  632. </t>
  633. <t>
  634. The maximum representable length is 255*4+255=1275&nbsp;bytes.
  635. For 20&nbsp;ms frames, this represents a bitrate of 510&nbsp;kbit/s, which is
  636. approximately the highest useful rate for lossily compressed fullband stereo
  637. music.
  638. Beyond this point, lossless codecs are more appropriate.
  639. It is also roughly the maximum useful rate of the MDCT layer as, shortly
  640. thereafter, quality no longer improves with additional bits due to limitations
  641. on the codebook sizes.
  642. </t>
  643. <t anchor="R2">
  644. No length is transmitted for the last frame in a VBR packet, or for any of the
  645. frames in a CBR packet, as it can be inferred from the total size of the
  646. packet and the size of all other data in the packet.
  647. However, the length of any individual frame MUST NOT exceed
  648. 1275&nbsp;bytes&nbsp;[R2] to allow for repacketization by gateways,
  649. conference bridges, or other software.
  650. </t>
  651. </section>
  652. <section title="Code 0: One Frame in the Packet">
  653. <t>
  654. For code&nbsp;0 packets, the TOC byte is immediately followed by N-1&nbsp;bytes
  655. of compressed data for a single frame (where N is the size of the packet),
  656. as illustrated in <xref target="code0_packet"/>.
  657. </t>
  658. <figure anchor="code0_packet" title="A Code 0 Packet" align="center">
  659. <artwork align="center"><![CDATA[
  660. 0 1 2 3
  661. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  662. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  663. | config |s|0|0| |
  664. +-+-+-+-+-+-+-+-+ |
  665. | Compressed frame 1 (N-1 bytes)... :
  666. : |
  667. | |
  668. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  669. ]]></artwork>
  670. </figure>
  671. </section>
  672. <section title="Code 1: Two Frames in the Packet, Each with Equal Compressed Size">
  673. <t anchor="R3">
  674. For code 1 packets, the TOC byte is immediately followed by the
  675. (N-1)/2&nbsp;bytes of compressed data for the first frame, followed by
  676. (N-1)/2&nbsp;bytes of compressed data for the second frame, as illustrated in
  677. <xref target="code1_packet"/>.
  678. The number of payload bytes available for compressed data, N-1, MUST be even
  679. for all code 1 packets&nbsp;[R3].
  680. </t>
  681. <figure anchor="code1_packet" title="A Code 1 Packet" align="center">
  682. <artwork align="center"><![CDATA[
  683. 0 1 2 3
  684. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  685. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  686. | config |s|0|1| |
  687. +-+-+-+-+-+-+-+-+ :
  688. | Compressed frame 1 ((N-1)/2 bytes)... |
  689. : +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  690. | | |
  691. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ :
  692. | Compressed frame 2 ((N-1)/2 bytes)... |
  693. : +-+-+-+-+-+-+-+-+
  694. | |
  695. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  696. ]]></artwork>
  697. </figure>
  698. </section>
  699. <section title="Code 2: Two Frames in the Packet, with Different Compressed Sizes">
  700. <t anchor="R4">
  701. For code 2 packets, the TOC byte is followed by a one- or two-byte sequence
  702. indicating the length of the first frame (marked N1 in <xref target='code2_packet'/>),
  703. followed by N1 bytes of compressed data for the first frame.
  704. The remaining N-N1-2 or N-N1-3&nbsp;bytes are the compressed data for the
  705. second frame.
  706. This is illustrated in <xref target="code2_packet"/>.
  707. A code 2 packet MUST contain enough bytes to represent a valid length.
  708. For example, a 1-byte code 2 packet is always invalid, and a 2-byte code 2
  709. packet whose second byte is in the range 252...255 is also invalid.
  710. The length of the first frame, N1, MUST also be no larger than the size of the
  711. payload remaining after decoding that length for all code 2 packets&nbsp;[R4].
  712. This makes, for example, a 2-byte code 2 packet with a second byte in the range
  713. 1...251 invalid as well (the only valid 2-byte code 2 packet is one where the
  714. length of both frames is zero).
  715. </t>
  716. <figure anchor="code2_packet" title="A Code 2 Packet" align="center">
  717. <artwork align="center"><![CDATA[
  718. 0 1 2 3
  719. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  720. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  721. | config |s|1|0| N1 (1-2 bytes): |
  722. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ :
  723. | Compressed frame 1 (N1 bytes)... |
  724. : +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  725. | | |
  726. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
  727. | Compressed frame 2... :
  728. : |
  729. | |
  730. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  731. ]]></artwork>
  732. </figure>
  733. </section>
  734. <section title="Code 3: A Signaled Number of Frames in the Packet">
  735. <t anchor="R5">
  736. Code 3 packets signal the number of frames, as well as additional
  737. padding, called "Opus padding" to indicate that this padding is added at the
  738. Opus layer rather than at the transport layer.
  739. Code 3 packets MUST have at least 2 bytes&nbsp;[R6,R7].
  740. The TOC byte is followed by a byte encoding the number of frames in the packet
  741. in bits 2 to 7 (marked "M" in <xref target='frame_count_byte'/>), with bit 1 indicating whether
  742. or not Opus padding is inserted (marked "p" in <xref target='frame_count_byte'/>), and bit 0
  743. indicating VBR (marked "v" in <xref target='frame_count_byte'/>).
  744. M MUST NOT be zero, and the audio duration contained within a packet MUST NOT
  745. exceed 120&nbsp;ms&nbsp;[R5].
  746. This limits the maximum frame count for any frame size to 48 (for 2.5&nbsp;ms
  747. frames), with lower limits for longer frame sizes.
  748. <xref target="frame_count_byte"/> illustrates the layout of the frame count
  749. byte.
  750. </t>
  751. <figure anchor="frame_count_byte" title="The frame count byte">
  752. <artwork align="center"><![CDATA[
  753. 0
  754. 0 1 2 3 4 5 6 7
  755. +-+-+-+-+-+-+-+-+
  756. |v|p| M |
  757. +-+-+-+-+-+-+-+-+
  758. ]]></artwork>
  759. </figure>
  760. <t>
  761. When Opus padding is used, the number of bytes of padding is encoded in the
  762. bytes following the frame count byte.
  763. Values from 0...254 indicate that 0...254&nbsp;bytes of padding are included,
  764. in addition to the byte(s) used to indicate the size of the padding.
  765. If the value is 255, then the size of the additional padding is 254&nbsp;bytes,
  766. plus the padding value encoded in the next byte.
  767. There MUST be at least one more byte in the packet in this case&nbsp;[R6,R7].
  768. The additional padding bytes appear at the end of the packet and MUST be set
  769. to zero by the encoder to avoid creating a covert channel.
  770. The decoder MUST accept any value for the padding bytes, however.
  771. </t>
  772. <t>
  773. Although this encoding provides multiple ways to indicate a given number of
  774. padding bytes, each uses a different number of bytes to indicate the padding
  775. size and thus will increase the total packet size by a different amount.
  776. For example, to add 255 bytes to a packet, set the padding bit, p, to 1, insert
  777. a single byte after the frame count byte with a value of 254, and append 254
  778. padding bytes with the value zero to the end of the packet.
  779. To add 256 bytes to a packet, set the padding bit to 1, insert two bytes after
  780. the frame count byte with the values 255 and 0, respectively, and append 254
  781. padding bytes with the value zero to the end of the packet.
  782. By using the value 255 multiple times, it is possible to create a packet of any
  783. specific, desired size.
  784. Let P be the number of header bytes used to indicate the padding size plus the
  785. number of padding bytes themselves (i.e., P is the total number of bytes added
  786. to the packet).
  787. Then, P MUST be no more than N-2&nbsp;[R6,R7].
  788. </t>
  789. <t anchor="R6">
  790. In the CBR case, let R=N-2-P be the number of bytes remaining in the packet
  791. after subtracting the (optional) padding.
  792. Then, the compressed length of each frame in bytes is equal to R/M.&nbsp;
  793. The value R MUST be a non-negative integer multiple of M&nbsp;[R6].
  794. The compressed data for all M frames follows, each of size
  795. R/M&nbsp;bytes, as illustrated in <xref target="code3cbr_packet"/>.
  796. </t>
  797. <figure anchor="code3cbr_packet" title="A CBR Code 3 Packet" align="center">
  798. <artwork align="center"><![CDATA[
  799. 0 1 2 3
  800. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  801. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  802. | config |s|1|1|0|p| M | Padding length (Optional) :
  803. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  804. | |
  805. : Compressed frame 1 (R/M bytes)... :
  806. | |
  807. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  808. | |
  809. : Compressed frame 2 (R/M bytes)... :
  810. | |
  811. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  812. | |
  813. : ... :
  814. | |
  815. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  816. | |
  817. : Compressed frame M (R/M bytes)... :
  818. | |
  819. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  820. : Opus Padding (Optional)... |
  821. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  822. ]]></artwork>
  823. </figure>
  824. <t anchor="R7">
  825. In the VBR case, the (optional) padding length is followed by M-1 frame
  826. lengths (indicated by "N1" to "N[M-1]" in <xref target='code3vbr_packet'/>), each encoded in a
  827. one- or two-byte sequence as described above.
  828. The packet MUST contain enough data for the M-1 lengths after removing the
  829. (optional) padding, and the sum of these lengths MUST be no larger than the
  830. number of bytes remaining in the packet after decoding them&nbsp;[R7].
  831. The compressed data for all M frames follows, each frame consisting of the
  832. indicated number of bytes, with the final frame consuming any remaining bytes
  833. before the final padding, as illustrated in <xref target="code3cbr_packet"/>.
  834. The number of header bytes (TOC byte, frame count byte, padding length bytes,
  835. and frame length bytes), plus the signaled length of the first M-1 frames themselves,
  836. plus the signaled length of the padding MUST be no larger than N, the total size of the
  837. packet.
  838. </t>
  839. <figure anchor="code3vbr_packet" title="A VBR Code 3 Packet" align="center">
  840. <artwork align="center"><![CDATA[
  841. 0 1 2 3
  842. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  843. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  844. | config |s|1|1|1|p| M | Padding length (Optional) :
  845. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  846. : N1 (1-2 bytes): N2 (1-2 bytes): ... : N[M-1] |
  847. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  848. | |
  849. : Compressed frame 1 (N1 bytes)... :
  850. | |
  851. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  852. | |
  853. : Compressed frame 2 (N2 bytes)... :
  854. | |
  855. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  856. | |
  857. : ... :
  858. | |
  859. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  860. | |
  861. : Compressed frame M... :
  862. | |
  863. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  864. : Opus Padding (Optional)... |
  865. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  866. ]]></artwork>
  867. </figure>
  868. </section>
  869. </section>
  870. <section anchor="examples" title="Examples">
  871. <t>
  872. Simplest case, one NB mono 20&nbsp;ms SILK frame:
  873. </t>
  874. <figure anchor='framing_example_1'>
  875. <artwork><![CDATA[
  876. 0 1 2 3
  877. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  878. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  879. | 1 |0|0|0| compressed data... :
  880. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  881. ]]></artwork>
  882. </figure>
  883. <t>
  884. Two FB mono 5&nbsp;ms CELT frames of the same compressed size:
  885. </t>
  886. <figure anchor='framing_example_2'>
  887. <artwork><![CDATA[
  888. 0 1 2 3
  889. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  890. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  891. | 29 |0|0|1| compressed data... :
  892. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  893. ]]></artwork>
  894. </figure>
  895. <t>
  896. Two FB mono 20&nbsp;ms Hybrid frames of different compressed size:
  897. </t>
  898. <figure anchor='framing_example_3'>
  899. <artwork><![CDATA[
  900. 0 1 2 3
  901. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  902. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  903. | 15 |0|1|1|1|0| 2 | N1 | |
  904. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
  905. | compressed data... :
  906. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  907. ]]></artwork>
  908. </figure>
  909. <t>
  910. Four FB stereo 20&nbsp;ms CELT frames of the same compressed size:
  911. </t>
  912. <figure anchor='framing_example_4'>
  913. <artwork><![CDATA[
  914. 0 1 2 3
  915. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  916. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  917. | 31 |1|1|1|0|0| 4 | compressed data... :
  918. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  919. ]]></artwork>
  920. </figure>
  921. </section>
  922. <section anchor="malformed-packets" title="Receiving Malformed Packets">
  923. <t>
  924. A receiver MUST NOT process packets that violate any of the rules above as
  925. normal Opus packets.
  926. They are reserved for future applications, such as in-band headers (containing
  927. metadata, etc.).
  928. Packets that violate these constraints may cause implementations of
  929. <spanx style="emph">this</spanx> specification to treat them as malformed and
  930. discard them.
  931. </t>
  932. <t>
  933. These constraints are summarized here for reference:
  934. <list style="format [R%d]">
  935. <t>Packets are at least one byte.</t>
  936. <t>No implicit frame length is larger than 1275 bytes.</t>
  937. <t>Code 1 packets have an odd total length, N, so that (N-1)/2 is an
  938. integer.</t>
  939. <t>Code 2 packets have enough bytes after the TOC for a valid frame
  940. length, and that length is no larger than the number of bytes remaining in the
  941. packet.</t>
  942. <t>Code 3 packets contain at least one frame, but no more than 120&nbsp;ms
  943. of audio total.</t>
  944. <t>The length of a CBR code 3 packet, N, is at least two bytes, the number of
  945. bytes added to indicate the padding size plus the trailing padding bytes
  946. themselves, P, is no more than N-2, and the frame count, M, satisfies
  947. the constraint that (N-2-P) is a non-negative integer multiple of M.</t>
  948. <t>VBR code 3 packets are large enough to contain all the header bytes (TOC
  949. byte, frame count byte, any padding length bytes, and any frame length bytes),
  950. plus the length of the first M-1 frames, plus any trailing padding bytes.</t>
  951. </list>
  952. </t>
  953. </section>
  954. </section>
  955. <section title="Opus Decoder">
  956. <t>
  957. The Opus decoder consists of two main blocks: the SILK decoder and the CELT
  958. decoder.
  959. At any given time, one or both of the SILK and CELT decoders may be active.
  960. The output of the Opus decode is the sum of the outputs from the SILK and CELT
  961. decoders with proper sample rate conversion and delay compensation on the SILK
  962. side, and optional decimation (when decoding to sample rates less than
  963. 48&nbsp;kHz) on the CELT side, as illustrated in the block diagram below.
  964. </t>
  965. <figure>
  966. <artwork>
  967. <![CDATA[
  968. +---------+ +------------+
  969. | SILK | | Sample |
  970. +->| Decoder |--->| Rate |----+
  971. Bit- +---------+ | | | | Conversion | v
  972. stream | Range |---+ +---------+ +------------+ /---\ Audio
  973. ------->| Decoder | | + |------>
  974. | |---+ +---------+ +------------+ \---/
  975. +---------+ | | CELT | | Decimation | ^
  976. +->| Decoder |--->| (Optional) |----+
  977. | | | |
  978. +---------+ +------------+
  979. ]]>
  980. </artwork>
  981. </figure>
  982. <section anchor="range-decoder" title="Range Decoder">
  983. <t>
  984. Opus uses an entropy coder based on range coding <xref target="RANGE-CODING"></xref>
  985. <xref target="MARTIN79"></xref>,
  986. which is itself a rediscovery of the FIFO arithmetic code introduced by <xref target="CODING-THESIS"></xref>.
  987. It is very similar to arithmetic encoding, except that encoding is done with
  988. digits in any base instead of with bits,
  989. so it is faster when using larger bases (i.e., a byte). All of the
  990. calculations in the range coder must use bit-exact integer arithmetic.
  991. </t>
  992. <t>
  993. Symbols may also be coded as "raw bits" packed directly into the bitstream,
  994. bypassing the range coder.
  995. These are packed backwards starting at the end of the frame, as illustrated in
  996. <xref target="rawbits-example"/>.
  997. This reduces complexity and makes the stream more resilient to bit errors, as
  998. corruption in the raw bits will not desynchronize the decoding process, unlike
  999. corruption in the input to the range decoder.
  1000. Raw bits are only used in the CELT layer.
  1001. </t>
  1002. <figure anchor="rawbits-example" title="Illustrative Example of Packing Range
  1003. Coder and Raw Bits Data">
  1004. <artwork align="center"><![CDATA[
  1005. 0 1 2 3
  1006. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  1007. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1008. | Range coder data (packed MSB to LSB) -> :
  1009. + +
  1010. : :
  1011. + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1012. : | <- Boundary occurs at an arbitrary bit position :
  1013. +-+-+-+ +
  1014. : <- Raw bits data (packed LSB to MSB) |
  1015. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1016. Legend:
  1017. LSB = Least Significant Bit
  1018. MSB = Most Significant Bit
  1019. ]]></artwork>
  1020. </figure>
  1021. <!--[rfced] Please review our addition of explanatory text regarding the
  1022. acronyms in Figure 12.
  1023. -->
  1024. <t>
  1025. Each symbol coded by the range coder is drawn from a finite alphabet and coded
  1026. in a separate "context", which describes the size of the alphabet and the
  1027. relative frequency of each symbol in that alphabet.
  1028. </t>
  1029. <t>
  1030. Suppose there is a context with n symbols, identified with an index that ranges
  1031. from 0 to n-1.
  1032. The parameters needed to encode or decode symbol k in this context are
  1033. represented by a three-tuple (fl[k],&nbsp;fh[k],&nbsp;ft), all 16-bit unsigned
  1034. integers, with
  1035. 0&nbsp;&lt;=&nbsp;fl[k]&nbsp;&lt;&nbsp;fh[k]&nbsp;&lt;=&nbsp;ft&nbsp;&lt;=&nbsp;65535.
  1036. The values of this tuple are derived from the probability model for the
  1037. symbol, represented by traditional "frequency counts".
  1038. Because Opus uses static contexts, those are not updated as symbols are decoded.
  1039. Let f[i] be the frequency of symbol i.
  1040. Then, the three-tuple corresponding to symbol k is given by the following:
  1041. </t>
  1042. <figure align="center">
  1043. <artwork align="center"><![CDATA[
  1044. k-1 n-1
  1045. __ __
  1046. fl[k] = \ f[i], fh[k] = fl[k] + f[k], ft = \ f[i]
  1047. /_ /_
  1048. i=0 i=0
  1049. ]]></artwork>
  1050. </figure>
  1051. <t>
  1052. The range decoder extracts the symbols and integers encoded using the range
  1053. encoder in <xref target="range-encoder"/>.
  1054. The range decoder maintains an internal state vector composed of the two-tuple
  1055. (val,&nbsp;rng), where val represents the difference between the high end of
  1056. the current range and the actual coded value, minus one, and rng represents
  1057. the size of the current range.
  1058. Both val and rng are 32-bit unsigned integer values.
  1059. </t>
  1060. <section anchor="range-decoder-init" title="Range Decoder Initialization">
  1061. <t>
  1062. Let b0 be an 8-bit unsigned integer containing first input byte (or containing
  1063. zero if there are no bytes in this Opus frame).
  1064. The decoder initializes rng to 128 and initializes val to
  1065. (127&nbsp;-&nbsp;(b0&gt;&gt;1)), where (b0&gt;&gt;1) is the top 7 bits of the
  1066. first input byte.
  1067. It saves the remaining bit, (b0&amp;1), for use in the renormalization
  1068. procedure described in <xref target="range-decoder-renorm"/>, which the
  1069. decoder invokes immediately after initialization to read additional bits and
  1070. establish the invariant that rng&nbsp;&gt;&nbsp;2**23.
  1071. </t>
  1072. </section>
  1073. <section anchor="decoding-symbols" title="Decoding Symbols">
  1074. <t>
  1075. Decoding a symbol is a two-step process.
  1076. The first step determines a 16-bit unsigned value fs, which lies within the
  1077. range of some symbol in the current context.
  1078. The second step updates the range decoder state with the three-tuple
  1079. (fl[k],&nbsp;fh[k],&nbsp;ft) corresponding to that symbol.
  1080. </t>
  1081. <t>
  1082. The first step is implemented by ec_decode() (entdec.c), which computes
  1083. <figure align="center">
  1084. <artwork align="center"><![CDATA[
  1085. val
  1086. fs = ft - min(------ + 1, ft)
  1087. rng/ft
  1088. ]]></artwork>
  1089. </figure>
  1090. The divisions here are integer division.
  1091. </t>
  1092. <t>
  1093. The decoder then identifies the symbol in the current context corresponding to
  1094. fs; i.e., the value of k whose three-tuple (fl[k],&nbsp;fh[k],&nbsp;ft)
  1095. satisfies fl[k]&nbsp;&lt;=&nbsp;fs&nbsp;&lt;&nbsp;fh[k].
  1096. It uses this tuple to update val according to
  1097. <figure align="center">
  1098. <artwork align="center"><![CDATA[
  1099. rng
  1100. val = val - --- * (ft - fh[k])
  1101. ft
  1102. ]]></artwork>
  1103. </figure>
  1104. If fl[k] is greater than zero, then the decoder updates rng using
  1105. <figure align="center">
  1106. <artwork align="center"><![CDATA[
  1107. rng
  1108. rng = --- * (fh[k] - fl[k])
  1109. ft
  1110. ]]></artwork>
  1111. </figure>
  1112. Otherwise, it updates rng using
  1113. <figure align="center">
  1114. <artwork align="center"><![CDATA[
  1115. rng
  1116. rng = rng - --- * (ft - fh[k])
  1117. ft
  1118. ]]></artwork>
  1119. </figure>
  1120. </t>
  1121. <t>
  1122. Using a special case for the first symbol (rather than the last symbol, as is
  1123. commonly done in other arithmetic coders) ensures that all the truncation
  1124. error from the finite precision arithmetic accumulates in symbol 0.
  1125. This makes the cost of coding a 0 slightly smaller, on average, than its
  1126. estimated probability indicates and makes the cost of coding any other symbol
  1127. slightly larger.
  1128. When contexts are designed so that 0 is the most probable symbol, which is
  1129. often the case, this strategy minimizes the inefficiency introduced by the
  1130. finite precision.
  1131. It also makes some of the special-case decoding routines in
  1132. <xref target="decoding-alternate"/> particularly simple.
  1133. </t>
  1134. <t>
  1135. After the updates, implemented by ec_dec_update() (entdec.c), the decoder
  1136. normalizes the range using the procedure in the next section, and returns the
  1137. index k.
  1138. </t>
  1139. <section anchor="range-decoder-renorm" title="Renormalization">
  1140. <t>
  1141. To normalize the range, the decoder repeats the following process, implemented
  1142. by ec_dec_normalize() (entdec.c), until rng&nbsp;&gt;&nbsp;2**23.
  1143. If rng is already greater than 2**23, the entire process is skipped.
  1144. First, it sets rng to (rng&lt;&lt;8).
  1145. Then, it reads the next byte of the Opus frame and forms an 8-bit value sym,
  1146. using the leftover bit buffered from the previous byte as the high bit
  1147. and the top 7 bits of the byte just read as the other 7 bits of sym.
  1148. The remaining bit in the byte just read is buffered for use in the next
  1149. iteration.
  1150. If no more input bytes remain, it uses zero bits instead.
  1151. See <xref target="range-decoder-init"/> for the initialization used to process
  1152. the first byte.
  1153. Then, it sets
  1154. <figure align="center">
  1155. <artwork align="center"><![CDATA[
  1156. val = ((val<<8) + (255-sym)) & 0x7FFFFFFF
  1157. ]]></artwork>
  1158. </figure>
  1159. </t>
  1160. <t>
  1161. It is normal and expected that the range decoder will read several bytes
  1162. into the data of the raw bits (if any) at the end of the frame by the time the
  1163. frame is completely decoded, as illustrated in
  1164. <xref target="finalize-example"/>.
  1165. This same data MUST also be returned as raw bits when requested.
  1166. The encoder is expected to terminate the stream in such a way that the range
  1167. decoder will decode the intended values regardless of the data contained in
  1168. the raw bits.
  1169. <xref target="encoder-finalizing"/> describes a procedure for doing this.
  1170. If the range decoder consumes all of the bytes belonging to the current frame,
  1171. it MUST continue to use zero when any further input bytes are required, even
  1172. if there is additional data in the current packet from padding or other
  1173. frames.
  1174. </t>
  1175. <figure anchor="finalize-example" title="Illustrative Example of Raw Bits
  1176. Overlapping Range Coder Data">
  1177. <artwork align="center"><![CDATA[
  1178. n n+1 n+2 n+3
  1179. 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
  1180. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1181. : | <----------- Overlap region ------------> | :
  1182. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1183. ^ ^
  1184. | End of data buffered by the range coder |
  1185. ...-----------------------------------------------+
  1186. |
  1187. | End of data consumed by raw bits
  1188. +-------------------------------------------------------...
  1189. ]]></artwork>
  1190. </figure>
  1191. </section>
  1192. </section>
  1193. <section anchor="decoding-alternate" title="Alternate Decoding Methods">
  1194. <t>
  1195. The reference implementation uses three additional decoding methods that are
  1196. exactly equivalent to the above but make assumptions and simplifications that
  1197. allow for a more efficient implementation.
  1198. </t>
  1199. <section anchor="ec_decode_bin" title="ec_decode_bin()">
  1200. <t>
  1201. The first is ec_decode_bin() (entdec.c), defined using the parameter ftb
  1202. instead of ft.
  1203. It is mathematically equivalent to calling ec_decode() with
  1204. ft&nbsp;=&nbsp;(1&lt;&lt;ftb), but it avoids one of the divisions.
  1205. </t>
  1206. </section>
  1207. <section anchor="ec_dec_bit_logp" title="ec_dec_bit_logp()">
  1208. <t>
  1209. The next is ec_dec_bit_logp() (entdec.c), which decodes a single binary symbol,
  1210. replacing both the ec_decode() and ec_dec_update() steps.
  1211. The context is described by a single parameter, logp, which is the absolute
  1212. value of the base-2 logarithm of the probability of a "1".
  1213. It is mathematically equivalent to calling ec_decode() with
  1214. ft&nbsp;=&nbsp;(1&lt;&lt;logp), followed by ec_dec_update() with
  1215. the 3-tuple (fl[k]&nbsp;=&nbsp;0,
  1216. fh[k]&nbsp;=&nbsp;(1&lt;&lt;logp)&nbsp;-&nbsp;1,
  1217. ft&nbsp;=&nbsp;(1&lt;&lt;logp)) if the returned value
  1218. of fs is less than (1&lt;&lt;logp)&nbsp;-&nbsp;1 (a "0" was decoded), and with
  1219. (fl[k]&nbsp;=&nbsp;(1&lt;&lt;logp)&nbsp;-&nbsp;1,
  1220. fh[k]&nbsp;=&nbsp;ft&nbsp;=&nbsp;(1&lt;&lt;logp)) otherwise (a "1" was
  1221. decoded).
  1222. The implementation requires no multiplications or divisions.
  1223. </t>
  1224. </section>
  1225. <section anchor="ec_dec_icdf" title="ec_dec_icdf()">
  1226. <t>
  1227. The last is ec_dec_icdf() (entdec.c), which decodes a single symbol with a
  1228. table-based context of up to 8 bits, also replacing both the ec_decode() and
  1229. ec_dec_update() steps, as well as the search for the decoded symbol in between.
  1230. The context is described by two parameters, an icdf
  1231. ("inverse" cumulative distribution function) table and ftb.
  1232. As with ec_decode_bin(), (1&lt;&lt;ftb) is equivalent to ft.
  1233. idcf[k], on the other hand, stores (1&lt;&lt;ftb)-fh[k], which is equal to
  1234. (1&lt;&lt;ftb)&nbsp;-&nbsp;fl[k+1].
  1235. fl[0] is assumed to be 0, and the table is terminated by a value of 0 (where
  1236. fh[k]&nbsp;==&nbsp;ft).
  1237. </t>
  1238. <t>
  1239. The function is mathematically equivalent to calling ec_decode() with
  1240. ft&nbsp;=&nbsp;(1&lt;&lt;ftb), using the returned value fs to search the table
  1241. for the first entry where fs&nbsp;&lt;&nbsp;(1&lt;&lt;ftb)-icdf[k], and
  1242. calling ec_dec_update() with
  1243. fl[k]&nbsp;=&nbsp;(1&lt;&lt;ftb)&nbsp;-&nbsp;icdf[k-1] (or 0
  1244. if k&nbsp;==&nbsp;0), fh[k]&nbsp;=&nbsp;(1&lt;&lt;ftb)&nbsp;-&nbsp;idcf[k],
  1245. and ft&nbsp;=&nbsp;(1&lt;&lt;ftb).
  1246. Combining the search with the update allows the division to be replaced by a
  1247. series of multiplications (which are usually much cheaper), and using an
  1248. inverse CDF allows the use of an ftb as large as 8 in an 8-bit table without
  1249. any special cases.
  1250. This is the primary interface with the range decoder in the SILK layer, though
  1251. it is used in a few places in the CELT layer as well.
  1252. </t>
  1253. <t>
  1254. Although icdf[k] is more convenient for the code, the frequency counts, f[k],
  1255. are a more natural representation of the probability distribution function
  1256. (PDF) for a given symbol.
  1257. Therefore, this document lists the latter, not the former, when describing the
  1258. context in which a symbol is coded as a list, e.g., {4, 4, 4, 4}/16 for a
  1259. uniform context with four possible values and ft&nbsp;=&nbsp;16.
  1260. The value of ft after the slash is always the sum of the entries in the PDF,
  1261. but is included for convenience.
  1262. Contexts with identical probabilities, f[k]/ft, but different values of ft
  1263. (or equivalently, ftb) are not the same, and cannot, in general, be used in
  1264. place of one another.
  1265. An icdf table is also not capable of representing a PDF where the first symbol
  1266. has 0 probability.
  1267. In such contexts, ec_dec_icdf() can decode the symbol by using a table that
  1268. drops the entries for any initial zero-probability values and by adding the
  1269. constant offset of the first value with a non-zero probability to its return
  1270. value.
  1271. </t>
  1272. </section>
  1273. </section>
  1274. <section anchor="decoding-bits" title="Decoding Raw Bits">
  1275. <t>
  1276. The raw bits used by the CELT layer are packed at the end of the frame, with
  1277. the least significant bit of the first value packed in the least significant
  1278. bit of the last byte, filling up to the most significant bit in the last byte,
  1279. continuing on to the least significant bit of the penultimate byte, and so on.
  1280. The reference implementation reads them using ec_dec_bits() (entdec.c).
  1281. Because the range decoder must read several bytes ahead in the stream, as
  1282. described in <xref target="range-decoder-renorm"/>, the input consumed by the
  1283. raw bits may overlap with the input consumed by the range coder, and a decoder
  1284. MUST allow this.
  1285. The format should render it impossible to attempt to read more raw bits than
  1286. there are actual bits in the frame, though a decoder may wish to check for
  1287. this and report an error.
  1288. </t>
  1289. </section>
  1290. <section anchor="ec_dec_uint" title="Decoding Uniformly Distributed Integers">
  1291. <t>
  1292. The function ec_dec_uint() (entdec.c) decodes one of ft equiprobable values in
  1293. the range 0 to (ft&nbsp;-&nbsp;1), inclusive, each with a frequency of 1,
  1294. where ft may be as large as (2**32&nbsp;-&nbsp;1).
  1295. Because ec_decode() is limited to a total frequency of (2**16&nbsp;-&nbsp;1),
  1296. it splits up the value into a range coded symbol representing up to 8 of the
  1297. high bits, and, if necessary, raw bits representing the remainder of the
  1298. value.
  1299. The limit of 8 bits in the range coded symbol is a trade-off between
  1300. implementation complexity, modeling error (since the symbols no longer truly
  1301. have equal coding cost), and rounding error introduced by the range coder
  1302. itself (which gets larger as more bits are included).
  1303. Using raw bits reduces the maximum number of divisions required in the worst
  1304. case, but means that it may be possible to decode a value outside the range
  1305. 0 to (ft&nbsp;-&nbsp;1), inclusive.
  1306. </t>
  1307. <t>
  1308. ec_dec_uint() takes a single, positive parameter, ft, which is not necessarily
  1309. a power of two, and returns an integer, t, whose value lies between 0 and
  1310. (ft&nbsp;-&nbsp;1), inclusive.
  1311. Let ftb&nbsp;=&nbsp;ilog(ft&nbsp;-&nbsp;1), i.e., the number of bits required
  1312. to store (ft&nbsp;-&nbsp;1) in two's complement notation.
  1313. If ftb is 8 or less, then t is decoded with t&nbsp;=&nbsp;ec_decode(ft), and
  1314. the range coder state is updated using the three-tuple (t, t&nbsp;+&nbsp;1,
  1315. ft).
  1316. </t>
  1317. <t>
  1318. If ftb is greater than 8, then the top 8 bits of t are decoded using
  1319. <figure align="center">
  1320. <artwork align="center"><![CDATA[
  1321. t = ec_decode(((ft - 1) >> (ftb - 8)) + 1)
  1322. ]]></artwork>
  1323. </figure>
  1324. the decoder state is updated using the three-tuple
  1325. (t, t&nbsp;+&nbsp;1,
  1326. ((ft&nbsp;-&nbsp;1)&nbsp;&gt;&gt;&nbsp;(ftb&nbsp;-&nbsp;8))&nbsp;+&nbsp;1),
  1327. and the remaining bits are decoded as raw bits, setting
  1328. <figure align="center">
  1329. <artwork align="center"><![CDATA[
  1330. t = (t << (ftb - 8)) | ec_dec_bits(ftb - 8)
  1331. ]]></artwork>
  1332. </figure>
  1333. If, at this point, t >= ft, then the current frame is corrupt.
  1334. In that case, the decoder should assume there has been an error in the coding,
  1335. decoding, or transmission and SHOULD take measures to conceal the
  1336. error (e.g., saturate to ft-1 or use the Packet Loss Concealment (PLC)) and/or report to the application
  1337. that the error has occurred.
  1338. </t>
  1339. </section>
  1340. <section anchor="decoder-tell" title="Current Bit Usage">
  1341. <t>
  1342. The bit allocation routines in the CELT decoder need a conservative upper bound
  1343. on the number of bits that have been used from the current frame thus far,
  1344. including both range coder bits and raw bits.
  1345. This drives allocation decisions that must match those made in the encoder.
  1346. The upper bound is computed in the reference implementation to whole-bit
  1347. precision by the function ec_tell() (entcode.h) and to fractional 1/8th bit
  1348. precision by the function ec_tell_frac() (entcode.c).
  1349. Like all operations in the range coder, it must be implemented in a bit-exact
  1350. manner, and it must produce exactly the same value returned by the same functions
  1351. in the encoder after encoding the same symbols.
  1352. </t>
  1353. <t>
  1354. ec_tell() is guaranteed to return ceil(ec_tell_frac()/8.0).
  1355. In various places, the codec will check to ensure there is enough room to
  1356. contain a symbol before attempting to decode it.
  1357. In practice, although the number of bits used so far is an upper bound,
  1358. decoding a symbol whose probability model suggests it has a worst-case cost of
  1359. p 1/8th bits may actually advance the return value of ec_tell_frac() by
  1360. p-1, p, or p+1 1/8th bits, due to approximation error in that upper bound,
  1361. truncation error in the range coder, and for large values of ft, modeling
  1362. error in ec_dec_uint().
  1363. </t>
  1364. <t>
  1365. However, this error is bounded, and periodic calls to ec_tell() or
  1366. ec_tell_frac() at precisely defined points in the decoding process prevent it
  1367. from accumulating.
  1368. For a range coder symbol that requires a whole number of bits (i.e.,
  1369. for which ft/(fh[k]&nbsp;-&nbsp;fl[k]) is a power of two), where there are at
  1370. least p 1/8th bits available, decoding the symbol will never cause ec_tell() or
  1371. ec_tell_frac() to exceed the size of the frame ("bust the budget").
  1372. In this case, the return value of ec_tell_frac() will only advance by more than
  1373. p 1/8th bits if there were an additional, fractional number of bits remaining,
  1374. and it will never advance beyond the next whole-bit boundary, which is safe,
  1375. since frames always contain a whole number of bits.
  1376. However, when p is not a whole number of bits, an extra 1/8th bit is required
  1377. to ensure that decoding the symbol will not bust the budget.
  1378. </t>
  1379. <t>
  1380. The reference implementation keeps track of the total number of whole bits that
  1381. have been processed by the decoder so far in the variable nbits_total,
  1382. including the (possibly fractional) number of bits that are currently
  1383. buffered, but not consumed, inside the range coder.
  1384. nbits_total is initialized to 9 just before the initial range renormalization
  1385. process completes (or equivalently, it can be initialized to 33 after the
  1386. first renormalization).
  1387. The extra two bits over the actual amount buffered by the range coder
  1388. guarantees that it is an upper bound and that there is enough room for the
  1389. encoder to terminate the stream.
  1390. Each iteration through the range coder's renormalization loop increases
  1391. nbits_total by 8.
  1392. Reading raw bits increases nbits_total by the number of raw bits read.
  1393. </t>
  1394. <section anchor="ec_tell" title="ec_tell()">
  1395. <t>
  1396. The whole number of bits buffered in rng may be estimated via lg = ilog(rng).
  1397. ec_tell() then becomes a simple matter of removing these bits from the total.
  1398. It returns (nbits_total - lg).
  1399. </t>
  1400. <t>
  1401. In a newly initialized decoder, before any symbols have been read, this reports
  1402. that 1 bit has been used.
  1403. This is the bit reserved for termination of the encoder.
  1404. </t>
  1405. </section>
  1406. <section anchor="ec_tell_frac" title="ec_tell_frac()">
  1407. <t>
  1408. ec_tell_frac() estimates the number of bits buffered in rng to fractional
  1409. precision.
  1410. Since rng must be greater than 2**23 after renormalization, lg must be at least
  1411. 24.
  1412. Let
  1413. <figure align="center">
  1414. <artwork align="center">
  1415. <![CDATA[
  1416. r_Q15 = rng >> (lg-16)
  1417. ]]></artwork>
  1418. </figure>
  1419. so that 32768 &lt;= r_Q15 &lt; 65536, an unsigned Q15 value representing the
  1420. fractional part of rng.
  1421. Then, the following procedure can be used to add one bit of precision to lg.
  1422. First, update
  1423. <figure align="center">
  1424. <artwork align="center">
  1425. <![CDATA[
  1426. r_Q15 = (r_Q15*r_Q15) >> 15
  1427. ]]></artwork>
  1428. </figure>
  1429. Then, add the 16th bit of r_Q15 to lg via
  1430. <figure align="center">
  1431. <artwork align="center">
  1432. <![CDATA[
  1433. lg = 2*lg + (r_Q15 >> 16)
  1434. ]]></artwork>
  1435. </figure>
  1436. Finally, if this bit was a 1, reduce r_Q15 by a factor of two via
  1437. <figure align="center">
  1438. <artwork align="center">
  1439. <![CDATA[
  1440. r_Q15 = r_Q15 >> 1
  1441. ]]></artwork>
  1442. </figure>
  1443. so that it once again lies in the range 32768 &lt;= r_Q15 &lt; 65536.
  1444. </t>
  1445. <t>
  1446. This procedure is repeated three times to extend lg to 1/8th bit precision.
  1447. ec_tell_frac() then returns (nbits_total*8 - lg).
  1448. </t>
  1449. </section>
  1450. </section>
  1451. </section>
  1452. <section anchor="silk_decoder_outline" title="SILK Decoder">
  1453. <t>
  1454. The decoder's LP layer uses a modified version of the SILK codec (herein simply
  1455. called "SILK"), which runs a decoded excitation signal through adaptive
  1456. long-term and short-term prediction synthesis filters.
  1457. It runs at NB, MB, and WB sample rates internally.
  1458. When used in a SWB or FB Hybrid frame, the LP layer itself still only runs in
  1459. WB.
  1460. </t>
  1461. <section title="SILK Decoder Modules">
  1462. <t>
  1463. An overview of the decoder is given in <xref target="silk_decoder_figure"/>.
  1464. </t>
  1465. <figure align="center" anchor="silk_decoder_figure" title="SILK Decoder">
  1466. <artwork align="center">
  1467. <![CDATA[
  1468. +---------+ +------------+
  1469. -->| Range |--->| Decode |---------------------------+
  1470. 1 | Decoder | 2 | Parameters |----------+ 5 |
  1471. +---------+ +------------+ 4 | |
  1472. 3 | | |
  1473. \/ \/ \/
  1474. +------------+ +------------+ +------------+
  1475. | Generate |-->| LTP |-->| LPC |
  1476. | Excitation | | Synthesis | | Synthesis |
  1477. +------------+ +------------+ +------------+
  1478. ^ |
  1479. | |
  1480. +-------------------+----------------+
  1481. | 6
  1482. | +------------+ +-------------+
  1483. +-->| Stereo |-->| Sample Rate |-->
  1484. | Unmixing | 7 | Conversion | 8
  1485. +------------+ +-------------+
  1486. 1: Range encoded bitstream
  1487. 2: Coded parameters
  1488. 3: Pulses, LSBs, and signs
  1489. 4: Pitch lags, Long-Term Prediction (LTP) coefficients
  1490. 5: Linear Predictive Coding (LPC) coefficients and gains
  1491. 6: Decoded signal (mono or mid-side stereo)
  1492. 7: Unmixed signal (mono or left-right stereo)
  1493. 8: Resampled signal
  1494. ]]>
  1495. </artwork>
  1496. </figure>
  1497. <t>
  1498. The decoder feeds the bitstream (1) to the range decoder from
  1499. <xref target="range-decoder"/> and then decodes the parameters in it (2)
  1500. using the procedures detailed in
  1501. Sections&nbsp;<xref format="counter" target="silk_header_bits"/>
  1502. through&nbsp;<xref format="counter" target="silk_signs"/>.
  1503. These parameters (3, 4, 5) are used to generate an excitation signal (see
  1504. <xref target="silk_excitation_reconstruction"/>), which is fed to an optional
  1505. Long-Term Prediction (LTP) filter (voiced frames only, see
  1506. <xref target="silk_ltp_synthesis"/>) and then a short-term prediction filter
  1507. (see <xref target="silk_lpc_synthesis"/>), producing the decoded signal (6).
  1508. For stereo streams, the mid-side representation is converted to separate left
  1509. and right channels (7).
  1510. The result is finally resampled to the desired output sample rate (e.g.,
  1511. 48&nbsp;kHz) so that the resampled signal (8) can be mixed with the CELT
  1512. layer.
  1513. </t>
  1514. </section>
  1515. <section anchor="silk_layer_organization" title="LP Layer Organization">
  1516. <t>
  1517. Internally, the LP layer of a single Opus frame is composed of either a single
  1518. 10&nbsp;ms regular SILK frame or between one and three 20&nbsp;ms regular SILK
  1519. frames.
  1520. A stereo Opus frame may double the number of regular SILK frames (up to a total
  1521. of six), since it includes separate frames for a mid channel and, optionally,
  1522. a side channel.
  1523. Optional Low Bit-Rate Redundancy (LBRR) frames, which are reduced-bitrate
  1524. encodings of previous SILK frames, may be included to aid in recovery from
  1525. packet loss.
  1526. If present, these appear before the regular SILK frames.
  1527. They are, in most respects, identical to regular, active SILK frames, except that
  1528. they are usually encoded with a lower bitrate.
  1529. This document uses "SILK frame" to refer to either one and "regular SILK frame" if
  1530. it needs to draw a distinction between the two.
  1531. </t>
  1532. <t>
  1533. Logically, each SILK frame is, in turn, composed of either two or four 5&nbsp;ms
  1534. subframes.
  1535. Various parameters, such as the quantization gain of the excitation and the
  1536. pitch lag and filter coefficients can vary on a subframe-by-subframe basis.
  1537. Physically, the parameters for each subframe are interleaved in the bitstream,
  1538. as described in the relevant sections for each parameter.
  1539. </t>
  1540. <t>
  1541. All of these frames and subframes are decoded from the same range coder, with
  1542. no padding between them.
  1543. Thus, packing multiple SILK frames in a single Opus frame saves, on average,
  1544. half a byte per SILK frame.
  1545. It also allows some parameters to be predicted from prior SILK frames in the
  1546. same Opus frame, since this does not degrade packet loss robustness (beyond
  1547. any penalty for merely using fewer, larger packets to store multiple frames).
  1548. </t>
  1549. <t>
  1550. Stereo support in SILK uses a variant of mid-side coding, allowing a mono
  1551. decoder to simply decode the mid channel.
  1552. However, the data for the two channels is interleaved, so a mono decoder must
  1553. still unpack the data for the side channel.
  1554. It would be required to do so anyway for Hybrid Opus frames or to support
  1555. decoding individual 20&nbsp;ms frames.
  1556. </t>
  1557. <t>
  1558. <xref target="silk_symbols"/> summarizes the overall grouping of the contents of
  1559. the LP layer.
  1560. Figures&nbsp;<xref format="counter" target="silk_mono_60ms_frame"/>
  1561. and&nbsp;<xref format="counter" target="silk_stereo_60ms_frame"/> illustrate
  1562. the ordering of the various SILK frames for a 60&nbsp;ms Opus frame, for both
  1563. mono and stereo, respectively.
  1564. </t>
  1565. <?rfc compact="no" ?>
  1566. <texttable anchor="silk_symbols"
  1567. title="Organization of the SILK layer of an Opus Frame">
  1568. <ttcol align="center">Symbol(s)</ttcol>
  1569. <ttcol align="center">PDF(s)</ttcol>
  1570. <ttcol align="center">Condition</ttcol>
  1571. <c>Voice Activity Detection (VAD) Flags</c>
  1572. <c>{1, 1}/2</c>
  1573. <c/>
  1574. <c>LBRR Flag</c>
  1575. <c>{1, 1}/2</c>
  1576. <c/>
  1577. <c>Per-Frame LBRR Flags</c>
  1578. <c><xref target="silk_lbrr_flag_pdfs"/></c>
  1579. <c><xref target="silk_lbrr_flags"/></c>
  1580. <c>LBRR Frame(s)</c>
  1581. <c><xref target="silk_frame"/></c>
  1582. <c><xref target="silk_lbrr_flags"/></c>
  1583. <c>Regular SILK Frame(s)</c>
  1584. <c><xref target="silk_frame"/></c>
  1585. <c/>
  1586. </texttable>
  1587. <?rfc compact="yes" ?>
  1588. <figure align="center" anchor="silk_mono_60ms_frame"
  1589. title="A 60&nbsp;ms Mono Frame">
  1590. <artwork align="center"><![CDATA[
  1591. +---------------------------------+
  1592. | VAD Flags |
  1593. +---------------------------------+
  1594. | LBRR Flag |
  1595. +---------------------------------+
  1596. | Per-Frame LBRR Flags (Optional) |
  1597. +---------------------------------+
  1598. | LBRR Frame 1 (Optional) |
  1599. +---------------------------------+
  1600. | LBRR Frame 2 (Optional) |
  1601. +---------------------------------+
  1602. | LBRR Frame 3 (Optional) |
  1603. +---------------------------------+
  1604. | Regular SILK Frame 1 |
  1605. +---------------------------------+
  1606. | Regular SILK Frame 2 |
  1607. +---------------------------------+
  1608. | Regular SILK Frame 3 |
  1609. +---------------------------------+
  1610. ]]></artwork>
  1611. </figure>
  1612. <figure align="center" anchor="silk_stereo_60ms_frame"
  1613. title="A 60&nbsp;ms Stereo Frame">
  1614. <artwork align="center"><![CDATA[
  1615. +---------------------------------------+
  1616. | Mid VAD Flags |
  1617. +---------------------------------------+
  1618. | Mid LBRR Flag |
  1619. +---------------------------------------+
  1620. | Side VAD Flags |
  1621. +---------------------------------------+
  1622. | Side LBRR Flag |
  1623. +---------------------------------------+
  1624. | Mid Per-Frame LBRR Flags (Optional) |
  1625. +---------------------------------------+
  1626. | Side Per-Frame LBRR Flags (Optional) |
  1627. +---------------------------------------+
  1628. | Mid LBRR Frame 1 (Optional) |
  1629. +---------------------------------------+
  1630. | Side LBRR Frame 1 (Optional) |
  1631. +---------------------------------------+
  1632. | Mid LBRR Frame 2 (Optional) |
  1633. +---------------------------------------+
  1634. | Side LBRR Frame 2 (Optional) |
  1635. +---------------------------------------+
  1636. | Mid LBRR Frame 3 (Optional) |
  1637. +---------------------------------------+
  1638. | Side LBRR Frame 3 (Optional) |
  1639. +---------------------------------------+
  1640. | Mid Regular SILK Frame 1 |
  1641. +---------------------------------------+
  1642. | Side Regular SILK Frame 1 (Optional) |
  1643. +---------------------------------------+
  1644. | Mid Regular SILK Frame 2 |
  1645. +---------------------------------------+
  1646. | Side Regular SILK Frame 2 (Optional) |
  1647. +---------------------------------------+
  1648. | Mid Regular SILK Frame 3 |
  1649. +---------------------------------------+
  1650. | Side Regular SILK Frame 3 (Optional) |
  1651. +---------------------------------------+
  1652. ]]></artwork>
  1653. </figure>
  1654. </section>
  1655. <section anchor="silk_header_bits" title="Header Bits">
  1656. <t>
  1657. The LP layer begins with two to eight header bits, decoded in silk_Decode()
  1658. (dec_API.c).
  1659. These consist of one Voice Activity Detection (VAD) bit per frame (up to 3),
  1660. followed by a single flag indicating the presence of LBRR frames.
  1661. For a stereo packet, these first flags correspond to the mid channel, and a
  1662. second set of flags is included for the side channel.
  1663. </t>
  1664. <t>
  1665. Because these are the first symbols decoded by the range coder and because they
  1666. are coded as binary values with uniform probability, they can be extracted
  1667. directly from the most significant bits of the first byte of compressed data.
  1668. Thus, a receiver can determine if an Opus frame contains any active SILK frames
  1669. without the overhead of using the range decoder.
  1670. </t>
  1671. </section>
  1672. <section anchor="silk_lbrr_flags" title="Per-Frame LBRR Flags">
  1673. <t>
  1674. For Opus frames longer than 20&nbsp;ms, a set of LBRR flags is
  1675. decoded for each channel that has its LBRR flag set.
  1676. Each set contains one flag per 20&nbsp;ms SILK frame.
  1677. 40&nbsp;ms Opus frames use the 2-frame LBRR flag PDF from
  1678. <xref target="silk_lbrr_flag_pdfs"/>, and 60&nbsp;ms Opus frames use the
  1679. 3-frame LBRR flag PDF.
  1680. For each channel, the resulting 2- or 3-bit integer contains the corresponding
  1681. LBRR flag for each frame, packed in order from the LSB to the MSB.
  1682. </t>
  1683. <?rfc compact="no" ?>
  1684. <texttable anchor="silk_lbrr_flag_pdfs" title="LBRR Flag PDFs">
  1685. <ttcol>Frame Size</ttcol>
  1686. <ttcol>PDF</ttcol>
  1687. <c>40&nbsp;ms</c> <c>{0, 53, 53, 150}/256</c>
  1688. <c>60&nbsp;ms</c> <c>{0, 41, 20, 29, 41, 15, 28, 82}/256</c>
  1689. </texttable>
  1690. <?rfc compact="yes" ?>
  1691. <t>
  1692. A 10&nbsp;or 20&nbsp;ms Opus frame does not contain any per-frame LBRR flags,
  1693. as there may be at most one LBRR frame per channel.
  1694. The global LBRR flag in the header bits (see <xref target="silk_header_bits"/>)
  1695. is already sufficient to indicate the presence of that single LBRR frame.
  1696. </t>
  1697. </section>
  1698. <section anchor="silk_lbrr_frames" title="LBRR Frames">
  1699. <t>
  1700. The LBRR frames, if present, contain an encoded representation of the signal
  1701. immediately prior to the current Opus frame as if it were encoded with the
  1702. current mode, frame size, audio bandwidth, and channel count, even if those
  1703. differ from the prior Opus frame.
  1704. When one of these parameters changes from one Opus frame to the next, this
  1705. implies that the LBRR frames of the current Opus frame may not be simple
  1706. drop-in replacements for the contents of the previous Opus frame.
  1707. </t>
  1708. <t>
  1709. For example, when switching from 20&nbsp;ms to 60&nbsp;ms, the 60&nbsp;ms Opus
  1710. frame may contain LBRR frames covering up to three prior 20&nbsp;ms Opus
  1711. frames, even if those frames already contained LBRR frames covering some of
  1712. the same time periods.
  1713. When switching from 20&nbsp;ms to 10&nbsp;ms, the 10&nbsp;ms Opus frame can
  1714. contain an LBRR frame covering at most half the prior 20&nbsp;ms Opus frame,
  1715. potentially leaving a hole that needs to be concealed from even a single
  1716. packet loss (see <xref target="Packet Loss Concealment"/>).
  1717. When switching from mono to stereo, the LBRR frames in the first stereo Opus
  1718. frame MAY contain a non-trivial side channel.
  1719. </t>
  1720. <t>
  1721. In order to properly produce LBRR frames under all conditions, an encoder might
  1722. need to buffer up to 60&nbsp;ms of audio and re-encode it during these
  1723. transitions.
  1724. However, the reference implementation opts to disable LBRR frames at the
  1725. transition point for simplicity.
  1726. Since transitions are relatively infrequent in normal usage, this does not have
  1727. a significant impact on packet loss robustness.
  1728. </t>
  1729. <t>
  1730. The LBRR frames immediately follow the LBRR flags, prior to any regular SILK
  1731. frames.
  1732. <xref target="silk_frame"/> describes their exact contents.
  1733. LBRR frames do not include their own separate VAD flags.
  1734. LBRR frames are only meant to be transmitted for active speech, thus all LBRR
  1735. frames are treated as active.
  1736. </t>
  1737. <t>
  1738. In a stereo Opus frame longer than 20&nbsp;ms, although the per-frame LBRR
  1739. flags for the mid channel are coded as a unit before the per-frame LBRR flags
  1740. for the side channel, the LBRR frames themselves are interleaved.
  1741. The decoder parses an LBRR frame for the mid channel of a given 20&nbsp;ms
  1742. interval (if present) and then immediately parses the corresponding LBRR
  1743. frame for the side channel (if present), before proceeding to the next
  1744. 20&nbsp;ms interval.
  1745. </t>
  1746. </section>
  1747. <section anchor="silk_regular_frames" title="Regular SILK Frames">
  1748. <t>
  1749. The regular SILK frame(s) follow the LBRR frames (if any).
  1750. <xref target="silk_frame"/> describes their contents, as well.
  1751. Unlike the LBRR frames, a regular SILK frame is coded for each time interval in
  1752. an Opus frame, even if the corresponding VAD flags are unset.
  1753. For stereo Opus frames longer than 20&nbsp;ms, the regular mid and side SILK
  1754. frames for each 20&nbsp;ms interval are interleaved, just as with the LBRR
  1755. frames.
  1756. The side frame may be skipped by coding an appropriate flag, as detailed in
  1757. <xref target="silk_mid_only_flag"/>.
  1758. </t>
  1759. </section>
  1760. <section anchor="silk_frame" title="SILK Frame Contents">
  1761. <t>
  1762. Each SILK frame includes a set of side information that encodes
  1763. <list style="symbols">
  1764. <t>The frame type and quantization type (<xref target="silk_frame_type"/>),</t>
  1765. <t>Quantization gains (<xref target="silk_gains"/>),</t>
  1766. <t>Short-term prediction filter coefficients (<xref target="silk_nlsfs"/>),</t>
  1767. <t>A Line Spectral Frequencies (LSFs) interpolation weight (<xref target="silk_nlsf_interpolation"/>),</t>
  1768. <t>
  1769. LTP filter lags and gains (<xref target="silk_ltp_params"/>),
  1770. and
  1771. </t>
  1772. <t>A Linear Congruential Generator (LCG) seed (<xref target="silk_seed"/>).</t>
  1773. </list>
  1774. The quantized excitation signal (see <xref target="silk_excitation"/>) follows
  1775. these at the end of the frame.
  1776. <xref target="silk_frame_symbols"/> details the overall organization of a
  1777. SILK frame.
  1778. </t>
  1779. <?rfc compact="no" ?>
  1780. <texttable anchor="silk_frame_symbols"
  1781. title="Order of the Symbols in an Individual SILK Frame">
  1782. <ttcol align="center">Symbol(s)</ttcol>
  1783. <ttcol align="center">PDF(s)</ttcol>
  1784. <ttcol align="center">Condition</ttcol>
  1785. <c>Stereo Prediction Weights</c>
  1786. <c><xref target="silk_stereo_pred_pdfs"/></c>
  1787. <c><xref target="silk_stereo_pred"/></c>
  1788. <c>Mid-only Flag</c>
  1789. <c><xref target="silk_mid_only_pdf"/></c>
  1790. <c><xref target="silk_mid_only_flag"/></c>
  1791. <c>Frame Type</c>
  1792. <c><xref target="silk_frame_type"/></c>
  1793. <c/>
  1794. <c>Subframe Gains</c>
  1795. <c><xref target="silk_gains"/></c>
  1796. <c/>
  1797. <c>Normalized LSF Stage-1 Index</c>
  1798. <c><xref target="silk_nlsf_stage1_pdfs"/></c>
  1799. <c/>
  1800. <c>Normalized LSF Stage-2 Residual</c>
  1801. <c><xref target="silk_nlsf_stage2"/></c>
  1802. <c/>
  1803. <c>Normalized LSF Interpolation Weight</c>
  1804. <c><xref target="silk_nlsf_interp_pdf"/></c>
  1805. <c>20&nbsp;ms frame</c>
  1806. <c>Primary Pitch Lag</c>
  1807. <c><xref target="silk_ltp_lags"/></c>
  1808. <c>Voiced frame</c>
  1809. <c>Subframe Pitch Contour</c>
  1810. <c><xref target="silk_pitch_contour_pdfs"/></c>
  1811. <c>Voiced frame</c>
  1812. <c>Periodicity Index</c>
  1813. <c><xref target="silk_perindex_pdf"/></c>
  1814. <c>Voiced frame</c>
  1815. <c>LTP Filter</c>
  1816. <c><xref target="silk_ltp_filter_pdfs"/></c>
  1817. <c>Voiced frame</c>
  1818. <c>LTP Scaling</c>
  1819. <c><xref target="silk_ltp_scaling_pdf"/></c>
  1820. <c><xref target="silk_ltp_scaling"/></c>
  1821. <c>LCG Seed</c>
  1822. <c><xref target="silk_seed_pdf"/></c>
  1823. <c/>
  1824. <c>Excitation Rate Level</c>
  1825. <c><xref target="silk_rate_level_pdfs"/></c>
  1826. <c/>
  1827. <c>Excitation Pulse Counts</c>
  1828. <c><xref target="silk_pulse_count_pdfs"/></c>
  1829. <c/>
  1830. <c>Excitation Pulse Locations</c>
  1831. <c><xref target="silk_pulse_locations"/></c>
  1832. <c>Non-zero pulse count</c>
  1833. <c>Excitation LSBs</c>
  1834. <c><xref target="silk_shell_lsb_pdf"/></c>
  1835. <c><xref target="silk_pulse_counts"/></c>
  1836. <c>Excitation Signs</c>
  1837. <c><xref target="silk_sign_pdfs"/></c>
  1838. <c/>
  1839. </texttable>
  1840. <?rfc compact="yes" ?>
  1841. <section anchor="silk_stereo_pred" toc="include"
  1842. title="Stereo Prediction Weights">
  1843. <t>
  1844. A SILK frame corresponding to the mid channel of a stereo Opus frame begins
  1845. with a pair of side channel prediction weights, designed such that zeros
  1846. indicate normal mid-side coupling.
  1847. Since these weights can change on every frame, the first portion of each frame
  1848. linearly interpolates between the previous weights and the current ones, using
  1849. zeros for the previous weights if none are available.
  1850. These prediction weights are never included in a mono Opus frame, and the
  1851. previous weights are reset to zeros on any transition from mono to stereo.
  1852. They are also not included in an LBRR frame for the side channel, even if the
  1853. LBRR flags indicate the corresponding mid channel was not coded.
  1854. In that case, the previous weights are used, again substituting in zeros if no
  1855. previous weights are available since the last decoder reset
  1856. (see <xref target="decoder-reset"/>).
  1857. </t>
  1858. <t>
  1859. To summarize, these weights are coded if and only if
  1860. <list style="symbols">
  1861. <t>This is a stereo Opus frame (<xref target="toc_byte"/>), and</t>
  1862. <t>The current SILK frame corresponds to the mid channel.</t>
  1863. </list>
  1864. </t>
  1865. <t>
  1866. The prediction weights are coded in three separate pieces, which are decoded
  1867. by silk_stereo_decode_pred() (stereo_decode_pred.c).
  1868. The first piece jointly codes the high-order part of a table index for both
  1869. weights.
  1870. The second piece codes the low-order part of each table index.
  1871. The third piece codes an offset used to linearly interpolate between table
  1872. indices.
  1873. The details are as follows.
  1874. </t>
  1875. <t>
  1876. Let n be an index decoded with the 25-element stage-1 PDF in
  1877. <xref target="silk_stereo_pred_pdfs"/>.
  1878. Then, let i0 and i1 be indices decoded with the stage-2 and stage-3 PDFs in
  1879. <xref target="silk_stereo_pred_pdfs"/>, respectively, and let i2 and i3
  1880. be two more indices decoded with the stage-2 and stage-3 PDFs, all in that
  1881. order.
  1882. </t>
  1883. <?rfc compact="no" ?>
  1884. <texttable anchor="silk_stereo_pred_pdfs" title="Stereo Weight PDFs">
  1885. <ttcol align="left">Stage</ttcol>
  1886. <ttcol align="left">PDF</ttcol>
  1887. <c>Stage 1</c>
  1888. <c>{7, 2, 1, 1, 1,
  1889. 10, 24, 8, 1, 1,
  1890. 3, 23, 92, 23, 3,
  1891. 1, 1, 8, 24, 10,
  1892. 1, 1, 1, 2, 7}/256</c>
  1893. <c>Stage 2</c>
  1894. <c>{85, 86, 85}/256</c>
  1895. <c>Stage 3</c>
  1896. <c>{51, 51, 52, 51, 51}/256</c>
  1897. </texttable>
  1898. <?rfc compact="yes" ?>
  1899. <t>
  1900. Then, use n, i0, and i2 to form two table indices, wi0 and wi1, according to
  1901. <figure align="center">
  1902. <artwork align="center"><![CDATA[
  1903. wi0 = i0 + 3*(n/5)
  1904. wi1 = i2 + 3*(n%5)
  1905. ]]></artwork>
  1906. </figure>
  1907. where the division is integer division.
  1908. The range of these indices is 0 to 14, inclusive.
  1909. Let w_Q13[i] be the i'th weight from <xref target="silk_stereo_weights_table"/>.
  1910. Then, the two prediction weights, w0_Q13 and w1_Q13, are
  1911. <figure align="center">
  1912. <artwork align="center"><![CDATA[
  1913. w1_Q13 = w_Q13[wi1]
  1914. + (((w_Q13[wi1+1] - w_Q13[wi1])*6554) >> 16)*(2*i3 + 1)
  1915. w0_Q13 = w_Q13[wi0]
  1916. + (((w_Q13[wi0+1] - w_Q13[wi0])*6554) >> 16)*(2*i1 + 1)
  1917. - w1_Q13
  1918. ]]></artwork>
  1919. </figure>
  1920. N.B., w1_Q13 is computed first here, because w0_Q13 depends on it.
  1921. The constant 6554 is approximately 0.1 in Q16.
  1922. Although wi0 and wi1 only have 15 possible values,
  1923. <xref target="silk_stereo_weights_table"/> contains 16 entries to allow
  1924. interpolation between entry wi0 and (wi0&nbsp;+&nbsp;1) (and likewise for wi1).
  1925. </t>
  1926. <?rfc compact="no" ?>
  1927. <texttable anchor="silk_stereo_weights_table"
  1928. title="Stereo Weight Table">
  1929. <ttcol align="left">Index</ttcol>
  1930. <ttcol align="right">Weight (Q13)</ttcol>
  1931. <c>0</c> <c>-13732</c>
  1932. <c>1</c> <c>-10050</c>
  1933. <c>2</c> <c>-8266</c>
  1934. <c>3</c> <c>-7526</c>
  1935. <c>4</c> <c>-6500</c>
  1936. <c>5</c> <c>-5000</c>
  1937. <c>6</c> <c>-2950</c>
  1938. <c>7</c> <c>-820</c>
  1939. <c>8</c> <c>820</c>
  1940. <c>9</c> <c>2950</c>
  1941. <c>10</c> <c>5000</c>
  1942. <c>11</c> <c>6500</c>
  1943. <c>12</c> <c>7526</c>
  1944. <c>13</c> <c>8266</c>
  1945. <c>14</c> <c>10050</c>
  1946. <c>15</c> <c>13732</c>
  1947. </texttable>
  1948. <?rfc compact="yes" ?>
  1949. </section>
  1950. <section anchor="silk_mid_only_flag" toc="include" title="Mid-Only Flag">
  1951. <t>
  1952. A flag appears after the stereo prediction weights that indicates if only the
  1953. mid channel is coded for this time interval.
  1954. It appears only when
  1955. <list style="symbols">
  1956. <t>This is a stereo Opus frame (see <xref target="toc_byte"/>),</t>
  1957. <t>The current SILK frame corresponds to the mid channel, and</t>
  1958. <t>Either
  1959. <list style="symbols">
  1960. <t>This is a regular SILK frame where the VAD flags
  1961. (see <xref target="silk_header_bits"/>) indicate that the corresponding side
  1962. channel is not active.</t>
  1963. <t>
  1964. This is an LBRR frame where the LBRR flags (see
  1965. Sections&nbsp;<xref target="silk_header_bits" format="counter"/>
  1966. and&nbsp;<xref target="silk_lbrr_flags" format="counter"/>)
  1967. indicate that the corresponding side channel is not coded.
  1968. </t>
  1969. </list>
  1970. </t>
  1971. </list>
  1972. It is omitted when there are no stereo weights, for all of the same reasons.
  1973. It is also omitted for a regular SILK frame when the VAD flag of the
  1974. corresponding side channel frame is set (indicating it is active).
  1975. The side channel must be coded in this case, making the mid-only flag
  1976. redundant.
  1977. It is also omitted for an LBRR frame when the corresponding LBRR flags
  1978. indicate the side channel is coded.
  1979. </t>
  1980. <t>
  1981. When the flag is present, the decoder reads a single value using the PDF in
  1982. <xref target="silk_mid_only_pdf"/>, as implemented in
  1983. silk_stereo_decode_mid_only() (stereo_decode_pred.c).
  1984. If the flag is set, then there is no corresponding SILK frame for the side
  1985. channel, the entire decoding process for the side channel is skipped, and
  1986. zeros are fed to the stereo unmixing process (see
  1987. <xref target="silk_stereo_unmixing"/>) instead.
  1988. As stated above, LBRR frames still include this flag when the LBRR flag
  1989. indicates that the side channel is not coded.
  1990. In that case, if this flag is zero (indicating that there should be a side
  1991. channel), then Packet Loss Concealment (PLC, see
  1992. <xref target="Packet Loss Concealment"/>) SHOULD be invoked to recover a
  1993. side channel signal.
  1994. Otherwise, the stereo image will collapse.
  1995. </t>
  1996. <?rfc compact="no" ?>
  1997. <texttable anchor="silk_mid_only_pdf" title="Mid-only Flag PDF">
  1998. <ttcol align="left">PDF</ttcol>
  1999. <c>{192, 64}/256</c>
  2000. </texttable>
  2001. <?rfc compact="yes" ?>
  2002. </section>
  2003. <section anchor="silk_frame_type" toc="include" title="Frame Type">
  2004. <t>
  2005. Each SILK frame contains a single "frame type" symbol that jointly codes the
  2006. signal type and quantization offset type of the corresponding frame.
  2007. If the current frame is a regular SILK frame whose VAD bit was not set (an
  2008. "inactive" frame), then the frame type symbol takes on a value of either 0 or
  2009. 1 and is decoded using the first PDF in <xref target="silk_frame_type_pdfs"/>.
  2010. If the frame is an LBRR frame or a regular SILK frame whose VAD flag was set
  2011. (an "active" frame), then the value of the symbol may range from 2 to 5,
  2012. inclusive, and is decoded using the second PDF in
  2013. <xref target="silk_frame_type_pdfs"/>.
  2014. <xref target="silk_frame_type_table"/> translates between the value of the
  2015. frame type symbol and the corresponding signal type and quantization offset
  2016. type.
  2017. </t>
  2018. <?rfc compact="no" ?>
  2019. <texttable anchor="silk_frame_type_pdfs" title="Frame Type PDFs">
  2020. <ttcol>VAD Flag</ttcol>
  2021. <ttcol>PDF</ttcol>
  2022. <c>Inactive</c> <c>{26, 230, 0, 0, 0, 0}/256</c>
  2023. <c>Active</c> <c>{0, 0, 24, 74, 148, 10}/256</c>
  2024. </texttable>
  2025. <?rfc compact="yes" ?>
  2026. <?rfc compact="no" ?>
  2027. <texttable anchor="silk_frame_type_table"
  2028. title="Signal Type and Quantization Offset Type from Frame Type">
  2029. <ttcol>Frame Type</ttcol>
  2030. <ttcol>Signal Type</ttcol>
  2031. <ttcol align="right">Quantization Offset Type</ttcol>
  2032. <c>0</c> <c>Inactive</c> <c>Low</c>
  2033. <c>1</c> <c>Inactive</c> <c>High</c>
  2034. <c>2</c> <c>Unvoiced</c> <c>Low</c>
  2035. <c>3</c> <c>Unvoiced</c> <c>High</c>
  2036. <c>4</c> <c>Voiced</c> <c>Low</c>
  2037. <c>5</c> <c>Voiced</c> <c>High</c>
  2038. </texttable>
  2039. <?rfc compact="yes" ?>
  2040. </section>
  2041. <section anchor="silk_gains" toc="include" title="Subframe Gains">
  2042. <t>
  2043. A separate quantization gain is coded for each 5&nbsp;ms subframe.
  2044. These gains control the step size between quantization levels of the excitation
  2045. signal and, therefore, the quality of the reconstruction.
  2046. They are independent of and unrelated to the pitch contours coded for voiced
  2047. frames.
  2048. The quantization gains are themselves uniformly quantized to 6&nbsp;bits on a
  2049. log scale, giving them a resolution of approximately 1.369&nbsp;dB and a range
  2050. of approximately 1.94&nbsp;dB to 88.21&nbsp;dB.
  2051. </t>
  2052. <t>
  2053. The subframe gains are either coded independently, or relative to the gain from
  2054. the most recent coded subframe in the same channel.
  2055. Independent coding is used if and only if
  2056. <list style="symbols">
  2057. <t>
  2058. This is the first subframe in the current SILK frame, and
  2059. </t>
  2060. <t>Either
  2061. <list style="symbols">
  2062. <t>
  2063. This is the first SILK frame of its type (LBRR or regular) for this channel in
  2064. the current Opus frame, or
  2065. </t>
  2066. <t>
  2067. The previous SILK frame of the same type (LBRR or regular) for this channel in
  2068. the same Opus frame was not coded.
  2069. </t>
  2070. </list>
  2071. </t>
  2072. </list>
  2073. </t>
  2074. <t>
  2075. In an independently coded subframe gain, the 3 most significant bits of the
  2076. quantization gain are decoded using a PDF selected from
  2077. <xref target="silk_independent_gain_msb_pdfs"/> based on the decoded signal
  2078. type (see <xref target="silk_frame_type"/>).
  2079. </t>
  2080. <?rfc compact="no" ?>
  2081. <texttable anchor="silk_independent_gain_msb_pdfs"
  2082. title="PDFs for Independent Quantization Gain MSB Coding">
  2083. <ttcol align="left">Signal Type</ttcol>
  2084. <ttcol align="left">PDF</ttcol>
  2085. <c>Inactive</c> <c>{32, 112, 68, 29, 12, 1, 1, 1}/256</c>
  2086. <c>Unvoiced</c> <c>{2, 17, 45, 60, 62, 47, 19, 4}/256</c>
  2087. <c>Voiced</c> <c>{1, 3, 26, 71, 94, 50, 9, 2}/256</c>
  2088. </texttable>
  2089. <?rfc compact="yes" ?>
  2090. <t>
  2091. The 3 least significant bits are decoded using a uniform PDF:
  2092. </t>
  2093. <?rfc compact="no" ?>
  2094. <texttable anchor="silk_independent_gain_lsb_pdf"
  2095. title="PDF for Independent Quantization Gain LSB Coding">
  2096. <ttcol align="left">PDF</ttcol>
  2097. <c>{32, 32, 32, 32, 32, 32, 32, 32}/256</c>
  2098. </texttable>
  2099. <?rfc compact="yes" ?>
  2100. <t>
  2101. These 6 bits are combined to form a value, gain_index, between 0 and 63.
  2102. When the gain for the previous subframe is available, then the current gain is
  2103. limited as follows:
  2104. <figure align="center">
  2105. <artwork align="center"><![CDATA[
  2106. log_gain = max(gain_index, previous_log_gain - 16)
  2107. ]]></artwork>
  2108. </figure>
  2109. This may help some implementations limit the change in precision of their
  2110. internal LTP history.
  2111. The indices to which this clamp applies cannot simply be removed from the
  2112. codebook, because previous_log_gain will not be available after packet loss.
  2113. The clamping is skipped after a decoder reset, and in the side channel if the
  2114. previous frame in the side channel was not coded, since there is no value for
  2115. previous_log_gain available.
  2116. It MAY also be skipped after packet loss.
  2117. </t>
  2118. <t>
  2119. For subframes that do not have an independent gain (including the first
  2120. subframe of frames not listed as using independent coding above), the
  2121. quantization gain is coded relative to the gain from the previous subframe (in
  2122. the same channel).
  2123. The PDF in <xref target="silk_delta_gain_pdf"/> yields a delta_gain_index value
  2124. between 0 and 40, inclusive.
  2125. </t>
  2126. <?rfc compact="no" ?>
  2127. <texttable anchor="silk_delta_gain_pdf"
  2128. title="PDF for Delta Quantization Gain Coding">
  2129. <ttcol align="left">PDF</ttcol>
  2130. <c>{6, 5, 11, 31, 132, 21, 8, 4,
  2131. 3, 2, 2, 2, 1, 1, 1, 1,
  2132. 1, 1, 1, 1, 1, 1, 1, 1,
  2133. 1, 1, 1, 1, 1, 1, 1, 1,
  2134. 1, 1, 1, 1, 1, 1, 1, 1, 1}/256</c>
  2135. </texttable>
  2136. <?rfc compact="yes" ?>
  2137. <t>
  2138. The following formula translates this index into a quantization gain for the
  2139. current subframe using the gain from the previous subframe:
  2140. <figure align="center">
  2141. <artwork align="center"><![CDATA[
  2142. log_gain = clamp(0, max(2*delta_gain_index - 16,
  2143. previous_log_gain + delta_gain_index - 4), 63)
  2144. ]]></artwork>
  2145. </figure>
  2146. </t>
  2147. <t>
  2148. silk_gains_dequant() (gain_quant.c) dequantizes log_gain for the k'th subframe
  2149. and converts it into a linear Q16 scale factor via
  2150. <figure align="center">
  2151. <artwork align="center"><![CDATA[
  2152. gain_Q16[k] = silk_log2lin((0x1D1C71*log_gain>>16) + 2090)
  2153. ]]></artwork>
  2154. </figure>
  2155. </t>
  2156. <t>
  2157. The function silk_log2lin() (log2lin.c) computes an approximation of
  2158. 2**(inLog_Q7/128.0), where inLog_Q7 is its Q7 input.
  2159. Let i = inLog_Q7&gt;&gt;7 be the integer part of inLogQ7 and
  2160. f = inLog_Q7&amp;127 be the fractional part.
  2161. Then,
  2162. <figure align="center">
  2163. <artwork align="center"><![CDATA[
  2164. (1<<i) + ((-174*f*(128-f)>>16)+f)*((1<<i)>>7)
  2165. ]]></artwork>
  2166. </figure>
  2167. yields the approximate exponential.
  2168. The final Q16 gain values lies between 81920 and 1686110208, inclusive
  2169. (representing scale factors of 1.25 to 25728, respectively).
  2170. </t>
  2171. </section>
  2172. <section anchor="silk_nlsfs" toc="include" title="Normalized Line Spectral
  2173. Frequency (LSF) and Linear Predictive Coding (LPC) Coefficients">
  2174. <t>
  2175. A set of normalized Line Spectral Frequency (LSF) coefficients follow the
  2176. quantization gains in the bitstream and represent the Linear Predictive
  2177. Coding (LPC) coefficients for the current SILK frame.
  2178. Once decoded, the normalized LSFs form an increasing list of Q15 values between
  2179. 0 and 1.
  2180. These represent the interleaved zeros on the upper half of the unit circle
  2181. (between 0 and pi, hence "normalized") in the standard decomposition
  2182. <xref target="SPECTRAL-PAIRS"/> of the LPC filter into a symmetric part
  2183. and an anti-symmetric part (P and Q in <xref target="silk_nlsf2lpc"/>).
  2184. Because of non-linear effects in the decoding process, an implementation SHOULD
  2185. match the fixed-point arithmetic described in this section exactly.
  2186. An encoder SHOULD also use the same process.
  2187. </t>
  2188. <t>
  2189. The normalized LSFs are coded using a two-stage vector quantizer (VQ)
  2190. (Sections&nbsp;<xref target="silk_nlsf_stage1" format="counter"/>
  2191. and&nbsp;<xref target="silk_nlsf_stage2" format="counter"/>).
  2192. NB and MB frames use an order-10 predictor, while WB frames use an order-16
  2193. predictor.
  2194. Thus, each of these two cases uses a different set of tables.
  2195. After reconstructing the normalized LSFs
  2196. (<xref target="silk_nlsf_reconstruction"/>), the decoder runs them through a
  2197. stabilization process (<xref target="silk_nlsf_stabilization"/>), interpolates
  2198. them between frames (<xref target="silk_nlsf_interpolation"/>), converts them
  2199. back into LPC coefficients (<xref target="silk_nlsf2lpc"/>), and then runs
  2200. them through further processes to limit the range of the coefficients
  2201. (<xref target="silk_lpc_range_limit"/>) and the gain of the filter
  2202. (<xref target="silk_lpc_gain_limit"/>).
  2203. All of this is necessary to ensure the reconstruction process is stable.
  2204. </t>
  2205. <section anchor="silk_nlsf_stage1" title="Normalized LSF Stage 1 Decoding">
  2206. <t>
  2207. The first VQ stage uses a 32-element codebook, coded with one of the PDFs in
  2208. <xref target="silk_nlsf_stage1_pdfs"/>, depending on the audio bandwidth and
  2209. the signal type of the current SILK frame.
  2210. This yields a single index, I1, for the entire frame, which
  2211. <list style="numbers">
  2212. <t>Indexes an element in a coarse codebook,</t>
  2213. <t>Selects the PDFs for the second stage of the VQ, and</t>
  2214. <t>Selects the prediction weights used to remove intra-frame redundancy from
  2215. the second stage.</t>
  2216. </list>
  2217. The actual codebook elements are listed in
  2218. Tables&nbsp;<xref target="silk_nlsf_nbmb_codebook" format="counter"/>
  2219. and&nbsp;<xref target="silk_nlsf_wb_codebook" format="counter"/>, but they are
  2220. not needed until the last stages of reconstructing the LSF coefficients.
  2221. </t>
  2222. <?rfc compact="no" ?>
  2223. <texttable anchor="silk_nlsf_stage1_pdfs"
  2224. title="PDFs for Normalized LSF Stage-1 Index Decoding">
  2225. <ttcol align="left">Audio Bandwidth</ttcol>
  2226. <ttcol align="left">Signal Type</ttcol>
  2227. <ttcol align="left">PDF</ttcol>
  2228. <c>NB or MB</c> <c>Inactive or unvoiced</c>
  2229. <c>
  2230. {44, 34, 30, 19, 21, 12, 11, 3,
  2231. 3, 2, 16, 2, 2, 1, 5, 2,
  2232. 1, 3, 3, 1, 1, 2, 2, 2,
  2233. 3, 1, 9, 9, 2, 7, 2, 1}/256
  2234. </c>
  2235. <c>NB or MB</c> <c>Voiced</c>
  2236. <c>
  2237. {1, 10, 1, 8, 3, 8, 8, 14,
  2238. 13, 14, 1, 14, 12, 13, 11, 11,
  2239. 12, 11, 10, 10, 11, 8, 9, 8,
  2240. 7, 8, 1, 1, 6, 1, 6, 5}/256
  2241. </c>
  2242. <c>WB</c> <c>Inactive or unvoiced</c>
  2243. <c>
  2244. {31, 21, 3, 17, 1, 8, 17, 4,
  2245. 1, 18, 16, 4, 2, 3, 1, 10,
  2246. 1, 3, 16, 11, 16, 2, 2, 3,
  2247. 2, 11, 1, 4, 9, 8, 7, 3}/256
  2248. </c>
  2249. <c>WB</c> <c>Voiced</c>
  2250. <c>
  2251. {1, 4, 16, 5, 18, 11, 5, 14,
  2252. 15, 1, 3, 12, 13, 14, 14, 6,
  2253. 14, 12, 2, 6, 1, 12, 12, 11,
  2254. 10, 3, 10, 5, 1, 1, 1, 3}/256
  2255. </c>
  2256. </texttable>
  2257. <?rfc compact="yes" ?>
  2258. </section>
  2259. <section anchor="silk_nlsf_stage2" title="Normalized LSF Stage 2 Decoding">
  2260. <t>
  2261. A total of 16 PDFs are available for the LSF residual in the second stage: the
  2262. 8 (a...h) for NB and MB frames given in
  2263. <xref target="silk_nlsf_stage2_nbmb_pdfs"/>, and the 8 (i...p) for WB frames
  2264. given in <xref target="silk_nlsf_stage2_wb_pdfs"/>.
  2265. Which PDF is used for which coefficient is driven by the index, I1,
  2266. decoded in the first stage.
  2267. <xref target="silk_nlsf_nbmb_stage2_cb_sel"/> lists the letter of the
  2268. corresponding PDF for each normalized LSF coefficient for NB and MB, and
  2269. <xref target="silk_nlsf_wb_stage2_cb_sel"/> lists the same information for WB.
  2270. </t>
  2271. <?rfc compact="no" ?>
  2272. <texttable anchor="silk_nlsf_stage2_nbmb_pdfs"
  2273. title="PDFs for NB/MB Normalized LSF Stage-2 Index Decoding">
  2274. <ttcol align="left">Codebook</ttcol>
  2275. <ttcol align="left">PDF</ttcol>
  2276. <c>a</c> <c>{1, 1, 1, 15, 224, 11, 1, 1, 1}/256</c>
  2277. <c>b</c> <c>{1, 1, 2, 34, 183, 32, 1, 1, 1}/256</c>
  2278. <c>c</c> <c>{1, 1, 4, 42, 149, 55, 2, 1, 1}/256</c>
  2279. <c>d</c> <c>{1, 1, 8, 52, 123, 61, 8, 1, 1}/256</c>
  2280. <c>e</c> <c>{1, 3, 16, 53, 101, 74, 6, 1, 1}/256</c>
  2281. <c>f</c> <c>{1, 3, 17, 55, 90, 73, 15, 1, 1}/256</c>
  2282. <c>g</c> <c>{1, 7, 24, 53, 74, 67, 26, 3, 1}/256</c>
  2283. <c>h</c> <c>{1, 1, 18, 63, 78, 58, 30, 6, 1}/256</c>
  2284. </texttable>
  2285. <?rfc compact="yes" ?>
  2286. <?rfc compact="no" ?>
  2287. <texttable anchor="silk_nlsf_stage2_wb_pdfs"
  2288. title="PDFs for WB Normalized LSF Stage-2 Index Decoding">
  2289. <ttcol align="left">Codebook</ttcol>
  2290. <ttcol align="left">PDF</ttcol>
  2291. <c>i</c> <c>{1, 1, 1, 9, 232, 9, 1, 1, 1}/256</c>
  2292. <c>j</c> <c>{1, 1, 2, 28, 186, 35, 1, 1, 1}/256</c>
  2293. <c>k</c> <c>{1, 1, 3, 42, 152, 53, 2, 1, 1}/256</c>
  2294. <c>l</c> <c>{1, 1, 10, 49, 126, 65, 2, 1, 1}/256</c>
  2295. <c>m</c> <c>{1, 4, 19, 48, 100, 77, 5, 1, 1}/256</c>
  2296. <c>n</c> <c>{1, 1, 14, 54, 100, 72, 12, 1, 1}/256</c>
  2297. <c>o</c> <c>{1, 1, 15, 61, 87, 61, 25, 4, 1}/256</c>
  2298. <c>p</c> <c>{1, 7, 21, 50, 77, 81, 17, 1, 1}/256</c>
  2299. </texttable>
  2300. <?rfc compact="yes" ?>
  2301. <?rfc compact="no" ?>
  2302. <texttable anchor="silk_nlsf_nbmb_stage2_cb_sel"
  2303. title="Codebook Selection for NB/MB Normalized LSF Stage-2 Index Decoding">
  2304. <ttcol>I1</ttcol>
  2305. <ttcol>Coefficient</ttcol>
  2306. <c/>
  2307. <c><spanx style="vbare">0&nbsp;1&nbsp;2&nbsp;3&nbsp;4&nbsp;5&nbsp;6&nbsp;7&nbsp;8&nbsp;9</spanx></c>
  2308. <c> 0</c>
  2309. <c><spanx style="vbare">a&nbsp;a&nbsp;a&nbsp;a&nbsp;a&nbsp;a&nbsp;a&nbsp;a&nbsp;a&nbsp;a</spanx></c>
  2310. <c> 1</c>
  2311. <c><spanx style="vbare">b&nbsp;d&nbsp;b&nbsp;c&nbsp;c&nbsp;b&nbsp;c&nbsp;b&nbsp;b&nbsp;b</spanx></c>
  2312. <c> 2</c>
  2313. <c><spanx style="vbare">c&nbsp;b&nbsp;b&nbsp;b&nbsp;b&nbsp;b&nbsp;b&nbsp;b&nbsp;b&nbsp;b</spanx></c>
  2314. <c> 3</c>
  2315. <c><spanx style="vbare">b&nbsp;c&nbsp;c&nbsp;c&nbsp;c&nbsp;b&nbsp;c&nbsp;b&nbsp;b&nbsp;b</spanx></c>
  2316. <c> 4</c>
  2317. <c><spanx style="vbare">c&nbsp;d&nbsp;d&nbsp;d&nbsp;d&nbsp;c&nbsp;c&nbsp;c&nbsp;c&nbsp;c</spanx></c>
  2318. <c> 5</c>
  2319. <c><spanx style="vbare">a&nbsp;f&nbsp;d&nbsp;d&nbsp;c&nbsp;c&nbsp;c&nbsp;c&nbsp;b&nbsp;b</spanx></c>
  2320. <c> g</c>
  2321. <c><spanx style="vbare">a&nbsp;c&nbsp;c&nbsp;c&nbsp;c&nbsp;c&nbsp;c&nbsp;c&nbsp;c&nbsp;b</spanx></c>
  2322. <c> 7</c>
  2323. <c><spanx style="vbare">c&nbsp;d&nbsp;g&nbsp;e&nbsp;e&nbsp;e&nbsp;f&nbsp;e&nbsp;f&nbsp;f</spanx></c>
  2324. <c> 8</c>
  2325. <c><spanx style="vbare">c&nbsp;e&nbsp;f&nbsp;f&nbsp;e&nbsp;f&nbsp;e&nbsp;g&nbsp;e&nbsp;e</spanx></c>
  2326. <c> 9</c>
  2327. <c><spanx style="vbare">c&nbsp;e&nbsp;e&nbsp;h&nbsp;e&nbsp;f&nbsp;e&nbsp;f&nbsp;f&nbsp;e</spanx></c>
  2328. <c>10</c>
  2329. <c><spanx style="vbare">e&nbsp;d&nbsp;d&nbsp;d&nbsp;c&nbsp;d&nbsp;c&nbsp;c&nbsp;c&nbsp;c</spanx></c>
  2330. <c>11</c>
  2331. <c><spanx style="vbare">b&nbsp;f&nbsp;f&nbsp;g&nbsp;e&nbsp;f&nbsp;e&nbsp;f&nbsp;f&nbsp;f</spanx></c>
  2332. <c>12</c>
  2333. <c><spanx style="vbare">c&nbsp;h&nbsp;e&nbsp;g&nbsp;f&nbsp;f&nbsp;f&nbsp;f&nbsp;f&nbsp;f</spanx></c>
  2334. <c>13</c>
  2335. <c><spanx style="vbare">c&nbsp;h&nbsp;f&nbsp;f&nbsp;f&nbsp;f&nbsp;f&nbsp;g&nbsp;f&nbsp;e</spanx></c>
  2336. <c>14</c>
  2337. <c><spanx style="vbare">d&nbsp;d&nbsp;f&nbsp;e&nbsp;e&nbsp;f&nbsp;e&nbsp;f&nbsp;e&nbsp;e</spanx></c>
  2338. <c>15</c>
  2339. <c><spanx style="vbare">c&nbsp;d&nbsp;d&nbsp;f&nbsp;f&nbsp;e&nbsp;e&nbsp;e&nbsp;e&nbsp;e</spanx></c>
  2340. <c>16</c>
  2341. <c><spanx style="vbare">c&nbsp;e&nbsp;e&nbsp;g&nbsp;e&nbsp;f&nbsp;e&nbsp;f&nbsp;f&nbsp;f</spanx></c>
  2342. <c>17</c>
  2343. <c><spanx style="vbare">c&nbsp;f&nbsp;e&nbsp;g&nbsp;f&nbsp;f&nbsp;f&nbsp;e&nbsp;f&nbsp;e</spanx></c>
  2344. <c>18</c>
  2345. <c><spanx style="vbare">c&nbsp;h&nbsp;e&nbsp;f&nbsp;e&nbsp;f&nbsp;e&nbsp;f&nbsp;f&nbsp;f</spanx></c>
  2346. <c>19</c>
  2347. <c><spanx style="vbare">c&nbsp;f&nbsp;e&nbsp;g&nbsp;h&nbsp;g&nbsp;f&nbsp;g&nbsp;f&nbsp;e</spanx></c>
  2348. <c>20</c>
  2349. <c><spanx style="vbare">d&nbsp;g&nbsp;h&nbsp;e&nbsp;g&nbsp;f&nbsp;f&nbsp;g&nbsp;e&nbsp;f</spanx></c>
  2350. <c>21</c>
  2351. <c><spanx style="vbare">c&nbsp;h&nbsp;g&nbsp;e&nbsp;e&nbsp;e&nbsp;f&nbsp;e&nbsp;f&nbsp;f</spanx></c>
  2352. <c>22</c>
  2353. <c><spanx style="vbare">e&nbsp;f&nbsp;f&nbsp;e&nbsp;g&nbsp;g&nbsp;f&nbsp;g&nbsp;f&nbsp;e</spanx></c>
  2354. <c>23</c>
  2355. <c><spanx style="vbare">c&nbsp;f&nbsp;f&nbsp;g&nbsp;f&nbsp;g&nbsp;e&nbsp;g&nbsp;e&nbsp;e</spanx></c>
  2356. <c>24</c>
  2357. <c><spanx style="vbare">e&nbsp;f&nbsp;f&nbsp;f&nbsp;d&nbsp;h&nbsp;e&nbsp;f&nbsp;f&nbsp;e</spanx></c>
  2358. <c>25</c>
  2359. <c><spanx style="vbare">c&nbsp;d&nbsp;e&nbsp;f&nbsp;f&nbsp;g&nbsp;e&nbsp;f&nbsp;f&nbsp;e</spanx></c>
  2360. <c>26</c>
  2361. <c><spanx style="vbare">c&nbsp;d&nbsp;c&nbsp;d&nbsp;d&nbsp;e&nbsp;c&nbsp;d&nbsp;d&nbsp;d</spanx></c>
  2362. <c>27</c>
  2363. <c><spanx style="vbare">b&nbsp;b&nbsp;c&nbsp;c&nbsp;c&nbsp;c&nbsp;c&nbsp;d&nbsp;c&nbsp;c</spanx></c>
  2364. <c>28</c>
  2365. <c><spanx style="vbare">e&nbsp;f&nbsp;f&nbsp;g&nbsp;g&nbsp;g&nbsp;f&nbsp;g&nbsp;e&nbsp;f</spanx></c>
  2366. <c>29</c>
  2367. <c><spanx style="vbare">d&nbsp;f&nbsp;f&nbsp;e&nbsp;e&nbsp;e&nbsp;e&nbsp;d&nbsp;d&nbsp;c</spanx></c>
  2368. <c>30</c>
  2369. <c><spanx style="vbare">c&nbsp;f&nbsp;d&nbsp;h&nbsp;f&nbsp;f&nbsp;e&nbsp;e&nbsp;f&nbsp;e</spanx></c>
  2370. <c>31</c>
  2371. <c><spanx style="vbare">e&nbsp;e&nbsp;f&nbsp;e&nbsp;f&nbsp;g&nbsp;f&nbsp;g&nbsp;f&nbsp;e</spanx></c>
  2372. </texttable>
  2373. <?rfc compact="yes" ?>
  2374. <?rfc compact="no" ?>
  2375. <texttable anchor="silk_nlsf_wb_stage2_cb_sel"
  2376. title="Codebook Selection for WB Normalized LSF Stage-2 Index Decoding">
  2377. <ttcol>I1</ttcol>
  2378. <ttcol>Coefficient</ttcol>
  2379. <c/>
  2380. <c><spanx style="vbare">0&nbsp;&nbsp;1&nbsp;&nbsp;2&nbsp;&nbsp;3&nbsp;&nbsp;4&nbsp;&nbsp;5&nbsp;&nbsp;6&nbsp;&nbsp;7&nbsp;&nbsp;8&nbsp;&nbsp;9&nbsp;10&nbsp;11&nbsp;12&nbsp;13&nbsp;14&nbsp;15</spanx></c>
  2381. <c> 0</c>
  2382. <c><spanx style="vbare">i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i</spanx></c>
  2383. <c> 1</c>
  2384. <c><spanx style="vbare">k&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;k&nbsp;&nbsp;k&nbsp;&nbsp;k&nbsp;&nbsp;k&nbsp;&nbsp;k&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;i&nbsp;&nbsp;l</spanx></c>
  2385. <c> 2</c>
  2386. <c><spanx style="vbare">k&nbsp;&nbsp;n&nbsp;&nbsp;n&nbsp;&nbsp;l&nbsp;&nbsp;p&nbsp;&nbsp;m&nbsp;&nbsp;m&nbsp;&nbsp;n&nbsp;&nbsp;k&nbsp;&nbsp;n&nbsp;&nbsp;m&nbsp;&nbsp;n&nbsp;&nbsp;n&nbsp;&nbsp;m&nbsp;&nbsp;l&nbsp;&nbsp;l</spanx></c>
  2387. <c> 3</c>
  2388. <c><spanx style="vbare">i&nbsp;&nbsp;k&nbsp;&nbsp;j&nbsp;&nbsp;k&nbsp;&nbsp;k&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;j</spanx></c>
  2389. <c> 4</c>
  2390. <c><spanx style="vbare">i&nbsp;&nbsp;o&nbsp;&nbsp;n&nbsp;&nbsp;m&nbsp;&nbsp;o&nbsp;&nbsp;m&nbsp;&nbsp;p&nbsp;&nbsp;n&nbsp;&nbsp;m&nbsp;&nbsp;m&nbsp;&nbsp;m&nbsp;&nbsp;n&nbsp;&nbsp;n&nbsp;&nbsp;m&nbsp;&nbsp;m&nbsp;&nbsp;l</spanx></c>
  2391. <c> 5</c>
  2392. <c><spanx style="vbare">i&nbsp;&nbsp;l&nbsp;&nbsp;n&nbsp;&nbsp;n&nbsp;&nbsp;m&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;n&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;k&nbsp;&nbsp;m</spanx></c>
  2393. <c> 6</c>
  2394. <c><spanx style="vbare">i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i</spanx></c>
  2395. <c> 7</c>
  2396. <c><spanx style="vbare">i&nbsp;&nbsp;k&nbsp;&nbsp;o&nbsp;&nbsp;l&nbsp;&nbsp;p&nbsp;&nbsp;k&nbsp;&nbsp;n&nbsp;&nbsp;l&nbsp;&nbsp;m&nbsp;&nbsp;n&nbsp;&nbsp;n&nbsp;&nbsp;m&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;k&nbsp;&nbsp;l</spanx></c>
  2397. <c> 8</c>
  2398. <c><spanx style="vbare">i&nbsp;&nbsp;o&nbsp;&nbsp;k&nbsp;&nbsp;o&nbsp;&nbsp;o&nbsp;&nbsp;m&nbsp;&nbsp;n&nbsp;&nbsp;m&nbsp;&nbsp;o&nbsp;&nbsp;n&nbsp;&nbsp;m&nbsp;&nbsp;m&nbsp;&nbsp;n&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l</spanx></c>
  2399. <c> 9</c>
  2400. <c><spanx style="vbare">k&nbsp;&nbsp;j&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i</spanx></c>
  2401. <c>10</c>
  2402. <c><spanx style="vbare">i&nbsp;&nbsp;j&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;j</spanx></c>
  2403. <c>11</c>
  2404. <c><spanx style="vbare">k&nbsp;&nbsp;k&nbsp;&nbsp;l&nbsp;&nbsp;m&nbsp;&nbsp;n&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;k&nbsp;&nbsp;k&nbsp;&nbsp;j&nbsp;&nbsp;l</spanx></c>
  2405. <c>12</c>
  2406. <c><spanx style="vbare">k&nbsp;&nbsp;k&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;m&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;k&nbsp;&nbsp;j&nbsp;&nbsp;l</spanx></c>
  2407. <c>13</c>
  2408. <c><spanx style="vbare">l&nbsp;&nbsp;m&nbsp;&nbsp;m&nbsp;&nbsp;m&nbsp;&nbsp;o&nbsp;&nbsp;m&nbsp;&nbsp;m&nbsp;&nbsp;n&nbsp;&nbsp;l&nbsp;&nbsp;n&nbsp;&nbsp;m&nbsp;&nbsp;m&nbsp;&nbsp;n&nbsp;&nbsp;m&nbsp;&nbsp;l&nbsp;&nbsp;m</spanx></c>
  2409. <c>14</c>
  2410. <c><spanx style="vbare">i&nbsp;&nbsp;o&nbsp;&nbsp;m&nbsp;&nbsp;n&nbsp;&nbsp;m&nbsp;&nbsp;p&nbsp;&nbsp;n&nbsp;&nbsp;k&nbsp;&nbsp;o&nbsp;&nbsp;n&nbsp;&nbsp;p&nbsp;&nbsp;m&nbsp;&nbsp;m&nbsp;&nbsp;l&nbsp;&nbsp;n&nbsp;&nbsp;l</spanx></c>
  2411. <c>15</c>
  2412. <c><spanx style="vbare">i&nbsp;&nbsp;j&nbsp;&nbsp;i&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;j&nbsp;&nbsp;i</spanx></c>
  2413. <c>16</c>
  2414. <c><spanx style="vbare">j&nbsp;&nbsp;o&nbsp;&nbsp;n&nbsp;&nbsp;p&nbsp;&nbsp;n&nbsp;&nbsp;m&nbsp;&nbsp;n&nbsp;&nbsp;l&nbsp;&nbsp;m&nbsp;&nbsp;n&nbsp;&nbsp;m&nbsp;&nbsp;m&nbsp;&nbsp;m&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;m</spanx></c>
  2415. <c>17</c>
  2416. <c><spanx style="vbare">j&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;m&nbsp;&nbsp;m&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;n&nbsp;&nbsp;k&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;n&nbsp;&nbsp;n&nbsp;&nbsp;n&nbsp;&nbsp;l&nbsp;&nbsp;m</spanx></c>
  2417. <c>18</c>
  2418. <c><spanx style="vbare">k&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;k&nbsp;&nbsp;k&nbsp;&nbsp;k&nbsp;&nbsp;l&nbsp;&nbsp;k&nbsp;&nbsp;j&nbsp;&nbsp;k&nbsp;&nbsp;j&nbsp;&nbsp;k&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;m</spanx></c>
  2419. <c>19</c>
  2420. <c><spanx style="vbare">i&nbsp;&nbsp;k&nbsp;&nbsp;l&nbsp;&nbsp;n&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;k&nbsp;&nbsp;k&nbsp;&nbsp;k&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i</spanx></c>
  2421. <c>20</c>
  2422. <c><spanx style="vbare">l&nbsp;&nbsp;m&nbsp;&nbsp;l&nbsp;&nbsp;n&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;k&nbsp;&nbsp;k&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;k&nbsp;&nbsp;k&nbsp;&nbsp;m</spanx></c>
  2423. <c>21</c>
  2424. <c><spanx style="vbare">k&nbsp;&nbsp;o&nbsp;&nbsp;l&nbsp;&nbsp;p&nbsp;&nbsp;p&nbsp;&nbsp;m&nbsp;&nbsp;n&nbsp;&nbsp;m&nbsp;&nbsp;n&nbsp;&nbsp;l&nbsp;&nbsp;n&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;k&nbsp;&nbsp;l&nbsp;&nbsp;l</spanx></c>
  2425. <c>22</c>
  2426. <c><spanx style="vbare">k&nbsp;&nbsp;l&nbsp;&nbsp;n&nbsp;&nbsp;o&nbsp;&nbsp;o&nbsp;&nbsp;l&nbsp;&nbsp;n&nbsp;&nbsp;l&nbsp;&nbsp;m&nbsp;&nbsp;m&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;k&nbsp;&nbsp;m</spanx></c>
  2427. <c>23</c>
  2428. <c><spanx style="vbare">j&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;m&nbsp;&nbsp;m&nbsp;&nbsp;m&nbsp;&nbsp;m&nbsp;&nbsp;l&nbsp;&nbsp;n&nbsp;&nbsp;n&nbsp;&nbsp;n&nbsp;&nbsp;l&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;j</spanx></c>
  2429. <c>24</c>
  2430. <c><spanx style="vbare">k&nbsp;&nbsp;n&nbsp;&nbsp;l&nbsp;&nbsp;o&nbsp;&nbsp;o&nbsp;&nbsp;m&nbsp;&nbsp;p&nbsp;&nbsp;m&nbsp;&nbsp;m&nbsp;&nbsp;n&nbsp;&nbsp;l&nbsp;&nbsp;m&nbsp;&nbsp;m&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l</spanx></c>
  2431. <c>25</c>
  2432. <c><spanx style="vbare">i&nbsp;&nbsp;o&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i</spanx></c>
  2433. <c>26</c>
  2434. <c><spanx style="vbare">i&nbsp;&nbsp;o&nbsp;&nbsp;o&nbsp;&nbsp;l&nbsp;&nbsp;n&nbsp;&nbsp;k&nbsp;&nbsp;n&nbsp;&nbsp;n&nbsp;&nbsp;l&nbsp;&nbsp;m&nbsp;&nbsp;m&nbsp;&nbsp;p&nbsp;&nbsp;p&nbsp;&nbsp;m&nbsp;&nbsp;m&nbsp;&nbsp;m</spanx></c>
  2435. <c>27</c>
  2436. <c><spanx style="vbare">l&nbsp;&nbsp;l&nbsp;&nbsp;p&nbsp;&nbsp;l&nbsp;&nbsp;n&nbsp;&nbsp;m&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;k&nbsp;&nbsp;k&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;k&nbsp;&nbsp;l</spanx></c>
  2437. <c>28</c>
  2438. <c><spanx style="vbare">i&nbsp;&nbsp;i&nbsp;&nbsp;j&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;k&nbsp;&nbsp;j&nbsp;&nbsp;k&nbsp;&nbsp;j&nbsp;&nbsp;j&nbsp;&nbsp;k&nbsp;&nbsp;k&nbsp;&nbsp;k&nbsp;&nbsp;j&nbsp;&nbsp;j</spanx></c>
  2439. <c>29</c>
  2440. <c><spanx style="vbare">i&nbsp;&nbsp;l&nbsp;&nbsp;k&nbsp;&nbsp;n&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;k&nbsp;&nbsp;l&nbsp;&nbsp;k&nbsp;&nbsp;j&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;j&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;j</spanx></c>
  2441. <c>30</c>
  2442. <c><spanx style="vbare">l&nbsp;&nbsp;n&nbsp;&nbsp;n&nbsp;&nbsp;m&nbsp;&nbsp;p&nbsp;&nbsp;n&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;k&nbsp;&nbsp;l&nbsp;&nbsp;k&nbsp;&nbsp;k&nbsp;&nbsp;j&nbsp;&nbsp;i&nbsp;&nbsp;j&nbsp;&nbsp;i</spanx></c>
  2443. <c>31</c>
  2444. <c><spanx style="vbare">k&nbsp;&nbsp;l&nbsp;&nbsp;n&nbsp;&nbsp;l&nbsp;&nbsp;m&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;l&nbsp;&nbsp;k&nbsp;&nbsp;j&nbsp;&nbsp;k&nbsp;&nbsp;o&nbsp;&nbsp;m&nbsp;&nbsp;i&nbsp;&nbsp;i&nbsp;&nbsp;i</spanx></c>
  2445. </texttable>
  2446. <?rfc compact="yes" ?>
  2447. <t>
  2448. Decoding the second stage residual proceeds as follows.
  2449. For each coefficient, the decoder reads a symbol using the PDF corresponding to
  2450. I1 from either <xref target="silk_nlsf_nbmb_stage2_cb_sel"/> or
  2451. <xref target="silk_nlsf_wb_stage2_cb_sel"/>, and subtracts 4 from the result
  2452. to give an index in the range -4 to 4, inclusive.
  2453. If the index is either -4 or 4, it reads a second symbol using the PDF in
  2454. <xref target="silk_nlsf_ext_pdf"/>, and adds the value of this second symbol
  2455. to the index, using the same sign.
  2456. This gives the index, I2[k], a total range of -10 to 10, inclusive.
  2457. </t>
  2458. <?rfc compact="no" ?>
  2459. <texttable anchor="silk_nlsf_ext_pdf"
  2460. title="PDF for Normalized LSF Index Extension Decoding">
  2461. <ttcol align="left">PDF</ttcol>
  2462. <c>{156, 60, 24, 9, 4, 2, 1}/256</c>
  2463. </texttable>
  2464. <?rfc compact="yes" ?>
  2465. <t>
  2466. The decoded indices from both stages are translated back into normalized LSF
  2467. coefficients in silk_NLSF_decode() (NLSF_decode.c).
  2468. The stage-2 indices represent residuals after both the first stage of the VQ
  2469. and a separate backwards-prediction step.
  2470. The backwards prediction process in the encoder subtracts a prediction from
  2471. each residual formed by a multiple of the coefficient that follows it.
  2472. The decoder must undo this process.
  2473. <xref target="silk_nlsf_pred_weights"/> contains lists of prediction weights
  2474. for each coefficient.
  2475. There are two lists for NB and MB, and another two lists for WB, giving two
  2476. possible prediction weights for each coefficient.
  2477. </t>
  2478. <?rfc compact="no" ?>
  2479. <texttable anchor="silk_nlsf_pred_weights"
  2480. title="Prediction Weights for Normalized LSF Decoding">
  2481. <ttcol align="left">Coefficient</ttcol>
  2482. <ttcol align="right">A</ttcol>
  2483. <ttcol align="right">B</ttcol>
  2484. <ttcol align="right">C</ttcol>
  2485. <ttcol align="right">D</ttcol>
  2486. <c>0</c> <c>179</c> <c>116</c> <c>175</c> <c>68</c>
  2487. <c>1</c> <c>138</c> <c>67</c> <c>148</c> <c>62</c>
  2488. <c>2</c> <c>140</c> <c>82</c> <c>160</c> <c>66</c>
  2489. <c>3</c> <c>148</c> <c>59</c> <c>176</c> <c>60</c>
  2490. <c>4</c> <c>151</c> <c>92</c> <c>178</c> <c>72</c>
  2491. <c>5</c> <c>149</c> <c>72</c> <c>173</c> <c>117</c>
  2492. <c>6</c> <c>153</c> <c>100</c> <c>174</c> <c>85</c>
  2493. <c>7</c> <c>151</c> <c>89</c> <c>164</c> <c>90</c>
  2494. <c>8</c> <c>163</c> <c>92</c> <c>177</c> <c>118</c>
  2495. <c>9</c> <c/> <c/> <c>174</c> <c>136</c>
  2496. <c>10</c> <c/> <c/> <c>196</c> <c>151</c>
  2497. <c>11</c> <c/> <c/> <c>182</c> <c>142</c>
  2498. <c>12</c> <c/> <c/> <c>198</c> <c>160</c>
  2499. <c>13</c> <c/> <c/> <c>192</c> <c>142</c>
  2500. <c>14</c> <c/> <c/> <c>182</c> <c>155</c>
  2501. </texttable>
  2502. <?rfc compact="yes" ?>
  2503. <t>
  2504. The prediction is undone using the procedure implemented in
  2505. silk_NLSF_residual_dequant() (NLSF_decode.c), which is as follows.
  2506. Each coefficient selects its prediction weight from one of the two lists based
  2507. on the stage-1 index, I1.
  2508. <xref target="silk_nlsf_nbmb_weight_sel"/> gives the selections for each
  2509. coefficient for NB and MB, and <xref target="silk_nlsf_wb_weight_sel"/> gives
  2510. the selections for WB.
  2511. Let d_LPC be the order of the codebook, i.e., 10 for NB and MB, and 16 for WB,
  2512. and let pred_Q8[k] be the weight for the k'th coefficient selected by this
  2513. process for 0&nbsp;&lt;=&nbsp;k&nbsp;&lt;&nbsp;d_LPC-1.
  2514. Then, the stage-2 residual for each coefficient is computed via
  2515. <figure align="center">
  2516. <artwork align="center"><![CDATA[
  2517. res_Q10[k] = (k+1 < d_LPC ? (res_Q10[k+1]*pred_Q8[k])>>8 : 0)
  2518. + ((((I2[k]<<10) - sign(I2[k])*102)*qstep)>>16) ,
  2519. ]]></artwork>
  2520. </figure>
  2521. where qstep is the Q16 quantization step size, which is 11796 for NB and MB
  2522. and 9830 for WB (representing step sizes of approximately 0.18 and 0.15,
  2523. respectively).
  2524. </t>
  2525. <?rfc compact="no" ?>
  2526. <texttable anchor="silk_nlsf_nbmb_weight_sel"
  2527. title="Prediction Weight Selection for NB/MB Normalized LSF Decoding">
  2528. <ttcol>I1</ttcol>
  2529. <ttcol>Coefficient</ttcol>
  2530. <c/>
  2531. <c><spanx style="vbare">0&nbsp;1&nbsp;2&nbsp;3&nbsp;4&nbsp;5&nbsp;6&nbsp;7&nbsp;8</spanx></c>
  2532. <c> 0</c>
  2533. <c><spanx style="vbare">A&nbsp;B&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A</spanx></c>
  2534. <c> 1</c>
  2535. <c><spanx style="vbare">B&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A</spanx></c>
  2536. <c> 2</c>
  2537. <c><spanx style="vbare">A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A</spanx></c>
  2538. <c> 3</c>
  2539. <c><spanx style="vbare">B&nbsp;B&nbsp;B&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;B&nbsp;A</spanx></c>
  2540. <c> 4</c>
  2541. <c><spanx style="vbare">A&nbsp;B&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A</spanx></c>
  2542. <c> 5</c>
  2543. <c><spanx style="vbare">A&nbsp;B&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A</spanx></c>
  2544. <c> 6</c>
  2545. <c><spanx style="vbare">B&nbsp;A&nbsp;B&nbsp;B&nbsp;A&nbsp;A&nbsp;A&nbsp;B&nbsp;A</spanx></c>
  2546. <c> 7</c>
  2547. <c><spanx style="vbare">A&nbsp;B&nbsp;B&nbsp;A&nbsp;A&nbsp;B&nbsp;B&nbsp;A&nbsp;A</spanx></c>
  2548. <c> 8</c>
  2549. <c><spanx style="vbare">A&nbsp;A&nbsp;B&nbsp;B&nbsp;A&nbsp;B&nbsp;A&nbsp;B&nbsp;B</spanx></c>
  2550. <c> 9</c>
  2551. <c><spanx style="vbare">A&nbsp;A&nbsp;B&nbsp;B&nbsp;A&nbsp;A&nbsp;B&nbsp;B&nbsp;B</spanx></c>
  2552. <c>10</c>
  2553. <c><spanx style="vbare">A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A</spanx></c>
  2554. <c>11</c>
  2555. <c><spanx style="vbare">A&nbsp;B&nbsp;A&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;A</spanx></c>
  2556. <c>12</c>
  2557. <c><spanx style="vbare">A&nbsp;B&nbsp;A&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;A</spanx></c>
  2558. <c>13</c>
  2559. <c><spanx style="vbare">A&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;A</spanx></c>
  2560. <c>14</c>
  2561. <c><spanx style="vbare">B&nbsp;A&nbsp;B&nbsp;B&nbsp;A&nbsp;B&nbsp;B&nbsp;B&nbsp;B</spanx></c>
  2562. <c>15</c>
  2563. <c><spanx style="vbare">A&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;A&nbsp;B&nbsp;A</spanx></c>
  2564. <c>16</c>
  2565. <c><spanx style="vbare">A&nbsp;A&nbsp;B&nbsp;B&nbsp;A&nbsp;B&nbsp;A&nbsp;B&nbsp;A</spanx></c>
  2566. <c>17</c>
  2567. <c><spanx style="vbare">A&nbsp;A&nbsp;B&nbsp;B&nbsp;B&nbsp;A&nbsp;B&nbsp;B&nbsp;B</spanx></c>
  2568. <c>18</c>
  2569. <c><spanx style="vbare">A&nbsp;B&nbsp;B&nbsp;A&nbsp;A&nbsp;B&nbsp;B&nbsp;B&nbsp;A</spanx></c>
  2570. <c>19</c>
  2571. <c><spanx style="vbare">A&nbsp;A&nbsp;A&nbsp;B&nbsp;B&nbsp;B&nbsp;A&nbsp;B&nbsp;A</spanx></c>
  2572. <c>20</c>
  2573. <c><spanx style="vbare">A&nbsp;B&nbsp;B&nbsp;A&nbsp;A&nbsp;B&nbsp;A&nbsp;B&nbsp;A</spanx></c>
  2574. <c>21</c>
  2575. <c><spanx style="vbare">A&nbsp;B&nbsp;B&nbsp;A&nbsp;A&nbsp;A&nbsp;B&nbsp;B&nbsp;A</spanx></c>
  2576. <c>22</c>
  2577. <c><spanx style="vbare">A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;B&nbsp;B&nbsp;B&nbsp;B</spanx></c>
  2578. <c>23</c>
  2579. <c><spanx style="vbare">A&nbsp;A&nbsp;B&nbsp;B&nbsp;A&nbsp;A&nbsp;A&nbsp;B&nbsp;B</spanx></c>
  2580. <c>24</c>
  2581. <c><spanx style="vbare">A&nbsp;A&nbsp;A&nbsp;B&nbsp;A&nbsp;B&nbsp;B&nbsp;B&nbsp;B</spanx></c>
  2582. <c>25</c>
  2583. <c><spanx style="vbare">A&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;A</spanx></c>
  2584. <c>26</c>
  2585. <c><spanx style="vbare">A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A</spanx></c>
  2586. <c>27</c>
  2587. <c><spanx style="vbare">A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A</spanx></c>
  2588. <c>28</c>
  2589. <c><spanx style="vbare">A&nbsp;A&nbsp;B&nbsp;A&nbsp;B&nbsp;B&nbsp;A&nbsp;B&nbsp;A</spanx></c>
  2590. <c>29</c>
  2591. <c><spanx style="vbare">B&nbsp;A&nbsp;A&nbsp;B&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A</spanx></c>
  2592. <c>30</c>
  2593. <c><spanx style="vbare">A&nbsp;A&nbsp;A&nbsp;B&nbsp;B&nbsp;A&nbsp;B&nbsp;A&nbsp;B</spanx></c>
  2594. <c>31</c>
  2595. <c><spanx style="vbare">B&nbsp;A&nbsp;B&nbsp;B&nbsp;A&nbsp;B&nbsp;B&nbsp;B&nbsp;B</spanx></c>
  2596. </texttable>
  2597. <?rfc compact="yes" ?>
  2598. <?rfc compact="no" ?>
  2599. <texttable anchor="silk_nlsf_wb_weight_sel"
  2600. title="Prediction Weight Selection for WB Normalized LSF Decoding">
  2601. <ttcol>I1</ttcol>
  2602. <ttcol>Coefficient</ttcol>
  2603. <c/>
  2604. <c><spanx style="vbare">0&nbsp;&nbsp;1&nbsp;&nbsp;2&nbsp;&nbsp;3&nbsp;&nbsp;4&nbsp;&nbsp;5&nbsp;&nbsp;6&nbsp;&nbsp;7&nbsp;&nbsp;8&nbsp;&nbsp;9&nbsp;10&nbsp;11&nbsp;12&nbsp;13&nbsp;14</spanx></c>
  2605. <c> 0</c>
  2606. <c><spanx style="vbare">C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D</spanx></c>
  2607. <c> 1</c>
  2608. <c><spanx style="vbare">C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C</spanx></c>
  2609. <c> 2</c>
  2610. <c><spanx style="vbare">C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C</spanx></c>
  2611. <c> 3</c>
  2612. <c><spanx style="vbare">C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C</spanx></c>
  2613. <c> 4</c>
  2614. <c><spanx style="vbare">C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C</spanx></c>
  2615. <c> 5</c>
  2616. <c><spanx style="vbare">C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C</spanx></c>
  2617. <c> 6</c>
  2618. <c><spanx style="vbare">D&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C</spanx></c>
  2619. <c> 7</c>
  2620. <c><spanx style="vbare">C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D</spanx></c>
  2621. <c> 8</c>
  2622. <c><spanx style="vbare">C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D</spanx></c>
  2623. <c> 9</c>
  2624. <c><spanx style="vbare">C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D</spanx></c>
  2625. <c>10</c>
  2626. <c><spanx style="vbare">C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C</spanx></c>
  2627. <c>11</c>
  2628. <c><spanx style="vbare">C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C</spanx></c>
  2629. <c>12</c>
  2630. <c><spanx style="vbare">C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C</spanx></c>
  2631. <c>13</c>
  2632. <c><spanx style="vbare">C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C</spanx></c>
  2633. <c>14</c>
  2634. <c><spanx style="vbare">C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D</spanx></c>
  2635. <c>15</c>
  2636. <c><spanx style="vbare">C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C</spanx></c>
  2637. <c>16</c>
  2638. <c><spanx style="vbare">C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C</spanx></c>
  2639. <c>17</c>
  2640. <c><spanx style="vbare">C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C</spanx></c>
  2641. <c>18</c>
  2642. <c><spanx style="vbare">C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D</spanx></c>
  2643. <c>19</c>
  2644. <c><spanx style="vbare">C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C</spanx></c>
  2645. <c>20</c>
  2646. <c><spanx style="vbare">C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C</spanx></c>
  2647. <c>21</c>
  2648. <c><spanx style="vbare">C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C</spanx></c>
  2649. <c>22</c>
  2650. <c><spanx style="vbare">C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C</spanx></c>
  2651. <c>23</c>
  2652. <c><spanx style="vbare">C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C</spanx></c>
  2653. <c>24</c>
  2654. <c><spanx style="vbare">C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D</spanx></c>
  2655. <c>25</c>
  2656. <c><spanx style="vbare">C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D</spanx></c>
  2657. <c>26</c>
  2658. <c><spanx style="vbare">C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D</spanx></c>
  2659. <c>27</c>
  2660. <c><spanx style="vbare">C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D</spanx></c>
  2661. <c>28</c>
  2662. <c><spanx style="vbare">C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D</spanx></c>
  2663. <c>29</c>
  2664. <c><spanx style="vbare">C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D</spanx></c>
  2665. <c>30</c>
  2666. <c><spanx style="vbare">D&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;C</spanx></c>
  2667. <c>31</c>
  2668. <c><spanx style="vbare">C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C&nbsp;&nbsp;C&nbsp;&nbsp;D&nbsp;&nbsp;C</spanx></c>
  2669. </texttable>
  2670. <?rfc compact="yes" ?>
  2671. </section>
  2672. <section anchor="silk_nlsf_reconstruction"
  2673. title="Reconstructing the Normalized LSF Coefficients">
  2674. <t>
  2675. Once the stage-1 index I1 and the stage-2 residual res_Q10[] have been decoded,
  2676. the final normalized LSF coefficients can be reconstructed.
  2677. </t>
  2678. <t>
  2679. The spectral distortion introduced by the quantization of each LSF coefficient
  2680. varies, so the stage-2 residual is weighted accordingly, using the
  2681. low-complexity Inverse Harmonic Mean Weighting (IHMW) function proposed in
  2682. <xref target="LAROIA-ICASSP"/>.
  2683. The weights are derived directly from the stage-1 codebook vector.
  2684. Let cb1_Q8[k] be the k'th entry of the stage-1 codebook vector from
  2685. <xref target="silk_nlsf_nbmb_codebook"/> or
  2686. <xref target="silk_nlsf_wb_codebook"/>.
  2687. Then, for 0&nbsp;&lt;=&nbsp;k&nbsp;&lt;&nbsp;d_LPC, the following expression
  2688. computes the square of the weight as a Q18 value:
  2689. <figure align="center">
  2690. <artwork align="center">
  2691. <![CDATA[
  2692. w2_Q18[k] = (1024/(cb1_Q8[k] - cb1_Q8[k-1])
  2693. + 1024/(cb1_Q8[k+1] - cb1_Q8[k])) << 16
  2694. ]]>
  2695. </artwork>
  2696. </figure>
  2697. where cb1_Q8[-1]&nbsp;=&nbsp;0 and cb1_Q8[d_LPC]&nbsp;=&nbsp;256, and the
  2698. division is integer division.
  2699. This is reduced to an unsquared, Q9 value using the following square-root
  2700. approximation:
  2701. <figure align="center">
  2702. <artwork align="center"><![CDATA[
  2703. i = ilog(w2_Q18[k])
  2704. f = (w2_Q18[k]>>(i-8)) & 127
  2705. y = ((i&1) ? 32768 : 46214) >> ((32-i)>>1)
  2706. w_Q9[k] = y + ((213*f*y)>>16)
  2707. ]]></artwork>
  2708. </figure>
  2709. The constant 46214 here is approximately the square root of 2 in Q15.
  2710. The cb1_Q8[] vector completely determines these weights, and they may be
  2711. tabulated and stored as 13-bit unsigned values (with a range of 1819 to 5227,
  2712. inclusive) to avoid computing them when decoding.
  2713. The reference implementation already requires code to compute these weights on
  2714. unquantized coefficients in the encoder, in silk_NLSF_VQ_weights_laroia()
  2715. (NLSF_VQ_weights_laroia.c) and its callers, so it reuses that code in the
  2716. decoder instead of using a pre-computed table to reduce the amount of ROM
  2717. required.
  2718. </t>
  2719. <?rfc compact="no" ?>
  2720. <texttable anchor="silk_nlsf_nbmb_codebook"
  2721. title="NB/MB Normalized LSF Stage-1 Codebook Vectors">
  2722. <ttcol>I1</ttcol>
  2723. <ttcol>Codebook (Q8)</ttcol>
  2724. <c/>
  2725. <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;5&nbsp;&nbsp;&nbsp;6&nbsp;&nbsp;&nbsp;7&nbsp;&nbsp;&nbsp;8&nbsp;&nbsp;&nbsp;9</spanx></c>
  2726. <c>0</c>
  2727. <c><spanx style="vbare">12&nbsp;&nbsp;35&nbsp;&nbsp;60&nbsp;&nbsp;83&nbsp;108&nbsp;132&nbsp;157&nbsp;180&nbsp;206&nbsp;228</spanx></c>
  2728. <c>1</c>
  2729. <c><spanx style="vbare">15&nbsp;&nbsp;32&nbsp;&nbsp;55&nbsp;&nbsp;77&nbsp;101&nbsp;125&nbsp;151&nbsp;175&nbsp;201&nbsp;225</spanx></c>
  2730. <c>2</c>
  2731. <c><spanx style="vbare">19&nbsp;&nbsp;42&nbsp;&nbsp;66&nbsp;&nbsp;89&nbsp;114&nbsp;137&nbsp;162&nbsp;184&nbsp;209&nbsp;230</spanx></c>
  2732. <c>3</c>
  2733. <c><spanx style="vbare">12&nbsp;&nbsp;25&nbsp;&nbsp;50&nbsp;&nbsp;72&nbsp;&nbsp;97&nbsp;120&nbsp;147&nbsp;172&nbsp;200&nbsp;223</spanx></c>
  2734. <c>4</c>
  2735. <c><spanx style="vbare">26&nbsp;&nbsp;44&nbsp;&nbsp;69&nbsp;&nbsp;90&nbsp;114&nbsp;135&nbsp;159&nbsp;180&nbsp;205&nbsp;225</spanx></c>
  2736. <c>5</c>
  2737. <c><spanx style="vbare">13&nbsp;&nbsp;22&nbsp;&nbsp;53&nbsp;&nbsp;80&nbsp;106&nbsp;130&nbsp;156&nbsp;180&nbsp;205&nbsp;228</spanx></c>
  2738. <c>6</c>
  2739. <c><spanx style="vbare">15&nbsp;&nbsp;25&nbsp;&nbsp;44&nbsp;&nbsp;64&nbsp;&nbsp;90&nbsp;115&nbsp;142&nbsp;168&nbsp;196&nbsp;222</spanx></c>
  2740. <c>7</c>
  2741. <c><spanx style="vbare">19&nbsp;&nbsp;24&nbsp;&nbsp;62&nbsp;&nbsp;82&nbsp;100&nbsp;120&nbsp;145&nbsp;168&nbsp;190&nbsp;214</spanx></c>
  2742. <c>8</c>
  2743. <c><spanx style="vbare">22&nbsp;&nbsp;31&nbsp;&nbsp;50&nbsp;&nbsp;79&nbsp;103&nbsp;120&nbsp;151&nbsp;170&nbsp;203&nbsp;227</spanx></c>
  2744. <c>9</c>
  2745. <c><spanx style="vbare">21&nbsp;&nbsp;29&nbsp;&nbsp;45&nbsp;&nbsp;65&nbsp;106&nbsp;124&nbsp;150&nbsp;171&nbsp;196&nbsp;224</spanx></c>
  2746. <c>10</c>
  2747. <c><spanx style="vbare">30&nbsp;&nbsp;49&nbsp;&nbsp;75&nbsp;&nbsp;97&nbsp;121&nbsp;142&nbsp;165&nbsp;186&nbsp;209&nbsp;229</spanx></c>
  2748. <c>11</c>
  2749. <c><spanx style="vbare">19&nbsp;&nbsp;25&nbsp;&nbsp;52&nbsp;&nbsp;70&nbsp;&nbsp;93&nbsp;116&nbsp;143&nbsp;166&nbsp;192&nbsp;219</spanx></c>
  2750. <c>12</c>
  2751. <c><spanx style="vbare">26&nbsp;&nbsp;34&nbsp;&nbsp;62&nbsp;&nbsp;75&nbsp;&nbsp;97&nbsp;118&nbsp;145&nbsp;167&nbsp;194&nbsp;217</spanx></c>
  2752. <c>13</c>
  2753. <c><spanx style="vbare">25&nbsp;&nbsp;33&nbsp;&nbsp;56&nbsp;&nbsp;70&nbsp;&nbsp;91&nbsp;113&nbsp;143&nbsp;165&nbsp;196&nbsp;223</spanx></c>
  2754. <c>14</c>
  2755. <c><spanx style="vbare">21&nbsp;&nbsp;34&nbsp;&nbsp;51&nbsp;&nbsp;72&nbsp;&nbsp;97&nbsp;117&nbsp;145&nbsp;171&nbsp;196&nbsp;222</spanx></c>
  2756. <c>15</c>
  2757. <c><spanx style="vbare">20&nbsp;&nbsp;29&nbsp;&nbsp;50&nbsp;&nbsp;67&nbsp;&nbsp;90&nbsp;117&nbsp;144&nbsp;168&nbsp;197&nbsp;221</spanx></c>
  2758. <c>16</c>
  2759. <c><spanx style="vbare">22&nbsp;&nbsp;31&nbsp;&nbsp;48&nbsp;&nbsp;66&nbsp;&nbsp;95&nbsp;117&nbsp;146&nbsp;168&nbsp;196&nbsp;222</spanx></c>
  2760. <c>17</c>
  2761. <c><spanx style="vbare">24&nbsp;&nbsp;33&nbsp;&nbsp;51&nbsp;&nbsp;77&nbsp;116&nbsp;134&nbsp;158&nbsp;180&nbsp;200&nbsp;224</spanx></c>
  2762. <c>18</c>
  2763. <c><spanx style="vbare">21&nbsp;&nbsp;28&nbsp;&nbsp;70&nbsp;&nbsp;87&nbsp;106&nbsp;124&nbsp;149&nbsp;170&nbsp;194&nbsp;217</spanx></c>
  2764. <c>19</c>
  2765. <c><spanx style="vbare">26&nbsp;&nbsp;33&nbsp;&nbsp;53&nbsp;&nbsp;64&nbsp;&nbsp;83&nbsp;117&nbsp;152&nbsp;173&nbsp;204&nbsp;225</spanx></c>
  2766. <c>20</c>
  2767. <c><spanx style="vbare">27&nbsp;&nbsp;34&nbsp;&nbsp;65&nbsp;&nbsp;95&nbsp;108&nbsp;129&nbsp;155&nbsp;174&nbsp;210&nbsp;225</spanx></c>
  2768. <c>21</c>
  2769. <c><spanx style="vbare">20&nbsp;&nbsp;26&nbsp;&nbsp;72&nbsp;&nbsp;99&nbsp;113&nbsp;131&nbsp;154&nbsp;176&nbsp;200&nbsp;219</spanx></c>
  2770. <c>22</c>
  2771. <c><spanx style="vbare">34&nbsp;&nbsp;43&nbsp;&nbsp;61&nbsp;&nbsp;78&nbsp;&nbsp;93&nbsp;114&nbsp;155&nbsp;177&nbsp;205&nbsp;229</spanx></c>
  2772. <c>23</c>
  2773. <c><spanx style="vbare">23&nbsp;&nbsp;29&nbsp;&nbsp;54&nbsp;&nbsp;97&nbsp;124&nbsp;138&nbsp;163&nbsp;179&nbsp;209&nbsp;229</spanx></c>
  2774. <c>24</c>
  2775. <c><spanx style="vbare">30&nbsp;&nbsp;38&nbsp;&nbsp;56&nbsp;&nbsp;89&nbsp;118&nbsp;129&nbsp;158&nbsp;178&nbsp;200&nbsp;231</spanx></c>
  2776. <c>25</c>
  2777. <c><spanx style="vbare">21&nbsp;&nbsp;29&nbsp;&nbsp;49&nbsp;&nbsp;63&nbsp;&nbsp;85&nbsp;111&nbsp;142&nbsp;163&nbsp;193&nbsp;222</spanx></c>
  2778. <c>26</c>
  2779. <c><spanx style="vbare">27&nbsp;&nbsp;48&nbsp;&nbsp;77&nbsp;103&nbsp;133&nbsp;158&nbsp;179&nbsp;196&nbsp;215&nbsp;232</spanx></c>
  2780. <c>27</c>
  2781. <c><spanx style="vbare">29&nbsp;&nbsp;47&nbsp;&nbsp;74&nbsp;&nbsp;99&nbsp;124&nbsp;151&nbsp;176&nbsp;198&nbsp;220&nbsp;237</spanx></c>
  2782. <c>28</c>
  2783. <c><spanx style="vbare">33&nbsp;&nbsp;42&nbsp;&nbsp;61&nbsp;&nbsp;76&nbsp;&nbsp;93&nbsp;121&nbsp;155&nbsp;174&nbsp;207&nbsp;225</spanx></c>
  2784. <c>29</c>
  2785. <c><spanx style="vbare">29&nbsp;&nbsp;53&nbsp;&nbsp;87&nbsp;112&nbsp;136&nbsp;154&nbsp;170&nbsp;188&nbsp;208&nbsp;227</spanx></c>
  2786. <c>30</c>
  2787. <c><spanx style="vbare">24&nbsp;&nbsp;30&nbsp;&nbsp;52&nbsp;&nbsp;84&nbsp;131&nbsp;150&nbsp;166&nbsp;186&nbsp;203&nbsp;229</spanx></c>
  2788. <c>31</c>
  2789. <c><spanx style="vbare">37&nbsp;&nbsp;48&nbsp;&nbsp;64&nbsp;&nbsp;84&nbsp;104&nbsp;118&nbsp;156&nbsp;177&nbsp;201&nbsp;230</spanx></c>
  2790. </texttable>
  2791. <?rfc compact="yes" ?>
  2792. <?rfc compact="no" ?>
  2793. <texttable anchor="silk_nlsf_wb_codebook"
  2794. title="WB Normalized LSF Stage-1 Codebook Vectors">
  2795. <ttcol>I1</ttcol>
  2796. <ttcol>Codebook (Q8)</ttcol>
  2797. <c/>
  2798. <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;1&nbsp;&nbsp;2&nbsp;&nbsp;3&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;5&nbsp;&nbsp;&nbsp;6&nbsp;&nbsp;&nbsp;7&nbsp;&nbsp;&nbsp;8&nbsp;&nbsp;&nbsp;9&nbsp;&nbsp;10&nbsp;&nbsp;11&nbsp;&nbsp;12&nbsp;&nbsp;13&nbsp;&nbsp;14&nbsp;&nbsp;15</spanx></c>
  2799. <c>0</c>
  2800. <c><spanx style="vbare">&nbsp;7&nbsp;23&nbsp;38&nbsp;54&nbsp;69&nbsp;&nbsp;85&nbsp;100&nbsp;116&nbsp;131&nbsp;147&nbsp;162&nbsp;178&nbsp;193&nbsp;208&nbsp;223&nbsp;239</spanx></c>
  2801. <c>1</c>
  2802. <c><spanx style="vbare">13&nbsp;25&nbsp;41&nbsp;55&nbsp;69&nbsp;&nbsp;83&nbsp;&nbsp;98&nbsp;112&nbsp;127&nbsp;142&nbsp;157&nbsp;171&nbsp;187&nbsp;203&nbsp;220&nbsp;236</spanx></c>
  2803. <c>2</c>
  2804. <c><spanx style="vbare">15&nbsp;21&nbsp;34&nbsp;51&nbsp;61&nbsp;&nbsp;78&nbsp;&nbsp;92&nbsp;106&nbsp;126&nbsp;136&nbsp;152&nbsp;167&nbsp;185&nbsp;205&nbsp;225&nbsp;240</spanx></c>
  2805. <c>3</c>
  2806. <c><spanx style="vbare">10&nbsp;21&nbsp;36&nbsp;50&nbsp;63&nbsp;&nbsp;79&nbsp;&nbsp;95&nbsp;110&nbsp;126&nbsp;141&nbsp;157&nbsp;173&nbsp;189&nbsp;205&nbsp;221&nbsp;237</spanx></c>
  2807. <c>4</c>
  2808. <c><spanx style="vbare">17&nbsp;20&nbsp;37&nbsp;51&nbsp;59&nbsp;&nbsp;78&nbsp;&nbsp;89&nbsp;107&nbsp;123&nbsp;134&nbsp;150&nbsp;164&nbsp;184&nbsp;205&nbsp;224&nbsp;240</spanx></c>
  2809. <c>5</c>
  2810. <c><spanx style="vbare">10&nbsp;15&nbsp;32&nbsp;51&nbsp;67&nbsp;&nbsp;81&nbsp;&nbsp;96&nbsp;112&nbsp;129&nbsp;142&nbsp;158&nbsp;173&nbsp;189&nbsp;204&nbsp;220&nbsp;236</spanx></c>
  2811. <c>6</c>
  2812. <c><spanx style="vbare">&nbsp;8&nbsp;21&nbsp;37&nbsp;51&nbsp;65&nbsp;&nbsp;79&nbsp;&nbsp;98&nbsp;113&nbsp;126&nbsp;138&nbsp;155&nbsp;168&nbsp;179&nbsp;192&nbsp;209&nbsp;218</spanx></c>
  2813. <c>7</c>
  2814. <c><spanx style="vbare">12&nbsp;15&nbsp;34&nbsp;55&nbsp;63&nbsp;&nbsp;78&nbsp;&nbsp;87&nbsp;108&nbsp;118&nbsp;131&nbsp;148&nbsp;167&nbsp;185&nbsp;203&nbsp;219&nbsp;236</spanx></c>
  2815. <c>8</c>
  2816. <c><spanx style="vbare">16&nbsp;19&nbsp;32&nbsp;36&nbsp;56&nbsp;&nbsp;79&nbsp;&nbsp;91&nbsp;108&nbsp;118&nbsp;136&nbsp;154&nbsp;171&nbsp;186&nbsp;204&nbsp;220&nbsp;237</spanx></c>
  2817. <c>9</c>
  2818. <c><spanx style="vbare">11&nbsp;28&nbsp;43&nbsp;58&nbsp;74&nbsp;&nbsp;89&nbsp;105&nbsp;120&nbsp;135&nbsp;150&nbsp;165&nbsp;180&nbsp;196&nbsp;211&nbsp;226&nbsp;241</spanx></c>
  2819. <c>10</c>
  2820. <c><spanx style="vbare">&nbsp;6&nbsp;16&nbsp;33&nbsp;46&nbsp;60&nbsp;&nbsp;75&nbsp;&nbsp;92&nbsp;107&nbsp;123&nbsp;137&nbsp;156&nbsp;169&nbsp;185&nbsp;199&nbsp;214&nbsp;225</spanx></c>
  2821. <c>11</c>
  2822. <c><spanx style="vbare">11&nbsp;19&nbsp;30&nbsp;44&nbsp;57&nbsp;&nbsp;74&nbsp;&nbsp;89&nbsp;105&nbsp;121&nbsp;135&nbsp;152&nbsp;169&nbsp;186&nbsp;202&nbsp;218&nbsp;234</spanx></c>
  2823. <c>12</c>
  2824. <c><spanx style="vbare">12&nbsp;19&nbsp;29&nbsp;46&nbsp;57&nbsp;&nbsp;71&nbsp;&nbsp;88&nbsp;100&nbsp;120&nbsp;132&nbsp;148&nbsp;165&nbsp;182&nbsp;199&nbsp;216&nbsp;233</spanx></c>
  2825. <c>13</c>
  2826. <c><spanx style="vbare">17&nbsp;23&nbsp;35&nbsp;46&nbsp;56&nbsp;&nbsp;77&nbsp;&nbsp;92&nbsp;106&nbsp;123&nbsp;134&nbsp;152&nbsp;167&nbsp;185&nbsp;204&nbsp;222&nbsp;237</spanx></c>
  2827. <c>14</c>
  2828. <c><spanx style="vbare">14&nbsp;17&nbsp;45&nbsp;53&nbsp;63&nbsp;&nbsp;75&nbsp;&nbsp;89&nbsp;107&nbsp;115&nbsp;132&nbsp;151&nbsp;171&nbsp;188&nbsp;206&nbsp;221&nbsp;240</spanx></c>
  2829. <c>15</c>
  2830. <c><spanx style="vbare">&nbsp;9&nbsp;16&nbsp;29&nbsp;40&nbsp;56&nbsp;&nbsp;71&nbsp;&nbsp;88&nbsp;103&nbsp;119&nbsp;137&nbsp;154&nbsp;171&nbsp;189&nbsp;205&nbsp;222&nbsp;237</spanx></c>
  2831. <c>16</c>
  2832. <c><spanx style="vbare">16&nbsp;19&nbsp;36&nbsp;48&nbsp;57&nbsp;&nbsp;76&nbsp;&nbsp;87&nbsp;105&nbsp;118&nbsp;132&nbsp;150&nbsp;167&nbsp;185&nbsp;202&nbsp;218&nbsp;236</spanx></c>
  2833. <c>17</c>
  2834. <c><spanx style="vbare">12&nbsp;17&nbsp;29&nbsp;54&nbsp;71&nbsp;&nbsp;81&nbsp;&nbsp;94&nbsp;104&nbsp;126&nbsp;136&nbsp;149&nbsp;164&nbsp;182&nbsp;201&nbsp;221&nbsp;237</spanx></c>
  2835. <c>18</c>
  2836. <c><spanx style="vbare">15&nbsp;28&nbsp;47&nbsp;62&nbsp;79&nbsp;&nbsp;97&nbsp;115&nbsp;129&nbsp;142&nbsp;155&nbsp;168&nbsp;180&nbsp;194&nbsp;208&nbsp;223&nbsp;238</spanx></c>
  2837. <c>19</c>
  2838. <c><spanx style="vbare">&nbsp;8&nbsp;14&nbsp;30&nbsp;45&nbsp;62&nbsp;&nbsp;78&nbsp;&nbsp;94&nbsp;111&nbsp;127&nbsp;143&nbsp;159&nbsp;175&nbsp;192&nbsp;207&nbsp;223&nbsp;239</spanx></c>
  2839. <c>20</c>
  2840. <c><spanx style="vbare">17&nbsp;30&nbsp;49&nbsp;62&nbsp;79&nbsp;&nbsp;92&nbsp;107&nbsp;119&nbsp;132&nbsp;145&nbsp;160&nbsp;174&nbsp;190&nbsp;204&nbsp;220&nbsp;235</spanx></c>
  2841. <c>21</c>
  2842. <c><spanx style="vbare">14&nbsp;19&nbsp;36&nbsp;45&nbsp;61&nbsp;&nbsp;76&nbsp;&nbsp;91&nbsp;108&nbsp;121&nbsp;138&nbsp;154&nbsp;172&nbsp;189&nbsp;205&nbsp;222&nbsp;238</spanx></c>
  2843. <c>22</c>
  2844. <c><spanx style="vbare">12&nbsp;18&nbsp;31&nbsp;45&nbsp;60&nbsp;&nbsp;76&nbsp;&nbsp;91&nbsp;107&nbsp;123&nbsp;138&nbsp;154&nbsp;171&nbsp;187&nbsp;204&nbsp;221&nbsp;236</spanx></c>
  2845. <c>23</c>
  2846. <c><spanx style="vbare">13&nbsp;17&nbsp;31&nbsp;43&nbsp;53&nbsp;&nbsp;70&nbsp;&nbsp;83&nbsp;103&nbsp;114&nbsp;131&nbsp;149&nbsp;167&nbsp;185&nbsp;203&nbsp;220&nbsp;237</spanx></c>
  2847. <c>24</c>
  2848. <c><spanx style="vbare">17&nbsp;22&nbsp;35&nbsp;42&nbsp;58&nbsp;&nbsp;78&nbsp;&nbsp;93&nbsp;110&nbsp;125&nbsp;139&nbsp;155&nbsp;170&nbsp;188&nbsp;206&nbsp;224&nbsp;240</spanx></c>
  2849. <c>25</c>
  2850. <c><spanx style="vbare">&nbsp;8&nbsp;15&nbsp;34&nbsp;50&nbsp;67&nbsp;&nbsp;83&nbsp;&nbsp;99&nbsp;115&nbsp;131&nbsp;146&nbsp;162&nbsp;178&nbsp;193&nbsp;209&nbsp;224&nbsp;239</spanx></c>
  2851. <c>26</c>
  2852. <c><spanx style="vbare">13&nbsp;16&nbsp;41&nbsp;66&nbsp;73&nbsp;&nbsp;86&nbsp;&nbsp;95&nbsp;111&nbsp;128&nbsp;137&nbsp;150&nbsp;163&nbsp;183&nbsp;206&nbsp;225&nbsp;241</spanx></c>
  2853. <c>27</c>
  2854. <c><spanx style="vbare">17&nbsp;25&nbsp;37&nbsp;52&nbsp;63&nbsp;&nbsp;75&nbsp;&nbsp;92&nbsp;102&nbsp;119&nbsp;132&nbsp;144&nbsp;160&nbsp;175&nbsp;191&nbsp;212&nbsp;231</spanx></c>
  2855. <c>28</c>
  2856. <c><spanx style="vbare">19&nbsp;31&nbsp;49&nbsp;65&nbsp;83&nbsp;100&nbsp;117&nbsp;133&nbsp;147&nbsp;161&nbsp;174&nbsp;187&nbsp;200&nbsp;213&nbsp;227&nbsp;242</spanx></c>
  2857. <c>29</c>
  2858. <c><spanx style="vbare">18&nbsp;31&nbsp;52&nbsp;68&nbsp;88&nbsp;103&nbsp;117&nbsp;126&nbsp;138&nbsp;149&nbsp;163&nbsp;177&nbsp;192&nbsp;207&nbsp;223&nbsp;239</spanx></c>
  2859. <c>30</c>
  2860. <c><spanx style="vbare">16&nbsp;29&nbsp;47&nbsp;61&nbsp;76&nbsp;&nbsp;90&nbsp;106&nbsp;119&nbsp;133&nbsp;147&nbsp;161&nbsp;176&nbsp;193&nbsp;209&nbsp;224&nbsp;240</spanx></c>
  2861. <c>31</c>
  2862. <c><spanx style="vbare">15&nbsp;21&nbsp;35&nbsp;50&nbsp;61&nbsp;&nbsp;73&nbsp;&nbsp;86&nbsp;&nbsp;97&nbsp;110&nbsp;119&nbsp;129&nbsp;141&nbsp;175&nbsp;198&nbsp;218&nbsp;237</spanx></c>
  2863. </texttable>
  2864. <?rfc compact="yes" ?>
  2865. <t>
  2866. Given the stage-1 codebook entry cb1_Q8[], the stage-2 residual res_Q10[], and
  2867. their corresponding weights, w_Q9[], the reconstructed normalized LSF
  2868. coefficients are
  2869. <figure align="center">
  2870. <artwork align="center"><![CDATA[
  2871. NLSF_Q15[k] = clamp(0,
  2872. (cb1_Q8[k]<<7) + (res_Q10[k]<<14)/w_Q9[k], 32767)
  2873. ]]></artwork>
  2874. </figure>
  2875. where the division is integer division.
  2876. However, nothing in either the reconstruction process or the
  2877. quantization process in the encoder thus far guarantees that the coefficients
  2878. are monotonically increasing and separated well enough to ensure a stable
  2879. filter <xref target="KABAL86"/>.
  2880. When using the reference encoder, roughly 2% of frames violate this constraint.
  2881. The next section describes a stabilization procedure used to make these
  2882. guarantees.
  2883. </t>
  2884. </section>
  2885. <section anchor="silk_nlsf_stabilization" title="Normalized LSF Stabilization">
  2886. <t>
  2887. The normalized LSF stabilization procedure is implemented in
  2888. silk_NLSF_stabilize() (NLSF_stabilize.c).
  2889. This process ensures that consecutive values of the normalized LSF
  2890. coefficients, NLSF_Q15[], are spaced some minimum distance apart
  2891. (predetermined to be the 0.01 percentile of a large training set).
  2892. <xref target="silk_nlsf_min_spacing"/> gives the minimum spacings for NB and MB
  2893. and those for WB, where row k is the minimum allowed value of
  2894. NLSF_Q15[k]-NLSF_Q15[k-1].
  2895. For the purposes of computing this spacing for the first and last coefficient,
  2896. NLSF_Q15[-1] is taken to be 0 and NLSF_Q15[d_LPC] is taken to be 32768.
  2897. </t>
  2898. <?rfc compact="no" ?>
  2899. <texttable anchor="silk_nlsf_min_spacing"
  2900. title="Minimum Spacing for Normalized LSF Coefficients">
  2901. <ttcol>Coefficient</ttcol>
  2902. <ttcol align="right">NB and MB</ttcol>
  2903. <ttcol align="right">WB</ttcol>
  2904. <c>0</c> <c>250</c> <c>100</c>
  2905. <c>1</c> <c>3</c> <c>3</c>
  2906. <c>2</c> <c>6</c> <c>40</c>
  2907. <c>3</c> <c>3</c> <c>3</c>
  2908. <c>4</c> <c>3</c> <c>3</c>
  2909. <c>5</c> <c>3</c> <c>3</c>
  2910. <c>6</c> <c>4</c> <c>5</c>
  2911. <c>7</c> <c>3</c> <c>14</c>
  2912. <c>8</c> <c>3</c> <c>14</c>
  2913. <c>9</c> <c>3</c> <c>10</c>
  2914. <c>10</c> <c>461</c> <c>11</c>
  2915. <c>11</c> <c/> <c>3</c>
  2916. <c>12</c> <c/> <c>8</c>
  2917. <c>13</c> <c/> <c>9</c>
  2918. <c>14</c> <c/> <c>7</c>
  2919. <c>15</c> <c/> <c>3</c>
  2920. <c>16</c> <c/> <c>347</c>
  2921. </texttable>
  2922. <?rfc compact="yes" ?>
  2923. <t>
  2924. The procedure starts off by trying to make small adjustments that attempt to
  2925. minimize the amount of distortion introduced.
  2926. After 20 such adjustments, it falls back to a more direct method that
  2927. guarantees the constraints are enforced but may require large adjustments.
  2928. </t>
  2929. <t>
  2930. Let NDeltaMin_Q15[k] be the minimum required spacing for the current audio
  2931. bandwidth from <xref target="silk_nlsf_min_spacing"/>.
  2932. First, the procedure finds the index i where
  2933. NLSF_Q15[i]&nbsp;-&nbsp;NLSF_Q15[i-1]&nbsp;-&nbsp;NDeltaMin_Q15[i] is the
  2934. smallest, breaking ties by using the lower value of i.
  2935. If this value is non-negative, then the stabilization stops; the coefficients
  2936. satisfy all the constraints.
  2937. Otherwise, if i&nbsp;==&nbsp;0, it sets NLSF_Q15[0] to NDeltaMin_Q15[0], and if
  2938. i&nbsp;==&nbsp;d_LPC, it sets NLSF_Q15[d_LPC-1] to
  2939. (32768&nbsp;-&nbsp;NDeltaMin_Q15[d_LPC]).
  2940. For all other values of i, both NLSF_Q15[i-1] and NLSF_Q15[i] are updated as
  2941. follows:
  2942. <figure align="center">
  2943. <artwork align="center"><![CDATA[
  2944. i-1
  2945. __
  2946. min_center_Q15 = (NDeltaMin_Q15[i]>>1) + \ NDeltaMin_Q15[k]
  2947. /_
  2948. k=0
  2949. d_LPC
  2950. __
  2951. max_center_Q15 = 32768 - (NDeltaMin_Q15[i]>>1) - \ NDeltaMin_Q15[k]
  2952. /_
  2953. k=i+1
  2954. center_freq_Q15 = clamp(min_center_Q15[i],
  2955. (NLSF_Q15[i-1] + NLSF_Q15[i] + 1)>>1
  2956. max_center_Q15[i])
  2957. NLSF_Q15[i-1] = center_freq_Q15 - (NDeltaMin_Q15[i]>>1)
  2958. NLSF_Q15[i] = NLSF_Q15[i-1] + NDeltaMin_Q15[i]
  2959. ]]></artwork>
  2960. </figure>
  2961. Then, the procedure repeats again, until it has either executed 20 times or
  2962. stopped because the coefficients satisfy all the constraints.
  2963. </t>
  2964. <t>
  2965. After the 20th repetition of the above procedure, the following fallback
  2966. procedure executes once.
  2967. First, the values of NLSF_Q15[k] for 0&nbsp;&lt;=&nbsp;k&nbsp;&lt;&nbsp;d_LPC
  2968. are sorted in ascending order.
  2969. Then, for each value of k from 0 to d_LPC-1, NLSF_Q15[k] is set to
  2970. <figure align="center">
  2971. <artwork align="center"><![CDATA[
  2972. max(NLSF_Q15[k], NLSF_Q15[k-1] + NDeltaMin_Q15[k])
  2973. ]]></artwork>
  2974. </figure>
  2975. Next, for each value of k from d_LPC-1 down to 0, NLSF_Q15[k] is set to
  2976. <figure align="center">
  2977. <artwork align="center"><![CDATA[
  2978. min(NLSF_Q15[k], NLSF_Q15[k+1] - NDeltaMin_Q15[k+1])
  2979. ]]></artwork>
  2980. </figure>
  2981. </t>
  2982. <t>
  2983. There is no need to check if the coefficients satisfy all the constraints
  2984. before applying this fallback procedure.
  2985. If they do, then it will not change their values.
  2986. </t>
  2987. </section>
  2988. <section anchor="silk_nlsf_interpolation" title="Normalized LSF Interpolation">
  2989. <t>
  2990. For 20&nbsp;ms SILK frames, the first half of the frame (i.e., the first two
  2991. subframes) may use normalized LSF coefficients that are interpolated between
  2992. the decoded LSFs for the most recent coded frame (in the same channel) and the
  2993. current frame.
  2994. A Q2 interpolation factor follows the LSF coefficient indices in the bitstream,
  2995. which is decoded using the PDF in <xref target="silk_nlsf_interp_pdf"/>.
  2996. This happens in silk_decode_indices() (decode_indices.c).
  2997. After either
  2998. <list style="symbols">
  2999. <t>An uncoded regular SILK frame in the side channel, or</t>
  3000. <t>A decoder reset (see <xref target="decoder-reset"/>),</t>
  3001. </list>
  3002. the decoder still decodes this factor, but ignores its value and always uses
  3003. 4 instead.
  3004. For 10&nbsp;ms SILK frames, this factor is not stored at all.
  3005. </t>
  3006. <?rfc compact="no" ?>
  3007. <texttable anchor="silk_nlsf_interp_pdf"
  3008. title="PDF for Normalized LSF Interpolation Index">
  3009. <ttcol>PDF</ttcol>
  3010. <c>{13, 22, 29, 11, 181}/256</c>
  3011. </texttable>
  3012. <?rfc compact="yes" ?>
  3013. <t>
  3014. Let n2_Q15[k] be the normalized LSF coefficients decoded by the procedure in
  3015. <xref target="silk_nlsfs"/>, n0_Q15[k] be the LSF coefficients
  3016. decoded for the prior frame, and w_Q2 be the interpolation factor.
  3017. Then, the normalized LSF coefficients used for the first half of a 20&nbsp;ms
  3018. frame, n1_Q15[k], are
  3019. <figure align="center">
  3020. <artwork align="center"><![CDATA[
  3021. n1_Q15[k] = n0_Q15[k] + (w_Q2*(n2_Q15[k] - n0_Q15[k]) >> 2)
  3022. ]]></artwork>
  3023. </figure>
  3024. This interpolation is performed in silk_decode_parameters()
  3025. (decode_parameters.c).
  3026. </t>
  3027. </section>
  3028. <section anchor="silk_nlsf2lpc"
  3029. title="Converting Normalized LSFs to LPC Coefficients">
  3030. <t>
  3031. Any LPC filter A(z) can be split into a symmetric part P(z) and an
  3032. anti-symmetric part Q(z) such that
  3033. <figure align="center">
  3034. <artwork align="center"><![CDATA[
  3035. d_LPC
  3036. __ -k 1
  3037. A(z) = 1 - \ a[k] * z = - * (P(z) + Q(z))
  3038. /_ 2
  3039. k=1
  3040. ]]></artwork>
  3041. </figure>
  3042. with
  3043. <figure align="center">
  3044. <artwork align="center"><![CDATA[
  3045. -d_LPC-1 -1
  3046. P(z) = A(z) + z * A(z )
  3047. -d_LPC-1 -1
  3048. Q(z) = A(z) - z * A(z )
  3049. ]]></artwork>
  3050. </figure>
  3051. The even normalized LSF coefficients correspond to a pair of conjugate roots of
  3052. P(z), while the odd coefficients correspond to a pair of conjugate roots of
  3053. Q(z), all of which lie on the unit circle.
  3054. In addition, P(z) has a root at pi and Q(z) has a root at 0.
  3055. Thus, they may be reconstructed mathematically from a set of normalized LSF
  3056. coefficients, n[k], as
  3057. <figure align="center">
  3058. <artwork align="center"><![CDATA[
  3059. d_LPC/2-1
  3060. -1 ___ -1 -2
  3061. P(z) = (1 + z ) * | | (1 - 2*cos(pi*n[2*k])*z + z )
  3062. k=0
  3063. d_LPC/2-1
  3064. -1 ___ -1 -2
  3065. Q(z) = (1 - z ) * | | (1 - 2*cos(pi*n[2*k+1])*z + z )
  3066. k=0
  3067. ]]></artwork>
  3068. </figure>
  3069. </t>
  3070. <t>
  3071. However, SILK performs this reconstruction using a fixed-point approximation so
  3072. that all decoders can reproduce it in a bit-exact manner to avoid prediction
  3073. drift.
  3074. The function silk_NLSF2A() (NLSF2A.c) implements this procedure.
  3075. </t>
  3076. <t>
  3077. To start, it approximates cos(pi*n[k]) using a table lookup with linear
  3078. interpolation.
  3079. The encoder SHOULD use the inverse of this piecewise linear approximation,
  3080. rather than the true inverse of the cosine function, when deriving the
  3081. normalized LSF coefficients.
  3082. These values are also re-ordered to improve numerical accuracy when
  3083. constructing the LPC polynomials.
  3084. </t>
  3085. <?rfc compact="no" ?>
  3086. <texttable anchor="silk_nlsf_orderings"
  3087. title="LSF Ordering for Polynomial Evaluation">
  3088. <ttcol>Coefficient</ttcol>
  3089. <ttcol align="right">NB and MB</ttcol>
  3090. <ttcol align="right">WB</ttcol>
  3091. <c>0</c> <c>0</c> <c>0</c>
  3092. <c>1</c> <c>9</c> <c>15</c>
  3093. <c>2</c> <c>6</c> <c>8</c>
  3094. <c>3</c> <c>3</c> <c>7</c>
  3095. <c>4</c> <c>4</c> <c>4</c>
  3096. <c>5</c> <c>5</c> <c>11</c>
  3097. <c>6</c> <c>8</c> <c>12</c>
  3098. <c>7</c> <c>1</c> <c>3</c>
  3099. <c>8</c> <c>2</c> <c>2</c>
  3100. <c>9</c> <c>7</c> <c>13</c>
  3101. <c>10</c> <c/> <c>10</c>
  3102. <c>11</c> <c/> <c>5</c>
  3103. <c>12</c> <c/> <c>6</c>
  3104. <c>13</c> <c/> <c>9</c>
  3105. <c>14</c> <c/> <c>14</c>
  3106. <c>15</c> <c/> <c>1</c>
  3107. </texttable>
  3108. <?rfc compact="yes" ?>
  3109. <t>
  3110. The top 7 bits of each normalized LSF coefficient index a value in the table,
  3111. and the next 8 bits interpolate between it and the next value.
  3112. Let i&nbsp;=&nbsp;(n[k]&nbsp;&gt;&gt;&nbsp;8) be the integer index and
  3113. f&nbsp;=&nbsp;(n[k]&nbsp;&amp;&nbsp;255) be the fractional part of a given
  3114. coefficient.
  3115. Then, the re-ordered, approximated cosine, c_Q17[ordering[k]], is
  3116. <figure align="center">
  3117. <artwork align="center"><![CDATA[
  3118. c_Q17[ordering[k]] = (cos_Q12[i]*256
  3119. + (cos_Q12[i+1]-cos_Q12[i])*f + 4) >> 3
  3120. ]]></artwork>
  3121. </figure>
  3122. where ordering[k] is the k'th entry of the column of
  3123. <xref target="silk_nlsf_orderings"/> corresponding to the current audio
  3124. bandwidth and cos_Q12[i] is the i'th entry of <xref target="silk_cos_table"/>.
  3125. </t>
  3126. <?rfc compact="no" ?>
  3127. <texttable anchor="silk_cos_table"
  3128. title="Q12 Cosine Table for LSF Conversion">
  3129. <ttcol align="right">i</ttcol>
  3130. <ttcol align="right">+0</ttcol>
  3131. <ttcol align="right">+1</ttcol>
  3132. <ttcol align="right">+2</ttcol>
  3133. <ttcol align="right">+3</ttcol>
  3134. <c>0</c>
  3135. <c>4096</c> <c>4095</c> <c>4091</c> <c>4085</c>
  3136. <c>4</c>
  3137. <c>4076</c> <c>4065</c> <c>4052</c> <c>4036</c>
  3138. <c>8</c>
  3139. <c>4017</c> <c>3997</c> <c>3973</c> <c>3948</c>
  3140. <c>12</c>
  3141. <c>3920</c> <c>3889</c> <c>3857</c> <c>3822</c>
  3142. <c>16</c>
  3143. <c>3784</c> <c>3745</c> <c>3703</c> <c>3659</c>
  3144. <c>20</c>
  3145. <c>3613</c> <c>3564</c> <c>3513</c> <c>3461</c>
  3146. <c>24</c>
  3147. <c>3406</c> <c>3349</c> <c>3290</c> <c>3229</c>
  3148. <c>28</c>
  3149. <c>3166</c> <c>3102</c> <c>3035</c> <c>2967</c>
  3150. <c>32</c>
  3151. <c>2896</c> <c>2824</c> <c>2751</c> <c>2676</c>
  3152. <c>36</c>
  3153. <c>2599</c> <c>2520</c> <c>2440</c> <c>2359</c>
  3154. <c>40</c>
  3155. <c>2276</c> <c>2191</c> <c>2106</c> <c>2019</c>
  3156. <c>44</c>
  3157. <c>1931</c> <c>1842</c> <c>1751</c> <c>1660</c>
  3158. <c>48</c>
  3159. <c>1568</c> <c>1474</c> <c>1380</c> <c>1285</c>
  3160. <c>52</c>
  3161. <c>1189</c> <c>1093</c> <c>995</c> <c>897</c>
  3162. <c>56</c>
  3163. <c>799</c> <c>700</c> <c>601</c> <c>501</c>
  3164. <c>60</c>
  3165. <c>401</c> <c>301</c> <c>201</c> <c>101</c>
  3166. <c>64</c>
  3167. <c>0</c> <c>-101</c> <c>-201</c> <c>-301</c>
  3168. <c>68</c>
  3169. <c>-401</c> <c>-501</c> <c>-601</c> <c>-700</c>
  3170. <c>72</c>
  3171. <c>-799</c> <c>-897</c> <c>-995</c> <c>-1093</c>
  3172. <c>76</c>
  3173. <c>-1189</c><c>-1285</c><c>-1380</c><c>-1474</c>
  3174. <c>80</c>
  3175. <c>-1568</c><c>-1660</c><c>-1751</c><c>-1842</c>
  3176. <c>84</c>
  3177. <c>-1931</c><c>-2019</c><c>-2106</c><c>-2191</c>
  3178. <c>88</c>
  3179. <c>-2276</c><c>-2359</c><c>-2440</c><c>-2520</c>
  3180. <c>92</c>
  3181. <c>-2599</c><c>-2676</c><c>-2751</c><c>-2824</c>
  3182. <c>96</c>
  3183. <c>-2896</c><c>-2967</c><c>-3035</c><c>-3102</c>
  3184. <c>100</c>
  3185. <c>-3166</c><c>-3229</c><c>-3290</c><c>-3349</c>
  3186. <c>104</c>
  3187. <c>-3406</c><c>-3461</c><c>-3513</c><c>-3564</c>
  3188. <c>108</c>
  3189. <c>-3613</c><c>-3659</c><c>-3703</c><c>-3745</c>
  3190. <c>112</c>
  3191. <c>-3784</c><c>-3822</c><c>-3857</c><c>-3889</c>
  3192. <c>116</c>
  3193. <c>-3920</c><c>-3948</c><c>-3973</c><c>-3997</c>
  3194. <c>120</c>
  3195. <c>-4017</c><c>-4036</c><c>-4052</c><c>-4065</c>
  3196. <c>124</c>
  3197. <c>-4076</c><c>-4085</c><c>-4091</c><c>-4095</c>
  3198. <c>128</c>
  3199. <c>-4096</c> <c/> <c/> <c/>
  3200. </texttable>
  3201. <?rfc compact="yes" ?>
  3202. <t>
  3203. Given the list of cosine values, silk_NLSF2A_find_poly() (NLSF2A.c)
  3204. computes the coefficients of P and Q, described here via a simple recurrence.
  3205. Let p_Q16[k][j] and q_Q16[k][j] be the coefficients of the products of the
  3206. first (k+1) root pairs for P and Q, with j indexing the coefficient number.
  3207. Only the first (k+2) coefficients are needed, as the products are symmetric.
  3208. Let p_Q16[0][0]&nbsp;=&nbsp;q_Q16[0][0]&nbsp;=&nbsp;1&lt;&lt;16,
  3209. p_Q16[0][1]&nbsp;=&nbsp;-c_Q17[0], q_Q16[0][1]&nbsp;=&nbsp;-c_Q17[1], and
  3210. d2&nbsp;=&nbsp;d_LPC/2.
  3211. As boundary conditions, assume
  3212. p_Q16[k][j]&nbsp;=&nbsp;q_Q16[k][j]&nbsp;=&nbsp;0 for all
  3213. j&nbsp;&lt;&nbsp;0.
  3214. Also, assume p_Q16[k][k+2]&nbsp;=&nbsp;p_Q16[k][k] and
  3215. q_Q16[k][k+2]&nbsp;=&nbsp;q_Q16[k][k] (because of the symmetry).
  3216. Then, for 0&nbsp;&lt;&nbsp;k&nbsp;&lt;&nbsp;d2 and 0&nbsp;&lt;=&nbsp;j&nbsp;&lt;=&nbsp;k+1,
  3217. <figure align="center">
  3218. <artwork align="center"><![CDATA[
  3219. p_Q16[k][j] = p_Q16[k-1][j] + p_Q16[k-1][j-2]
  3220. - ((c_Q17[2*k]*p_Q16[k-1][j-1] + 32768)>>16)
  3221. q_Q16[k][j] = q_Q16[k-1][j] + q_Q16[k-1][j-2]
  3222. - ((c_Q17[2*k+1]*q_Q16[k-1][j-1] + 32768)>>16)
  3223. ]]></artwork>
  3224. </figure>
  3225. The use of Q17 values for the cosine terms in an otherwise Q16 expression
  3226. implicitly scales them by a factor of 2.
  3227. The multiplications in this recurrence may require up to 48 bits of precision
  3228. in the result to avoid overflow.
  3229. In practice, each row of the recurrence only depends on the previous row, so an
  3230. implementation does not need to store all of them.
  3231. </t>
  3232. <t>
  3233. silk_NLSF2A() uses the values from the last row of this recurrence to
  3234. reconstruct a 32-bit version of the LPC filter (without the leading 1.0
  3235. coefficient), a32_Q17[k], 0&nbsp;&lt;=&nbsp;k&nbsp;&lt;&nbsp;d2:
  3236. <figure align="center">
  3237. <artwork align="center"><![CDATA[
  3238. a32_Q17[k] = -(q_Q16[d2-1][k+1] - q_Q16[d2-1][k])
  3239. - (p_Q16[d2-1][k+1] + p_Q16[d2-1][k]))
  3240. a32_Q17[d_LPC-k-1] = (q_Q16[d2-1][k+1] - q_Q16[d2-1][k])
  3241. - (p_Q16[d2-1][k+1] + p_Q16[d2-1][k]))
  3242. ]]></artwork>
  3243. </figure>
  3244. The sum and difference of two terms from each of the p_Q16 and q_Q16
  3245. coefficient lists reflect the (1&nbsp;+&nbsp;z**-1) and
  3246. (1&nbsp;-&nbsp;z**-1) factors of P and Q, respectively.
  3247. The promotion of the expression from Q16 to Q17 implicitly scales the result
  3248. by 1/2.
  3249. </t>
  3250. </section>
  3251. <section anchor="silk_lpc_range_limit"
  3252. title="Limiting the Range of the LPC Coefficients">
  3253. <t>
  3254. The a32_Q17[] coefficients are too large to fit in a 16-bit value, which
  3255. significantly increases the cost of applying this filter in fixed-point
  3256. decoders.
  3257. Reducing them to Q12 precision doesn't incur any significant quality loss,
  3258. but still does not guarantee they will fit.
  3259. silk_NLSF2A() applies up to 10 rounds of bandwidth expansion to limit
  3260. the dynamic range of these coefficients.
  3261. Even floating-point decoders SHOULD perform these steps, to avoid mismatch.
  3262. </t>
  3263. <t>
  3264. For each round, the process first finds the index k such that abs(a32_Q17[k])
  3265. is largest, breaking ties by choosing the lowest value of k.
  3266. Then, it computes the corresponding Q12 precision value, maxabs_Q12, subject to
  3267. an upper bound to avoid overflow in subsequent computations:
  3268. <figure align="center">
  3269. <artwork align="center"><![CDATA[
  3270. maxabs_Q12 = min((maxabs_Q17 + 16) >> 5, 163838)
  3271. ]]></artwork>
  3272. </figure>
  3273. If this is larger than 32767, the procedure derives the chirp factor,
  3274. sc_Q16[0], to use in the bandwidth expansion as
  3275. <figure align="center">
  3276. <artwork align="center"><![CDATA[
  3277. (maxabs_Q12 - 32767) << 14
  3278. sc_Q16[0] = 65470 - --------------------------
  3279. (maxabs_Q12 * (k+1)) >> 2
  3280. ]]></artwork>
  3281. </figure>
  3282. where the division here is integer division.
  3283. This is an approximation of the chirp factor needed to reduce the target
  3284. coefficient to 32767, though it is both less than 0.999 and, for
  3285. k&nbsp;&gt;&nbsp;0 when maxabs_Q12 is much greater than 32767, still slightly
  3286. too large.
  3287. The upper bound on maxabs_Q12, 163838, was chosen because it is equal to
  3288. ((2**31&nbsp;-&nbsp;1)&nbsp;&gt;&gt;&nbsp;14)&nbsp;+&nbsp;32767, i.e., the
  3289. largest value of maxabs_Q12 that would not overflow the numerator in the
  3290. equation above when stored in a signed 32-bit integer.
  3291. </t>
  3292. <t>
  3293. silk_bwexpander_32() (bwexpander_32.c) performs the bandwidth expansion (again,
  3294. only when maxabs_Q12 is greater than 32767) using the following recurrence:
  3295. <figure align="center">
  3296. <artwork align="center"><![CDATA[
  3297. a32_Q17[k] = (a32_Q17[k]*sc_Q16[k]) >> 16
  3298. sc_Q16[k+1] = (sc_Q16[0]*sc_Q16[k] + 32768) >> 16
  3299. ]]></artwork>
  3300. </figure>
  3301. The first multiply may require up to 48 bits of precision in the result to
  3302. avoid overflow.
  3303. The second multiply must be unsigned to avoid overflow with only 32 bits of
  3304. precision.
  3305. The reference implementation uses a slightly more complex formulation that
  3306. avoids the 32-bit overflow using signed multiplication, but is otherwise
  3307. equivalent.
  3308. </t>
  3309. <t>
  3310. After 10 rounds of bandwidth expansion are performed, they are simply saturated
  3311. to 16 bits:
  3312. <figure align="center">
  3313. <artwork align="center"><![CDATA[
  3314. a32_Q17[k] = clamp(-32768, (a32_Q17[k] + 16) >> 5, 32767) << 5
  3315. ]]></artwork>
  3316. </figure>
  3317. Because this performs the actual saturation in the Q12 domain, but converts the
  3318. coefficients back to the Q17 domain for the purposes of prediction gain
  3319. limiting, this step must be performed after the 10th round of bandwidth
  3320. expansion, regardless of whether or not the Q12 version of any coefficient
  3321. still overflows a 16-bit integer.
  3322. This saturation is not performed if maxabs_Q12 drops to 32767 or less prior to
  3323. the 10th round.
  3324. </t>
  3325. </section>
  3326. <section anchor="silk_lpc_gain_limit"
  3327. title="Limiting the Prediction Gain of the LPC Filter">
  3328. <t>
  3329. The prediction gain of an LPC synthesis filter is the square root of the output
  3330. energy when the filter is excited by a unit-energy impulse.
  3331. Even if the Q12 coefficients would fit, the resulting filter may still have a
  3332. significant gain (especially for voiced sounds), making the filter unstable.
  3333. silk_NLSF2A() applies up to 16 additional rounds of bandwidth expansion to
  3334. limit the prediction gain.
  3335. Instead of controlling the amount of bandwidth expansion using the prediction
  3336. gain itself (which may diverge to infinity for an unstable filter),
  3337. silk_NLSF2A() uses silk_LPC_inverse_pred_gain_QA() (LPC_inv_pred_gain.c) to
  3338. compute the reflection coefficients associated with the filter.
  3339. The filter is stable if and only if the magnitude of these coefficients is
  3340. sufficiently less than one.
  3341. The reflection coefficients, rc[k], can be computed using a simple Levinson
  3342. recurrence, initialized with the LPC coefficients
  3343. a[d_LPC-1][n]&nbsp;=&nbsp;a[n], and then updated via
  3344. <figure align="center">
  3345. <artwork align="center"><![CDATA[
  3346. rc[k] = -a[k][k] ,
  3347. a[k][n] - a[k][k-n-1]*rc[k]
  3348. a[k-1][n] = ---------------------------
  3349. 2
  3350. 1 - rc[k]
  3351. ]]></artwork>
  3352. </figure>
  3353. </t>
  3354. <t>
  3355. However, silk_LPC_inverse_pred_gain_QA() approximates this using fixed-point
  3356. arithmetic to guarantee reproducible results across platforms and
  3357. implementations.
  3358. Since small changes in the coefficients can make a stable filter unstable, it
  3359. takes the real Q12 coefficients that will be used during reconstruction as
  3360. input.
  3361. Thus, let
  3362. <figure align="center">
  3363. <artwork align="center"><![CDATA[
  3364. a32_Q12[n] = (a32_Q17[n] + 16) >> 5
  3365. ]]></artwork>
  3366. </figure>
  3367. be the Q12 version of the LPC coefficients that will eventually be used.
  3368. As a simple initial check, the decoder computes the DC response as
  3369. <figure align="center">
  3370. <artwork align="center"><![CDATA[
  3371. d_PLC-1
  3372. __
  3373. DC_resp = \ a32_Q12[n]
  3374. /_
  3375. n=0
  3376. ]]></artwork>
  3377. </figure>
  3378. and if DC_resp&nbsp;&gt;&nbsp;4096, the filter is unstable.
  3379. </t>
  3380. <t>
  3381. Increasing the precision of these Q12 coefficients to Q24 for intermediate
  3382. computations allows more accurate computation of the reflection coefficients,
  3383. so the decoder initializes the recurrence via
  3384. <figure align="center">
  3385. <artwork align="center"><![CDATA[
  3386. inv_gain_Q30[d_LPC] = 1 << 30
  3387. a32_Q24[d_LPC-1][n] = a32_Q12[n] << 12
  3388. ]]></artwork>
  3389. </figure>
  3390. Then, for each k from d_LPC-1 down to 0, if
  3391. abs(a32_Q24[k][k])&nbsp;&gt;&nbsp;16773022, the filter is unstable and the
  3392. recurrence stops.
  3393. The constant 16773022 here is approximately 0.99975 in Q24.
  3394. Otherwise, the inverse of the prediction gain, inv_gain_Q30[k], is updated via
  3395. <figure align="center">
  3396. <artwork align="center"><![CDATA[
  3397. rc_Q31[k] = -a32_Q24[k][k] << 7
  3398. div_Q30[k] = (1<<30) - (rc_Q31[k]*rc_Q31[k] >> 32)
  3399. inv_gain_Q30[k] = (inv_gain_Q30[k+1]*div_Q30[k] >> 32) << 2
  3400. ]]></artwork>
  3401. </figure>
  3402. and if inv_gain_Q30[k]&nbsp;&lt;&nbsp;107374, the filter is unstable and the
  3403. recurrence stops.
  3404. The constant 107374 here is approximately 1/10000 in Q30.
  3405. If neither of these checks determine that the filter is unstable and
  3406. k&nbsp;&gt;&nbsp;0, row k-1 of a32_Q24 is computed from row k as
  3407. <figure align="center">
  3408. <artwork align="center"><![CDATA[
  3409. b1[k] = ilog(div_Q30[k])
  3410. b2[k] = b1[k] - 16
  3411. (1<<29) - 1
  3412. inv_Qb2[k] = -----------------------
  3413. div_Q30[k] >> (b2[k]+1)
  3414. err_Q29[k] = (1<<29)
  3415. - ((div_Q30[k]<<(15-b2[k]))*inv_Qb2[k] >> 16)
  3416. gain_Qb1[k] = ((inv_Qb2[k] << 16)
  3417. + (err_Q29[k]*inv_Qb2[k] >> 13))
  3418. num_Q24[k-1][n] = a32_Q24[k][n]
  3419. - ((a32_Q24[k][k-n-1]*rc_Q31[k] + (1<<30)) >> 31)
  3420. a32_Q24[k-1][n] = (num_Q24[k-1][n]*gain_Qb1[k]
  3421. + (1<<(b1[k]-1))) >> b1[k]
  3422. ]]></artwork>
  3423. </figure>
  3424. where 0&nbsp;&lt;=&nbsp;n&nbsp;&lt;&nbsp;k.
  3425. In the above, rc_Q31[k] are the reflection coefficients.
  3426. div_Q30[k] is the denominator for each iteration, and gain_Qb1[k] is its
  3427. multiplicative inverse (with b1[k] fractional bits, where b1[k] ranges from
  3428. 20 to 31).
  3429. inv_Qb2[k], which ranges from 16384 to 32767, is a low-precision version of
  3430. that inverse (with b2[k] fractional bits).
  3431. err_Q29[k] is the residual error, ranging from -32763 to 32392, which is used
  3432. to improve the accuracy.
  3433. The values t_Q24[k-1][n] for each n are the numerators for the next row of
  3434. coefficients in the recursion, and a32_Q24[k-1][n] is the final version of
  3435. that row.
  3436. Every multiply in this procedure except the one used to compute gain_Qb1[k]
  3437. requires more than 32 bits of precision, but otherwise all intermediate
  3438. results fit in 32 bits or less.
  3439. In practice, because each row only depends on the next one, an implementation
  3440. does not need to store them all.
  3441. </t>
  3442. <t>
  3443. If abs(a32_Q24[k][k])&nbsp;&lt;=&nbsp;16773022 and
  3444. inv_gain_Q30[k]&nbsp;&gt;=&nbsp;107374 for
  3445. 0&nbsp;&lt;=&nbsp;k&nbsp;&lt;&nbsp;d_LPC, then the filter is considered
  3446. stable.
  3447. However, the problem of determining stability is ill-conditioned when the
  3448. filter contains several reflection coefficients whose magnitude is very close
  3449. to one.
  3450. This fixed-point algorithm is not mathematically guaranteed to correctly
  3451. classify filters as stable or unstable in this case, though it does very well
  3452. in practice.
  3453. </t>
  3454. <t>
  3455. On round i, 0&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;16, if the filter passes these
  3456. stability checks, then this procedure stops, and the final LPC coefficients to
  3457. use for reconstruction in <xref target="silk_lpc_synthesis"/> are
  3458. <figure align="center">
  3459. <artwork align="center"><![CDATA[
  3460. a_Q12[k] = (a32_Q17[k] + 16) >> 5
  3461. ]]></artwork>
  3462. </figure>
  3463. Otherwise, a round of bandwidth expansion is applied using the same procedure
  3464. as in <xref target="silk_lpc_range_limit"/>, with
  3465. <figure align="center">
  3466. <artwork align="center"><![CDATA[
  3467. sc_Q16[0] = 65536 - (2<<i)
  3468. ]]></artwork>
  3469. </figure>
  3470. During round 15, sc_Q16[0] becomes 0 in the above equation, so a_Q12[k]
  3471. is set to 0 for all k, guaranteeing a stable filter.
  3472. </t>
  3473. </section>
  3474. </section>
  3475. <section anchor="silk_ltp_params" toc="include"
  3476. title="Long-Term Prediction (LTP) Parameters">
  3477. <t>
  3478. After the normalized LSF indices and, for 20&nbsp;ms frames, the LSF
  3479. interpolation index, voiced frames (see <xref target="silk_frame_type"/>)
  3480. include additional LTP parameters.
  3481. There is one primary lag index for each SILK frame, but this is refined to
  3482. produce a separate lag index per subframe using a vector quantizer.
  3483. Each subframe also gets its own prediction gain coefficient.
  3484. </t>
  3485. <section anchor="silk_ltp_lags" title="Pitch Lags">
  3486. <t>
  3487. The primary lag index is coded either relative to the primary lag of the prior
  3488. frame in the same channel or as an absolute index.
  3489. Absolute coding is used if and only if
  3490. <list style="symbols">
  3491. <t>
  3492. This is the first SILK frame of its type (LBRR or regular) for this channel in
  3493. the current Opus frame,
  3494. </t>
  3495. <t>
  3496. The previous SILK frame of the same type (LBRR or regular) for this channel in
  3497. the same Opus frame was not coded, or
  3498. </t>
  3499. <t>
  3500. That previous SILK frame was coded, but was not voiced (see
  3501. <xref target="silk_frame_type"/>).
  3502. </t>
  3503. </list>
  3504. </t>
  3505. <t>
  3506. With absolute coding, the primary pitch lag may range from 2&nbsp;ms
  3507. (inclusive) up to 18&nbsp;ms (exclusive), corresponding to pitches from
  3508. 500&nbsp;Hz down to 55.6&nbsp;Hz, respectively.
  3509. It is comprised of a high part and a low part, where the decoder first reads
  3510. the high part using the 32-entry codebook in
  3511. <xref target="silk_abs_pitch_high_pdf"/> and then the low part using the
  3512. codebook corresponding to the current audio bandwidth from
  3513. <xref target="silk_abs_pitch_low_pdf"/>.
  3514. The final primary pitch lag is then
  3515. <figure align="center">
  3516. <artwork align="center"><![CDATA[
  3517. lag = lag_high*lag_scale + lag_low + lag_min
  3518. ]]></artwork>
  3519. </figure>
  3520. where lag_high is the high part, lag_low is the low part, and lag_scale
  3521. and lag_min are the values from the "Scale" and "Minimum Lag" columns of
  3522. <xref target="silk_abs_pitch_low_pdf"/>, respectively.
  3523. </t>
  3524. <?rfc compact="no" ?>
  3525. <texttable anchor="silk_abs_pitch_high_pdf"
  3526. title="PDF for High Part of Primary Pitch Lag">
  3527. <ttcol align="left">PDF</ttcol>
  3528. <c>{3, 3, 6, 11, 21, 30, 32, 19,
  3529. 11, 10, 12, 13, 13, 12, 11, 9,
  3530. 8, 7, 6, 4, 2, 2, 2, 1,
  3531. 1, 1, 1, 1, 1, 1, 1, 1}/256</c>
  3532. </texttable>
  3533. <?rfc compact="yes" ?>
  3534. <?rfc compact="no" ?>
  3535. <texttable anchor="silk_abs_pitch_low_pdf"
  3536. title="PDF for Low Part of Primary Pitch Lag">
  3537. <ttcol>Audio Bandwidth</ttcol>
  3538. <ttcol>PDF</ttcol>
  3539. <ttcol>Scale</ttcol>
  3540. <ttcol>Minimum Lag</ttcol>
  3541. <ttcol>Maximum Lag</ttcol>
  3542. <c>NB</c> <c>{64, 64, 64, 64}/256</c> <c>4</c> <c>16</c> <c>144</c>
  3543. <c>MB</c> <c>{43, 42, 43, 43, 42, 43}/256</c> <c>6</c> <c>24</c> <c>216</c>
  3544. <c>WB</c> <c>{32, 32, 32, 32, 32, 32, 32, 32}/256</c> <c>8</c> <c>32</c> <c>288</c>
  3545. </texttable>
  3546. <?rfc compact="yes" ?>
  3547. <t>
  3548. All frames that do not use absolute coding for the primary lag index use
  3549. relative coding instead.
  3550. The decoder reads a single delta value using the 21-entry PDF in
  3551. <xref target="silk_rel_pitch_pdf"/>.
  3552. If the resulting value is zero, it falls back to the absolute coding procedure
  3553. from the prior paragraph.
  3554. Otherwise, the final primary pitch lag is then
  3555. <figure align="center">
  3556. <artwork align="center"><![CDATA[
  3557. lag = previous_lag + (delta_lag_index - 9)
  3558. ]]></artwork>
  3559. </figure>
  3560. where previous_lag is the primary pitch lag from the most recent frame in the
  3561. same channel and delta_lag_index is the value just decoded.
  3562. This allows a per-frame change in the pitch lag of -8 to +11 samples.
  3563. The decoder does no clamping at this point, so this value can fall outside the
  3564. range of 2&nbsp;ms to 18&nbsp;ms, and the decoder must use this unclamped
  3565. value when using relative coding in the next SILK frame (if any).
  3566. However, because an Opus frame can use relative coding for at most two
  3567. consecutive SILK frames, integer overflow should not be an issue.
  3568. </t>
  3569. <?rfc compact="no" ?>
  3570. <texttable anchor="silk_rel_pitch_pdf"
  3571. title="PDF for Primary Pitch Lag Change">
  3572. <ttcol align="left">PDF</ttcol>
  3573. <c>{46, 2, 2, 3, 4, 6, 10, 15,
  3574. 26, 38, 30, 22, 15, 10, 7, 6,
  3575. 4, 4, 2, 2, 2}/256</c>
  3576. </texttable>
  3577. <?rfc compact="yes" ?>
  3578. <t>
  3579. After the primary pitch lag, a "pitch contour", stored as a single entry from
  3580. one of four small VQ codebooks, gives lag offsets for each subframe in the
  3581. current SILK frame.
  3582. The codebook index is decoded using one of the PDFs in
  3583. <xref target="silk_pitch_contour_pdfs"/> depending on the current frame size
  3584. and audio bandwidth.
  3585. Tables&nbsp;<xref format="counter" target="silk_pitch_contour_cb_nb10ms"/>
  3586. through&nbsp;<xref format="counter" target="silk_pitch_contour_cb_mbwb20ms"/>
  3587. give the corresponding offsets to apply to the primary pitch lag for each
  3588. subframe given the decoded codebook index.
  3589. </t>
  3590. <?rfc compact="no" ?>
  3591. <texttable anchor="silk_pitch_contour_pdfs"
  3592. title="PDFs for Subframe Pitch Contour">
  3593. <ttcol>Audio Bandwidth</ttcol>
  3594. <ttcol>SILK Frame Size</ttcol>
  3595. <ttcol align="right">Codebook Size</ttcol>
  3596. <ttcol>PDF</ttcol>
  3597. <c>NB</c> <c>10&nbsp;ms</c> <c>3</c>
  3598. <c>{143, 50, 63}/256</c>
  3599. <c>NB</c> <c>20&nbsp;ms</c> <c>11</c>
  3600. <c>{68, 12, 21, 17, 19, 22, 30, 24,
  3601. 17, 16, 10}/256</c>
  3602. <c>MB or WB</c> <c>10&nbsp;ms</c> <c>12</c>
  3603. <c>{91, 46, 39, 19, 14, 12, 8, 7,
  3604. 6, 5, 5, 4}/256</c>
  3605. <c>MB or WB</c> <c>20&nbsp;ms</c> <c>34</c>
  3606. <c>{33, 22, 18, 16, 15, 14, 14, 13,
  3607. 13, 10, 9, 9, 8, 6, 6, 6,
  3608. 5, 4, 4, 4, 3, 3, 3, 2,
  3609. 2, 2, 2, 2, 2, 2, 1, 1,
  3610. 1, 1}/256</c>
  3611. </texttable>
  3612. <?rfc compact="yes" ?>
  3613. <?rfc compact="no" ?>
  3614. <texttable anchor="silk_pitch_contour_cb_nb10ms"
  3615. title="Codebook Vectors for Subframe Pitch Contour: NB, 10&nbsp;ms Frames">
  3616. <ttcol>Index</ttcol>
  3617. <ttcol align="right">Subframe Offsets</ttcol>
  3618. <c>0</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;0</spanx></c>
  3619. <c>1</c> <c><spanx style="vbare">&nbsp;1&nbsp;&nbsp;0</spanx></c>
  3620. <c>2</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;1</spanx></c>
  3621. </texttable>
  3622. <?rfc compact="yes" ?>
  3623. <?rfc compact="no" ?>
  3624. <texttable anchor="silk_pitch_contour_cb_nb20ms"
  3625. title="Codebook Vectors for Subframe Pitch Contour: NB, 20&nbsp;ms Frames">
  3626. <ttcol>Index</ttcol>
  3627. <ttcol align="right">Subframe Offsets</ttcol>
  3628. <c>0</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0</spanx></c>
  3629. <c>1</c> <c><spanx style="vbare">&nbsp;2&nbsp;&nbsp;1&nbsp;&nbsp;0&nbsp;-1</spanx></c>
  3630. <c>2</c> <c><spanx style="vbare">-1&nbsp;&nbsp;0&nbsp;&nbsp;1&nbsp;&nbsp;2</spanx></c>
  3631. <c>3</c> <c><spanx style="vbare">-1&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;1</spanx></c>
  3632. <c>4</c> <c><spanx style="vbare">-1&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0</spanx></c>
  3633. <c>5</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;1</spanx></c>
  3634. <c>6</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;1&nbsp;&nbsp;1</spanx></c>
  3635. <c>7</c> <c><spanx style="vbare">&nbsp;1&nbsp;&nbsp;1&nbsp;&nbsp;0&nbsp;&nbsp;0</spanx></c>
  3636. <c>8</c> <c><spanx style="vbare">&nbsp;1&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0</spanx></c>
  3637. <c>9</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;-1</spanx></c>
  3638. <c>10</c> <c><spanx style="vbare">&nbsp;1&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;-1</spanx></c>
  3639. </texttable>
  3640. <?rfc compact="yes" ?>
  3641. <?rfc compact="no" ?>
  3642. <texttable anchor="silk_pitch_contour_cb_mbwb10ms"
  3643. title="Codebook Vectors for Subframe Pitch Contour: MB or WB, 10&nbsp;ms Frames">
  3644. <ttcol>Index</ttcol>
  3645. <ttcol align="right">Subframe Offsets</ttcol>
  3646. <c>0</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;0</spanx></c>
  3647. <c>1</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;1</spanx></c>
  3648. <c>2</c> <c><spanx style="vbare">&nbsp;1&nbsp;&nbsp;0</spanx></c>
  3649. <c>3</c> <c><spanx style="vbare">-1&nbsp;&nbsp;1</spanx></c>
  3650. <c>4</c> <c><spanx style="vbare">&nbsp;1&nbsp;-1</spanx></c>
  3651. <c>5</c> <c><spanx style="vbare">-1&nbsp;&nbsp;2</spanx></c>
  3652. <c>6</c> <c><spanx style="vbare">&nbsp;2&nbsp;-1</spanx></c>
  3653. <c>7</c> <c><spanx style="vbare">-2&nbsp;&nbsp;2</spanx></c>
  3654. <c>8</c> <c><spanx style="vbare">&nbsp;2&nbsp;-2</spanx></c>
  3655. <c>9</c> <c><spanx style="vbare">-2&nbsp;&nbsp;3</spanx></c>
  3656. <c>10</c> <c><spanx style="vbare">&nbsp;3&nbsp;-2</spanx></c>
  3657. <c>11</c> <c><spanx style="vbare">-3&nbsp;&nbsp;3</spanx></c>
  3658. </texttable>
  3659. <?rfc compact="yes" ?>
  3660. <?rfc compact="no" ?>
  3661. <texttable anchor="silk_pitch_contour_cb_mbwb20ms"
  3662. title="Codebook Vectors for Subframe Pitch Contour: MB or WB, 20&nbsp;ms Frames">
  3663. <ttcol>Index</ttcol>
  3664. <ttcol align="right">Subframe Offsets</ttcol>
  3665. <c>0</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0</spanx></c>
  3666. <c>1</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;1&nbsp;&nbsp;1</spanx></c>
  3667. <c>2</c> <c><spanx style="vbare">&nbsp;1&nbsp;&nbsp;1&nbsp;&nbsp;0&nbsp;&nbsp;0</spanx></c>
  3668. <c>3</c> <c><spanx style="vbare">-1&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0</spanx></c>
  3669. <c>4</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;1</spanx></c>
  3670. <c>5</c> <c><spanx style="vbare">&nbsp;1&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0</spanx></c>
  3671. <c>6</c> <c><spanx style="vbare">-1&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;1</spanx></c>
  3672. <c>7</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;-1</spanx></c>
  3673. <c>8</c> <c><spanx style="vbare">-1&nbsp;&nbsp;0&nbsp;&nbsp;1&nbsp;&nbsp;2</spanx></c>
  3674. <c>9</c> <c><spanx style="vbare">&nbsp;1&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;-1</spanx></c>
  3675. <c>10</c> <c><spanx style="vbare">-2&nbsp;-1&nbsp;&nbsp;1&nbsp;&nbsp;2</spanx></c>
  3676. <c>11</c> <c><spanx style="vbare">&nbsp;2&nbsp;&nbsp;1&nbsp;&nbsp;0&nbsp;-1</spanx></c>
  3677. <c>12</c> <c><spanx style="vbare">-2&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;2</spanx></c>
  3678. <c>13</c> <c><spanx style="vbare">-2&nbsp;&nbsp;0&nbsp;&nbsp;1&nbsp;&nbsp;3</spanx></c>
  3679. <c>14</c> <c><spanx style="vbare">&nbsp;2&nbsp;&nbsp;1&nbsp;-1&nbsp;-2</spanx></c>
  3680. <c>15</c> <c><spanx style="vbare">-3&nbsp;-1&nbsp;&nbsp;1&nbsp;&nbsp;3</spanx></c>
  3681. <c>16</c> <c><spanx style="vbare">&nbsp;2&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;-2</spanx></c>
  3682. <c>17</c> <c><spanx style="vbare">&nbsp;3&nbsp;&nbsp;1&nbsp;&nbsp;0&nbsp;-2</spanx></c>
  3683. <c>18</c> <c><spanx style="vbare">-3&nbsp;-1&nbsp;&nbsp;2&nbsp;&nbsp;4</spanx></c>
  3684. <c>19</c> <c><spanx style="vbare">-4&nbsp;-1&nbsp;&nbsp;1&nbsp;&nbsp;4</spanx></c>
  3685. <c>20</c> <c><spanx style="vbare">&nbsp;3&nbsp;&nbsp;1&nbsp;-1&nbsp;-3</spanx></c>
  3686. <c>21</c> <c><spanx style="vbare">-4&nbsp;-1&nbsp;&nbsp;2&nbsp;&nbsp;5</spanx></c>
  3687. <c>22</c> <c><spanx style="vbare">&nbsp;4&nbsp;&nbsp;2&nbsp;-1&nbsp;-3</spanx></c>
  3688. <c>23</c> <c><spanx style="vbare">&nbsp;4&nbsp;&nbsp;1&nbsp;-1&nbsp;-4</spanx></c>
  3689. <c>24</c> <c><spanx style="vbare">-5&nbsp;-1&nbsp;&nbsp;2&nbsp;&nbsp;6</spanx></c>
  3690. <c>25</c> <c><spanx style="vbare">&nbsp;5&nbsp;&nbsp;2&nbsp;-1&nbsp;-4</spanx></c>
  3691. <c>26</c> <c><spanx style="vbare">-6&nbsp;-2&nbsp;&nbsp;2&nbsp;&nbsp;6</spanx></c>
  3692. <c>27</c> <c><spanx style="vbare">-5&nbsp;-2&nbsp;&nbsp;2&nbsp;&nbsp;5</spanx></c>
  3693. <c>28</c> <c><spanx style="vbare">&nbsp;6&nbsp;&nbsp;2&nbsp;-1&nbsp;-5</spanx></c>
  3694. <c>29</c> <c><spanx style="vbare">-7&nbsp;-2&nbsp;&nbsp;3&nbsp;&nbsp;8</spanx></c>
  3695. <c>30</c> <c><spanx style="vbare">&nbsp;6&nbsp;&nbsp;2&nbsp;-2&nbsp;-6</spanx></c>
  3696. <c>31</c> <c><spanx style="vbare">&nbsp;5&nbsp;&nbsp;2&nbsp;-2&nbsp;-5</spanx></c>
  3697. <c>32</c> <c><spanx style="vbare">&nbsp;8&nbsp;&nbsp;3&nbsp;-2&nbsp;-7</spanx></c>
  3698. <c>33</c> <c><spanx style="vbare">-9&nbsp;-3&nbsp;&nbsp;3&nbsp;&nbsp;9</spanx></c>
  3699. </texttable>
  3700. <?rfc compact="yes" ?>
  3701. <t>
  3702. The final pitch lag for each subframe is assembled in silk_decode_pitch()
  3703. (decode_pitch.c).
  3704. Let lag be the primary pitch lag for the current SILK frame, contour_index be
  3705. index of the VQ codebook, and lag_cb[contour_index][k] be the corresponding
  3706. entry of the codebook from the appropriate table given above for the k'th
  3707. subframe.
  3708. Then the final pitch lag for that subframe is
  3709. <figure align="center">
  3710. <artwork align="center"><![CDATA[
  3711. pitch_lags[k] = clamp(lag_min, lag + lag_cb[contour_index][k],
  3712. lag_max)
  3713. ]]></artwork>
  3714. </figure>
  3715. where lag_min and lag_max are the values from the "Minimum Lag" and
  3716. "Maximum Lag" columns of <xref target="silk_abs_pitch_low_pdf"/>,
  3717. respectively.
  3718. </t>
  3719. </section>
  3720. <section anchor="silk_ltp_filter" title="LTP Filter Coefficients">
  3721. <t>
  3722. SILK uses a separate 5-tap pitch filter for each subframe, selected from one
  3723. of three codebooks.
  3724. The three codebooks each represent different rate-distortion trade-offs, with
  3725. average rates of 1.61&nbsp;bits/subframe, 3.68&nbsp;bits/subframe, and
  3726. 4.85&nbsp;bits/subframe, respectively.
  3727. </t>
  3728. <t>
  3729. The importance of the filter coefficients generally depends on two factors: the
  3730. periodicity of the signal and relative energy between the current subframe and
  3731. the signal from one period earlier.
  3732. Greater periodicity and decaying energy both lead to more important filter
  3733. coefficients.
  3734. Thus, they should be coded with lower distortion and higher rate.
  3735. These properties are relatively stable over the duration of a single SILK
  3736. frame.
  3737. Hence, all of the subframes in a SILK frame choose their filter from the same
  3738. codebook.
  3739. This is signaled with an explicitly-coded "periodicity index".
  3740. This immediately follows the subframe pitch lags, and is coded using the
  3741. 3-entry PDF from <xref target="silk_perindex_pdf"/>.
  3742. </t>
  3743. <?rfc compact="no" ?>
  3744. <texttable anchor="silk_perindex_pdf" title="Periodicity Index PDF">
  3745. <ttcol>PDF</ttcol>
  3746. <c>{77, 80, 99}/256</c>
  3747. </texttable>
  3748. <?rfc compact="yes" ?>
  3749. <t>
  3750. The indices of the filters for each subframe follow.
  3751. They are all coded using the PDF from <xref target="silk_ltp_filter_pdfs"/>
  3752. corresponding to the periodicity index.
  3753. Tables&nbsp;<xref format="counter" target="silk_ltp_filter_coeffs0"/>
  3754. through&nbsp;<xref format="counter" target="silk_ltp_filter_coeffs2"/>
  3755. contain the corresponding filter taps as signed Q7 integers.
  3756. </t>
  3757. <?rfc compact="no" ?>
  3758. <texttable anchor="silk_ltp_filter_pdfs" title="LTP Filter PDFs">
  3759. <ttcol>Periodicity Index</ttcol>
  3760. <ttcol align="right">Codebook Size</ttcol>
  3761. <ttcol>PDF</ttcol>
  3762. <c>0</c> <c>8</c> <c>{185, 15, 13, 13, 9, 9, 6, 6}/256</c>
  3763. <c>1</c> <c>16</c> <c>{57, 34, 21, 20, 15, 13, 12, 13,
  3764. 10, 10, 9, 10, 9, 8, 7, 8}/256</c>
  3765. <c>2</c> <c>32</c> <c>{15, 16, 14, 12, 12, 12, 11, 11,
  3766. 11, 10, 9, 9, 9, 9, 8, 8,
  3767. 8, 8, 7, 7, 6, 6, 5, 4,
  3768. 5, 4, 4, 4, 3, 4, 3, 2}/256</c>
  3769. </texttable>
  3770. <?rfc compact="yes" ?>
  3771. <?rfc compact="no" ?>
  3772. <texttable anchor="silk_ltp_filter_coeffs0"
  3773. title="Codebook Vectors for LTP Filter, Periodicity Index 0">
  3774. <ttcol>Index</ttcol>
  3775. <ttcol align="right">Filter Taps (Q7)</ttcol>
  3776. <c>0</c>
  3777. <c><spanx style="vbare">&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;6&nbsp;&nbsp;24&nbsp;&nbsp;&nbsp;7&nbsp;&nbsp;&nbsp;5</spanx></c>
  3778. <c>1</c>
  3779. <c><spanx style="vbare">&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;0</spanx></c>
  3780. <c>2</c>
  3781. <c><spanx style="vbare">&nbsp;12&nbsp;&nbsp;28&nbsp;&nbsp;41&nbsp;&nbsp;13&nbsp;&nbsp;-4</spanx></c>
  3782. <c>3</c>
  3783. <c><spanx style="vbare">&nbsp;-9&nbsp;&nbsp;15&nbsp;&nbsp;42&nbsp;&nbsp;25&nbsp;&nbsp;14</spanx></c>
  3784. <c>4</c>
  3785. <c><spanx style="vbare">&nbsp;&nbsp;1&nbsp;&nbsp;-2&nbsp;&nbsp;62&nbsp;&nbsp;41&nbsp;&nbsp;-9</spanx></c>
  3786. <c>5</c>
  3787. <c><spanx style="vbare">-10&nbsp;&nbsp;37&nbsp;&nbsp;65&nbsp;&nbsp;-4&nbsp;&nbsp;&nbsp;3</spanx></c>
  3788. <c>6</c>
  3789. <c><spanx style="vbare">&nbsp;-6&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;66&nbsp;&nbsp;&nbsp;7&nbsp;&nbsp;-8</spanx></c>
  3790. <c>7</c>
  3791. <c><spanx style="vbare">&nbsp;16&nbsp;&nbsp;14&nbsp;&nbsp;38&nbsp;&nbsp;-3&nbsp;&nbsp;33</spanx></c>
  3792. </texttable>
  3793. <?rfc compact="yes" ?>
  3794. <?rfc compact="no" ?>
  3795. <texttable anchor="silk_ltp_filter_coeffs1"
  3796. title="Codebook Vectors for LTP Filter, Periodicity Index 1">
  3797. <ttcol>Index</ttcol>
  3798. <ttcol align="right">Filter Taps (Q7)</ttcol>
  3799. <c>0</c>
  3800. <c><spanx style="vbare">&nbsp;13&nbsp;&nbsp;22&nbsp;&nbsp;39&nbsp;&nbsp;23&nbsp;&nbsp;12</spanx></c>
  3801. <c>1</c>
  3802. <c><spanx style="vbare">&nbsp;-1&nbsp;&nbsp;36&nbsp;&nbsp;64&nbsp;&nbsp;27&nbsp;&nbsp;-6</spanx></c>
  3803. <c>2</c>
  3804. <c><spanx style="vbare">&nbsp;-7&nbsp;&nbsp;10&nbsp;&nbsp;55&nbsp;&nbsp;43&nbsp;&nbsp;17</spanx></c>
  3805. <c>3</c>
  3806. <c><spanx style="vbare">&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;8&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;1</spanx></c>
  3807. <c>4</c>
  3808. <c><spanx style="vbare">&nbsp;&nbsp;6&nbsp;-11&nbsp;&nbsp;74&nbsp;&nbsp;53&nbsp;&nbsp;-9</spanx></c>
  3809. <c>5</c>
  3810. <c><spanx style="vbare">-12&nbsp;&nbsp;55&nbsp;&nbsp;76&nbsp;-12&nbsp;&nbsp;&nbsp;8</spanx></c>
  3811. <c>6</c>
  3812. <c><spanx style="vbare">&nbsp;-3&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;93&nbsp;&nbsp;27&nbsp;&nbsp;-4</spanx></c>
  3813. <c>7</c>
  3814. <c><spanx style="vbare">&nbsp;26&nbsp;&nbsp;39&nbsp;&nbsp;59&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;-8</spanx></c>
  3815. <c>8</c>
  3816. <c><spanx style="vbare">&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;77&nbsp;&nbsp;11&nbsp;&nbsp;&nbsp;9</spanx></c>
  3817. <c>9</c>
  3818. <c><spanx style="vbare">&nbsp;-8&nbsp;&nbsp;22&nbsp;&nbsp;44&nbsp;&nbsp;-6&nbsp;&nbsp;&nbsp;7</spanx></c>
  3819. <c>10</c>
  3820. <c><spanx style="vbare">&nbsp;40&nbsp;&nbsp;&nbsp;9&nbsp;&nbsp;26&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;9</spanx></c>
  3821. <c>11</c>
  3822. <c><spanx style="vbare">&nbsp;-7&nbsp;&nbsp;20&nbsp;101&nbsp;&nbsp;-7&nbsp;&nbsp;&nbsp;4</spanx></c>
  3823. <c>12</c>
  3824. <c><spanx style="vbare">&nbsp;&nbsp;3&nbsp;&nbsp;-8&nbsp;&nbsp;42&nbsp;&nbsp;26&nbsp;&nbsp;&nbsp;0</spanx></c>
  3825. <c>13</c>
  3826. <c><spanx style="vbare">-15&nbsp;&nbsp;33&nbsp;&nbsp;68&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;23</spanx></c>
  3827. <c>14</c>
  3828. <c><spanx style="vbare">&nbsp;-2&nbsp;&nbsp;55&nbsp;&nbsp;46&nbsp;&nbsp;-2&nbsp;&nbsp;15</spanx></c>
  3829. <c>15</c>
  3830. <c><spanx style="vbare">&nbsp;&nbsp;3&nbsp;&nbsp;-1&nbsp;&nbsp;21&nbsp;&nbsp;16&nbsp;&nbsp;41</spanx></c>
  3831. </texttable>
  3832. <?rfc compact="yes" ?>
  3833. <?rfc compact="no" ?>
  3834. <texttable anchor="silk_ltp_filter_coeffs2"
  3835. title="Codebook Vectors for LTP Filter, Periodicity Index 2">
  3836. <ttcol>Index</ttcol>
  3837. <ttcol align="right">Filter Taps (Q7)</ttcol>
  3838. <c>0</c>
  3839. <c><spanx style="vbare">&nbsp;-6&nbsp;&nbsp;27&nbsp;&nbsp;61&nbsp;&nbsp;39&nbsp;&nbsp;&nbsp;5</spanx></c>
  3840. <c>1</c>
  3841. <c><spanx style="vbare">-11&nbsp;&nbsp;42&nbsp;&nbsp;88&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;1</spanx></c>
  3842. <c>2</c>
  3843. <c><spanx style="vbare">&nbsp;-2&nbsp;&nbsp;60&nbsp;&nbsp;65&nbsp;&nbsp;&nbsp;6&nbsp;&nbsp;-4</spanx></c>
  3844. <c>3</c>
  3845. <c><spanx style="vbare">&nbsp;-1&nbsp;&nbsp;-5&nbsp;&nbsp;73&nbsp;&nbsp;56&nbsp;&nbsp;&nbsp;1</spanx></c>
  3846. <c>4</c>
  3847. <c><spanx style="vbare">&nbsp;-9&nbsp;&nbsp;19&nbsp;&nbsp;94&nbsp;&nbsp;29&nbsp;&nbsp;-9</spanx></c>
  3848. <c>5</c>
  3849. <c><spanx style="vbare">&nbsp;&nbsp;0&nbsp;&nbsp;12&nbsp;&nbsp;99&nbsp;&nbsp;&nbsp;6&nbsp;&nbsp;&nbsp;4</spanx></c>
  3850. <c>6</c>
  3851. <c><spanx style="vbare">&nbsp;&nbsp;8&nbsp;-19&nbsp;102&nbsp;&nbsp;46&nbsp;-13</spanx></c>
  3852. <c>7</c>
  3853. <c><spanx style="vbare">&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;13&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;2</spanx></c>
  3854. <c>8</c>
  3855. <c><spanx style="vbare">&nbsp;&nbsp;9&nbsp;-21&nbsp;&nbsp;84&nbsp;&nbsp;72&nbsp;-18</spanx></c>
  3856. <c>9</c>
  3857. <c><spanx style="vbare">-11&nbsp;&nbsp;46&nbsp;104&nbsp;-22&nbsp;&nbsp;&nbsp;8</spanx></c>
  3858. <c>10</c>
  3859. <c><spanx style="vbare">&nbsp;18&nbsp;&nbsp;38&nbsp;&nbsp;48&nbsp;&nbsp;23&nbsp;&nbsp;&nbsp;0</spanx></c>
  3860. <c>11</c>
  3861. <c><spanx style="vbare">-16&nbsp;&nbsp;70&nbsp;&nbsp;83&nbsp;-21&nbsp;&nbsp;11</spanx></c>
  3862. <c>12</c>
  3863. <c><spanx style="vbare">&nbsp;&nbsp;5&nbsp;-11&nbsp;117&nbsp;&nbsp;22&nbsp;&nbsp;-8</spanx></c>
  3864. <c>13</c>
  3865. <c><spanx style="vbare">&nbsp;-6&nbsp;&nbsp;23&nbsp;117&nbsp;-12&nbsp;&nbsp;&nbsp;3</spanx></c>
  3866. <c>14</c>
  3867. <c><spanx style="vbare">&nbsp;&nbsp;3&nbsp;&nbsp;-8&nbsp;&nbsp;95&nbsp;&nbsp;28&nbsp;&nbsp;&nbsp;4</spanx></c>
  3868. <c>15</c>
  3869. <c><spanx style="vbare">-10&nbsp;&nbsp;15&nbsp;&nbsp;77&nbsp;&nbsp;60&nbsp;-15</spanx></c>
  3870. <c>16</c>
  3871. <c><spanx style="vbare">&nbsp;-1&nbsp;&nbsp;&nbsp;4&nbsp;124&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;-4</spanx></c>
  3872. <c>17</c>
  3873. <c><spanx style="vbare">&nbsp;&nbsp;3&nbsp;&nbsp;38&nbsp;&nbsp;84&nbsp;&nbsp;24&nbsp;-25</spanx></c>
  3874. <c>18</c>
  3875. <c><spanx style="vbare">&nbsp;&nbsp;2&nbsp;&nbsp;13&nbsp;&nbsp;42&nbsp;&nbsp;13&nbsp;&nbsp;31</spanx></c>
  3876. <c>19</c>
  3877. <c><spanx style="vbare">&nbsp;21&nbsp;&nbsp;-4&nbsp;&nbsp;56&nbsp;&nbsp;46&nbsp;&nbsp;-1</spanx></c>
  3878. <c>20</c>
  3879. <c><spanx style="vbare">&nbsp;-1&nbsp;&nbsp;35&nbsp;&nbsp;79&nbsp;-13&nbsp;&nbsp;19</spanx></c>
  3880. <c>21</c>
  3881. <c><spanx style="vbare">&nbsp;-7&nbsp;&nbsp;65&nbsp;&nbsp;88&nbsp;&nbsp;-9&nbsp;-14</spanx></c>
  3882. <c>22</c>
  3883. <c><spanx style="vbare">&nbsp;20&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;81&nbsp;&nbsp;49&nbsp;-29</spanx></c>
  3884. <c>23</c>
  3885. <c><spanx style="vbare">&nbsp;20&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;75&nbsp;&nbsp;&nbsp;3&nbsp;-17</spanx></c>
  3886. <c>24</c>
  3887. <c><spanx style="vbare">&nbsp;&nbsp;5&nbsp;&nbsp;-9&nbsp;&nbsp;44&nbsp;&nbsp;92&nbsp;&nbsp;-8</spanx></c>
  3888. <c>25</c>
  3889. <c><spanx style="vbare">&nbsp;&nbsp;1&nbsp;&nbsp;-3&nbsp;&nbsp;22&nbsp;&nbsp;69&nbsp;&nbsp;31</spanx></c>
  3890. <c>26</c>
  3891. <c><spanx style="vbare">&nbsp;-6&nbsp;&nbsp;95&nbsp;&nbsp;41&nbsp;-12&nbsp;&nbsp;&nbsp;5</spanx></c>
  3892. <c>27</c>
  3893. <c><spanx style="vbare">&nbsp;39&nbsp;&nbsp;67&nbsp;&nbsp;16&nbsp;&nbsp;-4&nbsp;&nbsp;&nbsp;1</spanx></c>
  3894. <c>28</c>
  3895. <c><spanx style="vbare">&nbsp;&nbsp;0&nbsp;&nbsp;-6&nbsp;120&nbsp;&nbsp;55&nbsp;-36</spanx></c>
  3896. <c>29</c>
  3897. <c><spanx style="vbare">-13&nbsp;&nbsp;44&nbsp;122&nbsp;&nbsp;&nbsp;4&nbsp;-24</spanx></c>
  3898. <c>30</c>
  3899. <c><spanx style="vbare">&nbsp;81&nbsp;&nbsp;&nbsp;5&nbsp;&nbsp;11&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;7</spanx></c>
  3900. <c>31</c>
  3901. <c><spanx style="vbare">&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;9&nbsp;&nbsp;10&nbsp;&nbsp;88</spanx></c>
  3902. </texttable>
  3903. <?rfc compact="yes" ?>
  3904. </section>
  3905. <section anchor="silk_ltp_scaling" title="LTP Scaling Parameter">
  3906. <t>
  3907. An LTP scaling parameter appears after the LTP filter coefficients if and only
  3908. if
  3909. <list style="symbols">
  3910. <t>This is a voiced frame (see <xref target="silk_frame_type"/>), and</t>
  3911. <t>Either
  3912. <list style="symbols">
  3913. <t>
  3914. This SILK frame corresponds to the first time interval of the
  3915. current Opus frame for its type (LBRR or regular), or
  3916. </t>
  3917. <t>
  3918. This is an LBRR frame where the LBRR flags (see
  3919. <xref target="silk_lbrr_flags"/>) indicate the previous LBRR frame in the same
  3920. channel is not coded.
  3921. </t>
  3922. </list>
  3923. </t>
  3924. </list>
  3925. This allows the encoder to trade off the prediction gain between
  3926. packets against the recovery time after packet loss.
  3927. Unlike absolute-coding for pitch lags, regular SILK frames that are not at the
  3928. start of an Opus frame (i.e., that do not correspond to the first 20&nbsp;ms
  3929. time interval in Opus frames of 40&nbsp;or 60&nbsp;ms) do not include this
  3930. field, even if the prior frame was not voiced, or (in the case of the side
  3931. channel) not even coded.
  3932. After an uncoded frame in the side channel, the LTP buffer (see
  3933. <xref target="silk_ltp_synthesis"/>) is cleared to zero, and is thus in a
  3934. known state.
  3935. In contrast, LBRR frames do include this field when the prior frame was not
  3936. coded, since the LTP buffer contains the output of the PLC, which is
  3937. non-normative.
  3938. </t>
  3939. <t>
  3940. If present, the decoder reads a value using the 3-entry PDF in
  3941. <xref target="silk_ltp_scaling_pdf"/>.
  3942. The three possible values represent Q14 scale factors of 15565, 12288, and
  3943. 8192, respectively (corresponding to approximately 0.95, 0.75, and 0.5).
  3944. Frames that do not code the scaling parameter use the default factor of 15565
  3945. (approximately 0.95).
  3946. </t>
  3947. <?rfc compact="no" ?>
  3948. <texttable anchor="silk_ltp_scaling_pdf"
  3949. title="PDF for LTP Scaling Parameter">
  3950. <ttcol align="left">PDF</ttcol>
  3951. <c>{128, 64, 64}/256</c>
  3952. </texttable>
  3953. <?rfc compact="yes" ?>
  3954. </section>
  3955. </section>
  3956. <section anchor="silk_seed" toc="include"
  3957. title="Linear Congruential Generator (LCG) Seed">
  3958. <t>
  3959. As described in <xref target="silk_excitation_reconstruction"/>, SILK uses a
  3960. Linear Congruential Generator (LCG) to inject pseudorandom noise into the
  3961. quantized excitation.
  3962. To ensure synchronization of this process between the encoder and decoder, each
  3963. SILK frame stores a 2-bit seed after the LTP parameters (if any).
  3964. The encoder may consider the choice of seed during quantization, and the
  3965. flexibility of this choice lets it reduce distortion, helping to pay for the
  3966. bit cost required to signal it.
  3967. The decoder reads the seed using the uniform 4-entry PDF in
  3968. <xref target="silk_seed_pdf"/>, yielding a value between 0 and 3, inclusive.
  3969. </t>
  3970. <?rfc compact="no" ?>
  3971. <texttable anchor="silk_seed_pdf"
  3972. title="PDF for LCG Seed">
  3973. <ttcol align="left">PDF</ttcol>
  3974. <c>{64, 64, 64, 64}/256</c>
  3975. </texttable>
  3976. <?rfc compact="yes" ?>
  3977. </section>
  3978. <section anchor="silk_excitation" toc="include" title="Excitation">
  3979. <t>
  3980. SILK codes the excitation using a modified version of the Pyramid Vector
  3981. Quantizer (PVQ) codebook <xref target="PVQ"/>.
  3982. The PVQ codebook is designed for Laplace-distributed values and consists of all
  3983. sums of K signed, unit pulses in a vector of dimension N, where two pulses at
  3984. the same position are required to have the same sign.
  3985. Thus, the codebook includes all integer codevectors y of dimension N that
  3986. satisfy
  3987. <figure align="center">
  3988. <artwork align="center"><![CDATA[
  3989. N-1
  3990. __
  3991. \ abs(y[j]) = K
  3992. /_
  3993. j=0
  3994. ]]></artwork>
  3995. </figure>
  3996. Unlike regular PVQ, SILK uses a variable-length, rather than fixed-length,
  3997. encoding.
  3998. This encoding is better suited to the more Gaussian-like distribution of the
  3999. coefficient magnitudes and the non-uniform distribution of their signs (caused
  4000. by the quantization offset described below).
  4001. SILK also handles large codebooks by coding the least significant bits (LSBs)
  4002. of each coefficient directly.
  4003. This adds a small coding efficiency loss, but greatly reduces the computation
  4004. time and ROM size required for decoding, as implemented in
  4005. silk_decode_pulses() (decode_pulses.c).
  4006. </t>
  4007. <t>
  4008. SILK fixes the dimension of the codebook to N&nbsp;=&nbsp;16.
  4009. The excitation is made up of a number of "shell blocks", each 16 samples in
  4010. size.
  4011. <xref target="silk_shell_block_table"/> lists the number of shell blocks
  4012. required for a SILK frame for each possible audio bandwidth and frame size.
  4013. 10&nbsp;ms MB frames nominally contain 120&nbsp;samples (10&nbsp;ms at
  4014. 12&nbsp;kHz), which is not a multiple of 16.
  4015. This is handled by coding 8 shell blocks (128 samples) and discarding the final
  4016. 8 samples of the last block.
  4017. The decoder contains no special case that prevents an encoder from placing
  4018. pulses in these samples, and they must be correctly parsed from the bitstream
  4019. if present, but they are otherwise ignored.
  4020. </t>
  4021. <?rfc compact="no" ?>
  4022. <texttable anchor="silk_shell_block_table"
  4023. title="Number of Shell Blocks Per SILK Frame">
  4024. <ttcol>Audio Bandwidth</ttcol>
  4025. <ttcol>Frame Size</ttcol>
  4026. <ttcol align="right">Number of Shell Blocks</ttcol>
  4027. <c>NB</c> <c>10&nbsp;ms</c> <c>5</c>
  4028. <c>MB</c> <c>10&nbsp;ms</c> <c>8</c>
  4029. <c>WB</c> <c>10&nbsp;ms</c> <c>10</c>
  4030. <c>NB</c> <c>20&nbsp;ms</c> <c>10</c>
  4031. <c>MB</c> <c>20&nbsp;ms</c> <c>15</c>
  4032. <c>WB</c> <c>20&nbsp;ms</c> <c>20</c>
  4033. </texttable>
  4034. <?rfc compact="yes" ?>
  4035. <section anchor="silk_rate_level" title="Rate Level">
  4036. <t>
  4037. The first symbol in the excitation is a "rate level", which is an index from 0
  4038. to 8, inclusive, coded using the PDF in <xref target="silk_rate_level_pdfs"/>
  4039. corresponding to the signal type of the current frame (from
  4040. <xref target="silk_frame_type"/>).
  4041. The rate level selects the PDF used to decode the number of pulses in
  4042. the individual shell blocks.
  4043. It does not directly convey any information about the bitrate or the number of
  4044. pulses itself, but merely changes the probability of the symbols in
  4045. <xref target="silk_pulse_counts"/>.
  4046. Level&nbsp;0 provides a more efficient encoding at low rates generally, and
  4047. level&nbsp;8 provides a more efficient encoding at high rates generally,
  4048. though the most efficient level for a particular SILK frame may depend on the
  4049. exact distribution of the coded symbols.
  4050. An encoder should, but is not required to, use the most efficient rate level.
  4051. </t>
  4052. <?rfc compact="no" ?>
  4053. <texttable anchor="silk_rate_level_pdfs"
  4054. title="PDFs for the Rate Level">
  4055. <ttcol>Signal Type</ttcol>
  4056. <ttcol>PDF</ttcol>
  4057. <c>Inactive or Unvoiced</c>
  4058. <c>{15, 51, 12, 46, 45, 13, 33, 27, 14}/256</c>
  4059. <c>Voiced</c>
  4060. <c>{33, 30, 36, 17, 34, 49, 18, 21, 18}/256</c>
  4061. </texttable>
  4062. <?rfc compact="yes" ?>
  4063. </section>
  4064. <section anchor="silk_pulse_counts" title="Pulses Per Shell Block">
  4065. <t>
  4066. The total number of pulses in each of the shell blocks follows the rate level.
  4067. The pulse counts for all of the shell blocks are coded consecutively, before
  4068. the content of any of the blocks.
  4069. Each block may have anywhere from 0 to 16 pulses, inclusive, coded using the
  4070. 18-entry PDF in <xref target="silk_pulse_count_pdfs"/> corresponding to the
  4071. rate level from <xref target="silk_rate_level"/>.
  4072. The special value 17 indicates that this block has one or more additional
  4073. LSBs to decode for each coefficient.
  4074. If the decoder encounters this value, it decodes another value for the actual
  4075. pulse count of the block, but uses the PDF corresponding to the special rate
  4076. level&nbsp;9 instead of the normal rate level.
  4077. This process repeats until the decoder reads a value less than 17, and it then
  4078. sets the number of extra LSBs used to the number of 17's decoded for that
  4079. block.
  4080. If it reads the value 17 ten times, then the next iteration uses the special
  4081. rate level&nbsp;10 instead of 9.
  4082. The probability of decoding a 17 when using the PDF for rate level&nbsp;10 is
  4083. zero, ensuring that the number of LSBs for a block will not exceed 10.
  4084. The cumulative distribution for rate level&nbsp;10 is just a shifted version of
  4085. that for 9 and thus does not require any additional storage.
  4086. </t>
  4087. <?rfc compact="no" ?>
  4088. <texttable anchor="silk_pulse_count_pdfs"
  4089. title="PDFs for the Pulse Count">
  4090. <ttcol>Rate Level</ttcol>
  4091. <ttcol>PDF</ttcol>
  4092. <c>0</c>
  4093. <c>{131, 74, 25, 8, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}/256</c>
  4094. <c>1</c>
  4095. <c>{58, 93, 60, 23, 7, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}/256</c>
  4096. <c>2</c>
  4097. <c>{43, 51, 46, 33, 24, 16, 11, 8, 6, 3, 3, 3, 2, 1, 1, 2, 1, 2}/256</c>
  4098. <c>3</c>
  4099. <c>{17, 52, 71, 57, 31, 12, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}/256</c>
  4100. <c>4</c>
  4101. <c>{6, 21, 41, 53, 49, 35, 21, 11, 6, 3, 2, 2, 1, 1, 1, 1, 1, 1}/256</c>
  4102. <c>5</c>
  4103. <c>{7, 14, 22, 28, 29, 28, 25, 20, 17, 13, 11, 9, 7, 5, 4, 4, 3, 10}/256</c>
  4104. <c>6</c>
  4105. <c>{2, 5, 14, 29, 42, 46, 41, 31, 19, 11, 6, 3, 2, 1, 1, 1, 1, 1}/256</c>
  4106. <c>7</c>
  4107. <c>{1, 2, 4, 10, 19, 29, 35, 37, 34, 28, 20, 14, 8, 5, 4, 2, 2, 2}/256</c>
  4108. <c>8</c>
  4109. <c>{1, 2, 2, 5, 9, 14, 20, 24, 27, 28, 26, 23, 20, 15, 11, 8, 6, 15}/256</c>
  4110. <c>9</c>
  4111. <c>{1, 1, 1, 6, 27, 58, 56, 39, 25, 14, 10, 6, 3, 3, 2, 1, 1, 2}/256</c>
  4112. <c>10</c>
  4113. <c>{2, 1, 6, 27, 58, 56, 39, 25, 14, 10, 6, 3, 3, 2, 1, 1, 2, 0}/256</c>
  4114. </texttable>
  4115. <?rfc compact="yes" ?>
  4116. </section>
  4117. <section anchor="silk_pulse_locations" title="Pulse Location Decoding">
  4118. <t>
  4119. The locations of the pulses in each shell block follow the pulse counts,
  4120. as decoded by silk_shell_decoder() (shell_coder.c).
  4121. As with the pulse counts, these locations are coded for all the shell blocks
  4122. before any of the remaining information for each block.
  4123. Unlike many other codecs, SILK places no restriction on the distribution of
  4124. pulses within a shell block.
  4125. All of the pulses may be placed in a single location, or each one in a unique
  4126. location, or anything in between.
  4127. </t>
  4128. <t>
  4129. The location of pulses is coded by recursively partitioning each block into
  4130. halves, and coding how many pulses fall on the left side of the split.
  4131. All remaining pulses must fall on the right side of the split.
  4132. The process then recurses into the left half, and after that returns, the
  4133. right half (preorder traversal).
  4134. The PDF to use is chosen by the size of the current partition (16, 8, 4, or 2)
  4135. and the number of pulses in the partition (1 to 16, inclusive).
  4136. Tables&nbsp;<xref format="counter" target="silk_shell_code3_pdfs"/>
  4137. through&nbsp;<xref format="counter" target="silk_shell_code0_pdfs"/> list the
  4138. PDFs used for each partition size and pulse count.
  4139. This process skips partitions without any pulses, i.e., where the initial pulse
  4140. count from <xref target="silk_pulse_counts"/> was zero, or where the split in
  4141. the prior level indicated that all of the pulses fell on the other side.
  4142. These partitions have nothing to code, so they require no PDF.
  4143. </t>
  4144. <?rfc compact="no" ?>
  4145. <texttable anchor="silk_shell_code3_pdfs"
  4146. title="PDFs for Pulse Count Split, 16 Sample Partitions">
  4147. <ttcol>Pulse Count</ttcol>
  4148. <ttcol>PDF</ttcol>
  4149. <c>1</c> <c>{126, 130}/256</c>
  4150. <c>2</c> <c>{56, 142, 58}/256</c>
  4151. <c>3</c> <c>{25, 101, 104, 26}/256</c>
  4152. <c>4</c> <c>{12, 60, 108, 64, 12}/256</c>
  4153. <c>5</c> <c>{7, 35, 84, 87, 37, 6}/256</c>
  4154. <c>6</c> <c>{4, 20, 59, 86, 63, 21, 3}/256</c>
  4155. <c>7</c> <c>{3, 12, 38, 72, 75, 42, 12, 2}/256</c>
  4156. <c>8</c> <c>{2, 8, 25, 54, 73, 59, 27, 7, 1}/256</c>
  4157. <c>9</c> <c>{2, 5, 17, 39, 63, 65, 42, 18, 4, 1}/256</c>
  4158. <c>10</c> <c>{1, 4, 12, 28, 49, 63, 54, 30, 11, 3, 1}/256</c>
  4159. <c>11</c> <c>{1, 4, 8, 20, 37, 55, 57, 41, 22, 8, 2, 1}/256</c>
  4160. <c>12</c> <c>{1, 3, 7, 15, 28, 44, 53, 48, 33, 16, 6, 1, 1}/256</c>
  4161. <c>13</c> <c>{1, 2, 6, 12, 21, 35, 47, 48, 40, 25, 12, 5, 1, 1}/256</c>
  4162. <c>14</c> <c>{1, 1, 4, 10, 17, 27, 37, 47, 43, 33, 21, 9, 4, 1, 1}/256</c>
  4163. <c>15</c> <c>{1, 1, 1, 8, 14, 22, 33, 40, 43, 38, 28, 16, 8, 1, 1, 1}/256</c>
  4164. <c>16</c> <c>{1, 1, 1, 1, 13, 18, 27, 36, 41, 41, 34, 24, 14, 1, 1, 1, 1}/256</c>
  4165. </texttable>
  4166. <?rfc compact="yes" ?>
  4167. <?rfc compact="no" ?>
  4168. <texttable anchor="silk_shell_code2_pdfs"
  4169. title="PDFs for Pulse Count Split, 8 Sample Partitions">
  4170. <ttcol>Pulse Count</ttcol>
  4171. <ttcol>PDF</ttcol>
  4172. <c>1</c> <c>{127, 129}/256</c>
  4173. <c>2</c> <c>{53, 149, 54}/256</c>
  4174. <c>3</c> <c>{22, 105, 106, 23}/256</c>
  4175. <c>4</c> <c>{11, 61, 111, 63, 10}/256</c>
  4176. <c>5</c> <c>{6, 35, 86, 88, 36, 5}/256</c>
  4177. <c>6</c> <c>{4, 20, 59, 87, 62, 21, 3}/256</c>
  4178. <c>7</c> <c>{3, 13, 40, 71, 73, 41, 13, 2}/256</c>
  4179. <c>8</c> <c>{3, 9, 27, 53, 70, 56, 28, 9, 1}/256</c>
  4180. <c>9</c> <c>{3, 8, 19, 37, 57, 61, 44, 20, 6, 1}/256</c>
  4181. <c>10</c> <c>{3, 7, 15, 28, 44, 54, 49, 33, 17, 5, 1}/256</c>
  4182. <c>11</c> <c>{1, 7, 13, 22, 34, 46, 48, 38, 28, 14, 4, 1}/256</c>
  4183. <c>12</c> <c>{1, 1, 11, 22, 27, 35, 42, 47, 33, 25, 10, 1, 1}/256</c>
  4184. <c>13</c> <c>{1, 1, 6, 14, 26, 37, 43, 43, 37, 26, 14, 6, 1, 1}/256</c>
  4185. <c>14</c> <c>{1, 1, 4, 10, 20, 31, 40, 42, 40, 31, 20, 10, 4, 1, 1}/256</c>
  4186. <c>15</c> <c>{1, 1, 3, 8, 16, 26, 35, 38, 38, 35, 26, 16, 8, 3, 1, 1}/256</c>
  4187. <c>16</c> <c>{1, 1, 2, 6, 12, 21, 30, 36, 38, 36, 30, 21, 12, 6, 2, 1, 1}/256</c>
  4188. </texttable>
  4189. <?rfc compact="yes" ?>
  4190. <?rfc compact="no" ?>
  4191. <texttable anchor="silk_shell_code1_pdfs"
  4192. title="PDFs for Pulse Count Split, 4 Sample Partitions">
  4193. <ttcol>Pulse Count</ttcol>
  4194. <ttcol>PDF</ttcol>
  4195. <c>1</c> <c>{127, 129}/256</c>
  4196. <c>2</c> <c>{49, 157, 50}/256</c>
  4197. <c>3</c> <c>{20, 107, 109, 20}/256</c>
  4198. <c>4</c> <c>{11, 60, 113, 62, 10}/256</c>
  4199. <c>5</c> <c>{7, 36, 84, 87, 36, 6}/256</c>
  4200. <c>6</c> <c>{6, 24, 57, 82, 60, 23, 4}/256</c>
  4201. <c>7</c> <c>{5, 18, 39, 64, 68, 42, 16, 4}/256</c>
  4202. <c>8</c> <c>{6, 14, 29, 47, 61, 52, 30, 14, 3}/256</c>
  4203. <c>9</c> <c>{1, 15, 23, 35, 51, 50, 40, 30, 10, 1}/256</c>
  4204. <c>10</c> <c>{1, 1, 21, 32, 42, 52, 46, 41, 18, 1, 1}/256</c>
  4205. <c>11</c> <c>{1, 6, 16, 27, 36, 42, 42, 36, 27, 16, 6, 1}/256</c>
  4206. <c>12</c> <c>{1, 5, 12, 21, 31, 38, 40, 38, 31, 21, 12, 5, 1}/256</c>
  4207. <c>13</c> <c>{1, 3, 9, 17, 26, 34, 38, 38, 34, 26, 17, 9, 3, 1}/256</c>
  4208. <c>14</c> <c>{1, 3, 7, 14, 22, 29, 34, 36, 34, 29, 22, 14, 7, 3, 1}/256</c>
  4209. <c>15</c> <c>{1, 2, 5, 11, 18, 25, 31, 35, 35, 31, 25, 18, 11, 5, 2, 1}/256</c>
  4210. <c>16</c> <c>{1, 1, 4, 9, 15, 21, 28, 32, 34, 32, 28, 21, 15, 9, 4, 1, 1}/256</c>
  4211. </texttable>
  4212. <?rfc compact="yes" ?>
  4213. <?rfc compact="no" ?>
  4214. <texttable anchor="silk_shell_code0_pdfs"
  4215. title="PDFs for Pulse Count Split, 2 Sample Partitions">
  4216. <ttcol>Pulse Count</ttcol>
  4217. <ttcol>PDF</ttcol>
  4218. <c>1</c> <c>{128, 128}/256</c>
  4219. <c>2</c> <c>{42, 172, 42}/256</c>
  4220. <c>3</c> <c>{21, 107, 107, 21}/256</c>
  4221. <c>4</c> <c>{12, 60, 112, 61, 11}/256</c>
  4222. <c>5</c> <c>{8, 34, 86, 86, 35, 7}/256</c>
  4223. <c>6</c> <c>{8, 23, 55, 90, 55, 20, 5}/256</c>
  4224. <c>7</c> <c>{5, 15, 38, 72, 72, 36, 15, 3}/256</c>
  4225. <c>8</c> <c>{6, 12, 27, 52, 77, 47, 20, 10, 5}/256</c>
  4226. <c>9</c> <c>{6, 19, 28, 35, 40, 40, 35, 28, 19, 6}/256</c>
  4227. <c>10</c> <c>{4, 14, 22, 31, 37, 40, 37, 31, 22, 14, 4}/256</c>
  4228. <c>11</c> <c>{3, 10, 18, 26, 33, 38, 38, 33, 26, 18, 10, 3}/256</c>
  4229. <c>12</c> <c>{2, 8, 13, 21, 29, 36, 38, 36, 29, 21, 13, 8, 2}/256</c>
  4230. <c>13</c> <c>{1, 5, 10, 17, 25, 32, 38, 38, 32, 25, 17, 10, 5, 1}/256</c>
  4231. <c>14</c> <c>{1, 4, 7, 13, 21, 29, 35, 36, 35, 29, 21, 13, 7, 4, 1}/256</c>
  4232. <c>15</c> <c>{1, 2, 5, 10, 17, 25, 32, 36, 36, 32, 25, 17, 10, 5, 2, 1}/256</c>
  4233. <c>16</c> <c>{1, 2, 4, 7, 13, 21, 28, 34, 36, 34, 28, 21, 13, 7, 4, 2, 1}/256</c>
  4234. </texttable>
  4235. <?rfc compact="yes" ?>
  4236. </section>
  4237. <section anchor="silk_shell_lsb" title="LSB Decoding">
  4238. <t>
  4239. After the decoder reads the pulse locations for all blocks, it reads the LSBs
  4240. (if any) for each block in turn.
  4241. Inside each block, it reads all the LSBs for each coefficient in turn, even
  4242. those where no pulses were allocated, before proceeding to the next one.
  4243. For 10&nbsp;ms MB frames, it reads LSBs even for the extra 8&nbsp;samples in
  4244. the last block.
  4245. The LSBs are coded from most significant to least significant, and they all use
  4246. the PDF in <xref target="silk_shell_lsb_pdf"/>.
  4247. </t>
  4248. <?rfc compact="no" ?>
  4249. <texttable anchor="silk_shell_lsb_pdf" title="PDF for Excitation LSBs">
  4250. <ttcol>PDF</ttcol>
  4251. <c>{136, 120}/256</c>
  4252. </texttable>
  4253. <?rfc compact="yes" ?>
  4254. <t>
  4255. The number of LSBs read for each coefficient in a block is determined in
  4256. <xref target="silk_pulse_counts"/>.
  4257. The magnitude of the coefficient is initially equal to the number of pulses
  4258. placed at that location in <xref target="silk_pulse_locations"/>.
  4259. As each LSB is decoded, the magnitude is doubled, and then the value of the LSB
  4260. added to it, to obtain an updated magnitude.
  4261. </t>
  4262. </section>
  4263. <section anchor="silk_signs" title="Sign Decoding">
  4264. <t>
  4265. After decoding the pulse locations and the LSBs, the decoder knows the
  4266. magnitude of each coefficient in the excitation.
  4267. It then decodes a sign for all coefficients with a non-zero magnitude, using
  4268. one of the PDFs from <xref target="silk_sign_pdfs"/>.
  4269. If the value decoded is 0, then the coefficient magnitude is negated.
  4270. Otherwise, it remains positive.
  4271. </t>
  4272. <t>
  4273. The decoder chooses the PDF for the sign based on the signal type and
  4274. quantization offset type (from <xref target="silk_frame_type"/>) and the
  4275. number of pulses in the block (from <xref target="silk_pulse_counts"/>).
  4276. The number of pulses in the block does not take into account any LSBs.
  4277. Most PDFs are skewed towards negative signs because of the quantization offset,
  4278. but the PDFs for zero pulses are highly skewed towards positive signs.
  4279. If a block contains many positive coefficients, it is sometimes beneficial to
  4280. code it solely using LSBs (i.e., with zero pulses), since the encoder may be
  4281. able to save enough bits on the signs to justify the less efficient
  4282. coefficient magnitude encoding.
  4283. </t>
  4284. <?rfc compact="no" ?>
  4285. <texttable anchor="silk_sign_pdfs"
  4286. title="PDFs for Excitation Signs">
  4287. <ttcol>Signal Type</ttcol>
  4288. <ttcol>Quantization Offset Type</ttcol>
  4289. <ttcol>Pulse Count</ttcol>
  4290. <ttcol>PDF</ttcol>
  4291. <c>Inactive</c> <c>Low</c> <c>0</c> <c>{2, 254}/256</c>
  4292. <c>Inactive</c> <c>Low</c> <c>1</c> <c>{207, 49}/256</c>
  4293. <c>Inactive</c> <c>Low</c> <c>2</c> <c>{189, 67}/256</c>
  4294. <c>Inactive</c> <c>Low</c> <c>3</c> <c>{179, 77}/256</c>
  4295. <c>Inactive</c> <c>Low</c> <c>4</c> <c>{174, 82}/256</c>
  4296. <c>Inactive</c> <c>Low</c> <c>5</c> <c>{163, 93}/256</c>
  4297. <c>Inactive</c> <c>Low</c> <c>6 or more</c> <c>{157, 99}/256</c>
  4298. <c>Inactive</c> <c>High</c> <c>0</c> <c>{58, 198}/256</c>
  4299. <c>Inactive</c> <c>High</c> <c>1</c> <c>{245, 11}/256</c>
  4300. <c>Inactive</c> <c>High</c> <c>2</c> <c>{238, 18}/256</c>
  4301. <c>Inactive</c> <c>High</c> <c>3</c> <c>{232, 24}/256</c>
  4302. <c>Inactive</c> <c>High</c> <c>4</c> <c>{225, 31}/256</c>
  4303. <c>Inactive</c> <c>High</c> <c>5</c> <c>{220, 36}/256</c>
  4304. <c>Inactive</c> <c>High</c> <c>6 or more</c> <c>{211, 45}/256</c>
  4305. <c>Unvoiced</c> <c>Low</c> <c>0</c> <c>{1, 255}/256</c>
  4306. <c>Unvoiced</c> <c>Low</c> <c>1</c> <c>{210, 46}/256</c>
  4307. <c>Unvoiced</c> <c>Low</c> <c>2</c> <c>{190, 66}/256</c>
  4308. <c>Unvoiced</c> <c>Low</c> <c>3</c> <c>{178, 78}/256</c>
  4309. <c>Unvoiced</c> <c>Low</c> <c>4</c> <c>{169, 87}/256</c>
  4310. <c>Unvoiced</c> <c>Low</c> <c>5</c> <c>{162, 94}/256</c>
  4311. <c>Unvoiced</c> <c>Low</c> <c>6 or more</c> <c>{152, 104}/256</c>
  4312. <c>Unvoiced</c> <c>High</c> <c>0</c> <c>{48, 208}/256</c>
  4313. <c>Unvoiced</c> <c>High</c> <c>1</c> <c>{242, 14}/256</c>
  4314. <c>Unvoiced</c> <c>High</c> <c>2</c> <c>{235, 21}/256</c>
  4315. <c>Unvoiced</c> <c>High</c> <c>3</c> <c>{224, 32}/256</c>
  4316. <c>Unvoiced</c> <c>High</c> <c>4</c> <c>{214, 42}/256</c>
  4317. <c>Unvoiced</c> <c>High</c> <c>5</c> <c>{205, 51}/256</c>
  4318. <c>Unvoiced</c> <c>High</c> <c>6 or more</c> <c>{190, 66}/256</c>
  4319. <c>Voiced</c> <c>Low</c> <c>0</c> <c>{1, 255}/256</c>
  4320. <c>Voiced</c> <c>Low</c> <c>1</c> <c>{162, 94}/256</c>
  4321. <c>Voiced</c> <c>Low</c> <c>2</c> <c>{152, 104}/256</c>
  4322. <c>Voiced</c> <c>Low</c> <c>3</c> <c>{147, 109}/256</c>
  4323. <c>Voiced</c> <c>Low</c> <c>4</c> <c>{144, 112}/256</c>
  4324. <c>Voiced</c> <c>Low</c> <c>5</c> <c>{141, 115}/256</c>
  4325. <c>Voiced</c> <c>Low</c> <c>6 or more</c> <c>{138, 118}/256</c>
  4326. <c>Voiced</c> <c>High</c> <c>0</c> <c>{8, 248}/256</c>
  4327. <c>Voiced</c> <c>High</c> <c>1</c> <c>{203, 53}/256</c>
  4328. <c>Voiced</c> <c>High</c> <c>2</c> <c>{187, 69}/256</c>
  4329. <c>Voiced</c> <c>High</c> <c>3</c> <c>{176, 80}/256</c>
  4330. <c>Voiced</c> <c>High</c> <c>4</c> <c>{168, 88}/256</c>
  4331. <c>Voiced</c> <c>High</c> <c>5</c> <c>{161, 95}/256</c>
  4332. <c>Voiced</c> <c>High</c> <c>6 or more</c> <c>{154, 102}/256</c>
  4333. </texttable>
  4334. <?rfc compact="yes" ?>
  4335. </section>
  4336. <section anchor="silk_excitation_reconstruction"
  4337. title="Reconstructing the Excitation">
  4338. <t>
  4339. After the signs have been read, there is enough information to reconstruct the
  4340. complete excitation signal.
  4341. This requires adding a constant quantization offset to each non-zero sample
  4342. and then pseudorandomly inverting and offsetting every sample.
  4343. The constant quantization offset varies depending on the signal type and
  4344. quantization offset type (see <xref target="silk_frame_type"/>).
  4345. </t>
  4346. <?rfc compact="no" ?>
  4347. <texttable anchor="silk_quantization_offsets"
  4348. title="Excitation Quantization Offsets">
  4349. <ttcol align="left">Signal Type</ttcol>
  4350. <ttcol align="left">Quantization Offset Type</ttcol>
  4351. <ttcol align="right">Quantization Offset (Q23)</ttcol>
  4352. <c>Inactive</c> <c>Low</c> <c>25</c>
  4353. <c>Inactive</c> <c>High</c> <c>60</c>
  4354. <c>Unvoiced</c> <c>Low</c> <c>25</c>
  4355. <c>Unvoiced</c> <c>High</c> <c>60</c>
  4356. <c>Voiced</c> <c>Low</c> <c>8</c>
  4357. <c>Voiced</c> <c>High</c> <c>25</c>
  4358. </texttable>
  4359. <?rfc compact="yes" ?>
  4360. <t>
  4361. Let e_raw[i] be the raw excitation value at position i, with a magnitude
  4362. composed of the pulses at that location (see
  4363. <xref target="silk_pulse_locations"/>) combined with any additional LSBs (see
  4364. <xref target="silk_shell_lsb"/>), and with the corresponding sign decoded in
  4365. <xref target="silk_signs"/>.
  4366. Additionally, let seed be the current pseudorandom seed, which is initialized
  4367. to the value decoded from <xref target="silk_seed"/> for the first sample in
  4368. the current SILK frame, and updated for each subsequent sample according to
  4369. the procedure below.
  4370. Finally, let offset_Q23 be the quantization offset from
  4371. <xref target="silk_quantization_offsets"/>.
  4372. Then the following procedure produces the final reconstructed excitation value,
  4373. e_Q23[i]:
  4374. <figure align="center">
  4375. <artwork align="center"><![CDATA[
  4376. e_Q23[i] = (e_raw[i] << 8) - sign(e_raw[i])*20 + offset_Q23;
  4377. seed = (196314165*seed + 907633515) & 0xFFFFFFFF;
  4378. e_Q23[i] = (seed & 0x80000000) ? -e_Q23[i] : e_Q23[i];
  4379. seed = (seed + e_raw[i]) & 0xFFFFFFFF;
  4380. ]]></artwork>
  4381. </figure>
  4382. When e_raw[i] is zero, sign() returns 0 by the definition in
  4383. <xref target="sign"/>, so the factor of 20 does not get added.
  4384. The final e_Q23[i] value may require more than 16 bits per sample, but it will not
  4385. require more than 23, including the sign.
  4386. </t>
  4387. </section>
  4388. </section>
  4389. <section anchor="silk_frame_reconstruction" toc="include"
  4390. title="SILK Frame Reconstruction">
  4391. <t>
  4392. The remainder of the reconstruction process for the frame does not need to be
  4393. bit-exact, as small errors should only introduce proportionally small
  4394. distortions.
  4395. Although the reference implementation only includes a fixed-point version of
  4396. the remaining steps, this section describes them in terms of a floating-point
  4397. version for simplicity.
  4398. This produces a signal with a nominal range of -1.0 to 1.0.
  4399. </t>
  4400. <t>
  4401. silk_decode_core() (decode_core.c) contains the code for the main
  4402. reconstruction process.
  4403. It proceeds subframe-by-subframe, since quantization gains, LTP parameters, and
  4404. (in 20&nbsp;ms SILK frames) LPC coefficients can vary from one to the
  4405. next.
  4406. </t>
  4407. <t>
  4408. Let a_Q12[k] be the LPC coefficients for the current subframe.
  4409. If this is the first or second subframe of a 20&nbsp;ms SILK frame and the LSF
  4410. interpolation factor, w_Q2 (see <xref target="silk_nlsf_interpolation"/>), is
  4411. less than 4, then these correspond to the final LPC coefficients produced by
  4412. <xref target="silk_lpc_gain_limit"/> from the interpolated LSF coefficients,
  4413. n1_Q15[k] (computed in <xref target="silk_nlsf_interpolation"/>).
  4414. Otherwise, they correspond to the final LPC coefficients produced from the
  4415. uninterpolated LSF coefficients for the current frame, n2_Q15[k].
  4416. </t>
  4417. <t>
  4418. Also, let n be the number of samples in a subframe (40 for NB, 60 for MB, and
  4419. 80 for WB), s be the index of the current subframe in this SILK frame (0 or 1
  4420. for 10&nbsp;ms frames, or 0 to 3 for 20&nbsp;ms frames), and j be the index of
  4421. the first sample in the residual corresponding to the current subframe.
  4422. </t>
  4423. <section anchor="silk_ltp_synthesis" title="LTP Synthesis">
  4424. <t>
  4425. For unvoiced frames (see <xref target="silk_frame_type"/>), the LPC residual
  4426. for i such that j&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;(j&nbsp;+&nbsp;n) is simply
  4427. a normalized copy of the excitation signal, i.e.,
  4428. <figure align="center">
  4429. <artwork align="center"><![CDATA[
  4430. e_Q23[i]
  4431. res[i] = ---------
  4432. 2.0**23
  4433. ]]></artwork>
  4434. </figure>
  4435. </t>
  4436. <t>
  4437. Voiced SILK frames, on the other hand, pass the excitation through an LTP
  4438. filter using the parameters decoded in <xref target="silk_ltp_params"/> to
  4439. produce an LPC residual.
  4440. The LTP filter requires LPC residual values from before the current subframe as
  4441. input.
  4442. However, since the LPC coefficients may have changed, it obtains this residual
  4443. by "rewhitening" the corresponding output signal using the LPC coefficients
  4444. from the current subframe.
  4445. Let out[i] for i such that
  4446. (j&nbsp;-&nbsp;pitch_lags[s]&nbsp;-&nbsp;d_LPC&nbsp;-&nbsp;2)&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;j
  4447. be the fully reconstructed output signal from the last
  4448. (pitch_lags[s]&nbsp;+&nbsp;d_LPC&nbsp;+&nbsp;2) samples of previous subframes
  4449. (see <xref target="silk_lpc_synthesis"/>), where pitch_lags[s] is the pitch
  4450. lag for the current subframe from <xref target="silk_ltp_lags"/>.
  4451. Additionally, let lpc[i] for i such that
  4452. (j&nbsp;-&nbsp;s*n&nbsp;-&nbsp;d_LPC)&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;j
  4453. be the fully reconstructed output signal from the last
  4454. (s*n&nbsp;+&nbsp;d_LPC) samples of previous subframes before clamping
  4455. (see <xref target="silk_lpc_synthesis"/>).
  4456. During reconstruction of the first subframe for this channel after either
  4457. <list style="symbols">
  4458. <t>An uncoded regular SILK frame (if this is the side channel), or</t>
  4459. <t>A decoder reset (see <xref target="decoder-reset"/>),</t>
  4460. </list>
  4461. out[i] and lpc[i] are initially cleared to all zeros.
  4462. If this is the third or fourth subframe of a 20&nbsp;ms SILK frame and the LSF
  4463. interpolation factor, w_Q2 (see <xref target="silk_nlsf_interpolation"/>), is
  4464. less than 4, then let out_end be set to (j&nbsp;-&nbsp;(s-2)*n) and let
  4465. LTP_scale_Q14 be set to 16384.
  4466. Otherwise, set out_end to (j&nbsp;-&nbsp;s*n) and set LTP_scale_Q14 to the Q14
  4467. LTP scaling value from <xref target="silk_ltp_scaling"/>.
  4468. Then, for i such that
  4469. (j&nbsp;-&nbsp;pitch_lags[s]&nbsp;-&nbsp;2)&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;out_end,
  4470. out[i] is rewhitened into an LPC residual, res[i], via
  4471. <figure align="center">
  4472. <artwork align="center"><![CDATA[
  4473. 4.0*LTP_scale_Q14
  4474. res[i] = ----------------- * clamp(-1.0,
  4475. gain_Q16[s]
  4476. d_LPC-1
  4477. __ a_Q12[k]
  4478. out[i] - \ out[i-k-1] * --------, 1.0)
  4479. /_ 4096.0
  4480. k=0
  4481. ]]></artwork>
  4482. </figure>
  4483. This requires storage to buffer up to 306 values of out[i] from previous
  4484. subframes.
  4485. This corresponds to WB with a maximum pitch lag of
  4486. 18&nbsp;ms&nbsp;*&nbsp;16&nbsp;kHz samples, plus 16 samples for d_LPC, plus 2
  4487. samples for the width of the LTP filter.
  4488. Then, for i such that out_end&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;j, lpc[i] is
  4489. rewhitened into an LPC residual, res[i], via
  4490. <figure align="center">
  4491. <artwork align="center"><![CDATA[
  4492. d_LPC-1
  4493. 65536.0 __ a_Q12[k]
  4494. res[i] = ----------- * (lpc[i] - \ lpc[i-k-1] * --------)
  4495. gain_Q16[s] /_ 4096.0
  4496. k=0
  4497. ]]></artwork>
  4498. </figure>
  4499. This requires storage to buffer up to 256 values of lpc[i] from previous
  4500. subframes (240 from the current SILK frame and 16 from the previous SILK
  4501. frame).
  4502. This corresponds to WB with up to three previous subframes in the current SILK
  4503. frame, plus 16 samples for d_LPC.
  4504. The astute reader will notice that, given the definition of lpc[i] in
  4505. <xref target="silk_lpc_synthesis"/>, the output of this latter equation is
  4506. merely a scaled version of the values of res[i] from previous subframes.
  4507. </t>
  4508. <t>
  4509. Let e_Q23[i] for j&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;(j&nbsp;+&nbsp;n) be the
  4510. excitation for the current subframe, and b_Q7[k] for
  4511. 0&nbsp;&lt;=&nbsp;k&nbsp;&lt;&nbsp;5 be the coefficients of the LTP filter
  4512. taken from the codebook entry in one of
  4513. Tables&nbsp;<xref format="counter" target="silk_ltp_filter_coeffs0"/>
  4514. through&nbsp;<xref format="counter" target="silk_ltp_filter_coeffs2"/>
  4515. corresponding to the index decoded for the current subframe in
  4516. <xref target="silk_ltp_filter"/>.
  4517. Then for i such that j&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;(j&nbsp;+&nbsp;n),
  4518. the LPC residual is
  4519. <figure align="center">
  4520. <artwork align="center"><![CDATA[
  4521. 4
  4522. e_Q23[i] __ b_Q7[k]
  4523. res[i] = --------- + \ res[i - pitch_lags[s] + 2 - k] * -------
  4524. 2.0**23 /_ 128.0
  4525. k=0
  4526. ]]></artwork>
  4527. </figure>
  4528. </t>
  4529. </section>
  4530. <section anchor="silk_lpc_synthesis" title="LPC Synthesis">
  4531. <t>
  4532. LPC synthesis uses the short-term LPC filter to predict the next output
  4533. coefficient.
  4534. For i such that (j&nbsp;-&nbsp;d_LPC)&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;j, let
  4535. lpc[i] be the result of LPC synthesis from the last d_LPC samples of the
  4536. previous subframe or zeros in the first subframe for this channel after
  4537. either
  4538. <list style="symbols">
  4539. <t>An uncoded regular SILK frame (if this is the side channel), or</t>
  4540. <t>A decoder reset (see <xref target="decoder-reset"/>).</t>
  4541. </list>
  4542. Then, for i such that j&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;(j&nbsp;+&nbsp;n), the
  4543. result of LPC synthesis for the current subframe is
  4544. <figure align="center">
  4545. <artwork align="center"><![CDATA[
  4546. d_LPC-1
  4547. gain_Q16[i] __ a_Q12[k]
  4548. lpc[i] = ----------- * res[i] + \ lpc[i-k-1] * --------
  4549. 65536.0 /_ 4096.0
  4550. k=0
  4551. ]]></artwork>
  4552. </figure>
  4553. The decoder saves the final d_LPC values, i.e., lpc[i] such that
  4554. (j&nbsp;+&nbsp;n&nbsp;-&nbsp;d_LPC)&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;(j&nbsp;+&nbsp;n),
  4555. to feed into the LPC synthesis of the next subframe.
  4556. This requires storage for up to 16 values of lpc[i] (for WB frames).
  4557. </t>
  4558. <t>
  4559. Then, the signal is clamped into the final nominal range:
  4560. <figure align="center">
  4561. <artwork align="center"><![CDATA[
  4562. out[i] = clamp(-1.0, lpc[i], 1.0)
  4563. ]]></artwork>
  4564. </figure>
  4565. This clamping occurs entirely after the LPC synthesis filter has run.
  4566. The decoder saves the unclamped values, lpc[i], to feed into the LPC filter for
  4567. the next subframe, but saves the clamped values, out[i], for rewhitening in
  4568. voiced frames.
  4569. </t>
  4570. </section>
  4571. </section>
  4572. </section>
  4573. <section anchor="silk_stereo_unmixing" title="Stereo Unmixing">
  4574. <t>
  4575. For stereo streams, after decoding a frame from each channel, the decoder must
  4576. convert the mid-side (MS) representation into a left-right (LR)
  4577. representation.
  4578. The function silk_stereo_MS_to_LR (stereo_MS_to_LR.c) implements this process.
  4579. In it, the decoder predicts the side channel using a) a simple low-passed
  4580. version of the mid channel, and b) the unfiltered mid channel, using the
  4581. prediction weights decoded in <xref target="silk_stereo_pred"/>.
  4582. This simple low-pass filter imposes a one-sample delay, and the unfiltered
  4583. mid channel is also delayed by one sample.
  4584. In order to allow seamless switching between stereo and mono, mono streams must
  4585. also impose the same one-sample delay.
  4586. The encoder requires an additional one-sample delay for both mono and stereo
  4587. streams, though an encoder may omit the delay for mono if it knows it will
  4588. never switch to stereo.
  4589. </t>
  4590. <t>
  4591. The unmixing process operates in two phases.
  4592. The first phase lasts for 8&nbsp;ms, during which it interpolates the
  4593. prediction weights from the previous frame, prev_w0_Q13 and prev_w1_Q13, to
  4594. the values for the current frame, w0_Q13 and w1_Q13.
  4595. The second phase simply uses these weights for the remainder of the frame.
  4596. </t>
  4597. <t>
  4598. Let mid[i] and side[i] be the contents of out[i] (from
  4599. <xref target="silk_lpc_synthesis"/>) for the current mid and side channels,
  4600. respectively, and let left[i] and right[i] be the corresponding stereo output
  4601. channels.
  4602. If the side channel is not coded (see <xref target="silk_mid_only_flag"/>),
  4603. then side[i] is set to zero.
  4604. Also, let j be defined as in <xref target="silk_frame_reconstruction"/>, n1 be
  4605. the number of samples in phase&nbsp;1 (64 for NB, 96 for MB, and 128 for WB),
  4606. and n2 be the total number of samples in the frame.
  4607. Then, for i such that j&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;(j&nbsp;+&nbsp;n2),
  4608. the left and right channel output is
  4609. <figure align="center">
  4610. <artwork align="center"><![CDATA[
  4611. prev_w0_Q13 (w0_Q13 - prev_w0_Q13)
  4612. w0 = ----------- + min(i - j, n1)*----------------------
  4613. 8192.0 8192.0*n1
  4614. prev_w1_Q13 (w1_Q13 - prev_w1_Q13)
  4615. w1 = ----------- + min(i - j, n1)*----------------------
  4616. 8192.0 8192.0*n1
  4617. mid[i-2] + 2*mid[i-1] + mid[i]
  4618. p0 = ------------------------------
  4619. 4.0
  4620. left[i] = clamp(-1.0, (1 + w1)*mid[i-1] + side[i-1] + w0*p0, 1.0)
  4621. right[i] = clamp(-1.0, (1 - w1)*mid[i-1] - side[i-1] - w0*p0, 1.0)
  4622. ]]></artwork>
  4623. </figure>
  4624. These formulas require two samples prior to index&nbsp;j, the start of the
  4625. frame, for the mid channel, and one prior sample for the side channel.
  4626. For the first frame after a decoder reset, zeros are used instead.
  4627. </t>
  4628. </section>
  4629. <section title="Resampling">
  4630. <t>
  4631. After stereo unmixing (if any), the decoder applies resampling to convert the
  4632. decoded SILK output to the sample rate desired by the application.
  4633. This is necessary when decoding a Hybrid frame at SWB or FB sample rates, or
  4634. whenever the decoder wants the output at a different sample rate than the
  4635. internal SILK sampling rate (e.g., to allow a constant sample rate when the
  4636. audio bandwidth changes, or to allow mixing with audio from other
  4637. applications).
  4638. The resampler itself is non-normative, and a decoder can use any method it
  4639. wants to perform the resampling.
  4640. </t>
  4641. <t>
  4642. However, a minimum amount of delay is imposed to allow the resampler to
  4643. operate, and this delay is normative, so that the corresponding delay can be
  4644. applied to the MDCT layer in the encoder.
  4645. A decoder is always free to use a resampler that requires more delay than
  4646. allowed for here (e.g., to improve quality), but it must then delay the output
  4647. of the MDCT layer by this extra amount.
  4648. Keeping as much delay as possible on the encoder side allows an encoder that
  4649. knows it will never use any of the SILK or Hybrid modes to skip this delay.
  4650. By contrast, if it were all applied by the decoder, then a decoder that
  4651. processes audio in fixed-size blocks would be forced to delay the output of
  4652. CELT frames just in case of a later switch to a SILK or Hybrid mode.
  4653. </t>
  4654. <t>
  4655. <xref target="silk_resampler_delay_alloc"/> gives the maximum resampler delay
  4656. in samples at 48&nbsp;kHz for each SILK audio bandwidth.
  4657. Because the actual output rate may not be 48&nbsp;kHz, it may not be possible
  4658. to achieve exactly these delays while using a whole number of input or output
  4659. samples.
  4660. The reference implementation is able to resample to any of the supported
  4661. output sampling rates (8, 12, 16, 24, or 48&nbsp;kHz) within or near this
  4662. delay constraint.
  4663. Some resampling filters (including those used by the reference implementation)
  4664. may add a delay that is not an exact integer, or is not linear-phase, and so
  4665. cannot be represented by a single delay at all frequencies.
  4666. However, such deviations are unlikely to be perceptible, and the comparison
  4667. tool described in <xref target="conformance"/> is designed to be relatively
  4668. insensitive to them.
  4669. The delays listed here are the ones that should be targeted by the encoder.
  4670. </t>
  4671. <?rfc compact="no" ?>
  4672. <texttable anchor="silk_resampler_delay_alloc"
  4673. title="SILK Resampler Delay Allocations">
  4674. <ttcol>Audio Bandwidth</ttcol>
  4675. <ttcol>Delay in Milliseconds</ttcol>
  4676. <c>NB</c> <c>0.538</c>
  4677. <c>MB</c> <c>0.692</c>
  4678. <c>WB</c> <c>0.706</c>
  4679. </texttable>
  4680. <?rfc compact="yes" ?>
  4681. <t>
  4682. NB is given a smaller decoder delay allocation than MB and WB to allow a
  4683. higher-order filter when resampling to 8&nbsp;kHz in both the encoder and
  4684. decoder.
  4685. This implies that the audio content of two SILK frames operating at different
  4686. bandwidths is not perfectly aligned in time.
  4687. This is not an issue for any transitions described in
  4688. <xref target="switching"/>, because they all involve a SILK decoder reset.
  4689. When the decoder is reset, any samples remaining in the resampling buffer
  4690. are discarded, and the resampler is re-initialized with silence.
  4691. </t>
  4692. </section>
  4693. </section>
  4694. <section title="CELT Decoder">
  4695. <t>
  4696. The CELT layer of Opus is based on the Modified Discrete Cosine Transform
  4697. <xref target='MDCT'/> with partially overlapping windows of 5 to 22.5 ms.
  4698. The main principle behind CELT is that the MDCT spectrum is divided into
  4699. bands that (roughly) follow the Bark scale, i.e., the scale of the ear's
  4700. critical bands&nbsp;<xref target="ZWICKER61"/>. The normal CELT layer uses 21 of those bands, though Opus
  4701. Custom (see <xref target="opus-custom"/>) may use a different number of bands.
  4702. In Hybrid mode, the first 17 bands (up to 8&nbsp;kHz) are not coded.
  4703. A band can contain as little as one MDCT bin per channel, and as many as 176
  4704. bins per channel, as detailed in <xref target="celt_band_sizes"/>.
  4705. In each band, the gain (energy) is coded separately from
  4706. the shape of the spectrum. Coding the gain explicitly makes it easy to
  4707. preserve the spectral envelope of the signal. The remaining unit-norm shape
  4708. vector is encoded using a Pyramid Vector Quantizer (PVQ)&nbsp;<xref target='PVQ-decoder'/>.
  4709. </t>
  4710. <?rfc compact="no" ?>
  4711. <texttable anchor="celt_band_sizes"
  4712. title="MDCT Bins per Channel per Band for Each Frame Size">
  4713. <ttcol>Frame Size:</ttcol>
  4714. <ttcol align="right">2.5&nbsp;ms</ttcol>
  4715. <ttcol align="right">5&nbsp;ms</ttcol>
  4716. <ttcol align="right">10&nbsp;ms</ttcol>
  4717. <ttcol align="right">20&nbsp;ms</ttcol>
  4718. <ttcol align="right">Start Frequency</ttcol>
  4719. <ttcol align="right">Stop Frequency</ttcol>
  4720. <c>Band</c> <c>Bins:</c> <c/> <c/> <c/> <c/> <c/>
  4721. <c>0</c> <c>1</c> <c>2</c> <c>4</c> <c>8</c> <c>0&nbsp;Hz</c> <c>200&nbsp;Hz</c>
  4722. <c>1</c> <c>1</c> <c>2</c> <c>4</c> <c>8</c> <c>200&nbsp;Hz</c> <c>400&nbsp;Hz</c>
  4723. <c>2</c> <c>1</c> <c>2</c> <c>4</c> <c>8</c> <c>400&nbsp;Hz</c> <c>600&nbsp;Hz</c>
  4724. <c>3</c> <c>1</c> <c>2</c> <c>4</c> <c>8</c> <c>600&nbsp;Hz</c> <c>800&nbsp;Hz</c>
  4725. <c>4</c> <c>1</c> <c>2</c> <c>4</c> <c>8</c> <c>800&nbsp;Hz</c> <c>1000&nbsp;Hz</c>
  4726. <c>5</c> <c>1</c> <c>2</c> <c>4</c> <c>8</c> <c>1000&nbsp;Hz</c> <c>1200&nbsp;Hz</c>
  4727. <c>6</c> <c>1</c> <c>2</c> <c>4</c> <c>8</c> <c>1200&nbsp;Hz</c> <c>1400&nbsp;Hz</c>
  4728. <c>7</c> <c>1</c> <c>2</c> <c>4</c> <c>8</c> <c>1400&nbsp;Hz</c> <c>1600&nbsp;Hz</c>
  4729. <c>8</c> <c>2</c> <c>4</c> <c>8</c> <c>16</c> <c>1600&nbsp;Hz</c> <c>2000&nbsp;Hz</c>
  4730. <c>9</c> <c>2</c> <c>4</c> <c>8</c> <c>16</c> <c>2000&nbsp;Hz</c> <c>2400&nbsp;Hz</c>
  4731. <c>10</c> <c>2</c> <c>4</c> <c>8</c> <c>16</c> <c>2400&nbsp;Hz</c> <c>2800&nbsp;Hz</c>
  4732. <c>11</c> <c>2</c> <c>4</c> <c>8</c> <c>16</c> <c>2800&nbsp;Hz</c> <c>3200&nbsp;Hz</c>
  4733. <c>12</c> <c>4</c> <c>8</c> <c>16</c> <c>32</c> <c>3200&nbsp;Hz</c> <c>4000&nbsp;Hz</c>
  4734. <c>13</c> <c>4</c> <c>8</c> <c>16</c> <c>32</c> <c>4000&nbsp;Hz</c> <c>4800&nbsp;Hz</c>
  4735. <c>14</c> <c>4</c> <c>8</c> <c>16</c> <c>32</c> <c>4800&nbsp;Hz</c> <c>5600&nbsp;Hz</c>
  4736. <c>15</c> <c>6</c> <c>12</c> <c>24</c> <c>48</c> <c>5600&nbsp;Hz</c> <c>6800&nbsp;Hz</c>
  4737. <c>16</c> <c>6</c> <c>12</c> <c>24</c> <c>48</c> <c>6800&nbsp;Hz</c> <c>8000&nbsp;Hz</c>
  4738. <c>17</c> <c>8</c> <c>16</c> <c>32</c> <c>64</c> <c>8000&nbsp;Hz</c> <c>9600&nbsp;Hz</c>
  4739. <c>18</c> <c>12</c> <c>24</c> <c>48</c> <c>96</c> <c>9600&nbsp;Hz</c> <c>12000&nbsp;Hz</c>
  4740. <c>19</c> <c>18</c> <c>36</c> <c>72</c> <c>144</c> <c>12000&nbsp;Hz</c> <c>15600&nbsp;Hz</c>
  4741. <c>20</c> <c>22</c> <c>44</c> <c>88</c> <c>176</c> <c>15600&nbsp;Hz</c> <c>20000&nbsp;Hz</c>
  4742. </texttable>
  4743. <?rfc compact="yes" ?>
  4744. <t>
  4745. Transients are notoriously difficult for transform codecs to code.
  4746. CELT uses two different strategies for them:
  4747. <list style="numbers">
  4748. <t>Using multiple smaller MDCTs instead of a single large MDCT, and</t>
  4749. <t>Dynamic time-frequency resolution changes (See <xref target='tf-change'/>).</t>
  4750. </list>
  4751. To improve quality on highly tonal and periodic signals, CELT includes
  4752. a pre-filter/post-filter combination. The pre-filter on the encoder side
  4753. attenuates the signal's harmonics. The post-filter on the decoder side
  4754. restores the original gain of the harmonics, while shaping the coding noise
  4755. to roughly follow the harmonics. Such noise shaping reduces the perception
  4756. of the noise.
  4757. </t>
  4758. <t>
  4759. When coding a stereo signal, three coding methods are available:
  4760. <list style="symbols">
  4761. <t>mid-side stereo: encodes the mean and the difference of the left and right channels,</t>
  4762. <t>intensity stereo: only encodes the mean of the left and right channels (discards the difference),</t>
  4763. <t>dual stereo: encodes the left and right channels separately.</t>
  4764. </list>
  4765. </t>
  4766. <t>
  4767. An overview of the decoder is given in <xref target="celt-decoder-overview"/>.
  4768. </t>
  4769. <figure anchor="celt-decoder-overview" title="Structure of the CELT decoder">
  4770. <artwork align="center"><![CDATA[
  4771. +---------+
  4772. | Coarse |
  4773. +->| decoder |----+
  4774. | +---------+ |
  4775. | |
  4776. | +---------+ v
  4777. | | Fine | +---+
  4778. +->| decoder |->| + |
  4779. | +---------+ +---+
  4780. | ^ |
  4781. +---------+ | | |
  4782. | Range | | +----------+ v
  4783. | Decoder |-+ | Bit | +------+
  4784. +---------+ | |Allocation| | 2**x |
  4785. | +----------+ +------+
  4786. | | |
  4787. | v v +--------+
  4788. | +---------+ +---+ +-------+ | pitch |
  4789. +->| PVQ |->| * |->| IMDCT |->| post- |--->
  4790. | | decoder | +---+ +-------+ | filter |
  4791. | +---------+ +--------+
  4792. | ^
  4793. +--------------------------------------+
  4794. Legend:
  4795. IMDCT = Inverse MDCT
  4796. ]]></artwork>
  4797. </figure>
  4798. <t>
  4799. The decoder is based on the following symbols and sets of symbols:
  4800. </t>
  4801. <?rfc compact="no" ?>
  4802. <texttable anchor="celt_symbols"
  4803. title="Order of the Symbols in the CELT Section of the Bitstream">
  4804. <ttcol align="center">Symbol(s)</ttcol>
  4805. <ttcol align="center">PDF</ttcol>
  4806. <ttcol align="center">Condition</ttcol>
  4807. <c>silence</c> <c>{32767, 1}/32768</c> <c></c>
  4808. <c>post-filter</c> <c>{1, 1}/2</c> <c></c>
  4809. <c>octave</c> <c>uniform (6)</c><c>post-filter</c>
  4810. <c>period</c> <c>raw bits (4+octave)</c><c>post-filter</c>
  4811. <c>gain</c> <c>raw bits (3)</c><c>post-filter</c>
  4812. <c>tapset</c> <c>{2, 1, 1}/4</c><c>post-filter</c>
  4813. <c>transient</c> <c>{7, 1}/8</c><c></c>
  4814. <c>intra</c> <c>{7, 1}/8</c><c></c>
  4815. <c>coarse energy</c><c><xref target="energy-decoding"/></c><c></c>
  4816. <c>tf_change</c> <c><xref target="transient-decoding"/></c><c></c>
  4817. <c>tf_select</c> <c>{1, 1}/2</c><c><xref target="transient-decoding"/></c>
  4818. <c>spread</c> <c>{7, 2, 21, 2}/32</c><c></c>
  4819. <c>dyn. alloc.</c> <c><xref target="allocation"/></c><c></c>
  4820. <c>alloc. trim</c> <c><xref target="celt_trim_pdf"/></c><c></c>
  4821. <c>skip</c> <c>{1, 1}/2</c><c><xref target="allocation"/></c>
  4822. <c>intensity</c> <c>uniform</c><c><xref target="allocation"/></c>
  4823. <c>dual</c> <c>{1, 1}/2</c><c></c>
  4824. <c>fine energy</c> <c><xref target="energy-decoding"/></c><c></c>
  4825. <c>residual</c> <c><xref target="PVQ-decoder"/></c><c></c>
  4826. <c>anti-collapse</c><c>{1, 1}/2</c><c><xref target="anti-collapse"/></c>
  4827. <c>finalize</c> <c><xref target="energy-decoding"/></c><c></c>
  4828. </texttable>
  4829. <?rfc compact="yes" ?>
  4830. <t>
  4831. The decoder extracts information from the range-coded bitstream in the order
  4832. described in <xref target='celt_symbols'/>. In some circumstances, it is
  4833. possible for a decoded value to be out of range due to a very small amount of redundancy
  4834. in the encoding of large integers by the range coder.
  4835. In that case, the decoder should assume there has been an error in the coding,
  4836. decoding, or transmission and SHOULD take measures to conceal the error and/or report
  4837. to the application that a problem has occurred. Such out of range errors cannot occur
  4838. in the SILK layer.
  4839. </t>
  4840. <section anchor="transient-decoding" title="Transient Decoding">
  4841. <t>
  4842. The "transient" flag indicates whether the frame uses a single long MDCT or several short MDCTs.
  4843. When it is set, then the MDCT coefficients represent multiple
  4844. short MDCTs in the frame. When not set, the coefficients represent a single
  4845. long MDCT for the frame. The flag is encoded in the bitstream with a probability of 1/8.
  4846. In addition to the global transient flag is a per-band
  4847. binary flag to change the time-frequency (tf) resolution independently in each band. The
  4848. change in tf resolution is defined in tf_select_table[][] in celt.c and depends
  4849. on the frame size, whether the transient flag is set, and the value of tf_select.
  4850. The tf_select flag uses a 1/2 probability, but is only decoded
  4851. if it can have an impact on the result knowing the value of all per-band
  4852. tf_change flags.
  4853. </t>
  4854. </section>
  4855. <section anchor="energy-decoding" title="Energy Envelope Decoding">
  4856. <t>
  4857. It is important to quantize the energy with sufficient resolution because
  4858. any energy quantization error cannot be compensated for at a later
  4859. stage. Regardless of the resolution used for encoding the spectral shape of a band,
  4860. it is perceptually important to preserve the energy in each band. CELT uses a
  4861. three-step coarse-fine-fine strategy for encoding the energy in the base-2 log
  4862. domain, as implemented in quant_bands.c.</t>
  4863. <section anchor="coarse-energy-decoding" title="Coarse Energy Decoding">
  4864. <t>
  4865. Coarse quantization of the energy uses a fixed resolution of 6 dB
  4866. (integer part of base-2 log). To minimize the bitrate, prediction is applied
  4867. both in time (using the previous frame) and in frequency (using the previous
  4868. bands). The part of the prediction that is based on the
  4869. previous frame can be disabled, creating an "intra" frame where the energy
  4870. is coded without reference to prior frames. The decoder first reads the intra flag
  4871. to determine what prediction is used.
  4872. The 2-D z-transform <xref target='Z-TRANSFORM'/> of
  4873. the prediction filter is
  4874. <figure align="center">
  4875. <artwork align="center"><![CDATA[
  4876. -1 -1
  4877. (1 - alpha*z_l )*(1 - z_b )
  4878. A(z_l, z_b) = -----------------------------
  4879. -1
  4880. 1 - beta*z_b
  4881. ]]></artwork>
  4882. </figure>
  4883. where b is the band index and l is the frame index. The prediction coefficients
  4884. applied depend on the frame size in use when not using intra energy and are alpha=0, beta=4915/32768
  4885. when using intra energy.
  4886. The time-domain prediction is based on the final fine quantization of the previous
  4887. frame, while the frequency domain (within the current frame) prediction is based
  4888. on coarse quantization only (because the fine quantization has not been computed
  4889. yet). The prediction is clamped internally so that fixed-point implementations with
  4890. limited dynamic range always remain in the same state as floating point implementations.
  4891. We approximate the ideal
  4892. probability distribution of the prediction error using a Laplace distribution
  4893. with separate parameters for each frame size in intra- and inter-frame modes. These
  4894. parameters are held in the e_prob_model table in quant_bands.c.
  4895. The
  4896. coarse energy quantization is performed by unquant_coarse_energy() and
  4897. unquant_coarse_energy_impl() (quant_bands.c). The decoding of the Laplace-distributed values is
  4898. implemented in ec_laplace_decode() (laplace.c).
  4899. </t>
  4900. </section>
  4901. <section anchor="fine-energy-decoding" title="Fine Energy Quantization">
  4902. <t>
  4903. The number of bits assigned to fine energy quantization in each band is determined
  4904. by the bit allocation computation described in <xref target="allocation"></xref>.
  4905. Let B_i be the number of fine energy bits
  4906. for band i; the refinement is an integer f in the range [0,2**B_i-1]. The mapping between f
  4907. and the correction applied to the coarse energy is equal to (f+1/2)/2**B_i - 1/2. Fine
  4908. energy quantization is implemented in quant_fine_energy() (quant_bands.c).
  4909. </t>
  4910. <t>
  4911. When some bits are left "unused" after all other flags have been decoded, these bits
  4912. are assigned to a "final" step of fine allocation. In effect, these bits are used
  4913. to add one extra fine energy bit per band per channel. The allocation process
  4914. determines two "priorities" for the final fine bits.
  4915. Any remaining bits are first assigned only to bands of priority 0, starting
  4916. from band 0 and going up. If all bands of priority 0 have received one bit per
  4917. channel, then bands of priority 1 are assigned an extra bit per channel,
  4918. starting from band 0. If any bits are left after this, they are left unused.
  4919. This is implemented in unquant_energy_finalise() (quant_bands.c).
  4920. </t>
  4921. </section> <!-- fine energy -->
  4922. </section> <!-- Energy decode -->
  4923. <section anchor="allocation" title="Bit Allocation">
  4924. <t>Because the bit allocation drives the decoding of the range-coder
  4925. stream, it MUST be recovered exactly so that identical coding decisions are
  4926. made in the encoder and decoder. Any deviation from the reference's resulting
  4927. bit allocation will result in corrupted output, though implementers are
  4928. free to implement the procedure in any way that produces identical results.</t>
  4929. <t>The per-band gain-shape structure of the CELT layer ensures that using
  4930. the same number of bits for the spectral shape of a band in every frame will
  4931. result in a roughly constant signal-to-noise ratio in that band.
  4932. This results in coding noise that has the same spectral envelope as the signal.
  4933. The masking curve produced by a standard psychoacoustic model also closely
  4934. follows the spectral envelope of the signal.
  4935. This structure means that the ideal allocation is more consistent from frame to
  4936. frame than it is for other codecs without an equivalent structure and that a
  4937. fixed allocation provides fairly consistent perceptual
  4938. performance&nbsp;<xref target='VALIN2010'/>.</t>
  4939. <t>Many codecs transmit significant amounts of side information to control the
  4940. bit allocation within a frame.
  4941. Often this control is only indirect, and it must be exercised carefully to
  4942. achieve the desired rate constraints.
  4943. The CELT layer, however, can adapt over a very wide range of rates, so it has a
  4944. large number of codebook sizes to choose from for each band.
  4945. Explicitly signaling the size of each of these codebooks would impose
  4946. considerable overhead, even though the allocation is relatively static from
  4947. frame to frame.
  4948. This is because all of the information required to compute these codebook sizes
  4949. must be derived from a single frame by itself, in order to retain robustness
  4950. to packet loss, so the signaling cannot take advantage of knowledge of the
  4951. allocation in neighboring frames.
  4952. This problem is exacerbated in low-latency (small frame size) applications,
  4953. which would include this overhead in every frame.</t>
  4954. <t>For this reason, in the MDCT mode, Opus uses a primarily implicit bit
  4955. allocation. The available bitstream capacity is known in advance to both
  4956. the encoder and decoder without additional signaling, ultimately from the
  4957. packet sizes expressed by a higher-level protocol. Using this information,
  4958. the codec interpolates an allocation from a hard-coded table.</t>
  4959. <t>While the band-energy structure effectively models intra-band masking,
  4960. it ignores the weaker inter-band masking, band-temporal masking, and
  4961. other less significant perceptual effects. While these effects can
  4962. often be ignored, they can become significant for particular samples. One
  4963. mechanism available to encoders would be to simply increase the overall
  4964. rate for these frames, but this is not possible in a constant rate mode
  4965. and can be fairly inefficient. As a result three explicitly signaled
  4966. mechanisms are provided to alter the implicit allocation:</t>
  4967. <t>
  4968. <list style="symbols">
  4969. <t>Band boost</t>
  4970. <t>Allocation trim</t>
  4971. <t>Band skipping</t>
  4972. </list>
  4973. </t>
  4974. <t>The first of these mechanisms, band boost, allows an encoder to boost
  4975. the allocation in specific bands. The second, allocation trim, works by
  4976. biasing the overall allocation towards higher or lower frequency bands. The third, band
  4977. skipping, selects which low-precision high frequency bands
  4978. will be allocated no shape bits at all.</t>
  4979. <t>In stereo mode, there are two additional parameters
  4980. potentially coded as part of the allocation procedure: a parameter to allow the
  4981. selective elimination of allocation for the 'side' (i.e., intensity stereo) in jointly coded bands,
  4982. and a flag to deactivate joint coding (i.e., dual stereo). These values are not signaled if
  4983. they would be meaningless in the overall context of the allocation.</t>
  4984. <t>Because every signaled adjustment increases overhead and implementation
  4985. complexity, none were included speculatively: the reference encoder makes use
  4986. of all of these mechanisms. While the decision logic in the reference was
  4987. found to be effective enough to justify the overhead and complexity, further
  4988. analysis techniques may be discovered that increase the effectiveness of these
  4989. parameters. As with other signaled parameters, an encoder is free to choose the
  4990. values in any manner, but, unless a technique is known to deliver superior
  4991. perceptual results, the methods used by the reference implementation should be
  4992. used.</t>
  4993. <t>The allocation process consists of the following steps: determining the per-band
  4994. maximum allocation vector, decoding the boosts, decoding the tilt, determining
  4995. the remaining capacity of the frame, searching the mode table for the
  4996. entry nearest but not exceeding the available space (subject to the tilt, boosts, band
  4997. maximums, and band minimums), linear interpolation, reallocation of
  4998. unused bits with concurrent skip decoding, determination of the
  4999. fine-energy vs. shape split, and final reallocation. This process results
  5000. in a per-band shape allocation (in 1/8th-bit units), a per-band fine-energy
  5001. allocation (in 1 bit per channel units), a set of band priorities for
  5002. controlling the use of remaining bits at the end of the frame, and a
  5003. remaining balance of unallocated space, which is usually zero except
  5004. at very high rates.</t>
  5005. <t>
  5006. The "static" bit allocation (in 1/8 bits) for a quality q, excluding the minimums, maximums,
  5007. tilt and boosts, is equal to channels*N*alloc[band][q]&lt;&lt;LM&gt;&gt;2, where
  5008. alloc[][] is given in <xref target="static_alloc"/> and LM=log2(frame_size/120). The allocation
  5009. is obtained by linearly interpolating between two values of q (in steps of 1/64) to find the
  5010. highest allocation that does not exceed the number of bits remaining.
  5011. </t>
  5012. <?rfc compact="no" ?>
  5013. <texttable anchor="static_alloc"
  5014. title="CELT Static Allocation Table">
  5015. <preamble>Rows indicate the MDCT bands, columns are the different quality (q) parameters. The units are 1/32 bit per MDCT bin.</preamble>
  5016. <ttcol align="right">0</ttcol>
  5017. <ttcol align="right">1</ttcol>
  5018. <ttcol align="right">2</ttcol>
  5019. <ttcol align="right">3</ttcol>
  5020. <ttcol align="right">4</ttcol>
  5021. <ttcol align="right">5</ttcol>
  5022. <ttcol align="right">6</ttcol>
  5023. <ttcol align="right">7</ttcol>
  5024. <ttcol align="right">8</ttcol>
  5025. <ttcol align="right">9</ttcol>
  5026. <ttcol align="right">10</ttcol>
  5027. <c>0</c><c>90</c><c>110</c><c>118</c><c>126</c><c>134</c><c>144</c><c>152</c><c>162</c><c>172</c><c>200</c>
  5028. <c>0</c><c>80</c><c>100</c><c>110</c><c>119</c><c>127</c><c>137</c><c>145</c><c>155</c><c>165</c><c>200</c>
  5029. <c>0</c><c>75</c><c>90</c><c>103</c><c>112</c><c>120</c><c>130</c><c>138</c><c>148</c><c>158</c><c>200</c>
  5030. <c>0</c><c>69</c><c>84</c><c>93</c><c>104</c><c>114</c><c>124</c><c>132</c><c>142</c><c>152</c><c>200</c>
  5031. <c>0</c><c>63</c><c>78</c><c>86</c><c>95</c><c>103</c><c>113</c><c>123</c><c>133</c><c>143</c><c>200</c>
  5032. <c>0</c><c>56</c><c>71</c><c>80</c><c>89</c><c>97</c><c>107</c><c>117</c><c>127</c><c>137</c><c>200</c>
  5033. <c>0</c><c>49</c><c>65</c><c>75</c><c>83</c><c>91</c><c>101</c><c>111</c><c>121</c><c>131</c><c>200</c>
  5034. <c>0</c><c>40</c><c>58</c><c>70</c><c>78</c><c>85</c><c>95</c><c>105</c><c>115</c><c>125</c><c>200</c>
  5035. <c>0</c><c>34</c><c>51</c><c>65</c><c>72</c><c>78</c><c>88</c><c>98</c><c>108</c><c>118</c><c>198</c>
  5036. <c>0</c><c>29</c><c>45</c><c>59</c><c>66</c><c>72</c><c>82</c><c>92</c><c>102</c><c>112</c><c>193</c>
  5037. <c>0</c><c>20</c><c>39</c><c>53</c><c>60</c><c>66</c><c>76</c><c>86</c><c>96</c><c>106</c><c>188</c>
  5038. <c>0</c><c>18</c><c>32</c><c>47</c><c>54</c><c>60</c><c>70</c><c>80</c><c>90</c><c>100</c><c>183</c>
  5039. <c>0</c><c>10</c><c>26</c><c>40</c><c>47</c><c>54</c><c>64</c><c>74</c><c>84</c><c>94</c><c>178</c>
  5040. <c>0</c><c>0</c><c>20</c><c>31</c><c>39</c><c>47</c><c>57</c><c>67</c><c>77</c><c>87</c><c>173</c>
  5041. <c>0</c><c>0</c><c>12</c><c>23</c><c>32</c><c>41</c><c>51</c><c>61</c><c>71</c><c>81</c><c>168</c>
  5042. <c>0</c><c>0</c><c>0</c><c>15</c><c>25</c><c>35</c><c>45</c><c>55</c><c>65</c><c>75</c><c>163</c>
  5043. <c>0</c><c>0</c><c>0</c><c>4</c><c>17</c><c>29</c><c>39</c><c>49</c><c>59</c><c>69</c><c>158</c>
  5044. <c>0</c><c>0</c><c>0</c><c>0</c><c>12</c><c>23</c><c>33</c><c>43</c><c>53</c><c>63</c><c>153</c>
  5045. <c>0</c><c>0</c><c>0</c><c>0</c><c>1</c><c>16</c><c>26</c><c>36</c><c>46</c><c>56</c><c>148</c>
  5046. <c>0</c><c>0</c><c>0</c><c>0</c><c>0</c><c>10</c><c>15</c><c>20</c><c>30</c><c>45</c><c>129</c>
  5047. <c>0</c><c>0</c><c>0</c><c>0</c><c>0</c><c>1</c><c>1</c><c>1</c><c>1</c><c>20</c><c>104</c>
  5048. </texttable>
  5049. <?rfc compact="yes" ?>
  5050. <t>The maximum allocation vector is an approximation of the maximum space
  5051. that can be used by each band for a given mode. The value is
  5052. approximate because the shape encoding is variable rate (due
  5053. to entropy coding of splitting parameters). Setting the maximum too low reduces the
  5054. maximum achievable quality in a band while setting it too high
  5055. may result in waste: bitstream capacity available at the end
  5056. of the frame that cannot be put to any use. The maximums
  5057. specified by the codec reflect the average maximum. In the reference
  5058. implementation, the maximums in bits/sample are precomputed in a static table
  5059. (see cache_caps50[] in static_modes_float.h) for each band,
  5060. for each value of LM, and for both mono and stereo.
  5061. Implementations are expected
  5062. to simply use the same table data, but the procedure for generating
  5063. this table is included in rate.c as part of compute_pulse_cache().</t>
  5064. <t>To convert the values in cache.caps into the actual maximums: first,
  5065. set nbBands to the maximum number of bands for this mode, and stereo to
  5066. zero if stereo is not in use and one otherwise. For each band, set N
  5067. to the number of MDCT bins covered by the band (for one channel), set LM
  5068. to the shift value for the frame size.
  5069. Then, set i to nbBands*(2*LM+stereo). Next, set the maximum for the band to
  5070. the i-th index of cache.caps + 64 and multiply by the number of channels
  5071. in the current frame (one or two) and by N, then divide the result by 4
  5072. using integer division. The resulting vector will be called
  5073. cap[]. The elements fit in signed 16-bit integers but do not fit in 8 bits.
  5074. This procedure is implemented in the reference in the function init_caps() in celt.c.
  5075. </t>
  5076. <t>The band boosts are represented by a series of binary symbols that
  5077. are entropy coded with very low probability. Each band can potentially be boosted
  5078. multiple times, subject to the frame actually having enough room to obey
  5079. the boost and having enough room to code the boost symbol. The default
  5080. coding cost for a boost starts out at six bits (probability p=1/64), but subsequent boosts
  5081. in a band cost only a single bit and every time a band is boosted the
  5082. initial cost is reduced (down to a minimum of two bits, or p=1/4). Since the initial
  5083. cost of coding a boost is 6 bits, the coding cost of the boost symbols when
  5084. completely unused is 0.48 bits/frame for a 21 band mode (21*-log2(1-1/2**6)).</t>
  5085. <t>To decode the band boosts: First, set 'dynalloc_logp' to 6, the initial
  5086. amount of storage required to signal a boost in bits, 'total_bits' to the
  5087. size of the frame in 8th bits, 'total_boost' to zero, and 'tell' to the total number
  5088. of 8th bits decoded
  5089. so far. For each band from the coding start (0 normally, but 17 in Hybrid mode)
  5090. to the coding end (which changes depending on the signaled bandwidth), the boost quanta
  5091. in units of 1/8 bit is calculated as quanta = min(8*N, max(48, N)).
  5092. This represents a boost step size of six bits, subject to a lower limit of
  5093. 1/8th&nbsp;bit/sample and an upper limit of 1&nbsp;bit/sample.
  5094. Set 'boost' to zero and 'dynalloc_loop_logp'
  5095. to dynalloc_logp. While dynalloc_loop_log (the current worst case symbol cost) in
  5096. 8th bits plus tell is less than total_bits plus total_boost and boost is less than cap[] for this
  5097. band: Decode a bit from the bitstream with dynalloc_loop_logp as the cost
  5098. of a one and update tell to reflect the current used capacity.
  5099. If the decoded value is zero break the loop.
  5100. Otherwise, add quanta to boost and total_boost, subtract quanta from
  5101. total_bits, and set dynalloc_loop_log to 1. When the loop finishes
  5102. 'boost' contains the bit allocation boost for this band.
  5103. If boost is non-zero and dynalloc_logp
  5104. is greater than 2, decrease dynalloc_logp. Once this process has been
  5105. executed on all bands, the band boosts have been decoded. This procedure
  5106. is implemented around line 2474 of celt.c.</t>
  5107. <t>At very low rates, it is possible that there won't be enough available
  5108. space to execute the inner loop even once. In these cases, band boost
  5109. is not possible, but its overhead is completely eliminated. Because of the
  5110. high cost of band boost when activated, a reasonable encoder should not be
  5111. using it at very low rates. The reference implements its dynalloc decision
  5112. logic around line 1304 of celt.c.</t>
  5113. <t>The allocation trim is a integer value from 0-10. The default value of
  5114. 5 indicates no trim. The trim parameter is entropy coded in order to
  5115. lower the coding cost of less extreme adjustments. Values lower than
  5116. 5 bias the allocation towards lower frequencies and values above 5
  5117. bias it towards higher frequencies. Like other signaled parameters, signaling
  5118. of the trim is gated so that it is not included if there is insufficient space
  5119. available in the bitstream. To decode the trim, first set
  5120. the trim value to 5, then if and only if the count of decoded 8th bits so far (ec_tell_frac)
  5121. plus 48 (6 bits) is less than or equal to the total frame size in 8th
  5122. bits minus total_boost (a product of the above band boost procedure),
  5123. decode the trim value using the PDF in <xref target="celt_trim_pdf"/>.</t>
  5124. <?rfc compact="no" ?>
  5125. <texttable anchor="celt_trim_pdf" title="PDF for the Trim">
  5126. <ttcol>PDF</ttcol>
  5127. <c>{2, 2, 5, 10, 22, 46, 22, 10, 5, 2, 2}/128</c>
  5128. </texttable>
  5129. <?rfc compact="yes" ?>
  5130. <t>For 10 ms and 20 ms frames using short blocks and that have at least LM+2 bits left prior to
  5131. the allocation process, one anti-collapse bit is reserved in the allocation process so it can
  5132. be decoded later. Following the anti-collapse reservation, one bit is reserved for skip if available.</t>
  5133. <t>For stereo frames, bits are reserved for intensity stereo and for dual stereo. Intensity stereo
  5134. requires ilog2(end-start) bits. Those bits are reserved if there are enough bits left. Following this, one
  5135. bit is reserved for dual stereo if available.</t>
  5136. <t>The allocation computation begins by setting up some initial conditions.
  5137. 'total' is set to the remaining available 8th bits, computed by taking the
  5138. size of the coded frame times 8 and subtracting ec_tell_frac(). From this value, one (8th bit)
  5139. is subtracted to ensure that the resulting allocation will be conservative. 'anti_collapse_rsv'
  5140. is set to 8 (8th bits) if and only if the frame is a transient, LM is greater than 1, and total is
  5141. greater than or equal to (LM+2) * 8. Total is then decremented by anti_collapse_rsv and clamped
  5142. to be equal to or greater than zero. 'skip_rsv' is set to 8 (8th bits) if total is greater than
  5143. 8, otherwise it is zero. Total is then decremented by skip_rsv. This reserves space for the
  5144. final skipping flag.</t>
  5145. <t>If the current frame is stereo, intensity_rsv is set to the conservative log2 in 8th bits
  5146. of the number of coded bands for this frame (given by the table LOG2_FRAC_TABLE in rate.c). If
  5147. intensity_rsv is greater than total, then intensity_rsv is set to zero. Otherwise, total is
  5148. decremented by intensity_rsv, and if total is still greater than 8, dual_stereo_rsv is
  5149. set to 8 and total is decremented by dual_stereo_rsv.</t>
  5150. <t>The allocation process then computes a vector representing the hard minimum amounts allocation
  5151. any band will receive for shape. This minimum is higher than the technical limit of the PVQ
  5152. process, but very low rate allocations produce an excessively sparse spectrum and these bands
  5153. are better served by having no allocation at all. For each coded band, set thresh[band] to
  5154. 24 times the number of MDCT bins in the band and divide by 16. If 8 times the number
  5155. of channels is greater, use that instead. This sets the minimum allocation to one bit per channel
  5156. or 48 128th bits per MDCT bin, whichever is greater. The band-size dependent part of this
  5157. value is not scaled by the channel count, because at the very low rates where this limit is
  5158. applicable there will usually be no bits allocated to the side.</t>
  5159. <t>The previously decoded allocation trim is used to derive a vector of per-band adjustments,
  5160. 'trim_offsets[]'. For each coded band take the alloc_trim and subtract 5 and LM. Then, multiply
  5161. the result by the number of channels, the number of MDCT bins in the shortest frame size for this mode,
  5162. the number of remaining bands, 2**LM, and 8. Next, divide this value by 64. Finally, if the
  5163. number of MDCT bins in the band per channel is only one, 8 times the number of channels is subtracted
  5164. in order to diminish the allocation by one bit, because width 1 bands receive greater benefit
  5165. from the coarse energy coding.</t>
  5166. </section>
  5167. <section anchor="PVQ-decoder" title="Shape Decoding">
  5168. <t>
  5169. In each band, the normalized "shape" is encoded
  5170. using Pyramid Vector Quantizer.
  5171. </t>
  5172. <t>In
  5173. the simplest case, the number of bits allocated in
  5174. <xref target="allocation"></xref> is converted to a number of pulses as described
  5175. by <xref target="bits-pulses"></xref>. Knowing the number of pulses and the
  5176. number of samples in the band, the decoder calculates the size of the codebook
  5177. as detailed in <xref target="cwrs-decoder"></xref>. The size is used to decode
  5178. an unsigned integer (uniform probability model), which is the codeword index.
  5179. This index is converted into the corresponding vector as explained in
  5180. <xref target="cwrs-decoder"></xref>. This vector is then scaled to unit norm.
  5181. </t>
  5182. <section anchor="bits-pulses" title="Bits to Pulses">
  5183. <t>
  5184. Although the allocation is performed in 1/8th bit units, the quantization requires
  5185. an integer number of pulses K.&nbsp; To do this, the encoder searches for the value
  5186. of K that produces the number of bits nearest to the allocated value
  5187. (rounding down if exactly halfway between two values), not to exceed
  5188. the total number of bits available. For efficiency reasons, the search is performed against a
  5189. precomputed allocation table that only permits some K values for each N.&nbsp; The number of
  5190. codebook entries can be computed as explained in <xref target="cwrs-decoder"></xref>. The difference
  5191. between the number of bits allocated and the number of bits used is accumulated to a
  5192. "balance" (initialized to zero) that helps adjust the
  5193. allocation for the next bands. One third of the balance is applied to the
  5194. bit allocation of each band to help achieve the target allocation. The only
  5195. exceptions are the band before the last and the last band, for which half the balance
  5196. and the whole balance are applied, respectively.
  5197. </t>
  5198. </section>
  5199. <section anchor="cwrs-decoder" title="PVQ Decoding">
  5200. <t>
  5201. Decoding of PVQ vectors is implemented in decode_pulses() (cwrs.c).
  5202. The unique codeword index is decoded as a uniformly distributed integer value between 0 and
  5203. V(N,K)-1, where V(N,K) is the number of possible combinations of K pulses in
  5204. N samples. The index is then converted to a vector in the same way specified in
  5205. <xref target="PVQ"></xref>. The indexing is based on the calculation of V(N,K)
  5206. (denoted N(L,K) in <xref target="PVQ"></xref>).
  5207. </t>
  5208. <t>
  5209. The number of combinations can be computed recursively as
  5210. V(N,K) = V(N-1,K) + V(N,K-1) + V(N-1,K-1), with V(N,0) = 1 and V(0,K) = 0, K != 0.
  5211. There are many different ways to compute V(N,K), including precomputed tables and direct
  5212. use of the recursive formulation. The reference implementation applies the recursive
  5213. formulation one line (or column) at a time to save on memory use,
  5214. along with an alternate,
  5215. univariate recurrence to initialize an arbitrary line, and direct
  5216. polynomial solutions for small N.&nbsp; All of these methods are
  5217. equivalent, and have different trade-offs in speed, memory usage, and
  5218. code size. Implementations MAY use any methods they like, as long as
  5219. they are equivalent to the mathematical definition.
  5220. </t>
  5221. <t>
  5222. The decoded vector X is recovered as follows.
  5223. Let i be the index decoded with the procedure in <xref target="ec_dec_uint"/>
  5224. with ft&nbsp;=&nbsp;V(N,K), so that 0&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;V(N,K).
  5225. Let k&nbsp;=&nbsp;K.
  5226. Then, for j&nbsp;=&nbsp;0 to (N&nbsp;-&nbsp;1), inclusive, do:
  5227. <list style="numbers">
  5228. <t>Let p&nbsp;=&nbsp;(V(N-j-1,k)&nbsp;+&nbsp;V(N-j,k))/2.</t>
  5229. <t>
  5230. If i&nbsp;&lt;&nbsp;p, then let sgn&nbsp;=&nbsp;1, else let sgn&nbsp;=&nbsp;-1
  5231. and set i&nbsp;=&nbsp;i&nbsp;-&nbsp;p.
  5232. </t>
  5233. <t>Let k0&nbsp;=&nbsp;k and set p&nbsp;=&nbsp;p&nbsp;-&nbsp;V(N-j-1,k).</t>
  5234. <t>
  5235. While p&nbsp;&gt;&nbsp;i, set k&nbsp;=&nbsp;k&nbsp;-&nbsp;1 and
  5236. p&nbsp;=&nbsp;p&nbsp;-&nbsp;V(N-j-1,k).
  5237. </t>
  5238. <t>
  5239. Set X[j]&nbsp;=&nbsp;sgn*(k0&nbsp;-&nbsp;k) and i&nbsp;=&nbsp;i&nbsp;-&nbsp;p.
  5240. </t>
  5241. </list>
  5242. </t>
  5243. <t>
  5244. The decoded vector X is then normalized such that its
  5245. L2-norm equals one.
  5246. </t>
  5247. </section>
  5248. <section anchor="spreading" title="Spreading">
  5249. <t>
  5250. The normalized vector decoded in <xref target="cwrs-decoder"/> is then rotated
  5251. for the purpose of avoiding tonal artifacts. The rotation gain is equal to
  5252. <figure align="center">
  5253. <artwork align="center"><![CDATA[
  5254. g_r = N / (N + f_r*K)
  5255. ]]></artwork>
  5256. </figure>
  5257. where N is the number of dimensions, K is the number of pulses, and f_r depends on
  5258. the value of the "spread" parameter in the bitstream.
  5259. </t>
  5260. <?rfc compact="no" ?>
  5261. <texttable anchor="spread values" title="Spreading Values">
  5262. <ttcol>Spread value</ttcol>
  5263. <ttcol>f_r</ttcol>
  5264. <c>0</c> <c>infinite (no rotation)</c>
  5265. <c>1</c> <c>15</c>
  5266. <c>2</c> <c>10</c>
  5267. <c>3</c> <c>5</c>
  5268. </texttable>
  5269. <?rfc compact="yes" ?>
  5270. <t>
  5271. The rotation angle is then calculated as
  5272. <figure align="center">
  5273. <artwork align="center"><![CDATA[
  5274. 2
  5275. pi * g_r
  5276. theta = ----------
  5277. 4
  5278. ]]></artwork>
  5279. </figure>
  5280. A 2-D rotation R(i,j) between points x_i and x_j is defined as:
  5281. <figure align="center">
  5282. <artwork align="center"><![CDATA[
  5283. x_i' = cos(theta)*x_i + sin(theta)*x_j
  5284. x_j' = -sin(theta)*x_i + cos(theta)*x_j
  5285. ]]></artwork>
  5286. </figure>
  5287. An N-D rotation is then achieved by applying a series of 2-D rotations back and forth, in the
  5288. following order: R(x_1, x_2), R(x_2, x_3), ..., R(x_N-2, X_N-1), R(x_N-1, X_N),
  5289. R(x_N-2, X_N-1), ..., R(x_1, x_2).
  5290. </t>
  5291. <t>
  5292. If the decoded vector represents more
  5293. than one time block, then this spreading process is applied separately on each time block.
  5294. Also, if each block represents 8 samples or more, then another N-D rotation, by
  5295. (pi/2-theta), is applied <spanx style="emph">before</spanx> the rotation described above. This
  5296. extra rotation is applied in an interleaved manner with a stride equal to round(sqrt(N/nb_blocks)),
  5297. i.e., it is applied independently for each set of sample S_k = {stride*n + k}, n=0..N/stride-1.
  5298. </t>
  5299. </section>
  5300. <section anchor="split" title="Split Decoding">
  5301. <t>
  5302. To avoid the need for multi-precision calculations when decoding PVQ codevectors,
  5303. the maximum size allowed for codebooks is 32 bits. When larger codebooks are
  5304. needed, the vector is instead split in two sub-vectors of size N/2.
  5305. A quantized gain parameter with precision
  5306. derived from the current allocation is entropy coded to represent the relative
  5307. gains of each side of the split, and the entire decoding process is recursively
  5308. applied. Multiple levels of splitting may be applied up to a limit of LM+1 splits.
  5309. The same recursive mechanism is applied for the joint coding
  5310. of stereo audio.
  5311. </t>
  5312. </section>
  5313. <section anchor="tf-change" title="Time-Frequency Change">
  5314. <t>
  5315. The time-frequency (TF) parameters are used to control the time-frequency resolution trade-off
  5316. in each coded band. For each band, there are two possible TF choices. For the first
  5317. band coded, the PDF is {3, 1}/4 for frames marked as transient and {15, 1}/16 for
  5318. the other frames. For subsequent bands, the TF choice is coded relative to the
  5319. previous TF choice with probability {15, 1}/15 for transient frames and {31, 1}/32
  5320. otherwise. The mapping between the decoded TF choices and the adjustment in TF
  5321. resolution is shown in the tables below.
  5322. </t>
  5323. <?rfc compact="no" ?>
  5324. <texttable anchor='tf_00'
  5325. title="TF Adjustments for Non-transient Frames and tf_select=0">
  5326. <ttcol align='center'>Frame size (ms)</ttcol>
  5327. <ttcol align='center'>0</ttcol>
  5328. <ttcol align='center'>1</ttcol>
  5329. <c>2.5</c> <c>0</c> <c>-1</c>
  5330. <c>5</c> <c>0</c> <c>-1</c>
  5331. <c>10</c> <c>0</c> <c>-2</c>
  5332. <c>20</c> <c>0</c> <c>-2</c>
  5333. </texttable>
  5334. <?rfc compact="yes" ?>
  5335. <?rfc compact="no" ?>
  5336. <texttable anchor='tf_01'
  5337. title="TF Adjustments for Non-transient Frames and tf_select=1">
  5338. <ttcol align='center'>Frame size (ms)</ttcol>
  5339. <ttcol align='center'>0</ttcol>
  5340. <ttcol align='center'>1</ttcol>
  5341. <c>2.5</c> <c>0</c> <c>-1</c>
  5342. <c>5</c> <c>0</c> <c>-2</c>
  5343. <c>10</c> <c>0</c> <c>-3</c>
  5344. <c>20</c> <c>0</c> <c>-3</c>
  5345. </texttable>
  5346. <?rfc compact="yes" ?>
  5347. <?rfc compact="no" ?>
  5348. <texttable anchor='tf_10'
  5349. title="TF Adjustments for Transient Frames and tf_select=0">
  5350. <ttcol align='center'>Frame size (ms)</ttcol>
  5351. <ttcol align='center'>0</ttcol>
  5352. <ttcol align='center'>1</ttcol>
  5353. <c>2.5</c> <c>0</c> <c>-1</c>
  5354. <c>5</c> <c>1</c> <c>0</c>
  5355. <c>10</c> <c>2</c> <c>0</c>
  5356. <c>20</c> <c>3</c> <c>0</c>
  5357. </texttable>
  5358. <?rfc compact="yes" ?>
  5359. <?rfc compact="no" ?>
  5360. <texttable anchor='tf_11'
  5361. title="TF Adjustments for Transient Frames and tf_select=1">
  5362. <ttcol align='center'>Frame size (ms)</ttcol>
  5363. <ttcol align='center'>0</ttcol>
  5364. <ttcol align='center'>1</ttcol>
  5365. <c>2.5</c> <c>0</c> <c>-1</c>
  5366. <c>5</c> <c>1</c> <c>-1</c>
  5367. <c>10</c> <c>1</c> <c>-1</c>
  5368. <c>20</c> <c>1</c> <c>-1</c>
  5369. </texttable>
  5370. <?rfc compact="yes" ?>
  5371. <t>
  5372. A negative TF adjustment means that the temporal resolution is increased,
  5373. while a positive TF adjustment means that the frequency resolution is increased.
  5374. Changes in TF resolution are implemented using the Hadamard transform <xref target="HADAMARD"/>. To increase
  5375. the time resolution by N, N "levels" of the Hadamard transform are applied to the
  5376. decoded vector for each interleaved MDCT vector. To increase the frequency resolution
  5377. (assumes a transient frame), then N levels of the Hadamard transform are applied
  5378. <spanx style="emph">across</spanx> the interleaved MDCT vector. In the case of increased
  5379. time resolution, the decoder uses the "sequency order" because the input vector
  5380. is sorted in time.
  5381. </t>
  5382. </section>
  5383. </section>
  5384. <section anchor="anti-collapse" title="Anti-collapse Processing">
  5385. <t>
  5386. The anti-collapse feature is designed to avoid the situation where the use of multiple
  5387. short MDCTs causes the energy in one or more of the MDCTs to be zero for
  5388. some bands, causing unpleasant artifacts.
  5389. When the frame has the transient bit set, an anti-collapse bit is decoded.
  5390. When anti-collapse is set, the energy in each small MDCT is prevented
  5391. from collapsing to zero. For each band of each MDCT where a collapse is
  5392. detected, a pseudo-random signal is inserted with an energy corresponding
  5393. to the minimum energy over the two previous frames. A renormalization step is
  5394. then required to ensure that the anti-collapse step did not alter the
  5395. energy preservation property.
  5396. </t>
  5397. </section>
  5398. <section anchor="denormalization" title="Denormalization">
  5399. <t>
  5400. Just as each band was normalized in the encoder, the last step of the decoder before
  5401. the inverse MDCT is to denormalize the bands. Each decoded normalized band is
  5402. multiplied by the square root of the decoded energy. This is done by denormalise_bands()
  5403. (bands.c).
  5404. </t>
  5405. </section>
  5406. <section anchor="inverse-mdct" title="Inverse MDCT">
  5407. <t>The inverse MDCT implementation has no special characteristics. The
  5408. input is N frequency-domain samples and the output is 2*N time-domain
  5409. samples, while scaling by 1/2. A "low-overlap" window reduces the algorithmic delay.
  5410. It is derived from a basic (full-overlap) 240-sample version of the window used by the Vorbis codec:
  5411. <figure align="center">
  5412. <artwork align="center"><![CDATA[
  5413. 2
  5414. / /pi /pi n + 1/2\ \ \
  5415. W(n) = |sin|-- * sin|-- * -------| | |
  5416. \ \2 \2 L / / /
  5417. ]]></artwork>
  5418. </figure>
  5419. The low-overlap window is created by zero-padding the basic window and inserting ones in the
  5420. middle, such that the resulting window still satisfies power complementarity <xref target='PRINCEN86'/>.
  5421. The IMDCT and
  5422. windowing are performed by mdct_backward (mdct.c).
  5423. </t>
  5424. <section anchor="post-filter" title="Post-Filter">
  5425. <t>
  5426. The output of the inverse MDCT (after weighted overlap-add) is sent to the
  5427. post-filter. Although the post-filter is applied at the end, the post-filter
  5428. parameters are encoded at the beginning, just after the silence flag.
  5429. The post-filter can be switched on or off using one bit (logp=1).
  5430. If the post-filter is enabled, then the octave is decoded as an integer value
  5431. between 0 and 6 of uniform probability. Once the octave is known, the fine pitch
  5432. within the octave is decoded using 4+octave raw bits. The final pitch period
  5433. is equal to (16&lt;&lt;octave)+fine_pitch-1 so it is bounded between 15 and 1022,
  5434. inclusively. Next, the gain is decoded as three raw bits and is equal to
  5435. G=3*(int_gain+1)/32. The set of post-filter taps is decoded last, using
  5436. a pdf equal to {2, 1, 1}/4. Tapset zero corresponds to the filter coefficients
  5437. g0 = 0.3066406250, g1 = 0.2170410156, g2 = 0.1296386719. Tapset one
  5438. corresponds to the filter coefficients g0 = 0.4638671875, g1 = 0.2680664062,
  5439. g2 = 0, and tapset two uses filter coefficients g0 = 0.7998046875,
  5440. g1 = 0.1000976562, g2 = 0.
  5441. </t>
  5442. <t>
  5443. The post-filter response is thus computed as:
  5444. <figure align="center">
  5445. <artwork align="center">
  5446. <![CDATA[
  5447. y(n) = x(n) + G*(g0*y(n-T) + g1*(y(n-T+1)+y(n-T+1))
  5448. + g2*(y(n-T+2)+y(n-T+2)))
  5449. ]]>
  5450. </artwork>
  5451. </figure>
  5452. During a transition between different gains, a smooth transition is calculated
  5453. using the square of the MDCT window. It is important that values of y(n) be
  5454. interpolated one at a time such that the past value of y(n) used is interpolated.
  5455. </t>
  5456. </section>
  5457. <section anchor="deemphasis" title="De-emphasis">
  5458. <t>
  5459. After the post-filter,
  5460. the signal is de-emphasized using the inverse of the pre-emphasis filter
  5461. used in the encoder:
  5462. <figure align="center">
  5463. <artwork align="center"><![CDATA[
  5464. 1 1
  5465. ---- = ---------------
  5466. A(z) -1
  5467. 1 - alpha_p*z
  5468. ]]></artwork>
  5469. </figure>
  5470. where alpha_p=0.8500061035.
  5471. </t>
  5472. </section>
  5473. </section>
  5474. </section>
  5475. <section anchor="Packet Loss Concealment" title="Packet Loss Concealment (PLC)">
  5476. <t>
  5477. Packet Loss Concealment (PLC) is an optional decoder-side feature that
  5478. SHOULD be included when receiving from an unreliable channel. Because
  5479. PLC is not part of the bitstream, there are many acceptable ways to
  5480. implement PLC with different complexity/quality trade-offs.
  5481. </t>
  5482. <t>
  5483. The PLC in
  5484. the reference implementation depends on the mode of last packet received.
  5485. In CELT mode, the PLC finds a periodicity in the decoded
  5486. signal and repeats the windowed waveform using the pitch offset. The windowed
  5487. waveform is overlapped in such a way as to preserve the time-domain aliasing
  5488. cancellation with the previous frame and the next frame. This is implemented
  5489. in celt_decode_lost() (mdct.c). In SILK mode, the PLC uses LPC extrapolation
  5490. from the previous frame, implemented in silk_PLC() (PLC.c).
  5491. </t>
  5492. <section anchor="clock-drift" title="Clock Drift Compensation">
  5493. <t>
  5494. Clock drift refers to the gradual desynchronization of two endpoints
  5495. whose sample clocks run at different frequencies while they are streaming
  5496. live audio. Differences in clock frequencies are generally attributable to
  5497. manufacturing variation in the endpoints' clock hardware. For long-lived
  5498. streams, the time difference between sender and receiver can grow without
  5499. bound.
  5500. </t>
  5501. <t>
  5502. When the sender's clock runs slower than the receiver's, the effect is similar
  5503. to packet loss: too few packets are received. The receiver can distinguish
  5504. between drift and loss if the transport provides packet timestamps. A receiver
  5505. for live streams SHOULD conceal the effects of drift, and it MAY do so by invoking
  5506. the PLC.
  5507. </t>
  5508. <t>
  5509. When the sender's clock runs faster than the receiver's, too many packets will
  5510. be received. The receiver MAY respond by skipping any packet (i.e., not
  5511. submitting the packet for decoding). This is likely to produce a less severe
  5512. artifact than if the frame were dropped after decoding.
  5513. </t>
  5514. <t>
  5515. A decoder MAY employ a more sophisticated drift compensation method. For
  5516. example, the
  5517. <xref target='GOOGLE-NETEQ'>NetEQ component</xref>
  5518. of the
  5519. <xref target='GOOGLE-WEBRTC'>Google WebRTC codebase</xref>
  5520. compensates for drift by adding or removing
  5521. one period when the signal is highly periodic. The reference implementation of
  5522. Opus allows a caller to learn whether the current frame's signal is highly
  5523. periodic, and if so what the period is, using the OPUS_GET_PITCH() request.
  5524. </t>
  5525. </section>
  5526. </section>
  5527. <section anchor="switching" title="Configuration Switching">
  5528. <t>
  5529. Switching between the Opus coding modes, audio bandwidths, and channel counts
  5530. requires careful consideration to avoid audible glitches.
  5531. Switching between any two configurations of the CELT-only mode, any two
  5532. configurations of the Hybrid mode, or from WB SILK to Hybrid mode does not
  5533. require any special treatment in the decoder, as the MDCT overlap will smooth
  5534. the transition.
  5535. Switching from Hybrid mode to WB SILK requires adding in the final contents
  5536. of the CELT overlap buffer to the first SILK-only packet.
  5537. This can be done by decoding a 2.5&nbsp;ms silence frame with the CELT decoder
  5538. using the channel count of the SILK-only packet (and any choice of audio
  5539. bandwidth), which will correctly handle the cases when the channel count
  5540. changes as well.
  5541. </t>
  5542. <t>
  5543. When changing the channel count for SILK-only or Hybrid packets, the encoder
  5544. can avoid glitches by smoothly varying the stereo width of the input signal
  5545. before or after the transition, and it SHOULD do so.
  5546. However, other transitions between SILK-only packets or between NB or MB SILK
  5547. and Hybrid packets may cause glitches, because neither the LSF coefficients
  5548. nor the LTP, LPC, stereo unmixing, and resampler buffers are available at the
  5549. new sample rate.
  5550. These switches SHOULD be delayed by the encoder until quiet periods or
  5551. transients, where the inevitable glitches will be less audible. Additionally,
  5552. the bitstream MAY include redundant side information ("redundancy"), in the
  5553. form of additional CELT frames embedded in each of the Opus frames around the
  5554. transition.
  5555. </t>
  5556. <t>
  5557. The other transitions that cannot be easily handled are those where the lower
  5558. frequencies switch between the SILK LP-based model and the CELT MDCT model.
  5559. However, an encoder may not have an opportunity to delay such a switch to a
  5560. convenient point.
  5561. For example, if the content switches from speech to music, and the encoder does
  5562. not have enough latency in its analysis to detect this in advance, there may
  5563. be no convenient silence period during which to make the transition for quite
  5564. some time.
  5565. To avoid or reduce glitches during these problematic mode transitions, and
  5566. between audio bandwidth changes in the SILK-only modes, transitions MAY
  5567. include redundant side information ("redundancy"), in the form of an
  5568. additional CELT frame embedded in the Opus frame.
  5569. </t>
  5570. <t>
  5571. A transition between coding the lower frequencies with the LP model and the
  5572. MDCT model or a transition that involves changing the SILK bandwidth
  5573. is only normatively specified when it includes redundancy.
  5574. For those without redundancy, it is RECOMMENDED that the decoder use a
  5575. concealment technique (e.g., make use of a PLC algorithm) to "fill in" the
  5576. gap or discontinuity caused by the mode transition.
  5577. Therefore, PLC MUST NOT be applied during any normative transition, i.e., when
  5578. <list style="symbols">
  5579. <t>A packet includes redundancy for this transition (as described below),</t>
  5580. <t>The transition is between any WB SILK packet and any Hybrid packet, or vice
  5581. versa,</t>
  5582. <t>The transition is between any two Hybrid mode packets, or</t>
  5583. <t>The transition is between any two CELT mode packets,</t>
  5584. </list>
  5585. unless there is actual packet loss.
  5586. </t>
  5587. <section anchor="side-info" title="Transition Side Information (Redundancy)">
  5588. <t>
  5589. Transitions with side information include an extra 5&nbsp;ms "redundant" CELT
  5590. frame within the Opus frame.
  5591. This frame is designed to fill in the gap or discontinuity in the different
  5592. layers without requiring the decoder to conceal it.
  5593. For transitions from CELT-only to SILK-only or Hybrid, the redundant frame is
  5594. inserted in the first Opus frame after the transition (i.e., the first
  5595. SILK-only or Hybrid frame).
  5596. For transitions from SILK-only or Hybrid to CELT-only, the redundant frame is
  5597. inserted in the last Opus frame before the transition (i.e., the last
  5598. SILK-only or Hybrid frame).
  5599. </t>
  5600. <section anchor="opus_redundancy_flag" title="Redundancy Flag">
  5601. <t>
  5602. The presence of redundancy is signaled in all SILK-only and Hybrid frames, not
  5603. just those involved in a mode transition.
  5604. This allows the frames to be decoded correctly even if an adjacent frame is
  5605. lost.
  5606. For SILK-only frames, this signaling is implicit, based on the size of the
  5607. Opus frame and the number of bits consumed decoding the SILK portion of it.
  5608. After decoding the SILK portion of the Opus frame, the decoder uses ec_tell()
  5609. (see <xref target="ec_tell"/>) to check if there are at least 17 bits
  5610. remaining.
  5611. If so, then the frame contains redundancy.
  5612. </t>
  5613. <t>
  5614. For Hybrid frames, this signaling is explicit.
  5615. After decoding the SILK portion of the Opus frame, the decoder uses ec_tell()
  5616. (see <xref target="ec_tell"/>) to ensure there are at least 37 bits remaining.
  5617. If so, it reads a symbol with the PDF in
  5618. <xref target="opus_redundancy_flag_pdf"/>, and if the value is 1, then the
  5619. frame contains redundancy.
  5620. Otherwise (if there were fewer than 37 bits left or the value was 0), the frame
  5621. does not contain redundancy.
  5622. </t>
  5623. <?rfc compact="no" ?>
  5624. <texttable anchor="opus_redundancy_flag_pdf" title="Redundancy Flag PDF">
  5625. <ttcol>PDF</ttcol>
  5626. <c>{4095, 1}/4096</c>
  5627. </texttable>
  5628. <?rfc compact="yes" ?>
  5629. </section>
  5630. <section anchor="opus_redundancy_pos" title="Redundancy Position Flag">
  5631. <t>
  5632. Since the current frame is a SILK-only or a Hybrid frame, it must be at least
  5633. 10&nbsp;ms.
  5634. Therefore, it needs an additional flag to indicate whether the redundant
  5635. 5&nbsp;ms CELT frame should be mixed into the beginning of the current frame,
  5636. or the end.
  5637. After determining that a frame contains redundancy, the decoder reads a
  5638. 1&nbsp;bit symbol with a uniform PDF
  5639. (<xref target="opus_redundancy_pos_pdf"/>).
  5640. </t>
  5641. <?rfc compact="no" ?>
  5642. <texttable anchor="opus_redundancy_pos_pdf" title="Redundancy Position PDF">
  5643. <ttcol>PDF</ttcol>
  5644. <c>{1, 1}/2</c>
  5645. </texttable>
  5646. <?rfc compact="yes" ?>
  5647. <t>
  5648. If the value is zero, this is the first frame in the transition, and the
  5649. redundancy belongs at the end.
  5650. If the value is one, this is the second frame in the transition, and the
  5651. redundancy belongs at the beginning.
  5652. There is no way to specify that an Opus frame contains separate redundant CELT
  5653. frames at both the beginning and the end.
  5654. </t>
  5655. </section>
  5656. <section anchor="opus_redundancy_size" title="Redundancy Size">
  5657. <t>
  5658. Unlike the CELT portion of a Hybrid frame, the redundant CELT frame does not
  5659. use the same entropy coder state as the rest of the Opus frame, because this
  5660. would break the CELT bit allocation mechanism in Hybrid frames.
  5661. Thus, a redundant CELT frame always starts and ends on a byte boundary, even in
  5662. SILK-only frames, where this is not strictly necessary.
  5663. </t>
  5664. <t>
  5665. For SILK-only frames, the number of bytes in the redundant CELT frame is simply
  5666. the number of whole bytes remaining, which must be at least 2, due to the
  5667. space check in <xref target="opus_redundancy_flag"/>.
  5668. For Hybrid frames, the number of bytes is equal to 2, plus a decoded unsigned
  5669. integer less than 256 (see <xref target="ec_dec_uint"/>).
  5670. This may be more than the number of whole bytes remaining in the Opus frame,
  5671. in which case the frame is invalid.
  5672. However, a decoder is not required to ignore the entire frame, as this may be
  5673. the result of a bit error that desynchronized the range coder.
  5674. There may still be useful data before the error, and a decoder MAY keep any
  5675. audio decoded so far instead of invoking the PLC, but it is RECOMMENDED that
  5676. the decoder stop decoding and discard the rest of the current Opus frame.
  5677. </t>
  5678. <t>
  5679. It would have been possible to avoid these invalid states in the design of Opus
  5680. by limiting the range of the explicit length decoded from Hybrid frames by the
  5681. actual number of whole bytes remaining.
  5682. However, this would require an encoder to determine the rate allocation for the
  5683. MDCT layer up front, before it began encoding that layer.
  5684. By allowing some invalid sizes, the encoder is able to defer that decision
  5685. until much later.
  5686. When encoding Hybrid frames that do not include redundancy, the encoder must
  5687. still decide up front if it wishes to use the minimum 37 bits required to
  5688. trigger encoding of the redundancy flag, but this is a much looser
  5689. restriction.
  5690. </t>
  5691. <t>
  5692. After determining the size of the redundant CELT frame, the decoder reduces
  5693. the size of the buffer currently in use by the range coder by that amount.
  5694. The MDCT layer reads any raw bits from the end of this reduced buffer, and all
  5695. calculations of the number of bits remaining in the buffer must be done using
  5696. this new, reduced size, rather than the original size of the Opus frame.
  5697. </t>
  5698. </section>
  5699. <section anchor="opus_redundancy_decoding" title="Decoding the Redundancy">
  5700. <t>
  5701. The redundant frame is decoded like any other CELT-only frame, with the
  5702. exception that it does not contain a TOC byte.
  5703. The frame size is fixed at 5&nbsp;ms, the channel count is set to that of the
  5704. current frame, and the audio bandwidth is also set to that of the current
  5705. frame, with the exception that for MB SILK frames, it is set to WB.
  5706. </t>
  5707. <t>
  5708. If the redundancy belongs at the beginning (in a CELT-only to SILK-only or
  5709. Hybrid transition), the final reconstructed output uses the first 2.5&nbsp;ms
  5710. of audio output by the decoder for the redundant frame as is, discarding
  5711. the corresponding output from the SILK-only or Hybrid portion of the frame.
  5712. The remaining 2.5&nbsp;ms is cross-lapped with the decoded SILK/Hybrid signal
  5713. using the CELT's power-complementary MDCT window to ensure a smooth
  5714. transition.
  5715. </t>
  5716. <t>
  5717. If the redundancy belongs at the end (in a SILK-only or Hybrid to CELT-only
  5718. transition), only the second half (2.5&nbsp;ms) of the audio output by the
  5719. decoder for the redundant frame is used.
  5720. In that case, the second half of the redundant frame is cross-lapped with the
  5721. end of the SILK/Hybrid signal, again using CELT's power-complementary MDCT
  5722. window to ensure a smooth transition.
  5723. </t>
  5724. </section>
  5725. </section>
  5726. <section anchor="decoder-reset" title="State Reset">
  5727. <t>
  5728. When a transition occurs, the state of the SILK or the CELT decoder (or both)
  5729. may need to be reset before decoding a frame in the new mode.
  5730. This avoids reusing "out of date" memory, which may not have been updated in
  5731. some time or may not be in a well-defined state due to, e.g., PLC.
  5732. The SILK state is reset before every SILK-only or Hybrid frame where the
  5733. previous frame was CELT-only.
  5734. The CELT state is reset every time the operating mode changes and the new mode
  5735. is either Hybrid or CELT-only, except when the transition uses redundancy as
  5736. described above.
  5737. When switching from SILK-only or Hybrid to CELT-only with redundancy, the CELT
  5738. state is reset before decoding the redundant CELT frame embedded in the
  5739. SILK-only or Hybrid frame, but it is not reset before decoding the following
  5740. CELT-only frame.
  5741. When switching from CELT-only mode to SILK-only or Hybrid mode with redundancy,
  5742. the CELT decoder is not reset for decoding the redundant CELT frame.
  5743. </t>
  5744. </section>
  5745. <section title="Summary of Transitions">
  5746. <t>
  5747. <xref target="normative_transitions"/> illustrates all of the normative
  5748. transitions involving a mode change, an audio bandwidth change, or both.
  5749. Each one uses an S, H, or C to represent an Opus frame in the corresponding
  5750. mode.
  5751. In addition, an R indicates the presence of redundancy in the Opus frame with which it is
  5752. cross-lapped.
  5753. Its location in the first or last 5&nbsp;ms is assumed to correspond to whether
  5754. it is the frame before or after the transition.
  5755. Other uses of redundancy are non-normative.
  5756. Finally, a c indicates the contents of the CELT overlap buffer after the
  5757. previously decoded frame (i.e., as extracted by decoding a silence frame).
  5758. <figure align="center" anchor="normative_transitions"
  5759. title="Normative Transitions">
  5760. <artwork align="center"><![CDATA[
  5761. SILK to SILK with Redundancy: S -> S -> S
  5762. &
  5763. !R -> R
  5764. &
  5765. ;S -> S -> S
  5766. NB or MB SILK to Hybrid with Redundancy: S -> S -> S
  5767. &
  5768. !R ->;H -> H -> H
  5769. WB SILK to Hybrid: S -> S -> S ->!H -> H -> H
  5770. SILK to CELT with Redundancy: S -> S -> S
  5771. &
  5772. !R -> C -> C -> C
  5773. Hybrid to NB or MB SILK with Redundancy: H -> H -> H
  5774. &
  5775. !R -> R
  5776. &
  5777. ;S -> S -> S
  5778. Hybrid to WB SILK: H -> H -> H -> c
  5779. \ +
  5780. > S -> S -> S
  5781. Hybrid to CELT with Redundancy: H -> H -> H
  5782. &
  5783. !R -> C -> C -> C
  5784. CELT to SILK with Redundancy: C -> C -> C -> R
  5785. &
  5786. ;S -> S -> S
  5787. CELT to Hybrid with Redundancy: C -> C -> C -> R
  5788. &
  5789. |H -> H -> H
  5790. Key:
  5791. S SILK-only frame ; SILK decoder reset
  5792. H Hybrid frame | CELT and SILK decoder resets
  5793. C CELT-only frame ! CELT decoder reset
  5794. c CELT overlap + Direct mixing
  5795. R Redundant CELT frame & Windowed cross-lap
  5796. ]]></artwork>
  5797. </figure>
  5798. The first two and the last two Opus frames in each example are illustrative,
  5799. i.e., there is no requirement that a stream remain in the same configuration
  5800. for three consecutive frames before or after a switch.
  5801. </t>
  5802. <t>
  5803. The behavior of transitions without redundancy where PLC is allowed is non-normative.
  5804. An encoder might still wish to use these transitions if, for example, it
  5805. doesn't want to add the extra bitrate required for redundancy or if it makes
  5806. a decision to switch after it has already transmitted the frame that would
  5807. have had to contain the redundancy.
  5808. <xref target="nonnormative_transitions"/> illustrates the recommended
  5809. cross-lapping and decoder resets for these transitions.
  5810. <figure align="center" anchor="nonnormative_transitions"
  5811. title="Recommended Non-Normative Transitions">
  5812. <artwork align="center"><![CDATA[
  5813. SILK to SILK (audio bandwidth change): S -> S -> S ;S -> S -> S
  5814. NB or MB SILK to Hybrid: S -> S -> S |H -> H -> H
  5815. SILK to CELT without Redundancy: S -> S -> S -> P
  5816. &
  5817. !C -> C -> C
  5818. Hybrid to NB or MB SILK: H -> H -> H -> c
  5819. +
  5820. ;S -> S -> S
  5821. Hybrid to CELT without Redundancy: H -> H -> H -> P
  5822. &
  5823. !C -> C -> C
  5824. CELT to SILK without Redundancy: C -> C -> C -> P
  5825. &
  5826. ;S -> S -> S
  5827. CELT to Hybrid without Redundancy: C -> C -> C -> P
  5828. &
  5829. |H -> H -> H
  5830. Key:
  5831. S SILK-only frame ; SILK decoder reset
  5832. H Hybrid frame | CELT and SILK decoder resets
  5833. C CELT-only frame ! CELT decoder reset
  5834. c CELT overlap + Direct mixing
  5835. P Packet Loss Concealment & Windowed cross-lap
  5836. ]]></artwork>
  5837. </figure>
  5838. Encoders SHOULD NOT use other transitions, e.g., those that involve redundancy
  5839. in ways not illustrated in <xref target="normative_transitions"/>.
  5840. </t>
  5841. </section>
  5842. </section>
  5843. </section>
  5844. <!-- ******************************************************************* -->
  5845. <!-- ************************** OPUS ENCODER *********************** -->
  5846. <!-- ******************************************************************* -->
  5847. <section title="Opus Encoder">
  5848. <t>
  5849. Just like the decoder, the Opus encoder also normally consists of two main blocks: the
  5850. SILK encoder and the CELT encoder. However, unlike the case of the decoder, a valid
  5851. (though potentially suboptimal) Opus encoder is not required to support all modes and
  5852. may thus only include a SILK encoder module or a CELT encoder module.
  5853. The output bitstream of the Opus encoding contains bits from the SILK and CELT
  5854. encoders, though these are not separable due to the use of a range coder.
  5855. A block diagram of the encoder is illustrated below.
  5856. <figure align="center" anchor="opus-encoder-figure" title="Opus Encoder">
  5857. <artwork>
  5858. <![CDATA[
  5859. +------------+ +---------+
  5860. | Sample | | SILK |------+
  5861. +->| Rate |--->| Encoder | V
  5862. +-----------+ | | Conversion | | | +---------+
  5863. | Optional | | +------------+ +---------+ | Range |
  5864. ->| High-pass |--+ | Encoder |---->
  5865. | Filter | | +--------------+ +---------+ | | Bit-
  5866. +-----------+ | | Delay | | CELT | +---------+ stream
  5867. +->| Compensation |->| Encoder | ^
  5868. | | | |------+
  5869. +--------------+ +---------+
  5870. ]]>
  5871. </artwork>
  5872. </figure>
  5873. </t>
  5874. <t>
  5875. For a normal encoder where both the SILK and the CELT modules are included, an optimal
  5876. encoder should select which coding mode to use at run-time depending on the conditions.
  5877. In the reference implementation, the frame size is selected by the application, but the
  5878. other configuration parameters (number of channels, bandwidth, mode) are automatically
  5879. selected (unless explicitly overridden by the application) depending on the following:
  5880. <list style="symbols">
  5881. <t>Requested bitrate</t>
  5882. <t>Input sampling rate</t>
  5883. <t>Type of signal (speech vs. music)</t>
  5884. <t>Frame size in use</t>
  5885. </list>
  5886. The type of signal currently needs to be provided by the application (though it can be
  5887. changed in real-time). An Opus encoder implementation could also do automatic detection,
  5888. but since Opus is an interactive codec, such an implementation would likely have to either
  5889. delay the signal (for non-interactive applications) or delay the mode switching decisions (for
  5890. interactive applications).
  5891. </t>
  5892. <t>
  5893. When the encoder is configured for voice over IP applications, the input signal is
  5894. filtered by a high-pass filter to remove the lowest part of the spectrum
  5895. that contains little speech energy and may contain background noise. This is a second order
  5896. Auto Regressive Moving Average (i.e., with poles and zeros) filter with a cut-off frequency around 50&nbsp;Hz.
  5897. In the future, a music detector may also be used to lower the cut-off frequency when the
  5898. input signal is detected to be music rather than speech.
  5899. </t>
  5900. <section anchor="range-encoder" title="Range Encoder">
  5901. <t>
  5902. The range coder acts as the bit-packer for Opus.
  5903. It is used in three different ways: to encode
  5904. <list style="symbols">
  5905. <t>
  5906. Entropy-coded symbols with a fixed probability model using ec_encode()
  5907. (entenc.c),
  5908. </t>
  5909. <t>
  5910. Integers from 0 to (2**M&nbsp;-&nbsp;1) using ec_enc_uint() or ec_enc_bits()
  5911. (entenc.c),</t>
  5912. <t>
  5913. Integers from 0 to (ft&nbsp;-&nbsp;1) (where ft is not a power of two) using
  5914. ec_enc_uint() (entenc.c).
  5915. </t>
  5916. </list>
  5917. </t>
  5918. <t>
  5919. The range encoder maintains an internal state vector composed of the four-tuple
  5920. (val,&nbsp;rng,&nbsp;rem,&nbsp;ext) representing the low end of the current
  5921. range, the size of the current range, a single buffered output byte, and a
  5922. count of additional carry-propagating output bytes.
  5923. Both val and rng are 32-bit unsigned integer values, rem is a byte value or
  5924. less than 255 or the special value -1, and ext is an unsigned integer with at
  5925. least 11 bits.
  5926. This state vector is initialized at the start of each frame to the value
  5927. (0,&nbsp;2**31,&nbsp;-1,&nbsp;0).
  5928. After encoding a sequence of symbols, the value of rng in the encoder should
  5929. exactly match the value of rng in the decoder after decoding the same sequence
  5930. of symbols.
  5931. This is a powerful tool for detecting errors in either an encoder or decoder
  5932. implementation.
  5933. The value of val, on the other hand, represents different things in the encoder
  5934. and decoder, and is not expected to match.
  5935. </t>
  5936. <t>
  5937. The decoder has no analog for rem and ext.
  5938. These are used to perform carry propagation in the renormalization loop below.
  5939. Each iteration of this loop produces 9 bits of output, consisting of 8 data
  5940. bits and a carry flag.
  5941. The encoder cannot determine the final value of the output bytes until it
  5942. propagates these carry flags.
  5943. Therefore, the reference implementation buffers a single non-propagating output
  5944. byte (i.e., one less than 255) in rem and keeps a count of additional
  5945. propagating (i.e., 255) output bytes in ext.
  5946. An implementation may choose to use any mathematically equivalent scheme to
  5947. perform carry propagation.
  5948. </t>
  5949. <section anchor="encoding-symbols" title="Encoding Symbols">
  5950. <t>
  5951. The main encoding function is ec_encode() (entenc.c), which encodes symbol k in
  5952. the current context using the same three-tuple (fl[k],&nbsp;fh[k],&nbsp;ft)
  5953. as the decoder to describe the range of the symbol (see
  5954. <xref target="range-decoder"/>).
  5955. </t>
  5956. <t>
  5957. ec_encode() updates the state of the encoder as follows.
  5958. If fl[k] is greater than zero, then
  5959. <figure align="center">
  5960. <artwork align="center"><![CDATA[
  5961. rng
  5962. val = val + rng - --- * (ft - fl)
  5963. ft
  5964. rng
  5965. rng = --- * (fh - fl)
  5966. ft
  5967. ]]></artwork>
  5968. </figure>
  5969. Otherwise, val is unchanged and
  5970. <figure align="center">
  5971. <artwork align="center"><![CDATA[
  5972. rng
  5973. rng = rng - --- * (fh - fl)
  5974. ft
  5975. ]]></artwork>
  5976. </figure>
  5977. The divisions here are integer division.
  5978. </t>
  5979. <section anchor="range-encoder-renorm" title="Renormalization">
  5980. <t>
  5981. After this update, the range is normalized using a procedure very similar to
  5982. that of <xref target="range-decoder-renorm"/>, implemented by
  5983. ec_enc_normalize() (entenc.c).
  5984. The following process is repeated until rng&nbsp;&gt;&nbsp;2**23.
  5985. First, the top 9 bits of val, (val&gt;&gt;23), are sent to the carry buffer,
  5986. described in <xref target="ec_enc_carry_out"/>.
  5987. Then, the encoder sets
  5988. <figure align="center">
  5989. <artwork align="center"><![CDATA[
  5990. val = (val<<8) & 0x7FFFFFFF
  5991. rng = rng<<8
  5992. ]]></artwork>
  5993. </figure>
  5994. </t>
  5995. </section>
  5996. <section anchor="ec_enc_carry_out"
  5997. title="Carry Propagation and Output Buffering">
  5998. <t>
  5999. The function ec_enc_carry_out() (entenc.c) implements carry propagation and
  6000. output buffering.
  6001. It takes, as input, a 9-bit unsigned value, c, consisting of 8 data bits and an
  6002. additional carry bit.
  6003. If c is equal to the value 255, then ext is simply incremented, and no other
  6004. state updates are performed.
  6005. Otherwise, let b&nbsp;=&nbsp;(c&gt;&gt;8) be the carry bit.
  6006. Then,
  6007. <list style="symbols">
  6008. <t>
  6009. If the buffered byte rem contains a value other than -1, the encoder outputs
  6010. the byte (rem&nbsp;+&nbsp;b).
  6011. Otherwise, if rem is -1, no byte is output.
  6012. </t>
  6013. <t>
  6014. If ext is non-zero, then the encoder outputs ext bytes -- all with a value of 0
  6015. if b is set, or 255 if b is unset -- and sets ext to 0.
  6016. </t>
  6017. <t>
  6018. rem is set to the 8 data bits:
  6019. <figure align="center">
  6020. <artwork align="center"><![CDATA[
  6021. rem = c & 255
  6022. ]]></artwork>
  6023. </figure>
  6024. </t>
  6025. </list>
  6026. </t>
  6027. </section>
  6028. </section>
  6029. <section anchor="encoding-alternate" title="Alternate Encoding Methods">
  6030. <t>
  6031. The reference implementation uses three additional encoding methods that are
  6032. exactly equivalent to the above, but make assumptions and simplifications that
  6033. allow for a more efficient implementation.
  6034. </t>
  6035. <section anchor="ec_encode_bin" title="ec_encode_bin()">
  6036. <t>
  6037. The first is ec_encode_bin() (entenc.c), defined using the parameter ftb
  6038. instead of ft.
  6039. It is mathematically equivalent to calling ec_encode() with
  6040. ft&nbsp;=&nbsp;(1&lt;&lt;ftb), but it avoids using division.
  6041. </t>
  6042. </section>
  6043. <section anchor="ec_enc_bit_logp" title="ec_enc_bit_logp()">
  6044. <t>
  6045. The next is ec_enc_bit_logp() (entenc.c), which encodes a single binary symbol.
  6046. The context is described by a single parameter, logp, which is the absolute
  6047. value of the base-2 logarithm of the probability of a "1".
  6048. It is mathematically equivalent to calling ec_encode() with the 3-tuple
  6049. (fl[k]&nbsp;=&nbsp;0, fh[k]&nbsp;=&nbsp;(1&lt;&lt;logp)&nbsp;-&nbsp;1,
  6050. ft&nbsp;=&nbsp;(1&lt;&lt;logp)) if k is 0 and with
  6051. (fl[k]&nbsp;=&nbsp;(1&lt;&lt;logp)&nbsp;-&nbsp;1,
  6052. fh[k]&nbsp;=&nbsp;ft&nbsp;=&nbsp;(1&lt;&lt;logp)) if k is 1.
  6053. The implementation requires no multiplications or divisions.
  6054. </t>
  6055. </section>
  6056. <section anchor="ec_enc_icdf" title="ec_enc_icdf()">
  6057. <t>
  6058. The last is ec_enc_icdf() (entenc.c), which encodes a single binary symbol with
  6059. a table-based context of up to 8 bits.
  6060. This uses the same icdf table as ec_dec_icdf() from
  6061. <xref target="ec_dec_icdf"/>.
  6062. The function is mathematically equivalent to calling ec_encode() with
  6063. fl[k]&nbsp;=&nbsp;(1&lt;&lt;ftb)&nbsp;-&nbsp;icdf[k-1] (or 0 if
  6064. k&nbsp;==&nbsp;0), fh[k]&nbsp;=&nbsp;(1&lt;&lt;ftb)&nbsp;-&nbsp;icdf[k], and
  6065. ft&nbsp;=&nbsp;(1&lt;&lt;ftb).
  6066. This only saves a few arithmetic operations over ec_encode_bin(), but it allows
  6067. the encoder to use the same icdf tables as the decoder.
  6068. </t>
  6069. </section>
  6070. </section>
  6071. <section anchor="encoding-bits" title="Encoding Raw Bits">
  6072. <t>
  6073. The raw bits used by the CELT layer are packed at the end of the buffer using
  6074. ec_enc_bits() (entenc.c).
  6075. Because the raw bits may continue into the last byte output by the range coder
  6076. if there is room in the low-order bits, the encoder must be prepared to merge
  6077. these values into a single byte.
  6078. The procedure in <xref target="encoder-finalizing"/> does this in a way that
  6079. ensures both the range coded data and the raw bits can be decoded
  6080. successfully.
  6081. </t>
  6082. </section>
  6083. <section anchor="encoding-ints" title="Encoding Uniformly Distributed Integers">
  6084. <t>
  6085. The function ec_enc_uint() (entenc.c) encodes one of ft equiprobable symbols in
  6086. the range 0 to (ft&nbsp;-&nbsp;1), inclusive, each with a frequency of 1,
  6087. where ft may be as large as (2**32&nbsp;-&nbsp;1).
  6088. Like the decoder (see <xref target="ec_dec_uint"/>), it splits up the
  6089. value into a range coded symbol representing up to 8 of the high bits, and, if
  6090. necessary, raw bits representing the remainder of the value.
  6091. </t>
  6092. <t>
  6093. ec_enc_uint() takes a two-tuple (t,&nbsp;ft), where t is the unsigned integer
  6094. to be encoded, 0&nbsp;&lt;=&nbsp;t&nbsp;&lt;&nbsp;ft, and ft is not
  6095. necessarily a power of two.
  6096. Let ftb&nbsp;=&nbsp;ilog(ft&nbsp;-&nbsp;1), i.e., the number of bits required
  6097. to store (ft&nbsp;-&nbsp;1) in two's complement notation.
  6098. If ftb is 8 or less, then t is encoded directly using ec_encode() with the
  6099. three-tuple (t, t&nbsp;+&nbsp;1, ft).
  6100. </t>
  6101. <t>
  6102. If ftb is greater than 8, then the top 8 bits of t are encoded using the
  6103. three-tuple (t&gt;&gt;(ftb&nbsp;-&nbsp;8),
  6104. (t&gt;&gt;(ftb&nbsp;-&nbsp;8))&nbsp;+&nbsp;1,
  6105. ((ft&nbsp;-&nbsp;1)&gt;&gt;(ftb&nbsp;-&nbsp;8))&nbsp;+&nbsp;1), and the
  6106. remaining bits,
  6107. (t&nbsp;&amp;&nbsp;((1&lt;&lt;(ftb&nbsp;-&nbsp;8))&nbsp;-&nbsp;1),
  6108. are encoded as raw bits with ec_enc_bits().
  6109. </t>
  6110. </section>
  6111. <section anchor="encoder-finalizing" title="Finalizing the Stream">
  6112. <t>
  6113. After all symbols are encoded, the stream must be finalized by outputting a
  6114. value inside the current range.
  6115. Let end be the unsigned integer in the interval [val,&nbsp;val&nbsp;+&nbsp;rng)
  6116. with the largest number of trailing zero bits, b, such that
  6117. (end&nbsp;+&nbsp;(1&lt;&lt;b)&nbsp;-&nbsp;1) is also in the interval
  6118. [val,&nbsp;val&nbsp;+&nbsp;rng).
  6119. This choice of end allows the maximum number of trailing bits to be set to
  6120. arbitrary values while still ensuring the range coded part of the buffer can
  6121. be decoded correctly.
  6122. Then, while end is not zero, the top 9 bits of end, i.e., (end&gt;&gt;23), are
  6123. passed to the carry buffer in accordance with the procedure in
  6124. <xref target="ec_enc_carry_out"/>, and end is updated via
  6125. <figure align="center">
  6126. <artwork align="center"><![CDATA[
  6127. end = (end<<8) & 0x7FFFFFFF
  6128. ]]></artwork>
  6129. </figure>
  6130. Finally, if the buffered output byte, rem, is neither zero nor the special
  6131. value -1, or the carry count, ext, is greater than zero, then 9 zero bits are
  6132. sent to the carry buffer to flush it to the output buffer.
  6133. When outputting the final byte from the range coder, if it would overlap any
  6134. raw bits already packed into the end of the output buffer, they should be ORed
  6135. into the same byte.
  6136. The bit allocation routines in the CELT layer should ensure that this can be
  6137. done without corrupting the range coder data so long as end is chosen as
  6138. described above.
  6139. If there is any space between the end of the range coder data and the end of
  6140. the raw bits, it is padded with zero bits.
  6141. This entire process is implemented by ec_enc_done() (entenc.c).
  6142. </t>
  6143. </section>
  6144. <section anchor="encoder-tell" title="Current Bit Usage">
  6145. <t>
  6146. The bit allocation routines in Opus need to be able to determine a
  6147. conservative upper bound on the number of bits that have been used
  6148. to encode the current frame thus far. This drives allocation
  6149. decisions and ensures that the range coder and raw bits will not
  6150. overflow the output buffer. This is computed in the
  6151. reference implementation to whole-bit precision by
  6152. the function ec_tell() (entcode.h) and to fractional 1/8th bit
  6153. precision by the function ec_tell_frac() (entcode.c).
  6154. Like all operations in the range coder, it must be implemented in a
  6155. bit-exact manner, and it must produce exactly the same value returned by
  6156. the same functions in the decoder after decoding the same symbols.
  6157. </t>
  6158. </section>
  6159. </section>
  6160. <section title='SILK Encoder'>
  6161. <t>
  6162. In many respects, the SILK encoder mirrors the SILK decoder described
  6163. in <xref target='silk_decoder_outline'/>.
  6164. Details such as the quantization and range coder tables can be found
  6165. there, while this section describes the high-level design choices that
  6166. were made.
  6167. The diagram below shows the basic modules of the SILK encoder.
  6168. <figure align="center" anchor="silk_encoder_figure" title="SILK Encoder">
  6169. <artwork>
  6170. <![CDATA[
  6171. +----------+ +--------+ +---------+
  6172. | Sample | | Stereo | | SILK |
  6173. ------>| Rate |--->| Mixing |--->| Core |---------->
  6174. Input |Conversion| | | | Encoder | Bitstream
  6175. +----------+ +--------+ +---------+
  6176. ]]>
  6177. </artwork>
  6178. </figure>
  6179. </t>
  6180. <section title='Sample Rate Conversion'>
  6181. <t>
  6182. The input signal's sampling rate is adjusted by a sample rate conversion
  6183. module so that it matches the SILK internal sampling rate.
  6184. The input to the sample rate converter is delayed by a number of samples
  6185. depending on the sample rate ratio, such that the overall delay is constant
  6186. for all input and output sample rates.
  6187. </t>
  6188. </section>
  6189. <section title='Stereo Mixing'>
  6190. <t>
  6191. The stereo mixer is only used for stereo input signals.
  6192. It converts a stereo left-right signal into an adaptive
  6193. mid-side representation.
  6194. The first step is to compute non-adaptive mid-side signals
  6195. as half the sum and difference between left and right signals.
  6196. The side signal is then minimized in energy by subtracting a
  6197. prediction of it based on the mid signal.
  6198. This prediction works well when the left and right signals
  6199. exhibit linear dependency, for instance, for an amplitude-panned
  6200. input signal.
  6201. Like in the decoder, the prediction coefficients are linearly
  6202. interpolated during the first 8&nbsp;ms of the frame.
  6203. The mid signal is always encoded, whereas the residual
  6204. side signal is only encoded if it has sufficient
  6205. energy compared to the mid signal's energy.
  6206. If it has not,
  6207. the "mid_only_flag" is set without encoding the side signal.
  6208. </t>
  6209. <t>
  6210. The predictor coefficients are coded regardless of whether
  6211. the side signal is encoded.
  6212. For each frame, two predictor coefficients are computed, one
  6213. that predicts between low-passed mid and side channels, and
  6214. one that predicts between high-passed mid and side channels.
  6215. The low-pass filter is a simple three-tap filter
  6216. and creates a delay of one sample.
  6217. The high-pass filtered signal is the difference between
  6218. the mid signal delayed by one sample and the low-passed
  6219. signal. Instead of explicitly computing the high-passed
  6220. signal, it is computationally more efficient to transform
  6221. the prediction coefficients before applying them to the
  6222. filtered mid signal, as follows:
  6223. <figure align="center">
  6224. <artwork align="center">
  6225. <![CDATA[
  6226. pred(n) = LP(n) * w0 + HP(n) * w1
  6227. = LP(n) * w0 + (mid(n-1) - LP(n)) * w1
  6228. = LP(n) * (w0 - w1) + mid(n-1) * w1
  6229. ]]>
  6230. </artwork>
  6231. </figure>
  6232. where w0 and w1 are the low-pass and high-pass prediction
  6233. coefficients, mid(n-1) is the mid signal delayed by one sample,
  6234. LP(n) and HP(n) are the low-passed and high-passed
  6235. signals and pred(n) is the prediction signal that is subtracted
  6236. from the side signal.
  6237. </t>
  6238. </section>
  6239. <section title='SILK Core Encoder'>
  6240. <t>
  6241. What follows is a description of the core encoder and its components.
  6242. For simplicity, the core encoder is referred to simply as the encoder in
  6243. the remainder of this section. An overview of the encoder is given in
  6244. <xref target="encoder_figure" />.
  6245. </t>
  6246. <figure align="center" anchor="encoder_figure" title="SILK Core Encoder">
  6247. <artwork align="center">
  6248. <![CDATA[
  6249. +---+
  6250. +--------------------------------->| |
  6251. +---------+ | +---------+ | |
  6252. |Voice | | |LTP |12 | |
  6253. +-->|Activity |--+ +----->|Scaling |-----------+---->| |
  6254. | |Detection|3 | | |Control |<--+ | | |
  6255. | +---------+ | | +---------+ | | | |
  6256. | | | +---------+ | | | |
  6257. | | | |Gains | | | | |
  6258. | | | +-->|Processor|---|---+---|---->| R |
  6259. | | | | | |11 | | | | a |
  6260. | \/ | | +---------+ | | | | n |
  6261. | +---------+ | | +---------+ | | | | g |
  6262. | |Pitch | | | |LSF | | | | | e |
  6263. | +->|Analysis |---+ | |Quantizer|---|---|---|---->| |
  6264. | | | |4 | | | |8 | | | | E |-->
  6265. | | +---------+ | | +---------+ | | | | n | 2
  6266. | | | | 9/\ 10| | | | | c |
  6267. | | | | | \/ | | | | o |
  6268. | | +---------+ | | +----------+ | | | | d |
  6269. | | |Noise | +--|-->|Prediction|--+---|---|---->| e |
  6270. | +->|Shaping |---|--+ |Analysis |7 | | | | r |
  6271. | | |Analysis |5 | | | | | | | | |
  6272. | | +---------+ | | +----------+ | | | | |
  6273. | | | | /\ | | | | |
  6274. | | +----------|--|--------+ | | | | |
  6275. | | | \/ \/ \/ \/ \/ | |
  6276. | | | +----------+ +------------+ | |
  6277. | | | | | |Noise | | |
  6278. -+-------+-----+----->|Pre-filter|--------->|Shaping |-->| |
  6279. 1 | | 6 |Quantization|13 | |
  6280. +----------+ +------------+ +---+
  6281. 1: Input speech signal
  6282. 2: Range encoded bitstream
  6283. 3: Voice activity estimate
  6284. 4: Pitch lags (per 5 ms) and voicing decision (per 20 ms)
  6285. 5: Noise shaping quantization coefficients
  6286. - Short-term synthesis and analysis
  6287. noise shaping coefficients (per 5 ms)
  6288. - Long-term synthesis and analysis noise
  6289. shaping coefficients (per 5 ms and for voiced speech only)
  6290. - Noise shaping tilt (per 5 ms)
  6291. - Quantizer gain/step size (per 5 ms)
  6292. 6: Input signal filtered with analysis noise shaping filters
  6293. 7: Short- and Long-Term Prediction coefficients
  6294. LTP (per 5 ms) and LPC (per 20 ms)
  6295. 8: LSF quantization indices
  6296. 9: LSF coefficients
  6297. 10: Quantized LSF coefficients
  6298. 11: Processed gains, and synthesis noise shape coefficients
  6299. 12: LTP state scaling coefficient. Controlling error
  6300. propagation / prediction gain trade-off
  6301. 13: Quantized signal
  6302. ]]>
  6303. </artwork>
  6304. </figure>
  6305. <section title='Voice Activity Detection'>
  6306. <t>
  6307. The input signal is processed by a Voice Activity Detection (VAD) algorithm to produce
  6308. a measure of voice activity, spectral tilt, and signal-to-noise estimates for
  6309. each frame. The VAD uses a sequence of half-band filterbanks to split the
  6310. signal into four subbands: 0...Fs/16, Fs/16...Fs/8, Fs/8...Fs/4, and
  6311. Fs/4...Fs/2, where Fs is the sampling frequency (8, 12, 16, or 24&nbsp;kHz).
  6312. The lowest subband, from 0 - Fs/16, is high-pass filtered with a first-order
  6313. moving average (MA) filter (with transfer function H(z) = 1-z**(-1)) to
  6314. reduce the energy at the lowest frequencies. For each frame, the signal
  6315. energy per subband is computed.
  6316. In each subband, a noise level estimator tracks the background noise level
  6317. and a Signal-to-Noise Ratio (SNR) value is computed as the logarithm of the
  6318. ratio of energy-to-noise level.
  6319. Using these intermediate variables, the following parameters are calculated
  6320. for use in other SILK modules:
  6321. <list style="symbols">
  6322. <t>
  6323. Average SNR. The average of the subband SNR values.
  6324. </t>
  6325. <t>
  6326. Smoothed subband SNRs. Temporally smoothed subband SNR values.
  6327. </t>
  6328. <t>
  6329. Speech activity level. Based on the average SNR and a weighted average of the
  6330. subband energies.
  6331. </t>
  6332. <t>
  6333. Spectral tilt. A weighted average of the subband SNRs, with positive weights
  6334. for the low subbands and negative weights for the high subbands.
  6335. </t>
  6336. </list>
  6337. </t>
  6338. </section>
  6339. <section title='Pitch Analysis' anchor='pitch_estimator_overview_section'>
  6340. <t>
  6341. The input signal is processed by the open loop pitch estimator shown in
  6342. <xref target='pitch_estimator_figure' />.
  6343. <figure align="center" anchor="pitch_estimator_figure"
  6344. title="Block Diagram of the Pitch Estimator">
  6345. <artwork align="center">
  6346. <![CDATA[
  6347. +--------+ +----------+
  6348. |2 x Down| |Time- |
  6349. +->|sampling|->|Correlator| |
  6350. | | | | | |4
  6351. | +--------+ +----------+ \/
  6352. | | 2 +-------+
  6353. | | +-->|Speech |5
  6354. +---------+ +--------+ | \/ | |Type |->
  6355. |LPC | |Down | | +----------+ | |
  6356. +->|Analysis | +->|sample |-+------------->|Time- | +-------+
  6357. | | | | |to 8 kHz| |Correlator|----------->
  6358. | +---------+ | +--------+ |__________| 6
  6359. | | | |3
  6360. | \/ | \/
  6361. | +---------+ | +----------+
  6362. | |Whitening| | |Time- |
  6363. -+->|Filter |-+--------------------------->|Correlator|----------->
  6364. 1 | | | | 7
  6365. +---------+ +----------+
  6366. 1: Input signal
  6367. 2: Lag candidates from stage 1
  6368. 3: Lag candidates from stage 2
  6369. 4: Correlation threshold
  6370. 5: Voiced/unvoiced flag
  6371. 6: Pitch correlation
  6372. 7: Pitch lags
  6373. ]]>
  6374. </artwork>
  6375. </figure>
  6376. The pitch analysis finds a binary voiced/unvoiced classification, and, for
  6377. frames classified as voiced, four pitch lags per frame -- one for each
  6378. 5&nbsp;ms subframe -- and a pitch correlation indicating the periodicity of
  6379. the signal.
  6380. The input is first whitened using a Linear Prediction (LP) whitening filter,
  6381. where the coefficients are computed through standard Linear Predictive Coding
  6382. (LPC) analysis. The order of the whitening filter is 16 for best results, but
  6383. is reduced to 12 for medium complexity and 8 for low complexity modes.
  6384. The whitened signal is analyzed to find pitch lags for which the time
  6385. correlation is high.
  6386. The analysis consists of three stages for reducing the complexity:
  6387. <list style="symbols">
  6388. <t>In the first stage, the whitened signal is downsampled to 4&nbsp;kHz
  6389. (from 8&nbsp;kHz), and the current frame is correlated to a signal delayed
  6390. by a range of lags, starting from a shortest lag corresponding to
  6391. 500&nbsp;Hz, to a longest lag corresponding to 56&nbsp;Hz.</t>
  6392. <t>
  6393. The second stage operates on an 8&nbsp;kHz signal (downsampled from 12, 16,
  6394. or 24&nbsp;kHz) and measures time correlations only near the lags
  6395. corresponding to those that had sufficiently high correlations in the first
  6396. stage. The resulting correlations are adjusted for a small bias towards
  6397. short lags to avoid ending up with a multiple of the true pitch lag.
  6398. The highest adjusted correlation is compared to a threshold depending on:
  6399. <list style="symbols">
  6400. <t>
  6401. Whether the previous frame was classified as voiced.
  6402. </t>
  6403. <t>
  6404. The speech activity level.
  6405. </t>
  6406. <t>
  6407. The spectral tilt.
  6408. </t>
  6409. </list>
  6410. If the threshold is exceeded, the current frame is classified as voiced and
  6411. the lag with the highest adjusted correlation is stored for a final pitch
  6412. analysis of the highest precision in the third stage.
  6413. </t>
  6414. <t>
  6415. The last stage operates directly on the whitened input signal to compute time
  6416. correlations for each of the four subframes independently in a narrow range
  6417. around the lag with highest correlation from the second stage.
  6418. </t>
  6419. </list>
  6420. </t>
  6421. </section>
  6422. <section title='Noise Shaping Analysis' anchor='noise_shaping_analysis_overview_section'>
  6423. <t>
  6424. The noise shaping analysis finds gains and filter coefficients used in the
  6425. pre-filter and noise shaping quantizer. These parameters are chosen such that
  6426. they will fulfill several requirements:
  6427. <list style="symbols">
  6428. <t>
  6429. Balancing quantization noise and bitrate.
  6430. The quantization gains determine the step size between reconstruction levels
  6431. of the excitation signal. Therefore, increasing the quantization gain
  6432. amplifies quantization noise, but also reduces the bitrate by lowering
  6433. the entropy of the quantization indices.
  6434. </t>
  6435. <t>
  6436. Spectral shaping of the quantization noise; the noise shaping quantizer is
  6437. capable of reducing quantization noise in some parts of the spectrum at the
  6438. cost of increased noise in other parts without substantially changing the
  6439. bitrate.
  6440. By shaping the noise such that it follows the signal spectrum, it becomes
  6441. less audible. In practice, best results are obtained by making the shape
  6442. of the noise spectrum slightly flatter than the signal spectrum.
  6443. </t>
  6444. <t>
  6445. De-emphasizing spectral valleys; by using different coefficients in the
  6446. analysis and synthesis part of the pre-filter and noise shaping quantizer,
  6447. the levels of the spectral valleys can be decreased relative to the levels
  6448. of the spectral peaks such as speech formants and harmonics.
  6449. This reduces the entropy of the signal, which is the difference between the
  6450. coded signal and the quantization noise, thus lowering the bitrate.
  6451. </t>
  6452. <t>
  6453. Matching the levels of the decoded speech formants to the levels of the
  6454. original speech formants; an adjustment gain and a first order tilt
  6455. coefficient are computed to compensate for the effect of the noise
  6456. shaping quantization on the level and spectral tilt.
  6457. </t>
  6458. </list>
  6459. </t>
  6460. <t>
  6461. <figure align="center" anchor="noise_shape_analysis_spectra_figure"
  6462. title="Noise Shaping and Spectral De-emphasis Illustration">
  6463. <artwork align="center">
  6464. <![CDATA[
  6465. / \ ___
  6466. | // \\
  6467. | // \\ ____
  6468. |_// \\___// \\ ____
  6469. | / ___ \ / \\ // \\
  6470. P |/ / \ \_/ \\_____// \\
  6471. o | / \ ____ \ / \\
  6472. w | / \___/ \ \___/ ____ \\___ 1
  6473. e |/ \ / \ \
  6474. r | \_____/ \ \__ 2
  6475. | \
  6476. | \___ 3
  6477. |
  6478. +---------------------------------------->
  6479. Frequency
  6480. 1: Input signal spectrum
  6481. 2: De-emphasized and level matched spectrum
  6482. 3: Quantization noise spectrum
  6483. ]]>
  6484. </artwork>
  6485. </figure>
  6486. <xref target='noise_shape_analysis_spectra_figure' /> shows an example of an
  6487. input signal spectrum (1).
  6488. After de-emphasis and level matching, the spectrum has deeper valleys (2).
  6489. The quantization noise spectrum (3) more or less follows the input signal
  6490. spectrum, while having slightly less pronounced peaks.
  6491. The entropy, which provides a lower bound on the bitrate for encoding the
  6492. excitation signal, is proportional to the area between the de-emphasized
  6493. spectrum (2) and the quantization noise spectrum (3). Without de-emphasis,
  6494. the entropy is proportional to the area between input spectrum (1) and
  6495. quantization noise (3) -- clearly higher.
  6496. </t>
  6497. <t>
  6498. The transformation from input signal to de-emphasized signal can be
  6499. described as a filtering operation with a filter
  6500. <figure align="center">
  6501. <artwork align="center">
  6502. <![CDATA[
  6503. -1 Wana(z)
  6504. H(z) = G * ( 1 - c_tilt * z ) * -------
  6505. Wsyn(z)
  6506. ]]>
  6507. </artwork>
  6508. </figure>
  6509. having an adjustment gain G, a first order tilt adjustment filter with
  6510. tilt coefficient c_tilt, and where
  6511. <figure align="center">
  6512. <artwork align="center">
  6513. <![CDATA[
  6514. 16 d
  6515. __ -k -L __ -k
  6516. Wana(z) = (1 - \ a_ana(k) * z )*(1 - z * \ b_ana(k) * z )
  6517. /_ /_
  6518. k=1 k=-d
  6519. ]]>
  6520. </artwork>
  6521. </figure>
  6522. is the analysis part of the de-emphasis filter, consisting of the short-term
  6523. shaping filter with coefficients a_ana(k) and the long-term shaping filter
  6524. with coefficients b_ana(k) and pitch lag L.&nbsp;
  6525. The parameter d determines the number of long-term shaping filter taps.
  6526. </t>
  6527. <t>
  6528. Similarly, but without the tilt adjustment, the synthesis part can be written as
  6529. <figure align="center">
  6530. <artwork align="center">
  6531. <![CDATA[
  6532. 16 d
  6533. __ -k -L __ -k
  6534. Wsyn(z) = (1 - \ a_syn(k) * z )*(1 - z * \ b_syn(k) * z )
  6535. /_ /_
  6536. k=1 k=-d
  6537. ]]>
  6538. </artwork>
  6539. </figure>
  6540. </t>
  6541. <t>
  6542. All noise shaping parameters are computed and applied per subframe of 5&nbsp;ms.
  6543. First, an LPC analysis is performed on a windowed signal block of 15&nbsp;ms.
  6544. The signal block has a look-ahead of 5&nbsp;ms relative to the current subframe,
  6545. and the window is an asymmetric sine window. The LPC analysis is done with the
  6546. autocorrelation method, with an order of between 8, in lowest-complexity mode,
  6547. and 16, for best quality.
  6548. </t>
  6549. <t>
  6550. Optionally, the LPC analysis and noise shaping filters are warped by replacing
  6551. the delay elements by first-order allpass filters.
  6552. This increases the frequency resolution at low frequencies and reduces it at
  6553. high ones, which better matches the human auditory system and improves
  6554. quality.
  6555. The warped analysis and filtering comes at a cost in complexity
  6556. and is therefore only done in higher complexity modes.
  6557. </t>
  6558. <t>
  6559. The quantization gain is found by taking the square root of the residual energy
  6560. from the LPC analysis and multiplying it by a value inversely proportional
  6561. to the coding quality control parameter and the pitch correlation.
  6562. </t>
  6563. <t>
  6564. Next, the two sets of short-term noise shaping coefficients a_ana(k) and
  6565. a_syn(k) are obtained by applying different amounts of bandwidth expansion to the
  6566. coefficients found in the LPC analysis.
  6567. This bandwidth expansion moves the roots of the LPC polynomial towards the
  6568. origin, using the formulas
  6569. <figure align="center">
  6570. <artwork align="center">
  6571. <![CDATA[
  6572. k
  6573. a_ana(k) = a(k)*g_ana and
  6574. k
  6575. a_syn(k) = a(k)*g_syn
  6576. ]]>
  6577. </artwork>
  6578. </figure>
  6579. where a(k) is the k'th LPC coefficient, and the bandwidth expansion factors
  6580. g_ana and g_syn are calculated as
  6581. <figure align="center">
  6582. <artwork align="center">
  6583. <![CDATA[
  6584. g_ana = 0.95 - 0.01*C and
  6585. g_syn = 0.95 + 0.01*C
  6586. ]]>
  6587. </artwork>
  6588. </figure>
  6589. where C is the coding quality control parameter between 0 and 1.
  6590. Applying more bandwidth expansion to the analysis part than to the synthesis
  6591. part gives the desired de-emphasis of spectral valleys in between formants.
  6592. </t>
  6593. <t>
  6594. The long-term shaping is applied only during voiced frames.
  6595. It uses a three-tap filter, described by
  6596. <figure align="center">
  6597. <artwork align="center">
  6598. <![CDATA[
  6599. b_ana = F_ana * [0.25, 0.5, 0.25] and
  6600. b_syn = F_syn * [0.25, 0.5, 0.25].
  6601. ]]>
  6602. </artwork>
  6603. </figure>
  6604. For unvoiced frames, these coefficients are set to 0. The multiplication factors
  6605. F_ana and F_syn are chosen between 0 and 1, depending on the coding quality
  6606. control parameter, as well as the calculated pitch correlation and smoothed
  6607. subband SNR of the lowest subband. By having F_ana less than F_syn,
  6608. the pitch harmonics are emphasized relative to the valleys in between the
  6609. harmonics.
  6610. </t>
  6611. <t>
  6612. The tilt coefficient c_tilt is for unvoiced frames chosen as
  6613. <figure align="center">
  6614. <artwork align="center">
  6615. <![CDATA[
  6616. c_tilt = 0.25
  6617. ]]>
  6618. </artwork>
  6619. </figure>
  6620. and as
  6621. <figure align="center">
  6622. <artwork align="center">
  6623. <![CDATA[
  6624. c_tilt = 0.25 + 0.2625 * V
  6625. ]]>
  6626. </artwork>
  6627. </figure>
  6628. for voiced frames, where V is the voice activity level between 0 and 1.
  6629. </t>
  6630. <t>
  6631. The adjustment gain G serves to correct any level mismatch between the original
  6632. and decoded signals that might arise from the noise shaping and de-emphasis.
  6633. This gain is computed as the ratio of the prediction gain of the short-term
  6634. analysis and synthesis filter coefficients. The prediction gain of an LPC
  6635. synthesis filter is the square root of the output energy when the filter is
  6636. excited by a unit-energy impulse on the input.
  6637. An efficient way to compute the prediction gain is by first computing the
  6638. reflection coefficients from the LPC coefficients through the step-down
  6639. algorithm, and extracting the prediction gain from the reflection coefficients
  6640. as
  6641. <figure align="center">
  6642. <artwork align="center">
  6643. <![CDATA[
  6644. K
  6645. ___ 2 -0.5
  6646. predGain = ( | | 1 - (r_k) )
  6647. k=1
  6648. ]]>
  6649. </artwork>
  6650. </figure>
  6651. where r_k is the k'th reflection coefficient.
  6652. </t>
  6653. <t>
  6654. Initial values for the quantization gains are computed as the square root of
  6655. the residual energy of the LPC analysis, adjusted by the coding quality control
  6656. parameter.
  6657. These quantization gains are later adjusted based on the results of the
  6658. prediction analysis.
  6659. </t>
  6660. </section>
  6661. <section title='Prediction Analysis' anchor='pred_ana_overview_section'>
  6662. <t>
  6663. The prediction analysis is performed in one of two ways depending on how
  6664. the pitch estimator classified the frame.
  6665. The processing for voiced and unvoiced speech is described in
  6666. <xref target='pred_ana_voiced_overview_section' /> and
  6667. <xref target='pred_ana_unvoiced_overview_section' />, respectively.
  6668. Inputs to this function include the pre-whitened signal from the
  6669. pitch estimator (see <xref target='pitch_estimator_overview_section'/>).
  6670. </t>
  6671. <section title='Voiced Speech' anchor='pred_ana_voiced_overview_section'>
  6672. <t>
  6673. For a frame of voiced speech, the pitch pulses will remain dominant in the
  6674. pre-whitened input signal.
  6675. Further whitening is desirable as it leads to higher quality at the same
  6676. available bitrate.
  6677. To achieve this, a Long-Term Prediction (LTP) analysis is carried out to
  6678. estimate the coefficients of a fifth-order LTP filter for each of four
  6679. subframes.
  6680. The LTP coefficients are quantized using the method described in
  6681. <xref target='ltp_quantizer_overview_section'/>, and the quantized LTP
  6682. coefficients are used to compute the LTP residual signal.
  6683. This LTP residual signal is the input to an LPC analysis where the LPC coefficients are
  6684. estimated using Burg's method <xref target="BURG"/>, such that the residual energy is minimized.
  6685. The estimated LPC coefficients are converted to a Line Spectral Frequency (LSF) vector
  6686. and quantized as described in <xref target='lsf_quantizer_overview_section'/>.
  6687. After quantization, the quantized LSF vector is converted back to LPC
  6688. coefficients using the full procedure in <xref target="silk_nlsfs"/>.
  6689. By using quantized LTP coefficients and LPC coefficients derived from the
  6690. quantized LSF coefficients, the encoder remains fully synchronized with the
  6691. decoder.
  6692. The quantized LPC and LTP coefficients are also used to filter the input
  6693. signal and measure residual energy for each of the four subframes.
  6694. </t>
  6695. </section>
  6696. <section title='Unvoiced Speech' anchor='pred_ana_unvoiced_overview_section'>
  6697. <t>
  6698. For a speech signal that has been classified as unvoiced, there is no need
  6699. for LTP filtering, as it has already been determined that the pre-whitened
  6700. input signal is not periodic enough within the allowed pitch period range
  6701. for LTP analysis to be worth the cost in terms of complexity and bitrate.
  6702. The pre-whitened input signal is therefore discarded, and, instead, the input
  6703. signal is used for LPC analysis using Burg's method.
  6704. The resulting LPC coefficients are converted to an LSF vector and quantized
  6705. as described in the following section.
  6706. They are then transformed back to obtain quantized LPC coefficients, which
  6707. are then used to filter the input signal and measure residual energy for
  6708. each of the four subframes.
  6709. </t>
  6710. <section title="Burg's Method">
  6711. <t>
  6712. The main purpose of linear prediction in SILK is to reduce the bitrate by
  6713. minimizing the residual energy.
  6714. At least at high bitrates, perceptual aspects are handled
  6715. independently by the noise shaping filter.
  6716. Burg's method is used because it provides higher prediction gain
  6717. than the autocorrelation method and, unlike the covariance method,
  6718. produces stable filters (assuming numerical errors don't spoil
  6719. that). SILK's implementation of Burg's method is also computationally
  6720. faster than the autocovariance method.
  6721. The implementation of Burg's method differs from traditional
  6722. implementations in two aspects.
  6723. The first difference is that it
  6724. operates on autocorrelations, similar to the Schur algorithm <xref target="SCHUR"/>, but
  6725. with a simple update to the autocorrelations after finding each
  6726. reflection coefficient to make the result identical to Burg's method.
  6727. This brings down the complexity of Burg's method to near that of
  6728. the autocorrelation method.
  6729. The second difference is that the signal in each subframe is scaled
  6730. by the inverse of the residual quantization step size. Subframes with
  6731. a small quantization step size will, on average, spend more bits for a
  6732. given amount of residual energy than subframes with a large step size.
  6733. Without scaling, Burg's method minimizes the total residual energy in
  6734. all subframes, which doesn't necessarily minimize the total number of
  6735. bits needed for coding the quantized residual. The residual energy
  6736. of the scaled subframes is a better measure for that number of
  6737. bits.
  6738. </t>
  6739. </section>
  6740. </section>
  6741. </section>
  6742. <section title='LSF Quantization' anchor='lsf_quantizer_overview_section'>
  6743. <t>
  6744. Unlike many other speech codecs, SILK uses variable bitrate coding
  6745. for the LSFs.
  6746. This improves the average rate-distortion (R-D) trade-off and reduces outliers.
  6747. The variable bitrate coding minimizes a linear combination of the weighted
  6748. quantization errors and the bitrate.
  6749. The weights for the quantization errors are the Inverse
  6750. Harmonic Mean Weighting (IHMW) function proposed by Laroia et al.
  6751. (see <xref target="LAROIA-ICASSP" />).
  6752. These weights are referred to here as Laroia weights.
  6753. </t>
  6754. <t>
  6755. The LSF quantizer consists of two stages.
  6756. The first stage is an (unweighted) vector quantizer (VQ), with a
  6757. codebook size of 32 vectors.
  6758. The quantization errors for the codebook vector are sorted, and
  6759. for the N best vectors a second stage quantizer is run.
  6760. By varying the number N, a trade-off is made between R-D performance
  6761. and computational efficiency.
  6762. For each of the N codebook vectors, the Laroia weights corresponding
  6763. to that vector (and not to the input vector) are calculated.
  6764. Then, the residual between the input LSF vector and the codebook
  6765. vector is scaled by the square roots of these Laroia weights.
  6766. This scaling partially normalizes error sensitivity for the
  6767. residual vector so that a uniform quantizer with fixed
  6768. step sizes can be used in the second stage without too much
  6769. performance loss.
  6770. Additionally, by scaling with Laroia weights determined from the first-stage
  6771. codebook vector, the process can be reversed in the decoder.
  6772. </t>
  6773. <t>
  6774. The second stage uses predictive delayed decision scalar
  6775. quantization.
  6776. The quantization error is weighted by Laroia weights determined
  6777. from the LSF input vector.
  6778. The predictor multiplies the previous quantized residual value
  6779. by a prediction coefficient that depends on the vector index from the
  6780. first stage VQ and on the location in the LSF vector.
  6781. The prediction is subtracted from the LSF residual value before
  6782. quantizing the result and is added back afterwards.
  6783. This subtraction can be interpreted as shifting the quantization levels
  6784. of the scalar quantizer, and as a result the quantization error of
  6785. each value depends on the quantization decision of the previous value.
  6786. This dependency is exploited by the delayed decision mechanism to
  6787. search for a quantization sequency with best R-D performance
  6788. with a Viterbi-like algorithm <xref target="VITERBI"/>.
  6789. The quantizer processes the residual LSF vector in reverse order
  6790. (i.e., it starts with the highest residual LSF value).
  6791. This is done because the prediction works slightly
  6792. better in the reverse direction.
  6793. </t>
  6794. <t>
  6795. The quantization index of the first stage is entropy coded.
  6796. The quantization sequence from the second stage is also entropy
  6797. coded, where for each element the probability table is chosen
  6798. depending on the vector index from the first stage and the location
  6799. of that element in the LSF vector.
  6800. </t>
  6801. <section title='LSF Stabilization' anchor='lsf_stabilizer_overview_section'>
  6802. <t>
  6803. If the input is stable, finding the best candidate usually results in a
  6804. quantized vector that is also stable. Because of the two-stage approach,
  6805. however, it is possible that the best quantization candidate is unstable.
  6806. The encoder applies the same stabilization procedure applied by the decoder
  6807. (see <xref target="silk_nlsf_stabilization"/>) to ensure the LSF parameters
  6808. are within their valid range, increasingly sorted, and have minimum
  6809. distances between each other and the border values.
  6810. </t>
  6811. </section>
  6812. </section>
  6813. <section title='LTP Quantization' anchor='ltp_quantizer_overview_section'>
  6814. <t>
  6815. For voiced frames, the prediction analysis described in
  6816. <xref target='pred_ana_voiced_overview_section' /> resulted in four sets
  6817. (one set per subframe) of five LTP coefficients, plus four weighting matrices.
  6818. The LTP coefficients for each subframe are quantized using entropy constrained
  6819. vector quantization.
  6820. A total of three vector codebooks are available for quantization, with
  6821. different rate-distortion trade-offs. The three codebooks have 10, 20, and
  6822. 40 vectors and average rates of about 3, 4, and 5 bits per vector, respectively.
  6823. Consequently, the first codebook has larger average quantization distortion at
  6824. a lower rate, whereas the last codebook has smaller average quantization
  6825. distortion at a higher rate.
  6826. Given the weighting matrix W_ltp and LTP vector b, the weighted rate-distortion
  6827. measure for a codebook vector cb_i with rate r_i is give by
  6828. <figure align="center">
  6829. <artwork align="center">
  6830. <![CDATA[
  6831. RD = u * (b - cb_i)' * W_ltp * (b - cb_i) + r_i
  6832. ]]>
  6833. </artwork>
  6834. </figure>
  6835. where u is a fixed, heuristically determined parameter balancing the distortion
  6836. and rate.
  6837. Which codebook gives the best performance for a given LTP vector depends on the
  6838. weighting matrix for that LTP vector.
  6839. For example, for a low valued W_ltp, it is advantageous to use the codebook
  6840. with 10 vectors as it has a lower average rate.
  6841. For a large W_ltp, on the other hand, it is often better to use the codebook
  6842. with 40 vectors, as it is more likely to contain the best codebook vector.
  6843. The weighting matrix W_ltp depends mostly on two aspects of the input signal.
  6844. The first is the periodicity of the signal; the more periodic, the larger W_ltp.
  6845. The second is the change in signal energy in the current subframe, relative to
  6846. the signal one pitch lag earlier.
  6847. A decaying energy leads to a larger W_ltp than an increasing energy.
  6848. Both aspects fluctuate relatively slowly, which causes the W_ltp matrices for
  6849. different subframes of one frame often to be similar.
  6850. Because of this, one of the three codebooks typically gives good performance
  6851. for all subframes.
  6852. Therefore, the codebook search for the subframe LTP
  6853. vectors is constrained to only allow codebook vectors to be chosen from the
  6854. same codebook, resulting in a rate reduction.
  6855. </t>
  6856. <t>
  6857. To find the best codebook, each of the three vector codebooks is
  6858. used to quantize all subframe LTP vectors and produce a combined
  6859. weighted rate-distortion measure for each vector codebook.
  6860. The vector codebook with the lowest combined rate-distortion
  6861. over all subframes is chosen. The quantized LTP vectors are used
  6862. in the noise shaping quantizer, and the index of the codebook
  6863. plus the four indices for the four subframe codebook vectors
  6864. are passed on to the range encoder.
  6865. </t>
  6866. </section>
  6867. <section title='Pre-filter'>
  6868. <t>
  6869. In the pre-filter, the input signal is filtered using the spectral valley
  6870. de-emphasis filter coefficients from the noise shaping analysis
  6871. (see <xref target='noise_shaping_analysis_overview_section'/>).
  6872. By applying only the noise shaping analysis filter to the input signal,
  6873. it provides the input to the noise shaping quantizer.
  6874. </t>
  6875. </section>
  6876. <section title='Noise Shaping Quantizer'>
  6877. <t>
  6878. The noise shaping quantizer independently shapes the signal and coding noise
  6879. spectra to obtain a perceptually higher quality at the same bitrate.
  6880. </t>
  6881. <t>
  6882. The pre-filter output signal is multiplied with a compensation gain G computed
  6883. in the noise shaping analysis. Then, the output of a synthesis shaping filter
  6884. is added, and the output of a prediction filter is subtracted to create a
  6885. residual signal.
  6886. The residual signal is multiplied by the inverse quantized quantization gain
  6887. from the noise shaping analysis and input to a scalar quantizer.
  6888. The quantization indices of the scalar quantizer represent a signal of pulses
  6889. that is input to the pyramid range encoder.
  6890. The scalar quantizer also outputs a quantization signal, which is multiplied
  6891. by the quantized quantization gain from the noise shaping analysis to create
  6892. an excitation signal.
  6893. The output of the prediction filter is added to the excitation signal to form
  6894. the quantized output signal y(n).
  6895. The quantized output signal y(n) is input to the synthesis shaping and
  6896. prediction filters.
  6897. </t>
  6898. <t>
  6899. Optionally, the noise shaping quantizer operates in a delayed decision
  6900. mode.
  6901. In this mode, it uses a Viterbi algorithm to keep track of
  6902. multiple rounding choices in the quantizer and select the best
  6903. one after a delay of 32 samples. This improves the rate/distortion
  6904. performance of the quantizer.
  6905. </t>
  6906. </section>
  6907. <section title='Constant Bitrate Mode'>
  6908. <t>
  6909. SILK was designed to run in variable bitrate (VBR) mode. However,
  6910. the reference implementation also has a constant bitrate (CBR) mode
  6911. for SILK. In CBR mode, SILK will attempt to encode each packet with
  6912. no more than the allowed number of bits. The Opus wrapper code
  6913. then pads the bitstream if any unused bits are left in SILK mode, or it
  6914. encodes the high band with the remaining number of bits in Hybrid mode.
  6915. The number of payload bits is adjusted by changing
  6916. the quantization gains and the rate/distortion trade-off in the noise
  6917. shaping quantizer, in an iterative loop
  6918. around the noise shaping quantizer and entropy coding.
  6919. Compared to the SILK VBR mode, the CBR mode has lower
  6920. audio quality at a given average bitrate and has higher
  6921. computational complexity.
  6922. </t>
  6923. </section>
  6924. </section>
  6925. </section>
  6926. <section title="CELT Encoder">
  6927. <t>
  6928. Most of the aspects of the CELT encoder can be directly derived from the description
  6929. of the decoder. For example, the filters and rotations in the encoder are simply the
  6930. inverse of the operation performed by the decoder. Similarly, the quantizers generally
  6931. optimize for the mean square error (because noise shaping is part of the bitstream itself),
  6932. so no special search is required. For this reason, only the less straightforward aspects of the
  6933. encoder are described here.
  6934. </t>
  6935. <section anchor="pitch-prefilter" title="Pitch Pre-filter">
  6936. <t>The pitch pre-filter is applied after the pre-emphasis. It is applied
  6937. in such a way as to be the inverse of the decoder's post-filter. The main non-obvious aspect of the
  6938. pre-filter is the selection of the pitch period. The pitch search should be optimized for the
  6939. following criteria:
  6940. <list style="symbols">
  6941. <t>continuity: it is important that the pitch period
  6942. does not change abruptly between frames; and</t>
  6943. <t>avoidance of pitch multiples: when the period used is a multiple of the real period
  6944. (lower frequency fundamental), the post-filter loses most of its ability to reduce noise</t>
  6945. </list>
  6946. </t>
  6947. </section>
  6948. <section anchor="normalization" title="Bands and Normalization">
  6949. <t>
  6950. The MDCT output is divided into bands that are designed to match the ear's critical
  6951. bands for the smallest (2.5&nbsp;ms) frame size. The larger frame sizes use integer
  6952. multiples of the 2.5&nbsp;ms layout. For each band, the encoder
  6953. computes the energy that will later be encoded. Each band is then normalized by the
  6954. square root of the <spanx style="strong">unquantized</spanx> energy, such that each band now forms a unit vector X.
  6955. The energy and the normalization are computed by compute_band_energies()
  6956. and normalise_bands() (bands.c), respectively.
  6957. </t>
  6958. </section>
  6959. <section anchor="energy-quantization" title="Energy Envelope Quantization">
  6960. <t>
  6961. Energy quantization (both coarse and fine) can be easily understood from the decoding process.
  6962. For all useful bitrates, the coarse quantizer always chooses the quantized log energy value that
  6963. minimizes the error for each band. Only at very low rate does the encoder allow larger errors to
  6964. minimize the rate and avoid using more bits than are available. When the
  6965. available CPU requirements allow it, it is best to try encoding the coarse energy both with and without
  6966. inter-frame prediction such that the best prediction mode can be selected. The optimal mode depends on
  6967. the coding rate, the available bitrate, and the current rate of packet loss.
  6968. </t>
  6969. <t>The fine energy quantizer always chooses the quantized log energy value that
  6970. minimizes the error for each band because the rate of the fine quantization depends only
  6971. on the bit allocation and not on the values that are coded.
  6972. </t>
  6973. </section> <!-- Energy quant -->
  6974. <section title="Bit Allocation">
  6975. <t>The encoder must use exactly the same bit allocation process as used by the decoder
  6976. and described in <xref target="allocation"/>. The three mechanisms that can be used by the
  6977. encoder to adjust the bitrate on a frame-by-frame basis are band boost, allocation trim,
  6978. and band skipping.
  6979. </t>
  6980. <section title="Band Boost">
  6981. <t>The reference encoder makes a decision to boost a band when the energy of that band is significantly
  6982. higher than that of the neighboring bands. Let E_j be the log-energy of band j, we define
  6983. <list>
  6984. <t>D_j = 2*E_j - E_j-1 - E_j+1</t>
  6985. </list>
  6986. The allocation of band j is boosted once if D_j &gt; t1 and twice if D_j &gt; t2. For LM&gt;=1, t1=2 and t2=4,
  6987. while for LM&lt;1, t1=3 and t2=5.
  6988. </t>
  6989. </section>
  6990. <section title="Allocation Trim">
  6991. <t>The allocation trim is a value between 0 and 10 (inclusively) that controls the allocation
  6992. balance between the low and high frequencies. The encoder starts with a safe "default" of 5
  6993. and deviates from that default in two different ways. First, the trim can deviate by +/- 2
  6994. depending on the spectral tilt of the input signal. For signals with more low frequencies, the
  6995. trim is increased by up to 2, while for signals with more high frequencies, the trim is
  6996. decreased by up to 2.
  6997. For stereo inputs, the trim value can
  6998. be decreased by up to 4 when the inter-channel correlation at low frequency (first 8 bands)
  6999. is high.</t>
  7000. </section>
  7001. <section title="Band Skipping">
  7002. <t>The encoder uses band skipping to ensure that the shape of the bands is only coded
  7003. if there is at least 1/2 bit per sample available for the PVQ. If not, then no bit is allocated
  7004. and folding is used instead. To ensure continuity in the allocation, some amount of hysteresis is
  7005. added to the process, such that a band that received PVQ bits in the previous frame only needs 7/16
  7006. bit/sample to be coded for the current frame, while a band that did not receive PVQ bits in the
  7007. previous frames needs at least 9/16 bit/sample to be coded.</t>
  7008. </section>
  7009. </section>
  7010. <section title="Stereo Decisions">
  7011. <t>Because CELT applies mid-side stereo coupling in the normalized domain, it does not suffer from
  7012. important stereo image problems even when the two channels are completely uncorrelated. For this reason,
  7013. it is always safe to use stereo coupling on any audio frame. That being said, there are some frames
  7014. for which dual (independent) stereo is still more efficient. This decision is made by comparing the estimated
  7015. entropy with and without coupling over the first 13 bands, taking into account the fact that all bands with
  7016. more than two MDCT bins require one extra degree of freedom when coded in mid-side. Let L1_ms and L1_lr
  7017. be the L1-norm of the mid-side vector and the L1-norm of the left-right vector, respectively. The decision
  7018. to use mid-side is made if and only if
  7019. <figure align="center">
  7020. <artwork align="center"><![CDATA[
  7021. L1_ms L1_lr
  7022. -------- < -----
  7023. bins + E bins
  7024. ]]></artwork>
  7025. </figure>
  7026. where bins is the number of MDCT bins in the first 13 bands and E is the number of extra degrees of
  7027. freedom for mid-side coding. For LM>1, E=13, otherwise E=5.
  7028. </t>
  7029. <t>The reference encoder decides on the intensity stereo threshold based on the bitrate alone. After
  7030. taking into account the frame size by subtracting 80 bits per frame for coarse energy, the first
  7031. band using intensity coding is as follows:
  7032. </t>
  7033. <?rfc compact="no" ?>
  7034. <texttable anchor="intensity-thresholds"
  7035. title="Thresholds for Intensity Stereo">
  7036. <ttcol align='center'>bitrate (kbit/s)</ttcol>
  7037. <ttcol align='center'>start band</ttcol>
  7038. <c>&lt;35</c> <c>8</c>
  7039. <c>35-50</c> <c>12</c>
  7040. <c>50-68</c> <c>16</c>
  7041. <c>84-84</c> <c>18</c>
  7042. <c>84-102</c> <c>19</c>
  7043. <c>102-130</c> <c>20</c>
  7044. <c>&gt;130</c> <c>disabled</c>
  7045. </texttable>
  7046. <?rfc compact="yes" ?>
  7047. </section>
  7048. <section title="Time-Frequency Decision">
  7049. <t>
  7050. The choice of time-frequency resolution used in <xref target="tf-change"></xref> is based on
  7051. R-D optimization. The distortion is the L1-norm (sum of absolute values) of each band
  7052. after each TF resolution under consideration. The L1 norm is used because it represents the entropy
  7053. for a Laplacian source. The number of bits required to code a change in TF resolution between
  7054. two bands is higher than the cost of having those two bands use the same resolution, which is
  7055. what requires the R-D optimization. The optimal decision is computed using the Viterbi algorithm.
  7056. See tf_analysis() in celt/celt.c.
  7057. </t>
  7058. </section>
  7059. <section title="Spreading Values Decision">
  7060. <t>
  7061. The choice of the spreading value in <xref target="spread values"></xref> has an
  7062. impact on the nature of the coding noise introduced by CELT. The larger the f_r value, the
  7063. lower the impact of the rotation, and the more tonal the coding noise. The
  7064. more tonal the signal, the more tonal the noise should be, so the CELT encoder determines
  7065. the optimal value for f_r by estimating how tonal the signal is. The tonality estimate
  7066. is based on discrete pdf (4-bin histogram) of each band. Bands that have a large number of small
  7067. values are considered more tonal and a decision is made by combining all bands with more than
  7068. 8 samples. See spreading_decision() in celt/bands.c.
  7069. </t>
  7070. </section>
  7071. <section anchor="pvq" title="Spherical Vector Quantization">
  7072. <t>CELT uses a Pyramid Vector Quantizer (PVQ) <xref target="PVQ"></xref>
  7073. for quantizing the details of the spectrum in each band that have not
  7074. been predicted by the pitch predictor. The PVQ codebook consists of all sums
  7075. of K signed pulses in a vector of N samples, where two pulses at the same position
  7076. are required to have the same sign. Thus, the codebook includes
  7077. all integer codevectors y of N dimensions that satisfy sum(abs(y(j))) = K.
  7078. </t>
  7079. <t>
  7080. In bands where there are sufficient bits allocated, PVQ is used to encode
  7081. the unit vector that results from the normalization in
  7082. <xref target="normalization"></xref> directly. Given a PVQ codevector y,
  7083. the unit vector X is obtained as X = y/||y||, where ||.|| denotes the
  7084. L2 norm.
  7085. </t>
  7086. <section anchor="pvq-search" title="PVQ Search">
  7087. <t>
  7088. The search for the best codevector y is performed by alg_quant()
  7089. (vq.c). There are several possible approaches to the
  7090. search, with a trade-off between quality and complexity. The method used in the reference
  7091. implementation computes an initial codeword y1 by projecting the normalized spectrum
  7092. X onto the codebook pyramid of K-1 pulses:
  7093. </t>
  7094. <t>
  7095. y0 = truncate_towards_zero( (K-1) * X / sum(abs(X)))
  7096. </t>
  7097. <t>
  7098. Depending on N, K and the input data, the initial codeword y0 may contain from
  7099. 0 to K-1 non-zero values. All the remaining pulses, with the exception of the last one,
  7100. are found iteratively with a greedy search that minimizes the normalized correlation
  7101. between y and X:
  7102. <figure align="center">
  7103. <artwork align="center"><![CDATA[
  7104. T
  7105. J = -X * y / ||y||
  7106. ]]></artwork>
  7107. </figure>
  7108. </t>
  7109. <t>
  7110. The search described above is considered to be a good trade-off between quality
  7111. and computational cost. However, there are other possible ways to search the PVQ
  7112. codebook and the implementers MAY use any other search methods. See alg_quant() in celt/vq.c.
  7113. </t>
  7114. </section>
  7115. <section anchor="cwrs-encoder" title="PVQ Encoding">
  7116. <t>
  7117. The vector to encode, X, is converted into an index i such that
  7118. 0&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;V(N,K) as follows.
  7119. Let i&nbsp;=&nbsp;0 and k&nbsp;=&nbsp;0.
  7120. Then, for j&nbsp;=&nbsp;(N&nbsp;-&nbsp;1) down to 0, inclusive, do:
  7121. <list style="numbers">
  7122. <t>
  7123. If k&nbsp;>&nbsp;0, set
  7124. i&nbsp;=&nbsp;i&nbsp;+&nbsp;(V(N-j-1,k-1)&nbsp;+&nbsp;V(N-j,k-1))/2.
  7125. </t>
  7126. <t>Set k&nbsp;=&nbsp;k&nbsp;+&nbsp;abs(X[j]).</t>
  7127. <t>
  7128. If X[j]&nbsp;&lt;&nbsp;0, set
  7129. i&nbsp;=&nbsp;i&nbsp;+&nbsp;(V(N-j-1,k)&nbsp;+&nbsp;V(N-j,k))/2.
  7130. </t>
  7131. </list>
  7132. </t>
  7133. <t>
  7134. The index i is then encoded using the procedure in
  7135. <xref target="encoding-ints"/> with ft&nbsp;=&nbsp;V(N,K).
  7136. </t>
  7137. </section>
  7138. </section>
  7139. </section>
  7140. </section>
  7141. <section anchor="conformance" title="Conformance">
  7142. <t>
  7143. It is our intention to allow the greatest possible choice of freedom in
  7144. implementing the specification. For this reason, outside of the exceptions
  7145. noted in this section, conformance is defined through the reference
  7146. implementation of the decoder provided in <xref target="ref-implementation"/>.
  7147. Although this document includes a prose description of the codec, should
  7148. the description contradict the source code of the reference implementation,
  7149. the latter shall take precedence.
  7150. </t>
  7151. <t>
  7152. Compliance with this specification means that, in addition to following the normative keywords in this document,
  7153. a decoder's output MUST also be
  7154. within the thresholds specified by the opus_compare.c tool (included
  7155. with the code) when compared to the reference implementation for each of the
  7156. test vectors provided (see <xref target="test-vectors"></xref>) and for each output
  7157. sampling rate and channel count supported. In addition, a compliant
  7158. decoder implementation MUST have the same final range decoder state as that of the
  7159. reference decoder. It is therefore RECOMMENDED that the
  7160. decoder implement the same functional behavior as the reference.
  7161. A decoder implementation is not required to support all output sampling
  7162. rates or all output channel counts.
  7163. </t>
  7164. <section title="Testing">
  7165. <t>
  7166. Using the reference code provided in <xref target="ref-implementation"></xref>,
  7167. a test vector can be decoded with
  7168. <list>
  7169. <t>opus_demo -d &lt;rate&gt; &lt;channels&gt; testvectorX.bit testX.out</t>
  7170. </list>
  7171. where &lt;rate&gt; is the sampling rate and can be 8000, 12000, 16000, 24000, or 48000, and
  7172. &lt;channels&gt; is 1 for mono or 2 for stereo.
  7173. </t>
  7174. <t>
  7175. If the range decoder state is incorrect for one of the frames, the decoder will exit with
  7176. "Error: Range coder state mismatch between encoder and decoder". If the decoder succeeds, then
  7177. the output can be compared with the "reference" output with
  7178. <list>
  7179. <t>opus_compare -s -r &lt;rate&gt; testvectorX.dec testX.out</t>
  7180. </list>
  7181. for stereo or
  7182. <list>
  7183. <t>opus_compare -r &lt;rate&gt; testvectorX.dec testX.out</t>
  7184. </list>
  7185. for mono.
  7186. </t>
  7187. <t>In addition to indicating whether the test vector comparison passes, the opus_compare tool
  7188. outputs an "Opus quality metric" that indicates how well the tested decoder matches the
  7189. reference implementation. A quality of 0 corresponds to the passing threshold, while
  7190. a quality of 100 is the highest possible value and means that the output of the tested decoder is identical to the reference
  7191. implementation. The passing threshold (quality 0) was calibrated in such a way that it corresponds to
  7192. additive white noise with a 48 dB SNR (similar to what can be obtained on a cassette deck).
  7193. It is still possible for an implementation to sound very good with such a low quality measure
  7194. (e.g., if the deviation is due to inaudible phase distortion), but unless this is verified by
  7195. listening tests, it is RECOMMENDED that implementations achieve a quality above 90 for 48&nbsp;kHz
  7196. decoding. For other sampling rates, it is normal for the quality metric to be lower
  7197. (typically, as low as 50 even for a good implementation) because of harmless mismatch with
  7198. the delay and phase of the internal sampling rate conversion.
  7199. </t>
  7200. <t>
  7201. On POSIX environments, the run_vectors.sh script can be used to verify all test
  7202. vectors. This can be done with
  7203. <list>
  7204. <t>run_vectors.sh &lt;exec path&gt; &lt;vector path&gt; &lt;rate&gt;</t>
  7205. </list>
  7206. where &lt;exec path&gt; is the directory where the opus_demo and opus_compare executables
  7207. are built and &lt;vector path&gt; is the directory containing the test vectors.
  7208. </t>
  7209. </section>
  7210. <section anchor="opus-custom" title="Opus Custom">
  7211. <t>
  7212. Opus Custom is an OPTIONAL part of the specification that is defined to
  7213. handle special sample rates and frame rates that are not supported by the
  7214. main Opus specification. Use of Opus Custom is discouraged for all but very
  7215. special applications for which a frame size different from 2.5, 5, 10, or 20&nbsp;ms is
  7216. needed (for either complexity or latency reasons). Because Opus Custom is
  7217. optional, streams encoded using Opus Custom cannot be expected to be decodable by all Opus
  7218. implementations. Also, because no in-band mechanism exists for specifying the sampling
  7219. rate and frame size of Opus Custom streams, out-of-band signaling is required.
  7220. In Opus Custom operation, only the CELT layer is available, using the opus_custom_* function
  7221. calls in opus_custom.h.
  7222. </t>
  7223. </section>
  7224. </section>
  7225. <section anchor="security" title="Security Considerations">
  7226. <t>
  7227. Like any other audio codec, Opus should not be used with insecure ciphers
  7228. or cipher-modes that are vulnerable to known plaintext attacks. In addition to the zeros used
  7229. in Opus padding, digital silence frames generate predictable compressed results
  7230. and the TOC byte may have an easily predictable value.</t>
  7231. <t>
  7232. Implementations of the Opus codec need to take appropriate security considerations
  7233. into account, as outlined in <xref target="DOS"/>.
  7234. It is extremely important for the decoder to be robust against malicious
  7235. payloads.
  7236. Malicious payloads must not cause the decoder to overrun its allocated memory
  7237. or to take an excessive amount of resources to decode.
  7238. Although problems
  7239. in encoders are typically rarer, the same applies to the encoder. Malicious
  7240. audio streams must not cause the encoder to misbehave because this would
  7241. allow an attacker to attack transcoding gateways.
  7242. </t>
  7243. <t>
  7244. The reference implementation contains no known buffer overflow or cases where
  7245. a specially crafted packet or audio segment could cause a significant increase
  7246. in CPU load.
  7247. However, on certain CPU architectures where denormalized floating-point
  7248. operations are much slower than normal floating-point operations, it is
  7249. possible for some audio content (e.g., silence or near silence) to cause an
  7250. increase in CPU load.
  7251. Denormals can be introduced by reordering operations in the compiler and depend
  7252. on the target architecture, so it is difficult to guarantee that an implementation
  7253. avoids them.
  7254. For architectures on which denormals are problematic, adding very small
  7255. floating-point offsets to the affected signals to prevent significant numbers
  7256. of denormalized operations is RECOMMENDED.
  7257. Alternatively, it is often possible to configure the hardware to treat
  7258. denormals as zero (DAZ).
  7259. No such issue exists for the fixed-point reference implementation.
  7260. </t>
  7261. <t>The reference implementation was validated in the following conditions:
  7262. <list style="numbers">
  7263. <t>
  7264. Sending the decoder valid packets generated by the reference encoder and
  7265. verifying that the decoder's final range coder state matches that of the
  7266. encoder.
  7267. </t>
  7268. <t>
  7269. Sending the decoder packets generated by the reference encoder and then
  7270. subjected to random corruption.
  7271. </t>
  7272. <t>Sending the decoder random packets.</t>
  7273. <t>
  7274. Sending the decoder packets generated by a version of the reference encoder
  7275. modified to make random coding decisions (internal fuzzing), including mode
  7276. switching, and verifying that the range coder final states match.
  7277. </t>
  7278. </list>
  7279. In all of the conditions above, both the encoder and the decoder were run
  7280. inside the <xref target="VALGRIND">Valgrind</xref> memory
  7281. debugger, which tracks reads and writes to invalid memory regions as well as
  7282. the use of uninitialized memory.
  7283. There were no errors reported on any of the tested conditions.
  7284. </t>
  7285. </section>
  7286. <section anchor="Acknowledgements" title="Acknowledgements">
  7287. <t>
  7288. Thanks to all other developers, including Henrik Astrom, Jon Bergenheim,
  7289. Raymond Chen, Soren Skak Jensen,
  7290. Gregory Maxwell, Christopher Montgomery, and Karsten Vandborg Sorensen.
  7291. We would also like to thank Igor Dyakonov, Hoang Thi Minh Nguyet, Christian Hoene, Gian-Carlo Pascutto,
  7292. and Jan Skoglund for their help with testing of the Opus codec.
  7293. Thanks to Andrew D'Addesio, Elwyn Davies, Ralph Giles,
  7294. John Ridges, Ben Schwartz, Kat Walsh, Mark Warner, Keith Yan, and many others on the Opus
  7295. and CELT mailing lists for their bug reports and feedback. At last, the
  7296. authors would like to thank Robert Sparks, Cullen Jennings, and Jonathan
  7297. Rosenberg for their support throughout the standardization process.
  7298. </t>
  7299. </section>
  7300. <section title="Copying Conditions">
  7301. <!-- [rfced] Please note that there is discussion within legal@ietf.org
  7302. regarding whether this is appropriate in an RFC. We will discuss the outcome
  7303. of the discussion with you when there is some agreement.
  7304. 9. Copying Conditions
  7305. The authors agree to grant third parties the irrevocable right to
  7306. copy, use and distribute the work (excluding Code Components
  7307. available under the Simplified BSD license), with or without
  7308. modification, in any medium, without royalty, provided that, unless
  7309. separate permission is granted, redistributed modified works do not
  7310. contain misleading author, version, name of work, or endorsement
  7311. information.
  7312. -->
  7313. <t>The authors agree to grant third parties the irrevocable right to copy, use and distribute
  7314. the work (excluding Code Components available under the Simplified BSD license), with or
  7315. without modification, in any medium, without royalty, provided that, unless separate
  7316. permission is granted, redistributed modified works do not contain misleading author, version,
  7317. name of work, or endorsement information.</t>
  7318. </section>
  7319. </middle>
  7320. <back>
  7321. <!-- [rfced] Would you like the references to be alphabetized
  7322. or left in their current order?
  7323. -->
  7324. <references title="Normative References">
  7325. <reference anchor='RFC2119'>
  7326. <front>
  7327. <title abbrev='RFC Key Words'>Key words for use in RFCs to Indicate Requirement Levels</title>
  7328. <author initials='S.' surname='Bradner' fullname='Scott Bradner'>
  7329. <organization>Harvard University</organization>
  7330. <address>
  7331. <postal>
  7332. <street>1350 Mass. Ave.</street>
  7333. <street>Cambridge</street>
  7334. <street>MA 02138</street></postal>
  7335. <phone>- +1 617 495 3864</phone>
  7336. <email>sob@harvard.edu</email></address></author>
  7337. <date year='1997' month='March' />
  7338. <area>General</area>
  7339. <keyword>keyword</keyword>
  7340. <abstract>
  7341. <t>
  7342. In many standards track documents several words are used to signify
  7343. the requirements in the specification. These words are often
  7344. capitalized. This document defines these words as they should be
  7345. interpreted in IETF documents. Authors who follow these guidelines
  7346. should incorporate this phrase near the beginning of their document:
  7347. <list>
  7348. <t>
  7349. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL
  7350. NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and
  7351. "OPTIONAL" in this document are to be interpreted as described in
  7352. RFC 2119.
  7353. </t></list></t>
  7354. <t>
  7355. Note that the force of these words is modified by the requirement
  7356. level of the document in which they are used.
  7357. </t></abstract></front>
  7358. <seriesInfo name='BCP' value='14' />
  7359. <seriesInfo name='RFC' value='2119' />
  7360. <format type='TXT' octets='4723' target='http://www.rfc-editor.org/rfc/rfc2119.txt' />
  7361. <format type='HTML' octets='17491' target='http://xml.resource.org/public/rfc/html/rfc2119.html' />
  7362. <format type='XML' octets='5777' target='http://xml.resource.org/public/rfc/xml/rfc2119.xml' />
  7363. </reference>
  7364. </references>
  7365. <references title="Informative References">
  7366. <reference anchor='REQUIREMENTS'>
  7367. <front>
  7368. <title>Requirements for an Internet Audio Codec</title>
  7369. <author initials='JM' surname='Valin' fullname='Jean-Marc Valin'>
  7370. <organization /></author>
  7371. <author initials='K.' surname='Vos' fullname='Koen Vos'>
  7372. <organization /></author>
  7373. <date year='2011' month='August' />
  7374. <abstract>
  7375. <t>This document provides specific requirements for an Internet audio codec. These requirements address quality, sampling rate, bit-rate, and packet-loss robustness, as well as other desirable properties. This document is not an Internet Standards Track specification; it is published for informational purposes.</t></abstract></front>
  7376. <seriesInfo name='RFC' value='6366' />
  7377. <format type='TXT' octets='39355' target='http://www.rfc-editor.org/rfc/rfc6366.txt' />
  7378. </reference>
  7379. <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.3550.xml"?>
  7380. <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.3533.xml"?>
  7381. <!-- draft-vos-silk-01; Expired-->
  7382. <reference anchor='SILK'>
  7383. <front>
  7384. <title>SILK Speech Codec</title>
  7385. <author initials='K.' surname='Vos' fullname='Koen Vos'>
  7386. <organization />
  7387. </author>
  7388. <author initials='S.' surname='Jensen' fullname='Soren Skak Jensen'>
  7389. <organization />
  7390. </author>
  7391. <author initials='K.' surname='Sorensen' fullname='Karsten Vandborg Sorensen'>
  7392. <organization />
  7393. </author>
  7394. <date month='September' day='9' year='2010' />
  7395. <abstract><t>This document describes SILK, a speech codec for real-time, packet- based voice communications. Targeting a diverse range of operating environments, SILK provides scalability in several dimensions. Four different sampling frequencies are supported for encoding the audio input signal. Adaptation to network characteristics is provided through control of bitrate, packet rate, packet loss resilience and use of discontinuous transmission (DTX). And several different complexity levels let SILK take advantage of available processing power without relying on it. Each of these properties can be adjusted during operation of the codec on a frame-by-frame basis.</t></abstract>
  7396. </front>
  7397. <seriesInfo name='Work in' value='Progress' />
  7398. </reference>
  7399. <reference anchor="LAROIA-ICASSP">
  7400. <front>
  7401. <title abbrev="Robust and Efficient Quantization of Speech LSP">
  7402. Robust and Efficient Quantization of Speech LSP Parameters Using Structured Vector Quantization
  7403. </title>
  7404. <author initials="R." surname="Laroia" fullname="Rajiv Laroia">
  7405. <organization/>
  7406. </author>
  7407. <author initials="N." surname="Phamdo" fullname="Nam Phamdo">
  7408. <organization/>
  7409. </author>
  7410. <author initials="N." surname="Farvardin" fullname="Nariman Favardin">
  7411. <organization/>
  7412. </author>
  7413. </front>
  7414. <seriesInfo name="ICASSP-1991, Proc. IEEE Int. Conf. Acoust., Speech, Signal Processing, pp. 641-644, October" value="1991"/>
  7415. </reference>
  7416. <!--draft-valin-celt-codec-02; Expired -->
  7417. <reference anchor='CELT'>
  7418. <front>
  7419. <title>Constrained-Energy Lapped Transform (CELT) Codec</title>
  7420. <author initials='JM' surname='Valin' fullname='Jean-Marc Valin'>
  7421. <organization />
  7422. </author>
  7423. <author initials='T. B.' surname='Terriberry' fullname='Timothy B. Terriberry'>
  7424. <organization />
  7425. </author>
  7426. <author initials='G.' surname='Maxwell' fullname='Gregory Maxwell'>
  7427. <organization />
  7428. </author>
  7429. <author initials='C.' surname='Montgomery' fullname='Christopher Montgomery'>
  7430. <organization />
  7431. </author>
  7432. <date month='July' day='8' year='2010' />
  7433. <abstract><t>CELT [celt-website] is an open-source voice codec suitable for use in very low delay Voice over IP (VoIP) type applications. This document describes the encoding and decoding process.</t></abstract>
  7434. </front>
  7435. <seriesInfo name='Work in' value='Progress' />
  7436. </reference>
  7437. <reference anchor='SRTP-VBR'>
  7438. <front>
  7439. <title>Guidelines for the Use of Variable Bit Rate Audio with Secure RTP</title>
  7440. <author initials='C.' surname='Perkins' fullname='Colin Perkins'>
  7441. <organization /></author>
  7442. <author initials='JM' surname='Valin' fullname='Jean-Marc Valin'>
  7443. <organization /></author>
  7444. <date year='2012' month='March' />
  7445. <abstract>
  7446. <t>This memo discusses potential security issues that arise when using variable bit rate (VBR) audio with the secure RTP profile. Guidelines to mitigate these issues are suggested. [STANDARDS-TRACK]</t></abstract></front>
  7447. <seriesInfo name='RFC' value='6562' />
  7448. <format type='TXT' octets='14288' target='http://www.rfc-editor.org/rfc/rfc6562.txt' />
  7449. </reference>
  7450. <reference anchor='DOS'>
  7451. <front>
  7452. <title>Internet Denial-of-Service Considerations</title>
  7453. <author initials='M.' surname='Handley' fullname='Mark Handley'>
  7454. <organization /></author>
  7455. <author initials='E.' surname='Rescorla' fullname='Eric Rescorla'>
  7456. <organization /></author>
  7457. <author>
  7458. <organization>IAB</organization></author>
  7459. <date year='2006' month='December' />
  7460. <abstract>
  7461. <t>This document provides an overview of possible avenues for denial-of-service (DoS) attack on Internet systems. The aim is to encourage protocol designers and network engineers towards designs that are more robust. We discuss partial solutions that reduce the effectiveness of attacks, and how some solutions might inadvertently open up alternative vulnerabilities. This memo provides information for the Internet community.</t></abstract></front>
  7462. <seriesInfo name='RFC' value='4732' />
  7463. <format type='TXT' octets='91844' target='http://www.rfc-editor.org/rfc/rfc4732.txt' />
  7464. </reference>
  7465. <reference anchor="MARTIN79">
  7466. <front>
  7467. <title>Range encoding: An algorithm for removing redundancy from a digitised message</title>
  7468. <author initials="G.N.N." surname="Martin" fullname="G. Nigel N. Martin"><organization/></author>
  7469. <date year="1979" />
  7470. </front>
  7471. <seriesInfo name="Proc. Institution of Electronic and Radio Engineers International Conference on Video and Data" value="Recording" />
  7472. </reference>
  7473. <reference anchor="CODING-THESIS">
  7474. <front>
  7475. <title>Source coding algorithms for fast data compression</title>
  7476. <author initials="R." surname="Pasco" fullname="Richard C. Pasco"><organization/></author>
  7477. <date month="May" year="1976" />
  7478. </front>
  7479. <seriesInfo name="Ph.D. thesis" value="Dept. of Electrical Engineering, Stanford University" />
  7480. </reference>
  7481. <reference anchor="PVQ">
  7482. <front>
  7483. <title>A Pyramid Vector Quantizer</title>
  7484. <author initials="T." surname="Fischer" fullname="Thomas R. Fischer"><organization/></author>
  7485. <date month="July" year="1986" />
  7486. </front>
  7487. <seriesInfo name="IEEE Trans. on Information Theory, Vol. 32," value="pp. 568-583" />
  7488. </reference>
  7489. <reference anchor="KABAL86">
  7490. <front>
  7491. <title>The Computation of Line Spectral Frequencies Using Chebyshev Polynomials</title>
  7492. <author initials="P." surname="Kabal" fullname="Peter Kabal"><organization/></author>
  7493. <author initials="R." surname="Ramachandran" fullname="Ravi P. Ramachandran"><organization/></author>
  7494. <date month="December" year="1986" />
  7495. </front>
  7496. <seriesInfo name="IEEE Trans. Acoustics, Speech, Signal Processing, Vol. 34, no. 6," value="pp. 1419-1426" />
  7497. </reference>
  7498. <reference anchor="VALGRIND" target="http://valgrind.org/">
  7499. <front>
  7500. <title>Valgrind website</title>
  7501. <author></author>
  7502. </front>
  7503. </reference>
  7504. <reference anchor="GOOGLE-NETEQ" target="http://code.google.com/p/webrtc/source/browse/trunk/src/modules/audio_coding/NetEQ/main/source/?r=583">
  7505. <front>
  7506. <title>Google NetEQ code</title>
  7507. <author></author>
  7508. </front>
  7509. </reference>
  7510. <reference anchor="GOOGLE-WEBRTC" target="http://code.google.com/p/webrtc/">
  7511. <front>
  7512. <title>Google WebRTC code</title>
  7513. <author></author>
  7514. </front>
  7515. </reference>
  7516. <!-- [rfced] May we update the URL for reference [Opus-git] as follows?
  7517. http://git.xiph.org/?p=opus.git
  7518. -->
  7519. <reference anchor="OPUS-GIT" target="https://git.xiph.org/opus.git">
  7520. <front>
  7521. <title>Opus Git Repository</title>
  7522. <author></author>
  7523. </front>
  7524. </reference>
  7525. <reference anchor="OPUS-WEBSITE" target="http://opus-codec.org/">
  7526. <front>
  7527. <title>Opus website</title>
  7528. <author></author>
  7529. </front>
  7530. </reference>
  7531. <reference anchor="VORBIS-WEBSITE" target="http://xiph.org/vorbis/">
  7532. <front>
  7533. <title>Vorbis website</title>
  7534. <author></author>
  7535. </front>
  7536. </reference>
  7537. <reference anchor="MATROSKA-WEBSITE" target="http://matroska.org/">
  7538. <front>
  7539. <title>Matroska website</title>
  7540. <author></author>
  7541. </front>
  7542. </reference>
  7543. <reference anchor="VECTORS-WEBSITE" target="http://opus-codec.org/testvectors/">
  7544. <front>
  7545. <title>Opus Testvectors (website)</title>
  7546. <author></author>
  7547. </front>
  7548. </reference>
  7549. <reference anchor="VECTORS-PROC" target="http://www.ietf.org/proceedings/83/slides/slides-83-codec-0.gz">
  7550. <front>
  7551. <title>Opus Testvectors (proceedings)</title>
  7552. <author></author>
  7553. </front>
  7554. </reference>
  7555. <reference anchor="SPECTRAL-PAIRS" target="http://en.wikipedia.org/wiki/Line_spectral_pairs">
  7556. <front>
  7557. <title>Line Spectral Pairs</title>
  7558. <author><organization>Wikipedia</organization></author>
  7559. </front>
  7560. </reference>
  7561. <reference anchor="RANGE-CODING" target="http://en.wikipedia.org/wiki/Range_coding">
  7562. <front>
  7563. <title>Range Coding</title>
  7564. <author><organization>Wikipedia</organization></author>
  7565. </front>
  7566. </reference>
  7567. <reference anchor="HADAMARD" target="http://en.wikipedia.org/wiki/Hadamard_transform">
  7568. <front>
  7569. <title>Hadamard Transform</title>
  7570. <author><organization>Wikipedia</organization></author>
  7571. </front>
  7572. </reference>
  7573. <reference anchor="VITERBI" target="http://en.wikipedia.org/wiki/Viterbi_algorithm">
  7574. <front>
  7575. <title>Viterbi Algorithm</title>
  7576. <author><organization>Wikipedia</organization></author>
  7577. </front>
  7578. </reference>
  7579. <reference anchor="WHITENING" target="http://en.wikipedia.org/wiki/White_noise">
  7580. <front>
  7581. <title>White Noise</title>
  7582. <author><organization>Wikipedia</organization></author>
  7583. </front>
  7584. </reference>
  7585. <reference anchor="LPC" target="http://en.wikipedia.org/wiki/Linear_prediction">
  7586. <front>
  7587. <title>Linear Prediction</title>
  7588. <author><organization>Wikipedia</organization></author>
  7589. </front>
  7590. </reference>
  7591. <reference anchor="MDCT" target="http://en.wikipedia.org/wiki/Modified_discrete_cosine_transform">
  7592. <front>
  7593. <title>Modified Discrete Cosine Transform</title>
  7594. <author><organization>Wikipedia</organization></author>
  7595. </front>
  7596. </reference>
  7597. <reference anchor="FFT" target="http://en.wikipedia.org/wiki/Fast_Fourier_transform">
  7598. <front>
  7599. <title>Fast Fourier Transform</title>
  7600. <author><organization>Wikipedia</organization></author>
  7601. </front>
  7602. </reference>
  7603. <reference anchor="Z-TRANSFORM" target="http://en.wikipedia.org/wiki/Z-transform">
  7604. <front>
  7605. <title>Z-transform</title>
  7606. <author><organization>Wikipedia</organization></author>
  7607. </front>
  7608. </reference>
  7609. <reference anchor="BURG">
  7610. <front>
  7611. <title>Maximum Entropy Spectral Analysis</title>
  7612. <author initials="J.P." surname="Burg" fullname="John Parker Burg"><organization/></author>
  7613. </front>
  7614. <seriesInfo name="Proceedings of the 37th Annual International SEG Meeting, Vol. 6," value="1975"/>
  7615. </reference>
  7616. <reference anchor="SCHUR">
  7617. <front>
  7618. <title>A fixed point computation of partial correlation coefficients</title>
  7619. <author initials="J." surname="Le Roux" fullname="Joel Le Roux"><organization/></author>
  7620. <author initials="C." surname="Gueguen" fullname="Claude J. Gueguen"><organization/></author>
  7621. </front>
  7622. <seriesInfo name="ICASSP-1977, Proc. IEEE Int. Conf. Acoustics, Speech, and Signal Processing, pp. 257-259, June" value="1977"/>
  7623. </reference>
  7624. <reference anchor="PRINCEN86">
  7625. <front>
  7626. <title>Analysis/Synthesis Filter Bank Design Based on Time Domain Aliasing Cancellation</title>
  7627. <author initials="J." surname="Princen" fullname="John P. Princen"><organization/></author>
  7628. <author initials="A." surname="Bradley" fullname="Alan B. Bradley"><organization/></author>
  7629. </front>
  7630. <seriesInfo name="IEEE Trans. Acoustics, Speech, and Siginal Processing, ASSP-34 (5), pp. 1153-1161," value="October, 1986"/>
  7631. </reference>
  7632. <reference anchor="VALIN2010">
  7633. <front>
  7634. <title>A High-Quality Speech and Audio Codec With Less Than 10 ms Delay</title>
  7635. <author initials="JM" surname="Valin" fullname="Jean-Marc Valin"><organization/>
  7636. </author>
  7637. <author initials="T. B." surname="Terriberry" fullname="Timothy B. Terriberry"><organization/></author>
  7638. <author initials="C." surname="Montgomery" fullname="Christopher Montgomery"><organization/></author>
  7639. <author initials="G." surname="Maxwell" fullname="Gregory Maxwell"><organization/></author>
  7640. </front>
  7641. <seriesInfo name="IEEE Trans. on Audio, Speech, and Language Processing, Vol. 18, No. 1, pp. 58-67" value="2010" />
  7642. </reference>
  7643. <reference anchor="ZWICKER61">
  7644. <front>
  7645. <title>Subdivision of the Audible Frequency Range into Critical Bands</title>
  7646. <author initials="E." surname="Zwicker" fullname="E. Zwicker"><organization/></author>
  7647. <date month="February" year="1961" />
  7648. </front>
  7649. <seriesInfo name="The Journal of the Acoustical Society of America, Vol. 33, No 2" value="pp. 248" />
  7650. </reference>
  7651. </references>
  7652. <section anchor="ref-implementation" title="Reference Implementation">
  7653. <t>This appendix contains the complete source code for the
  7654. reference implementation of the Opus codec written in C.&nbsp; By default,
  7655. this implementation relies on floating-point arithmetic, but it can be
  7656. compiled to use only fixed-point arithmetic by defining the FIXED_POINT
  7657. macro. The normative behavior is defined as the output using the floating-point
  7658. configuration. Information on building and using the reference implementation is
  7659. available in the README file.
  7660. </t>
  7661. <t>The implementation can be compiled with either a C89 or a C99
  7662. compiler. It is reasonably optimized for most platforms such that
  7663. only architecture-specific optimizations are likely to be useful.
  7664. The Fast Fourier Transform (FFT) <xref target="FFT"/> used is a slightly modified version of the KISS-FFT library,
  7665. but it is easy to substitute any other FFT library.
  7666. </t>
  7667. <t>
  7668. While the reference implementation does not rely on any
  7669. <spanx style="emph">undefined behavior</spanx> as defined by C89 or C99,
  7670. it relies on common <spanx style="emph">implementation-defined behavior</spanx>
  7671. for two's complement architectures:
  7672. <list style="symbols">
  7673. <t>Right shifts of negative values are consistent with two's complement arithmetic, so that a>>b is equivalent to floor(a/(2**b)),</t>
  7674. <t>For conversion to a signed integer of N bits, the value is reduced modulo 2**N to be within range of the type,</t>
  7675. <t>The result of integer division of a negative value is truncated towards zero, and</t>
  7676. <t>The compiler provides a 64-bit integer type (a C99 requirement which is supported by most C89 compilers).</t>
  7677. </list>
  7678. </t>
  7679. <t>
  7680. In its current form, the reference implementation also requires the following
  7681. architectural characteristics to obtain acceptable performance:
  7682. <list style="symbols">
  7683. <t>Two's complement arithmetic,</t>
  7684. <t>At least a 16 bit by 16 bit integer multiplier (32-bit result), and</t>
  7685. <t>At least a 32-bit adder/accumulator.</t>
  7686. </list>
  7687. </t>
  7688. <section title="Extracting the Source">
  7689. <t>
  7690. The complete source code can be extracted from this document, by running the
  7691. following command line:
  7692. <list style="symbols">
  7693. <t><![CDATA[
  7694. cat rfc6716.txt | grep '^\ \ \ ###' | sed -e 's/...###//' | base64 -d > opus-rfc6716.tar.gz
  7695. ]]></t>
  7696. <t>
  7697. tar xzvf opus-rfc6716.tar.gz
  7698. </t>
  7699. <t>cd opus-rfc6716</t>
  7700. <t>make</t>
  7701. </list>
  7702. On systems where the provided Makefile does not work, the following command line may be used to compile
  7703. the source code:
  7704. <list style="symbols">
  7705. <t><![CDATA[
  7706. cc -O2 -g -o opus_demo src/opus_demo.c `cat *.mk | grep -v fixed | sed -e 's/.*=//' -e 's/\\\\//'` -DOPUS_BUILD -Iinclude -Icelt -Isilk -Isilk/float -DUSE_ALLOCA -Drestrict= -lm
  7707. ]]></t></list>
  7708. </t>
  7709. <t>
  7710. On systems where the base64 utility is not present, the following commands can be used instead:
  7711. <list style="symbols">
  7712. <t><![CDATA[
  7713. cat rfc6716.txt | grep '^\ \ \ ###' | sed -e 's/...###//' > opus.b64
  7714. ]]></t>
  7715. <t>openssl base64 -d -in opus.b64 > opus-rfc6716.tar.gz</t>
  7716. </list>
  7717. The SHA1 hash of the opus-rfc6716.tar.gz file is <?rfc include="code_sha1"?>
  7718. </t>
  7719. </section>
  7720. <section title="Up-to-Date Implementation">
  7721. <t>
  7722. As of the time of publication of this memo, an up-to-date implementation conforming to
  7723. this standard is available in a
  7724. <xref target='OPUS-GIT'>Git repository</xref>.
  7725. <!-- In the following, should "standard" be "Proposed Standard" (occurs 2x)?
  7726. As of the time of publication of this memo, an up-to-date implementation
  7727. conforming to this standard is available in a Git repository [OPUS-GIT].
  7728. However, although that implementation is expected to
  7729. remain conformant with the standard, it is the code in this document that
  7730. shall remain normative.
  7731. -->
  7732. Releases and other resources are available at
  7733. <xref target='OPUS-WEBSITE'/>. However, although that implementation is expected to
  7734. remain conformant with the standard, it is the code in this document that shall
  7735. remain normative.
  7736. </t>
  7737. </section>
  7738. <!--[rfced] We note that the files you sent (3 July) do not match what was
  7739. included in the original version 16 submitted. After speaking with Robert
  7740. Sparks, our understanding is that you will send us an updated file
  7741. that includes the RFC number and addresses these RFC Editor notes from the
  7742. Protocol Action:
  7743. Please work with the draft editors to replace rfcXXXX as it appears in the
  7744. files in the appendix with the rfc number assigned for this draft.
  7745. Please work with the draft editors to ensure that the following is added (with
  7746. XXXX replaced appropriately) to the README file in the appendix: "These
  7747. files were extracted from RFCXXXX. Please see that RFC for additional
  7748. information."
  7749. Additionally, we will ask Robert Sparks to approve the final update. Please
  7750. let us know if you need any additional information from us to make the
  7751. necessary updates.
  7752. -->
  7753. <section title="Base64-Encoded Source Code">
  7754. <t>
  7755. <?rfc include="opus-rfc6716.base64"?>
  7756. </t>
  7757. </section>
  7758. <section anchor="test-vectors" title="Test Vectors">
  7759. <t>
  7760. Because of size constraints, the Opus test vectors are not distributed in this
  7761. document. They are available in the proceedings of the 83rd IETF meeting (Paris) <xref target="VECTORS-PROC"/> and from the Opus codec website at
  7762. <xref target="VECTORS-WEBSITE"/>. These test vectors were created specifically to exercise
  7763. all aspects of the decoder.
  7764. Therefore, the audio quality of the decoded output is
  7765. significantly lower than what Opus can achieve in normal operation.
  7766. </t>
  7767. <t>
  7768. The SHA1 hash of the files in the test vector package are
  7769. <figure>
  7770. <artwork>
  7771. <![CDATA[
  7772. e49b2862ceec7324790ed8019eb9744596d5be01 testvector01.bit
  7773. b809795ae1bcd606049d76de4ad24236257135e0 testvector02.bit
  7774. e0c4ecaeab44d35a2f5b6575cd996848e5ee2acc testvector03.bit
  7775. a0f870cbe14ebb71fa9066ef3ee96e59c9a75187 testvector04.bit
  7776. 9b3d92b48b965dfe9edf7b8a85edd4309f8cf7c8 testvector05.bit
  7777. 28e66769ab17e17f72875283c14b19690cbc4e57 testvector06.bit
  7778. bacf467be3215fc7ec288f29e2477de1192947a6 testvector07.bit
  7779. ddbe08b688bbf934071f3893cd0030ce48dba12f testvector08.bit
  7780. 3932d9d61944dab1201645b8eeaad595d5705ecb testvector09.bit
  7781. 521eb2a1e0cc9c31b8b740673307c2d3b10c1900 testvector10.bit
  7782. 6bc8f3146fcb96450c901b16c3d464ccdf4d5d96 testvector11.bit
  7783. 338c3f1b4b97226bc60bc41038becbc6de06b28f testvector12.bit
  7784. a20a2122d42de644f94445e20185358559623a1f testvector01.dec
  7785. 48ac1ff1995250a756e1e17bd32acefa8cd2b820 testvector02.dec
  7786. d15567e919db2d0e818727092c0af8dd9df23c95 testvector03.dec
  7787. 1249dd28f5bd1e39a66fd6d99449dca7a8316342 testvector04.dec
  7788. 93eee37e5d26a456d2c24483060132ff7eae2143 testvector05.dec
  7789. a294fc17e3157768c46c5ec0f2116de0d2c37ee2 testvector06.dec
  7790. 2bf550e2f072e0941438db3f338fe99444385848 testvector07.dec
  7791. 2695c1f2d1f9748ea0bf07249c70fd7b87f61680 testvector08.dec
  7792. 12862add5d53a9d2a7079340a542a2f039b992bb testvector09.dec
  7793. a081252bb2b1a902fdc500530891f47e2a373d84 testvector10.dec
  7794. dfd0f844f2a42df506934fac2100a3c03beec711 testvector11.dec
  7795. 8c16b2a1fb60e3550ba165068f9d7341357fdb63 testvector12.dec
  7796. ]]>
  7797. </artwork>
  7798. </figure>
  7799. </t>
  7800. </section>
  7801. </section>
  7802. <section anchor="self-delimiting-framing" title="Self-Delimiting Framing">
  7803. <t>
  7804. To use the internal framing described in <xref target="modes"/>, the decoder
  7805. must know the total length of the Opus packet, in bytes.
  7806. This section describes a simple variation of that framing that can be used
  7807. when the total length of the packet is not known.
  7808. Nothing in the encoding of the packet itself allows a decoder to distinguish
  7809. between the regular, undelimited framing and the self-delimiting framing
  7810. described in this appendix.
  7811. Which one is used and where must be established by context at the transport
  7812. layer.
  7813. It is RECOMMENDED that a transport layer choose exactly one framing scheme,
  7814. rather than allowing an encoder to signal which one it wants to use.
  7815. </t>
  7816. <t>
  7817. For example, although a regular Opus stream does not support more than two
  7818. channels, a multi-channel Opus stream may be formed from several one- and
  7819. two-channel streams.
  7820. To pack an Opus packet from each of these streams together in a single packet
  7821. at the transport layer, one could use the self-delimiting framing for all but
  7822. the last stream, and then the regular, undelimited framing for the last one.
  7823. Reverting to the undelimited framing for the last stream saves overhead
  7824. (because the total size of the transport-layer packet will still be known),
  7825. and ensures that a "multi-channel" stream that only has a single Opus stream
  7826. uses the same framing as a regular Opus stream does.
  7827. This avoids the need for signaling to distinguish these two cases.
  7828. </t>
  7829. <t>
  7830. The self-delimiting framing is identical to the regular, undelimited framing
  7831. from <xref target="modes"/>, except that each Opus packet contains one extra
  7832. length field, encoded using the same one- or two-byte scheme from
  7833. <xref target="frame-length-coding"/>.
  7834. This extra length immediately precedes the compressed data of the first Opus
  7835. frame in the packet, and is interpreted in the various modes as follows:
  7836. <list style="symbols">
  7837. <t>
  7838. Code&nbsp;0 packets: It is the length of the single Opus frame (see
  7839. <xref target="sd_code0_packet"/>).
  7840. </t>
  7841. <t>
  7842. Code&nbsp;1 packets: It is the length used for both of the Opus frames (see
  7843. <xref target="sd_code1_packet"/>).
  7844. </t>
  7845. <t>
  7846. Code&nbsp;2 packets: It is the length of the second Opus frame (see
  7847. <xref target="sd_code2_packet"/>).</t>
  7848. <t>
  7849. CBR Code&nbsp;3 packets: It is the length used for all of the Opus frames (see
  7850. <xref target="sd_code3cbr_packet"/>).
  7851. </t>
  7852. <t>VBR Code&nbsp;3 packets: It is the length of the last Opus frame (see
  7853. <xref target="sd_code3vbr_packet"/>).
  7854. </t>
  7855. </list>
  7856. </t>
  7857. <figure anchor="sd_code0_packet" title="A Self-Delimited Code 0 Packet"
  7858. align="center">
  7859. <artwork align="center"><![CDATA[
  7860. 0 1 2 3
  7861. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  7862. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7863. | config |s|0|0| N1 (1-2 bytes): |
  7864. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
  7865. | Compressed frame 1 (N1 bytes)... :
  7866. : |
  7867. | |
  7868. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7869. ]]></artwork>
  7870. </figure>
  7871. <figure anchor="sd_code1_packet" title="A Self-Delimited Code 1 Packet"
  7872. align="center">
  7873. <artwork align="center"><![CDATA[
  7874. 0 1 2 3
  7875. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  7876. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7877. | config |s|0|1| N1 (1-2 bytes): |
  7878. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ :
  7879. | Compressed frame 1 (N1 bytes)... |
  7880. : +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7881. | | |
  7882. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ :
  7883. | Compressed frame 2 (N1 bytes)... |
  7884. : +-+-+-+-+-+-+-+-+
  7885. | |
  7886. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7887. ]]></artwork>
  7888. </figure>
  7889. <figure anchor="sd_code2_packet" title="A Self-Delimited Code 2 Packet"
  7890. align="center">
  7891. <artwork align="center"><![CDATA[
  7892. 0 1 2 3
  7893. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  7894. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7895. | config |s|1|0| N1 (1-2 bytes): N2 (1-2 bytes : |
  7896. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ :
  7897. | Compressed frame 1 (N1 bytes)... |
  7898. : +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7899. | | |
  7900. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
  7901. | Compressed frame 2 (N2 bytes)... :
  7902. : |
  7903. | |
  7904. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7905. ]]></artwork>
  7906. </figure>
  7907. <figure anchor="sd_code3cbr_packet" title="A Self-Delimited CBR Code 3 Packet"
  7908. align="center">
  7909. <artwork align="center"><![CDATA[
  7910. 0 1 2 3
  7911. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  7912. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7913. | config |s|1|1|0|p| M | Pad len (Opt) : N1 (1-2 bytes):
  7914. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7915. | |
  7916. : Compressed frame 1 (N1 bytes)... :
  7917. | |
  7918. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7919. | |
  7920. : Compressed frame 2 (N1 bytes)... :
  7921. | |
  7922. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7923. | |
  7924. : ... :
  7925. | |
  7926. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7927. | |
  7928. : Compressed frame M (N1 bytes)... :
  7929. | |
  7930. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7931. : Opus Padding (Optional)... |
  7932. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7933. ]]></artwork>
  7934. </figure>
  7935. <figure anchor="sd_code3vbr_packet" title="A Self-Delimited VBR Code 3 Packet"
  7936. align="center">
  7937. <artwork align="center"><![CDATA[
  7938. 0 1 2 3
  7939. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  7940. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7941. | config |s|1|1|1|p| M | Padding length (Optional) :
  7942. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7943. : N1 (1-2 bytes): ... : N[M-1] | N[M] :
  7944. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7945. | |
  7946. : Compressed frame 1 (N1 bytes)... :
  7947. | |
  7948. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7949. | |
  7950. : Compressed frame 2 (N2 bytes)... :
  7951. | |
  7952. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7953. | |
  7954. : ... :
  7955. | |
  7956. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7957. | |
  7958. : Compressed frame M (N[M] bytes)... :
  7959. | |
  7960. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7961. : Opus Padding (Optional)... |
  7962. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7963. ]]></artwork>
  7964. </figure>
  7965. </section>
  7966. </back>
  7967. </rfc>