ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Суббота
6 июля
164486
fk0, легенда (24.08.2009 16:54, просмотров: 3396)
Говнокод (помогите оптимизировать size & speed)  uint_fast8_t linear2ulaw(int samp) { uint_fast8_t sign, xexp, mant, ulaw; /* Get the sample into sign-magnitude. */ sign=(samp>>8)&0x80; if (samp<0) { if (samp==0x8000) samp=0x7fff; else samp=-samp; } if ((unsigned)samp > CLIP) samp = CLIP; /* Convert from 16 bit linear to ulaw. */ samp+=BIAS; ulaw=samp>>8; if (ulaw&0x40) { xexp = 7 << 4; samp>>=1; goto l1; } else if (ulaw&0x20) { xexp = 6 << 4; l1: samp>>=1; goto l2; } else if (ulaw&0x10) { xexp = 5 << 4; l2: samp>>=1; goto l3; } else if (ulaw&0x08) { xexp = 4 << 4; l3: samp>>=1; goto l4; } else if (ulaw&0x04) { xexp = 3 << 4; l4: samp>>=1; goto l5; } else if (ulaw&0x02) { xexp = 2 << 4; l5: samp>>=1; goto l6; } else if (ulaw&0x01) { xexp = 1 << 4; l6: samp>>=1; goto l7; } else xexp = 0; l7: mant=samp; mant=(mant>>3)&0x0f; ulaw = ~(sign | xexp | mant); return ulaw; } int ulaw2linear(uint_fast8_t ulaw) { bool sign; uint_fast8_t xexp, mant; int samp; ulaw = ~ulaw; sign = (ulaw & 0x80) ? 1 : 0; xexp = (ulaw >> 4) & 0x07; mant = ulaw & 0x0F; mant<<=3; switch (xexp) { case 7: samp=16764+(mant<<7); break; case 6: samp=8316+(mant<<6); break; case 5: samp=4092+(mant<<5); break; case 4: samp=1980+(mant<<4); break; case 3: samp=924+(mant<<3); break; case 2: samp=396+(mant<<2); break; case 1: samp=132+(mant<<1); break; default: samp=mant; } return sign ? -samp : samp; }
[ZX]