12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227 |
- /* v2.0 24.Jan.2000
- =============================================================================
- U U GGG SSSS TTTTT
- U U G S T
- U U G GG SSSS T
- U U G G S T
- UUU GG SSS T
- ========================================
- ITU-T - USER'S GROUP ON SOFTWARE TOOLS
- ========================================
- =============================================================
- COPYRIGHT NOTE: This source code, and all of its derivations,
- is subject to the "ITU-T General Public License". Please have
- it read in the distribution disk, or in the ITU-T
- Recommendation G.191 on "SOFTWARE TOOLS FOR SPEECH AND AUDIO
- CODING STANDARDS".
- =============================================================
- MODULE: G726.C ADPCM AT 40, 32, 24, AND 16 KBIT/S MODULE
- ORIGINAL BY:
- Jose' Sindi Yamamoto (Fortran version of the G.721)
- <tdsindi@venus.cpqd.ansp.br>
- Simao Ferraz de Campos Neto (C translation, adaptation&testing of the G.721)
- <simao@venus.cpqd.ansp.br>
- Fernando Tofolli Queiroz (Extension of the G.721 to the other rates=>G.726)
- <tofolli@venus.cpqd.ansp.br>
- Simao Ferraz de Campos Neto (Adaptation and testing of the G.726)
- <simao@venus.cpqd.ansp.br>
- HISTORY:
- 28.Feb.1994 v1.0c Version 1.0 in C, by translating Fortran to C (f2c)
- 24.Jan.2000 v2.0 Corrected bug G726_compress() that caused incorrect
- processing of test vector ri40fa. Corrected code
- provided by Jayesh Patel <jayesh@dspse.com>.
- Verified by <simao.campos@labs.comsat.com>
- FUNCTIONS:
- Public:
- G726_encode ..... G726 encoder function;
- G726_decode ..... G726 decoder function;
- Private:
- G726_accum ...... addition of predictor outputs to form the partial
- signal estimate (from the sixth order predictor) and
- the signal estimate.
- G726_adda ....... addition of scale factor to logarithmic version of
- quantized difference signal.
- G726_addb ....... addition of quantized difference signal and signal
- estimate to form reconstructed signal.
- G726_addc....... obtain sign of addition of quantized difference signal
- and partial signal estimate.
- G726_antilog .... convert quantized difference signal from the
- logarithmic to the linear domain.
- G726_compress ... convert from uniform pcm to either a-law or u-law pcm.
- G726_delaya ..... memory block.
- G726_delayb ..... memory block.
- G726_delayc ..... memory block.
- G726_delayd ..... memory block.
- G726_expand ..... convert either a-law (law=1) or u-law (law=0) to
- uniform pcm.
- G726_filta ...... update of short term average of f(i).
- G726_filtb ...... update of long term average of f(i).
- G726_filtc ...... low pass filter of speed control parameter.
- G726_filtd ...... update of fast quantizer scale factor.
- G726_filte ...... update of slow quantizer scale factor.
- G726_floata ..... convert 15-bit signed magnitude to floating point.
- G726_floatb ..... convert 16-bit two's complement to floating point.
- G726_fmult ...... multiply predictor coefficients with corresponding
- quantized difference signal or reconstructed signal.
- Multiplication is done in floating point format.
- G726_functf ..... map quantizer output into the f(i) function.
- G726_functw ..... map quantizer output into logarithmic version of scale
- factor multiplier.
- G726_lima ....... limit speed control parameter.
- G726_limb ....... limit quantizer scale factor.
- G726_limc ....... limits on a2 coefficient of second order predictor.
- G726_limd ....... limits on a1 coefficient of second order predictor.
- G726_log ........ convert difference signal from linear to the
- logarithmic domain.
- G726_mix ........ form linear combination of fast and slow quantizer
- scale factors.
- G726_quan ....... quantize difference signal in logarithmic domain.
- G726_reconst .... reconstruction of quantized difference signal in the
- logarithmic domain.
- G726_subta ...... compute difference signal by subtracting signal
- estimate from input signal (or quantized reconstructed
- signal in decoder).
- G726_subtb ...... scale logarithmic version of difference signal by
- subtracting scale factor.
- G726_subtc ...... compute magnitude of the difference of short and
- long-term function of quantizer output sequence and
- then perform threshold comparison for quantizing speed
- control parameter.
- G726_sync ....... re-encode output pcm sample in decoder for synchronous
- tandem coding.
- G726_tone ....... partial band signal detection.
- G726_trans ...... transition detector.
- G726_triga ...... speed control trigger block.
- G726_trigb ...... predictor trigger block.
- G726_upa1 ....... update a1 coefficient of second order predictor.
- G726_upa2 ....... update a2 coefficient of second order predictor.
- G726_upb ........ update for coefficients of sixth order predictor.
- G726_xor ........ one bit "exclusive or" of sign of difference signal
- and sign of delayed difference signal.
- =============================================================================
- */
- /*
- * .................. INCLUDES ..................
- */
- #include "g726.h"
- /*
- * .................. FUNCTIONS ..................
- */
- /*
- ----------------------------------------------------------------------------
- void G726_encode (short *inp_buf, short *out_buf, long smpno,
- ~~~~~~~~~~~~~~~~ char *law, short rate, short r, G726_state *state);
- Description:
- ~~~~~~~~~~~~
- Simulation of the ITU-T G.726 ADPCM encoder. Takes the A or mu
- law input array of shorts `inp_buf' (16 bit, right- justified,
- without sign extension) of length `smpno', and saves the
- encoded samples in the array of shorts `out_buf', with the
- same number of samples and right-justified.
- The state variables are saved in the structure `state', and the
- reset can be stablished by making r equal to 1. The law is A if
- `law'=='1', and mu law if `law'=='0'.
- Return value:
- ~~~~~~~~~~~~~
- None.
- Prototype: in file g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Version 1.0 in Fortran
- <tdsindi@venus.cpqd.ansp.br>
- 05.Feb.92 v1.0c Version 1.0 in C, by translating Fortran to C (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------------
- */
- void G726_encode (short *inp_buf, short *out_buf, long smpno, char *law, short rate, short r, G726_state * state) {
- short s;
- short d, i;
- short y;
- short sigpk;
- short sr, tr;
- short yu;
- short al, fi, dl, ap, dq, ds, se, ax, td, sl, wi;
- short u1, u2, u3, u4, u5, u6;
- short a1, a2, b1, b2, b3, b4, b5, b6;
- short dqln;
- short a1p, a2p, a1t, a2t, b1p, b2p, b3p, b4p, b5p, b6p, dq6, pk2, sr2, wa1, wa2, wb1, wb2, wb3, wb4, wb5, wb6;
- short dml, dln, app, dql, dms;
- short dqs, tdp;
- short sez;
- short yut;
- long yl;
- long j;
- /* Invert even bits if A law */
- if (*law == '1') {
- for (j = 0; j < smpno; j++)
- inp_buf[j] ^= 85;
- }
- /* Process all desired samples in inp_buf to out_buf; The comments about general blocks are given as in G.726, and refer to: 4.1.1 Input PCM format conversion and difference signal computation 4.1.2 Adaptive quantizer 4.1.3 Inverse adaptive quantizer 4.1.4 Quantizer scale factor adaptation 4.1.5 Adaptation speed control 4.1.6 Adaptive predictor and reconstructed signal calculator 4.1.7 Tone and transition detector 4.1.8 (Only in the decoder) */
- for (j = 0; j < smpno; j++, r = 0) {
- s = inp_buf[j];
- /* Process `known-state' part of 4.2.6 */
- G726_delayd (&r, &state->sr1, &sr2);
- G726_delayd (&r, &state->sr0, &state->sr1);
- G726_delaya (&r, &state->a2r, &a2);
- G726_delaya (&r, &state->a1r, &a1);
- G726_fmult (&a2, &sr2, &wa2);
- G726_fmult (&a1, &state->sr1, &wa1);
- G726_delayd (&r, &state->dq5, &dq6);
- G726_delayd (&r, &state->dq4, &state->dq5);
- G726_delayd (&r, &state->dq3, &state->dq4);
- G726_delayd (&r, &state->dq2, &state->dq3);
- G726_delayd (&r, &state->dq1, &state->dq2);
- G726_delayd (&r, &state->dq0, &state->dq1);
- G726_delaya (&r, &state->b1r, &b1);
- G726_delaya (&r, &state->b2r, &b2);
- G726_delaya (&r, &state->b3r, &b3);
- G726_delaya (&r, &state->b4r, &b4);
- G726_delaya (&r, &state->b5r, &b5);
- G726_delaya (&r, &state->b6r, &b6);
- G726_fmult (&b1, &state->dq1, &wb1);
- G726_fmult (&b2, &state->dq2, &wb2);
- G726_fmult (&b3, &state->dq3, &wb3);
- G726_fmult (&b4, &state->dq4, &wb4);
- G726_fmult (&b5, &state->dq5, &wb5);
- G726_fmult (&b6, &dq6, &wb6);
- G726_accum (&wa1, &wa2, &wb1, &wb2, &wb3, &wb4, &wb5, &wb6, &se, &sez);
- /* Process 4.2.1 */
- G726_expand (&s, law, &sl);
- G726_subta (&sl, &se, &d);
- /* Process delays and `know-state' part of 4.2.5 */
- G726_delaya (&r, &state->dmsp, &dms);
- G726_delaya (&r, &state->dmlp, &dml);
- G726_delaya (&r, &state->apr, &ap);
- G726_lima (&ap, &al);
- /* Process `know-state' parts of 4.2.4 */
- G726_delayb (&r, &state->yup, &yu);
- G726_delayc (&r, &state->ylp, &yl);
- G726_mix (&al, &yu, &yl, &y);
- /* Process 4.2.2 */
- G726_log (&d, &dl, &ds);
- G726_subtb (&dl, &y, &dln);
- G726_quan (rate, &dln, &ds, &i);
- /* Save ADPCM quantized sample into output buffer */
- out_buf[j] = i;
- /* Process 4.2.3 */
- G726_reconst (rate, &i, &dqln, &dqs);
- G726_adda (&dqln, &y, &dql);
- G726_antilog (&dql, &dqs, &dq);
- /* Part of 4.2.5 */
- G726_functf (rate, &i, &fi);
- G726_filta (&fi, &dms, &state->dmsp);
- G726_filtb (&fi, &dml, &state->dmlp);
- /* Remaining part of 4.2.4 */
- G726_functw (rate, &i, &wi);
- G726_filtd (&wi, &y, &yut);
- G726_limb (&yut, &state->yup);
- G726_filte (&state->yup, &yl, &state->ylp);
- /* Process `known-state' part of 4.2.7 */
- G726_delaya (&r, &state->tdr, &td);
- G726_trans (&td, &yl, &dq, &tr);
- /* More `known-state' parts of 4.2.6: update of `pk's */
- G726_delaya (&r, &state->pk1, &pk2);
- G726_delaya (&r, &state->pk0, &state->pk1);
- G726_addc (&dq, &sez, &state->pk0, &sigpk);
- /* 4.2.6: find sr0 */
- G726_addb (&dq, &se, &sr);
- G726_floatb (&sr, &state->sr0);
- /* 4.2.6: find dq0 */
- G726_floata (&dq, &state->dq0);
- /* 4.2.6: prepar a2(r) */
- G726_upa2 (&state->pk0, &state->pk1, &pk2, &a2, &a1, &sigpk, &a2t);
- G726_limc (&a2t, &a2p);
- G726_trigb (&tr, &a2p, &state->a2r);
- /* 4.2.6: prepar a1(r) */
- G726_upa1 (&state->pk0, &state->pk1, &a1, &sigpk, &a1t);
- G726_limd (&a1t, &a2p, &a1p);
- G726_trigb (&tr, &a1p, &state->a1r);
- /* Remaining of 4.2.7 */
- G726_tone (&a2p, &tdp);
- G726_trigb (&tr, &tdp, &state->tdr);
- /* Remaining of 4.2.5 */
- G726_subtc (&state->dmsp, &state->dmlp, &tdp, &y, &ax);
- G726_filtc (&ax, &ap, &app);
- G726_triga (&tr, &app, &state->apr);
- /* Remaining of 4.2.6: update of all `b's */
- G726_xor (&state->dq1, &dq, &u1); /* Here, b1 */
- G726_upb (rate, &u1, &b1, &dq, &b1p);
- G726_trigb (&tr, &b1p, &state->b1r);
- G726_xor (&state->dq2, &dq, &u2); /* Here, b2 */
- G726_upb (rate, &u2, &b2, &dq, &b2p);
- G726_trigb (&tr, &b2p, &state->b2r);
- G726_xor (&state->dq3, &dq, &u3); /* Here, b3 */
- G726_upb (rate, &u3, &b3, &dq, &b3p);
- G726_trigb (&tr, &b3p, &state->b3r);
- G726_xor (&state->dq4, &dq, &u4); /* Here, b4 */
- G726_upb (rate, &u4, &b4, &dq, &b4p);
- G726_trigb (&tr, &b4p, &state->b4r);
- G726_xor (&state->dq5, &dq, &u5); /* Here, b5 */
- G726_upb (rate, &u5, &b5, &dq, &b5p);
- G726_trigb (&tr, &b5p, &state->b5r);
- G726_xor (&dq6, &dq, &u6); /* At last, b6 */
- G726_upb (rate, &u6, &b6, &dq, &b6p);
- G726_trigb (&tr, &b6p, &state->b6r);
- }
- }
- /* ........................ end of G726_encode() ....................... */
- /*
- ----------------------------------------------------------------------------
- void G726_decode (short *inp_buf, short *out_buf, long smpno,
- ~~~~~~~~~~~~~~~~ char *law, short rate, short r, G726_state *state);
- Description:
- ~~~~~~~~~~~~
- Simulation of the ITU-T G.726 ADPCM decoder. Takes the ADPCM
- input array of shorts `inp_buf' (16 bit, right- justified,
- without sign extension) of length `smpno', and saves the
- decoded samples (A or mu law) in the array of shorts
- `out_buf', with the same number of samples and
- right-justified.
- The state variables are saved in the structure `state', and the
- reset can be stablished by making r equal to 1. The law is A if
- `law'=='1', and mu law if `law'=='0'.
- Return value:
- ~~~~~~~~~~~~~
- None.
- Prototype: in file g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Version 1.0 in Fortran
- <tdsindi@venus.cpqd.ansp.br>
- 05.Feb.92 v1.0c Version 1.0 in C, by translating Fortran to C (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------------
- */
- void G726_decode (short *inp_buf, short *out_buf, long smpno, char *law, short rate, short r, G726_state * state) {
- short i;
- short y;
- short sigpk;
- short sr, tr;
- short sp, dlnx, dsx, sd, slx, dlx, dx; /* these are unique to the decoder */
- long yl;
- short yu;
- short al, fi, ap, dq, se, ax, td, wi;
- short u1, u2, u3, u4, u5, u6;
- short a1, a2, b1, b2, b3, b4, b5, b6;
- short dqln;
- short a1p, a2p, a1t, a2t, b1p, b2p, b3p, b4p, b5p, b6p, dq6, pk2, sr2, wa1, wa2, wb1, wb2, wb3, wb4, wb5, wb6;
- short dml, app, dql, dms;
- short dqs, tdp;
- short sez;
- short yut;
- long j;
- /* Process all desired samples in inp_buf to out_buf; The comments about general blocks are given as in G.726, and refer to: 4.1.1 Input PCM format conversion and difference signal computation 4.1.2 Adaptive quantizer 4.1.3 Inverse adaptive quantizer 4.1.4 Quantizer scale factor adaptation 4.1.5 Adaptation speed control 4.1.6 Adaptive predictor and reconstructed signal calculator 4.1.7 Tone and transition detector 4.1.8 Output PCM format conversion and synchronous coding adjustment */
- for (j = 0; j < smpno; j++, r = 0) {
- /* Process `known-state' part of 4.2.6 */
- G726_delayd (&r, &state->sr1, &sr2);
- G726_delayd (&r, &state->sr0, &state->sr1);
- G726_delaya (&r, &state->a2r, &a2);
- G726_delaya (&r, &state->a1r, &a1);
- G726_fmult (&a2, &sr2, &wa2);
- G726_fmult (&a1, &state->sr1, &wa1);
- G726_delayd (&r, &state->dq5, &dq6);
- G726_delayd (&r, &state->dq4, &state->dq5);
- G726_delayd (&r, &state->dq3, &state->dq4);
- G726_delayd (&r, &state->dq2, &state->dq3);
- G726_delayd (&r, &state->dq1, &state->dq2);
- G726_delayd (&r, &state->dq0, &state->dq1);
- G726_delaya (&r, &state->b1r, &b1);
- G726_delaya (&r, &state->b2r, &b2);
- G726_delaya (&r, &state->b3r, &b3);
- G726_delaya (&r, &state->b4r, &b4);
- G726_delaya (&r, &state->b5r, &b5);
- G726_delaya (&r, &state->b6r, &b6);
- G726_fmult (&b1, &state->dq1, &wb1);
- G726_fmult (&b2, &state->dq2, &wb2);
- G726_fmult (&b3, &state->dq3, &wb3);
- G726_fmult (&b4, &state->dq4, &wb4);
- G726_fmult (&b5, &state->dq5, &wb5);
- G726_fmult (&b6, &dq6, &wb6);
- G726_accum (&wa1, &wa2, &wb1, &wb2, &wb3, &wb4, &wb5, &wb6, &se, &sez);
- /* Process delays and `know-state' part of 4.2.5 */
- G726_delaya (&r, &state->dmsp, &dms);
- G726_delaya (&r, &state->dmlp, &dml);
- G726_delaya (&r, &state->apr, &ap);
- G726_lima (&ap, &al);
- /* Process `know-state' parts of 4.2.4 */
- G726_delayb (&r, &state->yup, &yu);
- G726_delayc (&r, &state->ylp, &yl);
- G726_mix (&al, &yu, &yl, &y);
- /* Retrieve ADPCM sample from input buffer */
- i = inp_buf[j];
- /* Process 4.2.3 */
- G726_reconst (rate, &i, &dqln, &dqs);
- G726_adda (&dqln, &y, &dql);
- G726_antilog (&dql, &dqs, &dq);
- /* Process `known-state' part of 4.2.7 */
- G726_delaya (&r, &state->tdr, &td);
- G726_trans (&td, &yl, &dq, &tr);
- /* Part of 4.2.5 */
- G726_functf (rate, &i, &fi);
- G726_filta (&fi, &dms, &state->dmsp);
- G726_filtb (&fi, &dml, &state->dmlp);
- /* Remaining part of 4.2.4 */
- G726_functw (rate, &i, &wi);
- G726_filtd (&wi, &y, &yut);
- G726_limb (&yut, &state->yup);
- G726_filte (&state->yup, &yl, &state->ylp);
- /* More `known-state' parts of 4.2.6: update of `pk's */
- G726_delaya (&r, &state->pk1, &pk2);
- G726_delaya (&r, &state->pk0, &state->pk1);
- G726_addc (&dq, &sez, &state->pk0, &sigpk);
- /* 4.2.6: find sr0 */
- G726_addb (&dq, &se, &sr);
- G726_floatb (&sr, &state->sr0);
- /* 4.2.6: find dq0 */
- G726_floata (&dq, &state->dq0);
- /* Process 4.2.8 */
- G726_compress (&sr, law, &sp);
- G726_expand (&sp, law, &slx);
- G726_subta (&slx, &se, &dx);
- G726_log (&dx, &dlx, &dsx);
- G726_subtb (&dlx, &y, &dlnx);
- G726_sync (rate, &i, &sp, &dlnx, &dsx, law, &sd);
- /* Save output PCM word in output buffer */
- out_buf[j] = sd;
- /* 4.2.6: prepar a2(r) */
- G726_upa2 (&state->pk0, &state->pk1, &pk2, &a2, &a1, &sigpk, &a2t);
- G726_limc (&a2t, &a2p);
- G726_trigb (&tr, &a2p, &state->a2r);
- /* 4.2.6: prepar a1(r) */
- G726_upa1 (&state->pk0, &state->pk1, &a1, &sigpk, &a1t);
- G726_limd (&a1t, &a2p, &a1p);
- G726_trigb (&tr, &a1p, &state->a1r);
- /* Remaining of 4.2.7 */
- G726_tone (&a2p, &tdp);
- G726_trigb (&tr, &tdp, &state->tdr);
- /* Remaining of 4.2.5 */
- G726_subtc (&state->dmsp, &state->dmlp, &tdp, &y, &ax);
- G726_filtc (&ax, &ap, &app);
- G726_triga (&tr, &app, &state->apr);
- /* Remaining of 4.2.6: update of all `b's */
- G726_xor (&state->dq1, &dq, &u1); /* Here, b1 */
- G726_upb (rate, &u1, &b1, &dq, &b1p);
- G726_trigb (&tr, &b1p, &state->b1r);
- G726_xor (&state->dq2, &dq, &u2); /* Here, b2 */
- G726_upb (rate, &u2, &b2, &dq, &b2p);
- G726_trigb (&tr, &b2p, &state->b2r);
- G726_xor (&state->dq3, &dq, &u3); /* Here, b3 */
- G726_upb (rate, &u3, &b3, &dq, &b3p);
- G726_trigb (&tr, &b3p, &state->b3r);
- G726_xor (&state->dq4, &dq, &u4); /* Here, b4 */
- G726_upb (rate, &u4, &b4, &dq, &b4p);
- G726_trigb (&tr, &b4p, &state->b4r);
- G726_xor (&state->dq5, &dq, &u5); /* Here, b5 */
- G726_upb (rate, &u5, &b5, &dq, &b5p);
- G726_trigb (&tr, &b5p, &state->b5r);
- G726_xor (&dq6, &dq, &u6); /* At last, b6 */
- G726_upb (rate, &u6, &b6, &dq, &b6p);
- G726_trigb (&tr, &b6p, &state->b6r);
- }
- /* Invert even bits if A law */
- if (*law == '1') {
- for (j = 0; j < smpno; j++)
- out_buf[j] ^= 85;
- }
- }
- /* ...................... end of G726_decode() ...................... */
- /*
- ----------------------------------------------------------------------
- void G726_expand (short *s, char *law, short *sl);
- ~~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Convert either a-law (law=1) or u-law (law=0) to uniform pcm.
- Inputs: s (sp in decoder), law
- Output: sl (slx in decoder)
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_expand (short *s, char *law, short *sl) {
- long mant, iexp;
- short s1, ss, sig, ssm, ssq, sss;
- s1 = *s;
- if (*law == '1') {
- /* Invert sign bit */
- s1 ^= 128;
- if (s1 >= 128) {
- s1 += -128;
- sig = 4096;
- } else {
- sig = 0;
- }
- iexp = s1 / 16;
- mant = s1 - (iexp << 4);
- ss = (iexp == 0) ? ((mant << 1) + 1 + sig) : ((1 << (iexp - 1)) * ((mant << 1) + 33) + sig);
- sss = ss / 4096;
- ssm = ss & 4095;
- ssq = ssm << 1;
- } else {
- /* Invert sign bit */
- s1 ^= 128;
- if (s1 >= 128) {
- s1 += -128;
- s1 ^= 127;
- sig = 8192;
- } else {
- sig = 0;
- s1 ^= 127;
- }
- iexp = s1 / 16;
- mant = s1 - (iexp << 4);
- ss = (iexp == 0) ? ((mant << 1) + sig) : ((1 << iexp) * ((mant << 1) + 33) - 33 + sig);
- sss = ss / 8192;
- ssq = ss & 8191;
- }
- *sl = (sss == 0) ? ssq : ((16384 - ssq) & 16383);
- }
- /* ...................... end of G726_expand() ...................... */
- /*
- ----------------------------------------------------------------------
- void G726_subta (short *sl, short *se, short *d);
- ~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Compute difference signal by subtracting signal estimate from
- input signal (or quantized reconstructed signal in decoder).
- Inputs: sl (slx in decoder), se
- Output: d (dx in decoder)
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_subta (short *sl, short *se, short *d) {
- long se1;
- long sl1, sei, sli;
- short ses, sls;
- sls = (*sl >> 13);
- sl1 = *sl;
- se1 = *se;
- /* Sign extension */
- sli = (sls == 0) ? sl1 : (sl1 + 49152);
- ses = (*se >> 14);
- /* Sign extension */
- sei = (ses == 0) ? se1 : (se1 + 32768);
- /* 16 bit TC */
- *d = (short) ((sli + 65536 - sei) & 65535);
- }
- /* ......................... end of G726_subta() ......................... */
- /*
- --------------------------------------------------------------------------
- void G726_log (short *d, short *dl, short *ds);
- ~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Convert difference signal from linear to the logarithmic domain.
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f 1st release to UGST, in Fortran.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c release of 1st version, in C.
- <tdsimao@venus.cpqd.ansp.br>
- --------------------------------------------------------------------------
- */
- void G726_log (short *d, short *dl, short *ds) {
- long mant;
- long d1;
- long dqm, exp_;
- *ds = (*d >> 15);
- d1 = *d;
- /* Convert from 2-complement to signed magnitude */
- dqm = (*ds) ? ((65536 - d1) & 32767) : d1;
- /* Compute exponent */
- if (dqm >= 16384)
- exp_ = 14;
- else if (dqm >= 8192)
- exp_ = 13;
- else if (dqm >= 4096)
- exp_ = 12;
- else if (dqm >= 2048)
- exp_ = 11;
- else if (dqm >= 1024)
- exp_ = 10;
- else if (dqm >= 512)
- exp_ = 9;
- else if (dqm >= 256)
- exp_ = 8;
- else if (dqm >= 128)
- exp_ = 7;
- else if (dqm >= 64)
- exp_ = 6;
- else if (dqm >= 32)
- exp_ = 5;
- else if (dqm >= 16)
- exp_ = 4;
- else if (dqm >= 8)
- exp_ = 3;
- else if (dqm >= 4)
- exp_ = 2;
- else if (dqm >= 2)
- exp_ = 1;
- else
- exp_ = 0;
- /* Compute approximation log2(1+x) = x */
- mant = ((dqm << 7) >> exp_) & 127;
- /* Combine mantissa and exponent (7 and 4) bits into a 11-bit word */
- *dl = (short) ((exp_ << 7) + mant);
- }
- /* ........................ end of G726_log() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_quan (short rate, short *dln, short *ds, short *i);
- ~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Quantize difference signal in logarithmic
- domain.
- Inputs: dln, ds, rate
- Output: i
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_quan (short rate, short *dln, short *ds, short *i) {
- if (rate == 4) {
- if (*dln >= 3972)
- *i = 1;
- else if (*dln >= 2048)
- *i = 15;
- else if (*dln >= 400)
- *i = 7;
- else if (*dln >= 349)
- *i = 6;
- else if (*dln >= 300)
- *i = 5;
- else if (*dln >= 246)
- *i = 4;
- else if (*dln >= 178)
- *i = 3;
- else if (*dln >= 80)
- *i = 2;
- else
- *i = 1;
- /* Adjust for sign */
- if (*ds)
- *i = 15 - *i;
- if (*i == 0)
- *i = 15;
- }
- /* ......... end of 32 kbit part ........... */
- else if (rate == 3) {
- if (*dln >= 2048)
- *i = 7;
- else if (*dln >= 331)
- *i = 3;
- else if (*dln >= 218)
- *i = 2;
- else if (*dln >= 8)
- *i = 1;
- else if (*dln >= 0)
- *i = 7;
- /* Adjust for sign */
- if (*ds)
- *i = 7 - *i;
- if (*i == 0)
- *i = 7;
- }
- /* ......... end of 24 kbit part ........... */
- else if (rate == 2) {
- if (*dln >= 2048)
- *i = 0;
- else if (*dln >= 261)
- *i = 1;
- else
- *i = 0;
- /* Adjust for sign */
- if (*ds)
- *i = 3 - *i;
- }
- /* ......... end of 16 kbit part ........... */
- else {
- if (*dln >= 4080)
- *i = 2;
- else if (*dln >= 3974)
- *i = 1;
- else if (*dln >= 2048)
- *i = 31;
- else if (*dln >= 553)
- *i = 15;
- else if (*dln >= 528)
- *i = 14;
- else if (*dln >= 502)
- *i = 13;
- else if (*dln >= 475)
- *i = 12;
- else if (*dln >= 445)
- *i = 11;
- else if (*dln >= 413)
- *i = 10;
- else if (*dln >= 378)
- *i = 9;
- else if (*dln >= 339)
- *i = 8;
- else if (*dln >= 298)
- *i = 7;
- else if (*dln >= 250)
- *i = 6;
- else if (*dln >= 198)
- *i = 5;
- else if (*dln >= 139)
- *i = 4;
- else if (*dln >= 68)
- *i = 3;
- else if (*dln >= 0)
- *i = 2;
- if (*ds)
- *i = 31 - *i;
- if (*i == 0)
- *i = 31;
- } /* ......... end of 40 kbit part ........... */
- }
- /* ........................ end of G726_quan() ........................ */
- /*
- ----------------------------------------------------------------------
- void G726_subtb (short *dl, short *y, short *dln);
- ~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Scale logarithmic version of difference signal by subtracting
- scale factor.
- Inputs: dl (dlx no decodificador), y
- Output: dln (dlnx no decodificador)
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_subtb (short *dl, short *y, short *dln) {
- *dln = (*dl + 4096 - (*y >> 2)) & 4095;
- }
- /* ........................ end of G726_subtb() ........................ */
- /*
- ----------------------------------------------------------------------
- void G726_adda (short *dqln, short *y, short *dql);
- ~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Addition of scale factor to logarithmic version of quantized
- difference signal.
- Inputs: dqln, y
- Output: dql
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_adda (dqln, y, dql)
- short *dqln, *y, *dql;
- {
- *dql = (*dqln + (*y >> 2)) & 4095;
- }
- /* ....................... end of G726_adda() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_antilog (short *dql, short *dqs, short *dq);
- ~~~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Convert quantized difference signal from the logarithmic to
- the linear domain.
- Inputs: dql, dqs
- Output: dq
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_antilog (dql, dqs, dq)
- short *dql, *dqs, *dq;
- {
- long dqmag;
- long ds, dmn, dex, dqt;
- /* Extract 4-bit exponent */
- ds = (*dql >> 11);
- dex = (*dql >> 7) & 15;
- /* Extract 7-bit mantissa */
- dmn = *dql & 127;
- dqt = dmn + 128;
- /* Convert mantissa to linear using the approx. 2**x = 1+x */
- dqmag = ds ? 0 : ((dqt << 7) >> (14 - dex));
- /* Attach sign bit to signed mag. word */
- *dq = (short) (*dqs << 15) + dqmag;
- }
- /* ..................... end of G726_antilog() ..................... */
- /*
- ----------------------------------------------------------------------
- void G726_reconst (short rate, short *i, short *dqln, short *dqs);
- ~~~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Reconstruction of quantized difference signal in the
- logarithmic domain.
- Inputs: i, rate
- Outputs: dqln, dqs
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_reconst (short rate, short *i, short *dqln, short *dqs) {
- if (rate == 4) {
- /* Initialized data */
- static short tab[16] = { 2048, 4, 135, 213, 273, 323, 373, 425,
- 425, 373, 323, 273, 213, 135, 4, 2048
- };
- /* Extract sign */
- *dqs = (*i >> 3);
- /* Table look-up */
- *dqln = tab[*i];
- }
- /* ............... end of 32 kbit part * ................. */
- else if (rate == 3) {
- /* Initialized data */
- static short tab[8] = { 2048, 135, 273, 373, 373, 273, 135, 2048 };
- *dqs = (*i >> 2);
- /* Table look-up */
- *dqln = tab[*i];
- }
- /* ............... end of 24 kbit part * ................. */
- else if (rate == 2) {
- /* Initialized data */
- static short tab[4] = { 116, 365, 365, 116 };
- *dqs = (*i >> 1);
- /* Table look-up */
- *dqln = tab[*i];
- } /* ............... end of 16 kbit part * ................. */
- else {
- /* Initialized data */
- static short tab[32] = { 2048, 4030, 28, 104, 169, 224, 274, 318, 358, 395, 429,
- 459, 488, 514, 539, 566, 566, 539, 514, 488, 459, 429, 395, 358, 318, 274, 224,
- 169, 104, 28, 4030, 2048
- };
- *dqs = (*i >> 4);
- /* Table look-up */
- *dqln = tab[*i];
- } /* ................ end of 40 kbit part ................... */
- }
- /* ....................... end of G726_reconst() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_delaya (short *r, short *x, short *y);
- ~~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Memory block.
- Inputs: r, x
- Output: y
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_delaya (short *r, short *x, short *y) {
- *y = (*r == 0) ? *x : 0;
- }
- /* ....................... end of G726_delaya() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_delayb (short *r, short *x, short *y);
- ~~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Memory block.
- Inputs: r, x
- Output: y
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_delayb (short *r, short *x, short *y) {
- *y = (*r == 0) ? *x : 544;
- }
- /* ....................... end of G726_delayb() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_delayc (short *r, long *x, long *y);
- ~~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Memory block.
- Inputs: r, x
- Output: y
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_delayc (short *r, long *x, long *y) {
- *y = (*r == 0) ? *x : 34816;
- }
- /* ....................... end of G726_delayc() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_delayd (short *r, short *x, short *y);
- ~~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Memory block
- Inputs: r, x
- Output: y
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_delayd (short *r, short *x, short *y) {
- *y = (*r == 0) ? *x : 32;
- }
- /* ....................... end of G726_delayd() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_filtd (short *wi, short *y, short *yut);
- ~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Update of fast quantizer scale factor.
- Inputs: wi, y
- Output: yut
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_filtd (short *wi, short *y, short *yut) {
- long difs, difsx;
- long y1;
- long wi1, dif;
- /* Compute difference */
- wi1 = *wi;
- y1 = *y;
- dif = ((wi1 << 5) + 131072 - y1) & 131071;
- difs = (dif >> 16);
- /* Time constant is 1/32; sign extension */
- difsx = (difs == 0) ? (dif >> 5) : ((dif >> 5) + 4096);
- *yut = (short) ((y1 + difsx) & 8191);
- }
- /* ....................... end of G726_filte() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_filte (short *yup, long *yl, long *ylp);
- ~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Update of slow quantizer scale factor.
- Inputs: yup, yl
- Output: ylp
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_filte (short *yup, long *yl, long *ylp) {
- long difs, difsx;
- long dif, dif1, yup1;
- /* Compute difference */
- yup1 = *yup;
- dif1 = 1048576 - *yl;
- dif = (yup1 + (dif1 >> 6)) & 16383;
- difs = (dif >> 13);
- /* Sign extension */
- difsx = (difs == 0) ? dif : (dif + 507904);
- *ylp = (*yl + difsx) & 524287;
- }
- /* ....................... end of G726_filte() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_functw (short rate, short *i, short *wi);
- ~~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Map quantizer output into logarithmic version of scale factor
- multiplier.
- Inputs: i, rate
- Output: wi
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_functw (short rate, short *i, short *wi) {
- if (rate == 4) {
- /* Initialized data */
- static short tab[8] = { 4084, 18, 41, 64, 112, 198, 355, 1122 };
- short im, is;
- is = (*i >> 3);
- im = (is == 0) ? (*i & 7) : ((15 - *i) & 7);
- /* Scale factor multiplier */
- *wi = tab[im];
- }
- /* ................. end of 32 kbit part * .............. */
- else if (rate == 3) {
- /* Initialized data */
- static short tab[4] = { 4092, 30, 137, 582 };
- short im, is;
- is = (*i >> 2);
- im = (is == 0) ? (*i & 3) : ((7 - *i) & 3);
- *wi = tab[im];
- }
- /* ................. end of 24 kbit part * .............. */
- else if (rate == 2) {
- /* Initialized data */
- static short tab[2] = { 4074, 439 };
- short im, is;
- is = (*i >> 1);
- im = (is == 0) ? (*i & 1) : ((3 - *i) & 1);
- *wi = tab[im];
- }
- /* ................. end of 16 kbit part * .............. */
- else {
- /* Initialized data */
- static short tab[16] = { 14, 14, 24, 39, 40, 41, 58, 100, 141, 179, 219, 280, 358,
- 440, 529, 696
- };
- short im, is;
- is = (*i >> 4);
- im = (is == 0) ? (*i & 15) : ((31 - *i) & 15);
- *wi = tab[im];
- } /* ................. end of 40 kbit part .............. */
- }
- /* ....................... end of G726_functw() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_limb (short *yut, short *yup);
- ~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Limit quantizer scale factor.
- Inputs: yut
- Output: yup
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_limb (short *yut, short *yup) {
- short gell, geul;
- geul = ((*yut + 11264) & 16383) >> 13;
- gell = ((*yut + 15840) & 16383) >> 13;
- if (gell == 1)
- *yup = 544; /* Lower limit is 1.06 */
- else if (geul == 0)
- *yup = 5120; /* Upper limit is 10.0 */
- else
- *yup = *yut;
- }
- /* ....................... end of G726_limb() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_mix (short *al, short *yu, long *yl, short *y);
- ~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Form linear combination of fast and slow quantizer scale
- factors.
- Inputs: al, yu, yl
- Output: y
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_mix (short *al, short *yu, long *yl, short *y) {
- long difm, difs, prod;
- long prodm, al1;
- long yu1, dif;
- /* Preamble */
- al1 = *al;
- yu1 = *yu;
- /* Compute difference */
- dif = (yu1 + 16384 - (*yl >> 6)) & 16383;
- difs = (dif >> 13);
- /* Compute magnitude of difference */
- difm = (difs == 0) ? dif : ((16384 - dif) & 8191);
- /* Compute magnitude of product */
- prodm = ((difm * al1) >> 6);
- /* Convert magnitude to two's complement */
- prod = (difs == 0) ? prodm : ((16384 - prodm) & 16383);
- *y = (short) (((*yl >> 6) + prod) & 8191);
- }
- /* ....................... end of G726_mix() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_filta (short *fi, short *dms, short *dmsp);
- ~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Update of short term average of f(i).
- Inputs: fi, dms
- Output: dmsp
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_filta (short *fi, short *dms, short *dmsp) {
- short difs, difsx;
- short dif;
- /* Compute difference */
- dif = ((*fi << 9) + 8192 - *dms) & 8191;
- difs = (dif >> 12);
- /* Time constant is 1/32, sign extension */
- difsx = (difs == 0) ? (dif >> 5) : ((dif >> 5) + 3840);
- *dmsp = (difsx + *dms) & 4095;
- }
- /* ....................... end of G726_filta() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_filtb (short *fi, short *dml, short *dmlp);
- ~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Update of long term average of f(i).
- Inputs: fi, dml
- Output: dmlp
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_filtb (short *fi, short *dml, short *dmlp) {
- long difs, difsx;
- long fi1;
- long dif, dml1;
- /* Preamble */
- fi1 = *fi;
- dml1 = *dml;
- /* Compute difference */
- dif = ((fi1 << 11) + 32768 - dml1) & 32767;
- difs = (dif >> 14);
- /* Time constant is 1/28, sign extension */
- difsx = (difs == 0) ? (dif >> 7) : ((dif >> 7) + 16128);
- *dmlp = (short) ((difsx + dml1) & 16383);
- }
- /* ....................... end of G726_filtb() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_filtc (short *ax, short *ap, short *app);
- ~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Low pass filter of speed control parameter.
- Inputs: ax, ap
- Output: app
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_filtc (short *ax, short *ap, short *app) {
- short difs, difsx;
- short dif;
- /* Compute difference */
- dif = ((*ax << 9) + 2048 - *ap) & 2047;
- difs = (dif >> 10);
- /* Time constant is 1/16, sign extension */
- difsx = (difs == 0) ? (dif >> 4) : ((dif >> 4) + 896);
- *app = (difsx + *ap) & 1023;
- }
- /* .................... end of G726_filtc() .................... */
- /*
- ----------------------------------------------------------------------
- void G726_functf (short rate, short *i, short *fi);
- ~~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Map quantizer output into the f(i) function.
- Inputs: i, rate
- Output: fi
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_functf (short rate, short *i, short *fi) {
- short im, is;
- if (rate == 4) {
- /* Initialized data */
- static short tab[8] = { 0, 0, 0, 1, 1, 1, 3, 7 };
- is = (*i >> 3);
- im = (is == 0) ? (*i & 7) : ((15 - *i) & 7);
- *fi = tab[im];
- }
- /* ................ end of 32 kbit part * ................. */
- else if (rate == 3) {
- /* Initialized data */
- static short tab[4] = { 0, 1, 2, 7 };
- is = (*i >> 2);
- im = (is == 0) ? (*i & 3) : ((7 - *i) & 3);
- *fi = tab[im];
- } /* ................ end of 24 kbit part * ................. */
- else if (rate == 2) {
- /* Initialized data */
- static short tab[2] = { 0, 7 };
- is = (*i >> 1);
- im = (is == 0) ? (*i & 1) : ((3 - *i) & 1);
- *fi = tab[im];
- }
- /* ................ end of 16 kbit part * ................. */
- else {
- /* Initialized data */
- static short tab[16] = { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 6 };
- is = (*i >> 4);
- im = (is == 0) ? (*i & 15) : ((31 - *i) & 15);
- *fi = tab[im];
- } /* ................ end of 40 kbit part ................. */
- }
- /* ...................... end of G726_functf() ...................... */
- /*
- ----------------------------------------------------------------------
- void G726_lima (short *ap, short *al);
- ~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Limit speed control parameter.
- Inputs: ap
- Output: al
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_lima (short *ap, short *al) {
- *al = (*ap >= 256) ? 64 : (*ap >> 2);
- }
- /* ....................... end of G726_lima() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_subtc (short *dmsp, short *dmlp, short *tdp,
- ~~~~~~~~~~~~~~~ short *y, short *ax);
- Description:
- ~~~~~~~~~~~~
- Functions of quantizer output sequence and then perform
- threshold comparison for quantizing speed control parameter.
- compute magnitude of the difference of short and long-term
- Inputs: dmsp, dmlp, tdp, y
- Output: ax
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_subtc (short *dmsp, short *dmlp, short *tdp, short *y, short *ax) {
- long difm, difs, dthr, dmlp1, dmsp1;
- long dif;
- /* Preamble */
- dmsp1 = *dmsp;
- dmlp1 = *dmlp;
- /* Compute difference */
- dif = ((dmsp1 << 2) + 32768 - dmlp1) & 32767;
- difs = (dif >> 14);
- /* Compute magnitude of difference */
- difm = (difs == 0) ? dif : ((32768 - dif) & 16383);
- /* Compute threshold */
- dthr = (dmlp1 >> 3);
- /* Quantize speed control parameter */
- *ax = (*y >= 1536 && difm < dthr && *tdp == 0) ? 0 : 1;
- }
- /* ....................... end of G726_subtc() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_triga (short *tr, short *app, short *apr);
- ~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Speed control trigger block.
- Inputs: tr, app
- Output: apr
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_triga (short *tr, short *app, short *apr) {
- *apr = (*tr == 0) ? (*app) : 256;
- }
- /* ....................... end of G726_triga() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_accum (short *wa1, short *wa2, short *wb1,
- ~~~~~~~~~~~~~~~ short *wb2, short *wb3, short *wb4,
- short *wb5, short *wb6, short *se, short *sez);
- Description:
- ~~~~~~~~~~~~
- Addition of predictor outputs to form the partial signal
- estimate (from the sixth order predictor) and the signal
- estimate.
- Inputs: wa1, wa2, wb1, wb2, wb3, wb4, wb5, wb6
- Output: se, sez
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_accum (short *wa1, short *wa2, short *wb1, short *wb2, short *wb3, short *wb4, short *wb5, short *wb6, short *se, short *sez) {
- unsigned long sezi;
- unsigned long wa11, wa21, wb11, wb21, wb31, wb41, wb51, wb61, sei;
- /* Preamble */
- wa11 = *wa1;
- wa21 = *wa2;
- wb11 = *wb1;
- wb21 = *wb2;
- wb31 = *wb3;
- wb41 = *wb4;
- wb51 = *wb5;
- wb61 = *wb6;
- /* Sum of partial signal estimate */
- sezi = (((((((((wb11 + wb21) & 65535) + wb31) & 65535)
- + wb41) & 65535) + wb51) & 65535) + wb61) & 65535;
- /* Complete sum for signal estimate */
- sei = (((sezi + wa21) & 65535) + wa11) & 65535;
- *sez = (short) (sezi >> 1);
- *se = (short) (sei >> 1);
- }
- /* ....................... end of G726_accum() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_addb (short *dq, short *se, short *sr);
- ~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Addition of quantized difference signal and signal estimate
- to form reconstructed signal.
- Inputs: dq, se
- Output: sr
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_addb (short *dq, short *se, short *sr) {
- unsigned long dq1, se1;
- unsigned long dqi, sei;
- short dqs, ses;
- /* Preamble */
- dq1 = *dq & 65535;
- se1 = *se;
- /* Sign */
- dqs = (*dq >> 15) & 1;
- /* Convert signed magnitude to 2's complement */
- dqi = (dqs == 0) ? dq1 : ((65536 - (dq1 & 32767)) & 65535);
- ses = (*se >> 14);
- /* Sign extension */
- sei = (ses == 0) ? se1 : ((1 << 15) + se1);
- *sr = (short) ((dqi + sei) & 65535);
- }
- /* ....................... end of G726_addb() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_addc (short *dq, short *sez, short *pk0,
- ~~~~~~~~~~~~~~ short *sigpk);
- Description:
- ~~~~~~~~~~~~
- Obtain sign of addition of quantized difference signal and
- partial signal estimate.
- Inputs: dq, sez
- Outputs: pk0, sigpk
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_addc (short *dq, short *sez, short *pk0, short *sigpk) {
- unsigned long sezi;
- short sezs;
- unsigned long dqsez, dq1;
- unsigned long dqi;
- short dqs;
- unsigned long sez1;
- /* Preamble */
- dq1 = *dq & 65535;
- sez1 = *sez;
- /* Get sign */
- dqs = (*dq >> 15) & 1;
- /* Convert signed magnitude to 2's compelemnent */
- dqi = (dqs == 0) ? dq1 : ((65536 - (dq1 & 32767)) & 65535);
- sezs = (*sez >> 14);
- /* Sign extension */
- sezi = (sezs == 0) ? sez1 : (sez1 + 32768);
- dqsez = (dqi + sezi) & 65535;
- *pk0 = (short) (dqsez >> 15);
- *sigpk = (dqsez == 0) ? 1 : 0;
- }
- /* ....................... end of G726_addc() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_floata (short *dq, short *dq0);
- ~~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Convert 16-bit signed magnitude to floating point.
- Inputs: dq
- Output: dq0
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_floata (short *dq, short *dq0) {
- long mant;
- long mag, exp_;
- long dqs;
- dqs = (*dq >> 15) & 1;
- /* Compute magnitude */
- mag = *dq & 32767;
- /* Exponent */
- if (mag >= 16384)
- exp_ = 15;
- else if (mag >= 8192)
- exp_ = 14;
- else if (mag >= 4096)
- exp_ = 13;
- else if (mag >= 2048)
- exp_ = 12;
- else if (mag >= 1024)
- exp_ = 11;
- else if (mag >= 512)
- exp_ = 10;
- else if (mag >= 256)
- exp_ = 9;
- else if (mag >= 128)
- exp_ = 8;
- else if (mag >= 64)
- exp_ = 7;
- else if (mag >= 32)
- exp_ = 6;
- else if (mag >= 16)
- exp_ = 5;
- else if (mag >= 8)
- exp_ = 4;
- else if (mag >= 4)
- exp_ = 3;
- else if (mag >= 2)
- exp_ = 2;
- else if (mag == 1)
- exp_ = 1;
- else
- exp_ = 0;
- /* Compute mantissa w/a 1 in the most sig. bit */
- mant = (mag == 0) ? (1 << 5) : ((mag << 6) >> exp_);
- /* Combine sign, exponent and mantissa (1,4,6) bits in a word */
- *dq0 = (short) ((dqs << 10) + (exp_ << 6) + mant);
- }
- /* ....................... end of G726_floata() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_floatb (short *sr, short *sr0);
- ~~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Convert 16-bit two's complement to floating point.
- Inputs: sr
- Output: sr0
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_floatb (short *sr, short *sr0) {
- long mant;
- long mag, exp_, srr, srs;
- /* Preamble */
- srr = *sr & 65535;
- /* Sign */
- srs = (srr >> 15);
- /* Compute magnitude */
- mag = (srs == 0) ? srr : ((65536 - srr) & 32767);
- /* Exponent */
- if (mag >= 16384)
- exp_ = 15;
- else if (mag >= 8192)
- exp_ = 14;
- else if (mag >= 4096)
- exp_ = 13;
- else if (mag >= 2048)
- exp_ = 12;
- else if (mag >= 1024)
- exp_ = 11;
- else if (mag >= 512)
- exp_ = 10;
- else if (mag >= 256)
- exp_ = 9;
- else if (mag >= 128)
- exp_ = 8;
- else if (mag >= 64)
- exp_ = 7;
- else if (mag >= 32)
- exp_ = 6;
- else if (mag >= 16)
- exp_ = 5;
- else if (mag >= 8)
- exp_ = 4;
- else if (mag >= 4)
- exp_ = 3;
- else if (mag >= 2)
- exp_ = 2;
- else if (mag == 1)
- exp_ = 1;
- else
- exp_ = 0;
- /* Compute mantissa w/a 1 in the most sig. bit */
- mant = (mag == 0) ? (1 << 5) : ((mag << 6) >> exp_);
- /* Combine sign, exponent and mantissa (1,4,6) bits in a word */
- *sr0 = (short) ((srs << 10) + (exp_ << 6) + mant);
- }
- /* ....................... end of G726_floatb() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_fmult (short *a, short *srn, short *wa);
- ~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Multiply predictor coefficients with corresponding quantized
- difference signal or reconstructed signal. multiplication is
- done in floating piont format
- Inputs: a (or b), srn (or dqn)
- Outputs: wa (or wb)
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_fmult (short *An, short *SRn, short *WAn) {
- long anmag, anexp, wanmag, anmant;
- long wanexp, srnexp, an, ans, wanmant, srnmant;
- long wan, wans, srns, srn1;
- /* Preamble */
- an = *An & 65535;
- srn1 = *SRn & 65535;
- /* Sign */
- ans = an & 32768;
- ans = (ans >> 15);
- /* Convert 2's complement to signed magnitude */
- anmag = (ans == 0) ? (an >> 2) : ((16384 - (an >> 2)) & 8191);
- /* Exponent */
- if (anmag >= 4096)
- anexp = 13;
- else if (anmag >= 2048)
- anexp = 12;
- else if (anmag >= 1024)
- anexp = 11;
- else if (anmag >= 512)
- anexp = 10;
- else if (anmag >= 256)
- anexp = 9;
- else if (anmag >= 128)
- anexp = 8;
- else if (anmag >= 64)
- anexp = 7;
- else if (anmag >= 32)
- anexp = 6;
- else if (anmag >= 16)
- anexp = 5;
- else if (anmag >= 8)
- anexp = 4;
- else if (anmag >= 4)
- anexp = 3;
- else if (anmag >= 2)
- anexp = 2;
- else if (anmag == 1)
- anexp = 1;
- else
- anexp = 0;
- /* Compute mantissa w/a 1 in the most sig. bit */
- anmant = (anmag == 0) ? (1 << 5) : ((anmag << 6) >> anexp);
- /* Split floating point word into sign, exponent and mantissa */
- srns = (srn1 >> 10);
- srnexp = (srn1 >> 6) & 15;
- srnmant = srn1 & 63;
- /* Floating point multiplication */
- wans = srns ^ ans;
- wanexp = srnexp + anexp;
- wanmant = ((srnmant * anmant) + 48) >> 4;
- /* Convert floating point to magnitude */
- wanmag = (wanexp <= 26) ? (wanmant << 7) >> (26 - wanexp) : ((wanmant << 7) << (wanexp - 26)) & 32767;
- /* Convert mag. to 2's complement */
- wan = (wans == 0) ? wanmag : ((65536 - wanmag) & 65535);
- *WAn = (short) wan;
- }
- /* ....................... end of G726_fmult() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_limc (short *a2t, short *a2p);
- ~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Limits on a2 coefficient of second order predictor.
- Inputs: a2t
- Output: a2p
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_limc (short *a2t, short *a2p) {
- long a2p1, a2t1, a2ll, a2ul;
- a2t1 = *a2t & 65535;
- a2ul = 12288; /* Upper limit of +.75 */
- a2ll = 53248; /* Lower limit of -.75 */
- if (a2t1 >= 32768 && a2t1 <= a2ll)
- a2p1 = a2ll;
- else if (a2t1 >= a2ul && a2t1 <= 32767)
- a2p1 = a2ul;
- else
- a2p1 = a2t1;
- *a2p = (short) a2p1;
- }
- /* ....................... end of G726_limc() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_limd (short *a1t, short *a2p, short *a1p);
- ~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Limits on a1 coefficient of second order predictor.
- Inputs: a1t, a2p
- Output: a1p
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_limd (short *a1t, short *a2p, short *a1p) {
- long a1p1, a2p1, a1t1, ome, a1ll, a1ul;
- /* Preamble */
- a1t1 = *a1t & 65535;
- a2p1 = *a2p & 65535;
- /* (1-epsilon), where epsilon = (1/16) */
- ome = 15360;
- /* Compute upper limit */
- a1ul = (ome + 65536 - a2p1) & 65535;
- /* Compute lower limit */
- a1ll = (a2p1 + 65536 - ome) & 65535;
- if (a1t1 >= 32768 && a1t1 <= a1ll)
- a1p1 = a1ll;
- else if (a1t1 >= a1ul && a1t1 <= 32767)
- a1p1 = a1ul;
- else
- a1p1 = a1t1;
- *a1p = (short) a1p1;
- }
- /* ....................... end of G726_limd() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_trigb (short *tr, short *ap, short *ar);
- ~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Predictor trigger block.
- Inputs: tr, ap (ou bp ou tdp)
- Output: ar (ou br ou tdr)
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_trigb (short *tr, short *ap, short *ar) {
- *ar = (*tr == 0) ? *ap : 0;
- }
- /* ....................... end of G726_trigb() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_upa1 (short *pk0, short *pk1, short *a1,
- ~~~~~~~~~~~~~~ short *sigpk, short *a1t);
- Description:
- ~~~~~~~~~~~~
- Update a1 coefficient of second order predictor.
- Inputs: pk0, pk1, a1, sigpk
- Output: a1t
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_upa1 (short *pk0, short *pk1, short *a1, short *sigpk, short *a1t) {
- long a11, a1s, ua1;
- long ash;
- short pks;
- long uga1, ula1;
- /* Preamble */
- a11 = *a1 & 65535;
- pks = (*pk0) ^ (*pk1);
- /* Gain is +/- (3/256) */
- uga1 = (*sigpk == 1) ? 0 : ((pks == 0) ? 192 : 65344);
- a1s = (a11 >> 15);
- /* Leak factor is (1/256) */
- ash = (a11 >> 8);
- ula1 = ((a1s == 0) ? (65536 - ash) : (65536 - (ash + 65280))) & 65535;
- /* Compute update */
- ua1 = (uga1 + ula1) & 65535;
- *a1t = (short) ((a11 + ua1) & 65535);
- }
- /* ....................... end of G726_upa1() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_upa2 (short *pk0, short *pk1, short *pk2,
- ~~~~~~~~~~~~~~ short *a2, short *a1, short *sigpk, short *a2t);
- Description:
- ~~~~~~~~~~~~
- Update a2 coefficient of second order predictor.
- Inputs: pk0, pk1, pk2, a2, a1, sigpk
- Output: a2t
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_upa2 (short *pk0, short *pk1, short *pk2, short *a2, short *a1, short *sigpk, short *a2t) {
- long uga2a, uga2b, uga2s;
- long a11, a21, fa, fa1;
- short a1s, a2s;
- long ua2;
- long uga2, ula2;
- short pks1, pks2;
- /* Preamble */
- a11 = *a1 & 65535;
- a21 = *a2 & 65535;
- /* 1 bit xors */
- pks1 = (*pk0 ^ *pk1);
- pks2 = (*pk0 ^ *pk2);
- uga2a = (pks2 == 0) ? 16384 : 114688;
- a1s = (*a1 >> 15);
- /* Implement f(a1) w/ limiting at +/-(1/2) */
- if (a1s == 0)
- fa1 = (a11 <= 8191) ? (a11 << 2) : (8191 << 2);
- else
- fa1 = (a11 >= 57345) ? ((a11 << 2) & 131071) : (24577 << 2);
- /* Attach sign to the result of f(a1) */
- fa = (pks1) ? fa1 : ((131072 - fa1) & 131071);
- uga2b = (uga2a + fa) & 131071;
- uga2s = (uga2b >> 16);
- uga2 = (*sigpk == 1) ? 0 : ((uga2s) ? ((uga2b >> 7) + 64512) : (uga2b >> 7));
- a2s = (*a2 >> 15);
- ula2 = (a2s == 0) ? (65536 - (a21 >> 7)) & 65535 : (65536 - ((a21 >> 7) + 65024)) & 65535;
- /* Compute update */
- ua2 = (uga2 + ula2) & 65535;
- *a2t = (short) ((a21 + ua2) & 65535);
- }
- /* ....................... end of G726_upa2() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_upb (short rate, short *u, short *b, short *dq, short *bp);
- ~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Update for coefficients of sixth order predictor.
- Inputs: u, b, dq, rate
- Output: bp
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_upb (short rate, short *u, short *b, short *dq, short *bp) {
- short dqmag;
- long bb, bs, ub;
- long ugb, ulb;
- short param;
- short leak;
- /* Preamble */
- bb = *b & 65535;
- dqmag = *dq & 32767;
- if (rate != 5) {
- leak = 8;
- param = 65280;
- } else {
- leak = 9;
- param = 65408;
- }
- /* gain is 0 or +/- (1/128) */
- ugb = (dqmag == 0) ? 0 : ((*u == 0) ? 128 : 65408);
- bs = (bb >> 15);
- /* Leak factor is (1/256 or 1/512 for 40 kbit/s) */
- ulb = (bs == 0) ? ((65536 - (bb >> leak)) & 65535) : ((65536 - ((bb >> leak) + param)) & 65535);
- /* Compute update */
- ub = (ugb + ulb) & 65535;
- /* aux = bb + ub;*/
- *bp = (short) ((bb + ub) & 65535);
- }
- /* ....................... end of G726_upb() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_xor (short *dqn, short *dq, short *u);
- ~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- One bit "exclusive or" of sign of difference signal and sign
- of delayed difference signal.
- Inputs: dqn, dq
- Output: u
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_xor (short *dqn, short *dq, short *u) {
- short dqns;
- short dqs;
- dqs = (*dq >> 15) & 1;
- dqns = (*dqn >> 10);
- *u = (dqs ^ dqns);
- }
- /* ....................... end of G726_xor() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_tone (short *a2p, short *tdp);
- ~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Partial band signal detection.
- Inputs: a2p
- Output: tdp
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_tone (short *a2p, short *tdp) {
- long a2p1;
- a2p1 = *a2p & 65535;
- *tdp = (a2p1 >= 32768 && a2p1 < 53760) ? 1 : 0;
- }
- /* ....................... end of G726_tone() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_trans (short *td, long *yl, short *dq, short *tr);
- ~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Transition detector.
- Inputs: td, yl, dq
- Output: tr
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_trans (short *td, long *yl, short *dq, short *tr) {
- short dqmag;
- long dqthr;
- short ylint;
- long dqmag1;
- short ylfrac;
- long thr1, thr2;
- dqmag = *dq & 32767;
- ylint = (*yl >> 15);
- ylfrac = (*yl >> 10) & 31;
- thr1 = (ylfrac + 32) << ylint;
- thr2 = (ylint > 9) ? 31744 : thr1;
- dqthr = (thr2 + (thr2 >> 1)) >> 1;
- dqmag1 = dqmag;
- *tr = (dqmag1 > dqthr && *td == 1) ? 1 : 0;
- }
- /* ....................... end of G726_trans() ....................... */
- /*
- ----------------------------------------------------------------------
- void G726_compress (short *sr, char *law, short *sp);
- ~~~~~~~~~~~~~~~~~~
- Description:
- ~~~~~~~~~~~~
- Convert from uniform pcm to either a-law or u-law pcm
- Inputs: sr, law
- Output: sp
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- 24.Jan.00 v2.0 Corrected im calculation that caused incorrect
- processing of test vector ri40fa. Corrected
- code provided by Jayesh Patel <jayesh@dspse.com>.
- Verified by <simao.campos@labs.comsat.com>
- ----------------------------------------------------------------------
- */
- void G726_compress (short *sr, char *law, short *sp) {
- short imag, iesp, ofst;
- short ofst1;
- long i;
- long im;
- short is;
- long srr;
- is = (*sr >> 15);
- srr = (*sr & 65535);
- /* Convert 2-complement to signed magnitude */
- im = (is == 0) ? srr : ((65536 - srr) & 32767);
- /* Compress ... */
- if (*law == '1') {
- /* Next line added by J.Patel to fix a with test vector ri40fa.o */
- im = (*sr == -32768) ? 2 : im; /* *** */
- imag = (is == 0) ? (im >> 1) : ((im + 1) >> 1);
- if (is)
- --imag;
- /* Saturation */
- if (imag > 4095)
- imag = 4095;
- iesp = 7;
- for (i = 1; i <= 7; ++i) {
- imag += imag;
- if (imag >= 4096)
- break;
- iesp = 7 - i;
- }
- imag &= 4095;
- imag = (imag >> 8);
- *sp = (is == 0) ? imag + (iesp << 4) : imag + (iesp << 4) + 128;
- /* Sign bit inversion */
- *sp ^= 128;
- } else {
- imag = im;
- if (imag > 8158)
- imag = 8158; /* Saturation */
- ++imag;
- iesp = 0;
- ofst = 31;
- if (imag > ofst) {
- for (iesp = 1; iesp <= 8; ++iesp) {
- ofst1 = ofst;
- ofst += (1 << (iesp + 5));
- if (imag <= ofst)
- break;
- }
- imag -= ofst1 + 1;
- }
- imag /= (1 << (iesp + 1));
- *sp = (is == 0) ? (imag + (iesp << 4)) : (imag + (iesp << 4) + 128);
- /* Sign bit inversion */
- *sp ^= 128;
- *sp ^= 127;
- }
- }
- /* ....................... end of G726_compress()....................... */
- /*
- ----------------------------------------------------------------------
- void G726_sync (short rate, short *i, short *sp, short *dlnx,
- ~~~~~~~~~~~~~~ short *dsx, char *law, short *sd);
- Description:
- ~~~~~~~~~~~~
- Re-encode output pcm sample in decoder for synchronous tandem
- coding.
- Inputs: i, sp, dlnx, dsx, law, rate
- Output: sd
- Return value: none.
- ~~~~~~~~~~~~~
- Prototype: in g726.h
- ~~~~~~~~~~
- History:
- ~~~~~~~~
- 31.Jan.91 v1.0f Release of 1st Fortran version to UGST.
- <tdsindi@venus.cpqd.ansp.br>
- 13.Feb.92 v1.0c 1st version in C translated from Fortran (f2c)
- <tdsimao@venus.cpqd.ansp.br>
- ----------------------------------------------------------------------
- */
- void G726_sync (short rate, short *i, short *sp, short *dlnx, short *dsx, char *law, short *sd) {
- short mask, id, im, is, ss;
- if (rate == 4) {
- is = (*i >> 3);
- im = (is == 0) ? (*i + 8) : (*i & 7);
- /* Find value of `id' as in Table 17/G.726 */
- if (*dlnx >= 3972)
- id = 9;
- else if (*dlnx >= 2048)
- id = 7;
- else if (*dlnx >= 400)
- id = 15;
- else if (*dlnx >= 349)
- id = 14;
- else if (*dlnx >= 300)
- id = 13;
- else if (*dlnx >= 246)
- id = 12;
- else if (*dlnx >= 178)
- id = 11;
- else if (*dlnx >= 80)
- id = 10;
- else
- id = 9;
- /* Account for the negative part of the table */
- if (*dsx)
- id = 15 - id;
- if (id == 8)
- id = 7;
- } /* ............... end of 32 kbit part * ................. */
- else if (rate == 3) {
- is = (*i >> 2);
- im = (is == 0) ? (*i + 4) : (*i & 3);
- /* Find value of `id' as in the Table 18/G.726 */
- if (*dlnx >= 2048)
- id = 3;
- else if (*dlnx >= 331)
- id = 7;
- else if (*dlnx >= 218)
- id = 6;
- else if (*dlnx >= 8)
- id = 5;
- else if (*dlnx >= 0)
- id = 3;
- if (*dsx)
- id = 7 - id;
- if (id == 4)
- id = 3;
- } /* ............... end of 24 kbit part * ................. */
- else if (rate == 2) {
- is = (*i >> 1);
- im = (is == 0) ? (*i + 2) : (*i & 1);
- /* Find value of `id' as in the Table 19/G.726 */
- if (*dlnx >= 2048)
- id = 2;
- else if (*dlnx >= 261)
- id = 3;
- else if (*dlnx >= 0)
- id = 2;
- if (*dsx)
- id = 3 - id;
- } /* ............... end of 16 kbit part * ................. */
- else {
- is = (*i >> 4);
- im = (is == 0) ? (*i + 16) : (*i & 15);
- /* Find value of `id' as in the Table 16/G.726 */
- if (*dlnx >= 4080)
- id = 18;
- else if (*dlnx >= 3974)
- id = 17;
- else if (*dlnx >= 2048)
- id = 15;
- else if (*dlnx >= 553)
- id = 31;
- else if (*dlnx >= 528)
- id = 30;
- else if (*dlnx >= 502)
- id = 29;
- else if (*dlnx >= 475)
- id = 28;
- else if (*dlnx >= 445)
- id = 27;
- else if (*dlnx >= 413)
- id = 26;
- else if (*dlnx >= 378)
- id = 25;
- else if (*dlnx >= 339)
- id = 24;
- else if (*dlnx >= 298)
- id = 23;
- else if (*dlnx >= 250)
- id = 22;
- else if (*dlnx >= 198)
- id = 21;
- else if (*dlnx >= 139)
- id = 20;
- else if (*dlnx >= 68)
- id = 19;
- else if (*dlnx >= 0)
- id = 18;
- if (*dsx)
- id = 31 - id;
- if (id == 16)
- id = 15;
- } /* ............... end of 40 kbit part ................. */
- /* Choose sd as sp, sp+ or sp- */
- ss = (*sp & 128) >> 7;
- mask = (*sp & 127);
- if (*law == '1') { /* ......... A-law */
- if (id > im && ss == 1 && mask == 0)
- ss = 0;
- else if (id > im && ss == 1 && mask != 0)
- mask--;
- else if (id > im && ss == 0 && mask != 127)
- mask++;
- else if (id < im && ss == 1 && mask != 127)
- mask++;
- else if (id < im && ss == 0 && mask == 0)
- ss = 1;
- else if (id < im && ss == 0 && mask != 0)
- mask--;
- } else { /* ......... u-law */
- if (id > im && ss == 1 && mask == 127) {
- ss = 0;
- mask--;
- } else if (id > im && ss == 1 && mask != 127)
- mask++;
- else if (id > im && ss == 0 && mask != 0)
- mask--;
- else if (id < im && ss == 1 && mask != 0)
- mask--;
- else if (id < im && ss == 0 && mask == 127)
- ss = 1;
- else if (id < im && ss == 0 && mask != 127)
- mask++;
- }
- *sd = mask + (ss << 7);
- }
- /* ........................ end of G726_sync() ........................ */
- /* ************************* END OF G726.C ************************* */
|