draft-ietf-codec-opus.xml 363 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE rfc SYSTEM 'rfc2629.dtd'>
  3. <?rfc toc="yes" symrefs="yes" ?>
  4. <rfc ipr="trust200902" category="std" docName="draft-ietf-codec-opus-14">
  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>koen.vos@skype.net</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 day="17" month="May" year="2012" />
  50. <area>General</area>
  51. <workgroup></workgroup>
  52. <abstract>
  53. <t>
  54. This document defines the Opus interactive speech and audio codec.
  55. Opus is designed to handle a wide range of interactive audio applications,
  56. including Voice over IP, videoconferencing, in-game chat, and even live,
  57. distributed music performances.
  58. It scales from low bitrate narrowband speech at 6 kb/s to very high quality
  59. stereo music at 510 kb/s.
  60. Opus uses both linear prediction (LP) and the Modified Discrete Cosine
  61. Transform (MDCT) to achieve good compression of both speech and music.
  62. </t>
  63. </abstract>
  64. </front>
  65. <middle>
  66. <section anchor="introduction" title="Introduction">
  67. <t>
  68. The Opus codec is a real-time interactive audio codec designed to meet the requirements
  69. described in <xref target="requirements"></xref>.
  70. It is composed of a linear
  71. prediction (LP)-based <xref target="LPC"/> layer and a Modified Discrete Cosine Transform
  72. (MDCT)-based <xref target="MDCT"/> layer.
  73. The main idea behind using two layers is that in speech, linear prediction
  74. techniques (such as Code-Excited Linear Prediction, or CELP) code low frequencies more efficiently than transform
  75. (e.g., MDCT) domain techniques, while the situation is reversed for music and
  76. higher speech frequencies.
  77. Thus a codec with both layers available can operate over a wider range than
  78. either one alone and, by combining them, achieve better quality than either
  79. one individually.
  80. </t>
  81. <t>
  82. The primary normative part of this specification is provided by the source code
  83. in <xref target="ref-implementation"></xref>.
  84. Only the decoder portion of this software is normative, though a
  85. significant amount of code is shared by both the encoder and decoder.
  86. <xref target="conformance"/> provides a decoder conformance test.
  87. The decoder contains a great deal of integer and fixed-point arithmetic which
  88. needs to be performed exactly, including all rounding considerations, so any
  89. useful specification requires domain-specific symbolic language to adequately
  90. define these operations.
  91. Additionally, any
  92. conflict between the symbolic representation and the included reference
  93. implementation must be resolved. For the practical reasons of compatibility and
  94. testability it would be advantageous to give the reference implementation
  95. priority in any disagreement. The C language is also one of the most
  96. widely understood human-readable symbolic representations for machine
  97. behavior.
  98. For these reasons this RFC uses the reference implementation as the sole
  99. symbolic representation of the codec.
  100. </t>
  101. <t>While the symbolic representation is unambiguous and complete it is not
  102. always the easiest way to understand the codec's operation. For this reason
  103. this document also describes significant parts of the codec in English and
  104. takes the opportunity to explain the rationale behind many of the more
  105. surprising elements of the design. These descriptions are intended to be
  106. accurate and informative, but the limitations of common English sometimes
  107. result in ambiguity, so it is expected that the reader will always read
  108. them alongside the symbolic representation. Numerous references to the
  109. implementation are provided for this purpose. The descriptions sometimes
  110. differ from the reference in ordering or through mathematical simplification
  111. wherever such deviation makes an explanation easier to understand.
  112. For example, the right shift and left shift operations in the reference
  113. implementation are often described using division and multiplication in the text.
  114. In general, the text is focused on the "what" and "why" while the symbolic
  115. representation most clearly provides the "how".
  116. </t>
  117. <section anchor="notation" title="Notation and Conventions">
  118. <t>
  119. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
  120. "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be
  121. interpreted as described in RFC 2119 <xref target="rfc2119"></xref>.
  122. </t>
  123. <t>
  124. Various operations in the codec require bit-exact fixed-point behavior, even
  125. when writing a floating point implementation.
  126. The notation "Q&lt;n&gt;", where n is an integer, denotes the number of binary
  127. digits to the right of the decimal point in a fixed-point number.
  128. For example, a signed Q14 value in a 16-bit word can represent values from
  129. -2.0 to 1.99993896484375, inclusive.
  130. This notation is for informational purposes only.
  131. Arithmetic, when described, always operates on the underlying integer.
  132. E.g., the text will explicitly indicate any shifts required after a
  133. multiplication.
  134. </t>
  135. <t>
  136. Expressions, where included in the text, follow C operator rules and
  137. precedence, with the exception that the syntax "x**y" indicates x raised to
  138. the power y.
  139. The text also makes use of the following functions:
  140. </t>
  141. <section anchor="min" toc="exclude" title="min(x,y)">
  142. <t>
  143. The smallest of two values x and y.
  144. </t>
  145. </section>
  146. <section anchor="max" toc="exclude" title="max(x,y)">
  147. <t>
  148. The largest of two values x and y.
  149. </t>
  150. </section>
  151. <section anchor="clamp" toc="exclude" title="clamp(lo,x,hi)">
  152. <figure align="center">
  153. <artwork align="center"><![CDATA[
  154. clamp(lo,x,hi) = max(lo,min(x,hi))
  155. ]]></artwork>
  156. </figure>
  157. <t>
  158. With this definition, if lo&nbsp;&gt;&nbsp;hi, the lower bound is the one that
  159. is enforced.
  160. </t>
  161. </section>
  162. <section anchor="sign" toc="exclude" title="sign(x)">
  163. <t>
  164. The sign of x, i.e.,
  165. <figure align="center">
  166. <artwork align="center"><![CDATA[
  167. ( -1, x < 0 ,
  168. sign(x) = < 0, x == 0 ,
  169. ( 1, x > 0 .
  170. ]]></artwork>
  171. </figure>
  172. </t>
  173. </section>
  174. <section anchor="abs" toc="exclude" title="abs(x)">
  175. <t>
  176. The absolute value of x, i.e.,
  177. <figure align="center">
  178. <artwork align="center"><![CDATA[
  179. abs(x) = sign(x)*x .
  180. ]]></artwork>
  181. </figure>
  182. </t>
  183. </section>
  184. <section anchor="floor" toc="exclude" title="floor(f)">
  185. <t>
  186. The largest integer z such that z &lt;= f.
  187. </t>
  188. </section>
  189. <section anchor="ceil" toc="exclude" title="ceil(f)">
  190. <t>
  191. The smallest integer z such that z &gt;= f.
  192. </t>
  193. </section>
  194. <section anchor="round" toc="exclude" title="round(f)">
  195. <t>
  196. The integer z nearest to f, with ties rounded towards negative infinity,
  197. i.e.,
  198. <figure align="center">
  199. <artwork align="center"><![CDATA[
  200. round(f) = ceil(f - 0.5) .
  201. ]]></artwork>
  202. </figure>
  203. </t>
  204. </section>
  205. <section anchor="log2" toc="exclude" title="log2(f)">
  206. <t>
  207. The base-two logarithm of f.
  208. </t>
  209. </section>
  210. <section anchor="ilog" toc="exclude" title="ilog(n)">
  211. <t>
  212. The minimum number of bits required to store a positive integer n in two's
  213. complement notation, or 0 for a non-positive integer n.
  214. <figure align="center">
  215. <artwork align="center"><![CDATA[
  216. ( 0, n <= 0,
  217. ilog(n) = <
  218. ( floor(log2(n))+1, n > 0
  219. ]]></artwork>
  220. </figure>
  221. Examples:
  222. <list style="symbols">
  223. <t>ilog(-1) = 0</t>
  224. <t>ilog(0) = 0</t>
  225. <t>ilog(1) = 1</t>
  226. <t>ilog(2) = 2</t>
  227. <t>ilog(3) = 2</t>
  228. <t>ilog(4) = 3</t>
  229. <t>ilog(7) = 3</t>
  230. </list>
  231. </t>
  232. </section>
  233. </section>
  234. </section>
  235. <section anchor="overview" title="Opus Codec Overview">
  236. <t>
  237. The Opus codec scales from 6&nbsp;kb/s narrowband mono speech to 510&nbsp;kb/s
  238. fullband stereo music, with algorithmic delays ranging from 5&nbsp;ms to
  239. 65.2&nbsp;ms.
  240. At any given time, either the LP layer, the MDCT layer, or both, may be active.
  241. It can seamlessly switch between all of its various operating modes, giving it
  242. a great deal of flexibility to adapt to varying content and network
  243. conditions without renegotiating the current session.
  244. The codec allows input and output of various audio bandwidths, defined as
  245. follows:
  246. </t>
  247. <texttable anchor="audio-bandwidth">
  248. <ttcol>Abbreviation</ttcol>
  249. <ttcol align="right">Audio Bandwidth</ttcol>
  250. <ttcol align="right">Sample Rate (Effective)</ttcol>
  251. <c>NB (narrowband)</c> <c>4&nbsp;kHz</c> <c>8&nbsp;kHz</c>
  252. <c>MB (medium-band)</c> <c>6&nbsp;kHz</c> <c>12&nbsp;kHz</c>
  253. <c>WB (wideband)</c> <c>8&nbsp;kHz</c> <c>16&nbsp;kHz</c>
  254. <c>SWB (super-wideband)</c> <c>12&nbsp;kHz</c> <c>24&nbsp;kHz</c>
  255. <c>FB (fullband)</c> <c>20&nbsp;kHz (*)</c> <c>48&nbsp;kHz</c>
  256. </texttable>
  257. <t>
  258. (*) Although the sampling theorem allows a bandwidth as large as half the
  259. sampling rate, Opus never codes audio above 20&nbsp;kHz, as that is the
  260. generally accepted upper limit of human hearing.
  261. </t>
  262. <t>
  263. Opus defines super-wideband (SWB) with an effective sample rate of 24&nbsp;kHz,
  264. unlike some other audio coding standards that use 32&nbsp;kHz.
  265. This was chosen for a number of reasons.
  266. The band layout in the MDCT layer naturally allows skipping coefficients for
  267. frequencies over 12&nbsp;kHz, but does not allow cleanly dropping just those
  268. frequencies over 16&nbsp;kHz.
  269. A sample rate of 24&nbsp;kHz also makes resampling in the MDCT layer easier,
  270. as 24 evenly divides 48, and when 24&nbsp;kHz is sufficient, it can save
  271. computation in other processing, such as Acoustic Echo Cancellation (AEC).
  272. Experimental changes to the band layout to allow a 16&nbsp;kHz cutoff
  273. (32&nbsp;kHz effective sample rate) showed potential quality degradations at
  274. other sample rates, and at typical bitrates the number of bits saved by using
  275. such a cutoff instead of coding in fullband (FB) mode is very small.
  276. Therefore, if an application wishes to process a signal sampled at 32&nbsp;kHz,
  277. it should just use FB.
  278. </t>
  279. <t>
  280. The LP layer is based on the SILK codec
  281. <xref target="SILK"></xref>.
  282. It supports NB, MB, or WB audio and frame sizes from 10&nbsp;ms to 60&nbsp;ms,
  283. and requires an additional 5&nbsp;ms look-ahead for noise shaping estimation.
  284. A small additional delay (up to 1.5 ms) may be required for sampling rate
  285. conversion.
  286. Like Vorbis <xref target='Vorbis-website'/> and many other modern codecs, SILK is inherently designed for
  287. variable-bitrate (VBR) coding, though the encoder can also produce
  288. constant-bitrate (CBR) streams.
  289. The version of SILK used in Opus is substantially modified from, and not
  290. compatible with, the stand-alone SILK codec previously deployed by Skype.
  291. This document does not serve to define that format, but those interested in the
  292. original SILK codec should see <xref target="SILK"/> instead.
  293. </t>
  294. <t>
  295. The MDCT layer is based on the CELT codec <xref target="CELT"></xref>.
  296. It supports NB, WB, SWB, or FB audio and frame sizes from 2.5&nbsp;ms to
  297. 20&nbsp;ms, and requires an additional 2.5&nbsp;ms look-ahead due to the
  298. overlapping MDCT windows.
  299. The CELT codec is inherently designed for CBR coding, but unlike many CBR
  300. codecs it is not limited to a set of predetermined rates.
  301. It internally allocates bits to exactly fill any given target budget, and an
  302. encoder can produce a VBR stream by varying the target on a per-frame basis.
  303. The MDCT layer is not used for speech when the audio bandwidth is WB or less,
  304. as it is not useful there.
  305. On the other hand, non-speech signals are not always adequately coded using
  306. linear prediction, so for music only the MDCT layer should be used.
  307. </t>
  308. <t>
  309. A "Hybrid" mode allows the use of both layers simultaneously with a frame size
  310. of 10&nbsp;or 20&nbsp;ms and a SWB or FB audio bandwidth.
  311. The LP layer codes the low frequencies by resampling the signal down to WB.
  312. The MDCT layer follows, coding the high frequency portion of the signal.
  313. The cutoff between the two lies at 8&nbsp;kHz, the maximum WB audio bandwidth.
  314. In the MDCT layer, all bands below 8&nbsp;kHz are discarded, so there is no
  315. coding redundancy between the two layers.
  316. </t>
  317. <t>
  318. The sample rate (in contrast to the actual audio bandwidth) can be chosen
  319. independently on the encoder and decoder side, e.g., a fullband signal can be
  320. decoded as wideband, or vice versa.
  321. This approach ensures a sender and receiver can always interoperate, regardless
  322. of the capabilities of their actual audio hardware.
  323. Internally, the LP layer always operates at a sample rate of twice the audio
  324. bandwidth, up to a maximum of 16&nbsp;kHz, which it continues to use for SWB
  325. and FB.
  326. The decoder simply resamples its output to support different sample rates.
  327. The MDCT layer always operates internally at a sample rate of 48&nbsp;kHz.
  328. Since all the supported sample rates evenly divide this rate, and since the
  329. the decoder may easily zero out the high frequency portion of the spectrum in
  330. the frequency domain, it can simply decimate the MDCT layer output to achieve
  331. the other supported sample rates very cheaply.
  332. </t>
  333. <t>
  334. After conversion to the common, desired output sample rate, the decoder simply
  335. adds the output from the two layers together.
  336. To compensate for the different look-ahead required by each layer, the CELT
  337. encoder input is delayed by an additional 2.7&nbsp;ms.
  338. This ensures that low frequencies and high frequencies arrive at the same time.
  339. This extra delay may be reduced by an encoder by using less look-ahead for noise
  340. shaping or using a simpler resampler in the LP layer, but this will reduce
  341. quality.
  342. However, the base 2.5&nbsp;ms look-ahead in the CELT layer cannot be reduced in
  343. the encoder because it is needed for the MDCT overlap, whose size is fixed by
  344. the decoder.
  345. </t>
  346. <t>
  347. Both layers use the same entropy coder, avoiding any waste from "padding bits"
  348. between them.
  349. The hybrid approach makes it easy to support both CBR and VBR coding.
  350. Although the LP layer is VBR, the bit allocation of the MDCT layer can produce
  351. a final stream that is CBR by using all the bits left unused by the LP layer.
  352. </t>
  353. <section title="Control Parameters">
  354. <t>
  355. The Opus codec includes a number of control parameters which can be changed dynamically during
  356. regular operation of the codec, without interrupting the audio stream from the encoder to the decoder.
  357. These parameters only affect the encoder since any impact they have on the bit-stream is signaled
  358. in-band such that a decoder can decode any Opus stream without any out-of-band signaling. Any Opus
  359. implementation can add or modify these control parameters without affecting interoperability. The most
  360. important encoder control parameters in the reference encoder are listed below.
  361. </t>
  362. <section title="Bitrate" toc="exlcude">
  363. <t>
  364. Opus supports all bitrates from 6&nbsp;kb/s to 510&nbsp;kb/s. All other parameters being
  365. equal, higher bitrate results in higher quality. For a frame size of 20&nbsp;ms, these
  366. are the bitrate "sweet spots" for Opus in various configurations:
  367. <list style="symbols">
  368. <t>8-12 kb/s for NB speech,</t>
  369. <t>16-20 kb/s for WB speech,</t>
  370. <t>28-40 kb/s for FB speech,</t>
  371. <t>48-64 kb/s for FB mono music, and</t>
  372. <t>64-128 kb/s for FB stereo music.</t>
  373. </list>
  374. </t>
  375. </section>
  376. <section title="Number of Channels (Mono/Stereo)" toc="exlcude">
  377. <t>
  378. Opus can transmit either mono or stereo frames within a single stream.
  379. When decoding a mono frame in a stereo decoder, the left and right channels are
  380. identical, and when decoding a stereo frame in a mono decoder, the mono output
  381. is the average of the left and right channels.
  382. In some cases, it is desirable to encode a stereo input stream in mono (e.g.,
  383. because the bitrate is too low to encode stereo with sufficient quality).
  384. The number of channels encoded can be selected in real-time, but by default the
  385. reference encoder attempts to make the best decision possible given the
  386. current bitrate.
  387. </t>
  388. </section>
  389. <section title="Audio Bandwidth" toc="exlcude">
  390. <t>
  391. The audio bandwidths supported by Opus are listed in
  392. <xref target="audio-bandwidth"/>.
  393. Just like for the number of channels, any decoder can decode audio encoded at
  394. any bandwidth.
  395. For example, any Opus decoder operating at 8&nbsp;kHz can decode a FB Opus
  396. frame, and any Opus decoder operating at 48&nbsp;kHz can decode a NB frame.
  397. Similarly, the reference encoder can take a 48&nbsp;kHz input signal and
  398. encode it as NB.
  399. The higher the audio bandwidth, the higher the required bitrate to achieve
  400. acceptable quality.
  401. The audio bandwidth can be explicitly specified in real-time, but by default
  402. the reference encoder attempts to make the best bandwidth decision possible
  403. given the current bitrate.
  404. </t>
  405. </section>
  406. <section title="Frame Duration" toc="exlcude">
  407. <t>
  408. Opus can encode frames of 2.5, 5, 10, 20, 40 or 60&nbsp;ms.
  409. It can also combine multiple frames into packets of up to 120&nbsp;ms.
  410. For real-time applications, sending fewer packets per second reduces the
  411. bitrate, since it reduces the overhead from IP, UDP, and RTP headers.
  412. However, it increases latency and sensitivity to packet losses, as losing one
  413. packet constitutes a loss of a bigger chunk of audio.
  414. Increasing the frame duration also slightly improves coding efficiency, but the
  415. gain becomes small for frame sizes above 20&nbsp;ms.
  416. For this reason, 20&nbsp;ms frames are a good choice for most applications.
  417. </t>
  418. </section>
  419. <section title="Complexity" toc="exlcude">
  420. <t>
  421. There are various aspects of the Opus encoding process where trade-offs
  422. can be made between CPU complexity and quality/bitrate. In the reference
  423. encoder, the complexity is selected using an integer from 0 to 10, where
  424. 0 is the lowest complexity and 10 is the highest. Examples of
  425. computations for which such trade-offs may occur are:
  426. <list style="symbols">
  427. <t>The order of the pitch analysis whitening filter <xref target="Whitening"/>,</t>
  428. <t>The order of the short-term noise shaping filter,</t>
  429. <t>The number of states in delayed decision quantization of the
  430. residual signal, and</t>
  431. <t>The use of certain bit-stream features such as variable time-frequency
  432. resolution and the pitch post-filter.</t>
  433. </list>
  434. </t>
  435. </section>
  436. <section title="Packet Loss Resilience" toc="exlcude">
  437. <t>
  438. Audio codecs often exploit inter-frame correlations to reduce the
  439. bitrate at a cost in error propagation: after losing one packet
  440. several packets need to be received before the decoder is able to
  441. accurately reconstruct the speech signal. The extent to which Opus
  442. exploits inter-frame dependencies can be adjusted on the fly to
  443. choose a trade-off between bitrate and amount of error propagation.
  444. </t>
  445. </section>
  446. <section title="Forward Error Correction (FEC)" toc="exlcude">
  447. <t>
  448. Another mechanism providing robustness against packet loss is the in-band
  449. Forward Error Correction (FEC). Packets that are determined to
  450. contain perceptually important speech information, such as onsets or
  451. transients, are encoded again at a lower bitrate and this re-encoded
  452. information is added to a subsequent packet.
  453. </t>
  454. </section>
  455. <section title="Constant/Variable Bitrate" toc="exlcude">
  456. <t>
  457. Opus is more efficient when operating with variable bitrate (VBR), which is
  458. the default. However, in some (rare) applications, constant bitrate (CBR)
  459. is required. There are two main reasons to operate in CBR mode:
  460. <list style="symbols">
  461. <t>When the transport only supports a fixed size for each compressed frame</t>
  462. <t>When encryption is used for an audio stream that is either highly constrained
  463. (e.g. yes/no, recorded prompts) or highly sensitive <xref target="SRTP-VBR"></xref> </t>
  464. </list>
  465. When low-latency transmission is required over a relatively slow connection, then
  466. constrained VBR can also be used. This uses VBR in a way that simulates a
  467. "bit reservoir" and is equivalent to what MP3 (MPEG 1, Layer 3) and
  468. AAC (Advanced Audio Coding) call CBR (i.e., not true
  469. CBR due to the bit reservoir).
  470. </t>
  471. </section>
  472. <section title="Discontinuous Transmission (DTX)" toc="exlcude">
  473. <t>
  474. Discontinuous Transmission (DTX) reduces the bitrate during silence
  475. or background noise. When DTX is enabled, only one frame is encoded
  476. every 400 milliseconds.
  477. </t>
  478. </section>
  479. </section>
  480. </section>
  481. <section anchor="modes" title="Internal Framing">
  482. <t>
  483. The Opus encoder produces "packets", which are each a contiguous set of bytes
  484. meant to be transmitted as a single unit.
  485. The packets described here do not include such things as IP, UDP, or RTP
  486. headers which are normally found in a transport-layer packet.
  487. A single packet may contain multiple audio frames, so long as they share a
  488. common set of parameters, including the operating mode, audio bandwidth, frame
  489. size, and channel count (mono vs. stereo).
  490. This section describes the possible combinations of these parameters and the
  491. internal framing used to pack multiple frames into a single packet.
  492. This framing is not self-delimiting.
  493. Instead, it assumes that a higher layer (such as UDP or RTP <xref target='RFC3550'/>
  494. or Ogg <xref target='RFC3533'/> or Matroska <xref target='Matroska-website'/>)
  495. will communicate the length, in bytes, of the packet, and it uses this
  496. information to reduce the framing overhead in the packet itself.
  497. A decoder implementation MUST support the framing described in this section.
  498. An alternative, self-delimiting variant of the framing is described in
  499. <xref target="self-delimiting-framing"/>.
  500. Support for that variant is OPTIONAL.
  501. </t>
  502. <t>
  503. All bit diagrams in this document number the bits so that bit 0 is the most
  504. significant bit of the first byte, and bit 7 is the least significant.
  505. Bit 8 is thus the most significant bit of the second byte, etc.
  506. Well-formed Opus packets obey certain requirements, marked [R1] through [R7]
  507. below.
  508. These are summarized in <xref target="malformed-packets"/> along with
  509. appropriate means of handling malformed packets.
  510. </t>
  511. <section anchor="toc_byte" title="The TOC Byte">
  512. <t anchor="R1">
  513. A well-formed Opus packet MUST contain at least one byte&nbsp;[R1].
  514. This byte forms a table-of-contents (TOC) header that signals which of the
  515. various modes and configurations a given packet uses.
  516. It is composed of a configuration number, "config", a stereo flag, "s", and a
  517. frame count code, "c", arranged as illustrated in
  518. <xref target="toc_byte_fig"/>.
  519. A description of each of these fields follows.
  520. </t>
  521. <figure anchor="toc_byte_fig" title="The TOC Byte">
  522. <artwork align="center"><![CDATA[
  523. 0
  524. 0 1 2 3 4 5 6 7
  525. +-+-+-+-+-+-+-+-+
  526. | config |s| c |
  527. +-+-+-+-+-+-+-+-+
  528. ]]></artwork>
  529. </figure>
  530. <t>
  531. The top five bits of the TOC byte, labeled "config", encode one of 32 possible
  532. configurations of operating mode, audio bandwidth, and frame size.
  533. As described, the LP (SILK) layer and MDCT (CELT) layer can be combined in three possible
  534. operating modes:
  535. <list style="numbers">
  536. <t>A SILK-only mode for use in low bitrate connections with an audio bandwidth
  537. of WB or less,</t>
  538. <t>A Hybrid (SILK+CELT) mode for SWB or FB speech at medium bitrates, and</t>
  539. <t>A CELT-only mode for very low delay speech transmission as well as music
  540. transmission (NB to FB).</t>
  541. </list>
  542. The 32 possible configurations each identify which one of these operating modes
  543. the packet uses, as well as the audio bandwidth and the frame size.
  544. <xref target="config_bits"/> lists the parameters for each configuration.
  545. </t>
  546. <texttable anchor="config_bits" title="TOC Byte Configuration Parameters">
  547. <ttcol>Configuration Number(s)</ttcol>
  548. <ttcol>Mode</ttcol>
  549. <ttcol>Bandwidth</ttcol>
  550. <ttcol>Frame Sizes</ttcol>
  551. <c>0...3</c> <c>SILK-only</c> <c>NB</c> <c>10, 20, 40, 60&nbsp;ms</c>
  552. <c>4...7</c> <c>SILK-only</c> <c>MB</c> <c>10, 20, 40, 60&nbsp;ms</c>
  553. <c>8...11</c> <c>SILK-only</c> <c>WB</c> <c>10, 20, 40, 60&nbsp;ms</c>
  554. <c>12...13</c> <c>Hybrid</c> <c>SWB</c> <c>10, 20&nbsp;ms</c>
  555. <c>14...15</c> <c>Hybrid</c> <c>FB</c> <c>10, 20&nbsp;ms</c>
  556. <c>16...19</c> <c>CELT-only</c> <c>NB</c> <c>2.5, 5, 10, 20&nbsp;ms</c>
  557. <c>20...23</c> <c>CELT-only</c> <c>WB</c> <c>2.5, 5, 10, 20&nbsp;ms</c>
  558. <c>24...27</c> <c>CELT-only</c> <c>SWB</c> <c>2.5, 5, 10, 20&nbsp;ms</c>
  559. <c>28...31</c> <c>CELT-only</c> <c>FB</c> <c>2.5, 5, 10, 20&nbsp;ms</c>
  560. </texttable>
  561. <t>
  562. The configuration numbers in each range (e.g., 0...3 for NB SILK-only)
  563. correspond to the various choices of frame size, in the same order.
  564. For example, configuration 0 has a 10&nbsp;ms frame size and configuration 3
  565. has a 60&nbsp;ms frame size.
  566. </t>
  567. <t>
  568. One additional bit, labeled "s", signals mono vs. stereo, with 0 indicating
  569. mono and 1 indicating stereo.
  570. </t>
  571. <t>
  572. The remaining two bits of the TOC byte, labeled "c", code the number of frames
  573. per packet (codes 0 to 3) as follows:
  574. <list style="symbols">
  575. <t>0: 1 frame in the packet</t>
  576. <t>1: 2 frames in the packet, each with equal compressed size</t>
  577. <t>2: 2 frames in the packet, with different compressed sizes</t>
  578. <t>3: an arbitrary number of frames in the packet</t>
  579. </list>
  580. This draft refers to a packet as a code 0 packet, code 1 packet, etc., based on
  581. the value of "c".
  582. </t>
  583. </section>
  584. <section title="Frame Packing">
  585. <t>
  586. This section describes how frames are packed according to each possible value
  587. of "c" in the TOC byte.
  588. </t>
  589. <section anchor="frame-length-coding" title="Frame Length Coding">
  590. <t>
  591. When a packet contains multiple VBR frames (i.e., code 2 or 3), the compressed
  592. length of one or more of these frames is indicated with a one- or two-byte
  593. sequence, with the meaning of the first byte as follows:
  594. <list style="symbols">
  595. <t>0: No frame (discontinuous transmission (DTX) or lost packet)</t>
  596. <t>1...251: Length of the frame in bytes</t>
  597. <t>252...255: A second byte is needed. The total length is (second_byte*4)+first_byte</t>
  598. </list>
  599. </t>
  600. <t>
  601. The special length 0 indicates that no frame is available, either because it
  602. was dropped during transmission by some intermediary or because the encoder
  603. chose not to transmit it.
  604. Any Opus frame in any mode MAY have a length of 0.
  605. </t>
  606. <t>
  607. The maximum representable length is 255*4+255=1275&nbsp;bytes.
  608. For 20&nbsp;ms frames, this represents a bitrate of 510&nbsp;kb/s, which is
  609. approximately the highest useful rate for lossily compressed fullband stereo
  610. music.
  611. Beyond this point, lossless codecs are more appropriate.
  612. It is also roughly the maximum useful rate of the MDCT layer, as shortly
  613. thereafter quality no longer improves with additional bits due to limitations
  614. on the codebook sizes.
  615. </t>
  616. <t anchor="R2">
  617. No length is transmitted for the last frame in a VBR packet, or for any of the
  618. frames in a CBR packet, as it can be inferred from the total size of the
  619. packet and the size of all other data in the packet.
  620. However, the length of any individual frame MUST NOT exceed
  621. 1275&nbsp;bytes&nbsp;[R2], to allow for repacketization by gateways,
  622. conference bridges, or other software.
  623. </t>
  624. </section>
  625. <section title="Code 0: One Frame in the Packet">
  626. <t>
  627. For code&nbsp;0 packets, the TOC byte is immediately followed by N-1&nbsp;bytes
  628. of compressed data for a single frame (where N is the size of the packet),
  629. as illustrated in <xref target="code0_packet"/>.
  630. </t>
  631. <figure anchor="code0_packet" title="A Code 0 Packet" align="center">
  632. <artwork align="center"><![CDATA[
  633. 0 1 2 3
  634. 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
  635. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  636. | config |s|0|0| |
  637. +-+-+-+-+-+-+-+-+ |
  638. | Compressed frame 1 (N-1 bytes)... :
  639. : |
  640. | |
  641. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  642. ]]></artwork>
  643. </figure>
  644. </section>
  645. <section title="Code 1: Two Frames in the Packet, Each with Equal Compressed Size">
  646. <t anchor="R3">
  647. For code 1 packets, the TOC byte is immediately followed by the
  648. (N-1)/2&nbsp;bytes of compressed data for the first frame, followed by
  649. (N-1)/2&nbsp;bytes of compressed data for the second frame, as illustrated in
  650. <xref target="code1_packet"/>.
  651. The number of payload bytes available for compressed data, N-1, MUST be even
  652. for all code 1 packets&nbsp;[R3].
  653. </t>
  654. <figure anchor="code1_packet" title="A Code 1 Packet" align="center">
  655. <artwork align="center"><![CDATA[
  656. 0 1 2 3
  657. 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
  658. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  659. | config |s|0|1| |
  660. +-+-+-+-+-+-+-+-+ :
  661. | Compressed frame 1 ((N-1)/2 bytes)... |
  662. : +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  663. | | |
  664. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ :
  665. | Compressed frame 2 ((N-1)/2 bytes)... |
  666. : +-+-+-+-+-+-+-+-+
  667. | |
  668. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  669. ]]></artwork>
  670. </figure>
  671. </section>
  672. <section title="Code 2: Two Frames in the Packet, with Different Compressed Sizes">
  673. <t anchor="R4">
  674. For code 2 packets, the TOC byte is followed by a one- or two-byte sequence
  675. indicating the length of the first frame (marked N1 in <xref target='code2_packet'/>),
  676. followed by N1 bytes of compressed data for the first frame.
  677. The remaining N-N1-2 or N-N1-3&nbsp;bytes are the compressed data for the
  678. second frame.
  679. This is illustrated in <xref target="code2_packet"/>.
  680. A code 2 packet MUST contain enough bytes to represent a valid length.
  681. For example, a 1-byte code 2 packet is always invalid, and a 2-byte code 2
  682. packet whose second byte is in the range 252...255 is also invalid.
  683. The length of the first frame, N1, MUST also be no larger than the size of the
  684. payload remaining after decoding that length for all code 2 packets&nbsp;[R4].
  685. This makes, for example, a 2-byte code 2 packet with a second byte in the range
  686. 1...251 invalid as well (the only valid 2-byte code 2 packet is one where the
  687. length of both frames is zero).
  688. </t>
  689. <figure anchor="code2_packet" title="A Code 2 Packet" align="center">
  690. <artwork align="center"><![CDATA[
  691. 0 1 2 3
  692. 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
  693. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  694. | config |s|1|0| N1 (1-2 bytes): |
  695. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ :
  696. | Compressed frame 1 (N1 bytes)... |
  697. : +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  698. | | |
  699. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
  700. | Compressed frame 2... :
  701. : |
  702. | |
  703. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  704. ]]></artwork>
  705. </figure>
  706. </section>
  707. <section title="Code 3: A Signaled Number of Frames in the Packet">
  708. <t anchor="R5">
  709. Code 3 packets signal the number of frames, as well as additional
  710. padding, called "Opus padding" to indicate that this padding is added at the
  711. Opus layer, rather than at the transport layer.
  712. Code 3 packets MUST have at least 2 bytes&nbsp;[R6,R7].
  713. The TOC byte is followed by a byte encoding the number of frames in the packet
  714. in bits 2 to 7 (marked "M" in <xref target='frame_count_byte'/>), with bit 1 indicating whether
  715. or not Opus padding is inserted (marked "p" in <xref target='frame_count_byte'/>), and bit 0
  716. indicating VBR (marked "v" in <xref target='frame_count_byte'/>).
  717. M MUST NOT be zero, and the audio duration contained within a packet MUST NOT
  718. exceed 120&nbsp;ms&nbsp;[R5].
  719. This limits the maximum frame count for any frame size to 48 (for 2.5&nbsp;ms
  720. frames), with lower limits for longer frame sizes.
  721. <xref target="frame_count_byte"/> illustrates the layout of the frame count
  722. byte.
  723. </t>
  724. <figure anchor="frame_count_byte" title="The frame count byte">
  725. <artwork align="center"><![CDATA[
  726. 0
  727. 0 1 2 3 4 5 6 7
  728. +-+-+-+-+-+-+-+-+
  729. |v|p| M |
  730. +-+-+-+-+-+-+-+-+
  731. ]]></artwork>
  732. </figure>
  733. <t>
  734. When Opus padding is used, the number of bytes of padding is encoded in the
  735. bytes following the frame count byte.
  736. Values from 0...254 indicate that 0...254&nbsp;bytes of padding are included,
  737. in addition to the byte(s) used to indicate the size of the padding.
  738. If the value is 255, then the size of the additional padding is 254&nbsp;bytes,
  739. plus the padding value encoded in the next byte.
  740. There MUST be at least one more byte in the packet in this case&nbsp;[R6,R7].
  741. The additional padding bytes appear at the end of the packet, and MUST be set
  742. to zero by the encoder to avoid creating a covert channel.
  743. The decoder MUST accept any value for the padding bytes, however.
  744. </t>
  745. <t>
  746. Although this encoding provides multiple ways to indicate a given number of
  747. padding bytes, each uses a different number of bytes to indicate the padding
  748. size, and thus will increase the total packet size by a different amount.
  749. For example, to add 255 bytes to a packet, set the padding bit, p, to 1, insert
  750. a single byte after the frame count byte with a value of 254, and append 254
  751. padding bytes with the value zero to the end of the packet.
  752. To add 256 bytes to a packet, set the padding bit to 1, insert two bytes after
  753. the frame count byte with the values 255 and 0, respectively, and append 254
  754. padding bytes with the value zero to the end of the packet.
  755. By using the value 255 multiple times, it is possible to create a packet of any
  756. specific, desired size.
  757. Let P be the number of header bytes used to indicate the padding size plus the
  758. number of padding bytes themselves (i.e., P is the total number of bytes added
  759. to the packet).
  760. Then P MUST be no more than N-2&nbsp;[R6,R7].
  761. </t>
  762. <t anchor="R6">
  763. In the CBR case, let R=N-2-P be the number of bytes remaining in the packet
  764. after subtracting the (optional) padding.
  765. Then the compressed length of each frame in bytes is equal to R/M.
  766. The value R MUST be a non-negative integer multiple of M&nbsp;[R6].
  767. The compressed data for all M frames follows, each of size
  768. R/M&nbsp;bytes, as illustrated in <xref target="code3cbr_packet"/>.
  769. </t>
  770. <figure anchor="code3cbr_packet" title="A CBR Code 3 Packet" align="center">
  771. <artwork align="center"><![CDATA[
  772. 0 1 2 3
  773. 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
  774. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  775. | config |s|1|1|0|p| M | Padding length (Optional) :
  776. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  777. | |
  778. : Compressed frame 1 (R/M bytes)... :
  779. | |
  780. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  781. | |
  782. : Compressed frame 2 (R/M bytes)... :
  783. | |
  784. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  785. | |
  786. : ... :
  787. | |
  788. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  789. | |
  790. : Compressed frame M (R/M bytes)... :
  791. | |
  792. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  793. : Opus Padding (Optional)... |
  794. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  795. ]]></artwork>
  796. </figure>
  797. <t anchor="R7">
  798. In the VBR case, the (optional) padding length is followed by M-1 frame
  799. lengths (indicated by "N1" to "N[M-1]" in <xref target='code3vbr_packet'/>), each encoded in a
  800. one- or two-byte sequence as described above.
  801. The packet MUST contain enough data for the M-1 lengths after removing the
  802. (optional) padding, and the sum of these lengths MUST be no larger than the
  803. number of bytes remaining in the packet after decoding them&nbsp;[R7].
  804. The compressed data for all M frames follows, each frame consisting of the
  805. indicated number of bytes, with the final frame consuming any remaining bytes
  806. before the final padding, as illustrated in <xref target="code3cbr_packet"/>.
  807. The number of header bytes (TOC byte, frame count byte, padding length bytes,
  808. and frame length bytes), plus the signaled length of the first M-1 frames themselves,
  809. plus the signaled length of the padding MUST be no larger than N, the total size of the
  810. packet.
  811. </t>
  812. <figure anchor="code3vbr_packet" title="A VBR Code 3 Packet" align="center">
  813. <artwork align="center"><![CDATA[
  814. 0 1 2 3
  815. 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
  816. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  817. | config |s|1|1|1|p| M | Padding length (Optional) :
  818. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  819. : N1 (1-2 bytes): N2 (1-2 bytes): ... : N[M-1] |
  820. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  821. | |
  822. : Compressed frame 1 (N1 bytes)... :
  823. | |
  824. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  825. | |
  826. : Compressed frame 2 (N2 bytes)... :
  827. | |
  828. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  829. | |
  830. : ... :
  831. | |
  832. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  833. | |
  834. : Compressed frame M... :
  835. | |
  836. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  837. : Opus Padding (Optional)... |
  838. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  839. ]]></artwork>
  840. </figure>
  841. </section>
  842. </section>
  843. <section anchor="examples" title="Examples">
  844. <t>
  845. Simplest case, one NB mono 20&nbsp;ms SILK frame:
  846. </t>
  847. <figure anchor='framing_example_1'>
  848. <artwork><![CDATA[
  849. 0 1 2 3
  850. 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
  851. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  852. | 1 |0|0|0| compressed data... :
  853. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  854. ]]></artwork>
  855. </figure>
  856. <t>
  857. Two FB mono 5&nbsp;ms CELT frames of the same compressed size:
  858. </t>
  859. <figure anchor='framing_example_2'>
  860. <artwork><![CDATA[
  861. 0 1 2 3
  862. 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
  863. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  864. | 29 |0|0|1| compressed data... :
  865. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  866. ]]></artwork>
  867. </figure>
  868. <t>
  869. Two FB mono 20&nbsp;ms Hybrid frames of different compressed size:
  870. </t>
  871. <figure anchor='framing_example_3'>
  872. <artwork><![CDATA[
  873. 0 1 2 3
  874. 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
  875. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  876. | 15 |0|1|1|1|0| 2 | N1 | |
  877. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
  878. | compressed data... :
  879. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  880. ]]></artwork>
  881. </figure>
  882. <t>
  883. Four FB stereo 20&nbsp;ms CELT frames of the same compressed size:
  884. </t>
  885. <figure anchor='framing_example_4'>
  886. <artwork><![CDATA[
  887. 0 1 2 3
  888. 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
  889. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  890. | 31 |1|1|1|0|0| 4 | compressed data... :
  891. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  892. ]]></artwork>
  893. </figure>
  894. </section>
  895. <section anchor="malformed-packets" title="Receiving Malformed Packets">
  896. <t>
  897. A receiver MUST NOT process packets which violate any of the rules above as
  898. normal Opus packets.
  899. They are reserved for future applications, such as in-band headers (containing
  900. metadata, etc.).
  901. Packets which violate these constraints may cause implementations of
  902. <spanx style="emph">this</spanx> specification to treat them as malformed, and
  903. discard them.
  904. </t>
  905. <t>
  906. These constraints are summarized here for reference:
  907. <list style="format [R%d]">
  908. <t>Packets are at least one byte.</t>
  909. <t>No implicit frame length is larger than 1275 bytes.</t>
  910. <t>Code 1 packets have an odd total length, N, so that (N-1)/2 is an
  911. integer.</t>
  912. <t>Code 2 packets have enough bytes after the TOC for a valid frame
  913. length, and that length is no larger than the number of bytes remaining in the
  914. packet.</t>
  915. <t>Code 3 packets contain at least one frame, but no more than 120&nbsp;ms
  916. of audio total.</t>
  917. <t>The length of a CBR code 3 packet, N, is at least two bytes, the number of
  918. bytes added to indicate the padding size plus the trailing padding bytes
  919. themselves, P, is no more than N-2, and the frame count, M, satisfies
  920. the constraint that (N-2-P) is a non-negative integer multiple of M.</t>
  921. <t>VBR code 3 packets are large enough to contain all the header bytes (TOC
  922. byte, frame count byte, any padding length bytes, and any frame length bytes),
  923. plus the length of the first M-1 frames, plus any trailing padding bytes.</t>
  924. </list>
  925. </t>
  926. </section>
  927. </section>
  928. <section title="Opus Decoder">
  929. <t>
  930. The Opus decoder consists of two main blocks: the SILK decoder and the CELT
  931. decoder.
  932. At any given time, one or both of the SILK and CELT decoders may be active.
  933. The output of the Opus decode is the sum of the outputs from the SILK and CELT
  934. decoders with proper sample rate conversion and delay compensation on the SILK
  935. side, and optional decimation (when decoding to sample rates less than
  936. 48&nbsp;kHz) on the CELT side, as illustrated in the block diagram below.
  937. </t>
  938. <figure>
  939. <artwork>
  940. <![CDATA[
  941. +---------+ +------------+
  942. | SILK | | Sample |
  943. +->| Decoder |--->| Rate |----+
  944. Bit- +---------+ | | | | Conversion | v
  945. stream | Range |---+ +---------+ +------------+ /---\ Audio
  946. ------->| Decoder | | + |------>
  947. | |---+ +---------+ +------------+ \---/
  948. +---------+ | | CELT | | Decimation | ^
  949. +->| Decoder |--->| (Optional) |----+
  950. | | | |
  951. +---------+ +------------+
  952. ]]>
  953. </artwork>
  954. </figure>
  955. <section anchor="range-decoder" title="Range Decoder">
  956. <t>
  957. Opus uses an entropy coder based on range coding <xref target="range-coding"></xref>
  958. <xref target="Martin79"></xref>,
  959. which is itself a rediscovery of the FIFO arithmetic code introduced by <xref target="coding-thesis"></xref>.
  960. It is very similar to arithmetic encoding, except that encoding is done with
  961. digits in any base instead of with bits,
  962. so it is faster when using larger bases (i.e., a byte). All of the
  963. calculations in the range coder must use bit-exact integer arithmetic.
  964. </t>
  965. <t>
  966. Symbols may also be coded as "raw bits" packed directly into the bitstream,
  967. bypassing the range coder.
  968. These are packed backwards starting at the end of the frame, as illustrated in
  969. <xref target="rawbits-example"/>.
  970. This reduces complexity and makes the stream more resilient to bit errors, as
  971. corruption in the raw bits will not desynchronize the decoding process, unlike
  972. corruption in the input to the range decoder.
  973. Raw bits are only used in the CELT layer.
  974. </t>
  975. <figure anchor="rawbits-example" title="Illustrative example of packing range
  976. coder and raw bits data">
  977. <artwork align="center"><![CDATA[
  978. 0 1 2 3
  979. 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
  980. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  981. | Range coder data (packed MSB to LSB) -> :
  982. + +
  983. : :
  984. + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  985. : | <- Boundary occurs at an arbitrary bit position :
  986. +-+-+-+ +
  987. : <- Raw bits data (packed LSB to MSB) |
  988. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  989. ]]></artwork>
  990. </figure>
  991. <t>
  992. Each symbol coded by the range coder is drawn from a finite alphabet and coded
  993. in a separate "context", which describes the size of the alphabet and the
  994. relative frequency of each symbol in that alphabet.
  995. </t>
  996. <t>
  997. Suppose there is a context with n symbols, identified with an index that ranges
  998. from 0 to n-1.
  999. The parameters needed to encode or decode symbol k in this context are
  1000. represented by a three-tuple (fl[k],&nbsp;fh[k],&nbsp;ft), with
  1001. 0&nbsp;&lt;=&nbsp;fl[k]&nbsp;&lt;&nbsp;fh[k]&nbsp;&lt;=&nbsp;ft&nbsp;&lt;=&nbsp;65535.
  1002. The values of this tuple are derived from the probability model for the
  1003. symbol, represented by traditional "frequency counts".
  1004. Because Opus uses static contexts these are not updated as symbols are decoded.
  1005. Let f[i] be the frequency of symbol i.
  1006. Then the three-tuple corresponding to symbol k is given by
  1007. </t>
  1008. <figure align="center">
  1009. <artwork align="center"><![CDATA[
  1010. k-1 n-1
  1011. __ __
  1012. fl[k] = \ f[i], fh[k] = fl[k] + f[k], ft = \ f[i]
  1013. /_ /_
  1014. i=0 i=0
  1015. ]]></artwork>
  1016. </figure>
  1017. <t>
  1018. The range decoder extracts the symbols and integers encoded using the range
  1019. encoder in <xref target="range-encoder"/>.
  1020. The range decoder maintains an internal state vector composed of the two-tuple
  1021. (val,&nbsp;rng), representing the difference between the high end of the
  1022. current range and the actual coded value, minus one, and the size of the
  1023. current range, respectively.
  1024. Both val and rng are 32-bit unsigned integer values.
  1025. </t>
  1026. <section anchor="range-decoder-init" title="Range Decoder Initialization">
  1027. <t>
  1028. Let b0 be the first input byte (or zero if there are no bytes in this Opus
  1029. frame).
  1030. The decoder initializes rng to 128 and initializes val to
  1031. (127&nbsp;-&nbsp;(b0&gt;&gt;1)), where (b0&gt;&gt;1) is the top 7 bits of the
  1032. first input byte.
  1033. It saves the remaining bit, (b0&amp;1), for use in the renormalization
  1034. procedure described in <xref target="range-decoder-renorm"/>, which the
  1035. decoder invokes immediately after initialization to read additional bits and
  1036. establish the invariant that rng&nbsp;&gt;&nbsp;2**23.
  1037. </t>
  1038. </section>
  1039. <section anchor="decoding-symbols" title="Decoding Symbols">
  1040. <t>
  1041. Decoding a symbol is a two-step process.
  1042. The first step determines a 16-bit unsigned value fs, which lies within the
  1043. range of some symbol in the current context.
  1044. The second step updates the range decoder state with the three-tuple
  1045. (fl[k],&nbsp;fh[k],&nbsp;ft) corresponding to that symbol.
  1046. </t>
  1047. <t>
  1048. The first step is implemented by ec_decode() (entdec.c), which computes
  1049. <figure align="center">
  1050. <artwork align="center"><![CDATA[
  1051. val
  1052. fs = ft - min(------ + 1, ft) .
  1053. rng/ft
  1054. ]]></artwork>
  1055. </figure>
  1056. The divisions here are integer division.
  1057. </t>
  1058. <t>
  1059. The decoder then identifies the symbol in the current context corresponding to
  1060. fs; i.e., the value of k whose three-tuple (fl[k],&nbsp;fh[k],&nbsp;ft)
  1061. satisfies fl[k]&nbsp;&lt;=&nbsp;fs&nbsp;&lt;&nbsp;fh[k].
  1062. It uses this tuple to update val according to
  1063. <figure align="center">
  1064. <artwork align="center"><![CDATA[
  1065. rng
  1066. val = val - --- * (ft - fh[k]) .
  1067. ft
  1068. ]]></artwork>
  1069. </figure>
  1070. If fl[k] is greater than zero, then the decoder updates rng using
  1071. <figure align="center">
  1072. <artwork align="center"><![CDATA[
  1073. rng
  1074. rng = --- * (fh[k] - fl[k]) .
  1075. ft
  1076. ]]></artwork>
  1077. </figure>
  1078. Otherwise, it updates rng using
  1079. <figure align="center">
  1080. <artwork align="center"><![CDATA[
  1081. rng
  1082. rng = rng - --- * (ft - fh[k]) .
  1083. ft
  1084. ]]></artwork>
  1085. </figure>
  1086. </t>
  1087. <t>
  1088. Using a special case for the first symbol (rather than the last symbol, as is
  1089. commonly done in other arithmetic coders) ensures that all the truncation
  1090. error from the finite precision arithmetic accumulates in symbol 0.
  1091. This makes the cost of coding a 0 slightly smaller, on average, than its
  1092. estimated probability indicates and makes the cost of coding any other symbol
  1093. slightly larger.
  1094. When contexts are designed so that 0 is the most probable symbol, which is
  1095. often the case, this strategy minimizes the inefficiency introduced by the
  1096. finite precision.
  1097. It also makes some of the special-case decoding routines in
  1098. <xref target="decoding-alternate"/> particularly simple.
  1099. </t>
  1100. <t>
  1101. After the updates, implemented by ec_dec_update() (entdec.c), the decoder
  1102. normalizes the range using the procedure in the next section, and returns the
  1103. index k.
  1104. </t>
  1105. <section anchor="range-decoder-renorm" title="Renormalization">
  1106. <t>
  1107. To normalize the range, the decoder repeats the following process, implemented
  1108. by ec_dec_normalize() (entdec.c), until rng&nbsp;&gt;&nbsp;2**23.
  1109. If rng is already greater than 2**23, the entire process is skipped.
  1110. First, it sets rng to (rng&lt;&lt;8).
  1111. Then it reads the next byte of the Opus frame and forms an 8-bit value sym,
  1112. using the left-over bit buffered from the previous byte as the high bit
  1113. and the top 7 bits of the byte just read as the other 7 bits of sym.
  1114. The remaining bit in the byte just read is buffered for use in the next
  1115. iteration.
  1116. If no more input bytes remain, it uses zero bits instead.
  1117. See <xref target="range-decoder-init"/> for the initialization used to process
  1118. the first byte.
  1119. Then, it sets
  1120. <figure align="center">
  1121. <artwork align="center"><![CDATA[
  1122. val = ((val<<8) + (255-sym)) & 0x7FFFFFFF .
  1123. ]]></artwork>
  1124. </figure>
  1125. </t>
  1126. <t>
  1127. It is normal and expected that the range decoder will read several bytes
  1128. into the raw bits data (if any) at the end of the packet by the time the frame
  1129. is completely decoded, as illustrated in <xref target="finalize-example"/>.
  1130. This same data MUST also be returned as raw bits when requested.
  1131. The encoder is expected to terminate the stream in such a way that the decoder
  1132. will decode the intended values regardless of the data contained in the raw
  1133. bits.
  1134. <xref target="encoder-finalizing"/> describes a procedure for doing this.
  1135. If the range decoder consumes all of the bytes belonging to the current frame,
  1136. it MUST continue to use zero when any further input bytes are required, even
  1137. if there is additional data in the current packet from padding or other
  1138. frames.
  1139. </t>
  1140. <figure anchor="finalize-example" title="Illustrative example of raw bits
  1141. overlapping range coder data">
  1142. <artwork align="center"><![CDATA[
  1143. n n+1 n+2 n+3
  1144. 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
  1145. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1146. : | <----------- Overlap region ------------> | :
  1147. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  1148. ^ ^
  1149. | End of data buffered by the range coder |
  1150. ...-----------------------------------------------+
  1151. |
  1152. | End of data consumed by raw bits
  1153. +-------------------------------------------------------...
  1154. ]]></artwork>
  1155. </figure>
  1156. </section>
  1157. </section>
  1158. <section anchor="decoding-alternate" title="Alternate Decoding Methods">
  1159. <t>
  1160. The reference implementation uses three additional decoding methods that are
  1161. exactly equivalent to the above, but make assumptions and simplifications that
  1162. allow for a more efficient implementation.
  1163. </t>
  1164. <section anchor="ec_decode_bin" title="ec_decode_bin()">
  1165. <t>
  1166. The first is ec_decode_bin() (entdec.c), defined using the parameter ftb
  1167. instead of ft.
  1168. It is mathematically equivalent to calling ec_decode() with
  1169. ft&nbsp;=&nbsp;(1&lt;&lt;ftb), but avoids one of the divisions.
  1170. </t>
  1171. </section>
  1172. <section anchor="ec_dec_bit_logp" title="ec_dec_bit_logp()">
  1173. <t>
  1174. The next is ec_dec_bit_logp() (entdec.c), which decodes a single binary symbol,
  1175. replacing both the ec_decode() and ec_dec_update() steps.
  1176. The context is described by a single parameter, logp, which is the absolute
  1177. value of the base-2 logarithm of the probability of a "1".
  1178. It is mathematically equivalent to calling ec_decode() with
  1179. ft&nbsp;=&nbsp;(1&lt;&lt;logp), followed by ec_dec_update() with
  1180. the 3-tuple (fl[k]&nbsp;=&nbsp;0,
  1181. fh[k]&nbsp;=&nbsp;(1&lt;&lt;logp)&nbsp;-&nbsp;1,
  1182. ft&nbsp;=&nbsp;(1&lt;&lt;logp)) if the returned value
  1183. of fs is less than (1&lt;&lt;logp)&nbsp;-&nbsp;1 (a "0" was decoded), and with
  1184. (fl[k]&nbsp;=&nbsp;(1&lt;&lt;logp)&nbsp;-&nbsp;1,
  1185. fh[k]&nbsp;=&nbsp;ft&nbsp;=&nbsp;(1&lt;&lt;logp)) otherwise (a "1" was
  1186. decoded).
  1187. The implementation requires no multiplications or divisions.
  1188. </t>
  1189. </section>
  1190. <section anchor="ec_dec_icdf" title="ec_dec_icdf()">
  1191. <t>
  1192. The last is ec_dec_icdf() (entdec.c), which decodes a single symbol with a
  1193. table-based context of up to 8 bits, also replacing both the ec_decode() and
  1194. ec_dec_update() steps, as well as the search for the decoded symbol in between.
  1195. The context is described by two parameters, an icdf
  1196. ("inverse" cumulative distribution function) table and ftb.
  1197. As with ec_decode_bin(), (1&lt;&lt;ftb) is equivalent to ft.
  1198. idcf[k], on the other hand, stores (1&lt;&lt;ftb)-fh[k], which is equal to
  1199. (1&lt;&lt;ftb)&nbsp;-&nbsp;fl[k+1].
  1200. fl[0] is assumed to be 0, and the table is terminated by a value of 0 (where
  1201. fh[k]&nbsp;==&nbsp;ft).
  1202. </t>
  1203. <t>
  1204. The function is mathematically equivalent to calling ec_decode() with
  1205. ft&nbsp;=&nbsp;(1&lt;&lt;ftb), using the returned value fs to search the table
  1206. for the first entry where fs&nbsp;&lt;&nbsp;(1&lt;&lt;ftb)-icdf[k], and
  1207. calling ec_dec_update() with
  1208. fl[k]&nbsp;=&nbsp;(1&lt;&lt;ftb)&nbsp;-&nbsp;icdf[k-1] (or 0
  1209. if k&nbsp;==&nbsp;0), fh[k]&nbsp;=&nbsp;(1&lt;&lt;ftb)&nbsp;-&nbsp;idcf[k],
  1210. and ft&nbsp;=&nbsp;(1&lt;&lt;ftb).
  1211. Combining the search with the update allows the division to be replaced by a
  1212. series of multiplications (which are usually much cheaper), and using an
  1213. inverse CDF allows the use of an ftb as large as 8 in an 8-bit table without
  1214. any special cases.
  1215. This is the primary interface with the range decoder in the SILK layer, though
  1216. it is used in a few places in the CELT layer as well.
  1217. </t>
  1218. <t>
  1219. Although icdf[k] is more convenient for the code, the frequency counts, f[k],
  1220. are a more natural representation of the probability distribution function
  1221. (PDF) for a given symbol.
  1222. Therefore this draft lists the latter, not the former, when describing the
  1223. context in which a symbol is coded as a list, e.g., {4, 4, 4, 4}/16 for a
  1224. uniform context with four possible values and ft&nbsp;=&nbsp;16.
  1225. The value of ft after the slash is always the sum of the entries in the PDF,
  1226. but is included for convenience.
  1227. Contexts with identical probabilities, f[k]/ft, but different values of ft
  1228. (or equivalently, ftb) are not the same, and cannot, in general, be used in
  1229. place of one another.
  1230. An icdf table is also not capable of representing a PDF where the first symbol
  1231. has 0 probability.
  1232. In such contexts, ec_dec_icdf() can decode the symbol by using a table that
  1233. drops the entries for any initial zero-probability values and adding the
  1234. constant offset of the first value with a non-zero probability to its return
  1235. value.
  1236. </t>
  1237. </section>
  1238. </section>
  1239. <section anchor="decoding-bits" title="Decoding Raw Bits">
  1240. <t>
  1241. The raw bits used by the CELT layer are packed at the end of the packet, with
  1242. the least significant bit of the first value packed in the least significant
  1243. bit of the last byte, filling up to the most significant bit in the last byte,
  1244. continuing on to the least significant bit of the penultimate byte, and so on.
  1245. The reference implementation reads them using ec_dec_bits() (entdec.c).
  1246. Because the range decoder must read several bytes ahead in the stream, as
  1247. described in <xref target="range-decoder-renorm"/>, the input consumed by the
  1248. raw bits may overlap with the input consumed by the range coder, and a decoder
  1249. MUST allow this.
  1250. The format should render it impossible to attempt to read more raw bits than
  1251. there are actual bits in the frame, though a decoder may wish to check for
  1252. this and report an error.
  1253. </t>
  1254. </section>
  1255. <section anchor="ec_dec_uint" title="Decoding Uniformly Distributed Integers">
  1256. <t>
  1257. The function ec_dec_uint() (entdec.c) decodes one of ft equiprobable values in
  1258. the range 0 to (ft&nbsp;-&nbsp;1), inclusive, each with a frequency of 1,
  1259. where ft may be as large as (2**32&nbsp;-&nbsp;1).
  1260. Because ec_decode() is limited to a total frequency of (2**16&nbsp;-&nbsp;1),
  1261. it splits up the value into a range coded symbol representing up to 8 of the
  1262. high bits, and, if necessary, raw bits representing the remainder of the
  1263. value.
  1264. The limit of 8 bits in the range coded symbol is a trade-off between
  1265. implementation complexity, modeling error (since the symbols no longer truly
  1266. have equal coding cost), and rounding error introduced by the range coder
  1267. itself (which gets larger as more bits are included).
  1268. Using raw bits reduces the maximum number of divisions required in the worst
  1269. case, but means that it may be possible to decode a value outside the range
  1270. 0 to (ft&nbsp;-&nbsp;1), inclusive.
  1271. </t>
  1272. <t>
  1273. ec_dec_uint() takes a single, positive parameter, ft, which is not necessarily
  1274. a power of two, and returns an integer, t, whose value lies between 0 and
  1275. (ft&nbsp;-&nbsp;1), inclusive.
  1276. Let ftb&nbsp;=&nbsp;ilog(ft&nbsp;-&nbsp;1), i.e., the number of bits required
  1277. to store (ft&nbsp;-&nbsp;1) in two's complement notation.
  1278. If ftb is 8 or less, then t is decoded with t&nbsp;=&nbsp;ec_decode(ft), and
  1279. the range coder state is updated using the three-tuple (t, t&nbsp;+&nbsp;1,
  1280. ft).
  1281. </t>
  1282. <t>
  1283. If ftb is greater than 8, then the top 8 bits of t are decoded using
  1284. <figure align="center">
  1285. <artwork align="center"><![CDATA[
  1286. t = ec_decode(((ft - 1) >> (ftb - 8)) + 1) ,
  1287. ]]></artwork>
  1288. </figure>
  1289. the decoder state is updated using the three-tuple
  1290. (t, t&nbsp;+&nbsp;1,
  1291. ((ft&nbsp;-&nbsp;1)&nbsp;&gt;&gt;&nbsp;(ftb&nbsp;-&nbsp;8))&nbsp;+&nbsp;1),
  1292. and the remaining bits are decoded as raw bits, setting
  1293. <figure align="center">
  1294. <artwork align="center"><![CDATA[
  1295. t = (t << (ftb - 8)) | ec_dec_bits(ftb - 8) .
  1296. ]]></artwork>
  1297. </figure>
  1298. If, at this point, t >= ft, then the current frame is corrupt.
  1299. In that case, the decoder should assume there has been an error in the coding,
  1300. decoding, or transmission and SHOULD take measures to conceal the
  1301. error and/or report to the application that the error has occurred.
  1302. </t>
  1303. </section>
  1304. <section anchor="decoder-tell" title="Current Bit Usage">
  1305. <t>
  1306. The bit allocation routines in the CELT decoder need a conservative upper bound
  1307. on the number of bits that have been used from the current frame thus far,
  1308. including both range coder bits and raw bits.
  1309. This drives allocation decisions that must match those made in the encoder.
  1310. The upper bound is computed in the reference implementation to whole-bit
  1311. precision by the function ec_tell() (entcode.h) and to fractional 1/8th bit
  1312. precision by the function ec_tell_frac() (entcode.c).
  1313. Like all operations in the range coder, it must be implemented in a bit-exact
  1314. manner, and must produce exactly the same value returned by the same functions
  1315. in the encoder after encoding the same symbols.
  1316. </t>
  1317. <t>
  1318. ec_tell() is guaranteed to return ceil(ec_tell_frac()/8.0).
  1319. In various places the codec will check to ensure there is enough room to
  1320. contain a symbol before attempting to decode it.
  1321. In practice, although the number of bits used so far is an upper bound,
  1322. decoding a symbol whose probability model suggests it has a worst-case cost of
  1323. p 1/8th bits may actually advance the return value of ec_tell_frac() by
  1324. p-1, p, or p+1 1/8th bits, due to approximation error in that upper bound,
  1325. truncation error in the range coder, and for large values of ft, modeling
  1326. error in ec_dec_uint().
  1327. </t>
  1328. <t>
  1329. However, this error is bounded, and periodic calls to ec_tell() or
  1330. ec_tell_frac() at precisely defined points in the decoding process prevent it
  1331. from accumulating.
  1332. For a range coder symbol that requires a whole number of bits (i.e.,
  1333. for which ft/(fh[k]&nbsp;-&nbsp;fl[k]) is a power of two), where there are at
  1334. least p 1/8th bits available, decoding the symbol will never cause ec_tell() or
  1335. ec_tell_frac() to exceed the size of the frame ("bust the budget").
  1336. In this case the return value of ec_tell_frac() will only advance by more than
  1337. p 1/8th bits if there was an additional, fractional number of bits remaining,
  1338. and it will never advance beyond the next whole-bit boundary, which is safe,
  1339. since frames always contain a whole number of bits.
  1340. However, when p is not a whole number of bits, an extra 1/8th bit is required
  1341. to ensure that decoding the symbol will not bust the budget.
  1342. </t>
  1343. <t>
  1344. The reference implementation keeps track of the total number of whole bits that
  1345. have been processed by the decoder so far in the variable nbits_total,
  1346. including the (possibly fractional) number of bits that are currently
  1347. buffered, but not consumed, inside the range coder.
  1348. nbits_total is initialized to 9 just before the initial range renormalization
  1349. process completes (or equivalently, it can be initialized to 33 after the
  1350. first renormalization).
  1351. The extra two bits over the actual amount buffered by the range coder
  1352. guarantees that it is an upper bound and that there is enough room for the
  1353. encoder to terminate the stream.
  1354. Each iteration through the range coder's renormalization loop increases
  1355. nbits_total by 8.
  1356. Reading raw bits increases nbits_total by the number of raw bits read.
  1357. </t>
  1358. <section anchor="ec_tell" title="ec_tell()">
  1359. <t>
  1360. The whole number of bits buffered in rng may be estimated via lg = ilog(rng).
  1361. ec_tell() then becomes a simple matter of removing these bits from the total.
  1362. It returns (nbits_total - lg).
  1363. </t>
  1364. <t>
  1365. In a newly initialized decoder, before any symbols have been read, this reports
  1366. that 1 bit has been used.
  1367. This is the bit reserved for termination of the encoder.
  1368. </t>
  1369. </section>
  1370. <section anchor="ec_tell_frac" title="ec_tell_frac()">
  1371. <t>
  1372. ec_tell_frac() estimates the number of bits buffered in rng to fractional
  1373. precision.
  1374. Since rng must be greater than 2**23 after renormalization, lg must be at least
  1375. 24.
  1376. Let
  1377. <figure align="center">
  1378. <artwork align="center">
  1379. <![CDATA[
  1380. r_Q15 = rng >> (lg-16) ,
  1381. ]]></artwork>
  1382. </figure>
  1383. so that 32768 &lt;= r_Q15 &lt; 65536, an unsigned Q15 value representing the
  1384. fractional part of rng.
  1385. Then the following procedure can be used to add one bit of precision to lg.
  1386. First, update
  1387. <figure align="center">
  1388. <artwork align="center">
  1389. <![CDATA[
  1390. r_Q15 = (r_Q15*r_Q15) >> 15 .
  1391. ]]></artwork>
  1392. </figure>
  1393. Then add the 16th bit of r_Q15 to lg via
  1394. <figure align="center">
  1395. <artwork align="center">
  1396. <![CDATA[
  1397. lg = 2*lg + (r_Q15 >> 16) .
  1398. ]]></artwork>
  1399. </figure>
  1400. Finally, if this bit was a 1, reduce r_Q15 by a factor of two via
  1401. <figure align="center">
  1402. <artwork align="center">
  1403. <![CDATA[
  1404. r_Q15 = r_Q15 >> 1 ,
  1405. ]]></artwork>
  1406. </figure>
  1407. so that it once again lies in the range 32768 &lt;= r_Q15 &lt; 65536.
  1408. </t>
  1409. <t>
  1410. This procedure is repeated three times to extend lg to 1/8th bit precision.
  1411. ec_tell_frac() then returns (nbits_total*8 - lg).
  1412. </t>
  1413. </section>
  1414. </section>
  1415. </section>
  1416. <section anchor="silk_decoder_outline" title="SILK Decoder">
  1417. <t>
  1418. The decoder's LP layer uses a modified version of the SILK codec (herein simply
  1419. called "SILK"), which runs a decoded excitation signal through adaptive
  1420. long-term and short-term prediction synthesis filters.
  1421. It runs at NB, MB, and WB sample rates internally.
  1422. When used in a SWB or FB Hybrid frame, the LP layer itself still only runs in
  1423. WB.
  1424. </t>
  1425. <section title="SILK Decoder Modules">
  1426. <t>
  1427. An overview of the decoder is given in <xref target="silk_decoder_figure"/>.
  1428. </t>
  1429. <figure align="center" anchor="silk_decoder_figure" title="SILK Decoder">
  1430. <artwork align="center">
  1431. <![CDATA[
  1432. +---------+ +------------+
  1433. -->| Range |--->| Decode |---------------------------+
  1434. 1 | Decoder | 2 | Parameters |----------+ 5 |
  1435. +---------+ +------------+ 4 | |
  1436. 3 | | |
  1437. \/ \/ \/
  1438. +------------+ +------------+ +------------+
  1439. | Generate |-->| LTP |-->| LPC |
  1440. | Excitation | | Synthesis | | Synthesis |
  1441. +------------+ +------------+ +------------+
  1442. ^ |
  1443. | |
  1444. +-------------------+----------------+
  1445. | 6
  1446. | +------------+ +-------------+
  1447. +-->| Stereo |-->| Sample Rate |-->
  1448. | Unmixing | 7 | Conversion | 8
  1449. +------------+ +-------------+
  1450. 1: Range encoded bitstream
  1451. 2: Coded parameters
  1452. 3: Pulses, LSBs, and signs
  1453. 4: Pitch lags, Long-Term Prediction (LTP) coefficients
  1454. 5: Linear Predictive Coding (LPC) coefficients and gains
  1455. 6: Decoded signal (mono or mid-side stereo)
  1456. 7: Unmixed signal (mono or left-right stereo)
  1457. 8: Resampled signal
  1458. ]]>
  1459. </artwork>
  1460. </figure>
  1461. <t>
  1462. The decoder feeds the bitstream (1) to the range decoder from
  1463. <xref target="range-decoder"/>, and then decodes the parameters in it (2)
  1464. using the procedures detailed in
  1465. Sections&nbsp;<xref format="counter" target="silk_header_bits"/>
  1466. through&nbsp;<xref format="counter" target="silk_signs"/>.
  1467. These parameters (3, 4, 5) are used to generate an excitation signal (see
  1468. <xref target="silk_excitation_reconstruction"/>), which is fed to an optional
  1469. long-term prediction (LTP) filter (voiced frames only, see
  1470. <xref target="silk_ltp_synthesis"/>) and then a short-term prediction filter
  1471. (see <xref target="silk_lpc_synthesis"/>), producing the decoded signal (6).
  1472. For stereo streams, the mid-side representation is converted to separate left
  1473. and right channels (7).
  1474. The result is finally resampled to the desired output sample rate (e.g.,
  1475. 48&nbsp;kHz) so that the resampled signal (8) can be mixed with the CELT
  1476. layer.
  1477. </t>
  1478. </section>
  1479. <section anchor="silk_layer_organization" title="LP Layer Organization">
  1480. <t>
  1481. Internally, the LP layer of a single Opus frame is composed of either a single
  1482. 10&nbsp;ms regular SILK frame or between one and three 20&nbsp;ms regular SILK
  1483. frames.
  1484. A stereo Opus frame may double the number of regular SILK frames (up to a total
  1485. of six), since it includes separate frames for a mid channel and, optionally,
  1486. a side channel.
  1487. Optional Low Bit-Rate Redundancy (LBRR) frames, which are reduced-bitrate
  1488. encodings of previous SILK frames, may be included to aid in recovery from
  1489. packet loss.
  1490. If present, these appear before the regular SILK frames.
  1491. They are in most respects identical to regular, active SILK frames, except that
  1492. they are usually encoded with a lower bitrate.
  1493. This draft uses "SILK frame" to refer to either one and "regular SILK frame" if
  1494. it needs to draw a distinction between the two.
  1495. </t>
  1496. <t>
  1497. Logically, each SILK frame is in turn composed of either two or four 5&nbsp;ms
  1498. subframes.
  1499. Various parameters, such as the quantization gain of the excitation and the
  1500. pitch lag and filter coefficients can vary on a subframe-by-subframe basis.
  1501. Physically, the parameters for each subframe are interleaved in the bitstream,
  1502. as described in the relevant sections for each parameter.
  1503. </t>
  1504. <t>
  1505. All of these frames and subframes are decoded from the same range coder, with
  1506. no padding between them.
  1507. Thus packing multiple SILK frames in a single Opus frame saves, on average,
  1508. half a byte per SILK frame.
  1509. It also allows some parameters to be predicted from prior SILK frames in the
  1510. same Opus frame, since this does not degrade packet loss robustness (beyond
  1511. any penalty for merely using fewer, larger packets to store multiple frames).
  1512. </t>
  1513. <t>
  1514. Stereo support in SILK uses a variant of mid-side coding, allowing a mono
  1515. decoder to simply decode the mid channel.
  1516. However, the data for the two channels is interleaved, so a mono decoder must
  1517. still unpack the data for the side channel.
  1518. It would be required to do so anyway for Hybrid Opus frames, or to support
  1519. decoding individual 20&nbsp;ms frames.
  1520. </t>
  1521. <t>
  1522. <xref target="silk_symbols"/> summarizes the overall grouping of the contents of
  1523. the LP layer.
  1524. Figures&nbsp;<xref format="counter" target="silk_mono_60ms_frame"/>
  1525. and&nbsp;<xref format="counter" target="silk_stereo_60ms_frame"/> illustrate
  1526. the ordering of the various SILK frames for a 60&nbsp;ms Opus frame, for both
  1527. mono and stereo, respectively.
  1528. </t>
  1529. <texttable anchor="silk_symbols"
  1530. title="Organization of the SILK layer of an Opus frame">
  1531. <ttcol align="center">Symbol(s)</ttcol>
  1532. <ttcol align="center">PDF(s)</ttcol>
  1533. <ttcol align="center">Condition</ttcol>
  1534. <c>Voice Activity Detection (VAD) flags</c>
  1535. <c>{1, 1}/2</c>
  1536. <c/>
  1537. <c>LBRR flag</c>
  1538. <c>{1, 1}/2</c>
  1539. <c/>
  1540. <c>Per-frame LBRR flags</c>
  1541. <c><xref target="silk_lbrr_flag_pdfs"/></c>
  1542. <c><xref target="silk_lbrr_flags"/></c>
  1543. <c>LBRR Frame(s)</c>
  1544. <c><xref target="silk_frame"/></c>
  1545. <c><xref target="silk_lbrr_flags"/></c>
  1546. <c>Regular SILK Frame(s)</c>
  1547. <c><xref target="silk_frame"/></c>
  1548. <c/>
  1549. </texttable>
  1550. <figure align="center" anchor="silk_mono_60ms_frame"
  1551. title="A 60&nbsp;ms Mono Frame">
  1552. <artwork align="center"><![CDATA[
  1553. +---------------------------------+
  1554. | VAD Flags |
  1555. +---------------------------------+
  1556. | LBRR Flag |
  1557. +---------------------------------+
  1558. | Per-Frame LBRR Flags (Optional) |
  1559. +---------------------------------+
  1560. | LBRR Frame 1 (Optional) |
  1561. +---------------------------------+
  1562. | LBRR Frame 2 (Optional) |
  1563. +---------------------------------+
  1564. | LBRR Frame 3 (Optional) |
  1565. +---------------------------------+
  1566. | Regular SILK Frame 1 |
  1567. +---------------------------------+
  1568. | Regular SILK Frame 2 |
  1569. +---------------------------------+
  1570. | Regular SILK Frame 3 |
  1571. +---------------------------------+
  1572. ]]></artwork>
  1573. </figure>
  1574. <figure align="center" anchor="silk_stereo_60ms_frame"
  1575. title="A 60&nbsp;ms Stereo Frame">
  1576. <artwork align="center"><![CDATA[
  1577. +---------------------------------------+
  1578. | Mid VAD Flags |
  1579. +---------------------------------------+
  1580. | Mid LBRR Flag |
  1581. +---------------------------------------+
  1582. | Side VAD Flags |
  1583. +---------------------------------------+
  1584. | Side LBRR Flag |
  1585. +---------------------------------------+
  1586. | Mid Per-Frame LBRR Flags (Optional) |
  1587. +---------------------------------------+
  1588. | Side Per-Frame LBRR Flags (Optional) |
  1589. +---------------------------------------+
  1590. | Mid LBRR Frame 1 (Optional) |
  1591. +---------------------------------------+
  1592. | Side LBRR Frame 1 (Optional) |
  1593. +---------------------------------------+
  1594. | Mid LBRR Frame 2 (Optional) |
  1595. +---------------------------------------+
  1596. | Side LBRR Frame 2 (Optional) |
  1597. +---------------------------------------+
  1598. | Mid LBRR Frame 3 (Optional) |
  1599. +---------------------------------------+
  1600. | Side LBRR Frame 3 (Optional) |
  1601. +---------------------------------------+
  1602. | Mid Regular SILK Frame 1 |
  1603. +---------------------------------------+
  1604. | Side Regular SILK Frame 1 (Optional) |
  1605. +---------------------------------------+
  1606. | Mid Regular SILK Frame 2 |
  1607. +---------------------------------------+
  1608. | Side Regular SILK Frame 2 (Optional) |
  1609. +---------------------------------------+
  1610. | Mid Regular SILK Frame 3 |
  1611. +---------------------------------------+
  1612. | Side Regular SILK Frame 3 (Optional) |
  1613. +---------------------------------------+
  1614. ]]></artwork>
  1615. </figure>
  1616. </section>
  1617. <section anchor="silk_header_bits" title="Header Bits">
  1618. <t>
  1619. The LP layer begins with two to eight header bits, decoded in silk_Decode()
  1620. (dec_API.c).
  1621. These consist of one Voice Activity Detection (VAD) bit per frame (up to 3),
  1622. followed by a single flag indicating the presence of LBRR frames.
  1623. For a stereo packet, these first flags correspond to the mid channel, and a
  1624. second set of flags is included for the side channel.
  1625. </t>
  1626. <t>
  1627. Because these are the first symbols decoded by the range coder and because they
  1628. are coded as binary values with uniform probability, they can be extracted
  1629. directly from the most significant bits of the first byte of compressed data.
  1630. Thus, a receiver can determine if an Opus frame contains any active SILK frames
  1631. without the overhead of using the range decoder.
  1632. </t>
  1633. </section>
  1634. <section anchor="silk_lbrr_flags" title="Per-Frame LBRR Flags">
  1635. <t>
  1636. For Opus frames longer than 20&nbsp;ms, a set of LBRR flags is
  1637. decoded for each channel that has its LBRR flag set.
  1638. Each set contains one flag per 20&nbsp;ms SILK frame.
  1639. 40&nbsp;ms Opus frames use the 2-frame LBRR flag PDF from
  1640. <xref target="silk_lbrr_flag_pdfs"/>, and 60&nbsp;ms Opus frames use the
  1641. 3-frame LBRR flag PDF.
  1642. For each channel, the resulting 2- or 3-bit integer contains the corresponding
  1643. LBRR flag for each frame, packed in order from the LSB to the MSB.
  1644. </t>
  1645. <texttable anchor="silk_lbrr_flag_pdfs" title="LBRR Flag PDFs">
  1646. <ttcol>Frame Size</ttcol>
  1647. <ttcol>PDF</ttcol>
  1648. <c>40&nbsp;ms</c> <c>{0, 53, 53, 150}/256</c>
  1649. <c>60&nbsp;ms</c> <c>{0, 41, 20, 29, 41, 15, 28, 82}/256</c>
  1650. </texttable>
  1651. <t>
  1652. A 10&nbsp;or 20&nbsp;ms Opus frame does not contain any per-frame LBRR flags,
  1653. as there may be at most one LBRR frame per channel.
  1654. The global LBRR flag in the header bits (see <xref target="silk_header_bits"/>)
  1655. is already sufficient to indicate the presence of that single LBRR frame.
  1656. </t>
  1657. </section>
  1658. <section anchor="silk_lbrr_frames" title="LBRR Frames">
  1659. <t>
  1660. The LBRR frames, if present, contain an encoded representation of the signal
  1661. immediately prior to the current Opus frame as if it were encoded with the
  1662. current mode, frame size, audio bandwidth, and channel count, even if those
  1663. differ from the prior Opus frame.
  1664. When one of these parameters changes from one Opus frame to the next, this
  1665. implies that the LBRR frames of the current Opus frame may not be simple
  1666. drop-in replacements for the contents of the previous Opus frame.
  1667. </t>
  1668. <t>
  1669. For example, when switching from 20&nbsp;ms to 60&nbsp;ms, the 60&nbsp;ms Opus
  1670. frame may contain LBRR frames covering up to three prior 20&nbsp;ms Opus
  1671. frames, even if those frames already contained LBRR frames covering some of
  1672. the same time periods.
  1673. When switching from 20&nbsp;ms to 10&nbsp;ms, the 10&nbsp;ms Opus frame can
  1674. contain an LBRR frame covering at most half the prior 20&nbsp;ms Opus frame,
  1675. potentially leaving a hole that needs to be concealed from even a single
  1676. packet loss (see <xref target="Packet Loss Concealment"/>).
  1677. When switching from mono to stereo, the LBRR frames in the first stereo Opus
  1678. frame MAY contain a non-trivial side channel.
  1679. </t>
  1680. <t>
  1681. In order to properly produce LBRR frames under all conditions, an encoder might
  1682. need to buffer up to 60&nbsp;ms of audio and re-encode it during these
  1683. transitions.
  1684. However, the reference implementation opts to disable LBRR frames at the
  1685. transition point for simplicity.
  1686. Since transitions are relatively infrequent in normal usage, this does not have
  1687. a significant impact on packet loss robustness.
  1688. </t>
  1689. <t>
  1690. The LBRR frames immediately follow the LBRR flags, prior to any regular SILK
  1691. frames.
  1692. <xref target="silk_frame"/> describes their exact contents.
  1693. LBRR frames do not include their own separate VAD flags.
  1694. LBRR frames are only meant to be transmitted for active speech, thus all LBRR
  1695. frames are treated as active.
  1696. </t>
  1697. <t>
  1698. In a stereo Opus frame longer than 20&nbsp;ms, although the per-frame LBRR
  1699. flags for the mid channel are coded as a unit before the per-frame LBRR flags
  1700. for the side channel, the LBRR frames themselves are interleaved.
  1701. The decoder parses an LBRR frame for the mid channel of a given 20&nbsp;ms
  1702. interval (if present) and then immediately parses the corresponding LBRR
  1703. frame for the side channel (if present), before proceeding to the next
  1704. 20&nbsp;ms interval.
  1705. </t>
  1706. </section>
  1707. <section anchor="silk_regular_frames" title="Regular SILK Frames">
  1708. <t>
  1709. The regular SILK frame(s) follow the LBRR frames (if any).
  1710. <xref target="silk_frame"/> describes their contents, as well.
  1711. Unlike the LBRR frames, a regular SILK frame is coded for each time interval in
  1712. an Opus frame, even if the corresponding VAD flags are unset.
  1713. For stereo Opus frames longer than 20&nbsp;ms, the regular mid and side SILK
  1714. frames for each 20&nbsp;ms interval are interleaved, just as with the LBRR
  1715. frames.
  1716. The side frame may be skipped by coding an appropriate flag, as detailed in
  1717. <xref target="silk_mid_only_flag"/>.
  1718. </t>
  1719. </section>
  1720. <section anchor="silk_frame" title="SILK Frame Contents">
  1721. <t>
  1722. Each SILK frame includes a set of side information that encodes
  1723. <list style="symbols">
  1724. <t>The frame type and quantization type (<xref target="silk_frame_type"/>),</t>
  1725. <t>Quantization gains (<xref target="silk_gains"/>),</t>
  1726. <t>Short-term prediction filter coefficients (<xref target="silk_nlsfs"/>),</t>
  1727. <t>A Line Spectral Frequencies (LSF) interpolation weight (<xref target="silk_nlsf_interpolation"/>),</t>
  1728. <t>
  1729. Long-term prediction filter lags and gains (<xref target="silk_ltp_params"/>),
  1730. and
  1731. </t>
  1732. <t>A linear congruential generator (LCG) seed (<xref target="silk_seed"/>).</t>
  1733. </list>
  1734. The quantized excitation signal (see <xref target="silk_excitation"/>) follows
  1735. these at the end of the frame.
  1736. <xref target="silk_frame_symbols"/> details the overall organization of a
  1737. SILK frame.
  1738. </t>
  1739. <texttable anchor="silk_frame_symbols"
  1740. title="Order of the symbols in an individual SILK frame">
  1741. <ttcol align="center">Symbol(s)</ttcol>
  1742. <ttcol align="center">PDF(s)</ttcol>
  1743. <ttcol align="center">Condition</ttcol>
  1744. <c>Stereo Prediction Weights</c>
  1745. <c><xref target="silk_stereo_pred_pdfs"/></c>
  1746. <c><xref target="silk_stereo_pred"/></c>
  1747. <c>Mid-only Flag</c>
  1748. <c><xref target="silk_mid_only_pdf"/></c>
  1749. <c><xref target="silk_mid_only_flag"/></c>
  1750. <c>Frame Type</c>
  1751. <c><xref target="silk_frame_type"/></c>
  1752. <c/>
  1753. <c>Subframe Gains</c>
  1754. <c><xref target="silk_gains"/></c>
  1755. <c/>
  1756. <c>Normalized LSF Stage-1 Index</c>
  1757. <c><xref target="silk_nlsf_stage1_pdfs"/></c>
  1758. <c/>
  1759. <c>Normalized LSF Stage-2 Residual</c>
  1760. <c><xref target="silk_nlsf_stage2"/></c>
  1761. <c/>
  1762. <c>Normalized LSF Interpolation Weight</c>
  1763. <c><xref target="silk_nlsf_interp_pdf"/></c>
  1764. <c>20&nbsp;ms frame</c>
  1765. <c>Primary Pitch Lag</c>
  1766. <c><xref target="silk_ltp_lags"/></c>
  1767. <c>Voiced frame</c>
  1768. <c>Subframe Pitch Contour</c>
  1769. <c><xref target="silk_pitch_contour_pdfs"/></c>
  1770. <c>Voiced frame</c>
  1771. <c>Periodicity Index</c>
  1772. <c><xref target="silk_perindex_pdf"/></c>
  1773. <c>Voiced frame</c>
  1774. <c>LTP Filter</c>
  1775. <c><xref target="silk_ltp_filter_pdfs"/></c>
  1776. <c>Voiced frame</c>
  1777. <c>LTP Scaling</c>
  1778. <c><xref target="silk_ltp_scaling_pdf"/></c>
  1779. <c><xref target="silk_ltp_scaling"/></c>
  1780. <c>LCG Seed</c>
  1781. <c><xref target="silk_seed_pdf"/></c>
  1782. <c/>
  1783. <c>Excitation Rate Level</c>
  1784. <c><xref target="silk_rate_level_pdfs"/></c>
  1785. <c/>
  1786. <c>Excitation Pulse Counts</c>
  1787. <c><xref target="silk_pulse_count_pdfs"/></c>
  1788. <c/>
  1789. <c>Excitation Pulse Locations</c>
  1790. <c><xref target="silk_pulse_locations"/></c>
  1791. <c>Non-zero pulse count</c>
  1792. <c>Excitation LSBs</c>
  1793. <c><xref target="silk_shell_lsb_pdf"/></c>
  1794. <c><xref target="silk_pulse_counts"/></c>
  1795. <c>Excitation Signs</c>
  1796. <c><xref target="silk_sign_pdfs"/></c>
  1797. <c/>
  1798. </texttable>
  1799. <section anchor="silk_stereo_pred" toc="include"
  1800. title="Stereo Prediction Weights">
  1801. <t>
  1802. A SILK frame corresponding to the mid channel of a stereo Opus frame begins
  1803. with a pair of side channel prediction weights, designed such that zeros
  1804. indicate normal mid-side coupling.
  1805. Since these weights can change on every frame, the first portion of each frame
  1806. linearly interpolates between the previous weights and the current ones, using
  1807. zeros for the previous weights if none are available.
  1808. These prediction weights are never included in a mono Opus frame, and the
  1809. previous weights are reset to zeros on any transition from mono to stereo.
  1810. They are also not included in an LBRR frame for the side channel, even if the
  1811. LBRR flags indicate the corresponding mid channel was not coded.
  1812. In that case, the previous weights are used, again substituting in zeros if no
  1813. previous weights are available since the last decoder reset
  1814. (see <xref target="decoder-reset"/>).
  1815. </t>
  1816. <t>
  1817. To summarize, these weights are coded if and only if
  1818. <list style="symbols">
  1819. <t>This is a stereo Opus frame (<xref target="toc_byte"/>), and</t>
  1820. <t>The current SILK frame corresponds to the mid channel.</t>
  1821. </list>
  1822. </t>
  1823. <t>
  1824. The prediction weights are coded in three separate pieces, which are decoded
  1825. by silk_stereo_decode_pred() (decode_stereo_pred.c).
  1826. The first piece jointly codes the high-order part of a table index for both
  1827. weights.
  1828. The second piece codes the low-order part of each table index.
  1829. The third piece codes an offset used to linearly interpolate between table
  1830. indices.
  1831. The details are as follows.
  1832. </t>
  1833. <t>
  1834. Let n be an index decoded with the 25-element stage-1 PDF in
  1835. <xref target="silk_stereo_pred_pdfs"/>.
  1836. Then let i0 and i1 be indices decoded with the stage-2 and stage-3 PDFs in
  1837. <xref target="silk_stereo_pred_pdfs"/>, respectively, and let i2 and i3
  1838. be two more indices decoded with the stage-2 and stage-3 PDFs, all in that
  1839. order.
  1840. </t>
  1841. <texttable anchor="silk_stereo_pred_pdfs" title="Stereo Weight PDFs">
  1842. <ttcol align="left">Stage</ttcol>
  1843. <ttcol align="left">PDF</ttcol>
  1844. <c>Stage 1</c>
  1845. <c>{7, 2, 1, 1, 1,
  1846. 10, 24, 8, 1, 1,
  1847. 3, 23, 92, 23, 3,
  1848. 1, 1, 8, 24, 10,
  1849. 1, 1, 1, 2, 7}/256</c>
  1850. <c>Stage 2</c>
  1851. <c>{85, 86, 85}/256</c>
  1852. <c>Stage 3</c>
  1853. <c>{51, 51, 52, 51, 51}/256</c>
  1854. </texttable>
  1855. <t>
  1856. Then use n, i0, and i2 to form two table indices, wi0 and wi1, according to
  1857. <figure align="center">
  1858. <artwork align="center"><![CDATA[
  1859. wi0 = i0 + 3*(n/5)
  1860. wi1 = i2 + 3*(n%5)
  1861. ]]></artwork>
  1862. </figure>
  1863. where the division is integer division.
  1864. The range of these indices is 0 to 14, inclusive.
  1865. Let w[i] be the i'th weight from <xref target="silk_stereo_weights_table"/>.
  1866. Then the two prediction weights, w0_Q13 and w1_Q13, are
  1867. <figure align="center">
  1868. <artwork align="center"><![CDATA[
  1869. w1_Q13 = w_Q13[wi1]
  1870. + ((w_Q13[wi1+1] - w_Q13[wi1])*6554) >> 16)*(2*i3 + 1)
  1871. w0_Q13 = w_Q13[wi0]
  1872. + ((w_Q13[wi0+1] - w_Q13[wi0])*6554) >> 16)*(2*i1 + 1)
  1873. - w1_Q13
  1874. ]]></artwork>
  1875. </figure>
  1876. N.b., w1_Q13 is computed first here, because w0_Q13 depends on it.
  1877. The constant 6554 is approximately 0.1 in Q16.
  1878. Although wi0 and wi1 only have 15 possible values,
  1879. <xref target="silk_stereo_weights_table"/> contains 16 entries to allow
  1880. interpolation between entry wi0 and (wi0&nbsp;+&nbsp;1) (and likewise for wi1).
  1881. </t>
  1882. <texttable anchor="silk_stereo_weights_table"
  1883. title="Stereo Weight Table">
  1884. <ttcol align="left">Index</ttcol>
  1885. <ttcol align="right">Weight (Q13)</ttcol>
  1886. <c>0</c> <c>-13732</c>
  1887. <c>1</c> <c>-10050</c>
  1888. <c>2</c> <c>-8266</c>
  1889. <c>3</c> <c>-7526</c>
  1890. <c>4</c> <c>-6500</c>
  1891. <c>5</c> <c>-5000</c>
  1892. <c>6</c> <c>-2950</c>
  1893. <c>7</c> <c>-820</c>
  1894. <c>8</c> <c>820</c>
  1895. <c>9</c> <c>2950</c>
  1896. <c>10</c> <c>5000</c>
  1897. <c>11</c> <c>6500</c>
  1898. <c>12</c> <c>7526</c>
  1899. <c>13</c> <c>8266</c>
  1900. <c>14</c> <c>10050</c>
  1901. <c>15</c> <c>13732</c>
  1902. </texttable>
  1903. </section>
  1904. <section anchor="silk_mid_only_flag" toc="include" title="Mid-only Flag">
  1905. <t>
  1906. A flag appears after the stereo prediction weights that indicates if only the
  1907. mid channel is coded for this time interval.
  1908. It appears only when
  1909. <list style="symbols">
  1910. <t>This is a stereo Opus frame (see <xref target="toc_byte"/>),</t>
  1911. <t>The current SILK frame corresponds to the mid channel, and</t>
  1912. <t>Either
  1913. <list style="symbols">
  1914. <t>This is a regular SILK frame where the VAD flags
  1915. (see <xref target="silk_header_bits"/>) indicate that the corresponding side
  1916. channel is not active.</t>
  1917. <t>
  1918. This is an LBRR frame where the LBRR flags
  1919. (see <xref target="silk_header_bits"/> and <xref target="silk_lbrr_flags"/>)
  1920. indicate that the corresponding side channel is not coded.
  1921. </t>
  1922. </list>
  1923. </t>
  1924. </list>
  1925. It is omitted when there are no stereo weights, for all of the same reasons.
  1926. It is also omitted for a regular SILK frame when the VAD flag of the
  1927. corresponding side channel frame is set (indicating it is active).
  1928. The side channel must be coded in this case, making the mid-only flag
  1929. redundant.
  1930. It is also omitted for an LBRR frame when the corresponding LBRR flags
  1931. indicate the side channel is coded.
  1932. </t>
  1933. <t>
  1934. When the flag is present, the decoder reads a single value using the PDF in
  1935. <xref target="silk_mid_only_pdf"/>, as implemented in
  1936. silk_stereo_decode_mid_only() (decode_stereo_pred.c).
  1937. If the flag is set, then there is no corresponding SILK frame for the side
  1938. channel, the entire decoding process for the side channel is skipped, and
  1939. zeros are fed to the stereo unmixing process (see
  1940. <xref target="silk_stereo_unmixing"/>) instead.
  1941. As stated above, LBRR frames still include this flag when the LBRR flag
  1942. indicates that the side channel is not coded.
  1943. In that case, if this flag is zero (indicating that there should be a side
  1944. channel), then Packet Loss Concealment (PLC, see
  1945. <xref target="Packet Loss Concealment"/>) SHOULD be invoked to recover a
  1946. side channel signal.
  1947. Otherwise, the stereo image will collapse.
  1948. </t>
  1949. <texttable anchor="silk_mid_only_pdf" title="Mid-only Flag PDF">
  1950. <ttcol align="left">PDF</ttcol>
  1951. <c>{192, 64}/256</c>
  1952. </texttable>
  1953. </section>
  1954. <section anchor="silk_frame_type" toc="include" title="Frame Type">
  1955. <t>
  1956. Each SILK frame contains a single "frame type" symbol that jointly codes the
  1957. signal type and quantization offset type of the corresponding frame.
  1958. If the current frame is a regular SILK frame whose VAD bit was not set (an
  1959. "inactive" frame), then the frame type symbol takes on a value of either 0 or
  1960. 1 and is decoded using the first PDF in <xref target="silk_frame_type_pdfs"/>.
  1961. If the frame is an LBRR frame or a regular SILK frame whose VAD flag was set
  1962. (an "active" frame), then the value of the symbol may range from 2 to 5,
  1963. inclusive, and is decoded using the second PDF in
  1964. <xref target="silk_frame_type_pdfs"/>.
  1965. <xref target="silk_frame_type_table"/> translates between the value of the
  1966. frame type symbol and the corresponding signal type and quantization offset
  1967. type.
  1968. </t>
  1969. <texttable anchor="silk_frame_type_pdfs" title="Frame Type PDFs">
  1970. <ttcol>VAD Flag</ttcol>
  1971. <ttcol>PDF</ttcol>
  1972. <c>Inactive</c> <c>{26, 230, 0, 0, 0, 0}/256</c>
  1973. <c>Active</c> <c>{0, 0, 24, 74, 148, 10}/256</c>
  1974. </texttable>
  1975. <texttable anchor="silk_frame_type_table"
  1976. title="Signal Type and Quantization Offset Type from Frame Type">
  1977. <ttcol>Frame Type</ttcol>
  1978. <ttcol>Signal Type</ttcol>
  1979. <ttcol align="right">Quantization Offset Type</ttcol>
  1980. <c>0</c> <c>Inactive</c> <c>Low</c>
  1981. <c>1</c> <c>Inactive</c> <c>High</c>
  1982. <c>2</c> <c>Unvoiced</c> <c>Low</c>
  1983. <c>3</c> <c>Unvoiced</c> <c>High</c>
  1984. <c>4</c> <c>Voiced</c> <c>Low</c>
  1985. <c>5</c> <c>Voiced</c> <c>High</c>
  1986. </texttable>
  1987. </section>
  1988. <section anchor="silk_gains" toc="include" title="Subframe Gains">
  1989. <t>
  1990. A separate quantization gain is coded for each 5&nbsp;ms subframe.
  1991. These gains control the step size between quantization levels of the excitation
  1992. signal and, therefore, the quality of the reconstruction.
  1993. They are independent of and unrelated to the pitch contours coded for voiced
  1994. frames.
  1995. The quantization gains are themselves uniformly quantized to 6&nbsp;bits on a
  1996. log scale, giving them a resolution of approximately 1.369&nbsp;dB and a range
  1997. of approximately 1.94&nbsp;dB to 88.21&nbsp;dB.
  1998. </t>
  1999. <t>
  2000. The subframe gains are either coded independently, or relative to the gain from
  2001. the most recent coded subframe in the same channel.
  2002. Independent coding is used if and only if
  2003. <list style="symbols">
  2004. <t>
  2005. This is the first subframe in the current SILK frame, and
  2006. </t>
  2007. <t>Either
  2008. <list style="symbols">
  2009. <t>
  2010. This is the first SILK frame of its type (LBRR or regular) for this channel in
  2011. the current Opus frame, or
  2012. </t>
  2013. <t>
  2014. The previous SILK frame of the same type (LBRR or regular) for this channel in
  2015. the same Opus frame was not coded.
  2016. </t>
  2017. </list>
  2018. </t>
  2019. </list>
  2020. </t>
  2021. <t>
  2022. In an independently coded subframe gain, the 3 most significant bits of the
  2023. quantization gain are decoded using a PDF selected from
  2024. <xref target="silk_independent_gain_msb_pdfs"/> based on the decoded signal
  2025. type (see <xref target="silk_frame_type"/>).
  2026. </t>
  2027. <texttable anchor="silk_independent_gain_msb_pdfs"
  2028. title="PDFs for Independent Quantization Gain MSB Coding">
  2029. <ttcol align="left">Signal Type</ttcol>
  2030. <ttcol align="left">PDF</ttcol>
  2031. <c>Inactive</c> <c>{32, 112, 68, 29, 12, 1, 1, 1}/256</c>
  2032. <c>Unvoiced</c> <c>{2, 17, 45, 60, 62, 47, 19, 4}/256</c>
  2033. <c>Voiced</c> <c>{1, 3, 26, 71, 94, 50, 9, 2}/256</c>
  2034. </texttable>
  2035. <t>
  2036. The 3 least significant bits are decoded using a uniform PDF:
  2037. </t>
  2038. <texttable anchor="silk_independent_gain_lsb_pdf"
  2039. title="PDF for Independent Quantization Gain LSB Coding">
  2040. <ttcol align="left">PDF</ttcol>
  2041. <c>{32, 32, 32, 32, 32, 32, 32, 32}/256</c>
  2042. </texttable>
  2043. <t>
  2044. These 6 bits are combined to form a value, gain_index, between 0 and 63.
  2045. When the gain for the previous subframe is available, then the current gain is
  2046. limited as follows:
  2047. <figure align="center">
  2048. <artwork align="center"><![CDATA[
  2049. log_gain = max(gain_index, previous_log_gain - 16) .
  2050. ]]></artwork>
  2051. </figure>
  2052. This may help some implementations limit the change in precision of their
  2053. internal LTP history.
  2054. The indices which this clamp applies to cannot simply be removed from the
  2055. codebook, because previous_log_gain will not be available after packet loss.
  2056. The clamping is skipped after a decoder reset, and in the side channel if the
  2057. previous frame in the side channel was not coded, since there is no value for
  2058. previous_log_gain available.
  2059. It MAY also be skipped after packet loss.
  2060. </t>
  2061. <t>
  2062. For subframes which do not have an independent gain (including the first
  2063. subframe of frames not listed as using independent coding above), the
  2064. quantization gain is coded relative to the gain from the previous subframe (in
  2065. the same channel).
  2066. The PDF in <xref target="silk_delta_gain_pdf"/> yields a delta_gain_index value
  2067. between 0 and 40, inclusive.
  2068. </t>
  2069. <texttable anchor="silk_delta_gain_pdf"
  2070. title="PDF for Delta Quantization Gain Coding">
  2071. <ttcol align="left">PDF</ttcol>
  2072. <c>{6, 5, 11, 31, 132, 21, 8, 4,
  2073. 3, 2, 2, 2, 1, 1, 1, 1,
  2074. 1, 1, 1, 1, 1, 1, 1, 1,
  2075. 1, 1, 1, 1, 1, 1, 1, 1,
  2076. 1, 1, 1, 1, 1, 1, 1, 1, 1}/256</c>
  2077. </texttable>
  2078. <t>
  2079. The following formula translates this index into a quantization gain for the
  2080. current subframe using the gain from the previous subframe:
  2081. <figure align="center">
  2082. <artwork align="center"><![CDATA[
  2083. log_gain = clamp(0, max(2*delta_gain_index - 16,
  2084. previous_log_gain + delta_gain_index - 4), 63) .
  2085. ]]></artwork>
  2086. </figure>
  2087. </t>
  2088. <t>
  2089. silk_gains_dequant() (gain_quant.c) dequantizes log_gain for the k'th subframe
  2090. and converts it into a linear Q16 scale factor via
  2091. <figure align="center">
  2092. <artwork align="center"><![CDATA[
  2093. gain_Q16[k] = silk_log2lin((0x1D1C71*log_gain>>16) + 2090)
  2094. ]]></artwork>
  2095. </figure>
  2096. </t>
  2097. <t>
  2098. The function silk_log2lin() (log2lin.c) computes an approximation of
  2099. 2**(inLog_Q7/128.0), where inLog_Q7 is its Q7 input.
  2100. Let i = inLog_Q7&gt;&gt;7 be the integer part of inLogQ7 and
  2101. f = inLog_Q7&amp;127 be the fractional part.
  2102. Then
  2103. <figure align="center">
  2104. <artwork align="center"><![CDATA[
  2105. (1<<i) + ((-174*f*(128-f)>>16)+f)*((1<<i)>>7)
  2106. ]]></artwork>
  2107. </figure>
  2108. yields the approximate exponential.
  2109. The final Q16 gain values lies between 81920 and 1686110208, inclusive
  2110. (representing scale factors of 1.25 to 25728, respectively).
  2111. </t>
  2112. </section>
  2113. <section anchor="silk_nlsfs" toc="include" title="Normalized Line Spectral
  2114. Frequency (LSF) and Linear Predictive Coding (LPC) Coefficients">
  2115. <t>
  2116. A set of normalized Line Spectral Frequency (LSF) coefficients follow the
  2117. quantization gains in the bitstream, and represent the Linear Predictive
  2118. Coding (LPC) coefficients for the current SILK frame.
  2119. Once decoded, the normalized LSFs form an increasing list of Q15 values between
  2120. 0 and 1.
  2121. These represent the interleaved zeros on the upper half of the unit circle
  2122. (between 0 and pi, hence "normalized") in the standard decomposition
  2123. <xref target="line-spectral-pairs"/> of the LPC filter into a symmetric part
  2124. and an anti-symmetric part (P and Q in <xref target="silk_nlsf2lpc"/>).
  2125. Because of non-linear effects in the decoding process, an implementation SHOULD
  2126. match the fixed-point arithmetic described in this section exactly.
  2127. An encoder SHOULD also use the same process.
  2128. </t>
  2129. <t>
  2130. The normalized LSFs are coded using a two-stage vector quantizer (VQ)
  2131. (<xref target="silk_nlsf_stage1"/> and <xref target="silk_nlsf_stage2"/>).
  2132. NB and MB frames use an order-10 predictor, while WB frames use an order-16
  2133. predictor, and thus have different sets of tables.
  2134. After reconstructing the normalized LSFs
  2135. (<xref target="silk_nlsf_reconstruction"/>), the decoder runs them through a
  2136. stabilization process (<xref target="silk_nlsf_stabilization"/>), interpolates
  2137. them between frames (<xref target="silk_nlsf_interpolation"/>), converts them
  2138. back into LPC coefficients (<xref target="silk_nlsf2lpc"/>), and then runs
  2139. them through further processes to limit the range of the coefficients
  2140. (<xref target="silk_lpc_range_limit"/>) and the gain of the filter
  2141. (<xref target="silk_lpc_gain_limit"/>).
  2142. All of this is necessary to ensure the reconstruction process is stable.
  2143. </t>
  2144. <section anchor="silk_nlsf_stage1" title="Normalized LSF Stage 1 Decoding">
  2145. <t>
  2146. The first VQ stage uses a 32-element codebook, coded with one of the PDFs in
  2147. <xref target="silk_nlsf_stage1_pdfs"/>, depending on the audio bandwidth and
  2148. the signal type of the current SILK frame.
  2149. This yields a single index, I1, for the entire frame, which
  2150. <list style="numbers">
  2151. <t>Indexes an element in a coarse codebook,</t>
  2152. <t>Selects the PDFs for the second stage of the VQ, and</t>
  2153. <t>Selects the prediction weights used to remove intra-frame redundancy from
  2154. the second stage.</t>
  2155. </list>
  2156. The actual codebook elements are listed in
  2157. <xref target="silk_nlsf_nbmb_codebook"/> and
  2158. <xref target="silk_nlsf_wb_codebook"/>, but they are not needed until the last
  2159. stages of reconstructing the LSF coefficients.
  2160. </t>
  2161. <texttable anchor="silk_nlsf_stage1_pdfs"
  2162. title="PDFs for Normalized LSF Stage-1 Index Decoding">
  2163. <ttcol align="left">Audio Bandwidth</ttcol>
  2164. <ttcol align="left">Signal Type</ttcol>
  2165. <ttcol align="left">PDF</ttcol>
  2166. <c>NB or MB</c> <c>Inactive or unvoiced</c>
  2167. <c>
  2168. {44, 34, 30, 19, 21, 12, 11, 3,
  2169. 3, 2, 16, 2, 2, 1, 5, 2,
  2170. 1, 3, 3, 1, 1, 2, 2, 2,
  2171. 3, 1, 9, 9, 2, 7, 2, 1}/256
  2172. </c>
  2173. <c>NB or MB</c> <c>Voiced</c>
  2174. <c>
  2175. {1, 10, 1, 8, 3, 8, 8, 14,
  2176. 13, 14, 1, 14, 12, 13, 11, 11,
  2177. 12, 11, 10, 10, 11, 8, 9, 8,
  2178. 7, 8, 1, 1, 6, 1, 6, 5}/256
  2179. </c>
  2180. <c>WB</c> <c>Inactive or unvoiced</c>
  2181. <c>
  2182. {31, 21, 3, 17, 1, 8, 17, 4,
  2183. 1, 18, 16, 4, 2, 3, 1, 10,
  2184. 1, 3, 16, 11, 16, 2, 2, 3,
  2185. 2, 11, 1, 4, 9, 8, 7, 3}/256
  2186. </c>
  2187. <c>WB</c> <c>Voiced</c>
  2188. <c>
  2189. {1, 4, 16, 5, 18, 11, 5, 14,
  2190. 15, 1, 3, 12, 13, 14, 14, 6,
  2191. 14, 12, 2, 6, 1, 12, 12, 11,
  2192. 10, 3, 10, 5, 1, 1, 1, 3}/256
  2193. </c>
  2194. </texttable>
  2195. </section>
  2196. <section anchor="silk_nlsf_stage2" title="Normalized LSF Stage 2 Decoding">
  2197. <t>
  2198. A total of 16 PDFs are available for the LSF residual in the second stage: the
  2199. 8 (a...h) for NB and MB frames given in
  2200. <xref target="silk_nlsf_stage2_nbmb_pdfs"/>, and the 8 (i...p) for WB frames
  2201. given in <xref target="silk_nlsf_stage2_wb_pdfs"/>.
  2202. Which PDF is used for which coefficient is driven by the index, I1,
  2203. decoded in the first stage.
  2204. <xref target="silk_nlsf_nbmb_stage2_cb_sel"/> lists the letter of the
  2205. corresponding PDF for each normalized LSF coefficient for NB and MB, and
  2206. <xref target="silk_nlsf_wb_stage2_cb_sel"/> lists the same information for WB.
  2207. </t>
  2208. <texttable anchor="silk_nlsf_stage2_nbmb_pdfs"
  2209. title="PDFs for NB/MB Normalized LSF Stage-2 Index Decoding">
  2210. <ttcol align="left">Codebook</ttcol>
  2211. <ttcol align="left">PDF</ttcol>
  2212. <c>a</c> <c>{1, 1, 1, 15, 224, 11, 1, 1, 1}/256</c>
  2213. <c>b</c> <c>{1, 1, 2, 34, 183, 32, 1, 1, 1}/256</c>
  2214. <c>c</c> <c>{1, 1, 4, 42, 149, 55, 2, 1, 1}/256</c>
  2215. <c>d</c> <c>{1, 1, 8, 52, 123, 61, 8, 1, 1}/256</c>
  2216. <c>e</c> <c>{1, 3, 16, 53, 101, 74, 6, 1, 1}/256</c>
  2217. <c>f</c> <c>{1, 3, 17, 55, 90, 73, 15, 1, 1}/256</c>
  2218. <c>g</c> <c>{1, 7, 24, 53, 74, 67, 26, 3, 1}/256</c>
  2219. <c>h</c> <c>{1, 1, 18, 63, 78, 58, 30, 6, 1}/256</c>
  2220. </texttable>
  2221. <texttable anchor="silk_nlsf_stage2_wb_pdfs"
  2222. title="PDFs for WB Normalized LSF Stage-2 Index Decoding">
  2223. <ttcol align="left">Codebook</ttcol>
  2224. <ttcol align="left">PDF</ttcol>
  2225. <c>i</c> <c>{1, 1, 1, 9, 232, 9, 1, 1, 1}/256</c>
  2226. <c>j</c> <c>{1, 1, 2, 28, 186, 35, 1, 1, 1}/256</c>
  2227. <c>k</c> <c>{1, 1, 3, 42, 152, 53, 2, 1, 1}/256</c>
  2228. <c>l</c> <c>{1, 1, 10, 49, 126, 65, 2, 1, 1}/256</c>
  2229. <c>m</c> <c>{1, 4, 19, 48, 100, 77, 5, 1, 1}/256</c>
  2230. <c>n</c> <c>{1, 1, 14, 54, 100, 72, 12, 1, 1}/256</c>
  2231. <c>o</c> <c>{1, 1, 15, 61, 87, 61, 25, 4, 1}/256</c>
  2232. <c>p</c> <c>{1, 7, 21, 50, 77, 81, 17, 1, 1}/256</c>
  2233. </texttable>
  2234. <texttable anchor="silk_nlsf_nbmb_stage2_cb_sel"
  2235. title="Codebook Selection for NB/MB Normalized LSF Stage-2 Index Decoding">
  2236. <ttcol>I1</ttcol>
  2237. <ttcol>Coefficient</ttcol>
  2238. <c/>
  2239. <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>
  2240. <c> 0</c>
  2241. <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>
  2242. <c> 1</c>
  2243. <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>
  2244. <c> 2</c>
  2245. <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>
  2246. <c> 3</c>
  2247. <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>
  2248. <c> 4</c>
  2249. <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>
  2250. <c> 5</c>
  2251. <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>
  2252. <c> g</c>
  2253. <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>
  2254. <c> 7</c>
  2255. <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>
  2256. <c> 8</c>
  2257. <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>
  2258. <c> 9</c>
  2259. <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>
  2260. <c>10</c>
  2261. <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>
  2262. <c>11</c>
  2263. <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>
  2264. <c>12</c>
  2265. <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>
  2266. <c>13</c>
  2267. <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>
  2268. <c>14</c>
  2269. <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>
  2270. <c>15</c>
  2271. <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>
  2272. <c>16</c>
  2273. <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>
  2274. <c>17</c>
  2275. <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>
  2276. <c>18</c>
  2277. <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>
  2278. <c>19</c>
  2279. <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>
  2280. <c>20</c>
  2281. <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>
  2282. <c>21</c>
  2283. <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>
  2284. <c>22</c>
  2285. <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>
  2286. <c>23</c>
  2287. <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>
  2288. <c>24</c>
  2289. <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>
  2290. <c>25</c>
  2291. <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>
  2292. <c>26</c>
  2293. <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>
  2294. <c>27</c>
  2295. <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>
  2296. <c>28</c>
  2297. <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>
  2298. <c>29</c>
  2299. <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>
  2300. <c>30</c>
  2301. <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>
  2302. <c>31</c>
  2303. <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>
  2304. </texttable>
  2305. <texttable anchor="silk_nlsf_wb_stage2_cb_sel"
  2306. title="Codebook Selection for WB Normalized LSF Stage-2 Index Decoding">
  2307. <ttcol>I1</ttcol>
  2308. <ttcol>Coefficient</ttcol>
  2309. <c/>
  2310. <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>
  2311. <c> 0</c>
  2312. <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>
  2313. <c> 1</c>
  2314. <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>
  2315. <c> 2</c>
  2316. <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>
  2317. <c> 3</c>
  2318. <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>
  2319. <c> 4</c>
  2320. <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>
  2321. <c> 5</c>
  2322. <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>
  2323. <c> 6</c>
  2324. <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>
  2325. <c> 7</c>
  2326. <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>
  2327. <c> 8</c>
  2328. <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>
  2329. <c> 9</c>
  2330. <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>
  2331. <c>10</c>
  2332. <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>
  2333. <c>11</c>
  2334. <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>
  2335. <c>12</c>
  2336. <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>
  2337. <c>13</c>
  2338. <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>
  2339. <c>14</c>
  2340. <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>
  2341. <c>15</c>
  2342. <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>
  2343. <c>16</c>
  2344. <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>
  2345. <c>17</c>
  2346. <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>
  2347. <c>18</c>
  2348. <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>
  2349. <c>19</c>
  2350. <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>
  2351. <c>20</c>
  2352. <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>
  2353. <c>21</c>
  2354. <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>
  2355. <c>22</c>
  2356. <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>
  2357. <c>23</c>
  2358. <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>
  2359. <c>24</c>
  2360. <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>
  2361. <c>25</c>
  2362. <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>
  2363. <c>26</c>
  2364. <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>
  2365. <c>27</c>
  2366. <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>
  2367. <c>28</c>
  2368. <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>
  2369. <c>29</c>
  2370. <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>
  2371. <c>30</c>
  2372. <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>
  2373. <c>31</c>
  2374. <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>
  2375. </texttable>
  2376. <t>
  2377. Decoding the second stage residual proceeds as follows.
  2378. For each coefficient, the decoder reads a symbol using the PDF corresponding to
  2379. I1 from either <xref target="silk_nlsf_nbmb_stage2_cb_sel"/> or
  2380. <xref target="silk_nlsf_wb_stage2_cb_sel"/>, and subtracts 4 from the result
  2381. to give an index in the range -4 to 4, inclusive.
  2382. If the index is either -4 or 4, it reads a second symbol using the PDF in
  2383. <xref target="silk_nlsf_ext_pdf"/>, and adds the value of this second symbol
  2384. to the index, using the same sign.
  2385. This gives the index, I2[k], a total range of -10 to 10, inclusive.
  2386. </t>
  2387. <texttable anchor="silk_nlsf_ext_pdf"
  2388. title="PDF for Normalized LSF Index Extension Decoding">
  2389. <ttcol align="left">PDF</ttcol>
  2390. <c>{156, 60, 24, 9, 4, 2, 1}/256</c>
  2391. </texttable>
  2392. <t>
  2393. The decoded indices from both stages are translated back into normalized LSF
  2394. coefficients in silk_NLSF_decode() (NLSF_decode.c).
  2395. The stage-2 indices represent residuals after both the first stage of the VQ
  2396. and a separate backwards-prediction step.
  2397. The backwards prediction process in the encoder subtracts a prediction from
  2398. each residual formed by a multiple of the coefficient that follows it.
  2399. The decoder must undo this process.
  2400. <xref target="silk_nlsf_pred_weights"/> contains lists of prediction weights
  2401. for each coefficient.
  2402. There are two lists for NB and MB, and another two lists for WB, giving two
  2403. possible prediction weights for each coefficient.
  2404. </t>
  2405. <texttable anchor="silk_nlsf_pred_weights"
  2406. title="Prediction Weights for Normalized LSF Decoding">
  2407. <ttcol align="left">Coefficient</ttcol>
  2408. <ttcol align="right">A</ttcol>
  2409. <ttcol align="right">B</ttcol>
  2410. <ttcol align="right">C</ttcol>
  2411. <ttcol align="right">D</ttcol>
  2412. <c>0</c> <c>179</c> <c>116</c> <c>175</c> <c>68</c>
  2413. <c>1</c> <c>138</c> <c>67</c> <c>148</c> <c>62</c>
  2414. <c>2</c> <c>140</c> <c>82</c> <c>160</c> <c>66</c>
  2415. <c>3</c> <c>148</c> <c>59</c> <c>176</c> <c>60</c>
  2416. <c>4</c> <c>151</c> <c>92</c> <c>178</c> <c>72</c>
  2417. <c>5</c> <c>149</c> <c>72</c> <c>173</c> <c>117</c>
  2418. <c>6</c> <c>153</c> <c>100</c> <c>174</c> <c>85</c>
  2419. <c>7</c> <c>151</c> <c>89</c> <c>164</c> <c>90</c>
  2420. <c>8</c> <c>163</c> <c>92</c> <c>177</c> <c>118</c>
  2421. <c>9</c> <c/> <c/> <c>174</c> <c>136</c>
  2422. <c>10</c> <c/> <c/> <c>196</c> <c>151</c>
  2423. <c>11</c> <c/> <c/> <c>182</c> <c>142</c>
  2424. <c>12</c> <c/> <c/> <c>198</c> <c>160</c>
  2425. <c>13</c> <c/> <c/> <c>192</c> <c>142</c>
  2426. <c>14</c> <c/> <c/> <c>182</c> <c>155</c>
  2427. </texttable>
  2428. <t>
  2429. The prediction is undone using the procedure implemented in
  2430. silk_NLSF_residual_dequant() (NLSF_decode.c), which is as follows.
  2431. Each coefficient selects its prediction weight from one of the two lists based
  2432. on the stage-1 index, I1.
  2433. <xref target="silk_nlsf_nbmb_weight_sel"/> gives the selections for each
  2434. coefficient for NB and MB, and <xref target="silk_nlsf_wb_weight_sel"/> gives
  2435. the selections for WB.
  2436. Let d_LPC be the order of the codebook, i.e., 10 for NB and MB, and 16 for WB,
  2437. and let pred_Q8[k] be the weight for the k'th coefficient selected by this
  2438. process for 0&nbsp;&lt;=&nbsp;k&nbsp;&lt;&nbsp;d_LPC-1.
  2439. Then, the stage-2 residual for each coefficient is computed via
  2440. <figure align="center">
  2441. <artwork align="center"><![CDATA[
  2442. res_Q10[k] = (k+1 < d_LPC ? (res_Q10[k+1]*pred_Q8[k])>>8 : 0)
  2443. + ((((I2[k]<<10) - sign(I2[k])*102)*qstep)>>16) ,
  2444. ]]></artwork>
  2445. </figure>
  2446. where qstep is the Q16 quantization step size, which is 11796 for NB and MB
  2447. and 9830 for WB (representing step sizes of approximately 0.18 and 0.15,
  2448. respectively).
  2449. </t>
  2450. <texttable anchor="silk_nlsf_nbmb_weight_sel"
  2451. title="Prediction Weight Selection for NB/MB Normalized LSF Decoding">
  2452. <ttcol>I1</ttcol>
  2453. <ttcol>Coefficient</ttcol>
  2454. <c/>
  2455. <c><spanx style="vbare">0&nbsp;1&nbsp;2&nbsp;3&nbsp;4&nbsp;5&nbsp;6&nbsp;7&nbsp;8</spanx></c>
  2456. <c> 0</c>
  2457. <c><spanx style="vbare">A&nbsp;B&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A</spanx></c>
  2458. <c> 1</c>
  2459. <c><spanx style="vbare">B&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A</spanx></c>
  2460. <c> 2</c>
  2461. <c><spanx style="vbare">A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A</spanx></c>
  2462. <c> 3</c>
  2463. <c><spanx style="vbare">B&nbsp;B&nbsp;B&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;B&nbsp;A</spanx></c>
  2464. <c> 4</c>
  2465. <c><spanx style="vbare">A&nbsp;B&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A</spanx></c>
  2466. <c> 5</c>
  2467. <c><spanx style="vbare">A&nbsp;B&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A</spanx></c>
  2468. <c> 6</c>
  2469. <c><spanx style="vbare">B&nbsp;A&nbsp;B&nbsp;B&nbsp;A&nbsp;A&nbsp;A&nbsp;B&nbsp;A</spanx></c>
  2470. <c> 7</c>
  2471. <c><spanx style="vbare">A&nbsp;B&nbsp;B&nbsp;A&nbsp;A&nbsp;B&nbsp;B&nbsp;A&nbsp;A</spanx></c>
  2472. <c> 8</c>
  2473. <c><spanx style="vbare">A&nbsp;A&nbsp;B&nbsp;B&nbsp;A&nbsp;B&nbsp;A&nbsp;B&nbsp;B</spanx></c>
  2474. <c> 9</c>
  2475. <c><spanx style="vbare">A&nbsp;A&nbsp;B&nbsp;B&nbsp;A&nbsp;A&nbsp;B&nbsp;B&nbsp;B</spanx></c>
  2476. <c>10</c>
  2477. <c><spanx style="vbare">A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A</spanx></c>
  2478. <c>11</c>
  2479. <c><spanx style="vbare">A&nbsp;B&nbsp;A&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;A</spanx></c>
  2480. <c>12</c>
  2481. <c><spanx style="vbare">A&nbsp;B&nbsp;A&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;A</spanx></c>
  2482. <c>13</c>
  2483. <c><spanx style="vbare">A&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;A</spanx></c>
  2484. <c>14</c>
  2485. <c><spanx style="vbare">B&nbsp;A&nbsp;B&nbsp;B&nbsp;A&nbsp;B&nbsp;B&nbsp;B&nbsp;B</spanx></c>
  2486. <c>15</c>
  2487. <c><spanx style="vbare">A&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;A&nbsp;B&nbsp;A</spanx></c>
  2488. <c>16</c>
  2489. <c><spanx style="vbare">A&nbsp;A&nbsp;B&nbsp;B&nbsp;A&nbsp;B&nbsp;A&nbsp;B&nbsp;A</spanx></c>
  2490. <c>17</c>
  2491. <c><spanx style="vbare">A&nbsp;A&nbsp;B&nbsp;B&nbsp;B&nbsp;A&nbsp;B&nbsp;B&nbsp;B</spanx></c>
  2492. <c>18</c>
  2493. <c><spanx style="vbare">A&nbsp;B&nbsp;B&nbsp;A&nbsp;A&nbsp;B&nbsp;B&nbsp;B&nbsp;A</spanx></c>
  2494. <c>19</c>
  2495. <c><spanx style="vbare">A&nbsp;A&nbsp;A&nbsp;B&nbsp;B&nbsp;B&nbsp;A&nbsp;B&nbsp;A</spanx></c>
  2496. <c>20</c>
  2497. <c><spanx style="vbare">A&nbsp;B&nbsp;B&nbsp;A&nbsp;A&nbsp;B&nbsp;A&nbsp;B&nbsp;A</spanx></c>
  2498. <c>21</c>
  2499. <c><spanx style="vbare">A&nbsp;B&nbsp;B&nbsp;A&nbsp;A&nbsp;A&nbsp;B&nbsp;B&nbsp;A</spanx></c>
  2500. <c>22</c>
  2501. <c><spanx style="vbare">A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;B&nbsp;B&nbsp;B&nbsp;B</spanx></c>
  2502. <c>23</c>
  2503. <c><spanx style="vbare">A&nbsp;A&nbsp;B&nbsp;B&nbsp;A&nbsp;A&nbsp;A&nbsp;B&nbsp;B</spanx></c>
  2504. <c>24</c>
  2505. <c><spanx style="vbare">A&nbsp;A&nbsp;A&nbsp;B&nbsp;A&nbsp;B&nbsp;B&nbsp;B&nbsp;B</spanx></c>
  2506. <c>25</c>
  2507. <c><spanx style="vbare">A&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;B&nbsp;A</spanx></c>
  2508. <c>26</c>
  2509. <c><spanx style="vbare">A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A</spanx></c>
  2510. <c>27</c>
  2511. <c><spanx style="vbare">A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A</spanx></c>
  2512. <c>28</c>
  2513. <c><spanx style="vbare">A&nbsp;A&nbsp;B&nbsp;A&nbsp;B&nbsp;B&nbsp;A&nbsp;B&nbsp;A</spanx></c>
  2514. <c>29</c>
  2515. <c><spanx style="vbare">B&nbsp;A&nbsp;A&nbsp;B&nbsp;A&nbsp;A&nbsp;A&nbsp;A&nbsp;A</spanx></c>
  2516. <c>30</c>
  2517. <c><spanx style="vbare">A&nbsp;A&nbsp;A&nbsp;B&nbsp;B&nbsp;A&nbsp;B&nbsp;A&nbsp;B</spanx></c>
  2518. <c>31</c>
  2519. <c><spanx style="vbare">B&nbsp;A&nbsp;B&nbsp;B&nbsp;A&nbsp;B&nbsp;B&nbsp;B&nbsp;B</spanx></c>
  2520. </texttable>
  2521. <texttable anchor="silk_nlsf_wb_weight_sel"
  2522. title="Prediction Weight Selection for WB Normalized LSF Decoding">
  2523. <ttcol>I1</ttcol>
  2524. <ttcol>Coefficient</ttcol>
  2525. <c/>
  2526. <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>
  2527. <c> 0</c>
  2528. <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>
  2529. <c> 1</c>
  2530. <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>
  2531. <c> 2</c>
  2532. <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>
  2533. <c> 3</c>
  2534. <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>
  2535. <c> 4</c>
  2536. <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>
  2537. <c> 5</c>
  2538. <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>
  2539. <c> 6</c>
  2540. <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>
  2541. <c> 7</c>
  2542. <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>
  2543. <c> 8</c>
  2544. <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>
  2545. <c> 9</c>
  2546. <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>
  2547. <c>10</c>
  2548. <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>
  2549. <c>11</c>
  2550. <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>
  2551. <c>12</c>
  2552. <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>
  2553. <c>13</c>
  2554. <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>
  2555. <c>14</c>
  2556. <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>
  2557. <c>15</c>
  2558. <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>
  2559. <c>16</c>
  2560. <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>
  2561. <c>17</c>
  2562. <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>
  2563. <c>18</c>
  2564. <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>
  2565. <c>19</c>
  2566. <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>
  2567. <c>20</c>
  2568. <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>
  2569. <c>21</c>
  2570. <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>
  2571. <c>22</c>
  2572. <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>
  2573. <c>23</c>
  2574. <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>
  2575. <c>24</c>
  2576. <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>
  2577. <c>25</c>
  2578. <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>
  2579. <c>26</c>
  2580. <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>
  2581. <c>27</c>
  2582. <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>
  2583. <c>28</c>
  2584. <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>
  2585. <c>29</c>
  2586. <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>
  2587. <c>30</c>
  2588. <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>
  2589. <c>31</c>
  2590. <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>
  2591. </texttable>
  2592. </section>
  2593. <section anchor="silk_nlsf_reconstruction"
  2594. title="Reconstructing the Normalized LSF Coefficients">
  2595. <t>
  2596. Once the stage-1 index I1 and the stage-2 residual res_Q10[] have been decoded,
  2597. the final normalized LSF coefficients can be reconstructed.
  2598. </t>
  2599. <t>
  2600. The spectral distortion introduced by the quantization of each LSF coefficient
  2601. varies, so the stage-2 residual is weighted accordingly, using the
  2602. low-complexity Inverse Harmonic Mean Weighting (IHMW) function proposed in
  2603. <xref target="laroia-icassp"/>.
  2604. The weights are derived directly from the stage-1 codebook vector.
  2605. Let cb1_Q8[k] be the k'th entry of the stage-1 codebook vector from
  2606. <xref target="silk_nlsf_nbmb_codebook"/> or
  2607. <xref target="silk_nlsf_wb_codebook"/>.
  2608. Then for 0&nbsp;&lt;=&nbsp;k&nbsp;&lt;&nbsp;d_LPC the following expression
  2609. computes the square of the weight as a Q18 value:
  2610. <figure align="center">
  2611. <artwork align="center">
  2612. <![CDATA[
  2613. w2_Q18[k] = (1024/(cb1_Q8[k] - cb1_Q8[k-1])
  2614. + 1024/(cb1_Q8[k+1] - cb1_Q8[k])) << 16 ,
  2615. ]]>
  2616. </artwork>
  2617. </figure>
  2618. where cb1_Q8[-1]&nbsp;=&nbsp;0 and cb1_Q8[d_LPC]&nbsp;=&nbsp;256, and the
  2619. division is integer division.
  2620. This is reduced to an unsquared, Q9 value using the following square-root
  2621. approximation:
  2622. <figure align="center">
  2623. <artwork align="center"><![CDATA[
  2624. i = ilog(w2_Q18[k])
  2625. f = (w2_Q18[k]>>(i-8)) & 127
  2626. y = ((i&1) ? 32768 : 46214) >> ((32-i)>>1)
  2627. w_Q9[k] = y + ((213*f*y)>>16)
  2628. ]]></artwork>
  2629. </figure>
  2630. The constant 46214 here is approximately the square root of 2 in Q15.
  2631. The cb1_Q8[] vector completely determines these weights, and they may be
  2632. tabulated and stored as 13-bit unsigned values (with a range of 1819 to 5227,
  2633. inclusive) to avoid computing them when decoding.
  2634. The reference implementation already requires code to compute these weights on
  2635. unquantized coefficients in the encoder, in silk_NLSF_VQ_weights_laroia()
  2636. (NLSF_VQ_weights_laroia.c) and its callers, so it reuses that code in the
  2637. decoder instead of using a pre-computed table to reduce the amount of ROM
  2638. required.
  2639. </t>
  2640. <texttable anchor="silk_nlsf_nbmb_codebook"
  2641. title="NB/MB Normalized LSF Stage-1 Codebook Vectors">
  2642. <ttcol>I1</ttcol>
  2643. <ttcol>Codebook (Q8)</ttcol>
  2644. <c/>
  2645. <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>
  2646. <c>0</c>
  2647. <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>
  2648. <c>1</c>
  2649. <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>
  2650. <c>2</c>
  2651. <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>
  2652. <c>3</c>
  2653. <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>
  2654. <c>4</c>
  2655. <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>
  2656. <c>5</c>
  2657. <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>
  2658. <c>6</c>
  2659. <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>
  2660. <c>7</c>
  2661. <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>
  2662. <c>8</c>
  2663. <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>
  2664. <c>9</c>
  2665. <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>
  2666. <c>10</c>
  2667. <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>
  2668. <c>11</c>
  2669. <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>
  2670. <c>12</c>
  2671. <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>
  2672. <c>13</c>
  2673. <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>
  2674. <c>14</c>
  2675. <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>
  2676. <c>15</c>
  2677. <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>
  2678. <c>16</c>
  2679. <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>
  2680. <c>17</c>
  2681. <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>
  2682. <c>18</c>
  2683. <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>
  2684. <c>19</c>
  2685. <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>
  2686. <c>20</c>
  2687. <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>
  2688. <c>21</c>
  2689. <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>
  2690. <c>22</c>
  2691. <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>
  2692. <c>23</c>
  2693. <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>
  2694. <c>24</c>
  2695. <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>
  2696. <c>25</c>
  2697. <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>
  2698. <c>26</c>
  2699. <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>
  2700. <c>27</c>
  2701. <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>
  2702. <c>28</c>
  2703. <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>
  2704. <c>29</c>
  2705. <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>
  2706. <c>30</c>
  2707. <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>
  2708. <c>31</c>
  2709. <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>
  2710. </texttable>
  2711. <texttable anchor="silk_nlsf_wb_codebook"
  2712. title="WB Normalized LSF Stage-1 Codebook Vectors">
  2713. <ttcol>I1</ttcol>
  2714. <ttcol>Codebook (Q8)</ttcol>
  2715. <c/>
  2716. <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>
  2717. <c>0</c>
  2718. <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>
  2719. <c>1</c>
  2720. <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>
  2721. <c>2</c>
  2722. <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>
  2723. <c>3</c>
  2724. <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>
  2725. <c>4</c>
  2726. <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>
  2727. <c>5</c>
  2728. <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>
  2729. <c>6</c>
  2730. <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>
  2731. <c>7</c>
  2732. <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>
  2733. <c>8</c>
  2734. <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>
  2735. <c>9</c>
  2736. <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>
  2737. <c>10</c>
  2738. <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>
  2739. <c>11</c>
  2740. <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>
  2741. <c>12</c>
  2742. <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>
  2743. <c>13</c>
  2744. <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>
  2745. <c>14</c>
  2746. <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>
  2747. <c>15</c>
  2748. <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>
  2749. <c>16</c>
  2750. <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>
  2751. <c>17</c>
  2752. <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>
  2753. <c>18</c>
  2754. <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>
  2755. <c>19</c>
  2756. <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>
  2757. <c>20</c>
  2758. <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>
  2759. <c>21</c>
  2760. <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>
  2761. <c>22</c>
  2762. <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>
  2763. <c>23</c>
  2764. <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>
  2765. <c>24</c>
  2766. <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>
  2767. <c>25</c>
  2768. <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>
  2769. <c>26</c>
  2770. <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>
  2771. <c>27</c>
  2772. <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>
  2773. <c>28</c>
  2774. <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>
  2775. <c>29</c>
  2776. <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>
  2777. <c>30</c>
  2778. <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>
  2779. <c>31</c>
  2780. <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>
  2781. </texttable>
  2782. <t>
  2783. Given the stage-1 codebook entry cb1_Q8[], the stage-2 residual res_Q10[], and
  2784. their corresponding weights, w_Q9[], the reconstructed normalized LSF
  2785. coefficients are
  2786. <figure align="center">
  2787. <artwork align="center"><![CDATA[
  2788. NLSF_Q15[k] = clamp(0,
  2789. (cb1_Q8[k]<<7) + (res_Q10[k]<<14)/w_Q9[k], 32767) ,
  2790. ]]></artwork>
  2791. </figure>
  2792. where the division is integer division.
  2793. However, nothing in either the reconstruction process or the
  2794. quantization process in the encoder thus far guarantees that the coefficients
  2795. are monotonically increasing and separated well enough to ensure a stable
  2796. filter <xref target="Kabal86"/>.
  2797. When using the reference encoder, roughly 2% of frames violate this constraint.
  2798. The next section describes a stabilization procedure used to make these
  2799. guarantees.
  2800. </t>
  2801. </section>
  2802. <section anchor="silk_nlsf_stabilization" title="Normalized LSF Stabilization">
  2803. <t>
  2804. The normalized LSF stabilization procedure is implemented in
  2805. silk_NLSF_stabilize() (NLSF_stabilize.c).
  2806. This process ensures that consecutive values of the normalized LSF
  2807. coefficients, NLSF_Q15[], are spaced some minimum distance apart
  2808. (predetermined to be the 0.01 percentile of a large training set).
  2809. <xref target="silk_nlsf_min_spacing"/> gives the minimum spacings for NB and MB
  2810. and those for WB, where row k is the minimum allowed value of
  2811. NLSF_Q[k]-NLSF_Q[k-1].
  2812. For the purposes of computing this spacing for the first and last coefficient,
  2813. NLSF_Q15[-1] is taken to be 0, and NLSF_Q15[d_LPC] is taken to be 32768.
  2814. </t>
  2815. <texttable anchor="silk_nlsf_min_spacing"
  2816. title="Minimum Spacing for Normalized LSF Coefficients">
  2817. <ttcol>Coefficient</ttcol>
  2818. <ttcol align="right">NB and MB</ttcol>
  2819. <ttcol align="right">WB</ttcol>
  2820. <c>0</c> <c>250</c> <c>100</c>
  2821. <c>1</c> <c>3</c> <c>3</c>
  2822. <c>2</c> <c>6</c> <c>40</c>
  2823. <c>3</c> <c>3</c> <c>3</c>
  2824. <c>4</c> <c>3</c> <c>3</c>
  2825. <c>5</c> <c>3</c> <c>3</c>
  2826. <c>6</c> <c>4</c> <c>5</c>
  2827. <c>7</c> <c>3</c> <c>14</c>
  2828. <c>8</c> <c>3</c> <c>14</c>
  2829. <c>9</c> <c>3</c> <c>10</c>
  2830. <c>10</c> <c>461</c> <c>11</c>
  2831. <c>11</c> <c/> <c>3</c>
  2832. <c>12</c> <c/> <c>8</c>
  2833. <c>13</c> <c/> <c>9</c>
  2834. <c>14</c> <c/> <c>7</c>
  2835. <c>15</c> <c/> <c>3</c>
  2836. <c>16</c> <c/> <c>347</c>
  2837. </texttable>
  2838. <t>
  2839. The procedure starts off by trying to make small adjustments which attempt to
  2840. minimize the amount of distortion introduced.
  2841. After 20 such adjustments, it falls back to a more direct method which
  2842. guarantees the constraints are enforced but may require large adjustments.
  2843. </t>
  2844. <t>
  2845. Let NDeltaMin_Q15[k] be the minimum required spacing for the current audio
  2846. bandwidth from <xref target="silk_nlsf_min_spacing"/>.
  2847. First, the procedure finds the index i where
  2848. NLSF_Q15[i]&nbsp;-&nbsp;NLSF_Q15[i-1]&nbsp;-&nbsp;NDeltaMin_Q15[i] is the
  2849. smallest, breaking ties by using the lower value of i.
  2850. If this value is non-negative, then the stabilization stops; the coefficients
  2851. satisfy all the constraints.
  2852. Otherwise, if i&nbsp;==&nbsp;0, it sets NLSF_Q15[0] to NDeltaMin_Q15[0], and if
  2853. i&nbsp;==&nbsp;d_LPC, it sets NLSF_Q15[d_LPC-1] to
  2854. (32768&nbsp;-&nbsp;NDeltaMin_Q15[d_LPC]).
  2855. For all other values of i, both NLSF_Q15[i-1] and NLSF_Q15[i] are updated as
  2856. follows:
  2857. <figure align="center">
  2858. <artwork align="center"><![CDATA[
  2859. i-1
  2860. __
  2861. min_center_Q15 = (NDeltaMin_Q15[i]>>1) + \ NDeltaMin_Q15[k]
  2862. /_
  2863. k=0
  2864. d_LPC
  2865. __
  2866. max_center_Q15 = 32768 - (NDeltaMin_Q15[i]>>1) - \ NDeltaMin_Q15[k]
  2867. /_
  2868. k=i+1
  2869. center_freq_Q15 = clamp(min_center_Q15[i],
  2870. (NLSF_Q15[i-1] + NLSF_Q15[i] + 1)>>1,
  2871. max_center_Q15[i])
  2872. NLSF_Q15[i-1] = center_freq_Q15 - (NDeltaMin_Q15[i]>>1)
  2873. NLSF_Q15[i] = NLSF_Q15[i-1] + NDeltaMin_Q15[i] .
  2874. ]]></artwork>
  2875. </figure>
  2876. Then the procedure repeats again, until it has either executed 20 times or
  2877. has stopped because the coefficients satisfy all the constraints.
  2878. </t>
  2879. <t>
  2880. After the 20th repetition of the above procedure, the following fallback
  2881. procedure executes once.
  2882. First, the values of NLSF_Q15[k] for 0&nbsp;&lt;=&nbsp;k&nbsp;&lt;&nbsp;d_LPC
  2883. are sorted in ascending order.
  2884. Then for each value of k from 0 to d_LPC-1, NLSF_Q15[k] is set to
  2885. <figure align="center">
  2886. <artwork align="center"><![CDATA[
  2887. max(NLSF_Q15[k], NLSF_Q15[k-1] + NDeltaMin_Q15[k]) .
  2888. ]]></artwork>
  2889. </figure>
  2890. Next, for each value of k from d_LPC-1 down to 0, NLSF_Q15[k] is set to
  2891. <figure align="center">
  2892. <artwork align="center"><![CDATA[
  2893. min(NLSF_Q15[k], NLSF_Q15[k+1] - NDeltaMin_Q15[k+1]) .
  2894. ]]></artwork>
  2895. </figure>
  2896. </t>
  2897. </section>
  2898. <section anchor="silk_nlsf_interpolation" title="Normalized LSF Interpolation">
  2899. <t>
  2900. For 20&nbsp;ms SILK frames, the first half of the frame (i.e., the first two
  2901. subframes) may use normalized LSF coefficients that are interpolated between
  2902. the decoded LSFs for the most recent coded frame (in the same channel) and the
  2903. current frame.
  2904. A Q2 interpolation factor follows the LSF coefficient indices in the bitstream,
  2905. which is decoded using the PDF in <xref target="silk_nlsf_interp_pdf"/>.
  2906. This happens in silk_decode_indices() (decode_indices.c).
  2907. After either
  2908. <list style="symbols">
  2909. <t>An uncoded regular SILK frame in the side channel, or</t>
  2910. <t>A decoder reset (see <xref target="decoder-reset"/>),</t>
  2911. </list>
  2912. the decoder still decodes this factor, but ignores its value and always uses
  2913. 4 instead.
  2914. For 10&nbsp;ms SILK frames, this factor is not stored at all.
  2915. </t>
  2916. <texttable anchor="silk_nlsf_interp_pdf"
  2917. title="PDF for Normalized LSF Interpolation Index">
  2918. <ttcol>PDF</ttcol>
  2919. <c>{13, 22, 29, 11, 181}/256</c>
  2920. </texttable>
  2921. <t>
  2922. Let n2_Q15[k] be the normalized LSF coefficients decoded by the procedure in
  2923. <xref target="silk_nlsfs"/>, n0_Q15[k] be the LSF coefficients
  2924. decoded for the prior frame, and w_Q2 be the interpolation factor.
  2925. Then the normalized LSF coefficients used for the first half of a 20&nbsp;ms
  2926. frame, n1_Q15[k], are
  2927. <figure align="center">
  2928. <artwork align="center"><![CDATA[
  2929. n1_Q15[k] = n0_Q15[k] + (w_Q2*(n2_Q15[k] - n0_Q15[k]) >> 2) .
  2930. ]]></artwork>
  2931. </figure>
  2932. This interpolation is performed in silk_decode_parameters()
  2933. (decode_parameters.c).
  2934. </t>
  2935. </section>
  2936. <section anchor="silk_nlsf2lpc"
  2937. title="Converting Normalized LSFs to LPC Coefficients">
  2938. <t>
  2939. Any LPC filter A(z) can be split into a symmetric part P(z) and an
  2940. anti-symmetric part Q(z) such that
  2941. <figure align="center">
  2942. <artwork align="center"><![CDATA[
  2943. d_LPC
  2944. __ -k 1
  2945. A(z) = 1 - \ a[k] * z = - * (P(z) + Q(z))
  2946. /_ 2
  2947. k=1
  2948. ]]></artwork>
  2949. </figure>
  2950. with
  2951. <figure align="center">
  2952. <artwork align="center"><![CDATA[
  2953. -d_LPC-1 -1
  2954. P(z) = A(z) + z * A(z )
  2955. -d_LPC-1 -1
  2956. Q(z) = A(z) - z * A(z ) .
  2957. ]]></artwork>
  2958. </figure>
  2959. The even normalized LSF coefficients correspond to a pair of conjugate roots of
  2960. P(z), while the odd coefficients correspond to a pair of conjugate roots of
  2961. Q(z), all of which lie on the unit circle.
  2962. In addition, P(z) has a root at pi and Q(z) has a root at 0.
  2963. Thus, they may be reconstructed mathematically from a set of normalized LSF
  2964. coefficients, n[k], as
  2965. <figure align="center">
  2966. <artwork align="center"><![CDATA[
  2967. d_LPC/2-1
  2968. -1 ___ -1 -2
  2969. P(z) = (1 + z ) * | | (1 - 2*cos(pi*n[2*k])*z + z )
  2970. k=0
  2971. d_LPC/2-1
  2972. -1 ___ -1 -2
  2973. Q(z) = (1 - z ) * | | (1 - 2*cos(pi*n[2*k+1])*z + z )
  2974. k=0
  2975. ]]></artwork>
  2976. </figure>
  2977. </t>
  2978. <t>
  2979. However, SILK performs this reconstruction using a fixed-point approximation so
  2980. that all decoders can reproduce it in a bit-exact manner to avoid prediction
  2981. drift.
  2982. The function silk_NLSF2A() (NLSF2A.c) implements this procedure.
  2983. </t>
  2984. <t>
  2985. To start, it approximates cos(pi*n[k]) using a table lookup with linear
  2986. interpolation.
  2987. The encoder SHOULD use the inverse of this piecewise linear approximation,
  2988. rather than the true inverse of the cosine function, when deriving the
  2989. normalized LSF coefficients.
  2990. These values are also re-ordered to improve numerical accuracy when
  2991. constructing the LPC polynomials.
  2992. </t>
  2993. <texttable anchor="silk_nlsf_orderings"
  2994. title="LSF Ordering for Polynomial Evaluation">
  2995. <ttcol>Coefficient</ttcol>
  2996. <ttcol align="right">NB and MB</ttcol>
  2997. <ttcol align="right">WB</ttcol>
  2998. <c>0</c> <c>0</c> <c>0</c>
  2999. <c>1</c> <c>9</c> <c>15</c>
  3000. <c>2</c> <c>6</c> <c>8</c>
  3001. <c>3</c> <c>3</c> <c>7</c>
  3002. <c>4</c> <c>4</c> <c>4</c>
  3003. <c>5</c> <c>5</c> <c>11</c>
  3004. <c>6</c> <c>8</c> <c>12</c>
  3005. <c>7</c> <c>1</c> <c>3</c>
  3006. <c>8</c> <c>2</c> <c>2</c>
  3007. <c>9</c> <c>7</c> <c>13</c>
  3008. <c>10</c> <c/> <c>10</c>
  3009. <c>11</c> <c/> <c>5</c>
  3010. <c>12</c> <c/> <c>6</c>
  3011. <c>13</c> <c/> <c>9</c>
  3012. <c>14</c> <c/> <c>14</c>
  3013. <c>15</c> <c/> <c>1</c>
  3014. </texttable>
  3015. <t>
  3016. The top 7 bits of each normalized LSF coefficient index a value in the table,
  3017. and the next 8 bits interpolate between it and the next value.
  3018. Let i&nbsp;=&nbsp;(n[k]&nbsp;&gt;&gt;&nbsp;8) be the integer index and
  3019. f&nbsp;=&nbsp;(n[k]&nbsp;&amp;&nbsp;255) be the fractional part of a given
  3020. coefficient.
  3021. Then the re-ordered, approximated cosine, c_Q17[ordering[k]], is
  3022. <figure align="center">
  3023. <artwork align="center"><![CDATA[
  3024. c_Q17[ordering[k]] = (cos_Q12[i]*256
  3025. + (cos_Q12[i+1]-cos_Q12[i])*f + 4) >> 3 ,
  3026. ]]></artwork>
  3027. </figure>
  3028. where ordering[k] is the k'th entry of the column of
  3029. <xref target="silk_nlsf_orderings"/> corresponding to the current audio
  3030. bandwidth and cos_Q12[i] is the i'th entry of <xref target="silk_cos_table"/>.
  3031. </t>
  3032. <texttable anchor="silk_cos_table"
  3033. title="Q12 Cosine Table for LSF Conversion">
  3034. <ttcol align="right">i</ttcol>
  3035. <ttcol align="right">+0</ttcol>
  3036. <ttcol align="right">+1</ttcol>
  3037. <ttcol align="right">+2</ttcol>
  3038. <ttcol align="right">+3</ttcol>
  3039. <c>0</c>
  3040. <c>4096</c> <c>4095</c> <c>4091</c> <c>4085</c>
  3041. <c>4</c>
  3042. <c>4076</c> <c>4065</c> <c>4052</c> <c>4036</c>
  3043. <c>8</c>
  3044. <c>4017</c> <c>3997</c> <c>3973</c> <c>3948</c>
  3045. <c>12</c>
  3046. <c>3920</c> <c>3889</c> <c>3857</c> <c>3822</c>
  3047. <c>16</c>
  3048. <c>3784</c> <c>3745</c> <c>3703</c> <c>3659</c>
  3049. <c>20</c>
  3050. <c>3613</c> <c>3564</c> <c>3513</c> <c>3461</c>
  3051. <c>24</c>
  3052. <c>3406</c> <c>3349</c> <c>3290</c> <c>3229</c>
  3053. <c>28</c>
  3054. <c>3166</c> <c>3102</c> <c>3035</c> <c>2967</c>
  3055. <c>32</c>
  3056. <c>2896</c> <c>2824</c> <c>2751</c> <c>2676</c>
  3057. <c>36</c>
  3058. <c>2599</c> <c>2520</c> <c>2440</c> <c>2359</c>
  3059. <c>40</c>
  3060. <c>2276</c> <c>2191</c> <c>2106</c> <c>2019</c>
  3061. <c>44</c>
  3062. <c>1931</c> <c>1842</c> <c>1751</c> <c>1660</c>
  3063. <c>48</c>
  3064. <c>1568</c> <c>1474</c> <c>1380</c> <c>1285</c>
  3065. <c>52</c>
  3066. <c>1189</c> <c>1093</c> <c>995</c> <c>897</c>
  3067. <c>56</c>
  3068. <c>799</c> <c>700</c> <c>601</c> <c>501</c>
  3069. <c>60</c>
  3070. <c>401</c> <c>301</c> <c>201</c> <c>101</c>
  3071. <c>64</c>
  3072. <c>0</c> <c>-101</c> <c>-201</c> <c>-301</c>
  3073. <c>68</c>
  3074. <c>-401</c> <c>-501</c> <c>-601</c> <c>-700</c>
  3075. <c>72</c>
  3076. <c>-799</c> <c>-897</c> <c>-995</c> <c>-1093</c>
  3077. <c>76</c>
  3078. <c>-1189</c><c>-1285</c><c>-1380</c><c>-1474</c>
  3079. <c>80</c>
  3080. <c>-1568</c><c>-1660</c><c>-1751</c><c>-1842</c>
  3081. <c>84</c>
  3082. <c>-1931</c><c>-2019</c><c>-2106</c><c>-2191</c>
  3083. <c>88</c>
  3084. <c>-2276</c><c>-2359</c><c>-2440</c><c>-2520</c>
  3085. <c>92</c>
  3086. <c>-2599</c><c>-2676</c><c>-2751</c><c>-2824</c>
  3087. <c>96</c>
  3088. <c>-2896</c><c>-2967</c><c>-3035</c><c>-3102</c>
  3089. <c>100</c>
  3090. <c>-3166</c><c>-3229</c><c>-3290</c><c>-3349</c>
  3091. <c>104</c>
  3092. <c>-3406</c><c>-3461</c><c>-3513</c><c>-3564</c>
  3093. <c>108</c>
  3094. <c>-3613</c><c>-3659</c><c>-3703</c><c>-3745</c>
  3095. <c>112</c>
  3096. <c>-3784</c><c>-3822</c><c>-3857</c><c>-3889</c>
  3097. <c>116</c>
  3098. <c>-3920</c><c>-3948</c><c>-3973</c><c>-3997</c>
  3099. <c>120</c>
  3100. <c>-4017</c><c>-4036</c><c>-4052</c><c>-4065</c>
  3101. <c>124</c>
  3102. <c>-4076</c><c>-4085</c><c>-4091</c><c>-4095</c>
  3103. <c>128</c>
  3104. <c>-4096</c> <c/> <c/> <c/>
  3105. </texttable>
  3106. <t>
  3107. Given the list of cosine values, silk_NLSF2A_find_poly() (NLSF2A.c)
  3108. computes the coefficients of P and Q, described here via a simple recurrence.
  3109. Let p_Q16[k][j] and q_Q16[k][j] be the coefficients of the products of the
  3110. first (k+1) root pairs for P and Q, with j indexing the coefficient number.
  3111. Only the first (k+2) coefficients are needed, as the products are symmetric.
  3112. Let p_Q16[0][0]&nbsp;=&nbsp;q_Q16[0][0]&nbsp;=&nbsp;1&lt;&lt;16,
  3113. p_Q16[0][1]&nbsp;=&nbsp;-c_Q17[0], q_Q16[0][1]&nbsp;=&nbsp;-c_Q17[1], and
  3114. d2&nbsp;=&nbsp;d_LPC/2.
  3115. As boundary conditions, assume
  3116. p_Q16[k][j]&nbsp;=&nbsp;q_Q16[k][j]&nbsp;=&nbsp;0 for all
  3117. j&nbsp;&lt;&nbsp;0.
  3118. Also, assume p_Q16[k][k+2]&nbsp;=&nbsp;p_Q16[k][k] and
  3119. q_Q16[k][k+2]&nbsp;=&nbsp;q_Q16[k][k] (because of the symmetry).
  3120. Then, for 0&nbsp;&lt;&nbsp;k&nbsp;&lt;&nbsp;d2 and 0&nbsp;&lt;=&nbsp;j&nbsp;&lt;=&nbsp;k+1,
  3121. <figure align="center">
  3122. <artwork align="center"><![CDATA[
  3123. p_Q16[k][j] = p_Q16[k-1][j] + p_Q16[k-1][j-2]
  3124. - ((c_Q17[2*k]*p_Q16[k-1][j-1] + 32768)>>16) ,
  3125. q_Q16[k][j] = q_Q16[k-1][j] + q_Q16[k-1][j-2]
  3126. - ((c_Q17[2*k+1]*q_Q16[k-1][j-1] + 32768)>>16) .
  3127. ]]></artwork>
  3128. </figure>
  3129. The use of Q17 values for the cosine terms in an otherwise Q16 expression
  3130. implicitly scales them by a factor of 2.
  3131. The multiplications in this recurrence may require up to 48 bits of precision
  3132. in the result to avoid overflow.
  3133. In practice, each row of the recurrence only depends on the previous row, so an
  3134. implementation does not need to store all of them.
  3135. </t>
  3136. <t>
  3137. silk_NLSF2A() uses the values from the last row of this recurrence to
  3138. reconstruct a 32-bit version of the LPC filter (without the leading 1.0
  3139. coefficient), a32_Q17[k], 0&nbsp;&lt;=&nbsp;k&nbsp;&lt;&nbsp;d2:
  3140. <figure align="center">
  3141. <artwork align="center"><![CDATA[
  3142. a32_Q17[k] = -(q_Q16[d2-1][k+1] - q_Q16[d2-1][k])
  3143. - (p_Q16[d2-1][k+1] + p_Q16[d2-1][k])) ,
  3144. a32_Q17[d_LPC-k-1] = (q_Q16[d2-1][k+1] - q_Q16[d2-1][k])
  3145. - (p_Q16[d2-1][k+1] + p_Q16[d2-1][k])) .
  3146. ]]></artwork>
  3147. </figure>
  3148. The sum and difference of two terms from each of the p_Q16 and q_Q16
  3149. coefficient lists reflect the (1&nbsp;+&nbsp;z**-1) and
  3150. (1&nbsp;-&nbsp;z**-1) factors of P and Q, respectively.
  3151. The promotion of the expression from Q16 to Q17 implicitly scales the result
  3152. by 1/2.
  3153. </t>
  3154. </section>
  3155. <section anchor="silk_lpc_range_limit"
  3156. title="Limiting the Range of the LPC Coefficients">
  3157. <t>
  3158. The a32_Q17[] coefficients are too large to fit in a 16-bit value, which
  3159. significantly increases the cost of applying this filter in fixed-point
  3160. decoders.
  3161. Reducing them to Q12 precision doesn't incur any significant quality loss,
  3162. but still does not guarantee they will fit.
  3163. silk_NLSF2A() applies up to 10 rounds of bandwidth expansion to limit
  3164. the dynamic range of these coefficients.
  3165. Even floating-point decoders SHOULD perform these steps, to avoid mismatch.
  3166. </t>
  3167. <t>
  3168. For each round, the process first finds the index k such that abs(a32_Q17[k])
  3169. is largest, breaking ties by choosing the lowest value of k.
  3170. Then, it computes the corresponding Q12 precision value, maxabs_Q12, subject to
  3171. an upper bound to avoid overflow in subsequent computations:
  3172. <figure align="center">
  3173. <artwork align="center"><![CDATA[
  3174. maxabs_Q12 = min((maxabs_Q17 + 16) >> 5, 163838) .
  3175. ]]></artwork>
  3176. </figure>
  3177. If this is larger than 32767, the procedure derives the chirp factor,
  3178. sc_Q16[0], to use in the bandwidth expansion as
  3179. <figure align="center">
  3180. <artwork align="center"><![CDATA[
  3181. (maxabs_Q12 - 32767) << 14
  3182. sc_Q16[0] = 65470 - -------------------------- ,
  3183. (maxabs_Q12 * (k+1)) >> 2
  3184. ]]></artwork>
  3185. </figure>
  3186. where the division here is integer division.
  3187. This is an approximation of the chirp factor needed to reduce the target
  3188. coefficient to 32767, though it is both less than 0.999 and, for
  3189. k&nbsp;&gt;&nbsp;0 when maxabs_Q12 is much greater than 32767, still slightly
  3190. too large.
  3191. The upper bound on maxabs_Q12, 163838, was chosen because it is equal to
  3192. ((2**31&nbsp;-&nbsp;1)&nbsp;&gt;&gt;&nbsp;14)&nbsp;+&nbsp;32767, i.e., the
  3193. largest value of maxabs_Q12 that would not overflow the numerator in the
  3194. equation above when stored in a signed 32-bit integer.
  3195. </t>
  3196. <t>
  3197. silk_bwexpander_32() (bwexpander_32.c) performs the bandwidth expansion (again,
  3198. only when maxabs_Q12 is greater than 32767) using the following recurrence:
  3199. <figure align="center">
  3200. <artwork align="center"><![CDATA[
  3201. a32_Q17[k] = (a32_Q17[k]*sc_Q16[k]) >> 16
  3202. sc_Q16[k+1] = (sc_Q16[0]*sc_Q16[k] + 32768) >> 16
  3203. ]]></artwork>
  3204. </figure>
  3205. The first multiply may require up to 48 bits of precision in the result to
  3206. avoid overflow.
  3207. The second multiply must be unsigned to avoid overflow with only 32 bits of
  3208. precision.
  3209. The reference implementation uses a slightly more complex formulation that
  3210. avoids the 32-bit overflow using signed multiplication, but is otherwise
  3211. equivalent.
  3212. </t>
  3213. <t>
  3214. After 10 rounds of bandwidth expansion are performed, they are simply saturated
  3215. to 16 bits:
  3216. <figure align="center">
  3217. <artwork align="center"><![CDATA[
  3218. a32_Q17[k] = clamp(-32768, (a32_Q17[k] + 16) >> 5, 32767) << 5 .
  3219. ]]></artwork>
  3220. </figure>
  3221. Because this performs the actual saturation in the Q12 domain, but converts the
  3222. coefficients back to the Q17 domain for the purposes of prediction gain
  3223. limiting, this step must be performed after the 10th round of bandwidth
  3224. expansion, regardless of whether or not the Q12 version of any coefficient
  3225. still overflows a 16-bit integer.
  3226. This saturation is not performed if maxabs_Q12 drops to 32767 or less prior to
  3227. the 10th round.
  3228. </t>
  3229. </section>
  3230. <section anchor="silk_lpc_gain_limit"
  3231. title="Limiting the Prediction Gain of the LPC Filter">
  3232. <t>
  3233. The prediction gain of an LPC synthesis filter is the square-root of the output
  3234. energy when the filter is excited by a unit-energy impulse.
  3235. Even if the Q12 coefficients would fit, the resulting filter may still have a
  3236. significant gain (especially for voiced sounds), making the filter unstable.
  3237. silk_NLSF2A() applies up to 18 additional rounds of bandwidth expansion to
  3238. limit the prediction gain.
  3239. Instead of controlling the amount of bandwidth expansion using the prediction
  3240. gain itself (which may diverge to infinity for an unstable filter),
  3241. silk_NLSF2A() uses silk_LPC_inverse_pred_gain_QA() (LPC_inv_pred_gain.c) to
  3242. compute the reflection coefficients associated with the filter.
  3243. The filter is stable if and only if the magnitude of these coefficients is
  3244. sufficiently less than one.
  3245. The reflection coefficients, rc[k], can be computed using a simple Levinson
  3246. recurrence, initialized with the LPC coefficients
  3247. a[d_LPC-1][n]&nbsp;=&nbsp;a[n], and then updated via
  3248. <figure align="center">
  3249. <artwork align="center"><![CDATA[
  3250. rc[k] = -a[k][k] ,
  3251. a[k][n] - a[k][k-n-1]*rc[k]
  3252. a[k-1][n] = --------------------------- .
  3253. 2
  3254. 1 - rc[k]
  3255. ]]></artwork>
  3256. </figure>
  3257. </t>
  3258. <t>
  3259. However, silk_LPC_inverse_pred_gain_QA() approximates this using fixed-point
  3260. arithmetic to guarantee reproducible results across platforms and
  3261. implementations.
  3262. Since small changes in the coefficients can make a stable filter unstable, it
  3263. takes the real Q12 coefficients that will be used during reconstruction as
  3264. input.
  3265. Thus, let
  3266. <figure align="center">
  3267. <artwork align="center"><![CDATA[
  3268. a32_Q12[n] = (a32_Q17[n] + 16) >> 5
  3269. ]]></artwork>
  3270. </figure>
  3271. be the Q12 version of the LPC coefficients that will eventually be used.
  3272. As a simple initial check, the decoder computes the DC response as
  3273. <figure align="center">
  3274. <artwork align="center"><![CDATA[
  3275. d_PLC-1
  3276. __
  3277. DC_resp = \ a32_Q12[n]
  3278. /_
  3279. n=0
  3280. ]]></artwork>
  3281. </figure>
  3282. and if DC_resp&nbsp;&gt;&nbsp;4096, the filter is unstable.
  3283. </t>
  3284. <t>
  3285. Increasing the precision of these Q12 coefficients to Q24 for intermediate
  3286. computations allows more accurate computation of the reflection coefficients,
  3287. so the decoder initializes the recurrence via
  3288. <figure align="center">
  3289. <artwork align="center"><![CDATA[
  3290. a32_Q24[d_LPC-1][n] = a32_Q12[n] << 12 .
  3291. ]]></artwork>
  3292. </figure>
  3293. Then for each k from d_LPC-1 down to 0, if
  3294. abs(a32_Q24[k][k])&nbsp;&gt;&nbsp;16773022, the filter is unstable and the
  3295. recurrence stops.
  3296. The constant 16773022 here is approximately 0.99975 in Q24.
  3297. Otherwise, row k-1 of a32_Q24 is computed from row k as
  3298. <figure align="center">
  3299. <artwork align="center"><![CDATA[
  3300. rc_Q31[k] = -a32_Q24[k][k] << 7 ,
  3301. div_Q30[k] = (1<<30) - (rc_Q31[k]*rc_Q31[k] >> 32) ,
  3302. b1[k] = ilog(div_Q30[k]) ,
  3303. b2[k] = b1[k] - 16 ,
  3304. (1<<29) - 1
  3305. inv_Qb2[k] = ----------------------- ,
  3306. div_Q30[k] >> (b2[k]+1)
  3307. err_Q29[k] = (1<<29)
  3308. - ((div_Q30[k]<<(15-b2[k]))*inv_Qb2[k] >> 16) ,
  3309. gain_Qb1[k] = ((inv_Qb2[k] << 16)
  3310. + (err_Q29[k]*inv_Qb2[k] >> 13)) ,
  3311. num_Q24[k-1][n] = a32_Q24[k][n]
  3312. - ((a32_Q24[k][k-n-1]*rc_Q31[k] + (1<<30)) >> 31) ,
  3313. a32_Q24[k-1][n] = (num_Q24[k-1][n]*gain_Qb1[k]
  3314. + (1<<(b1[k]-1))) >> b1[k] ,
  3315. ]]></artwork>
  3316. </figure>
  3317. where 0&nbsp;&lt;=&nbsp;n&nbsp;&lt;&nbsp;k.
  3318. Here, rc_Q30[k] are the reflection coefficients.
  3319. div_Q30[k] is the denominator for each iteration, and gain_Qb1[k] is its
  3320. multiplicative inverse (with b1[k] fractional bits, where b1[k] ranges from
  3321. 20 to 31).
  3322. inv_Qb2[k], which ranges from 16384 to 32767, is a low-precision version of
  3323. that inverse (with b2[k] fractional bits).
  3324. err_Q29[k] is the residual error, ranging from -32763 to 32392, which is used
  3325. to improve the accuracy.
  3326. The values t_Q24[k-1][n] for each n are the numerators for the next row of
  3327. coefficients in the recursion, and a32_Q24[k-1][n] is the final version of
  3328. that row.
  3329. Every multiply in this procedure except the one used to compute gain_Qb1[k]
  3330. requires more than 32 bits of precision, but otherwise all intermediate
  3331. results fit in 32 bits or less.
  3332. In practice, because each row only depends on the next one, an implementation
  3333. does not need to store them all.
  3334. </t>
  3335. <t>
  3336. If abs(a32_Q24[k][k])&nbsp;&lt;=&nbsp;16773022 for
  3337. 0&nbsp;&lt;=&nbsp;k&nbsp;&lt;&nbsp;d_LPC, then the filter is considered stable.
  3338. However, the problem of determining stability is ill-conditioned when the
  3339. filter contains several reflection coefficients whose magnitude is very close
  3340. to one.
  3341. This fixed-point algorithm is not mathematically guaranteed to correctly
  3342. classify filters as stable or unstable in this case, though it does very well
  3343. in practice.
  3344. </t>
  3345. <t>
  3346. On round i, 1&nbsp;&lt;=&nbsp;i&nbsp;&lt;=&nbsp;18, if the filter passes these
  3347. stability checks, then this procedure stops, and the final LPC coefficients to
  3348. use for reconstruction in <xref target="silk_lpc_synthesis"/> are
  3349. <figure align="center">
  3350. <artwork align="center"><![CDATA[
  3351. a_Q12[k] = (a32_Q17[k] + 16) >> 5 .
  3352. ]]></artwork>
  3353. </figure>
  3354. Otherwise, a round of bandwidth expansion is applied using the same procedure
  3355. as in <xref target="silk_lpc_range_limit"/>, with
  3356. <figure align="center">
  3357. <artwork align="center"><![CDATA[
  3358. sc_Q16[0] = 65536 - (2<<i) .
  3359. ]]></artwork>
  3360. </figure>
  3361. During the 15th round, sc_Q16[0] becomes 0 in the above equation, so a_Q12[k]
  3362. is set to 0 for all k, guaranteeing a stable filter.
  3363. </t>
  3364. </section>
  3365. </section>
  3366. <section anchor="silk_ltp_params" toc="include"
  3367. title="Long-Term Prediction (LTP) Parameters">
  3368. <t>
  3369. After the normalized LSF indices and, for 20&nbsp;ms frames, the LSF
  3370. interpolation index, voiced frames (see <xref target="silk_frame_type"/>)
  3371. include additional LTP parameters.
  3372. There is one primary lag index for each SILK frame, but this is refined to
  3373. produce a separate lag index per subframe using a vector quantizer.
  3374. Each subframe also gets its own prediction gain coefficient.
  3375. </t>
  3376. <section anchor="silk_ltp_lags" title="Pitch Lags">
  3377. <t>
  3378. The primary lag index is coded either relative to the primary lag of the prior
  3379. frame in the same channel, or as an absolute index.
  3380. Absolute coding is used if and only if
  3381. <list style="symbols">
  3382. <t>
  3383. This is the first SILK frame of its type (LBRR or regular) for this channel in
  3384. the current Opus frame,
  3385. </t>
  3386. <t>
  3387. The previous SILK frame of the same type (LBRR or regular) for this channel in
  3388. the same Opus frame was not coded, or
  3389. </t>
  3390. <t>
  3391. That previous SILK frame was coded, but was not voiced (see
  3392. <xref target="silk_frame_type"/>).
  3393. </t>
  3394. </list>
  3395. </t>
  3396. <t>
  3397. With absolute coding, the primary pitch lag may range from 2&nbsp;ms
  3398. (inclusive) up to 18&nbsp;ms (exclusive), corresponding to pitches from
  3399. 500&nbsp;Hz down to 55.6&nbsp;Hz, respectively.
  3400. It is comprised of a high part and a low part, where the decoder reads the high
  3401. part using the 32-entry codebook in <xref target="silk_abs_pitch_high_pdf"/>
  3402. and the low part using the codebook corresponding to the current audio
  3403. bandwidth from <xref target="silk_abs_pitch_low_pdf"/>.
  3404. The final primary pitch lag is then
  3405. <figure align="center">
  3406. <artwork align="center"><![CDATA[
  3407. lag = lag_high*lag_scale + lag_low + lag_min
  3408. ]]></artwork>
  3409. </figure>
  3410. where lag_high is the high part, lag_low is the low part, and lag_scale
  3411. and lag_min are the values from the "Scale" and "Minimum Lag" columns of
  3412. <xref target="silk_abs_pitch_low_pdf"/>, respectively.
  3413. </t>
  3414. <texttable anchor="silk_abs_pitch_high_pdf"
  3415. title="PDF for High Part of Primary Pitch Lag">
  3416. <ttcol align="left">PDF</ttcol>
  3417. <c>{3, 3, 6, 11, 21, 30, 32, 19,
  3418. 11, 10, 12, 13, 13, 12, 11, 9,
  3419. 8, 7, 6, 4, 2, 2, 2, 1,
  3420. 1, 1, 1, 1, 1, 1, 1, 1}/256</c>
  3421. </texttable>
  3422. <texttable anchor="silk_abs_pitch_low_pdf"
  3423. title="PDF for Low Part of Primary Pitch Lag">
  3424. <ttcol>Audio Bandwidth</ttcol>
  3425. <ttcol>PDF</ttcol>
  3426. <ttcol>Scale</ttcol>
  3427. <ttcol>Minimum Lag</ttcol>
  3428. <ttcol>Maximum Lag</ttcol>
  3429. <c>NB</c> <c>{64, 64, 64, 64}/256</c> <c>4</c> <c>16</c> <c>144</c>
  3430. <c>MB</c> <c>{43, 42, 43, 43, 42, 43}/256</c> <c>6</c> <c>24</c> <c>216</c>
  3431. <c>WB</c> <c>{32, 32, 32, 32, 32, 32, 32, 32}/256</c> <c>8</c> <c>32</c> <c>288</c>
  3432. </texttable>
  3433. <t>
  3434. All frames that do not use absolute coding for the primary lag index use
  3435. relative coding instead.
  3436. The decoder reads a single delta value using the 21-entry PDF in
  3437. <xref target="silk_rel_pitch_pdf"/>.
  3438. If the resulting value is zero, it falls back to the absolute coding procedure
  3439. from the prior paragraph.
  3440. Otherwise, the final primary pitch lag is then
  3441. <figure align="center">
  3442. <artwork align="center"><![CDATA[
  3443. lag = previous_lag + (delta_lag_index - 9)
  3444. ]]></artwork>
  3445. </figure>
  3446. where previous_lag is the primary pitch lag from the most recent frame in the
  3447. same channel and delta_lag_index is the value just decoded.
  3448. This allows a per-frame change in the pitch lag of -8 to +11 samples.
  3449. The decoder does no clamping at this point, so this value can fall outside the
  3450. range of 2&nbsp;ms to 18&nbsp;ms, and the decoder must use this unclamped
  3451. value when using relative coding in the next SILK frame (if any).
  3452. However, because an Opus frame can use relative coding for at most two
  3453. consecutive SILK frames, integer overflow should not be an issue.
  3454. </t>
  3455. <texttable anchor="silk_rel_pitch_pdf"
  3456. title="PDF for Primary Pitch Lag Change">
  3457. <ttcol align="left">PDF</ttcol>
  3458. <c>{46, 2, 2, 3, 4, 6, 10, 15,
  3459. 26, 38, 30, 22, 15, 10, 7, 6,
  3460. 4, 4, 2, 2, 2}/256</c>
  3461. </texttable>
  3462. <t>
  3463. After the primary pitch lag, a "pitch contour", stored as a single entry from
  3464. one of four small VQ codebooks, gives lag offsets for each subframe in the
  3465. current SILK frame.
  3466. The codebook index is decoded using one of the PDFs in
  3467. <xref target="silk_pitch_contour_pdfs"/> depending on the current frame size
  3468. and audio bandwidth.
  3469. Tables&nbsp;<xref format="counter" target="silk_pitch_contour_cb_nb10ms"/>
  3470. through&nbsp;<xref format="counter" target="silk_pitch_contour_cb_mbwb20ms"/>
  3471. give the corresponding offsets to apply to the primary pitch lag for each
  3472. subframe given the decoded codebook index.
  3473. </t>
  3474. <texttable anchor="silk_pitch_contour_pdfs"
  3475. title="PDFs for Subframe Pitch Contour">
  3476. <ttcol>Audio Bandwidth</ttcol>
  3477. <ttcol>SILK Frame Size</ttcol>
  3478. <ttcol align="right">Codebook Size</ttcol>
  3479. <ttcol>PDF</ttcol>
  3480. <c>NB</c> <c>10&nbsp;ms</c> <c>3</c>
  3481. <c>{143, 50, 63}/256</c>
  3482. <c>NB</c> <c>20&nbsp;ms</c> <c>11</c>
  3483. <c>{68, 12, 21, 17, 19, 22, 30, 24,
  3484. 17, 16, 10}/256</c>
  3485. <c>MB or WB</c> <c>10&nbsp;ms</c> <c>12</c>
  3486. <c>{91, 46, 39, 19, 14, 12, 8, 7,
  3487. 6, 5, 5, 4}/256</c>
  3488. <c>MB or WB</c> <c>20&nbsp;ms</c> <c>34</c>
  3489. <c>{33, 22, 18, 16, 15, 14, 14, 13,
  3490. 13, 10, 9, 9, 8, 6, 6, 6,
  3491. 5, 4, 4, 4, 3, 3, 3, 2,
  3492. 2, 2, 2, 2, 2, 2, 1, 1,
  3493. 1, 1}/256</c>
  3494. </texttable>
  3495. <texttable anchor="silk_pitch_contour_cb_nb10ms"
  3496. title="Codebook Vectors for Subframe Pitch Contour: NB, 10&nbsp;ms Frames">
  3497. <ttcol>Index</ttcol>
  3498. <ttcol align="right">Subframe Offsets</ttcol>
  3499. <c>0</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;0</spanx></c>
  3500. <c>1</c> <c><spanx style="vbare">&nbsp;1&nbsp;&nbsp;0</spanx></c>
  3501. <c>2</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;1</spanx></c>
  3502. </texttable>
  3503. <texttable anchor="silk_pitch_contour_cb_nb20ms"
  3504. title="Codebook Vectors for Subframe Pitch Contour: NB, 20&nbsp;ms Frames">
  3505. <ttcol>Index</ttcol>
  3506. <ttcol align="right">Subframe Offsets</ttcol>
  3507. <c>0</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0</spanx></c>
  3508. <c>1</c> <c><spanx style="vbare">&nbsp;2&nbsp;&nbsp;1&nbsp;&nbsp;0&nbsp;-1</spanx></c>
  3509. <c>2</c> <c><spanx style="vbare">-1&nbsp;&nbsp;0&nbsp;&nbsp;1&nbsp;&nbsp;2</spanx></c>
  3510. <c>3</c> <c><spanx style="vbare">-1&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;1</spanx></c>
  3511. <c>4</c> <c><spanx style="vbare">-1&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0</spanx></c>
  3512. <c>5</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;1</spanx></c>
  3513. <c>6</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;1&nbsp;&nbsp;1</spanx></c>
  3514. <c>7</c> <c><spanx style="vbare">&nbsp;1&nbsp;&nbsp;1&nbsp;&nbsp;0&nbsp;&nbsp;0</spanx></c>
  3515. <c>8</c> <c><spanx style="vbare">&nbsp;1&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0</spanx></c>
  3516. <c>9</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;-1</spanx></c>
  3517. <c>10</c> <c><spanx style="vbare">&nbsp;1&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;-1</spanx></c>
  3518. </texttable>
  3519. <texttable anchor="silk_pitch_contour_cb_mbwb10ms"
  3520. title="Codebook Vectors for Subframe Pitch Contour: MB or WB, 10&nbsp;ms Frames">
  3521. <ttcol>Index</ttcol>
  3522. <ttcol align="right">Subframe Offsets</ttcol>
  3523. <c>0</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;0</spanx></c>
  3524. <c>1</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;1</spanx></c>
  3525. <c>2</c> <c><spanx style="vbare">&nbsp;1&nbsp;&nbsp;0</spanx></c>
  3526. <c>3</c> <c><spanx style="vbare">-1&nbsp;&nbsp;1</spanx></c>
  3527. <c>4</c> <c><spanx style="vbare">&nbsp;1&nbsp;-1</spanx></c>
  3528. <c>5</c> <c><spanx style="vbare">-1&nbsp;&nbsp;2</spanx></c>
  3529. <c>6</c> <c><spanx style="vbare">&nbsp;2&nbsp;-1</spanx></c>
  3530. <c>7</c> <c><spanx style="vbare">-2&nbsp;&nbsp;2</spanx></c>
  3531. <c>8</c> <c><spanx style="vbare">&nbsp;2&nbsp;-2</spanx></c>
  3532. <c>9</c> <c><spanx style="vbare">-2&nbsp;&nbsp;3</spanx></c>
  3533. <c>10</c> <c><spanx style="vbare">&nbsp;3&nbsp;-2</spanx></c>
  3534. <c>11</c> <c><spanx style="vbare">-3&nbsp;&nbsp;3</spanx></c>
  3535. </texttable>
  3536. <texttable anchor="silk_pitch_contour_cb_mbwb20ms"
  3537. title="Codebook Vectors for Subframe Pitch Contour: MB or WB, 20&nbsp;ms Frames">
  3538. <ttcol>Index</ttcol>
  3539. <ttcol align="right">Subframe Offsets</ttcol>
  3540. <c>0</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0</spanx></c>
  3541. <c>1</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;1&nbsp;&nbsp;1</spanx></c>
  3542. <c>2</c> <c><spanx style="vbare">&nbsp;1&nbsp;&nbsp;1&nbsp;&nbsp;0&nbsp;&nbsp;0</spanx></c>
  3543. <c>3</c> <c><spanx style="vbare">-1&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0</spanx></c>
  3544. <c>4</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;1</spanx></c>
  3545. <c>5</c> <c><spanx style="vbare">&nbsp;1&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0</spanx></c>
  3546. <c>6</c> <c><spanx style="vbare">-1&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;1</spanx></c>
  3547. <c>7</c> <c><spanx style="vbare">&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;-1</spanx></c>
  3548. <c>8</c> <c><spanx style="vbare">-1&nbsp;&nbsp;0&nbsp;&nbsp;1&nbsp;&nbsp;2</spanx></c>
  3549. <c>9</c> <c><spanx style="vbare">&nbsp;1&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;-1</spanx></c>
  3550. <c>10</c> <c><spanx style="vbare">-2&nbsp;-1&nbsp;&nbsp;1&nbsp;&nbsp;2</spanx></c>
  3551. <c>11</c> <c><spanx style="vbare">&nbsp;2&nbsp;&nbsp;1&nbsp;&nbsp;0&nbsp;-1</spanx></c>
  3552. <c>12</c> <c><spanx style="vbare">-2&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;2</spanx></c>
  3553. <c>13</c> <c><spanx style="vbare">-2&nbsp;&nbsp;0&nbsp;&nbsp;1&nbsp;&nbsp;3</spanx></c>
  3554. <c>14</c> <c><spanx style="vbare">&nbsp;2&nbsp;&nbsp;1&nbsp;-1&nbsp;-2</spanx></c>
  3555. <c>15</c> <c><spanx style="vbare">-3&nbsp;-1&nbsp;&nbsp;1&nbsp;&nbsp;3</spanx></c>
  3556. <c>16</c> <c><spanx style="vbare">&nbsp;2&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;-2</spanx></c>
  3557. <c>17</c> <c><spanx style="vbare">&nbsp;3&nbsp;&nbsp;1&nbsp;&nbsp;0&nbsp;-2</spanx></c>
  3558. <c>18</c> <c><spanx style="vbare">-3&nbsp;-1&nbsp;&nbsp;2&nbsp;&nbsp;4</spanx></c>
  3559. <c>19</c> <c><spanx style="vbare">-4&nbsp;-1&nbsp;&nbsp;1&nbsp;&nbsp;4</spanx></c>
  3560. <c>20</c> <c><spanx style="vbare">&nbsp;3&nbsp;&nbsp;1&nbsp;-1&nbsp;-3</spanx></c>
  3561. <c>21</c> <c><spanx style="vbare">-4&nbsp;-1&nbsp;&nbsp;2&nbsp;&nbsp;5</spanx></c>
  3562. <c>22</c> <c><spanx style="vbare">&nbsp;4&nbsp;&nbsp;2&nbsp;-1&nbsp;-3</spanx></c>
  3563. <c>23</c> <c><spanx style="vbare">&nbsp;4&nbsp;&nbsp;1&nbsp;-1&nbsp;-4</spanx></c>
  3564. <c>24</c> <c><spanx style="vbare">-5&nbsp;-1&nbsp;&nbsp;2&nbsp;&nbsp;6</spanx></c>
  3565. <c>25</c> <c><spanx style="vbare">&nbsp;5&nbsp;&nbsp;2&nbsp;-1&nbsp;-4</spanx></c>
  3566. <c>26</c> <c><spanx style="vbare">-6&nbsp;-2&nbsp;&nbsp;2&nbsp;&nbsp;6</spanx></c>
  3567. <c>27</c> <c><spanx style="vbare">-5&nbsp;-2&nbsp;&nbsp;2&nbsp;&nbsp;5</spanx></c>
  3568. <c>28</c> <c><spanx style="vbare">&nbsp;6&nbsp;&nbsp;2&nbsp;-1&nbsp;-5</spanx></c>
  3569. <c>29</c> <c><spanx style="vbare">-7&nbsp;-2&nbsp;&nbsp;3&nbsp;&nbsp;8</spanx></c>
  3570. <c>30</c> <c><spanx style="vbare">&nbsp;6&nbsp;&nbsp;2&nbsp;-2&nbsp;-6</spanx></c>
  3571. <c>31</c> <c><spanx style="vbare">&nbsp;5&nbsp;&nbsp;2&nbsp;-2&nbsp;-5</spanx></c>
  3572. <c>32</c> <c><spanx style="vbare">&nbsp;8&nbsp;&nbsp;3&nbsp;-2&nbsp;-7</spanx></c>
  3573. <c>33</c> <c><spanx style="vbare">-9&nbsp;-3&nbsp;&nbsp;3&nbsp;&nbsp;9</spanx></c>
  3574. </texttable>
  3575. <t>
  3576. The final pitch lag for each subframe is assembled in silk_decode_pitch()
  3577. (decode_pitch.c).
  3578. Let lag be the primary pitch lag for the current SILK frame, contour_index be
  3579. index of the VQ codebook, and lag_cb[contour_index][k] be the corresponding
  3580. entry of the codebook from the appropriate table given above for the k'th
  3581. subframe.
  3582. Then the final pitch lag for that subframe is
  3583. <figure align="center">
  3584. <artwork align="center"><![CDATA[
  3585. pitch_lags[k] = clamp(lag_min, lag + lag_cb[contour_index][k],
  3586. lag_max)
  3587. ]]></artwork>
  3588. </figure>
  3589. where lag_min and lag_max are the values from the "Minimum Lag" and
  3590. "Maximum Lag" columns of <xref target="silk_abs_pitch_low_pdf"/>,
  3591. respectively.
  3592. </t>
  3593. </section>
  3594. <section anchor="silk_ltp_filter" title="LTP Filter Coefficients">
  3595. <t>
  3596. SILK uses a separate 5-tap pitch filter for each subframe, selected from one
  3597. of three codebooks.
  3598. The three codebooks each represent different rate-distortion trade-offs, with
  3599. average rates of 1.61&nbsp;bits/subframe, 3.68&nbsp;bits/subframe, and
  3600. 4.85&nbsp;bits/subframe, respectively.
  3601. </t>
  3602. <t>
  3603. The importance of the filter coefficients generally depends on two factors: the
  3604. periodicity of the signal and relative energy between the current subframe and
  3605. the signal from one period earlier.
  3606. Greater periodicity and decaying energy both lead to more important filter
  3607. coefficients, and thus should be coded with lower distortion and higher rate.
  3608. These properties are relatively stable over the duration of a single SILK
  3609. frame, hence all of the subframes in a SILK frame choose their filter from the
  3610. same codebook.
  3611. This is signaled with an explicitly-coded "periodicity index".
  3612. This immediately follows the subframe pitch lags, and is coded using the
  3613. 3-entry PDF from <xref target="silk_perindex_pdf"/>.
  3614. </t>
  3615. <texttable anchor="silk_perindex_pdf" title="Periodicity Index PDF">
  3616. <ttcol>PDF</ttcol>
  3617. <c>{77, 80, 99}/256</c>
  3618. </texttable>
  3619. <t>
  3620. The indices of the filters for each subframe follow.
  3621. They are all coded using the PDF from <xref target="silk_ltp_filter_pdfs"/>
  3622. corresponding to the periodicity index.
  3623. Tables&nbsp;<xref format="counter" target="silk_ltp_filter_coeffs0"/>
  3624. through&nbsp;<xref format="counter" target="silk_ltp_filter_coeffs2"/>
  3625. contain the corresponding filter taps as signed Q7 integers.
  3626. </t>
  3627. <texttable anchor="silk_ltp_filter_pdfs" title="LTP Filter PDFs">
  3628. <ttcol>Periodicity Index</ttcol>
  3629. <ttcol align="right">Codebook Size</ttcol>
  3630. <ttcol>PDF</ttcol>
  3631. <c>0</c> <c>8</c> <c>{185, 15, 13, 13, 9, 9, 6, 6}/256</c>
  3632. <c>1</c> <c>16</c> <c>{57, 34, 21, 20, 15, 13, 12, 13,
  3633. 10, 10, 9, 10, 9, 8, 7, 8}/256</c>
  3634. <c>2</c> <c>32</c> <c>{15, 16, 14, 12, 12, 12, 11, 11,
  3635. 11, 10, 9, 9, 9, 9, 8, 8,
  3636. 8, 8, 7, 7, 6, 6, 5, 4,
  3637. 5, 4, 4, 4, 3, 4, 3, 2}/256</c>
  3638. </texttable>
  3639. <texttable anchor="silk_ltp_filter_coeffs0"
  3640. title="Codebook Vectors for LTP Filter, Periodicity Index 0">
  3641. <ttcol>Index</ttcol>
  3642. <ttcol align="right">Filter Taps (Q7)</ttcol>
  3643. <c>0</c>
  3644. <c><spanx style="vbare">&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;6&nbsp;&nbsp;24&nbsp;&nbsp;&nbsp;7&nbsp;&nbsp;&nbsp;5</spanx></c>
  3645. <c>1</c>
  3646. <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>
  3647. <c>2</c>
  3648. <c><spanx style="vbare">&nbsp;12&nbsp;&nbsp;28&nbsp;&nbsp;41&nbsp;&nbsp;13&nbsp;&nbsp;-4</spanx></c>
  3649. <c>3</c>
  3650. <c><spanx style="vbare">&nbsp;-9&nbsp;&nbsp;15&nbsp;&nbsp;42&nbsp;&nbsp;25&nbsp;&nbsp;14</spanx></c>
  3651. <c>4</c>
  3652. <c><spanx style="vbare">&nbsp;&nbsp;1&nbsp;&nbsp;-2&nbsp;&nbsp;62&nbsp;&nbsp;41&nbsp;&nbsp;-9</spanx></c>
  3653. <c>5</c>
  3654. <c><spanx style="vbare">-10&nbsp;&nbsp;37&nbsp;&nbsp;65&nbsp;&nbsp;-4&nbsp;&nbsp;&nbsp;3</spanx></c>
  3655. <c>6</c>
  3656. <c><spanx style="vbare">&nbsp;-6&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;66&nbsp;&nbsp;&nbsp;7&nbsp;&nbsp;-8</spanx></c>
  3657. <c>7</c>
  3658. <c><spanx style="vbare">&nbsp;16&nbsp;&nbsp;14&nbsp;&nbsp;38&nbsp;&nbsp;-3&nbsp;&nbsp;33</spanx></c>
  3659. </texttable>
  3660. <texttable anchor="silk_ltp_filter_coeffs1"
  3661. title="Codebook Vectors for LTP Filter, Periodicity Index 1">
  3662. <ttcol>Index</ttcol>
  3663. <ttcol align="right">Filter Taps (Q7)</ttcol>
  3664. <c>0</c>
  3665. <c><spanx style="vbare">&nbsp;13&nbsp;&nbsp;22&nbsp;&nbsp;39&nbsp;&nbsp;23&nbsp;&nbsp;12</spanx></c>
  3666. <c>1</c>
  3667. <c><spanx style="vbare">&nbsp;-1&nbsp;&nbsp;36&nbsp;&nbsp;64&nbsp;&nbsp;27&nbsp;&nbsp;-6</spanx></c>
  3668. <c>2</c>
  3669. <c><spanx style="vbare">&nbsp;-7&nbsp;&nbsp;10&nbsp;&nbsp;55&nbsp;&nbsp;43&nbsp;&nbsp;17</spanx></c>
  3670. <c>3</c>
  3671. <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>
  3672. <c>4</c>
  3673. <c><spanx style="vbare">&nbsp;&nbsp;6&nbsp;-11&nbsp;&nbsp;74&nbsp;&nbsp;53&nbsp;&nbsp;-9</spanx></c>
  3674. <c>5</c>
  3675. <c><spanx style="vbare">-12&nbsp;&nbsp;55&nbsp;&nbsp;76&nbsp;-12&nbsp;&nbsp;&nbsp;8</spanx></c>
  3676. <c>6</c>
  3677. <c><spanx style="vbare">&nbsp;-3&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;93&nbsp;&nbsp;27&nbsp;&nbsp;-4</spanx></c>
  3678. <c>7</c>
  3679. <c><spanx style="vbare">&nbsp;26&nbsp;&nbsp;39&nbsp;&nbsp;59&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;-8</spanx></c>
  3680. <c>8</c>
  3681. <c><spanx style="vbare">&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;77&nbsp;&nbsp;11&nbsp;&nbsp;&nbsp;9</spanx></c>
  3682. <c>9</c>
  3683. <c><spanx style="vbare">&nbsp;-8&nbsp;&nbsp;22&nbsp;&nbsp;44&nbsp;&nbsp;-6&nbsp;&nbsp;&nbsp;7</spanx></c>
  3684. <c>10</c>
  3685. <c><spanx style="vbare">&nbsp;40&nbsp;&nbsp;&nbsp;9&nbsp;&nbsp;26&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;9</spanx></c>
  3686. <c>11</c>
  3687. <c><spanx style="vbare">&nbsp;-7&nbsp;&nbsp;20&nbsp;101&nbsp;&nbsp;-7&nbsp;&nbsp;&nbsp;4</spanx></c>
  3688. <c>12</c>
  3689. <c><spanx style="vbare">&nbsp;&nbsp;3&nbsp;&nbsp;-8&nbsp;&nbsp;42&nbsp;&nbsp;26&nbsp;&nbsp;&nbsp;0</spanx></c>
  3690. <c>13</c>
  3691. <c><spanx style="vbare">-15&nbsp;&nbsp;33&nbsp;&nbsp;68&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;23</spanx></c>
  3692. <c>14</c>
  3693. <c><spanx style="vbare">&nbsp;-2&nbsp;&nbsp;55&nbsp;&nbsp;46&nbsp;&nbsp;-2&nbsp;&nbsp;15</spanx></c>
  3694. <c>15</c>
  3695. <c><spanx style="vbare">&nbsp;&nbsp;3&nbsp;&nbsp;-1&nbsp;&nbsp;21&nbsp;&nbsp;16&nbsp;&nbsp;41</spanx></c>
  3696. </texttable>
  3697. <texttable anchor="silk_ltp_filter_coeffs2"
  3698. title="Codebook Vectors for LTP Filter, Periodicity Index 2">
  3699. <ttcol>Index</ttcol>
  3700. <ttcol align="right">Filter Taps (Q7)</ttcol>
  3701. <c>0</c>
  3702. <c><spanx style="vbare">&nbsp;-6&nbsp;&nbsp;27&nbsp;&nbsp;61&nbsp;&nbsp;39&nbsp;&nbsp;&nbsp;5</spanx></c>
  3703. <c>1</c>
  3704. <c><spanx style="vbare">-11&nbsp;&nbsp;42&nbsp;&nbsp;88&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;1</spanx></c>
  3705. <c>2</c>
  3706. <c><spanx style="vbare">&nbsp;-2&nbsp;&nbsp;60&nbsp;&nbsp;65&nbsp;&nbsp;&nbsp;6&nbsp;&nbsp;-4</spanx></c>
  3707. <c>3</c>
  3708. <c><spanx style="vbare">&nbsp;-1&nbsp;&nbsp;-5&nbsp;&nbsp;73&nbsp;&nbsp;56&nbsp;&nbsp;&nbsp;1</spanx></c>
  3709. <c>4</c>
  3710. <c><spanx style="vbare">&nbsp;-9&nbsp;&nbsp;19&nbsp;&nbsp;94&nbsp;&nbsp;29&nbsp;&nbsp;-9</spanx></c>
  3711. <c>5</c>
  3712. <c><spanx style="vbare">&nbsp;&nbsp;0&nbsp;&nbsp;12&nbsp;&nbsp;99&nbsp;&nbsp;&nbsp;6&nbsp;&nbsp;&nbsp;4</spanx></c>
  3713. <c>6</c>
  3714. <c><spanx style="vbare">&nbsp;&nbsp;8&nbsp;-19&nbsp;102&nbsp;&nbsp;46&nbsp;-13</spanx></c>
  3715. <c>7</c>
  3716. <c><spanx style="vbare">&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;13&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;2</spanx></c>
  3717. <c>8</c>
  3718. <c><spanx style="vbare">&nbsp;&nbsp;9&nbsp;-21&nbsp;&nbsp;84&nbsp;&nbsp;72&nbsp;-18</spanx></c>
  3719. <c>9</c>
  3720. <c><spanx style="vbare">-11&nbsp;&nbsp;46&nbsp;104&nbsp;-22&nbsp;&nbsp;&nbsp;8</spanx></c>
  3721. <c>10</c>
  3722. <c><spanx style="vbare">&nbsp;18&nbsp;&nbsp;38&nbsp;&nbsp;48&nbsp;&nbsp;23&nbsp;&nbsp;&nbsp;0</spanx></c>
  3723. <c>11</c>
  3724. <c><spanx style="vbare">-16&nbsp;&nbsp;70&nbsp;&nbsp;83&nbsp;-21&nbsp;&nbsp;11</spanx></c>
  3725. <c>12</c>
  3726. <c><spanx style="vbare">&nbsp;&nbsp;5&nbsp;-11&nbsp;117&nbsp;&nbsp;22&nbsp;&nbsp;-8</spanx></c>
  3727. <c>13</c>
  3728. <c><spanx style="vbare">&nbsp;-6&nbsp;&nbsp;23&nbsp;117&nbsp;-12&nbsp;&nbsp;&nbsp;3</spanx></c>
  3729. <c>14</c>
  3730. <c><spanx style="vbare">&nbsp;&nbsp;3&nbsp;&nbsp;-8&nbsp;&nbsp;95&nbsp;&nbsp;28&nbsp;&nbsp;&nbsp;4</spanx></c>
  3731. <c>15</c>
  3732. <c><spanx style="vbare">-10&nbsp;&nbsp;15&nbsp;&nbsp;77&nbsp;&nbsp;60&nbsp;-15</spanx></c>
  3733. <c>16</c>
  3734. <c><spanx style="vbare">&nbsp;-1&nbsp;&nbsp;&nbsp;4&nbsp;124&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;-4</spanx></c>
  3735. <c>17</c>
  3736. <c><spanx style="vbare">&nbsp;&nbsp;3&nbsp;&nbsp;38&nbsp;&nbsp;84&nbsp;&nbsp;24&nbsp;-25</spanx></c>
  3737. <c>18</c>
  3738. <c><spanx style="vbare">&nbsp;&nbsp;2&nbsp;&nbsp;13&nbsp;&nbsp;42&nbsp;&nbsp;13&nbsp;&nbsp;31</spanx></c>
  3739. <c>19</c>
  3740. <c><spanx style="vbare">&nbsp;21&nbsp;&nbsp;-4&nbsp;&nbsp;56&nbsp;&nbsp;46&nbsp;&nbsp;-1</spanx></c>
  3741. <c>20</c>
  3742. <c><spanx style="vbare">&nbsp;-1&nbsp;&nbsp;35&nbsp;&nbsp;79&nbsp;-13&nbsp;&nbsp;19</spanx></c>
  3743. <c>21</c>
  3744. <c><spanx style="vbare">&nbsp;-7&nbsp;&nbsp;65&nbsp;&nbsp;88&nbsp;&nbsp;-9&nbsp;-14</spanx></c>
  3745. <c>22</c>
  3746. <c><spanx style="vbare">&nbsp;20&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;81&nbsp;&nbsp;49&nbsp;-29</spanx></c>
  3747. <c>23</c>
  3748. <c><spanx style="vbare">&nbsp;20&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;75&nbsp;&nbsp;&nbsp;3&nbsp;-17</spanx></c>
  3749. <c>24</c>
  3750. <c><spanx style="vbare">&nbsp;&nbsp;5&nbsp;&nbsp;-9&nbsp;&nbsp;44&nbsp;&nbsp;92&nbsp;&nbsp;-8</spanx></c>
  3751. <c>25</c>
  3752. <c><spanx style="vbare">&nbsp;&nbsp;1&nbsp;&nbsp;-3&nbsp;&nbsp;22&nbsp;&nbsp;69&nbsp;&nbsp;31</spanx></c>
  3753. <c>26</c>
  3754. <c><spanx style="vbare">&nbsp;-6&nbsp;&nbsp;95&nbsp;&nbsp;41&nbsp;-12&nbsp;&nbsp;&nbsp;5</spanx></c>
  3755. <c>27</c>
  3756. <c><spanx style="vbare">&nbsp;39&nbsp;&nbsp;67&nbsp;&nbsp;16&nbsp;&nbsp;-4&nbsp;&nbsp;&nbsp;1</spanx></c>
  3757. <c>28</c>
  3758. <c><spanx style="vbare">&nbsp;&nbsp;0&nbsp;&nbsp;-6&nbsp;120&nbsp;&nbsp;55&nbsp;-36</spanx></c>
  3759. <c>29</c>
  3760. <c><spanx style="vbare">-13&nbsp;&nbsp;44&nbsp;122&nbsp;&nbsp;&nbsp;4&nbsp;-24</spanx></c>
  3761. <c>30</c>
  3762. <c><spanx style="vbare">&nbsp;81&nbsp;&nbsp;&nbsp;5&nbsp;&nbsp;11&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;7</spanx></c>
  3763. <c>31</c>
  3764. <c><spanx style="vbare">&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;9&nbsp;&nbsp;10&nbsp;&nbsp;88</spanx></c>
  3765. </texttable>
  3766. </section>
  3767. <section anchor="silk_ltp_scaling" title="LTP Scaling Parameter">
  3768. <t>
  3769. An LTP scaling parameter appears after the LTP filter coefficients if and only
  3770. if
  3771. <list style="symbols">
  3772. <t>This is a voiced frame (see <xref target="silk_frame_type"/>), and</t>
  3773. <t>Either
  3774. <list style="symbols">
  3775. <t>
  3776. This SILK frame corresponds to the first time interval of the
  3777. current Opus frame for its type (LBRR or regular), or
  3778. </t>
  3779. <t>
  3780. This is an LBRR frame where the LBRR flags (see
  3781. <xref target="silk_lbrr_flags"/>) indicate the previous LBRR frame in the same
  3782. channel is not coded.
  3783. </t>
  3784. </list>
  3785. </t>
  3786. </list>
  3787. This allows the encoder to trade off the prediction gain between
  3788. packets against the recovery time after packet loss.
  3789. Unlike absolute-coding for pitch lags, regular SILK frames that are not at the
  3790. start of an Opus frame (i.e., that do not correspond to the first 20&nbsp;ms
  3791. time interval in Opus frames of 40&nbsp;or 60&nbsp;ms) do not include this
  3792. field, even if the prior frame was not voiced, or (in the case of the side
  3793. channel) not even coded.
  3794. After an uncoded frame in the side channel, the LTP buffer (see
  3795. <xref target="silk_ltp_synthesis"/>) is cleared to zero, and is thus in a
  3796. known state.
  3797. In contrast, LBRR frames do include this field when the prior frame was not
  3798. coded, since the LTP buffer contains the output of the PLC, which is
  3799. non-normative.
  3800. </t>
  3801. <t>
  3802. If present, the decoder reads a value using the 3-entry PDF in
  3803. <xref target="silk_ltp_scaling_pdf"/>.
  3804. The three possible values represent Q14 scale factors of 15565, 12288, and
  3805. 8192, respectively (corresponding to approximately 0.95, 0.75, and 0.5).
  3806. Frames that do not code the scaling parameter use the default factor of 15565
  3807. (approximately 0.95).
  3808. </t>
  3809. <texttable anchor="silk_ltp_scaling_pdf"
  3810. title="PDF for LTP Scaling Parameter">
  3811. <ttcol align="left">PDF</ttcol>
  3812. <c>{128, 64, 64}/256</c>
  3813. </texttable>
  3814. </section>
  3815. </section>
  3816. <section anchor="silk_seed" toc="include"
  3817. title="Linear Congruential Generator (LCG) Seed">
  3818. <t>
  3819. As described in <xref target="silk_excitation_reconstruction"/>, SILK uses a
  3820. linear congruential generator (LCG) to inject pseudorandom noise into the
  3821. quantized excitation.
  3822. To ensure synchronization of this process between the encoder and decoder, each
  3823. SILK frame stores a 2-bit seed after the LTP parameters (if any).
  3824. The encoder may consider the choice of seed during quantization, and the
  3825. flexibility of this choice lets it reduce distortion, helping to pay for the
  3826. bit cost required to signal it.
  3827. The decoder reads the seed using the uniform 4-entry PDF in
  3828. <xref target="silk_seed_pdf"/>, yielding a value between 0 and 3, inclusive.
  3829. </t>
  3830. <texttable anchor="silk_seed_pdf"
  3831. title="PDF for LCG Seed">
  3832. <ttcol align="left">PDF</ttcol>
  3833. <c>{64, 64, 64, 64}/256</c>
  3834. </texttable>
  3835. </section>
  3836. <section anchor="silk_excitation" toc="include" title="Excitation">
  3837. <t>
  3838. SILK codes the excitation using a modified version of the Pyramid Vector
  3839. Quantization (PVQ) codebook <xref target="PVQ"/>.
  3840. The PVQ codebook is designed for Laplace-distributed values and consists of all
  3841. sums of K signed, unit pulses in a vector of dimension N, where two pulses at
  3842. the same position are required to have the same sign.
  3843. Thus the codebook includes all integer codevectors y of dimension N that
  3844. satisfy
  3845. <figure align="center">
  3846. <artwork align="center"><![CDATA[
  3847. N-1
  3848. __
  3849. \ abs(y[j]) = K .
  3850. /_
  3851. j=0
  3852. ]]></artwork>
  3853. </figure>
  3854. Unlike regular PVQ, SILK uses a variable-length, rather than fixed-length,
  3855. encoding.
  3856. This encoding is better suited to the more Gaussian-like distribution of the
  3857. coefficient magnitudes and the non-uniform distribution of their signs (caused
  3858. by the quantization offset described below).
  3859. SILK also handles large codebooks by coding the least significant bits (LSBs)
  3860. of each coefficient directly.
  3861. This adds a small coding efficiency loss, but greatly reduces the computation
  3862. time and ROM size required for decoding, as implemented in
  3863. silk_decode_pulses() (decode_pulses.c).
  3864. </t>
  3865. <t>
  3866. SILK fixes the dimension of the codebook to N&nbsp;=&nbsp;16.
  3867. The excitation is made up of a number of "shell blocks", each 16 samples in
  3868. size.
  3869. <xref target="silk_shell_block_table"/> lists the number of shell blocks
  3870. required for a SILK frame for each possible audio bandwidth and frame size.
  3871. 10&nbsp;ms MB frames nominally contain 120&nbsp;samples (10&nbsp;ms at
  3872. 12&nbsp;kHz), which is not a multiple of 16.
  3873. This is handled by coding 8 shell blocks (128 samples) and discarding the final
  3874. 8 samples of the last block.
  3875. The decoder contains no special case that prevents an encoder from placing
  3876. pulses in these samples, and they must be correctly parsed from the bitstream
  3877. if present, but they are otherwise ignored.
  3878. </t>
  3879. <texttable anchor="silk_shell_block_table"
  3880. title="Number of Shell Blocks Per SILK Frame">
  3881. <ttcol>Audio Bandwidth</ttcol>
  3882. <ttcol>Frame Size</ttcol>
  3883. <ttcol align="right">Number of Shell Blocks</ttcol>
  3884. <c>NB</c> <c>10&nbsp;ms</c> <c>5</c>
  3885. <c>MB</c> <c>10&nbsp;ms</c> <c>8</c>
  3886. <c>WB</c> <c>10&nbsp;ms</c> <c>10</c>
  3887. <c>NB</c> <c>20&nbsp;ms</c> <c>10</c>
  3888. <c>MB</c> <c>20&nbsp;ms</c> <c>15</c>
  3889. <c>WB</c> <c>20&nbsp;ms</c> <c>20</c>
  3890. </texttable>
  3891. <section anchor="silk_rate_level" title="Rate Level">
  3892. <t>
  3893. The first symbol in the excitation is a "rate level", which is an index from 0
  3894. to 8, inclusive, coded using the PDF in <xref target="silk_rate_level_pdfs"/>
  3895. corresponding to the signal type of the current frame (from
  3896. <xref target="silk_frame_type"/>).
  3897. The rate level selects the PDF used to decode the number of pulses in
  3898. the individual shell blocks.
  3899. It does not directly convey any information about the bitrate or the number of
  3900. pulses itself, but merely changes the probability of the symbols in
  3901. <xref target="silk_pulse_counts"/>.
  3902. Level&nbsp;0 provides a more efficient encoding at low rates generally, and
  3903. level&nbsp;8 provides a more efficient encoding at high rates generally,
  3904. though the most efficient level for a particular SILK frame may depend on the
  3905. exact distribution of the coded symbols.
  3906. An encoder should, but is not required to, use the most efficient rate level.
  3907. </t>
  3908. <texttable anchor="silk_rate_level_pdfs"
  3909. title="PDFs for the Rate Level">
  3910. <ttcol>Signal Type</ttcol>
  3911. <ttcol>PDF</ttcol>
  3912. <c>Inactive or Unvoiced</c>
  3913. <c>{15, 51, 12, 46, 45, 13, 33, 27, 14}/256</c>
  3914. <c>Voiced</c>
  3915. <c>{33, 30, 36, 17, 34, 49, 18, 21, 18}/256</c>
  3916. </texttable>
  3917. </section>
  3918. <section anchor="silk_pulse_counts" title="Pulses Per Shell Block">
  3919. <t>
  3920. The total number of pulses in each of the shell blocks follows the rate level.
  3921. The pulse counts for all of the shell blocks are coded consecutively, before
  3922. the content of any of the blocks.
  3923. Each block may have anywhere from 0 to 16 pulses, inclusive, coded using the
  3924. 18-entry PDF in <xref target="silk_pulse_count_pdfs"/> corresponding to the
  3925. rate level from <xref target="silk_rate_level"/>.
  3926. The special value 17 indicates that this block has one or more additional
  3927. LSBs to decode for each coefficient.
  3928. If the decoder encounters this value, it decodes another value for the actual
  3929. pulse count of the block, but uses the PDF corresponding to the special rate
  3930. level&nbsp;9 instead of the normal rate level.
  3931. This process repeats until the decoder reads a value less than 17, and it then
  3932. sets the number of extra LSBs used to the number of 17's decoded for that
  3933. block.
  3934. If it reads the value 17 ten times, then the next iteration uses the special
  3935. rate level&nbsp;10 instead of 9.
  3936. The probability of decoding a 17 when using the PDF for rate level&nbsp;10 is
  3937. zero, ensuring that the number of LSBs for a block will not exceed 10.
  3938. The cumulative distribution for rate level&nbsp;10 is just a shifted version of
  3939. that for 9 and thus does not require any additional storage.
  3940. </t>
  3941. <texttable anchor="silk_pulse_count_pdfs"
  3942. title="PDFs for the Pulse Count">
  3943. <ttcol>Rate Level</ttcol>
  3944. <ttcol>PDF</ttcol>
  3945. <c>0</c>
  3946. <c>{131, 74, 25, 8, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}/256</c>
  3947. <c>1</c>
  3948. <c>{58, 93, 60, 23, 7, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}/256</c>
  3949. <c>2</c>
  3950. <c>{43, 51, 46, 33, 24, 16, 11, 8, 6, 3, 3, 3, 2, 1, 1, 2, 1, 2}/256</c>
  3951. <c>3</c>
  3952. <c>{17, 52, 71, 57, 31, 12, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}/256</c>
  3953. <c>4</c>
  3954. <c>{6, 21, 41, 53, 49, 35, 21, 11, 6, 3, 2, 2, 1, 1, 1, 1, 1, 1}/256</c>
  3955. <c>5</c>
  3956. <c>{7, 14, 22, 28, 29, 28, 25, 20, 17, 13, 11, 9, 7, 5, 4, 4, 3, 10}/256</c>
  3957. <c>6</c>
  3958. <c>{2, 5, 14, 29, 42, 46, 41, 31, 19, 11, 6, 3, 2, 1, 1, 1, 1, 1}/256</c>
  3959. <c>7</c>
  3960. <c>{1, 2, 4, 10, 19, 29, 35, 37, 34, 28, 20, 14, 8, 5, 4, 2, 2, 2}/256</c>
  3961. <c>8</c>
  3962. <c>{1, 2, 2, 5, 9, 14, 20, 24, 27, 28, 26, 23, 20, 15, 11, 8, 6, 15}/256</c>
  3963. <c>9</c>
  3964. <c>{1, 1, 1, 6, 27, 58, 56, 39, 25, 14, 10, 6, 3, 3, 2, 1, 1, 2}/256</c>
  3965. <c>10</c>
  3966. <c>{2, 1, 6, 27, 58, 56, 39, 25, 14, 10, 6, 3, 3, 2, 1, 1, 2, 0}/256</c>
  3967. </texttable>
  3968. </section>
  3969. <section anchor="silk_pulse_locations" title="Pulse Location Decoding">
  3970. <t>
  3971. The locations of the pulses in each shell block follow the pulse counts,
  3972. as decoded by silk_shell_decoder() (shell_coder.c).
  3973. As with the pulse counts, these locations are coded for all the shell blocks
  3974. before any of the remaining information for each block.
  3975. Unlike many other codecs, SILK places no restriction on the distribution of
  3976. pulses within a shell block.
  3977. All of the pulses may be placed in a single location, or each one in a unique
  3978. location, or anything in between.
  3979. </t>
  3980. <t>
  3981. The location of pulses is coded by recursively partitioning each block into
  3982. halves, and coding how many pulses fall on the left side of the split.
  3983. All remaining pulses must fall on the right side of the split.
  3984. The process then recurses into the left half, and after that returns, the
  3985. right half (preorder traversal).
  3986. The PDF to use is chosen by the size of the current partition (16, 8, 4, or 2)
  3987. and the number of pulses in the partition (1 to 16, inclusive).
  3988. Tables&nbsp;<xref format="counter" target="silk_shell_code3_pdfs"/>
  3989. through&nbsp;<xref format="counter" target="silk_shell_code0_pdfs"/> list the
  3990. PDFs used for each partition size and pulse count.
  3991. This process skips partitions without any pulses, i.e., where the initial pulse
  3992. count from <xref target="silk_pulse_counts"/> was zero, or where the split in
  3993. the prior level indicated that all of the pulses fell on the other side.
  3994. These partitions have nothing to code, so they require no PDF.
  3995. </t>
  3996. <texttable anchor="silk_shell_code3_pdfs"
  3997. title="PDFs for Pulse Count Split, 16 Sample Partitions">
  3998. <ttcol>Pulse Count</ttcol>
  3999. <ttcol>PDF</ttcol>
  4000. <c>1</c> <c>{126, 130}/256</c>
  4001. <c>2</c> <c>{56, 142, 58}/256</c>
  4002. <c>3</c> <c>{25, 101, 104, 26}/256</c>
  4003. <c>4</c> <c>{12, 60, 108, 64, 12}/256</c>
  4004. <c>5</c> <c>{7, 35, 84, 87, 37, 6}/256</c>
  4005. <c>6</c> <c>{4, 20, 59, 86, 63, 21, 3}/256</c>
  4006. <c>7</c> <c>{3, 12, 38, 72, 75, 42, 12, 2}/256</c>
  4007. <c>8</c> <c>{2, 8, 25, 54, 73, 59, 27, 7, 1}/256</c>
  4008. <c>9</c> <c>{2, 5, 17, 39, 63, 65, 42, 18, 4, 1}/256</c>
  4009. <c>10</c> <c>{1, 4, 12, 28, 49, 63, 54, 30, 11, 3, 1}/256</c>
  4010. <c>11</c> <c>{1, 4, 8, 20, 37, 55, 57, 41, 22, 8, 2, 1}/256</c>
  4011. <c>12</c> <c>{1, 3, 7, 15, 28, 44, 53, 48, 33, 16, 6, 1, 1}/256</c>
  4012. <c>13</c> <c>{1, 2, 6, 12, 21, 35, 47, 48, 40, 25, 12, 5, 1, 1}/256</c>
  4013. <c>14</c> <c>{1, 1, 4, 10, 17, 27, 37, 47, 43, 33, 21, 9, 4, 1, 1}/256</c>
  4014. <c>15</c> <c>{1, 1, 1, 8, 14, 22, 33, 40, 43, 38, 28, 16, 8, 1, 1, 1}/256</c>
  4015. <c>16</c> <c>{1, 1, 1, 1, 13, 18, 27, 36, 41, 41, 34, 24, 14, 1, 1, 1, 1}/256</c>
  4016. </texttable>
  4017. <texttable anchor="silk_shell_code2_pdfs"
  4018. title="PDFs for Pulse Count Split, 8 Sample Partitions">
  4019. <ttcol>Pulse Count</ttcol>
  4020. <ttcol>PDF</ttcol>
  4021. <c>1</c> <c>{127, 129}/256</c>
  4022. <c>2</c> <c>{53, 149, 54}/256</c>
  4023. <c>3</c> <c>{22, 105, 106, 23}/256</c>
  4024. <c>4</c> <c>{11, 61, 111, 63, 10}/256</c>
  4025. <c>5</c> <c>{6, 35, 86, 88, 36, 5}/256</c>
  4026. <c>6</c> <c>{4, 20, 59, 87, 62, 21, 3}/256</c>
  4027. <c>7</c> <c>{3, 13, 40, 71, 73, 41, 13, 2}/256</c>
  4028. <c>8</c> <c>{3, 9, 27, 53, 70, 56, 28, 9, 1}/256</c>
  4029. <c>9</c> <c>{3, 8, 19, 37, 57, 61, 44, 20, 6, 1}/256</c>
  4030. <c>10</c> <c>{3, 7, 15, 28, 44, 54, 49, 33, 17, 5, 1}/256</c>
  4031. <c>11</c> <c>{1, 7, 13, 22, 34, 46, 48, 38, 28, 14, 4, 1}/256</c>
  4032. <c>12</c> <c>{1, 1, 11, 22, 27, 35, 42, 47, 33, 25, 10, 1, 1}/256</c>
  4033. <c>13</c> <c>{1, 1, 6, 14, 26, 37, 43, 43, 37, 26, 14, 6, 1, 1}/256</c>
  4034. <c>14</c> <c>{1, 1, 4, 10, 20, 31, 40, 42, 40, 31, 20, 10, 4, 1, 1}/256</c>
  4035. <c>15</c> <c>{1, 1, 3, 8, 16, 26, 35, 38, 38, 35, 26, 16, 8, 3, 1, 1}/256</c>
  4036. <c>16</c> <c>{1, 1, 2, 6, 12, 21, 30, 36, 38, 36, 30, 21, 12, 6, 2, 1, 1}/256</c>
  4037. </texttable>
  4038. <texttable anchor="silk_shell_code1_pdfs"
  4039. title="PDFs for Pulse Count Split, 4 Sample Partitions">
  4040. <ttcol>Pulse Count</ttcol>
  4041. <ttcol>PDF</ttcol>
  4042. <c>1</c> <c>{127, 129}/256</c>
  4043. <c>2</c> <c>{49, 157, 50}/256</c>
  4044. <c>3</c> <c>{20, 107, 109, 20}/256</c>
  4045. <c>4</c> <c>{11, 60, 113, 62, 10}/256</c>
  4046. <c>5</c> <c>{7, 36, 84, 87, 36, 6}/256</c>
  4047. <c>6</c> <c>{6, 24, 57, 82, 60, 23, 4}/256</c>
  4048. <c>7</c> <c>{5, 18, 39, 64, 68, 42, 16, 4}/256</c>
  4049. <c>8</c> <c>{6, 14, 29, 47, 61, 52, 30, 14, 3}/256</c>
  4050. <c>9</c> <c>{1, 15, 23, 35, 51, 50, 40, 30, 10, 1}/256</c>
  4051. <c>10</c> <c>{1, 1, 21, 32, 42, 52, 46, 41, 18, 1, 1}/256</c>
  4052. <c>11</c> <c>{1, 6, 16, 27, 36, 42, 42, 36, 27, 16, 6, 1}/256</c>
  4053. <c>12</c> <c>{1, 5, 12, 21, 31, 38, 40, 38, 31, 21, 12, 5, 1}/256</c>
  4054. <c>13</c> <c>{1, 3, 9, 17, 26, 34, 38, 38, 34, 26, 17, 9, 3, 1}/256</c>
  4055. <c>14</c> <c>{1, 3, 7, 14, 22, 29, 34, 36, 34, 29, 22, 14, 7, 3, 1}/256</c>
  4056. <c>15</c> <c>{1, 2, 5, 11, 18, 25, 31, 35, 35, 31, 25, 18, 11, 5, 2, 1}/256</c>
  4057. <c>16</c> <c>{1, 1, 4, 9, 15, 21, 28, 32, 34, 32, 28, 21, 15, 9, 4, 1, 1}/256</c>
  4058. </texttable>
  4059. <texttable anchor="silk_shell_code0_pdfs"
  4060. title="PDFs for Pulse Count Split, 2 Sample Partitions">
  4061. <ttcol>Pulse Count</ttcol>
  4062. <ttcol>PDF</ttcol>
  4063. <c>1</c> <c>{128, 128}/256</c>
  4064. <c>2</c> <c>{42, 172, 42}/256</c>
  4065. <c>3</c> <c>{21, 107, 107, 21}/256</c>
  4066. <c>4</c> <c>{12, 60, 112, 61, 11}/256</c>
  4067. <c>5</c> <c>{8, 34, 86, 86, 35, 7}/256</c>
  4068. <c>6</c> <c>{8, 23, 55, 90, 55, 20, 5}/256</c>
  4069. <c>7</c> <c>{5, 15, 38, 72, 72, 36, 15, 3}/256</c>
  4070. <c>8</c> <c>{6, 12, 27, 52, 77, 47, 20, 10, 5}/256</c>
  4071. <c>9</c> <c>{6, 19, 28, 35, 40, 40, 35, 28, 19, 6}/256</c>
  4072. <c>10</c> <c>{4, 14, 22, 31, 37, 40, 37, 31, 22, 14, 4}/256</c>
  4073. <c>11</c> <c>{3, 10, 18, 26, 33, 38, 38, 33, 26, 18, 10, 3}/256</c>
  4074. <c>12</c> <c>{2, 8, 13, 21, 29, 36, 38, 36, 29, 21, 13, 8, 2}/256</c>
  4075. <c>13</c> <c>{1, 5, 10, 17, 25, 32, 38, 38, 32, 25, 17, 10, 5, 1}/256</c>
  4076. <c>14</c> <c>{1, 4, 7, 13, 21, 29, 35, 36, 35, 29, 21, 13, 7, 4, 1}/256</c>
  4077. <c>15</c> <c>{1, 2, 5, 10, 17, 25, 32, 36, 36, 32, 25, 17, 10, 5, 2, 1}/256</c>
  4078. <c>16</c> <c>{1, 2, 4, 7, 13, 21, 28, 34, 36, 34, 28, 21, 13, 7, 4, 2, 1}/256</c>
  4079. </texttable>
  4080. </section>
  4081. <section anchor="silk_shell_lsb" title="LSB Decoding">
  4082. <t>
  4083. After the decoder reads the pulse locations for all blocks, it reads the LSBs
  4084. (if any) for each block in turn.
  4085. Inside each block, it reads all the LSBs for each coefficient in turn, even
  4086. those where no pulses were allocated, before proceeding to the next one.
  4087. For 10&nbsp;ms MB frames, it reads LSBs even for the extra 8&nbsp;samples in
  4088. the last block.
  4089. The LSBs are coded from most significant to least significant, and they all use
  4090. the PDF in <xref target="silk_shell_lsb_pdf"/>.
  4091. </t>
  4092. <texttable anchor="silk_shell_lsb_pdf" title="PDF for Excitation LSBs">
  4093. <ttcol>PDF</ttcol>
  4094. <c>{136, 120}/256</c>
  4095. </texttable>
  4096. <t>
  4097. The number of LSBs read for each coefficient in a block is determined in
  4098. <xref target="silk_pulse_counts"/>.
  4099. The magnitude of the coefficient is initially equal to the number of pulses
  4100. placed at that location in <xref target="silk_pulse_locations"/>.
  4101. As each LSB is decoded, the magnitude is doubled, and then the value of the LSB
  4102. added to it, to obtain an updated magnitude.
  4103. </t>
  4104. </section>
  4105. <section anchor="silk_signs" title="Sign Decoding">
  4106. <t>
  4107. After decoding the pulse locations and the LSBs, the decoder knows the
  4108. magnitude of each coefficient in the excitation.
  4109. It then decodes a sign for all coefficients with a non-zero magnitude, using
  4110. one of the PDFs from <xref target="silk_sign_pdfs"/>.
  4111. If the value decoded is 0, then the coefficient magnitude is negated.
  4112. Otherwise, it remains positive.
  4113. </t>
  4114. <t>
  4115. The decoder chooses the PDF for the sign based on the signal type and
  4116. quantization offset type (from <xref target="silk_frame_type"/>) and the
  4117. number of pulses in the block (from <xref target="silk_pulse_counts"/>).
  4118. The number of pulses in the block does not take into account any LSBs.
  4119. Most PDFs are skewed towards negative signs because of the quantization offset,
  4120. but the PDFs for zero pulses are highly skewed towards positive signs.
  4121. If a block contains many positive coefficients, it is sometimes beneficial to
  4122. code it solely using LSBs (i.e., with zero pulses), since the encoder may be
  4123. able to save enough bits on the signs to justify the less efficient
  4124. coefficient magnitude encoding.
  4125. </t>
  4126. <texttable anchor="silk_sign_pdfs"
  4127. title="PDFs for Excitation Signs">
  4128. <ttcol>Signal Type</ttcol>
  4129. <ttcol>Quantization Offset Type</ttcol>
  4130. <ttcol>Pulse Count</ttcol>
  4131. <ttcol>PDF</ttcol>
  4132. <c>Inactive</c> <c>Low</c> <c>0</c> <c>{2, 254}/256</c>
  4133. <c>Inactive</c> <c>Low</c> <c>1</c> <c>{207, 49}/256</c>
  4134. <c>Inactive</c> <c>Low</c> <c>2</c> <c>{189, 67}/256</c>
  4135. <c>Inactive</c> <c>Low</c> <c>3</c> <c>{179, 77}/256</c>
  4136. <c>Inactive</c> <c>Low</c> <c>4</c> <c>{174, 82}/256</c>
  4137. <c>Inactive</c> <c>Low</c> <c>5</c> <c>{163, 93}/256</c>
  4138. <c>Inactive</c> <c>Low</c> <c>6 or more</c> <c>{157, 99}/256</c>
  4139. <c>Inactive</c> <c>High</c> <c>0</c> <c>{58, 198}/256</c>
  4140. <c>Inactive</c> <c>High</c> <c>1</c> <c>{245, 11}/256</c>
  4141. <c>Inactive</c> <c>High</c> <c>2</c> <c>{238, 18}/256</c>
  4142. <c>Inactive</c> <c>High</c> <c>3</c> <c>{232, 24}/256</c>
  4143. <c>Inactive</c> <c>High</c> <c>4</c> <c>{225, 31}/256</c>
  4144. <c>Inactive</c> <c>High</c> <c>5</c> <c>{220, 36}/256</c>
  4145. <c>Inactive</c> <c>High</c> <c>6 or more</c> <c>{211, 45}/256</c>
  4146. <c>Unvoiced</c> <c>Low</c> <c>0</c> <c>{1, 255}/256</c>
  4147. <c>Unvoiced</c> <c>Low</c> <c>1</c> <c>{210, 46}/256</c>
  4148. <c>Unvoiced</c> <c>Low</c> <c>2</c> <c>{190, 66}/256</c>
  4149. <c>Unvoiced</c> <c>Low</c> <c>3</c> <c>{178, 78}/256</c>
  4150. <c>Unvoiced</c> <c>Low</c> <c>4</c> <c>{169, 87}/256</c>
  4151. <c>Unvoiced</c> <c>Low</c> <c>5</c> <c>{162, 94}/256</c>
  4152. <c>Unvoiced</c> <c>Low</c> <c>6 or more</c> <c>{152, 104}/256</c>
  4153. <c>Unvoiced</c> <c>High</c> <c>0</c> <c>{48, 208}/256</c>
  4154. <c>Unvoiced</c> <c>High</c> <c>1</c> <c>{242, 14}/256</c>
  4155. <c>Unvoiced</c> <c>High</c> <c>2</c> <c>{235, 21}/256</c>
  4156. <c>Unvoiced</c> <c>High</c> <c>3</c> <c>{224, 32}/256</c>
  4157. <c>Unvoiced</c> <c>High</c> <c>4</c> <c>{214, 42}/256</c>
  4158. <c>Unvoiced</c> <c>High</c> <c>5</c> <c>{205, 51}/256</c>
  4159. <c>Unvoiced</c> <c>High</c> <c>6 or more</c> <c>{190, 66}/256</c>
  4160. <c>Voiced</c> <c>Low</c> <c>0</c> <c>{1, 255}/256</c>
  4161. <c>Voiced</c> <c>Low</c> <c>1</c> <c>{162, 94}/256</c>
  4162. <c>Voiced</c> <c>Low</c> <c>2</c> <c>{152, 104}/256</c>
  4163. <c>Voiced</c> <c>Low</c> <c>3</c> <c>{147, 109}/256</c>
  4164. <c>Voiced</c> <c>Low</c> <c>4</c> <c>{144, 112}/256</c>
  4165. <c>Voiced</c> <c>Low</c> <c>5</c> <c>{141, 115}/256</c>
  4166. <c>Voiced</c> <c>Low</c> <c>6 or more</c> <c>{138, 118}/256</c>
  4167. <c>Voiced</c> <c>High</c> <c>0</c> <c>{8, 248}/256</c>
  4168. <c>Voiced</c> <c>High</c> <c>1</c> <c>{203, 53}/256</c>
  4169. <c>Voiced</c> <c>High</c> <c>2</c> <c>{187, 69}/256</c>
  4170. <c>Voiced</c> <c>High</c> <c>3</c> <c>{176, 80}/256</c>
  4171. <c>Voiced</c> <c>High</c> <c>4</c> <c>{168, 88}/256</c>
  4172. <c>Voiced</c> <c>High</c> <c>5</c> <c>{161, 95}/256</c>
  4173. <c>Voiced</c> <c>High</c> <c>6 or more</c> <c>{154, 102}/256</c>
  4174. </texttable>
  4175. </section>
  4176. <section anchor="silk_excitation_reconstruction"
  4177. title="Reconstructing the Excitation">
  4178. <t>
  4179. After the signs have been read, there is enough information to reconstruct the
  4180. complete excitation signal.
  4181. This requires adding a constant quantization offset to each non-zero sample,
  4182. and then pseudorandomly inverting and offsetting every sample.
  4183. The constant quantization offset varies depending on the signal type and
  4184. quantization offset type (see <xref target="silk_frame_type"/>).
  4185. </t>
  4186. <texttable anchor="silk_quantization_offsets"
  4187. title="Excitation Quantization Offsets">
  4188. <ttcol align="left">Signal Type</ttcol>
  4189. <ttcol align="left">Quantization Offset Type</ttcol>
  4190. <ttcol align="right">Quantization Offset (Q23)</ttcol>
  4191. <c>Inactive</c> <c>Low</c> <c>25</c>
  4192. <c>Inactive</c> <c>High</c> <c>60</c>
  4193. <c>Unvoiced</c> <c>Low</c> <c>25</c>
  4194. <c>Unvoiced</c> <c>High</c> <c>60</c>
  4195. <c>Voiced</c> <c>Low</c> <c>8</c>
  4196. <c>Voiced</c> <c>High</c> <c>25</c>
  4197. </texttable>
  4198. <t>
  4199. Let e_raw[i] be the raw excitation value at position i, with a magnitude
  4200. composed of the pulses at that location (see
  4201. <xref target="silk_pulse_locations"/>) combined with any additional LSBs (see
  4202. <xref target="silk_shell_lsb"/>), and with the corresponding sign decoded in
  4203. <xref target="silk_signs"/>.
  4204. Additionally, let seed be the current pseudorandom seed, which is initialized
  4205. to the value decoded from <xref target="silk_seed"/> for the first sample in
  4206. the current SILK frame, and updated for each subsequent sample according to
  4207. the procedure below.
  4208. Finally, let offset_Q23 be the quantization offset from
  4209. <xref target="silk_quantization_offsets"/>.
  4210. Then the following procedure produces the final reconstructed excitation value,
  4211. e_Q23[i]:
  4212. <figure align="center">
  4213. <artwork align="center"><![CDATA[
  4214. e_Q23[i] = (e_raw[i] << 8) - sign(e_raw[i])*20 + offset_Q23;
  4215. seed = (196314165*seed + 907633515) & 0xFFFFFFFF;
  4216. e_Q23[i] = (seed & 0x80000000) ? -e_Q23[i] : e_Q23[i];
  4217. seed = (seed + e_raw[i]) & 0xFFFFFFFF;
  4218. ]]></artwork>
  4219. </figure>
  4220. When e_raw[i] is zero, sign() returns 0 by the definition in
  4221. <xref target="sign"/>, so the factor of 20 does not get added.
  4222. The final e_Q23[i] value may require more than 16 bits per sample, but will not
  4223. require more than 23, including the sign.
  4224. </t>
  4225. </section>
  4226. </section>
  4227. <section anchor="silk_frame_reconstruction" toc="include"
  4228. title="SILK Frame Reconstruction">
  4229. <t>
  4230. The remainder of the reconstruction process for the frame does not need to be
  4231. bit-exact, as small errors should only introduce proportionally small
  4232. distortions.
  4233. Although the reference implementation only includes a fixed-point version of
  4234. the remaining steps, this section describes them in terms of a floating-point
  4235. version for simplicity.
  4236. This produces a signal with a nominal range of -1.0 to 1.0.
  4237. </t>
  4238. <t>
  4239. silk_decode_core() (decode_core.c) contains the code for the main
  4240. reconstruction process.
  4241. It proceeds subframe-by-subframe, since quantization gains, LTP parameters, and
  4242. (in 20&nbsp;ms SILK frames) LPC coefficients can vary from one to the
  4243. next.
  4244. </t>
  4245. <t>
  4246. Let a_Q12[k] be the LPC coefficients for the current subframe.
  4247. If this is the first or second subframe of a 20&nbsp;ms SILK frame and the LSF
  4248. interpolation factor, w_Q2 (see <xref target="silk_nlsf_interpolation"/>), is
  4249. less than 4, then these correspond to the final LPC coefficients produced by
  4250. <xref target="silk_lpc_gain_limit"/> from the interpolated LSF coefficients,
  4251. n1_Q15[k] (computed in <xref target="silk_nlsf_interpolation"/>).
  4252. Otherwise, they correspond to the final LPC coefficients produced from the
  4253. uninterpolated LSF coefficients for the current frame, n2_Q15[k].
  4254. </t>
  4255. <t>
  4256. Also, let n be the number of samples in a subframe (40 for NB, 60 for MB, and
  4257. 80 for WB), s be the index of the current subframe in this SILK frame (0 or 1
  4258. for 10&nbsp;ms frames, or 0 to 3 for 20&nbsp;ms frames), and j be the index of
  4259. the first sample in the residual corresponding to the current subframe.
  4260. </t>
  4261. <section anchor="silk_ltp_synthesis" title="LTP Synthesis">
  4262. <t>
  4263. Voiced SILK frames (see <xref target="silk_frame_type"/>) pass the excitation
  4264. through an LTP filter using the parameters decoded in
  4265. <xref target="silk_ltp_params"/> to produce an LPC residual.
  4266. The LTP filter requires LPC residual values from before the current subframe as
  4267. input.
  4268. However, since the LPC coefficients may have changed, it obtains this residual
  4269. by "rewhitening" the corresponding output signal using the LPC coefficients
  4270. from the current subframe.
  4271. Let out[i] for
  4272. (j&nbsp;-&nbsp;pitch_lags[s]&nbsp;-&nbsp;d_LPC&nbsp;-&nbsp;2)&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;j
  4273. be the fully reconstructed output signal from the last
  4274. (pitch_lags[s]&nbsp;+&nbsp;d_LPC&nbsp;+&nbsp;2) samples of previous subframes
  4275. (see <xref target="silk_lpc_synthesis"/>), where pitch_lags[s] is the pitch
  4276. lag for the current subframe from <xref target="silk_ltp_lags"/>.
  4277. During reconstruction of the first subframe for this channel after either
  4278. <list style="symbols">
  4279. <t>An uncoded regular SILK frame (if this is the side channel), or</t>
  4280. <t>A decoder reset (see <xref target="decoder-reset"/>),</t>
  4281. </list>
  4282. out[] is rewhitened into an LPC residual,
  4283. res[i], via
  4284. <figure align="center">
  4285. <artwork align="center"><![CDATA[
  4286. 4.0*LTP_scale_Q14
  4287. res[i] = ----------------- * clamp(-1.0,
  4288. gain_Q16[s]
  4289. d_LPC-1
  4290. __ a_Q12[k]
  4291. out[i] - \ out[i-k-1] * --------, 1.0) .
  4292. /_ 4096.0
  4293. k=0
  4294. ]]></artwork>
  4295. </figure>
  4296. This requires storage to buffer up to 306 values of out[i] from previous
  4297. subframes.
  4298. This corresponds to WB with a maximum pitch lag of
  4299. 18&nbsp;ms&nbsp;*&nbsp;16&nbsp;kHz samples, plus 16 samples for d_LPC, plus 2
  4300. samples for the width of the LTP filter.
  4301. </t>
  4302. <t>
  4303. Let e_Q23[i] for j&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;(j&nbsp;+&nbsp;n) be the
  4304. excitation for the current subframe, and b_Q7[k] for
  4305. 0&nbsp;&lt;=&nbsp;k&nbsp;&lt;&nbsp;5 be the coefficients of the LTP filter
  4306. taken from the codebook entry in one of
  4307. Tables&nbsp;<xref format="counter" target="silk_ltp_filter_coeffs0"/>
  4308. through&nbsp;<xref format="counter" target="silk_ltp_filter_coeffs2"/>
  4309. corresponding to the index decoded for the current subframe in
  4310. <xref target="silk_ltp_filter"/>.
  4311. Then for i such that j&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;(j&nbsp;+&nbsp;n),
  4312. the LPC residual is
  4313. <figure align="center">
  4314. <artwork align="center"><![CDATA[
  4315. 4
  4316. e_Q23[i] __ b_Q7[k]
  4317. res[i] = --------- + \ res[i - pitch_lags[s] + 2 - k] * ------- .
  4318. 2.0**23 /_ 128.0
  4319. k=0
  4320. ]]></artwork>
  4321. </figure>
  4322. </t>
  4323. <t>
  4324. For unvoiced frames, the LPC residual for
  4325. j&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;(j&nbsp;+&nbsp;n) is simply a normalized
  4326. copy of the excitation signal, i.e.,
  4327. <figure align="center">
  4328. <artwork align="center"><![CDATA[
  4329. e_Q23[i]
  4330. res[i] = ---------
  4331. 2.0**23
  4332. ]]></artwork>
  4333. </figure>
  4334. </t>
  4335. </section>
  4336. <section anchor="silk_lpc_synthesis" title="LPC Synthesis">
  4337. <t>
  4338. LPC synthesis uses the short-term LPC filter to predict the next output
  4339. coefficient.
  4340. For i such that (j&nbsp;-&nbsp;d_LPC)&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;j, let
  4341. lpc[i] be the result of LPC synthesis from the last d_LPC samples of the
  4342. previous subframe, or zeros in the first subframe for this channel after
  4343. either
  4344. <list style="symbols">
  4345. <t>An uncoded regular SILK frame (if this is the side channel), or</t>
  4346. <t>A decoder reset (see <xref target="decoder-reset"/>).</t>
  4347. </list>
  4348. Then for i such that j&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;(j&nbsp;+&nbsp;n), the
  4349. result of LPC synthesis for the current subframe is
  4350. <figure align="center">
  4351. <artwork align="center"><![CDATA[
  4352. d_LPC-1
  4353. gain_Q16[i] __ a_Q12[k]
  4354. lpc[i] = ----------- * res[i] + \ lpc[i-k-1] * -------- .
  4355. 65536.0 /_ 4096.0
  4356. k=0
  4357. ]]></artwork>
  4358. </figure>
  4359. The decoder saves the final d_LPC values, i.e., lpc[i] such that
  4360. (j&nbsp;+&nbsp;n&nbsp;-&nbsp;d_LPC)&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;(j&nbsp;+&nbsp;n),
  4361. to feed into the LPC synthesis of the next subframe.
  4362. This requires storage for up to 16 values of lpc[i] (for WB frames).
  4363. </t>
  4364. <t>
  4365. Then, the signal is clamped into the final nominal range:
  4366. <figure align="center">
  4367. <artwork align="center"><![CDATA[
  4368. out[i] = clamp(-1.0, lpc[i], 1.0) .
  4369. ]]></artwork>
  4370. </figure>
  4371. This clamping occurs entirely after the LPC synthesis filter has run.
  4372. The decoder saves the unclamped values, lpc[i], to feed into the LPC filter for
  4373. the next subframe, but saves the clamped values, out[i], for rewhitening in
  4374. voiced frames.
  4375. </t>
  4376. </section>
  4377. </section>
  4378. </section>
  4379. <section anchor="silk_stereo_unmixing" title="Stereo Unmixing">
  4380. <t>
  4381. For stereo streams, after decoding a frame from each channel, the decoder must
  4382. convert the mid-side (MS) representation into a left-right (LR)
  4383. representation.
  4384. The function silk_stereo_MS_to_LR (stereo_MS_to_LR.c) implements this process.
  4385. In it, the decoder predicts the side channel using a) a simple low-passed
  4386. version of the mid channel, and b) the unfiltered mid channel, using the
  4387. prediction weights decoded in <xref target="silk_stereo_pred"/>.
  4388. This simple low-pass filter imposes a one-sample delay, and the unfiltered
  4389. mid channel is also delayed by one sample.
  4390. In order to allow seamless switching between stereo and mono, mono streams must
  4391. also impose the same one-sample delay.
  4392. The encoder requires an additional one-sample delay for both mono and stereo
  4393. streams, though an encoder may omit the delay for mono if it knows it will
  4394. never switch to stereo.
  4395. </t>
  4396. <t>
  4397. The unmixing process operates in two phases.
  4398. The first phase lasts for 8&nbsp;ms, during which it interpolates the
  4399. prediction weights from the previous frame, prev_w0_Q13 and prev_w1_Q13, to
  4400. the values for the current frame, w0_Q13 and w1_Q13.
  4401. The second phase simply uses these weights for the remainder of the frame.
  4402. </t>
  4403. <t>
  4404. Let mid[i] and side[i] be the contents of out[i] (from
  4405. <xref target="silk_lpc_synthesis"/>) for the current mid and side channels,
  4406. respectively, and let left[i] and right[i] be the corresponding stereo output
  4407. channels.
  4408. If the side channel is not coded (see <xref target="silk_mid_only_flag"/>),
  4409. then side[i] is set to zero.
  4410. Also let j be defined as in <xref target="silk_frame_reconstruction"/>, n1 be
  4411. the number of samples in phase&nbsp;1 (64 for NB, 96 for MB, and 128 for WB),
  4412. and n2 be the total number of samples in the frame.
  4413. Then for i such that j&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;(j&nbsp;+&nbsp;n2),
  4414. the left and right channel output is
  4415. <figure align="center">
  4416. <artwork align="center"><![CDATA[
  4417. prev_w0_Q13 (w0_Q13 - prev_w0_Q13)
  4418. w0 = ----------- + min(i - j, n1)*---------------------- ,
  4419. 8192.0 8192.0*n1
  4420. prev_w1_Q13 (w1_Q13 - prev_w1_Q13)
  4421. w1 = ----------- + min(i - j, n1)*---------------------- ,
  4422. 8192.0 8192.0*n1
  4423. mid[i-2] + 2*mid[i-1] + mid[i]
  4424. p0 = ------------------------------ ,
  4425. 4.0
  4426. left[i] = clamp(-1.0, (1 + w1)*mid[i-1] + side[i-1] + w0*p0, 1.0) ,
  4427. right[i] = clamp(-1.0, (1 - w1)*mid[i-1] - side[i-1] - w0*p0, 1.0) .
  4428. ]]></artwork>
  4429. </figure>
  4430. These formulas require two samples prior to index&nbsp;j, the start of the
  4431. frame, for the mid channel, and one prior sample for the side channel.
  4432. For the first frame after a decoder reset, zeros are used instead.
  4433. </t>
  4434. </section>
  4435. <section title="Resampling">
  4436. <t>
  4437. After stereo unmixing (if any), the decoder applies resampling to convert the
  4438. decoded SILK output to the sample rate desired by the application.
  4439. This is necessary when decoding a Hybrid frame at SWB or FB sample rates, or
  4440. whenever the decoder wants the output at a different sample rate than the
  4441. internal SILK sampling rate (e.g., to allow a constant sample rate when the
  4442. audio bandwidth changes, or to allow mixing with audio from other
  4443. applications).
  4444. The resampler itself is non-normative, and a decoder can use any method it
  4445. wants to perform the resampling.
  4446. </t>
  4447. <t>
  4448. However, a minimum amount of delay is imposed to allow the resampler to
  4449. operate, and this delay is normative, so that the corresponding delay can be
  4450. applied to the MDCT layer in the encoder.
  4451. A decoder is always free to use a resampler which requires more delay than
  4452. allowed for here (e.g., to improve quality), but it must then delay the output
  4453. of the MDCT layer by this extra amount.
  4454. Keeping as much delay as possible on the encoder side allows an encoder which
  4455. knows it will never use any of the SILK or Hybrid modes to skip this delay.
  4456. By contrast, if it were all applied by the decoder, then a decoder which
  4457. processes audio in fixed-size blocks would be forced to delay the output of
  4458. CELT frames just in case of a later switch to a SILK or Hybrid mode.
  4459. </t>
  4460. <t>
  4461. <xref target="silk_resampler_delay_alloc"/> gives the maximum resampler delay
  4462. in samples at 48&nbsp;kHz for each SILK audio bandwidth.
  4463. Because the actual output rate may not be 48&nbsp;kHz, it may not be possible
  4464. to achieve exactly these delays while using a whole number of input or output
  4465. samples.
  4466. The reference implementation is able to resample to any of the supported
  4467. output sampling rates (8, 12, 16, 24, or 48&nbsp;kHz) within or near this
  4468. delay constraint.
  4469. Some resampling filters (including those used by the reference implementation)
  4470. may add a delay that is not an exact integer, or is not linear-phase, and so
  4471. cannot be represented by a single delay at all frequencies.
  4472. However, such deviations are unlikely to be perceptible, and the comparison
  4473. tool described in <xref target="conformance"/> is designed to be relatively
  4474. insensitive to them.
  4475. The delays listed here are the ones that should be targeted by the encoder.
  4476. </t>
  4477. <texttable anchor="silk_resampler_delay_alloc"
  4478. title="SILK Resampler Delay Allocations">
  4479. <ttcol>Audio Bandwidth</ttcol>
  4480. <ttcol>Delay in millisecond</ttcol>
  4481. <c>NB</c> <c>0.538</c>
  4482. <c>MB</c> <c>0.692</c>
  4483. <c>WB</c> <c>0.706</c>
  4484. </texttable>
  4485. <t>
  4486. NB is given a smaller decoder delay allocation than MB and WB to allow a
  4487. higher-order filter when resampling to 8&nbsp;kHz in both the encoder and
  4488. decoder.
  4489. This implies that the audio content of two SILK frames operating at different
  4490. bandwidths are not perfectly aligned in time.
  4491. This is not an issue for any transitions described in
  4492. <xref target="switching"/>, because they all involve a SILK decoder reset.
  4493. When the decoder is reset, any samples remaining in the resampling buffer
  4494. are discarded, and the resampler is re-initialized with silence.
  4495. </t>
  4496. </section>
  4497. </section>
  4498. <section title="CELT Decoder">
  4499. <t>
  4500. The CELT layer of Opus is based on the Modified Discrete Cosine Transform
  4501. <xref target='MDCT'/> with partially overlapping windows of 5 to 22.5 ms.
  4502. The main principle behind CELT is that the MDCT spectrum is divided into
  4503. bands that (roughly) follow the Bark scale, i.e., the scale of the ear's
  4504. critical bands&nbsp;<xref target="Zwicker61"/>. The normal CELT layer uses 21 of those bands, though Opus
  4505. Custom (see <xref target="opus-custom"/>) may use a different number of bands.
  4506. In Hybrid mode, the first 17 bands (up to 8&nbsp;kHz) are not coded.
  4507. A band can contain as little as one MDCT bin per channel, and as many as 176
  4508. bins per channel, as detailed in <xref target="celt_band_sizes"/>.
  4509. In each band, the gain (energy) is coded separately from
  4510. the shape of the spectrum. Coding the gain explicitly makes it easy to
  4511. preserve the spectral envelope of the signal. The remaining unit-norm shape
  4512. vector is encoded using a Pyramid Vector Quantizer (PVQ)&nbsp;<xref target='PVQ-decoder'/>.
  4513. </t>
  4514. <texttable anchor="celt_band_sizes"
  4515. title="MDCT Bins Per Channel Per Band for Each Frame Size">
  4516. <ttcol>Frame Size:</ttcol>
  4517. <ttcol align="right">2.5&nbsp;ms</ttcol>
  4518. <ttcol align="right">5&nbsp;ms</ttcol>
  4519. <ttcol align="right">10&nbsp;ms</ttcol>
  4520. <ttcol align="right">20&nbsp;ms</ttcol>
  4521. <ttcol align="right">Start Frequency</ttcol>
  4522. <ttcol align="right">Stop Frequency</ttcol>
  4523. <c>Band</c> <c>Bins:</c> <c/> <c/> <c/> <c/> <c/>
  4524. <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>
  4525. <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>
  4526. <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>
  4527. <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>
  4528. <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>
  4529. <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>
  4530. <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>
  4531. <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>
  4532. <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>
  4533. <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>
  4534. <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>
  4535. <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>
  4536. <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>
  4537. <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>
  4538. <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>
  4539. <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>
  4540. <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>
  4541. <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>
  4542. <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>
  4543. <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>
  4544. <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>
  4545. </texttable>
  4546. <t>
  4547. Transients are notoriously difficult for transform codecs to code.
  4548. CELT uses two different strategies for them:
  4549. <list style="numbers">
  4550. <t>Using multiple smaller MDCTs instead of a single large MDCT, and</t>
  4551. <t>Dynamic time-frequency resolution changes (See <xref target='tf-change'/>).</t>
  4552. </list>
  4553. To improve quality on highly tonal and periodic signals, CELT includes
  4554. a prefilter/postfilter combination. The prefilter on the encoder side
  4555. attenuates the signal's harmonics. The postfilter on the decoder side
  4556. restores the original gain of the harmonics, while shaping the coding noise
  4557. to roughly follow the harmonics. Such noise shaping reduces the perception
  4558. of the noise.
  4559. </t>
  4560. <t>
  4561. When coding a stereo signal, three coding methods are available:
  4562. <list style="symbols">
  4563. <t>mid-side stereo: encodes the mean and the difference of the left and right channels,</t>
  4564. <t>intensity stereo: only encodes the mean of the left and right channels (discards the difference),</t>
  4565. <t>dual stereo: encodes the left and right channels separately.</t>
  4566. </list>
  4567. </t>
  4568. <t>
  4569. An overview of the decoder is given in <xref target="celt-decoder-overview"/>.
  4570. </t>
  4571. <figure anchor="celt-decoder-overview" title="Structure of the CELT decoder">
  4572. <artwork align="center"><![CDATA[
  4573. +---------+
  4574. | Coarse |
  4575. +->| decoder |----+
  4576. | +---------+ |
  4577. | |
  4578. | +---------+ v
  4579. | | Fine | +---+
  4580. +->| decoder |->| + |
  4581. | +---------+ +---+
  4582. | ^ |
  4583. +---------+ | | |
  4584. | Range | | +----------+ v
  4585. | Decoder |-+ | Bit | +------+
  4586. +---------+ | |Allocation| | 2**x |
  4587. | +----------+ +------+
  4588. | | |
  4589. | v v +--------+
  4590. | +---------+ +---+ +-------+ | pitch |
  4591. +->| PVQ |->| * |->| IMDCT |->| post- |--->
  4592. | | decoder | +---+ +-------+ | filter |
  4593. | +---------+ +--------+
  4594. | ^
  4595. +--------------------------------------+
  4596. ]]></artwork>
  4597. </figure>
  4598. <t>
  4599. The decoder is based on the following symbols and sets of symbols:
  4600. </t>
  4601. <texttable anchor="celt_symbols"
  4602. title="Order of the Symbols in the CELT Section of the Bitstream">
  4603. <ttcol align="center">Symbol(s)</ttcol>
  4604. <ttcol align="center">PDF</ttcol>
  4605. <ttcol align="center">Condition</ttcol>
  4606. <c>silence</c> <c>{32767, 1}/32768</c> <c></c>
  4607. <c>post-filter</c> <c>{1, 1}/2</c> <c></c>
  4608. <c>octave</c> <c>uniform (6)</c><c>post-filter</c>
  4609. <c>period</c> <c>raw bits (4+octave)</c><c>post-filter</c>
  4610. <c>gain</c> <c>raw bits (3)</c><c>post-filter</c>
  4611. <c>tapset</c> <c>{2, 1, 1}/4</c><c>post-filter</c>
  4612. <c>transient</c> <c>{7, 1}/8</c><c></c>
  4613. <c>intra</c> <c>{7, 1}/8</c><c></c>
  4614. <c>coarse energy</c><c><xref target="energy-decoding"/></c><c></c>
  4615. <c>tf_change</c> <c><xref target="transient-decoding"/></c><c></c>
  4616. <c>tf_select</c> <c>{1, 1}/2</c><c><xref target="transient-decoding"/></c>
  4617. <c>spread</c> <c>{7, 2, 21, 2}/32</c><c></c>
  4618. <c>dyn. alloc.</c> <c><xref target="allocation"/></c><c></c>
  4619. <c>alloc. trim</c> <c>{2, 2, 5, 10, 22, 46, 22, 10, 5, 2, 2}/128</c><c></c>
  4620. <c>skip</c> <c>{1, 1}/2</c><c><xref target="allocation"/></c>
  4621. <c>intensity</c> <c>uniform</c><c><xref target="allocation"/></c>
  4622. <c>dual</c> <c>{1, 1}/2</c><c></c>
  4623. <c>fine energy</c> <c><xref target="energy-decoding"/></c><c></c>
  4624. <c>residual</c> <c><xref target="PVQ-decoder"/></c><c></c>
  4625. <c>anti-collapse</c><c>{1, 1}/2</c><c><xref target="anti-collapse"/></c>
  4626. <c>finalize</c> <c><xref target="energy-decoding"/></c><c></c>
  4627. </texttable>
  4628. <t>
  4629. The decoder extracts information from the range-coded bitstream in the order
  4630. described in <xref target='celt_symbols'/>. In some circumstances, it is
  4631. possible for a decoded value to be out of range due to a very small amount of redundancy
  4632. in the encoding of large integers by the range coder.
  4633. In that case, the decoder should assume there has been an error in the coding,
  4634. decoding, or transmission and SHOULD take measures to conceal the error and/or report
  4635. to the application that a problem has occurred. Such out of range errors cannot occur
  4636. in the SILK layer.
  4637. </t>
  4638. <section anchor="transient-decoding" title="Transient Decoding">
  4639. <t>
  4640. The "transient" flag indicates whether the frame uses a single long MDCT or several short MDCTs.
  4641. When it is set, then the MDCT coefficients represent multiple
  4642. short MDCTs in the frame. When not set, the coefficients represent a single
  4643. long MDCT for the frame. The flag is encoded in the bitstream with a probability of 1/8.
  4644. In addition to the global transient flag is a per-band
  4645. binary flag to change the time-frequency (tf) resolution independently in each band. The
  4646. change in tf resolution is defined in tf_select_table[][] in celt.c and depends
  4647. on the frame size, whether the transient flag is set, and the value of tf_select.
  4648. The tf_select flag uses a 1/2 probability, but is only decoded
  4649. if it can have an impact on the result knowing the value of all per-band
  4650. tf_change flags.
  4651. </t>
  4652. </section>
  4653. <section anchor="energy-decoding" title="Energy Envelope Decoding">
  4654. <t>
  4655. It is important to quantize the energy with sufficient resolution because
  4656. any energy quantization error cannot be compensated for at a later
  4657. stage. Regardless of the resolution used for encoding the spectral shape of a band,
  4658. it is perceptually important to preserve the energy in each band. CELT uses a
  4659. three-step coarse-fine-fine strategy for encoding the energy in the base-2 log
  4660. domain, as implemented in quant_bands.c</t>
  4661. <section anchor="coarse-energy-decoding" title="Coarse energy decoding">
  4662. <t>
  4663. Coarse quantization of the energy uses a fixed resolution of 6 dB
  4664. (integer part of base-2 log). To minimize the bitrate, prediction is applied
  4665. both in time (using the previous frame) and in frequency (using the previous
  4666. bands). The part of the prediction that is based on the
  4667. previous frame can be disabled, creating an "intra" frame where the energy
  4668. is coded without reference to prior frames. The decoder first reads the intra flag
  4669. to determine what prediction is used.
  4670. The 2-D z-transform <xref target='z-transform'/> of
  4671. the prediction filter is:
  4672. <figure align="center">
  4673. <artwork align="center"><![CDATA[
  4674. -1 -1
  4675. (1 - alpha*z_l )*(1 - z_b )
  4676. A(z_l, z_b) = -----------------------------
  4677. -1
  4678. 1 - beta*z_b
  4679. ]]></artwork>
  4680. </figure>
  4681. where b is the band index and l is the frame index. The prediction coefficients
  4682. applied depend on the frame size in use when not using intra energy and are alpha=0, beta=4915/32768
  4683. when using intra energy.
  4684. The time-domain prediction is based on the final fine quantization of the previous
  4685. frame, while the frequency domain (within the current frame) prediction is based
  4686. on coarse quantization only (because the fine quantization has not been computed
  4687. yet). The prediction is clamped internally so that fixed point implementations with
  4688. limited dynamic range always remain in the same state as floating point implementations.
  4689. We approximate the ideal
  4690. probability distribution of the prediction error using a Laplace distribution
  4691. with separate parameters for each frame size in intra- and inter-frame modes. These
  4692. parameters are held in the e_prob_model table in quant_bands.c.
  4693. The
  4694. coarse energy quantization is performed by unquant_coarse_energy() and
  4695. unquant_coarse_energy_impl() (quant_bands.c). The encoding of the Laplace-distributed values is
  4696. implemented in ec_laplace_decode() (laplace.c).
  4697. </t>
  4698. </section>
  4699. <section anchor="fine-energy-decoding" title="Fine energy quantization">
  4700. <t>
  4701. The number of bits assigned to fine energy quantization in each band is determined
  4702. by the bit allocation computation described in <xref target="allocation"></xref>.
  4703. Let B_i be the number of fine energy bits
  4704. for band i; the refinement is an integer f in the range [0,2**B_i-1]. The mapping between f
  4705. and the correction applied to the coarse energy is equal to (f+1/2)/2**B_i - 1/2. Fine
  4706. energy quantization is implemented in quant_fine_energy() (quant_bands.c).
  4707. </t>
  4708. <t>
  4709. When some bits are left "unused" after all other flags have been decoded, these bits
  4710. are assigned to a "final" step of fine allocation. In effect, these bits are used
  4711. to add one extra fine energy bit per band per channel. The allocation process
  4712. determines two "priorities" for the final fine bits.
  4713. Any remaining bits are first assigned only to bands of priority 0, starting
  4714. from band 0 and going up. If all bands of priority 0 have received one bit per
  4715. channel, then bands of priority 1 are assigned an extra bit per channel,
  4716. starting from band 0. If any bits are left after this, they are left unused.
  4717. This is implemented in unquant_energy_finalise() (quant_bands.c).
  4718. </t>
  4719. </section> <!-- fine energy -->
  4720. </section> <!-- Energy decode -->
  4721. <section anchor="allocation" title="Bit Allocation">
  4722. <t>Because the bit allocation drives the decoding of the range-coder
  4723. stream, it MUST be recovered exactly so that identical coding decisions are
  4724. made in the encoder and decoder. Any deviation from the reference's resulting
  4725. bit allocation will result in corrupted output, though implementers are
  4726. free to implement the procedure in any way which produces identical results.</t>
  4727. <t>The per-band gain-shape structure of the CELT layer ensures that using
  4728. the same number of bits for the spectral shape of a band in every frame will
  4729. result in a roughly constant signal-to-noise ratio in that band.
  4730. This results in coding noise that has the same spectral envelope as the signal.
  4731. The masking curve produced by a standard psychoacoustic model also closely
  4732. follows the spectral envelope of the signal.
  4733. This structure means that the ideal allocation is more consistent from frame to
  4734. frame than it is for other codecs without an equivalent structure, and that a
  4735. fixed allocation provides fairly consistent perceptual
  4736. performance&nbsp;<xref target='Valin2010'/>.</t>
  4737. <t>Many codecs transmit significant amounts of side information to control the
  4738. bit allocation within a frame.
  4739. Often this control is only indirect, and must be exercised carefully to
  4740. achieve the desired rate constraints.
  4741. The CELT layer, however, can adapt over a very wide range of rates, and thus
  4742. has a large number of codebook sizes to choose from for each band.
  4743. Explicitly signaling the size of each of these codebooks would impose
  4744. considerable overhead, even though the allocation is relatively static from
  4745. frame to frame.
  4746. This is because all of the information required to compute these codebook sizes
  4747. must be derived from a single frame by itself, in order to retain robustness
  4748. to packet loss, so the signaling cannot take advantage of knowledge of the
  4749. allocation in neighboring frames.
  4750. This problem is exacerbated in low-latency (small frame size) applications,
  4751. which would include this overhead in every frame.</t>
  4752. <t>For this reason, in the MDCT mode Opus uses a primarily implicit bit
  4753. allocation. The available bitstream capacity is known in advance to both
  4754. the encoder and decoder without additional signaling, ultimately from the
  4755. packet sizes expressed by a higher-level protocol. Using this information,
  4756. the codec interpolates an allocation from a hard-coded table.</t>
  4757. <t>While the band-energy structure effectively models intra-band masking,
  4758. it ignores the weaker inter-band masking, band-temporal masking, and
  4759. other less significant perceptual effects. While these effects can
  4760. often be ignored, they can become significant for particular samples. One
  4761. mechanism available to encoders would be to simply increase the overall
  4762. rate for these frames, but this is not possible in a constant rate mode
  4763. and can be fairly inefficient. As a result three explicitly signaled
  4764. mechanisms are provided to alter the implicit allocation:</t>
  4765. <t>
  4766. <list style="symbols">
  4767. <t>Band boost</t>
  4768. <t>Allocation trim</t>
  4769. <t>Band skipping</t>
  4770. </list>
  4771. </t>
  4772. <t>The first of these mechanisms, band boost, allows an encoder to boost
  4773. the allocation in specific bands. The second, allocation trim, works by
  4774. biasing the overall allocation towards higher or lower frequency bands. The third, band
  4775. skipping, selects which low-precision high frequency bands
  4776. will be allocated no shape bits at all.</t>
  4777. <t>In stereo mode there are two additional parameters
  4778. potentially coded as part of the allocation procedure: a parameter to allow the
  4779. selective elimination of allocation for the 'side' (i.e., intensity stereo) in jointly coded bands,
  4780. and a flag to deactivate joint coding (i.e., dual stereo). These values are not signaled if
  4781. they would be meaningless in the overall context of the allocation.</t>
  4782. <t>Because every signaled adjustment increases overhead and implementation
  4783. complexity, none were included speculatively: the reference encoder makes use
  4784. of all of these mechanisms. While the decision logic in the reference was
  4785. found to be effective enough to justify the overhead and complexity, further
  4786. analysis techniques may be discovered which increase the effectiveness of these
  4787. parameters. As with other signaled parameters, an encoder is free to choose the
  4788. values in any manner, but unless a technique is known to deliver superior
  4789. perceptual results the methods used by the reference implementation should be
  4790. used.</t>
  4791. <t>The allocation process consists of the following steps: determining the per-band
  4792. maximum allocation vector, decoding the boosts, decoding the tilt, determining
  4793. the remaining capacity of the frame, searching the mode table for the
  4794. entry nearest but not exceeding the available space (subject to the tilt, boosts, band
  4795. maximums, and band minimums), linear interpolation, reallocation of
  4796. unused bits with concurrent skip decoding, determination of the
  4797. fine-energy vs. shape split, and final reallocation. This process results
  4798. in a per-band shape allocation (in 1/8th bit units), a per-band fine-energy
  4799. allocation (in 1 bit per channel units), a set of band priorities for
  4800. controlling the use of remaining bits at the end of the frame, and a
  4801. remaining balance of unallocated space, which is usually zero except
  4802. at very high rates.</t>
  4803. <t>
  4804. The "static" bit allocation (in 1/8 bits) for a quality q, excluding the minimums, maximums,
  4805. tilt and boosts, is equal to channels*N*alloc[band][q]&lt;&lt;LM&gt;&gt;2, where
  4806. alloc[][] is given in <xref target="static_alloc"/> and LM=log2(frame_size/120). The allocation
  4807. is obtained by linearly interpolating between two values of q (in steps of 1/64) to find the
  4808. highest allocation that does not exceed the number of bits remaining.
  4809. </t>
  4810. <texttable anchor="static_alloc"
  4811. title="CELT Static Allocation Table">
  4812. <preamble>Rows indicate the MDCT bands, columns are the different quality (q) parameters. The units are 1/32 bit per MDCT bin.</preamble>
  4813. <ttcol align="right">0</ttcol>
  4814. <ttcol align="right">1</ttcol>
  4815. <ttcol align="right">2</ttcol>
  4816. <ttcol align="right">3</ttcol>
  4817. <ttcol align="right">4</ttcol>
  4818. <ttcol align="right">5</ttcol>
  4819. <ttcol align="right">6</ttcol>
  4820. <ttcol align="right">7</ttcol>
  4821. <ttcol align="right">8</ttcol>
  4822. <ttcol align="right">9</ttcol>
  4823. <ttcol align="right">10</ttcol>
  4824. <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>
  4825. <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>
  4826. <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>
  4827. <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>
  4828. <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>
  4829. <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>
  4830. <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>
  4831. <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>
  4832. <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>
  4833. <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>
  4834. <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>
  4835. <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>
  4836. <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>
  4837. <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>
  4838. <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>
  4839. <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>
  4840. <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>
  4841. <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>
  4842. <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>
  4843. <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>
  4844. <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>
  4845. </texttable>
  4846. <t>The maximum allocation vector is an approximation of the maximum space
  4847. that can be used by each band for a given mode. The value is
  4848. approximate because the shape encoding is variable rate (due
  4849. to entropy coding of splitting parameters). Setting the maximum too low reduces the
  4850. maximum achievable quality in a band while setting it too high
  4851. may result in waste: bitstream capacity available at the end
  4852. of the frame which can not be put to any use. The maximums
  4853. specified by the codec reflect the average maximum. In the reference
  4854. implementation, the maximums in bits/sample are precomputed in a static table
  4855. (see cache_caps50[] in static_modes_float.h) for each band,
  4856. for each value of LM, and for both mono and stereo.
  4857. Implementations are expected
  4858. to simply use the same table data, but the procedure for generating
  4859. this table is included in rate.c as part of compute_pulse_cache().</t>
  4860. <t>To convert the values in cache.caps into the actual maximums: first
  4861. set nbBands to the maximum number of bands for this mode, and stereo to
  4862. zero if stereo is not in use and one otherwise. For each band set N
  4863. to the number of MDCT bins covered by the band (for one channel), set LM
  4864. to the shift value for the frame size,
  4865. then set i to nbBands*(2*LM+stereo). Then set the maximum for the band to
  4866. the i-th index of cache.caps + 64 and multiply by the number of channels
  4867. in the current frame (one or two) and by N, then divide the result by 4
  4868. using integer division. The resulting vector will be called
  4869. cap[]. The elements fit in signed 16-bit integers but do not fit in 8 bits.
  4870. This procedure is implemented in the reference in the function init_caps() in celt.c.
  4871. </t>
  4872. <t>The band boosts are represented by a series of binary symbols which
  4873. are entropy coded with very low probability. Each band can potentially be boosted
  4874. multiple times, subject to the frame actually having enough room to obey
  4875. the boost and having enough room to code the boost symbol. The default
  4876. coding cost for a boost starts out at six bits (probability p=1/64), but subsequent boosts
  4877. in a band cost only a single bit and every time a band is boosted the
  4878. initial cost is reduced (down to a minimum of two bits, or p=1/4). Since the initial
  4879. cost of coding a boost is 6 bits, the coding cost of the boost symbols when
  4880. completely unused is 0.48 bits/frame for a 21 band mode (21*-log2(1-1/2**6)).</t>
  4881. <t>To decode the band boosts: First set 'dynalloc_logp' to 6, the initial
  4882. amount of storage required to signal a boost in bits, 'total_bits' to the
  4883. size of the frame in 8th bits, 'total_boost' to zero, and 'tell' to the total number
  4884. of 8th bits decoded
  4885. so far. For each band from the coding start (0 normally, but 17 in Hybrid mode)
  4886. to the coding end (which changes depending on the signaled bandwidth), the boost quanta
  4887. in units of 1/8 bit is calculated as quanta = min(8*N, max(48, N)).
  4888. This represents a boost step size of six bits, subject to a lower limit of
  4889. 1/8th&nbsp;bit/sample and an upper limit of 1&nbsp;bit/sample.
  4890. Set 'boost' to zero and 'dynalloc_loop_logp'
  4891. to dynalloc_logp. While dynalloc_loop_log (the current worst case symbol cost) in
  4892. 8th bits plus tell is less than total_bits plus total_boost and boost is less than cap[] for this
  4893. band: Decode a bit from the bitstream with a with dynalloc_loop_logp as the cost
  4894. of a one, update tell to reflect the current used capacity, if the decoded value
  4895. is zero break the loop otherwise add quanta to boost and total_boost, subtract quanta from
  4896. total_bits, and set dynalloc_loop_log to 1. When the while loop finishes
  4897. boost contains the boost for this band. If boost is non-zero and dynalloc_logp
  4898. is greater than 2, decrease dynalloc_logp. Once this process has been
  4899. executed on all bands, the band boosts have been decoded. This procedure
  4900. is implemented around line 2474 of celt.c.</t>
  4901. <t>At very low rates it is possible that there won't be enough available
  4902. space to execute the inner loop even once. In these cases band boost
  4903. is not possible but its overhead is completely eliminated. Because of the
  4904. high cost of band boost when activated, a reasonable encoder should not be
  4905. using it at very low rates. The reference implements its dynalloc decision
  4906. logic around line 1304 of celt.c.</t>
  4907. <t>The allocation trim is a integer value from 0-10. The default value of
  4908. 5 indicates no trim. The trim parameter is entropy coded in order to
  4909. lower the coding cost of less extreme adjustments. Values lower than
  4910. 5 bias the allocation towards lower frequencies and values above 5
  4911. bias it towards higher frequencies. Like other signaled parameters, signaling
  4912. of the trim is gated so that it is not included if there is insufficient space
  4913. available in the bitstream. To decode the trim, first set
  4914. the trim value to 5, then if and only if the count of decoded 8th bits so far (ec_tell_frac)
  4915. plus 48 (6 bits) is less than or equal to the total frame size in 8th
  4916. bits minus total_boost (a product of the above band boost procedure),
  4917. decode the trim value using the PDF in <xref target="celt_trim_pdf"/>.</t>
  4918. <texttable anchor="celt_trim_pdf" title="PDF for the Trim">
  4919. <ttcol>PDF</ttcol>
  4920. <c>{1, 1, 2, 5, 10, 22, 46, 22, 10, 5, 2, 2}/128</c>
  4921. </texttable>
  4922. <t>For 10 ms and 20 ms frames using short blocks and that have at least LM+2 bits left prior to
  4923. the allocation process, then one anti-collapse bit is reserved in the allocation process so it can
  4924. be decoded later. Following the the anti-collapse reservation, one bit is reserved for skip if available.</t>
  4925. <t>For stereo frames, bits are reserved for intensity stereo and for dual stereo. Intensity stereo
  4926. requires ilog2(end-start) bits. Those bits are reserved if there is enough bits left. Following this, one
  4927. bit is reserved for dual stereo if available.</t>
  4928. <t>The allocation computation begins by setting up some initial conditions.
  4929. 'total' is set to the remaining available 8th bits, computed by taking the
  4930. size of the coded frame times 8 and subtracting ec_tell_frac(). From this value, one (8th bit)
  4931. is subtracted to ensure that the resulting allocation will be conservative. 'anti_collapse_rsv'
  4932. is set to 8 (8th bits) if and only if the frame is a transient, LM is greater than 1, and total is
  4933. greater than or equal to (LM+2) * 8. Total is then decremented by anti_collapse_rsv and clamped
  4934. to be equal to or greater than zero. 'skip_rsv' is set to 8 (8th bits) if total is greater than
  4935. 8, otherwise it is zero. Total is then decremented by skip_rsv. This reserves space for the
  4936. final skipping flag.</t>
  4937. <t>If the current frame is stereo, intensity_rsv is set to the conservative log2 in 8th bits
  4938. of the number of coded bands for this frame (given by the table LOG2_FRAC_TABLE in rate.c). If
  4939. intensity_rsv is greater than total then intensity_rsv is set to zero. Otherwise total is
  4940. decremented by intensity_rsv, and if total is still greater than 8, dual_stereo_rsv is
  4941. set to 8 and total is decremented by dual_stereo_rsv.</t>
  4942. <t>The allocation process then computes a vector representing the hard minimum amounts allocation
  4943. any band will receive for shape. This minimum is higher than the technical limit of the PVQ
  4944. process, but very low rate allocations produce an excessively sparse spectrum and these bands
  4945. are better served by having no allocation at all. For each coded band, set thresh[band] to
  4946. twenty-four times the number of MDCT bins in the band and divide by 16. If 8 times the number
  4947. of channels is greater, use that instead. This sets the minimum allocation to one bit per channel
  4948. or 48 128th bits per MDCT bin, whichever is greater. The band-size dependent part of this
  4949. value is not scaled by the channel count, because at the very low rates where this limit is
  4950. applicable there will usually be no bits allocated to the side.</t>
  4951. <t>The previously decoded allocation trim is used to derive a vector of per-band adjustments,
  4952. 'trim_offsets[]'. For each coded band take the alloc_trim and subtract 5 and LM. Then multiply
  4953. the result by the number of channels, the number of MDCT bins in the shortest frame size for this mode,
  4954. the number of remaining bands, 2**LM, and 8. Then divide this value by 64. Finally, if the
  4955. number of MDCT bins in the band per channel is only one, 8 times the number of channels is subtracted
  4956. in order to diminish the allocation by one bit, because width 1 bands receive greater benefit
  4957. from the coarse energy coding.</t>
  4958. </section>
  4959. <section anchor="PVQ-decoder" title="Shape Decoding">
  4960. <t>
  4961. In each band, the normalized "shape" is encoded
  4962. using a vector quantization scheme called a "pyramid vector quantizer".
  4963. </t>
  4964. <t>In
  4965. the simplest case, the number of bits allocated in
  4966. <xref target="allocation"></xref> is converted to a number of pulses as described
  4967. by <xref target="bits-pulses"></xref>. Knowing the number of pulses and the
  4968. number of samples in the band, the decoder calculates the size of the codebook
  4969. as detailed in <xref target="cwrs-decoder"></xref>. The size is used to decode
  4970. an unsigned integer (uniform probability model), which is the codeword index.
  4971. This index is converted into the corresponding vector as explained in
  4972. <xref target="cwrs-decoder"></xref>. This vector is then scaled to unit norm.
  4973. </t>
  4974. <section anchor="bits-pulses" title="Bits to Pulses">
  4975. <t>
  4976. Although the allocation is performed in 1/8th bit units, the quantization requires
  4977. an integer number of pulses K. To do this, the encoder searches for the value
  4978. of K that produces the number of bits nearest to the allocated value
  4979. (rounding down if exactly halfway between two values), not to exceed
  4980. the total number of bits available. For efficiency reasons, the search is performed against a
  4981. precomputed allocation table which only permits some K values for each N. The number of
  4982. codebook entries can be computed as explained in <xref target="cwrs-decoder"></xref>. The difference
  4983. between the number of bits allocated and the number of bits used is accumulated to a
  4984. "balance" (initialized to zero) that helps adjust the
  4985. allocation for the next bands. One third of the balance is applied to the
  4986. bit allocation of each band to help achieve the target allocation. The only
  4987. exceptions are the band before the last and the last band, for which half the balance
  4988. and the whole balance are applied, respectively.
  4989. </t>
  4990. </section>
  4991. <section anchor="cwrs-decoder" title="PVQ Decoding">
  4992. <t>
  4993. Decoding of PVQ vectors is implemented in decode_pulses() (cwrs.c).
  4994. The unique codeword index is decoded as a uniformly-distributed integer value between 0 and
  4995. V(N,K)-1, where V(N,K) is the number of possible combinations of K pulses in
  4996. N samples. The index is then converted to a vector in the same way specified in
  4997. <xref target="PVQ"></xref>. The indexing is based on the calculation of V(N,K)
  4998. (denoted N(L,K) in <xref target="PVQ"></xref>).
  4999. </t>
  5000. <t>
  5001. The number of combinations can be computed recursively as
  5002. 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.
  5003. There are many different ways to compute V(N,K), including precomputed tables and direct
  5004. use of the recursive formulation. The reference implementation applies the recursive
  5005. formulation one line (or column) at a time to save on memory use,
  5006. along with an alternate,
  5007. univariate recurrence to initialize an arbitrary line, and direct
  5008. polynomial solutions for small N. All of these methods are
  5009. equivalent, and have different trade-offs in speed, memory usage, and
  5010. code size. Implementations MAY use any methods they like, as long as
  5011. they are equivalent to the mathematical definition.
  5012. </t>
  5013. <t>
  5014. The decoded vector X is recovered as follows.
  5015. Let i be the index decoded with the procedure in <xref target="ec_dec_uint"/>
  5016. with ft&nbsp;=&nbsp;V(N,K), so that 0&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;V(N,K).
  5017. Let k&nbsp;=&nbsp;K.
  5018. Then for j&nbsp;=&nbsp;0 to (N&nbsp;-&nbsp;1), inclusive, do:
  5019. <list style="numbers">
  5020. <t>Let p&nbsp;=&nbsp;(V(N-j-1,k)&nbsp;+&nbsp;V(N-j,k))/2.</t>
  5021. <t>
  5022. If i&nbsp;&lt;&nbsp;p, then let sgn&nbsp;=&nbsp;1, else let sgn&nbsp;=&nbsp;-1
  5023. and set i&nbsp;=&nbsp;i&nbsp;-&nbsp;p.
  5024. </t>
  5025. <t>Let k0&nbsp;=&nbsp;k and set p&nbsp;=&nbsp;p&nbsp;-&nbsp;V(N-j-1,k).</t>
  5026. <t>
  5027. While p&nbsp;&gt;&nbsp;i, set k&nbsp;=&nbsp;k&nbsp;-&nbsp;1 and
  5028. p&nbsp;=&nbsp;p&nbsp;-&nbsp;V(N-j-1,k).
  5029. </t>
  5030. <t>
  5031. Set X[j]&nbsp;=&nbsp;sgn*(k0&nbsp;-&nbsp;k) and i&nbsp;=&nbsp;i&nbsp;-&nbsp;p.
  5032. </t>
  5033. </list>
  5034. </t>
  5035. <t>
  5036. The decoded vector X is then normalized such that its
  5037. L2-norm equals one.
  5038. </t>
  5039. </section>
  5040. <section anchor="spreading" title="Spreading">
  5041. <t>
  5042. The normalized vector decoded in <xref target="cwrs-decoder"/> is then rotated
  5043. for the purpose of avoiding tonal artifacts. The rotation gain is equal to
  5044. <figure align="center">
  5045. <artwork align="center"><![CDATA[
  5046. g_r = N / (N + f_r*K)
  5047. ]]></artwork>
  5048. </figure>
  5049. where N is the number of dimensions, K is the number of pulses, and f_r depends on
  5050. the value of the "spread" parameter in the bit-stream.
  5051. </t>
  5052. <texttable anchor="spread values" title="Spreading Values">
  5053. <ttcol>Spread value</ttcol>
  5054. <ttcol>f_r</ttcol>
  5055. <c>0</c> <c>infinite (no rotation)</c>
  5056. <c>1</c> <c>15</c>
  5057. <c>2</c> <c>10</c>
  5058. <c>3</c> <c>5</c>
  5059. </texttable>
  5060. <t>
  5061. The rotation angle is then calculated as
  5062. <figure align="center">
  5063. <artwork align="center"><![CDATA[
  5064. 2
  5065. pi * g_r
  5066. theta = ----------
  5067. 4
  5068. ]]></artwork>
  5069. </figure>
  5070. A 2-D rotation R(i,j) between points x_i and x_j is defined as:
  5071. <figure align="center">
  5072. <artwork align="center"><![CDATA[
  5073. x_i' = cos(theta)*x_i + sin(theta)*x_j
  5074. x_j' = -sin(theta)*x_i + cos(theta)*x_j
  5075. ]]></artwork>
  5076. </figure>
  5077. An N-D rotation is then achieved by applying a series of 2-D rotations back and forth, in the
  5078. 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),
  5079. R(x_N-2, X_N-1), ..., R(x_1, x_2).
  5080. </t>
  5081. <t>
  5082. If the decoded vector represents more
  5083. than one time block, then this spreading process is applied separately on each time block.
  5084. Also, if each block represents 8 samples or more, then another N-D rotation, by
  5085. (pi/2-theta), is applied <spanx style="emph">before</spanx> the rotation described above. This
  5086. extra rotation is applied in an interleaved manner with a stride equal to round(sqrt(N/nb_blocks)),
  5087. i.e., it is applied independently for each set of sample S_k = {stride*n + k}, n=0..N/stride-1.
  5088. </t>
  5089. </section>
  5090. <section anchor="split" title="Split decoding">
  5091. <t>
  5092. To avoid the need for multi-precision calculations when decoding PVQ codevectors,
  5093. the maximum size allowed for codebooks is 32 bits. When larger codebooks are
  5094. needed, the vector is instead split in two sub-vectors of size N/2.
  5095. A quantized gain parameter with precision
  5096. derived from the current allocation is entropy coded to represent the relative
  5097. gains of each side of the split, and the entire decoding process is recursively
  5098. applied. Multiple levels of splitting may be applied up to a limit of LM+1 splits.
  5099. The same recursive mechanism is applied for the joint coding
  5100. of stereo audio.
  5101. </t>
  5102. </section>
  5103. <section anchor="tf-change" title="Time-Frequency change">
  5104. <t>
  5105. The time-frequency (TF) parameters are used to control the time-frequency resolution tradeoff
  5106. in each coded band. For each band, there are two possible TF choices. For the first
  5107. band coded, the PDF is {3, 1}/4 for frames marked as transient and {15, 1}/16 for
  5108. the other frames. For subsequent bands, the TF choice is coded relative to the
  5109. previous TF choice with probability {15, 1}/15 for transient frames and {31, 1}/32
  5110. otherwise. The mapping between the decoded TF choices and the adjustment in TF
  5111. resolution is shown in the tables below.
  5112. </t>
  5113. <texttable anchor='tf_00'
  5114. title="TF Adjustments for Non-transient Frames and tf_select=0">
  5115. <ttcol align='center'>Frame size (ms)</ttcol>
  5116. <ttcol align='center'>0</ttcol>
  5117. <ttcol align='center'>1</ttcol>
  5118. <c>2.5</c> <c>0</c> <c>-1</c>
  5119. <c>5</c> <c>0</c> <c>-1</c>
  5120. <c>10</c> <c>0</c> <c>-2</c>
  5121. <c>20</c> <c>0</c> <c>-2</c>
  5122. </texttable>
  5123. <texttable anchor='tf_01'
  5124. title="TF Adjustments for Non-transient Frames and tf_select=1">
  5125. <ttcol align='center'>Frame size (ms)</ttcol>
  5126. <ttcol align='center'>0</ttcol>
  5127. <ttcol align='center'>1</ttcol>
  5128. <c>2.5</c> <c>0</c> <c>-1</c>
  5129. <c>5</c> <c>0</c> <c>-2</c>
  5130. <c>10</c> <c>0</c> <c>-3</c>
  5131. <c>20</c> <c>0</c> <c>-3</c>
  5132. </texttable>
  5133. <texttable anchor='tf_10'
  5134. title="TF Adjustments for Transient Frames and tf_select=0">
  5135. <ttcol align='center'>Frame size (ms)</ttcol>
  5136. <ttcol align='center'>0</ttcol>
  5137. <ttcol align='center'>1</ttcol>
  5138. <c>2.5</c> <c>0</c> <c>-1</c>
  5139. <c>5</c> <c>1</c> <c>0</c>
  5140. <c>10</c> <c>2</c> <c>0</c>
  5141. <c>20</c> <c>3</c> <c>0</c>
  5142. </texttable>
  5143. <texttable anchor='tf_11'
  5144. title="TF Adjustments for Transient Frames and tf_select=1">
  5145. <ttcol align='center'>Frame size (ms)</ttcol>
  5146. <ttcol align='center'>0</ttcol>
  5147. <ttcol align='center'>1</ttcol>
  5148. <c>2.5</c> <c>0</c> <c>-1</c>
  5149. <c>5</c> <c>1</c> <c>-1</c>
  5150. <c>10</c> <c>1</c> <c>-1</c>
  5151. <c>20</c> <c>1</c> <c>-1</c>
  5152. </texttable>
  5153. <t>
  5154. A negative TF adjustment means that the temporal resolution is increased,
  5155. while a positive TF adjustment means that the frequency resolution is increased.
  5156. Changes in TF resolution are implemented using the Hadamard transform <xref target="Hadamard"/>. To increase
  5157. the time resolution by N, N "levels" of the Hadamard transform are applied to the
  5158. decoded vector for each interleaved MDCT vector. To increase the frequency resolution
  5159. (assumes a transient frame), then N levels of the Hadamard transform are applied
  5160. <spanx style="emph">across</spanx> the interleaved MDCT vector. In the case of increased
  5161. time resolution the decoder uses the "sequency order" because the input vector
  5162. is sorted in time.
  5163. </t>
  5164. </section>
  5165. </section>
  5166. <section anchor="anti-collapse" title="Anti-Collapse Processing">
  5167. <t>
  5168. The anti-collapse feature is designed to avoid the situation where the use of multiple
  5169. short MDCTs causes the energy in one or more of the MDCTs to be zero for
  5170. some bands, causing unpleasant artifacts.
  5171. When the frame has the transient bit set, an anti-collapse bit is decoded.
  5172. When anti-collapse is set, the energy in each small MDCT is prevented
  5173. from collapsing to zero. For each band of each MDCT where a collapse is
  5174. detected, a pseudo-random signal is inserted with an energy corresponding
  5175. to the minimum energy over the two previous frames. A renormalization step is
  5176. then required to ensure that the anti-collapse step did not alter the
  5177. energy preservation property.
  5178. </t>
  5179. </section>
  5180. <section anchor="denormalization" title="Denormalization">
  5181. <t>
  5182. Just as each band was normalized in the encoder, the last step of the decoder before
  5183. the inverse MDCT is to denormalize the bands. Each decoded normalized band is
  5184. multiplied by the square root of the decoded energy. This is done by denormalise_bands()
  5185. (bands.c).
  5186. </t>
  5187. </section>
  5188. <section anchor="inverse-mdct" title="Inverse MDCT">
  5189. <t>The inverse MDCT implementation has no special characteristics. The
  5190. input is N frequency-domain samples and the output is 2*N time-domain
  5191. samples, while scaling by 1/2. A "low-overlap" window reduces the algorithmic delay.
  5192. It is derived from a basic (full overlap) 240-sample version of the window used by the Vorbis codec:
  5193. <figure align="center">
  5194. <artwork align="center"><![CDATA[
  5195. 2
  5196. / /pi /pi n + 1/2\ \ \
  5197. W(n) = |sin|-- * sin|-- * -------| | | .
  5198. \ \2 \2 L / / /
  5199. ]]></artwork>
  5200. </figure>
  5201. The low-overlap window is created by zero-padding the basic window and inserting ones in the
  5202. middle, such that the resulting window still satisfies power complementarity <xref target='Princen86'/>.
  5203. The IMDCT and
  5204. windowing are performed by mdct_backward (mdct.c).
  5205. </t>
  5206. <section anchor="post-filter" title="Post-filter">
  5207. <t>
  5208. The output of the inverse MDCT (after weighted overlap-add) is sent to the
  5209. post-filter. Although the post-filter is applied at the end, the post-filter
  5210. parameters are encoded at the beginning, just after the silence flag.
  5211. The post-filter can be switched on or off using one bit (logp=1).
  5212. If the post-filter is enabled, then the octave is decoded as an integer value
  5213. between 0 and 6 of uniform probability. Once the octave is known, the fine pitch
  5214. within the octave is decoded using 4+octave raw bits. The final pitch period
  5215. is equal to (16&lt;&lt;octave)+fine_pitch-1 so it is bounded between 15 and 1022,
  5216. inclusively. Next, the gain is decoded as three raw bits and is equal to
  5217. G=3*(int_gain+1)/32. The set of post-filter taps is decoded last, using
  5218. a pdf equal to {2, 1, 1}/4. Tapset zero corresponds to the filter coefficients
  5219. g0 = 0.3066406250, g1 = 0.2170410156, g2 = 0.1296386719. Tapset one
  5220. corresponds to the filter coefficients g0 = 0.4638671875, g1 = 0.2680664062,
  5221. g2 = 0, and tapset two uses filter coefficients g0 = 0.7998046875,
  5222. g1 = 0.1000976562, g2 = 0.
  5223. </t>
  5224. <t>
  5225. The post-filter response is thus computed as:
  5226. <figure align="center">
  5227. <artwork align="center">
  5228. <![CDATA[
  5229. y(n) = x(n) + G*(g0*y(n-T) + g1*(y(n-T+1)+y(n-T+1))
  5230. + g2*(y(n-T+2)+y(n-T+2)))
  5231. ]]>
  5232. </artwork>
  5233. </figure>
  5234. During a transition between different gains, a smooth transition is calculated
  5235. using the square of the MDCT window. It is important that values of y(n) be
  5236. interpolated one at a time such that the past value of y(n) used is interpolated.
  5237. </t>
  5238. </section>
  5239. <section anchor="deemphasis" title="De-emphasis">
  5240. <t>
  5241. After the post-filter,
  5242. the signal is de-emphasized using the inverse of the pre-emphasis filter
  5243. used in the encoder:
  5244. <figure align="center">
  5245. <artwork align="center"><![CDATA[
  5246. 1 1
  5247. ---- = --------------- ,
  5248. A(z) -1
  5249. 1 - alpha_p*z
  5250. ]]></artwork>
  5251. </figure>
  5252. where alpha_p=0.8500061035.
  5253. </t>
  5254. </section>
  5255. </section>
  5256. </section>
  5257. <section anchor="Packet Loss Concealment" title="Packet Loss Concealment (PLC)">
  5258. <t>
  5259. Packet loss concealment (PLC) is an optional decoder-side feature that
  5260. SHOULD be included when receiving from an unreliable channel. Because
  5261. PLC is not part of the bitstream, there are many acceptable ways to
  5262. implement PLC with different complexity/quality trade-offs.
  5263. </t>
  5264. <t>
  5265. The PLC in
  5266. the reference implementation depends on the mode of last packet received.
  5267. In CELT mode, the PLC finds a periodicity in the decoded
  5268. signal and repeats the windowed waveform using the pitch offset. The windowed
  5269. waveform is overlapped in such a way as to preserve the time-domain aliasing
  5270. cancellation with the previous frame and the next frame. This is implemented
  5271. in celt_decode_lost() (mdct.c). In SILK mode, the PLC uses LPC extrapolation
  5272. from the previous frame, implemented in silk_PLC() (PLC.c).
  5273. </t>
  5274. <section anchor="clock-drift" title="Clock Drift Compensation">
  5275. <t>
  5276. Clock drift refers to the gradual desynchronization of two endpoints
  5277. whose sample clocks run at different frequencies while they are streaming
  5278. live audio. Differences in clock frequencies are generally attributable to
  5279. manufacturing variation in the endpoints' clock hardware. For long-lived
  5280. streams, the time difference between sender and receiver can grow without
  5281. bound.
  5282. </t>
  5283. <t>
  5284. When the sender's clock runs slower than the receiver's, the effect is similar
  5285. to packet loss: too few packets are received. The receiver can distinguish
  5286. between drift and loss if the transport provides packet timestamps. A receiver
  5287. for live streams SHOULD conceal the effects of drift, and MAY do so by invoking
  5288. the PLC.
  5289. </t>
  5290. <t>
  5291. When the sender's clock runs faster than the receiver's, too many packets will
  5292. be received. The receiver MAY respond by skipping any packet (i.e., not
  5293. submitting the packet for decoding). This is likely to produce a less severe
  5294. artifact than if the frame were dropped after decoding.
  5295. </t>
  5296. <t>
  5297. A decoder MAY employ a more sophisticated drift compensation method. For
  5298. example, the
  5299. <xref target='Google-NetEQ'>NetEQ component</xref>
  5300. of the
  5301. <xref target='Google-WebRTC'>Google WebRTC codebase</xref>
  5302. compensates for drift by adding or removing
  5303. one period when the signal is highly periodic. The reference implementation of
  5304. Opus allows a caller to learn whether the current frame's signal is highly
  5305. periodic, and if so what the period is, using the OPUS_GET_PITCH() request.
  5306. </t>
  5307. </section>
  5308. </section>
  5309. <section anchor="switching" title="Configuration Switching">
  5310. <t>
  5311. Switching between the Opus coding modes, audio bandwidths, and channel counts
  5312. requires careful consideration to avoid audible glitches.
  5313. Switching between any two configurations of the CELT-only mode, any two
  5314. configurations of the Hybrid mode, or from WB SILK to Hybrid mode does not
  5315. require any special treatment in the decoder, as the MDCT overlap will smooth
  5316. the transition.
  5317. Switching from Hybrid mode to WB SILK requires adding in the final contents
  5318. of the CELT overlap buffer to the first SILK-only packet.
  5319. This can be done by decoding a 2.5&nbsp;ms silence frame with the CELT decoder
  5320. using the channel count of the SILK-only packet (and any choice of audio
  5321. bandwidth), which will correctly handle the cases when the channel count
  5322. changes as well.
  5323. </t>
  5324. <t>
  5325. When changing the channel count for SILK-only or Hybrid packets, the encoder
  5326. can avoid glitches by smoothly varying the stereo width of the input signal
  5327. before or after the transition, and SHOULD do so.
  5328. However, other transitions between SILK-only packets or between NB or MB SILK
  5329. and Hybrid packets may cause glitches, because neither the LSF coefficients
  5330. nor the LTP, LPC, stereo unmixing, and resampler buffers are available at the
  5331. new sample rate.
  5332. These switches SHOULD be delayed by the encoder until quiet periods or
  5333. transients, where the inevitable glitches will be less audible. Additionally,
  5334. the bit-stream MAY include redundant side information ("redundancy"), in the
  5335. form of additional CELT frames embedded in each of the Opus frames around the
  5336. transition.
  5337. </t>
  5338. <t>
  5339. The other transitions that cannot be easily handled are those where the lower
  5340. frequencies switch between the SILK LP-based model and the CELT MDCT model.
  5341. However, an encoder may not have an opportunity to delay such a switch to a
  5342. convenient point.
  5343. For example, if the content switches from speech to music, and the encoder does
  5344. not have enough latency in its analysis to detect this in advance, there may
  5345. be no convenient silence period during which to make the transition for quite
  5346. some time.
  5347. To avoid or reduce glitches during these problematic mode transitions, and
  5348. also between audio bandwidth changes in the SILK-only modes, transitions MAY
  5349. include redundant side information ("redundancy"), in the form of an
  5350. additional CELT frame embedded in the Opus frame.
  5351. </t>
  5352. <t>
  5353. A transition between coding the lower frequencies with the LP model and the
  5354. MDCT model or a transition that involves changing the SILK bandwidth
  5355. is only normatively specified when it includes redundancy.
  5356. For those without redundancy, it is RECOMMENDED that the decoder use a
  5357. concealment technique (e.g., make use of a PLC algorithm) to "fill in" the
  5358. gap or discontinuity caused by the mode transition.
  5359. Therefore, PLC MUST NOT be applied during any normative transition, i.e., when
  5360. <list style="symbols">
  5361. <t>A packet includes redundancy for this transition (as described below),</t>
  5362. <t>The transition is between any WB SILK packet and any Hybrid packet, or vice
  5363. versa,</t>
  5364. <t>The transition is between any two Hybrid mode packets, or</t>
  5365. <t>The transition is between any two CELT mode packets,</t>
  5366. </list>
  5367. unless there is actual packet loss.
  5368. </t>
  5369. <section anchor="side-info" title="Transition Side Information (Redundancy)">
  5370. <t>
  5371. Transitions with side information include an extra 5&nbsp;ms "redundant" CELT
  5372. frame within the Opus frame.
  5373. This frame is designed to fill in the gap or discontinuity in the different
  5374. layers without requiring the decoder to conceal it.
  5375. For transitions from CELT-only to SILK-only or Hybrid, the redundant frame is
  5376. inserted in the first Opus frame after the transition (i.e., the first
  5377. SILK-only or Hybrid frame).
  5378. For transitions from SILK-only or Hybrid to CELT-only, the redundant frame is
  5379. inserted in the last Opus frame before the transition (i.e., the last
  5380. SILK-only or Hybrid frame).
  5381. </t>
  5382. <section anchor="opus_redundancy_flag" title="Redundancy Flag">
  5383. <t>
  5384. The presence of redundancy is signaled in all SILK-only and Hybrid frames, not
  5385. just those involved in a mode transition.
  5386. This allows the frames to be decoded correctly even if an adjacent frame is
  5387. lost.
  5388. For SILK-only frames, this signaling is implicit, based on the size of the
  5389. of the Opus frame and the number of bits consumed decoding the SILK portion of
  5390. it.
  5391. After decoding the SILK portion of the Opus frame, the decoder uses ec_tell()
  5392. (see <xref target="ec_tell"/>) to check if there are at least 17 bits
  5393. remaining.
  5394. If so, then the frame contains redundancy.
  5395. </t>
  5396. <t>
  5397. For Hybrid frames, this signaling is explicit.
  5398. After decoding the SILK portion of the Opus frame, the decoder uses ec_tell()
  5399. (see <xref target="ec_tell"/>) to ensure there are at least 37 bits remaining.
  5400. If so, it reads a symbol with the PDF in
  5401. <xref target="opus_redundancy_flag_pdf"/>, and if the value is 1, then the
  5402. frame contains redundancy.
  5403. Otherwise (if there were fewer than 37 bits left or the value was 0), the frame
  5404. does not contain redundancy.
  5405. </t>
  5406. <texttable anchor="opus_redundancy_flag_pdf" title="Redundancy Flag PDF">
  5407. <ttcol>PDF</ttcol>
  5408. <c>{4095, 1}/4096</c>
  5409. </texttable>
  5410. </section>
  5411. <section anchor="opus_redundancy_pos" title="Redundancy Position Flag">
  5412. <t>
  5413. Since the current frame is a SILK-only or a Hybrid frame, it must be at least
  5414. 10&nbsp;ms.
  5415. Therefore, it needs an additional flag to indicate whether the redundant
  5416. 5&nbsp;ms CELT frame should be mixed into the beginning of the current frame,
  5417. or the end.
  5418. After determining that a frame contains redundancy, the decoder reads a
  5419. 1&nbsp;bit symbol with a uniform PDF
  5420. (<xref target="opus_redundancy_pos_pdf"/>).
  5421. </t>
  5422. <texttable anchor="opus_redundancy_pos_pdf" title="Redundancy Position PDF">
  5423. <ttcol>PDF</ttcol>
  5424. <c>{1, 1}/2</c>
  5425. </texttable>
  5426. <t>
  5427. If the value is zero, this is the first frame in the transition, and the
  5428. redundancy belongs at the end.
  5429. If the value is one, this is the second frame in the transition, and the
  5430. redundancy belongs at the beginning.
  5431. There is no way to specify that an Opus frame contains separate redundant CELT
  5432. frames at both the beginning and the end.
  5433. </t>
  5434. </section>
  5435. <section anchor="opus_redundancy_size" title="Redundancy Size">
  5436. <t>
  5437. Unlike the CELT portion of a Hybrid frame, the redundant CELT frame does not
  5438. use the same entropy coder state as the rest of the Opus frame, because this
  5439. would break the CELT bit allocation mechanism in Hybrid frames.
  5440. Thus, a redundant CELT frame always starts and ends on a byte boundary, even in
  5441. SILK-only frames, where this is not strictly necessary.
  5442. </t>
  5443. <t>
  5444. For SILK-only frames, the number of bytes in the redundant CELT frame is simply
  5445. the number of whole bytes remaining, which must be at least 2, due to the
  5446. space check in <xref target="opus_redundancy_flag"/>.
  5447. For Hybrid frames, the number of bytes is equal to 2, plus a decoded unsigned
  5448. integer less than 256 (see <xref target="ec_dec_uint"/>).
  5449. This may be more than the number of whole bytes remaining in the Opus frame,
  5450. in which case the frame is invalid.
  5451. However, a decoder is not required to ignore the entire frame, as this may be
  5452. the result of a bit error that desynchronized the range coder.
  5453. There may still be useful data before the error, and a decoder MAY keep any
  5454. audio decoded so far instead of invoking the PLC, but it is RECOMMENDED that
  5455. the decoder stop decoding and discard the rest of the current Opus frame.
  5456. </t>
  5457. <t>
  5458. It would have been possible to avoid these invalid states in the design of Opus
  5459. by limiting the range of the explicit length decoded from Hybrid frames by the
  5460. actual number of whole bytes remaining.
  5461. However, this would require an encoder to determine the rate allocation for the
  5462. MDCT layer up front, before it began encoding that layer.
  5463. By allowing some invalid sizes, the encoder is able to defer that decision
  5464. until much later.
  5465. When encoding Hybrid frames which do not include redundancy, the encoder must
  5466. still decide up-front if it wishes to use the minimum 37 bits required to
  5467. trigger encoding of the redundancy flag, but this is a much looser
  5468. restriction.
  5469. </t>
  5470. <t>
  5471. After determining the size of the redundant CELT frame, the decoder reduces
  5472. the size of the buffer currently in use by the range coder by that amount.
  5473. The CELT layer read any raw bits from the end of this reduced buffer, and all
  5474. calculations of the number of bits remaining in the buffer must be done using
  5475. this new, reduced size, rather than the original size of the Opus frame.
  5476. </t>
  5477. </section>
  5478. <section anchor="opus_redundancy_decoding" title="Decoding the Redundancy">
  5479. <t>
  5480. The redundant frame is decoded like any other CELT-only frame, with the
  5481. exception that it does not contain a TOC byte.
  5482. The frame size is fixed at 5&nbsp;ms, the channel count is set to that of the
  5483. current frame, and the audio bandwidth is also set to that of the current
  5484. frame, with the exception that for MB SILK frames, it is set to WB.
  5485. </t>
  5486. <t>
  5487. If the redundancy belongs at the beginning (in a CELT-only to SILK-only or
  5488. Hybrid transition), the final reconstructed output uses the first 2.5&nbsp;ms
  5489. of audio output by the decoder for the redundant frame as-is, discarding
  5490. the corresponding output from the SILK-only or Hybrid portion of the frame.
  5491. The remaining 2.5&nbsp;ms is cross-lapped with the decoded SILK/Hybrid signal
  5492. using the CELT's power-complementary MDCT window to ensure a smooth
  5493. transition.
  5494. </t>
  5495. <t>
  5496. If the redundancy belongs at the end (in a SILK-only or Hybrid to CELT-only
  5497. transition), only the second half (2.5&nbsp;ms) of the audio output by the
  5498. decoder for the redundant frame is used.
  5499. In that case, the second half of the redundant frame is cross-lapped with the
  5500. end of the SILK/Hybrid signal, again using CELT's power-complementary MDCT
  5501. window to ensure a smooth transition.
  5502. </t>
  5503. </section>
  5504. </section>
  5505. <section anchor="decoder-reset" title="State Reset">
  5506. <t>
  5507. When a transition occurs, the state of the SILK or the CELT decoder (or both)
  5508. may need to be reset before decoding a frame in the new mode.
  5509. This avoids reusing "out of date" memory, which may not have been updated in
  5510. some time or may not be in a well-defined state due to, e.g., PLC.
  5511. The SILK state is reset before every SILK-only or Hybrid frame where the
  5512. previous frame was CELT-only.
  5513. The CELT state is reset every time the operating mode changes and the new mode
  5514. is either Hybrid or CELT-only, except when the transition uses redundancy as
  5515. described above.
  5516. When switching from SILK-only or Hybrid to CELT-only with redundancy, the CELT
  5517. state is reset before decoding the redundant CELT frame embedded in the
  5518. SILK-only or Hybrid frame, but it is not reset before decoding the following
  5519. CELT-only frame.
  5520. When switching from CELT-only mode to SILK-only or Hybrid mode with redundancy,
  5521. the CELT decoder is not reset for decoding the redundant CELT frame.
  5522. </t>
  5523. </section>
  5524. <section title="Summary of Transitions">
  5525. <t>
  5526. <xref target="normative_transitions"/> illustrates all of the normative
  5527. transitions involving a mode change, an audio bandwidth change, or both.
  5528. Each one uses an S, H, or C to represent an Opus frame in the corresponding
  5529. mode.
  5530. In addition, an R indicates the presence of redundancy in the Opus frame it is
  5531. cross-lapped with.
  5532. Its location in the first or last 5&nbsp;ms is assumed to correspond to whether
  5533. it is the frame before or after the transition.
  5534. Other uses of redundancy are non-normative.
  5535. Finally, a c indicates the contents of the CELT overlap buffer after the
  5536. previously decoded frame (i.e., as extracted by decoding a silence frame).
  5537. <figure align="center" anchor="normative_transitions"
  5538. title="Normative Transitions">
  5539. <artwork align="center"><![CDATA[
  5540. SILK to SILK with Redundancy: S -> S -> S
  5541. &
  5542. !R -> R
  5543. &
  5544. ;S -> S -> S
  5545. NB or MB SILK to Hybrid with Redundancy: S -> S -> S
  5546. &
  5547. !R ->;H -> H -> H
  5548. WB SILK to Hybrid: S -> S -> S ->!H -> H -> H
  5549. SILK to CELT with Redundancy: S -> S -> S
  5550. &
  5551. !R -> C -> C -> C
  5552. Hybrid to NB or MB SILK with Redundancy: H -> H -> H
  5553. &
  5554. !R -> R
  5555. &
  5556. ;S -> S -> S
  5557. Hybrid to WB SILK: H -> H -> H -> c
  5558. \ +
  5559. > S -> S -> S
  5560. Hybrid to CELT with Redundancy: H -> H -> H
  5561. &
  5562. !R -> C -> C -> C
  5563. CELT to SILK with Redundancy: C -> C -> C -> R
  5564. &
  5565. ;S -> S -> S
  5566. CELT to Hybrid with Redundancy: C -> C -> C -> R
  5567. &
  5568. |H -> H -> H
  5569. Key:
  5570. S SILK-only frame ; SILK decoder reset
  5571. H Hybrid frame | CELT and SILK decoder resets
  5572. C CELT-only frame ! CELT decoder reset
  5573. c CELT overlap + Direct mixing
  5574. R Redundant CELT frame & Windowed cross-lap
  5575. ]]></artwork>
  5576. </figure>
  5577. The first two and the last two Opus frames in each example are illustrative,
  5578. i.e., there is no requirement that a stream remain in the same configuration
  5579. for three consecutive frames before or after a switch.
  5580. </t>
  5581. <t>
  5582. The behavior of transitions without redundancy where PLC is allowed is non-normative.
  5583. An encoder might still wish to use these transitions if, for example, it
  5584. doesn't want to add the extra bitrate required for redundancy or if it makes
  5585. a decision to switch after it has already transmitted the frame that would
  5586. have had to contain the redundancy.
  5587. <xref target="nonnormative_transitions"/> illustrates the recommended
  5588. cross-lapping and decoder resets for these transitions.
  5589. <figure align="center" anchor="nonnormative_transitions"
  5590. title="Recommended Non-Normative Transitions">
  5591. <artwork align="center"><![CDATA[
  5592. SILK to SILK (audio bandwidth change): S -> S -> S ;S -> S -> S
  5593. NB or MB SILK to Hybrid: S -> S -> S |H -> H -> H
  5594. SILK to CELT without Redundancy: S -> S -> S -> P
  5595. &
  5596. !C -> C -> C
  5597. Hybrid to NB or MB SILK: H -> H -> H -> c
  5598. +
  5599. ;S -> S -> S
  5600. Hybrid to CELT without Redundancy: H -> H -> H -> P
  5601. &
  5602. !C -> C -> C
  5603. CELT to SILK without Redundancy: C -> C -> C -> P
  5604. &
  5605. ;S -> S -> S
  5606. CELT to Hybrid without Redundancy: C -> C -> C -> P
  5607. &
  5608. |H -> H -> H
  5609. Key:
  5610. S SILK-only frame ; SILK decoder reset
  5611. H Hybrid frame | CELT and SILK decoder resets
  5612. C CELT-only frame ! CELT decoder reset
  5613. c CELT overlap + Direct mixing
  5614. P Packet Loss Concealment & Windowed cross-lap
  5615. ]]></artwork>
  5616. </figure>
  5617. Encoders SHOULD NOT use other transitions, e.g., those that involve redundancy
  5618. in ways not illustrated in <xref target="normative_transitions"/>.
  5619. </t>
  5620. </section>
  5621. </section>
  5622. </section>
  5623. <!-- ******************************************************************* -->
  5624. <!-- ************************** OPUS ENCODER *********************** -->
  5625. <!-- ******************************************************************* -->
  5626. <section title="Opus Encoder">
  5627. <t>
  5628. Just like the decoder, the Opus encoder also normally consists of two main blocks: the
  5629. SILK encoder and the CELT encoder. However, unlike the case of the decoder, a valid
  5630. (though potentially suboptimal) Opus encoder is not required to support all modes and
  5631. may thus only include a SILK encoder module or a CELT encoder module.
  5632. The output bit-stream of the Opus encoding contains bits from the SILK and CELT
  5633. encoders, though these are not separable due to the use of a range coder.
  5634. A block diagram of the encoder is illustrated below.
  5635. <figure align="center" anchor="opus-encoder-figure" title="Opus Encoder">
  5636. <artwork>
  5637. <![CDATA[
  5638. +------------+ +---------+
  5639. | Sample | | SILK |------+
  5640. +->| Rate |--->| Encoder | V
  5641. +-----------+ | | Conversion | | | +---------+
  5642. | Optional | | +------------+ +---------+ | Range |
  5643. ->| High-pass |--+ | Encoder |---->
  5644. | Filter | | +--------------+ +---------+ | | Bit-
  5645. +-----------+ | | Delay | | CELT | +---------+ stream
  5646. +->| Compensation |->| Encoder | ^
  5647. | | | |------+
  5648. +--------------+ +---------+
  5649. ]]>
  5650. </artwork>
  5651. </figure>
  5652. </t>
  5653. <t>
  5654. For a normal encoder where both the SILK and the CELT modules are included, an optimal
  5655. encoder should select which coding mode to use at run-time depending on the conditions.
  5656. In the reference implementation, the frame size is selected by the application, but the
  5657. other configuration parameters (number of channels, bandwidth, mode) are automatically
  5658. selected (unless explicitly overridden by the application) depend on the following:
  5659. <list style="symbols">
  5660. <t>Requested bitrate</t>
  5661. <t>Input sampling rate</t>
  5662. <t>Type of signal (speech vs music)</t>
  5663. <t>Frame size in use</t>
  5664. </list>
  5665. The type of signal currently needs to be provided by the application (though it can be
  5666. changed in real-time). An Opus encoder implementation could also do automatic detection,
  5667. but since Opus is an interactive codec, such an implementation would likely have to either
  5668. delay the signal (for non-interactive applications) or delay the mode switching decisions (for
  5669. interactive applications).
  5670. </t>
  5671. <t>
  5672. When the encoder is configured for voice over IP applications, the input signal is
  5673. filtered by a high-pass filter to remove the lowest part of the spectrum
  5674. that contains little speech energy and may contain background noise. This is a second order
  5675. Auto Regressive Moving Average (i.e., with poles and zeros) filter with a cut-off frequency around 50&nbsp;Hz.
  5676. In the future, a music detector may also be used to lower the cut-off frequency when the
  5677. input signal is detected to be music rather than speech.
  5678. </t>
  5679. <section anchor="range-encoder" title="Range Encoder">
  5680. <t>
  5681. The range coder acts as the bit-packer for Opus.
  5682. It is used in three different ways: to encode
  5683. <list style="symbols">
  5684. <t>
  5685. Entropy-coded symbols with a fixed probability model using ec_encode()
  5686. (entenc.c),
  5687. </t>
  5688. <t>
  5689. Integers from 0 to (2**M&nbsp;-&nbsp;1) using ec_enc_uint() or ec_enc_bits()
  5690. (entenc.c),</t>
  5691. <t>
  5692. Integers from 0 to (ft&nbsp;-&nbsp;1) (where ft is not a power of two) using
  5693. ec_enc_uint() (entenc.c).
  5694. </t>
  5695. </list>
  5696. </t>
  5697. <t>
  5698. The range encoder maintains an internal state vector composed of the four-tuple
  5699. (val,&nbsp;rng,&nbsp;rem,&nbsp;ext) representing the low end of the current
  5700. range, the size of the current range, a single buffered output byte, and a
  5701. count of additional carry-propagating output bytes.
  5702. Both val and rng are 32-bit unsigned integer values, rem is a byte value or
  5703. less than 255 or the special value -1, and ext is an unsigned integer with at
  5704. least 11 bits.
  5705. This state vector is initialized at the start of each each frame to the value
  5706. (0,&nbsp;2**31,&nbsp;-1,&nbsp;0).
  5707. After encoding a sequence of symbols, the value of rng in the encoder should
  5708. exactly match the value of rng in the decoder after decoding the same sequence
  5709. of symbols.
  5710. This is a powerful tool for detecting errors in either an encoder or decoder
  5711. implementation.
  5712. The value of val, on the other hand, represents different things in the encoder
  5713. and decoder, and is not expected to match.
  5714. </t>
  5715. <t>
  5716. The decoder has no analog for rem and ext.
  5717. These are used to perform carry propagation in the renormalization loop below.
  5718. Each iteration of this loop produces 9 bits of output, consisting of 8 data
  5719. bits and a carry flag.
  5720. The encoder cannot determine the final value of the output bytes until it
  5721. propagates these carry flags.
  5722. Therefore the reference implementation buffers a single non-propagating output
  5723. byte (i.e., one less than 255) in rem and keeps a count of additional
  5724. propagating (i.e., 255) output bytes in ext.
  5725. An implementation may choose to use any mathematically equivalent scheme to
  5726. perform carry propagation.
  5727. </t>
  5728. <section anchor="encoding-symbols" title="Encoding Symbols">
  5729. <t>
  5730. The main encoding function is ec_encode() (entenc.c), which encodes symbol k in
  5731. the current context using the same three-tuple (fl[k],&nbsp;fh[k],&nbsp;ft)
  5732. as the decoder to describe the range of the symbol (see
  5733. <xref target="range-decoder"/>).
  5734. </t>
  5735. <t>
  5736. ec_encode() updates the state of the encoder as follows.
  5737. If fl[k] is greater than zero, then
  5738. <figure align="center">
  5739. <artwork align="center"><![CDATA[
  5740. rng
  5741. val = val + rng - --- * (ft - fl) ,
  5742. ft
  5743. rng
  5744. rng = --- * (fh - fl) .
  5745. ft
  5746. ]]></artwork>
  5747. </figure>
  5748. Otherwise, val is unchanged and
  5749. <figure align="center">
  5750. <artwork align="center"><![CDATA[
  5751. rng
  5752. rng = rng - --- * (fh - fl) .
  5753. ft
  5754. ]]></artwork>
  5755. </figure>
  5756. The divisions here are integer division.
  5757. </t>
  5758. <section anchor="range-encoder-renorm" title="Renormalization">
  5759. <t>
  5760. After this update, the range is normalized using a procedure very similar to
  5761. that of <xref target="range-decoder-renorm"/>, implemented by
  5762. ec_enc_normalize() (entenc.c).
  5763. The following process is repeated until rng&nbsp;&gt;&nbsp;2**23.
  5764. First, the top 9 bits of val, (val&gt;&gt;23), are sent to the carry buffer,
  5765. described in <xref target="ec_enc_carry_out"/>.
  5766. Then, the encoder sets
  5767. <figure align="center">
  5768. <artwork align="center"><![CDATA[
  5769. val = (val<<8) & 0x7FFFFFFF ,
  5770. rng = rng<<8 .
  5771. ]]></artwork>
  5772. </figure>
  5773. </t>
  5774. </section>
  5775. <section anchor="ec_enc_carry_out"
  5776. title="Carry Propagation and Output Buffering">
  5777. <t>
  5778. The function ec_enc_carry_out() (entenc.c) implements carry propagation and
  5779. output buffering.
  5780. It takes as input a 9-bit value, c, consisting of 8 data bits and an additional
  5781. carry bit.
  5782. If c is equal to the value 255, then ext is simply incremented, and no other
  5783. state updates are performed.
  5784. Otherwise, let b&nbsp;=&nbsp;(c&gt;&gt;8) be the carry bit.
  5785. Then,
  5786. <list style="symbols">
  5787. <t>
  5788. If the buffered byte rem contains a value other than -1, the encoder outputs
  5789. the byte (rem&nbsp;+&nbsp;b).
  5790. Otherwise, if rem is -1, no byte is output.
  5791. </t>
  5792. <t>
  5793. If ext is non-zero, then the encoder outputs ext bytes---all with a value of 0
  5794. if b is set, or 255 if b is unset---and sets ext to 0.
  5795. </t>
  5796. <t>
  5797. rem is set to the 8 data bits:
  5798. <figure align="center">
  5799. <artwork align="center"><![CDATA[
  5800. rem = c & 255 .
  5801. ]]></artwork>
  5802. </figure>
  5803. </t>
  5804. </list>
  5805. </t>
  5806. </section>
  5807. </section>
  5808. <section anchor="encoding-alternate" title="Alternate Encoding Methods">
  5809. <t>
  5810. The reference implementation uses three additional encoding methods that are
  5811. exactly equivalent to the above, but make assumptions and simplifications that
  5812. allow for a more efficient implementation.
  5813. </t>
  5814. <section anchor="ec_encode_bin" title="ec_encode_bin()">
  5815. <t>
  5816. The first is ec_encode_bin() (entenc.c), defined using the parameter ftb
  5817. instead of ft.
  5818. It is mathematically equivalent to calling ec_encode() with
  5819. ft&nbsp;=&nbsp;(1&lt;&lt;ftb), but avoids using division.
  5820. </t>
  5821. </section>
  5822. <section anchor="ec_enc_bit_logp" title="ec_enc_bit_logp()">
  5823. <t>
  5824. The next is ec_enc_bit_logp() (entenc.c), which encodes a single binary symbol.
  5825. The context is described by a single parameter, logp, which is the absolute
  5826. value of the base-2 logarithm of the probability of a "1".
  5827. It is mathematically equivalent to calling ec_encode() with the 3-tuple
  5828. (fl[k]&nbsp;=&nbsp;0, fh[k]&nbsp;=&nbsp;(1&lt;&lt;logp)&nbsp;-&nbsp;1,
  5829. ft&nbsp;=&nbsp;(1&lt;&lt;logp)) if k is 0 and with
  5830. (fl[k]&nbsp;=&nbsp;(1&lt;&lt;logp)&nbsp;-&nbsp;1,
  5831. fh[k]&nbsp;=&nbsp;ft&nbsp;=&nbsp;(1&lt;&lt;logp)) if k is 1.
  5832. The implementation requires no multiplications or divisions.
  5833. </t>
  5834. </section>
  5835. <section anchor="ec_enc_icdf" title="ec_enc_icdf()">
  5836. <t>
  5837. The last is ec_enc_icdf() (entenc.c), which encodes a single binary symbol with
  5838. a table-based context of up to 8 bits.
  5839. This uses the same icdf table as ec_dec_icdf() from
  5840. <xref target="ec_dec_icdf"/>.
  5841. The function is mathematically equivalent to calling ec_encode() with
  5842. fl[k]&nbsp;=&nbsp;(1&lt;&lt;ftb)&nbsp;-&nbsp;icdf[k-1] (or 0 if
  5843. k&nbsp;==&nbsp;0), fh[k]&nbsp;=&nbsp;(1&lt;&lt;ftb)&nbsp;-&nbsp;icdf[k], and
  5844. ft&nbsp;=&nbsp;(1&lt;&lt;ftb).
  5845. This only saves a few arithmetic operations over ec_encode_bin(), but allows
  5846. the encoder to use the same icdf tables as the decoder.
  5847. </t>
  5848. </section>
  5849. </section>
  5850. <section anchor="encoding-bits" title="Encoding Raw Bits">
  5851. <t>
  5852. The raw bits used by the CELT layer are packed at the end of the buffer using
  5853. ec_enc_bits() (entenc.c).
  5854. Because the raw bits may continue into the last byte output by the range coder
  5855. if there is room in the low-order bits, the encoder must be prepared to merge
  5856. these values into a single byte.
  5857. The procedure in <xref target="encoder-finalizing"/> does this in a way that
  5858. ensures both the range coded data and the raw bits can be decoded
  5859. successfully.
  5860. </t>
  5861. </section>
  5862. <section anchor="encoding-ints" title="Encoding Uniformly Distributed Integers">
  5863. <t>
  5864. The function ec_enc_uint() (entenc.c) encodes one of ft equiprobable symbols in
  5865. the range 0 to (ft&nbsp;-&nbsp;1), inclusive, each with a frequency of 1,
  5866. where ft may be as large as (2**32&nbsp;-&nbsp;1).
  5867. Like the decoder (see <xref target="ec_dec_uint"/>), it splits up the
  5868. value into a range coded symbol representing up to 8 of the high bits, and, if
  5869. necessary, raw bits representing the remainder of the value.
  5870. </t>
  5871. <t>
  5872. ec_enc_uint() takes a two-tuple (t,&nbsp;ft), where t is the value to be
  5873. encoded, 0&nbsp;&lt;=&nbsp;t&nbsp;&lt;&nbsp;ft, and ft is not necessarily a
  5874. power of two.
  5875. Let ftb&nbsp;=&nbsp;ilog(ft&nbsp;-&nbsp;1), i.e., the number of bits required
  5876. to store (ft&nbsp;-&nbsp;1) in two's complement notation.
  5877. If ftb is 8 or less, then t is encoded directly using ec_encode() with the
  5878. three-tuple (t, t&nbsp;+&nbsp;1, ft).
  5879. </t>
  5880. <t>
  5881. If ftb is greater than 8, then the top 8 bits of t are encoded using the
  5882. three-tuple (t&gt;&gt;(ftb&nbsp;-&nbsp;8),
  5883. (t&gt;&gt;(ftb&nbsp;-&nbsp;8))&nbsp;+&nbsp;1,
  5884. ((ft&nbsp;-&nbsp;1)&gt;&gt;(ftb&nbsp;-&nbsp;8))&nbsp;+&nbsp;1), and the
  5885. remaining bits,
  5886. (t&nbsp;&amp;&nbsp;((1&lt;&lt;(ftb&nbsp;-&nbsp;8))&nbsp;-&nbsp;1),
  5887. are encoded as raw bits with ec_enc_bits().
  5888. </t>
  5889. </section>
  5890. <section anchor="encoder-finalizing" title="Finalizing the Stream">
  5891. <t>
  5892. After all symbols are encoded, the stream must be finalized by outputting a
  5893. value inside the current range.
  5894. Let end be the integer in the interval [val,&nbsp;val&nbsp;+&nbsp;rng) with the
  5895. largest number of trailing zero bits, b, such that
  5896. (end&nbsp;+&nbsp;(1&lt;&lt;b)&nbsp;-&nbsp;1) is also in the interval
  5897. [val,&nbsp;val&nbsp;+&nbsp;rng).
  5898. This choice of end allows the maximum number of trailing bits to be set to
  5899. arbitrary values while still ensuring the range coded part of the buffer can
  5900. be decoded correctly.
  5901. Then, while end is not zero, the top 9 bits of end, i.e., (end&gt;&gt;23), are
  5902. passed to the carry buffer in accordance with the procedure in
  5903. <xref target="ec_enc_carry_out"/>, and end is updated via
  5904. <figure align="center">
  5905. <artwork align="center"><![CDATA[
  5906. end = (end<<8) & 0x7FFFFFFF .
  5907. ]]></artwork>
  5908. </figure>
  5909. Finally, if the buffered output byte, rem, is neither zero nor the special
  5910. value -1, or the carry count, ext, is greater than zero, then 9 zero bits are
  5911. sent to the carry buffer to flush it to the output buffer.
  5912. When outputting the final byte from the range coder, if it would overlap any
  5913. raw bits already packed into the end of the output buffer, they should be ORed
  5914. into the same byte.
  5915. The bit allocation routines in the CELT layer should ensure that this can be
  5916. done without corrupting the range coder data so long as end is chosen as
  5917. described above.
  5918. If there is any space between the end of the range coder data and the end of
  5919. the raw bits, it is padded with zero bits.
  5920. This entire process is implemented by ec_enc_done() (entenc.c).
  5921. </t>
  5922. </section>
  5923. <section anchor="encoder-tell" title="Current Bit Usage">
  5924. <t>
  5925. The bit allocation routines in Opus need to be able to determine a
  5926. conservative upper bound on the number of bits that have been used
  5927. to encode the current frame thus far. This drives allocation
  5928. decisions and ensures that the range coder and raw bits will not
  5929. overflow the output buffer. This is computed in the
  5930. reference implementation to whole-bit precision by
  5931. the function ec_tell() (entcode.h) and to fractional 1/8th bit
  5932. precision by the function ec_tell_frac() (entcode.c).
  5933. Like all operations in the range coder, it must be implemented in a
  5934. bit-exact manner, and must produce exactly the same value returned by
  5935. the same functions in the decoder after decoding the same symbols.
  5936. </t>
  5937. </section>
  5938. </section>
  5939. <section title='SILK Encoder'>
  5940. <t>
  5941. In many respects the SILK encoder mirrors the SILK decoder described
  5942. in <xref target='silk_decoder_outline'/>.
  5943. Details such as the quantization and range coder tables can be found
  5944. there, while this section describes the high-level design choices that
  5945. were made.
  5946. The diagram below shows the basic modules of the SILK encoder.
  5947. <figure align="center" anchor="silk_encoder_figure" title="SILK Encoder">
  5948. <artwork>
  5949. <![CDATA[
  5950. +----------+ +--------+ +---------+
  5951. | Sample | | Stereo | | SILK |
  5952. ------>| Rate |--->| Mixing |--->| Core |---------->
  5953. Input |Conversion| | | | Encoder | Bitstream
  5954. +----------+ +--------+ +---------+
  5955. ]]>
  5956. </artwork>
  5957. </figure>
  5958. </t>
  5959. <section title='Sample Rate Conversion'>
  5960. <t>
  5961. The input signal's sampling rate is adjusted by a sample rate conversion
  5962. module so that it matches the SILK internal sampling rate.
  5963. The input to the sample rate converter is delayed by a number of samples
  5964. depending on the sample rate ratio, such that the overall delay is constant
  5965. for all input and output sample rates.
  5966. </t>
  5967. </section>
  5968. <section title='Stereo Mixing'>
  5969. <t>
  5970. The stereo mixer is only used for stereo input signals.
  5971. It converts a stereo left/right signal into an adaptive
  5972. mid/side representation.
  5973. The first step is to compute non-adaptive mid/side signals
  5974. as half the sum and difference between left and right signals.
  5975. The side signal is then minimized in energy by subtracting a
  5976. prediction of it based on the mid signal.
  5977. This prediction works well when the left and right signals
  5978. exhibit linear dependency, for instance for an amplitude-panned
  5979. input signal.
  5980. Like in the decoder, the prediction coefficients are linearly
  5981. interpolated during the first 8&nbsp;ms of the frame.
  5982. The mid signal is always encoded, whereas the residual
  5983. side signal is only encoded if it has sufficient
  5984. energy compared to the mid signal's energy.
  5985. If it has not,
  5986. the "mid_only_flag" is set without encoding the side signal.
  5987. </t>
  5988. <t>
  5989. The predictor coefficients are coded regardless of whether
  5990. the side signal is encoded.
  5991. For each frame, two predictor coefficients are computed, one
  5992. that predicts between low-passed mid and side channels, and
  5993. one that predicts between high-passed mid and side channels.
  5994. The low-pass filter is a simple three-tap filter
  5995. and creates a delay of one sample.
  5996. The high-pass filtered signal is the difference between
  5997. the mid signal delayed by one sample and the low-passed
  5998. signal. Instead of explicitly computing the high-passed
  5999. signal, it is computationally more efficient to transform
  6000. the prediction coefficients before applying them to the
  6001. filtered mid signal, as follows
  6002. <figure align="center">
  6003. <artwork align="center">
  6004. <![CDATA[
  6005. pred(n) = LP(n) * w0 + HP(n) * w1
  6006. = LP(n) * w0 + (mid(n-1) - LP(n)) * w1
  6007. = LP(n) * (w0 - w1) + mid(n-1) * w1
  6008. ]]>
  6009. </artwork>
  6010. </figure>
  6011. where w0 and w1 are the low-pass and high-pass prediction
  6012. coefficients, mid(n-1) is the mid signal delayed by one sample,
  6013. LP(n) and HP(n) are the low-passed and high-passed
  6014. signals and pred(n) is the prediction signal that is subtracted
  6015. from the side signal.
  6016. </t>
  6017. </section>
  6018. <section title='SILK Core Encoder'>
  6019. <t>
  6020. What follows is a description of the core encoder and its components.
  6021. For simplicity, the core encoder is referred to simply as the encoder in
  6022. the remainder of this section. An overview of the encoder is given in
  6023. <xref target="encoder_figure" />.
  6024. </t>
  6025. <figure align="center" anchor="encoder_figure" title="SILK Core Encoder">
  6026. <artwork align="center">
  6027. <![CDATA[
  6028. +---+
  6029. +--------------------------------->| |
  6030. +---------+ | +---------+ | |
  6031. |Voice | | |LTP |12 | |
  6032. +-->|Activity |--+ +----->|Scaling |-----------+---->| |
  6033. | |Detector |3 | | |Control |<--+ | | |
  6034. | +---------+ | | +---------+ | | | |
  6035. | | | +---------+ | | | |
  6036. | | | |Gains | | | | |
  6037. | | | +-->|Processor|---|---+---|---->| R |
  6038. | | | | | |11 | | | | a |
  6039. | \/ | | +---------+ | | | | n |
  6040. | +---------+ | | +---------+ | | | | g |
  6041. | |Pitch | | | |LSF | | | | | e |
  6042. | +->|Analysis |---+ | |Quantizer|---|---|---|---->| |
  6043. | | | |4 | | | |8 | | | | E |-->
  6044. | | +---------+ | | +---------+ | | | | n | 2
  6045. | | | | 9/\ 10| | | | | c |
  6046. | | | | | \/ | | | | o |
  6047. | | +---------+ | | +----------+ | | | | d |
  6048. | | |Noise | +--|-->|Prediction|--+---|---|---->| e |
  6049. | +->|Shaping |---|--+ |Analysis |7 | | | | r |
  6050. | | |Analysis |5 | | | | | | | | |
  6051. | | +---------+ | | +----------+ | | | | |
  6052. | | | | /\ | | | | |
  6053. | | +----------|--|--------+ | | | | |
  6054. | | | \/ \/ \/ \/ \/ | |
  6055. | | | +---------+ +------------+ | |
  6056. | | | | | |Noise | | |
  6057. -+-------+-----+------>|Prefilter|--------->|Shaping |-->| |
  6058. 1 | | 6 |Quantization|13 | |
  6059. +---------+ +------------+ +---+
  6060. 1: Input speech signal
  6061. 2: Range encoded bitstream
  6062. 3: Voice activity estimate
  6063. 4: Pitch lags (per 5 ms) and voicing decision (per 20 ms)
  6064. 5: Noise shaping quantization coefficients
  6065. - Short term synthesis and analysis
  6066. noise shaping coefficients (per 5 ms)
  6067. - Long term synthesis and analysis noise
  6068. shaping coefficients (per 5 ms and for voiced speech only)
  6069. - Noise shaping tilt (per 5 ms)
  6070. - Quantizer gain/step size (per 5 ms)
  6071. 6: Input signal filtered with analysis noise shaping filters
  6072. 7: Short and long term prediction coefficients
  6073. LTP (per 5 ms) and LPC (per 20 ms)
  6074. 8: LSF quantization indices
  6075. 9: LSF coefficients
  6076. 10: Quantized LSF coefficients
  6077. 11: Processed gains, and synthesis noise shape coefficients
  6078. 12: LTP state scaling coefficient. Controlling error propagation
  6079. / prediction gain trade-off
  6080. 13: Quantized signal
  6081. ]]>
  6082. </artwork>
  6083. </figure>
  6084. <section title='Voice Activity Detection'>
  6085. <t>
  6086. The input signal is processed by a Voice Activity Detector (VAD) to produce
  6087. a measure of voice activity, spectral tilt, and signal-to-noise estimates for
  6088. each frame. The VAD uses a sequence of half-band filterbanks to split the
  6089. signal into four subbands: 0...Fs/16, Fs/16...Fs/8, Fs/8...Fs/4, and
  6090. Fs/4...Fs/2, where Fs is the sampling frequency (8, 12, 16, or 24&nbsp;kHz).
  6091. The lowest subband, from 0 - Fs/16, is high-pass filtered with a first-order
  6092. moving average (MA) filter (with transfer function H(z) = 1-z**(-1)) to
  6093. reduce the energy at the lowest frequencies. For each frame, the signal
  6094. energy per subband is computed.
  6095. In each subband, a noise level estimator tracks the background noise level
  6096. and a Signal-to-Noise Ratio (SNR) value is computed as the logarithm of the
  6097. ratio of energy to noise level.
  6098. Using these intermediate variables, the following parameters are calculated
  6099. for use in other SILK modules:
  6100. <list style="symbols">
  6101. <t>
  6102. Average SNR. The average of the subband SNR values.
  6103. </t>
  6104. <t>
  6105. Smoothed subband SNRs. Temporally smoothed subband SNR values.
  6106. </t>
  6107. <t>
  6108. Speech activity level. Based on the average SNR and a weighted average of the
  6109. subband energies.
  6110. </t>
  6111. <t>
  6112. Spectral tilt. A weighted average of the subband SNRs, with positive weights
  6113. for the low subbands and negative weights for the high subbands.
  6114. </t>
  6115. </list>
  6116. </t>
  6117. </section>
  6118. <section title='Pitch Analysis' anchor='pitch_estimator_overview_section'>
  6119. <t>
  6120. The input signal is processed by the open loop pitch estimator shown in
  6121. <xref target='pitch_estimator_figure' />.
  6122. <figure align="center" anchor="pitch_estimator_figure"
  6123. title="Block diagram of the pitch estimator">
  6124. <artwork align="center">
  6125. <![CDATA[
  6126. +--------+ +----------+
  6127. |2 x Down| |Time- |
  6128. +->|sampling|->|Correlator| |
  6129. | | | | | |4
  6130. | +--------+ +----------+ \/
  6131. | | 2 +-------+
  6132. | | +-->|Speech |5
  6133. +---------+ +--------+ | \/ | |Type |->
  6134. |LPC | |Down | | +----------+ | |
  6135. +->|Analysis | +->|sample |-+------------->|Time- | +-------+
  6136. | | | | |to 8 kHz| |Correlator|----------->
  6137. | +---------+ | +--------+ |__________| 6
  6138. | | | |3
  6139. | \/ | \/
  6140. | +---------+ | +----------+
  6141. | |Whitening| | |Time- |
  6142. -+->|Filter |-+--------------------------->|Correlator|----------->
  6143. 1 | | | | 7
  6144. +---------+ +----------+
  6145. 1: Input signal
  6146. 2: Lag candidates from stage 1
  6147. 3: Lag candidates from stage 2
  6148. 4: Correlation threshold
  6149. 5: Voiced/unvoiced flag
  6150. 6: Pitch correlation
  6151. 7: Pitch lags
  6152. ]]>
  6153. </artwork>
  6154. </figure>
  6155. The pitch analysis finds a binary voiced/unvoiced classification, and, for
  6156. frames classified as voiced, four pitch lags per frame - one for each
  6157. 5&nbsp;ms subframe - and a pitch correlation indicating the periodicity of
  6158. the signal.
  6159. The input is first whitened using a Linear Prediction (LP) whitening filter,
  6160. where the coefficients are computed through standard Linear Prediction Coding
  6161. (LPC) analysis. The order of the whitening filter is 16 for best results, but
  6162. is reduced to 12 for medium complexity and 8 for low complexity modes.
  6163. The whitened signal is analyzed to find pitch lags for which the time
  6164. correlation is high.
  6165. The analysis consists of three stages for reducing the complexity:
  6166. <list style="symbols">
  6167. <t>In the first stage, the whitened signal is downsampled to 4&nbsp;kHz
  6168. (from 8&nbsp;kHz) and the current frame is correlated to a signal delayed
  6169. by a range of lags, starting from a shortest lag corresponding to
  6170. 500&nbsp;Hz, to a longest lag corresponding to 56&nbsp;Hz.</t>
  6171. <t>
  6172. The second stage operates on an 8&nbsp;kHz signal (downsampled from 12, 16,
  6173. or 24&nbsp;kHz) and measures time correlations only near the lags
  6174. corresponding to those that had sufficiently high correlations in the first
  6175. stage. The resulting correlations are adjusted for a small bias towards
  6176. short lags to avoid ending up with a multiple of the true pitch lag.
  6177. The highest adjusted correlation is compared to a threshold depending on:
  6178. <list style="symbols">
  6179. <t>
  6180. Whether the previous frame was classified as voiced
  6181. </t>
  6182. <t>
  6183. The speech activity level
  6184. </t>
  6185. <t>
  6186. The spectral tilt.
  6187. </t>
  6188. </list>
  6189. If the threshold is exceeded, the current frame is classified as voiced and
  6190. the lag with the highest adjusted correlation is stored for a final pitch
  6191. analysis of the highest precision in the third stage.
  6192. </t>
  6193. <t>
  6194. The last stage operates directly on the whitened input signal to compute time
  6195. correlations for each of the four subframes independently in a narrow range
  6196. around the lag with highest correlation from the second stage.
  6197. </t>
  6198. </list>
  6199. </t>
  6200. </section>
  6201. <section title='Noise Shaping Analysis' anchor='noise_shaping_analysis_overview_section'>
  6202. <t>
  6203. The noise shaping analysis finds gains and filter coefficients used in the
  6204. prefilter and noise shaping quantizer. These parameters are chosen such that
  6205. they will fulfill several requirements:
  6206. <list style="symbols">
  6207. <t>
  6208. Balancing quantization noise and bitrate.
  6209. The quantization gains determine the step size between reconstruction levels
  6210. of the excitation signal. Therefore, increasing the quantization gain
  6211. amplifies quantization noise, but also reduces the bitrate by lowering
  6212. the entropy of the quantization indices.
  6213. </t>
  6214. <t>
  6215. Spectral shaping of the quantization noise; the noise shaping quantizer is
  6216. capable of reducing quantization noise in some parts of the spectrum at the
  6217. cost of increased noise in other parts without substantially changing the
  6218. bitrate.
  6219. By shaping the noise such that it follows the signal spectrum, it becomes
  6220. less audible. In practice, best results are obtained by making the shape
  6221. of the noise spectrum slightly flatter than the signal spectrum.
  6222. </t>
  6223. <t>
  6224. De-emphasizing spectral valleys; by using different coefficients in the
  6225. analysis and synthesis part of the prefilter and noise shaping quantizer,
  6226. the levels of the spectral valleys can be decreased relative to the levels
  6227. of the spectral peaks such as speech formants and harmonics.
  6228. This reduces the entropy of the signal, which is the difference between the
  6229. coded signal and the quantization noise, thus lowering the bitrate.
  6230. </t>
  6231. <t>
  6232. Matching the levels of the decoded speech formants to the levels of the
  6233. original speech formants; an adjustment gain and a first order tilt
  6234. coefficient are computed to compensate for the effect of the noise
  6235. shaping quantization on the level and spectral tilt.
  6236. </t>
  6237. </list>
  6238. </t>
  6239. <t>
  6240. <figure align="center" anchor="noise_shape_analysis_spectra_figure"
  6241. title="Noise shaping and spectral de-emphasis illustration">
  6242. <artwork align="center">
  6243. <![CDATA[
  6244. / \ ___
  6245. | // \\
  6246. | // \\ ____
  6247. |_// \\___// \\ ____
  6248. | / ___ \ / \\ // \\
  6249. P |/ / \ \_/ \\_____// \\
  6250. o | / \ ____ \ / \\
  6251. w | / \___/ \ \___/ ____ \\___ 1
  6252. e |/ \ / \ \
  6253. r | \_____/ \ \__ 2
  6254. | \
  6255. | \___ 3
  6256. |
  6257. +---------------------------------------->
  6258. Frequency
  6259. 1: Input signal spectrum
  6260. 2: De-emphasized and level matched spectrum
  6261. 3: Quantization noise spectrum
  6262. ]]>
  6263. </artwork>
  6264. </figure>
  6265. <xref target='noise_shape_analysis_spectra_figure' /> shows an example of an
  6266. input signal spectrum (1).
  6267. After de-emphasis and level matching, the spectrum has deeper valleys (2).
  6268. The quantization noise spectrum (3) more or less follows the input signal
  6269. spectrum, while having slightly less pronounced peaks.
  6270. The entropy, which provides a lower bound on the bitrate for encoding the
  6271. excitation signal, is proportional to the area between the de-emphasized
  6272. spectrum (2) and the quantization noise spectrum (3). Without de-emphasis,
  6273. the entropy is proportional to the area between input spectrum (1) and
  6274. quantization noise (3) - clearly higher.
  6275. </t>
  6276. <t>
  6277. The transformation from input signal to de-emphasized signal can be
  6278. described as a filtering operation with a filter
  6279. <figure align="center">
  6280. <artwork align="center">
  6281. <![CDATA[
  6282. -1 Wana(z)
  6283. H(z) = G * ( 1 - c_tilt * z ) * -------
  6284. Wsyn(z),
  6285. ]]>
  6286. </artwork>
  6287. </figure>
  6288. having an adjustment gain G, a first order tilt adjustment filter with
  6289. tilt coefficient c_tilt, and where
  6290. <figure align="center">
  6291. <artwork align="center">
  6292. <![CDATA[
  6293. 16 d
  6294. __ -k -L __ -k
  6295. Wana(z) = (1 - \ (a_ana(k) * z )*(1 - z * \ b_ana(k) * z ),
  6296. /_ /_
  6297. k=1 k=-d
  6298. ]]>
  6299. </artwork>
  6300. </figure>
  6301. is the analysis part of the de-emphasis filter, consisting of the short-term
  6302. shaping filter with coefficients a_ana(k), and the long-term shaping filter
  6303. with coefficients b_ana(k) and pitch lag L.
  6304. The parameter d determines the number of long-term shaping filter taps.
  6305. </t>
  6306. <t>
  6307. Similarly, but without the tilt adjustment, the synthesis part can be written as
  6308. <figure align="center">
  6309. <artwork align="center">
  6310. <![CDATA[
  6311. 16 d
  6312. __ -k -L __ -k
  6313. Wsyn(z) = (1 - \ (a_syn(k) * z )*(1 - z * \ b_syn(k) * z ).
  6314. /_ /_
  6315. k=1 k=-d
  6316. ]]>
  6317. </artwork>
  6318. </figure>
  6319. </t>
  6320. <t>
  6321. All noise shaping parameters are computed and applied per subframe of 5&nbsp;ms.
  6322. First, an LPC analysis is performed on a windowed signal block of 15&nbsp;ms.
  6323. The signal block has a look-ahead of 5&nbsp;ms relative to the current subframe,
  6324. and the window is an asymmetric sine window. The LPC analysis is done with the
  6325. autocorrelation method, with an order of between 8, in lowest-complexity mode,
  6326. and 16, for best quality.
  6327. </t>
  6328. <t>
  6329. Optionally the LPC analysis and noise shaping filters are warped by replacing
  6330. the delay elements by first-order allpass filters.
  6331. This increases the frequency resolution at low frequencies and reduces it at
  6332. high ones, which better matches the human auditory system and improves
  6333. quality.
  6334. The warped analysis and filtering comes at a cost in complexity
  6335. and is therefore only done in higher complexity modes.
  6336. </t>
  6337. <t>
  6338. The quantization gain is found by taking the square root of the residual energy
  6339. from the LPC analysis and multiplying it by a value inversely proportional
  6340. to the coding quality control parameter and the pitch correlation.
  6341. </t>
  6342. <t>
  6343. Next the two sets of short-term noise shaping coefficients a_ana(k) and
  6344. a_syn(k) are obtained by applying different amounts of bandwidth expansion to the
  6345. coefficients found in the LPC analysis.
  6346. This bandwidth expansion moves the roots of the LPC polynomial towards the
  6347. origin, using the formulas
  6348. <figure align="center">
  6349. <artwork align="center">
  6350. <![CDATA[
  6351. k
  6352. a_ana(k) = a(k)*g_ana , and
  6353. k
  6354. a_syn(k) = a(k)*g_syn ,
  6355. ]]>
  6356. </artwork>
  6357. </figure>
  6358. where a(k) is the k'th LPC coefficient, and the bandwidth expansion factors
  6359. g_ana and g_syn are calculated as
  6360. <figure align="center">
  6361. <artwork align="center">
  6362. <![CDATA[
  6363. g_ana = 0.95 - 0.01*C, and
  6364. g_syn = 0.95 + 0.01*C,
  6365. ]]>
  6366. </artwork>
  6367. </figure>
  6368. where C is the coding quality control parameter between 0 and 1.
  6369. Applying more bandwidth expansion to the analysis part than to the synthesis
  6370. part gives the desired de-emphasis of spectral valleys in between formants.
  6371. </t>
  6372. <t>
  6373. The long-term shaping is applied only during voiced frames.
  6374. It uses three filter taps, described by
  6375. <figure align="center">
  6376. <artwork align="center">
  6377. <![CDATA[
  6378. b_ana = F_ana * [0.25, 0.5, 0.25], and
  6379. b_syn = F_syn * [0.25, 0.5, 0.25].
  6380. ]]>
  6381. </artwork>
  6382. </figure>
  6383. For unvoiced frames these coefficients are set to 0. The multiplication factors
  6384. F_ana and F_syn are chosen between 0 and 1, depending on the coding quality
  6385. control parameter, as well as the calculated pitch correlation and smoothed
  6386. subband SNR of the lowest subband. By having F_ana less than F_syn,
  6387. the pitch harmonics are emphasized relative to the valleys in between the
  6388. harmonics.
  6389. </t>
  6390. <t>
  6391. The tilt coefficient c_tilt is for unvoiced frames chosen as
  6392. <figure align="center">
  6393. <artwork align="center">
  6394. <![CDATA[
  6395. c_tilt = 0.25,
  6396. ]]>
  6397. </artwork>
  6398. </figure>
  6399. and as
  6400. <figure align="center">
  6401. <artwork align="center">
  6402. <![CDATA[
  6403. c_tilt = 0.25 + 0.2625 * V
  6404. ]]>
  6405. </artwork>
  6406. </figure>
  6407. for voiced frames, where V is the voice activity level between 0 and 1.
  6408. </t>
  6409. <t>
  6410. The adjustment gain G serves to correct any level mismatch between the original
  6411. and decoded signals that might arise from the noise shaping and de-emphasis.
  6412. This gain is computed as the ratio of the prediction gain of the short-term
  6413. analysis and synthesis filter coefficients. The prediction gain of an LPC
  6414. synthesis filter is the square root of the output energy when the filter is
  6415. excited by a unit-energy impulse on the input.
  6416. An efficient way to compute the prediction gain is by first computing the
  6417. reflection coefficients from the LPC coefficients through the step-down
  6418. algorithm, and extracting the prediction gain from the reflection coefficients
  6419. as
  6420. <figure align="center">
  6421. <artwork align="center">
  6422. <![CDATA[
  6423. K
  6424. ___ 2 -0.5
  6425. predGain = ( | | 1 - (r_k) ) ,
  6426. k=1
  6427. ]]>
  6428. </artwork>
  6429. </figure>
  6430. where r_k is the k'th reflection coefficient.
  6431. </t>
  6432. <t>
  6433. Initial values for the quantization gains are computed as the square-root of
  6434. the residual energy of the LPC analysis, adjusted by the coding quality control
  6435. parameter.
  6436. These quantization gains are later adjusted based on the results of the
  6437. prediction analysis.
  6438. </t>
  6439. </section>
  6440. <section title='Prediction Analysis' anchor='pred_ana_overview_section'>
  6441. <t>
  6442. The prediction analysis is performed in one of two ways depending on how
  6443. the pitch estimator classified the frame.
  6444. The processing for voiced and unvoiced speech is described in
  6445. <xref target='pred_ana_voiced_overview_section' /> and
  6446. <xref target='pred_ana_unvoiced_overview_section' />, respectively.
  6447. Inputs to this function include the pre-whitened signal from the
  6448. pitch estimator (see <xref target='pitch_estimator_overview_section'/>).
  6449. </t>
  6450. <section title='Voiced Speech' anchor='pred_ana_voiced_overview_section'>
  6451. <t>
  6452. For a frame of voiced speech the pitch pulses will remain dominant in the
  6453. pre-whitened input signal.
  6454. Further whitening is desirable as it leads to higher quality at the same
  6455. available bitrate.
  6456. To achieve this, a Long-Term Prediction (LTP) analysis is carried out to
  6457. estimate the coefficients of a fifth-order LTP filter for each of four
  6458. subframes.
  6459. The LTP coefficients are quantized using the method described in
  6460. <xref target='ltp_quantizer_overview_section'/>, and the quantized LTP
  6461. coefficients are used to compute the LTP residual signal.
  6462. This LTP residual signal is the input to an LPC analysis where the LPC coefficients are
  6463. estimated using Burg's method <xref target="Burg"/>, such that the residual energy is minimized.
  6464. The estimated LPC coefficients are converted to a Line Spectral Frequency (LSF) vector
  6465. and quantized as described in <xref target='lsf_quantizer_overview_section'/>.
  6466. After quantization, the quantized LSF vector is converted back to LPC
  6467. coefficients using the full procedure in <xref target="silk_nlsfs"/>.
  6468. By using quantized LTP coefficients and LPC coefficients derived from the
  6469. quantized LSF coefficients, the encoder remains fully synchronized with the
  6470. decoder.
  6471. The quantized LPC and LTP coefficients are also used to filter the input
  6472. signal and measure residual energy for each of the four subframes.
  6473. </t>
  6474. </section>
  6475. <section title='Unvoiced Speech' anchor='pred_ana_unvoiced_overview_section'>
  6476. <t>
  6477. For a speech signal that has been classified as unvoiced, there is no need
  6478. for LTP filtering, as it has already been determined that the pre-whitened
  6479. input signal is not periodic enough within the allowed pitch period range
  6480. for LTP analysis to be worth the cost in terms of complexity and bitrate.
  6481. The pre-whitened input signal is therefore discarded, and instead the input
  6482. signal is used for LPC analysis using Burg's method.
  6483. The resulting LPC coefficients are converted to an LSF vector and quantized
  6484. as described in the following section.
  6485. They are then transformed back to obtain quantized LPC coefficients, which
  6486. are then used to filter the input signal and measure residual energy for
  6487. each of the four subframes.
  6488. </t>
  6489. <section title="Burg's Method">
  6490. <t>
  6491. The main purpose of linear prediction in SILK is to reduce the bitrate by
  6492. minimizing the residual energy.
  6493. At least at high bitrates, perceptual aspects are handled
  6494. independently by the noise shaping filter.
  6495. Burg's method is used because it provides higher prediction gain
  6496. than the autocorrelation method and, unlike the covariance method,
  6497. produces stable filters (assuming numerical errors don't spoil
  6498. that). SILK's implementation of Burg's method is also computationally
  6499. faster than the autocovariance method.
  6500. The implementation of Burg's method differs from traditional
  6501. implementations in two aspects.
  6502. The first difference is that it
  6503. operates on autocorrelations, similar to the Schur algorithm <xref target="Schur"/>, but
  6504. with a simple update to the autocorrelations after finding each
  6505. reflection coefficient to make the result identical to Burg's method.
  6506. This brings down the complexity of Burg's method to near that of
  6507. the autocorrelation method.
  6508. The second difference is that the signal in each subframe is scaled
  6509. by the inverse of the residual quantization step size. Subframes with
  6510. a small quantization step size will on average spend more bits for a
  6511. given amount of residual energy than subframes with a large step size.
  6512. Without scaling, Burg's method minimizes the total residual energy in
  6513. all subframes, which doesn't necessarily minimize the total number of
  6514. bits needed for coding the quantized residual. The residual energy
  6515. of the scaled subframes is a better measure for that number of
  6516. bits.
  6517. </t>
  6518. </section>
  6519. </section>
  6520. </section>
  6521. <section title='LSF Quantization' anchor='lsf_quantizer_overview_section'>
  6522. <t>
  6523. Unlike many other speech codecs, SILK uses variable bitrate coding
  6524. for the LSFs.
  6525. This improves the average rate-distortion (R-D) tradeoff and reduces outliers.
  6526. The variable bitrate coding minimizes a linear combination of the weighted
  6527. quantization errors and the bitrate.
  6528. The weights for the quantization errors are the Inverse
  6529. Harmonic Mean Weighting (IHMW) function proposed by Laroia et al.
  6530. (see <xref target="laroia-icassp" />).
  6531. These weights are referred to here as Laroia weights.
  6532. </t>
  6533. <t>
  6534. The LSF quantizer consists of two stages.
  6535. The first stage is an (unweighted) vector quantizer (VQ), with a
  6536. codebook size of 32 vectors.
  6537. The quantization errors for the codebook vector are sorted, and
  6538. for the N best vectors a second stage quantizer is run.
  6539. By varying the number N a tradeoff is made between R-D performance
  6540. and computational efficiency.
  6541. For each of the N codebook vectors the Laroia weights corresponding
  6542. to that vector (and not to the input vector) are calculated.
  6543. Then the residual between the input LSF vector and the codebook
  6544. vector is scaled by the square roots of these Laroia weights.
  6545. This scaling partially normalizes error sensitivity for the
  6546. residual vector, so that a uniform quantizer with fixed
  6547. step sizes can be used in the second stage without too much
  6548. performance loss.
  6549. And by scaling with Laroia weights determined from the first-stage
  6550. codebook vector, the process can be reversed in the decoder.
  6551. </t>
  6552. <t>
  6553. The second stage uses predictive delayed decision scalar
  6554. quantization.
  6555. The quantization error is weighted by Laroia weights determined
  6556. from the LSF input vector.
  6557. The predictor multiplies the previous quantized residual value
  6558. by a prediction coefficient that depends on the vector index from the
  6559. first stage VQ and on the location in the LSF vector.
  6560. The prediction is subtracted from the LSF residual value before
  6561. quantizing the result, and added back afterwards.
  6562. This subtraction can be interpreted as shifting the quantization levels
  6563. of the scalar quantizer, and as a result the quantization error of
  6564. each value depends on the quantization decision of the previous value.
  6565. This dependency is exploited by the delayed decision mechanism to
  6566. search for a quantization sequency with best R-D performance
  6567. with a Viterbi-like algorithm <xref target="Viterbi"/>.
  6568. The quantizer processes the residual LSF vector in reverse order
  6569. (i.e., it starts with the highest residual LSF value).
  6570. This is done because the prediction works slightly
  6571. better in the reverse direction.
  6572. </t>
  6573. <t>
  6574. The quantization index of the first stage is entropy coded.
  6575. The quantization sequence from the second stage is also entropy
  6576. coded, where for each element the probability table is chosen
  6577. depending on the vector index from the first stage and the location
  6578. of that element in the LSF vector.
  6579. </t>
  6580. <section title='LSF Stabilization' anchor='lsf_stabilizer_overview_section'>
  6581. <t>
  6582. If the input is stable, finding the best candidate usually results in a
  6583. quantized vector that is also stable. Because of the two-stage approach,
  6584. however, it is possible that the best quantization candidate is unstable.
  6585. The encoder applies the same stabilization procedure applied by the decoder
  6586. (see <xref target="silk_nlsf_stabilization"/> to ensure the LSF parameters
  6587. are within their valid range, increasingly sorted, and have minimum
  6588. distances between each other and the border values.
  6589. </t>
  6590. </section>
  6591. </section>
  6592. <section title='LTP Quantization' anchor='ltp_quantizer_overview_section'>
  6593. <t>
  6594. For voiced frames, the prediction analysis described in
  6595. <xref target='pred_ana_voiced_overview_section' /> resulted in four sets
  6596. (one set per subframe) of five LTP coefficients, plus four weighting matrices.
  6597. The LTP coefficients for each subframe are quantized using entropy constrained
  6598. vector quantization.
  6599. A total of three vector codebooks are available for quantization, with
  6600. different rate-distortion trade-offs. The three codebooks have 10, 20, and
  6601. 40 vectors and average rates of about 3, 4, and 5 bits per vector, respectively.
  6602. Consequently, the first codebook has larger average quantization distortion at
  6603. a lower rate, whereas the last codebook has smaller average quantization
  6604. distortion at a higher rate.
  6605. Given the weighting matrix W_ltp and LTP vector b, the weighted rate-distortion
  6606. measure for a codebook vector cb_i with rate r_i is give by
  6607. <figure align="center">
  6608. <artwork align="center">
  6609. <![CDATA[
  6610. RD = u * (b - cb_i)' * W_ltp * (b - cb_i) + r_i,
  6611. ]]>
  6612. </artwork>
  6613. </figure>
  6614. where u is a fixed, heuristically-determined parameter balancing the distortion
  6615. and rate.
  6616. Which codebook gives the best performance for a given LTP vector depends on the
  6617. weighting matrix for that LTP vector.
  6618. For example, for a low valued W_ltp, it is advantageous to use the codebook
  6619. with 10 vectors as it has a lower average rate.
  6620. For a large W_ltp, on the other hand, it is often better to use the codebook
  6621. with 40 vectors, as it is more likely to contain the best codebook vector.
  6622. The weighting matrix W_ltp depends mostly on two aspects of the input signal.
  6623. The first is the periodicity of the signal; the more periodic, the larger W_ltp.
  6624. The second is the change in signal energy in the current subframe, relative to
  6625. the signal one pitch lag earlier.
  6626. A decaying energy leads to a larger W_ltp than an increasing energy.
  6627. Both aspects fluctuate relatively slowly, which causes the W_ltp matrices for
  6628. different subframes of one frame often to be similar.
  6629. Because of this, one of the three codebooks typically gives good performance
  6630. for all subframes, and therefore the codebook search for the subframe LTP
  6631. vectors is constrained to only allow codebook vectors to be chosen from the
  6632. same codebook, resulting in a rate reduction.
  6633. </t>
  6634. <t>
  6635. To find the best codebook, each of the three vector codebooks is
  6636. used to quantize all subframe LTP vectors and produce a combined
  6637. weighted rate-distortion measure for each vector codebook.
  6638. The vector codebook with the lowest combined rate-distortion
  6639. over all subframes is chosen. The quantized LTP vectors are used
  6640. in the noise shaping quantizer, and the index of the codebook
  6641. plus the four indices for the four subframe codebook vectors
  6642. are passed on to the range encoder.
  6643. </t>
  6644. </section>
  6645. <section title='Prefilter'>
  6646. <t>
  6647. In the prefilter the input signal is filtered using the spectral valley
  6648. de-emphasis filter coefficients from the noise shaping analysis
  6649. (see <xref target='noise_shaping_analysis_overview_section'/>).
  6650. By applying only the noise shaping analysis filter to the input signal,
  6651. it provides the input to the noise shaping quantizer.
  6652. </t>
  6653. </section>
  6654. <section title='Noise Shaping Quantizer'>
  6655. <t>
  6656. The noise shaping quantizer independently shapes the signal and coding noise
  6657. spectra to obtain a perceptually higher quality at the same bitrate.
  6658. </t>
  6659. <t>
  6660. The prefilter output signal is multiplied with a compensation gain G computed
  6661. in the noise shaping analysis. Then the output of a synthesis shaping filter
  6662. is added, and the output of a prediction filter is subtracted to create a
  6663. residual signal.
  6664. The residual signal is multiplied by the inverse quantized quantization gain
  6665. from the noise shaping analysis, and input to a scalar quantizer.
  6666. The quantization indices of the scalar quantizer represent a signal of pulses
  6667. that is input to the pyramid range encoder.
  6668. The scalar quantizer also outputs a quantization signal, which is multiplied
  6669. by the quantized quantization gain from the noise shaping analysis to create
  6670. an excitation signal.
  6671. The output of the prediction filter is added to the excitation signal to form
  6672. the quantized output signal y(n).
  6673. The quantized output signal y(n) is input to the synthesis shaping and
  6674. prediction filters.
  6675. </t>
  6676. <t>
  6677. Optionally the noise shaping quantizer operates in a delayed decision
  6678. mode.
  6679. In this mode it uses a Viterbi algorithm to keep track of
  6680. multiple rounding choices in the quantizer and select the best
  6681. one after a delay of 32 samples. This improves the rate/distortion
  6682. performance of the quantizer.
  6683. </t>
  6684. </section>
  6685. <section title='Constant Bitrate Mode'>
  6686. <t>
  6687. SILK was designed to run in Variable Bitrate (VBR) mode. However
  6688. the reference implementation also has a Constant Bitrate (CBR) mode
  6689. for SILK. In CBR mode SILK will attempt to encode each packet with
  6690. no more than the allowed number of bits. The Opus wrapper code
  6691. then pads the bitstream if any unused bits are left in SILK mode, or
  6692. encodes the high band with the remaining number of bits in Hybrid mode.
  6693. The number of payload bits is adjusted by changing
  6694. the quantization gains and the rate/distortion tradeoff in the noise
  6695. shaping quantizer, in an iterative loop
  6696. around the noise shaping quantizer and entropy coding.
  6697. Compared to the SILK VBR mode, the CBR mode has lower
  6698. audio quality at a given average bitrate, and also has higher
  6699. computational complexity.
  6700. </t>
  6701. </section>
  6702. </section>
  6703. </section>
  6704. <section title="CELT Encoder">
  6705. <t>
  6706. Most of the aspects of the CELT encoder can be directly derived from the description
  6707. of the decoder. For example, the filters and rotations in the encoder are simply the
  6708. inverse of the operation performed by the decoder. Similarly, the quantizers generally
  6709. optimize for the mean square error (because noise shaping is part of the bit-stream itself),
  6710. so no special search is required. For this reason, only the less straightforward aspects of the
  6711. encoder are described here.
  6712. </t>
  6713. <section anchor="pitch-prefilter" title="Pitch Prefilter">
  6714. <t>The pitch prefilter is applied after the pre-emphasis. It is applied
  6715. in such a way as to be the inverse of the decoder's post-filter. The main non-obvious aspect of the
  6716. prefilter is the selection of the pitch period. The pitch search should be optimized for the
  6717. following criteria:
  6718. <list style="symbols">
  6719. <t>continuity: it is important that the pitch period
  6720. does not change abruptly between frames; and</t>
  6721. <t>avoidance of pitch multiples: when the period used is a multiple of the real period
  6722. (lower frequency fundamental), the post-filter loses most of its ability to reduce noise</t>
  6723. </list>
  6724. </t>
  6725. </section>
  6726. <section anchor="normalization" title="Bands and Normalization">
  6727. <t>
  6728. The MDCT output is divided into bands that are designed to match the ear's critical
  6729. bands for the smallest (2.5&nbsp;ms) frame size. The larger frame sizes use integer
  6730. multiples of the 2.5&nbsp;ms layout. For each band, the encoder
  6731. computes the energy that will later be encoded. Each band is then normalized by the
  6732. square root of the <spanx style="strong">unquantized</spanx> energy, such that each band now forms a unit vector X.
  6733. The energy and the normalization are computed by compute_band_energies()
  6734. and normalise_bands() (bands.c), respectively.
  6735. </t>
  6736. </section>
  6737. <section anchor="energy-quantization" title="Energy Envelope Quantization">
  6738. <t>
  6739. Energy quantization (both coarse and fine) can be easily understood from the decoding process.
  6740. For all useful bitrates, the coarse quantizer always chooses the quantized log energy value that
  6741. minimizes the error for each band. Only at very low rate does the encoder allow larger errors to
  6742. minimize the rate and avoid using more bits than are available. When the
  6743. available CPU requirements allow it, it is best to try encoding the coarse energy both with and without
  6744. inter-frame prediction such that the best prediction mode can be selected. The optimal mode depends on
  6745. the coding rate, the available bitrate, and the current rate of packet loss.
  6746. </t>
  6747. <t>The fine energy quantizer always chooses the quantized log energy value that
  6748. minimizes the error for each band because the rate of the fine quantization depends only
  6749. on the bit allocation and not on the values that are coded.
  6750. </t>
  6751. </section> <!-- Energy quant -->
  6752. <section title="Bit Allocation">
  6753. <t>The encoder must use exactly the same bit allocation process as used by the decoder
  6754. and described in <xref target="allocation"/>. The three mechanisms that can be used by the
  6755. encoder to adjust the bitrate on a frame-by-frame basis are band boost, allocation trim,
  6756. and band skipping.
  6757. </t>
  6758. <section title="Band Boost">
  6759. <t>The reference encoder makes a decision to boost a band when the energy of that band is significantly
  6760. higher than that of the neighboring bands. Let E_j be the log-energy of band j, we define
  6761. <list>
  6762. <t>D_j = 2*E_j - E_j-1 - E_j+1 </t>
  6763. </list>
  6764. 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,
  6765. while for LM&lt;1, t1=3 and t2=5.
  6766. </t>
  6767. </section>
  6768. <section title="Allocation Trim">
  6769. <t>The allocation trim is a value between 0 and 10 (inclusively) that controls the allocation
  6770. balance between the low and high frequencies. The encoder starts with a safe "default" of 5
  6771. and deviates from that default in two different ways. First the trim can deviate by +/- 2
  6772. depending on the spectral tilt of the input signal. For signals with more low frequencies, the
  6773. trim is increased by up to 2, while for signals with more high frequencies, the trim is
  6774. decreased by up to 2.
  6775. For stereo inputs, the trim value can
  6776. be decreased by up to 4 when the inter-channel correlation at low frequency (first 8 bands)
  6777. is high. </t>
  6778. </section>
  6779. <section title="Band Skipping">
  6780. <t>The encoder uses band skipping to ensure that the shape of the bands is only coded
  6781. if there is at least 1/2 bit per sample available for the PVQ. If not, then no bit is allocated
  6782. and folding is used instead. To ensure continuity in the allocation, some amount of hysteresis is
  6783. added to the process, such that a band that received PVQ bits in the previous frame only needs 7/16
  6784. bit/sample to be coded for the current frame, while a band that did not receive PVQ bits in the
  6785. previous frames needs at least 9/16 bit/sample to be coded.</t>
  6786. </section>
  6787. </section>
  6788. <section title="Stereo Decisions">
  6789. <t>Because CELT applies mid-side stereo coupling in the normalized domain, it does not suffer from
  6790. important stereo image problems even when the two channels are completely uncorrelated. For this reason
  6791. it is always safe to use stereo coupling on any audio frame. That being said, there are some frames
  6792. for which dual (independent) stereo is still more efficient. This decision is made by comparing the estimated
  6793. entropy with and without coupling over the first 13 bands, taking into account the fact that all bands with
  6794. more than two MDCT bins require one extra degree of freedom when coded in mid-side. Let L1_ms and L1_lr
  6795. be the L1-norm of the mid-side vector and the L1-norm of the left-right vector, respectively. The decision
  6796. to use mid-side is made if and only if
  6797. <figure align="center">
  6798. <artwork align="center"><![CDATA[
  6799. L1_ms L1_lr
  6800. -------- < -----
  6801. bins + E bins
  6802. ]]></artwork>
  6803. </figure>
  6804. where bins is the number of MDCT bins in the first 13 bands and E is the number of extra degrees of
  6805. freedom for mid-side coding. For LM>1, E=13, otherwise E=5.
  6806. </t>
  6807. <t>The reference encoder decides on the intensity stereo threshold based on the bitrate alone. After
  6808. taking into account the frame size by subtracting 80 bits per frame for coarse energy, the first
  6809. band using intensity coding is as follows:
  6810. </t>
  6811. <texttable anchor="intensity-thresholds"
  6812. title="Thresholds for Intensity Stereo">
  6813. <ttcol align='center'>bitrate (kb/s)</ttcol>
  6814. <ttcol align='center'>start band</ttcol>
  6815. <c>&lt;35</c> <c>8</c>
  6816. <c>35-50</c> <c>12</c>
  6817. <c>50-68</c> <c>16</c>
  6818. <c>84-84</c> <c>18</c>
  6819. <c>84-102</c> <c>19</c>
  6820. <c>102-130</c> <c>20</c>
  6821. <c>&gt;130</c> <c>disabled</c>
  6822. </texttable>
  6823. </section>
  6824. <section title="Time-Frequency Decision">
  6825. <t>
  6826. The choice of time-frequency resolution used in <xref target="tf-change"></xref> is based on
  6827. R-D optimization. The distortion is the L1-norm (sum of absolute values) of each band
  6828. after each TF resolution under consideration. The L1 norm is used because it represents the entropy
  6829. for a Laplacian source. The number of bits required to code a change in TF resolution between
  6830. two bands is higher than the cost of having those two bands use the same resolution, which is
  6831. what requires the R-D optimization. The optimal decision is computed using the Viterbi algorithm.
  6832. See tf_analysis() in celt/celt.c.
  6833. </t>
  6834. </section>
  6835. <section title="Spreading Values Decision">
  6836. <t>
  6837. The choice of the spreading value in <xref target="spread values"></xref> has an
  6838. impact on the nature of the coding noise introduced by CELT. The larger the f_r value, the
  6839. lower the impact of the rotation, and the more tonal the coding noise. The
  6840. more tonal the signal, the more tonal the noise should be, so the CELT encoder determines
  6841. the optimal value for f_r by estimating how tonal the signal is. The tonality estimate
  6842. is based on discrete pdf (4-bin histogram) of each band. Bands that have a large number of small
  6843. values are considered more tonal and a decision is made by combining all bands with more than
  6844. 8 samples. See spreading_decision() in celt/bands.c.
  6845. </t>
  6846. </section>
  6847. <section anchor="pvq" title="Spherical Vector Quantization">
  6848. <t>CELT uses a Pyramid Vector Quantization (PVQ) <xref target="PVQ"></xref>
  6849. codebook for quantizing the details of the spectrum in each band that have not
  6850. been predicted by the pitch predictor. The PVQ codebook consists of all sums
  6851. of K signed pulses in a vector of N samples, where two pulses at the same position
  6852. are required to have the same sign. Thus the codebook includes
  6853. all integer codevectors y of N dimensions that satisfy sum(abs(y(j))) = K.
  6854. </t>
  6855. <t>
  6856. In bands where there are sufficient bits allocated PVQ is used to encode
  6857. the unit vector that results from the normalization in
  6858. <xref target="normalization"></xref> directly. Given a PVQ codevector y,
  6859. the unit vector X is obtained as X = y/||y||, where ||.|| denotes the
  6860. L2 norm.
  6861. </t>
  6862. <section anchor="pvq-search" title="PVQ Search">
  6863. <t>
  6864. The search for the best codevector y is performed by alg_quant()
  6865. (vq.c). There are several possible approaches to the
  6866. search, with a trade-off between quality and complexity. The method used in the reference
  6867. implementation computes an initial codeword y1 by projecting the normalized spectrum
  6868. X onto the codebook pyramid of K-1 pulses:
  6869. </t>
  6870. <t>
  6871. y0 = truncate_towards_zero( (K-1) * X / sum(abs(X)))
  6872. </t>
  6873. <t>
  6874. Depending on N, K and the input data, the initial codeword y0 may contain from
  6875. 0 to K-1 non-zero values. All the remaining pulses, with the exception of the last one,
  6876. are found iteratively with a greedy search that minimizes the normalized correlation
  6877. between y and X:
  6878. <figure align="center">
  6879. <artwork align="center"><![CDATA[
  6880. T
  6881. J = -X * y / ||y||
  6882. ]]></artwork>
  6883. </figure>
  6884. </t>
  6885. <t>
  6886. The search described above is considered to be a good trade-off between quality
  6887. and computational cost. However, there are other possible ways to search the PVQ
  6888. codebook and the implementers MAY use any other search methods. See alg_quant() in celt/vq.c.
  6889. </t>
  6890. </section>
  6891. <section anchor="cwrs-encoder" title="PVQ Encoding">
  6892. <t>
  6893. The vector to encode, X, is converted into an index i such that
  6894. 0&nbsp;&lt;=&nbsp;i&nbsp;&lt;&nbsp;V(N,K) as follows.
  6895. Let i&nbsp;=&nbsp;0 and k&nbsp;=&nbsp;0.
  6896. Then for j&nbsp;=&nbsp;(N&nbsp;-&nbsp;1) down to 0, inclusive, do:
  6897. <list style="numbers">
  6898. <t>
  6899. If k&nbsp;>&nbsp;0, set
  6900. i&nbsp;=&nbsp;i&nbsp;+&nbsp;(V(N-j-1,k-1)&nbsp;+&nbsp;V(N-j,k-1))/2.
  6901. </t>
  6902. <t>Set k&nbsp;=&nbsp;k&nbsp;+&nbsp;abs(X[j]).</t>
  6903. <t>
  6904. If X[j]&nbsp;&lt;&nbsp;0, set
  6905. i&nbsp;=&nbsp;i&nbsp;+&nbsp;(V(N-j-1,k)&nbsp;+&nbsp;V(N-j,k))/2.
  6906. </t>
  6907. </list>
  6908. </t>
  6909. <t>
  6910. The index i is then encoded using the procedure in
  6911. <xref target="encoding-ints"/> with ft&nbsp;=&nbsp;V(N,K).
  6912. </t>
  6913. </section>
  6914. </section>
  6915. </section>
  6916. </section>
  6917. <section anchor="conformance" title="Conformance">
  6918. <t>
  6919. It is our intention to allow the greatest possible choice of freedom in
  6920. implementing the specification. For this reason, outside of the exceptions
  6921. noted in this section, conformance is defined through the reference
  6922. implementation of the decoder provided in <xref target="ref-implementation"/>.
  6923. Although this document includes an English description of the codec, should
  6924. the description contradict the source code of the reference implementation,
  6925. the latter shall take precedence.
  6926. </t>
  6927. <t>
  6928. Compliance with this specification means that in addition to following the normative keywords in this document,
  6929. a decoder's output MUST also be
  6930. within the thresholds specified by the opus_compare.c tool (included
  6931. with the code) when compared to the reference implementation for each of the
  6932. test vectors provided (see <xref target="test-vectors"></xref>) and for each output
  6933. sampling rate and channel count supported. In addition, a compliant
  6934. decoder implementation MUST have the same final range decoder state as that of the
  6935. reference decoder. It is therefore RECOMMENDED that the
  6936. decoder implement the same functional behavior as the reference.
  6937. A decoder implementation is not required to support all output sampling
  6938. rates or all output channel counts.
  6939. </t>
  6940. <section title="Testing">
  6941. <t>
  6942. Using the reference code provided in <xref target="ref-implementation"></xref>,
  6943. a test vector can be decoded with
  6944. <list>
  6945. <t>opus_demo -d &lt;rate&gt; &lt;channels&gt; testvectorX.bit testX.out</t>
  6946. </list>
  6947. where &lt;rate&gt; is the sampling rate and can be 8000, 12000, 16000, 24000, or 48000, and
  6948. &lt;channels&gt; is 1 for mono or 2 for stereo.
  6949. </t>
  6950. <t>
  6951. If the range decoder state is incorrect for one of the frames, the decoder will exit with
  6952. "Error: Range coder state mismatch between encoder and decoder". If the decoder succeeds, then
  6953. the output can be compared with the "reference" output with
  6954. <list>
  6955. <t>opus_compare -s -r &lt;rate&gt; testvectorX.dec testX.out</t>
  6956. </list>
  6957. for stereo or
  6958. <list>
  6959. <t>opus_compare -r &lt;rate&gt; testvectorX.dec testX.out</t>
  6960. </list>
  6961. for mono.
  6962. </t>
  6963. <t>In addition to indicating whether the test vector comparison passes, the opus_compare tool
  6964. outputs an "Opus quality metric" that indicates how well the tested decoder matches the
  6965. reference implementation. A quality of 0 corresponds to the passing threshold, while
  6966. a quality of 100 is the highest possible value and means that the output of the tested decoder is identical to the reference
  6967. implementation. The passing threshold (quality 0) was calibrated in such a way that it corresponds to
  6968. additive white noise with a 48 dB SNR (similar to what can be obtained on a cassette deck).
  6969. It is still possible for an implementation to sound very good with such a low quality measure
  6970. (e.g. if the deviation is due to inaudible phase distortion), but unless this is verified by
  6971. listening tests, it is RECOMMENDED that implementations achieve a quality above 90 for 48&nbsp;kHz
  6972. decoding. For other sampling rates, it is normal for the quality metric to be lower
  6973. (typically as low as 50 even for a good implementation) because of harmless mismatch with
  6974. the delay and phase of the internal sampling rate conversion.
  6975. </t>
  6976. <t>
  6977. On POSIX environments, the run_vectors.sh script can be used to verify all test
  6978. vectors. This can be done with
  6979. <list>
  6980. <t>run_vectors.sh &lt;exec path&gt; &lt;vector path&gt; &lt;rate&gt;</t>
  6981. </list>
  6982. where &lt;exec path&gt; is the directory where the opus_demo and opus_compare executables
  6983. are built and &lt;vector path&gt; is the directory containing the test vectors.
  6984. </t>
  6985. </section>
  6986. <section anchor="opus-custom" title="Opus Custom">
  6987. <t>
  6988. Opus Custom is an OPTIONAL part of the specification that is defined to
  6989. handle special sample rates and frame rates that are not supported by the
  6990. main Opus specification. Use of Opus Custom is discouraged for all but very
  6991. special applications for which a frame size different from 2.5, 5, 10, or 20&nbsp;ms is
  6992. needed (for either complexity or latency reasons). Because Opus Custom is
  6993. optional, streams encoded using Opus Custom cannot be expected to be decodable by all Opus
  6994. implementations. Also, because no in-band mechanism exists for specifying the sampling
  6995. rate and frame size of Opus Custom streams, out-of-band signaling is required.
  6996. In Opus Custom operation, only the CELT layer is available, using the opus_custom_* function
  6997. calls in opus_custom.h.
  6998. </t>
  6999. </section>
  7000. </section>
  7001. <section anchor="security" title="Security Considerations">
  7002. <t>
  7003. Implementations of the Opus codec need to take appropriate security considerations
  7004. into account, as outlined in <xref target="DOS"/>.
  7005. It is extremely important for the decoder to be robust against malicious
  7006. payloads.
  7007. Malicious payloads must not cause the decoder to overrun its allocated memory
  7008. or to take an excessive amount of resources to decode.
  7009. Although problems
  7010. in encoders are typically rarer, the same applies to the encoder. Malicious
  7011. audio streams must not cause the encoder to misbehave because this would
  7012. allow an attacker to attack transcoding gateways.
  7013. </t>
  7014. <t>
  7015. The reference implementation contains no known buffer overflow or cases where
  7016. a specially crafted packet or audio segment could cause a significant increase
  7017. in CPU load.
  7018. However, on certain CPU architectures where denormalized floating-point
  7019. operations are much slower than normal floating-point operations, it is
  7020. possible for some audio content (e.g., silence or near-silence) to cause an
  7021. increase in CPU load.
  7022. Denormals can be introduced by reordering operations in the compiler and depend
  7023. on the target architecture, so it is difficult to guarantee that an implementation
  7024. avoids them.
  7025. For architectures on which denormals are problematic, adding very small
  7026. floating-point offsets to the affected signals to prevent significant numbers
  7027. of denormalized operations is RECOMMENDED.
  7028. Alternatively, it is often possible to configure the hardware to treat
  7029. denormals as zero (DAZ).
  7030. No such issue exists for the fixed-point reference implementation.
  7031. </t>
  7032. <t>The reference implementation was validated in the following conditions:
  7033. <list style="numbers">
  7034. <t>
  7035. Sending the decoder valid packets generated by the reference encoder and
  7036. verifying that the decoder's final range coder state matches that of the
  7037. encoder.
  7038. </t>
  7039. <t>
  7040. Sending the decoder packets generated by the reference encoder and then
  7041. subjected to random corruption.
  7042. </t>
  7043. <t>Sending the decoder random packets.</t>
  7044. <t>
  7045. Sending the decoder packets generated by a version of the reference encoder
  7046. modified to make random coding decisions (internal fuzzing), including mode
  7047. switching, and verifying that the range coder final states match.
  7048. </t>
  7049. </list>
  7050. In all of the conditions above, both the encoder and the decoder were run
  7051. inside the <xref target="Valgrind">Valgrind</xref> memory
  7052. debugger, which tracks reads and writes to invalid memory regions as well as
  7053. the use of uninitialized memory.
  7054. There were no errors reported on any of the tested conditions.
  7055. </t>
  7056. </section>
  7057. <section title="IANA Considerations">
  7058. <t>
  7059. This document has no actions for IANA.
  7060. </t>
  7061. </section>
  7062. <section anchor="Acknowledgements" title="Acknowledgements">
  7063. <t>
  7064. Thanks to all other developers, including Raymond Chen, Soeren Skak Jensen, Gregory Maxwell,
  7065. Christopher Montgomery, and Karsten Vandborg Soerensen. We would also
  7066. like to thank Igor Dyakonov, Jan Skoglund, and Christian Hoene for their help with subjective testing of the
  7067. Opus codec. Thanks to Ralph Giles, John Ridges, Ben Schwartz, Keith Yan, Christian Hoene, Kat Walsh, and many others on the Opus and CELT mailing lists
  7068. for their bug reports and feedback.
  7069. </t>
  7070. </section>
  7071. <section title="Copying Conditions">
  7072. <t>The authors agree to grant third parties the irrevocable right to copy, use and distribute
  7073. the work (excluding Code Components available under the simplified BSD license), with or
  7074. without modification, in any medium, without royalty, provided that, unless separate
  7075. permission is granted, redistributed modified works do not contain misleading author, version,
  7076. name of work, or endorsement information.</t>
  7077. </section>
  7078. </middle>
  7079. <back>
  7080. <references title="Normative References">
  7081. <reference anchor="rfc2119">
  7082. <front>
  7083. <title>Key words for use in RFCs to Indicate Requirement Levels </title>
  7084. <author initials="S." surname="Bradner" fullname="Scott Bradner"></author>
  7085. </front>
  7086. <seriesInfo name="RFC" value="2119" />
  7087. </reference>
  7088. </references>
  7089. <references title="Informative References">
  7090. <reference anchor='requirements'>
  7091. <front>
  7092. <title>Requirements for an Internet Audio Codec</title>
  7093. <author initials='J.-M.' surname='Valin' fullname='J.-M. Valin'>
  7094. <organization /></author>
  7095. <author initials='K.' surname='Vos' fullname='K. Vos'>
  7096. <organization /></author>
  7097. <author>
  7098. <organization>IETF</organization></author>
  7099. <date year='2011' month='August' />
  7100. <abstract>
  7101. <t>This document provides specific requirements for an Internet audio
  7102. codec. These requirements address quality, sample rate, bitrate,
  7103. and packet-loss robustness, as well as other desirable properties.
  7104. </t></abstract></front>
  7105. <seriesInfo name='RFC' value='6366' />
  7106. <format type='TXT' target='http://tools.ietf.org/rfc/rfc6366.txt' />
  7107. </reference>
  7108. <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.3550.xml"?>
  7109. <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.3533.xml"?>
  7110. <reference anchor='SILK' target='http://developer.skype.com/silk'>
  7111. <front>
  7112. <title>SILK Speech Codec</title>
  7113. <author initials='K.' surname='Vos' fullname='K. Vos'>
  7114. <organization /></author>
  7115. <author initials='S.' surname='Jensen' fullname='S. Jensen'>
  7116. <organization /></author>
  7117. <author initials='K.' surname='Soerensen' fullname='K. Soerensen'>
  7118. <organization /></author>
  7119. <date year='2010' month='March' />
  7120. <abstract>
  7121. <t></t>
  7122. </abstract></front>
  7123. <seriesInfo name='Internet-Draft' value='draft-vos-silk-01' />
  7124. <format type='TXT' target='http://tools.ietf.org/html/draft-vos-silk-01' />
  7125. </reference>
  7126. <reference anchor="laroia-icassp">
  7127. <front>
  7128. <title abbrev="Robust and Efficient Quantization of Speech LSP">
  7129. Robust and Efficient Quantization of Speech LSP Parameters Using Structured Vector Quantization
  7130. </title>
  7131. <author initials="R.L." surname="Laroia" fullname="R.">
  7132. <organization/>
  7133. </author>
  7134. <author initials="N.P." surname="Phamdo" fullname="N.">
  7135. <organization/>
  7136. </author>
  7137. <author initials="N.F." surname="Farvardin" fullname="N.">
  7138. <organization/>
  7139. </author>
  7140. </front>
  7141. <seriesInfo name="ICASSP-1991, Proc. IEEE Int. Conf. Acoust., Speech, Signal Processing, pp. 641-644, October" value="1991"/>
  7142. </reference>
  7143. <reference anchor='CELT' target='http://celt-codec.org/'>
  7144. <front>
  7145. <title>Constrained-Energy Lapped Transform (CELT) Codec</title>
  7146. <author initials='J-M.' surname='Valin' fullname='J-M. Valin'>
  7147. <organization /></author>
  7148. <author initials='T&#x2E;B.' surname='Terriberry' fullname='Timothy B. Terriberry'>
  7149. <organization /></author>
  7150. <author initials='G.' surname='Maxwell' fullname='G. Maxwell'>
  7151. <organization /></author>
  7152. <author initials='C.' surname='Montgomery' fullname='C. Montgomery'>
  7153. <organization /></author>
  7154. <date year='2010' month='July' />
  7155. <abstract>
  7156. <t></t>
  7157. </abstract></front>
  7158. <seriesInfo name='Internet-Draft' value='draft-valin-celt-codec-02' />
  7159. <format type='TXT' target='http://tools.ietf.org/html/draft-valin-celt-codec-02' />
  7160. </reference>
  7161. <reference anchor='SRTP-VBR'>
  7162. <front>
  7163. <title>Guidelines for the use of Variable Bit Rate Audio with Secure RTP</title>
  7164. <author initials='C.' surname='Perkins' fullname='K. Vos'>
  7165. <organization /></author>
  7166. <author initials='J.M.' surname='Valin' fullname='J.M. Valin'>
  7167. <organization /></author>
  7168. <date year='2011' month='July' />
  7169. <abstract>
  7170. <t></t>
  7171. </abstract></front>
  7172. <seriesInfo name='RFC' value='6562' />
  7173. <format type='TXT' target='http://tools.ietf.org/html/rfc6562' />
  7174. </reference>
  7175. <reference anchor='DOS'>
  7176. <front>
  7177. <title>Internet Denial-of-Service Considerations</title>
  7178. <author initials='M.' surname='Handley' fullname='M. Handley'>
  7179. <organization /></author>
  7180. <author initials='E.' surname='Rescorla' fullname='E. Rescorla'>
  7181. <organization /></author>
  7182. <author>
  7183. <organization>IAB</organization></author>
  7184. <date year='2006' month='December' />
  7185. <abstract>
  7186. <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>
  7187. <seriesInfo name='RFC' value='4732' />
  7188. <format type='TXT' octets='91844' target='ftp://ftp.isi.edu/in-notes/rfc4732.txt' />
  7189. </reference>
  7190. <reference anchor="Martin79">
  7191. <front>
  7192. <title>Range encoding: An algorithm for removing redundancy from a digitised message</title>
  7193. <author initials="G.N.N." surname="Martin" fullname="G. Nigel N. Martin"><organization/></author>
  7194. <date year="1979" />
  7195. </front>
  7196. <seriesInfo name="Proc. Institution of Electronic and Radio Engineers International Conference on Video and Data Recording" value="" />
  7197. </reference>
  7198. <reference anchor="coding-thesis">
  7199. <front>
  7200. <title>Source coding algorithms for fast data compression</title>
  7201. <author initials="R." surname="Pasco" fullname=""><organization/></author>
  7202. <date month="May" year="1976" />
  7203. </front>
  7204. <seriesInfo name="Ph.D. thesis" value="Dept. of Electrical Engineering, Stanford University" />
  7205. </reference>
  7206. <reference anchor="PVQ">
  7207. <front>
  7208. <title>A Pyramid Vector Quantizer</title>
  7209. <author initials="T." surname="Fischer" fullname=""><organization/></author>
  7210. <date month="July" year="1986" />
  7211. </front>
  7212. <seriesInfo name="IEEE Trans. on Information Theory, Vol. 32" value="pp. 568-583" />
  7213. </reference>
  7214. <reference anchor="Kabal86">
  7215. <front>
  7216. <title>The Computation of Line Spectral Frequencies Using Chebyshev Polynomials</title>
  7217. <author initials="P." surname="Kabal" fullname="P. Kabal"><organization/></author>
  7218. <author initials="R." surname="Ramachandran" fullname="R. P. Ramachandran"><organization/></author>
  7219. <date month="December" year="1986" />
  7220. </front>
  7221. <seriesInfo name="IEEE Trans. Acoustics, Speech, Signal Processing, vol. 34, no. 6" value="pp. 1419-1426" />
  7222. </reference>
  7223. <reference anchor="Valgrind" target="http://valgrind.org/">
  7224. <front>
  7225. <title>Valgrind website</title>
  7226. <author></author>
  7227. </front>
  7228. </reference>
  7229. <reference anchor="Google-NetEQ" target="http://code.google.com/p/webrtc/source/browse/trunk/src/modules/audio_coding/NetEQ/main/source/?r=583">
  7230. <front>
  7231. <title>Google NetEQ code</title>
  7232. <author></author>
  7233. </front>
  7234. </reference>
  7235. <reference anchor="Google-WebRTC" target="http://code.google.com/p/webrtc/">
  7236. <front>
  7237. <title>Google WebRTC code</title>
  7238. <author></author>
  7239. </front>
  7240. </reference>
  7241. <reference anchor="Opus-git" target="git://git.xiph.org/opus.git">
  7242. <front>
  7243. <title>Opus Git Repository</title>
  7244. <author></author>
  7245. </front>
  7246. </reference>
  7247. <reference anchor="Opus-website" target="http://opus-codec.org/">
  7248. <front>
  7249. <title>Opus website</title>
  7250. <author></author>
  7251. </front>
  7252. </reference>
  7253. <reference anchor="Vorbis-website" target="http://xiph.org/vorbis/">
  7254. <front>
  7255. <title>Vorbis website</title>
  7256. <author></author>
  7257. </front>
  7258. </reference>
  7259. <reference anchor="Matroska-website" target="http://matroska.org/">
  7260. <front>
  7261. <title>Matroska website</title>
  7262. <author></author>
  7263. </front>
  7264. </reference>
  7265. <reference anchor="Vectors-website" target="http://opus-codec.org/testvectors/">
  7266. <front>
  7267. <title>Opus Testvectors (webside)</title>
  7268. <author></author>
  7269. </front>
  7270. </reference>
  7271. <reference anchor="Vectors-proc" target="http://www.ietf.org/proceedings/83/slides/slides-83-codec-0.gz">
  7272. <front>
  7273. <title>Opus Testvectors (proceedings)</title>
  7274. <author></author>
  7275. </front>
  7276. </reference>
  7277. <reference anchor="line-spectral-pairs" target="http://en.wikipedia.org/wiki/Line_spectral_pairs">
  7278. <front>
  7279. <title>Line Spectral Pairs</title>
  7280. <author><organization>Wikipedia</organization></author>
  7281. </front>
  7282. </reference>
  7283. <reference anchor="range-coding" target="http://en.wikipedia.org/wiki/Range_coding">
  7284. <front>
  7285. <title>Range Coding</title>
  7286. <author><organization>Wikipedia</organization></author>
  7287. </front>
  7288. </reference>
  7289. <reference anchor="Hadamard" target="http://en.wikipedia.org/wiki/Hadamard_transform">
  7290. <front>
  7291. <title>Hadamard Transform</title>
  7292. <author><organization>Wikipedia</organization></author>
  7293. </front>
  7294. </reference>
  7295. <reference anchor="Viterbi" target="http://en.wikipedia.org/wiki/Viterbi_algorithm">
  7296. <front>
  7297. <title>Viterbi Algorithm</title>
  7298. <author><organization>Wikipedia</organization></author>
  7299. </front>
  7300. </reference>
  7301. <reference anchor="Whitening" target="http://en.wikipedia.org/wiki/White_noise">
  7302. <front>
  7303. <title>White Noise</title>
  7304. <author><organization>Wikipedia</organization></author>
  7305. </front>
  7306. </reference>
  7307. <reference anchor="LPC" target="http://en.wikipedia.org/wiki/Linear_prediction">
  7308. <front>
  7309. <title>Linear Prediction</title>
  7310. <author><organization>Wikipedia</organization></author>
  7311. </front>
  7312. </reference>
  7313. <reference anchor="MDCT" target="http://en.wikipedia.org/wiki/Modified_discrete_cosine_transform">
  7314. <front>
  7315. <title>Modified Discrete Cosine Transform</title>
  7316. <author><organization>Wikipedia</organization></author>
  7317. </front>
  7318. </reference>
  7319. <reference anchor="FFT" target="http://en.wikipedia.org/wiki/Fast_Fourier_transform">
  7320. <front>
  7321. <title>Fast Fourier Transform</title>
  7322. <author><organization>Wikipedia</organization></author>
  7323. </front>
  7324. </reference>
  7325. <reference anchor="z-transform" target="http://en.wikipedia.org/wiki/Z-transform">
  7326. <front>
  7327. <title>Z-transform</title>
  7328. <author><organization>Wikipedia</organization></author>
  7329. </front>
  7330. </reference>
  7331. <reference anchor="Burg">
  7332. <front>
  7333. <title>Maximum Entropy Spectral Analysis</title>
  7334. <author initials="JP." surname="Burg" fullname="J.P. Burg"><organization/></author>
  7335. </front>
  7336. </reference>
  7337. <reference anchor="Schur">
  7338. <front>
  7339. <title>A fixed point computation of partial correlation coefficients</title>
  7340. <author initials="J." surname="Le Roux" fullname="J. Le Roux"><organization/></author>
  7341. <author initials="C." surname="Gueguen" fullname="C. Gueguen"><organization/></author>
  7342. </front>
  7343. <seriesInfo name="ICASSP-1977, Proc. IEEE Int. Conf. Acoust., Speech, Signal Processing, pp. 257-259, October" value="1977"/>
  7344. </reference>
  7345. <reference anchor="Princen86">
  7346. <front>
  7347. <title>Analysis/synthesis filter bank design based on time domain aliasing cancellation</title>
  7348. <author initials="J." surname="Princen" fullname="John P. Princen"><organization/></author>
  7349. <author initials="A." surname="Bradley" fullname="Alan B. Bradley"><organization/></author>
  7350. </front>
  7351. <seriesInfo name="IEEE Trans. Acoust. Speech Sig. Proc. ASSP-34 (5), 1153-1161" value="1986"/>
  7352. </reference>
  7353. <reference anchor="Valin2010">
  7354. <front>
  7355. <title>A High-Quality Speech and Audio Codec With Less Than 10 ms delay</title>
  7356. <author initials="JM" surname="Valin" fullname="Jean-Marc Valin"><organization/>
  7357. </author>
  7358. <author initials="T. B." surname="Terriberry" fullname="Timothy Terriberry"><organization/></author>
  7359. <author initials="C." surname="Montgomery" fullname="Christopher Montgomery"><organization/></author>
  7360. <author initials="G." surname="Maxwell" fullname="Gregory Maxwell"><organization/></author>
  7361. </front>
  7362. <seriesInfo name="IEEE Trans. on Audio, Speech and Language Processing, Vol. 18, No. 1, pp. 58-67" value="2010" />
  7363. </reference>
  7364. <reference anchor="Zwicker61">
  7365. <front>
  7366. <title>Subdivision of the audible frequency range into critical bands</title>
  7367. <author initials="E." surname="Zwicker" fullname="E. Zwicker"><organization/></author>
  7368. <date month="February" year="1961" />
  7369. </front>
  7370. <seriesInfo name="The Journal of the Acoustical Society of America, Vol. 33, No 2" value="p. 248" />
  7371. </reference>
  7372. </references>
  7373. <section anchor="ref-implementation" title="Reference Implementation">
  7374. <t>This appendix contains the complete source code for the
  7375. reference implementation of the Opus codec written in C. By default,
  7376. this implementation relies on floating-point arithmetic, but it can be
  7377. compiled to use only fixed-point arithmetic by defining the FIXED_POINT
  7378. macro. Information on building and using the reference implementation is
  7379. available in the README file.
  7380. </t>
  7381. <t>The implementation can be compiled with either a C89 or a C99
  7382. compiler. It is reasonably optimized for most platforms such that
  7383. only architecture-specific optimizations are likely to be useful.
  7384. The FFT <xref target="FFT"/> used is a slightly modified version of the KISS-FFT library,
  7385. but it is easy to substitute any other FFT library.
  7386. </t>
  7387. <t>
  7388. While the reference implementation does not rely on any
  7389. <spanx style="emph">undefined behavior</spanx> as defined by C89 or C99,
  7390. it relies on common <spanx style="emph">implementation-defined behavior</spanx>
  7391. for two's complement architectures:
  7392. <list style="symbols">
  7393. <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>
  7394. <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>
  7395. <t>The result of integer division of a negative value is truncated towards zero, and</t>
  7396. <t>The compiler provides a 64-bit integer type (a C99 requirement which is supported by most C89 compilers).</t>
  7397. </list>
  7398. </t>
  7399. <t>
  7400. In its current form, the reference implementation also requires the following
  7401. architectural characteristics to obtain acceptable performance:
  7402. <list style="symbols">
  7403. <t>Two's complement arithmetic,</t>
  7404. <t>At least a 16 bit by 16 bit integer multiplier (32-bit result), and</t>
  7405. <t>At least a 32-bit adder/accumulator.</t>
  7406. </list>
  7407. </t>
  7408. <section title="Extracting the source">
  7409. <t>
  7410. The complete source code can be extracted from this draft, by running the
  7411. following command line:
  7412. <list style="symbols">
  7413. <t><![CDATA[
  7414. cat draft-ietf-codec-opus.txt | grep '^\ \ \ ###' | sed -e 's/...###//' | base64 -d > opus_source.tar.gz
  7415. ]]></t>
  7416. <t>
  7417. tar xzvf opus_source.tar.gz
  7418. </t>
  7419. <t>cd opus_source</t>
  7420. <t>make</t>
  7421. </list>
  7422. On systems where the provided Makefile does not work, the following command line may be used to compile
  7423. the source code:
  7424. <list style="symbols">
  7425. <t><![CDATA[
  7426. 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
  7427. ]]></t></list>
  7428. </t>
  7429. <t>
  7430. On systems where the base64 utility is not present, the following commands can be used instead:
  7431. <list style="symbols">
  7432. <t><![CDATA[
  7433. cat draft-ietf-codec-opus.txt | grep '^\ \ \ ###' | sed -e 's/...###//' > opus.b64
  7434. ]]></t>
  7435. <t>openssl base64 -d -in opus.b64 > opus_source.tar.gz</t>
  7436. </list>
  7437. </t>
  7438. </section>
  7439. <section title="Up-to-date Implementation">
  7440. <t>
  7441. As of the time of publication of this memo, an up-to-date implementation conforming to
  7442. this standard is available in a
  7443. <xref target='Opus-git'>Git repository</xref>.
  7444. Releases and other resources are available at
  7445. <xref target='Opus-website'/>. However, although that implementation is expected to
  7446. remain conformant with the standard, it is the code in this document that shall
  7447. remain normative.
  7448. </t>
  7449. </section>
  7450. <section title="Base64-encoded Source Code">
  7451. <t>
  7452. <?rfc include="opus_source.base64"?>
  7453. </t>
  7454. </section>
  7455. <section anchor="test-vectors" title="Test Vectors">
  7456. <t>
  7457. Because of size constraints, the Opus test vectors are not distributed in this
  7458. draft. They are available in the proceedings of the 83th IETF meeting (Paris) <xref target="Vectors-proc"/> and from the Opus codec website at
  7459. <xref target="Vectors-website"/>. These test vectors were created specifically to exercise
  7460. all aspects of the decoder and therefore the audio quality of the decoded output is
  7461. significantly lower than what Opus can achieve in normal operation.
  7462. </t>
  7463. <t>
  7464. The SHA1 hash of the files in the test vector package are
  7465. <?rfc include="testvectors_sha1"?>
  7466. </t>
  7467. </section>
  7468. </section>
  7469. <section anchor="self-delimiting-framing" title="Self-Delimiting Framing">
  7470. <t>
  7471. To use the internal framing described in <xref target="modes"/>, the decoder
  7472. must know the total length of the Opus packet, in bytes.
  7473. This section describes a simple variation of that framing which can be used
  7474. when the total length of the packet is not known.
  7475. Nothing in the encoding of the packet itself allows a decoder to distinguish
  7476. between the regular, undelimited framing and the self-delimiting framing
  7477. described in this appendix.
  7478. Which one is used and where must be established by context at the transport
  7479. layer.
  7480. It is RECOMMENDED that a transport layer choose exactly one framing scheme,
  7481. rather than allowing an encoder to signal which one it wants to use.
  7482. </t>
  7483. <t>
  7484. For example, although a regular Opus stream does not support more than two
  7485. channels, a multi-channel Opus stream may be formed from several one- and
  7486. two-channel streams.
  7487. To pack an Opus packet from each of these streams together in a single packet
  7488. at the transport layer, one could use the self-delimiting framing for all but
  7489. the last stream, and then the regular, undelimited framing for the last one.
  7490. Reverting to the undelimited framing for the last stream saves overhead
  7491. (because the total size of the transport-layer packet will still be known),
  7492. and ensures that a "multi-channel" stream which only has a single Opus stream
  7493. uses the same framing as a regular Opus stream does.
  7494. This avoids the need for signaling to distinguish these two cases.
  7495. </t>
  7496. <t>
  7497. The self-delimiting framing is identical to the regular, undelimited framing
  7498. from <xref target="modes"/>, except that each Opus packet contains one extra
  7499. length field, encoded using the same one- or two-byte scheme from
  7500. <xref target="frame-length-coding"/>.
  7501. This extra length immediately precedes the compressed data of the first Opus
  7502. frame in the packet, and is interpreted in the various modes as follows:
  7503. <list style="symbols">
  7504. <t>
  7505. Code&nbsp;0 packets: It is the length of the single Opus frame (see
  7506. <xref target="sd_code0_packet"/>).
  7507. </t>
  7508. <t>
  7509. Code&nbsp;1 packets: It is the length used for both of the Opus frames (see
  7510. <xref target="sd_code1_packet"/>).
  7511. </t>
  7512. <t>
  7513. Code&nbsp;2 packets: It is the length of the second Opus frame (see
  7514. <xref target="sd_code2_packet"/>).</t>
  7515. <t>
  7516. CBR Code&nbsp;3 packets: It is the length used for all of the Opus frames (see
  7517. <xref target="sd_code3cbr_packet"/>).
  7518. </t>
  7519. <t>VBR Code&nbsp;3 packets: It is the length of the last Opus frame (see
  7520. <xref target="sd_code3vbr_packet"/>).
  7521. </t>
  7522. </list>
  7523. </t>
  7524. <figure anchor="sd_code0_packet" title="A Self-Delimited Code 0 Packet"
  7525. align="center">
  7526. <artwork align="center"><![CDATA[
  7527. 0 1 2 3
  7528. 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
  7529. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7530. | config |s|0|0| N1 (1-2 bytes): |
  7531. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
  7532. | Compressed frame 1 (N1 bytes)... :
  7533. : |
  7534. | |
  7535. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7536. ]]></artwork>
  7537. </figure>
  7538. <figure anchor="sd_code1_packet" title="A Self-Delimited Code 1 Packet"
  7539. align="center">
  7540. <artwork align="center"><![CDATA[
  7541. 0 1 2 3
  7542. 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
  7543. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7544. | config |s|0|1| N1 (1-2 bytes): |
  7545. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ :
  7546. | Compressed frame 1 (N1 bytes)... |
  7547. : +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7548. | | |
  7549. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ :
  7550. | Compressed frame 2 (N1 bytes)... |
  7551. : +-+-+-+-+-+-+-+-+
  7552. | |
  7553. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7554. ]]></artwork>
  7555. </figure>
  7556. <figure anchor="sd_code2_packet" title="A Self-Delimited Code 2 Packet"
  7557. align="center">
  7558. <artwork align="center"><![CDATA[
  7559. 0 1 2 3
  7560. 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
  7561. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7562. | config |s|1|0| N1 (1-2 bytes): N2 (1-2 bytes : |
  7563. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ :
  7564. | Compressed frame 1 (N1 bytes)... |
  7565. : +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7566. | | |
  7567. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
  7568. | Compressed frame 2 (N2 bytes)... :
  7569. : |
  7570. | |
  7571. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7572. ]]></artwork>
  7573. </figure>
  7574. <figure anchor="sd_code3cbr_packet" title="A Self-Delimited CBR Code 3 Packet"
  7575. align="center">
  7576. <artwork align="center"><![CDATA[
  7577. 0 1 2 3
  7578. 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
  7579. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7580. | config |s|1|1|0|p| M | Pad len (Opt) : N1 (1-2 bytes):
  7581. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7582. | |
  7583. : Compressed frame 1 (N1 bytes)... :
  7584. | |
  7585. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7586. | |
  7587. : Compressed frame 2 (N1 bytes)... :
  7588. | |
  7589. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7590. | |
  7591. : ... :
  7592. | |
  7593. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7594. | |
  7595. : Compressed frame M (N1 bytes)... :
  7596. | |
  7597. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7598. : Opus Padding (Optional)... |
  7599. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7600. ]]></artwork>
  7601. </figure>
  7602. <figure anchor="sd_code3vbr_packet" title="A Self-Delimited VBR Code 3 Packet"
  7603. align="center">
  7604. <artwork align="center"><![CDATA[
  7605. 0 1 2 3
  7606. 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
  7607. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7608. | config |s|1|1|1|p| M | Padding length (Optional) :
  7609. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7610. : N1 (1-2 bytes): ... : N[M-1] | N[M] :
  7611. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7612. | |
  7613. : Compressed frame 1 (N1 bytes)... :
  7614. | |
  7615. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7616. | |
  7617. : Compressed frame 2 (N2 bytes)... :
  7618. | |
  7619. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7620. | |
  7621. : ... :
  7622. | |
  7623. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7624. | |
  7625. : Compressed frame M (N[M] bytes)... :
  7626. | |
  7627. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7628. : Opus Padding (Optional)... |
  7629. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  7630. ]]></artwork>
  7631. </figure>
  7632. </section>
  7633. </back>
  7634. </rfc>