static void cvtMS168C(DWORD srcRate, const unsigned char* src, LPDWORD nsrc, DWORD dstRate, unsigned char* dst, LPDWORD ndst) { DWORD error = dstRate / 2; TRACE("(%d, %p, %p, %d, %p, %p)\n", srcRate, src, nsrc, dstRate, dst, ndst); while ((*ndst)--) { *dst++ = C168(R16(src)); *dst++ = C168(R16(src)); error = error + srcRate; while (error > dstRate) { src += 2; (*nsrc)--; if (*nsrc==0) return; error = error - dstRate; } } }
static void cvtMS1616K(const unsigned char* src, int ns, unsigned char* dst) { short v; TRACE("(%p, %d, %p)\n", src, ns, dst); while (ns--) { v = R16(src); src += 2; W16(dst, v); dst += 2; W16(dst, v); dst += 2; } }
static void cvtMS168K(const unsigned char* src, int ns, unsigned char* dst) { unsigned char v; TRACE("(%p, %d, %p)\n", src, ns, dst); while (ns--) { v = C168(R16(src)); src += 2; *dst++ = v; *dst++ = v; } }
/* * FIXME: This might be useful in the future. Otherwise feel free to remove. * If mode=1, it sets the panel in a low-power, low-performance state; * if mode=0, then high performance. */ static int ViaVbePanelLowPower(vbeInfoPtr pVbe, int mode) { pVbe->pInt10->num = 0x10; pVbe->pInt10->ax = 0x5F60; pVbe->pInt10->bx = (mode) ? 0x01 : 0x00; xf86ExecX86int10(pVbe->pInt10); return (R16(pVbe->pInt10->ax) == 0x015f); }
static void cvtMMms16K(const ACMDRVSTREAMINSTANCE *adsi, const unsigned char* src, LPDWORD nsrc, unsigned char* dst, LPDWORD ndst) { int idelta; int sample1, sample2; ADPCMCOEFSET coeff; int nsamp; int nsamp_blk = ((ADPCMWAVEFORMAT*)adsi->pwfxSrc)->wSamplesPerBlock; DWORD nblock = min(*nsrc / adsi->pwfxSrc->nBlockAlign, *ndst / (nsamp_blk * 2)); *nsrc = nblock * adsi->pwfxSrc->nBlockAlign; *ndst = nblock * nsamp_blk * 2; nsamp_blk -= 2; /* see below for samples from block head */ for (; nblock > 0; nblock--) { const unsigned char* in_src = src; assert(*src <= 6); coeff = MSADPCM_CoeffSet[*src++]; idelta = R16(src); src += 2; sample1 = R16(src); src += 2; sample2 = R16(src); src += 2; /* store samples from block head */ W16(dst, sample2); dst += 2; W16(dst, sample1); dst += 2; for (nsamp = nsamp_blk; nsamp > 0; nsamp -= 2) { process_nibble(*src >> 4, &idelta, &sample1, &sample2, &coeff); W16(dst, sample1); dst += 2; process_nibble(*src++ & 0x0F, &idelta, &sample1, &sample2, &coeff); W16(dst, sample1); dst += 2; } src = in_src + adsi->pwfxSrc->nBlockAlign; } }
void speck_set_decrypt_key16(SPECK_TYPE16 const K[SPECK_KEY_LEN16], SPECK_TYPE16 S[SPECK_ROUNDS16]) { SPECK_TYPE16 i, b = K[0]; SPECK_TYPE16 a[SPECK_KEY_LEN16 - 1]; for (i = 0; i < (SPECK_KEY_LEN16 - 1); i++) { a[i] = K[i + 1]; } S[0] = b; for (i = 0; i < SPECK_ROUNDS16 - 1; i++) { R16(a[i % (SPECK_KEY_LEN16 - 1)], b, i); S[i + 1] = b; } }
static s32 BTHandleData(void *arg,void *buffer,u16 len) { sync_before_read(arg, sizeof(struct BTPadStat)); struct BTPadStat *stat = (struct BTPadStat*)arg; u32 chan = stat->channel; if(*(u8*)buffer == 0x3D) //21 expansion bytes report { if(stat->transferstate == TRANSFER_CALIBRATE) { stat->xAxisLmid = bswap16(R16((u32)(((u8*)buffer)+1))); stat->xAxisRmid = bswap16(R16((u32)(((u8*)buffer)+3))); stat->yAxisLmid = bswap16(R16((u32)(((u8*)buffer)+5))); stat->yAxisRmid = bswap16(R16((u32)(((u8*)buffer)+7))); stat->transferstate = TRANSFER_DONE; sync_after_write(arg, sizeof(struct BTPadStat)); sync_before_read(arg, sizeof(struct BTPadStat)); } if(chan == CHAN_NOT_SET) return ERR_OK; sync_before_read(&BTPad[chan], sizeof(struct BTPadCont)); BTPad[chan].xAxisL = ((bswap16(R16((u32)(((u8*)buffer)+1))) - stat->xAxisLmid) *3) >>5; BTPad[chan].xAxisR = ((bswap16(R16((u32)(((u8*)buffer)+3))) - stat->xAxisRmid) *3) >>5; BTPad[chan].yAxisL = ((bswap16(R16((u32)(((u8*)buffer)+5))) - stat->yAxisLmid) *3) >>5; BTPad[chan].yAxisR = ((bswap16(R16((u32)(((u8*)buffer)+7))) - stat->yAxisRmid) *3) >>5; u32 prevButton = BTPad[chan].button; BTPad[chan].button = ~(R16((u32)(((u8*)buffer)+9))); if((!(prevButton & BT_BUTTON_SELECT)) && BTPad[chan].button & BT_BUTTON_SELECT) { //dbgprintf("Using %s control scheme\n", (stat->controller & C_SWAP) ? "orginal" : "swapped"); stat->controller = (stat->controller & C_SWAP) ? (stat->controller & ~C_SWAP) : (stat->controller | C_SWAP); sync_after_write(arg, sizeof(struct BTPadStat)); sync_before_read(arg, sizeof(struct BTPadStat)); } BTPad[chan].used = stat->controller; sync_after_write(&BTPad[chan], sizeof(struct BTPadCont)); } else if(*(u8*)buffer == 0x34) //core buttons with 19 exptension bytes report
static void stop(struct net_device *dev) { struct fs_enet_private *fep = netdev_priv(dev); scc_t __iomem *sccp = fep->scc.sccp; int i; for (i = 0; (R16(sccp, scc_sccm) == 0) && i < SCC_RESET_DELAY; i++) udelay(1); if (i == SCC_RESET_DELAY) printk(KERN_WARNING DRV_MODULE_NAME ": %s SCC timeout on graceful transmit stop\n", dev->name); W16(sccp, scc_sccm, 0); C32(sccp, scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT); fs_cleanup_bds(dev); }
static void cvtSSms16K(const ACMDRVSTREAMINSTANCE *adsi, const unsigned char* src, LPDWORD nsrc, unsigned char* dst, LPDWORD ndst) { int ideltaL, ideltaR; int sample1L, sample2L; int sample1R, sample2R; ADPCMCOEFSET coeffL, coeffR; int nsamp; int nsamp_blk = ((ADPCMWAVEFORMAT*)adsi->pwfxSrc)->wSamplesPerBlock; DWORD nblock = min(*nsrc / adsi->pwfxSrc->nBlockAlign, *ndst / (nsamp_blk * adsi->pwfxDst->nBlockAlign)); *nsrc = nblock * adsi->pwfxSrc->nBlockAlign; *ndst = nblock * nsamp_blk * adsi->pwfxDst->nBlockAlign; nsamp_blk -= 2; /* see below for samples from block head */ for (; nblock > 0; nblock--) { const unsigned char* in_src = src; assert(*src <= 6); coeffL = MSADPCM_CoeffSet[*src++]; assert(*src <= 6); coeffR = MSADPCM_CoeffSet[*src++]; ideltaL = R16(src); src += 2; ideltaR = R16(src); src += 2; sample1L = R16(src); src += 2; sample1R = R16(src); src += 2; sample2L = R16(src); src += 2; sample2R = R16(src); src += 2; if(adsi->pwfxDst->wBitsPerSample == 8){ /* store samples from block head */ *dst = C168(sample2L); ++dst; *dst = C168(sample2R); ++dst; *dst = C168(sample1L); ++dst; *dst = C168(sample1R); ++dst; for (nsamp = nsamp_blk; nsamp > 0; nsamp--) { process_nibble(*src >> 4, &ideltaL, &sample1L, &sample2L, &coeffL); *dst = C168(sample1L); ++dst; process_nibble(*src++ & 0x0F, &ideltaR, &sample1R, &sample2R, &coeffR); *dst = C168(sample1R); ++dst; } }else if(adsi->pwfxDst->wBitsPerSample == 16){
inline void AlphaBlend( Uint16& p, int cr, int cg, int cb, int a, int ia ) { //565 p = R16G16B16_TO_RGB565( a * cr + ia * R16(p), a * cg + ia * G16(p), a * cb + ia * B16(p) ); }
void ExtractRgb( uint16 c, int& r, int &g, int &b ) { r = R16(c); g = G16(c); b = B16(c); }
uint8_t picHeader::open(char *inname) { uint32_t nnum,fcc; FILE *fd; char *end; uint32_t w=0,h=0; // 1- identity the file type // fd=fopen(inname,"rb"); if(!fd) { printf("\n Cannot open that file!\n"); return 0; } fread(&fcc,4,1,fd); fclose(fd); if(fourCC::check(fcc,(uint8_t *)"RIFF")) { _type=PIC_BMP; printf("\n It looks like BMP...\n"); } else { if((fcc&0xffff)==R16(0xd8ff)) { _type=PIC_JPEG; printf("\n It looks like Jpg...\n"); } else { printf("\n Cannot identify file (%x %x)\n",fcc,fcc&0xffff); return 0; } } // Then spit the name in name and extension char *name; char *extension; PathSplit(inname, &name, &extension); nnum=1; end=name+strlen(name)-1; while(( *end>='0') && (*end<='9')) { end--; nnum++; }; if(nnum==1) { printf("\n only one file!"); return 0; } nnum--; end++; _first=atoi(end); printf("\n First : %lu, num digit :%lu",_first,nnum); *(end)=0; printf("\n Path : %s",name); char realname[250]; char realstring[250]; sprintf(realstring,"%%s%%0%lud.%s",nnum,extension); printf("\n string : %s",realstring); _nb_file=0; for(uint32_t i=0;i<999;i++) { sprintf(realname,realstring,name,i+_first); printf("\n %lu : %s",i,realname); fd=fopen(realname,"rb"); if(fd==NULL) break; fclose(fd); _nb_file++; } printf("\n found %lu images\n",_nb_file); _fd=(FILE **)malloc(_nb_file*sizeof(FILE*)); _imgSize=new uint32_t[_nb_file]; //_________________________________ // now open them and assign fd && imgSize //__________________________________ for(uint32_t i=0;i<_nb_file;i++) { sprintf(realname,realstring,name,i+_first); printf("\n %lu : %s",i,realname); _fd[i]=fopen(realname,"rb"); fseek(_fd[i],0,SEEK_END); _imgSize[i]=ftell( _fd[i] ); fseek(_fd[i],0,SEEK_SET); assert(_fd[i]!=NULL); } delete [] name; delete [] extension; // // Image is bmp type //________________________ if(PIC_BMP==_type) { BITMAPHEADER bmph; fread(&s16,2,1, _fd[0]); if(s16!=0x4D42) { printf("\n incorrect bmp sig.\n"); return 0; } fread(&s32,4,1, _fd[0]); fread(&s32,4,1, _fd[0]); fread(&s32,4,1, _fd[0]); fread(&bmph, sizeof(bmph), 1, _fd[0]); if(bmph.compressionScheme!=0) { printf("\ncannot handle compressed bmp\n"); return 0; } _offset=bmph.size+14; w=bmph.width ; h=bmph.height ; } else { // Jpeg : Grab the size //____________________ uint16_t tag=0,count=0,off; _offset=0; fseek(_fd[0],0,SEEK_SET); read16(_fd[0]); // skip jpeg ffd8 while(count<10 && tag!=0xFFC0) { tag=read16(_fd[0]); if( (tag >>8 ) !=0xff) { printf("invalid jpeg tag found (%x)\n",tag); } if(tag==0xFFC0) { read16(_fd[0]); // size read8(_fd[0]); // precision h=read16(_fd[0]); w=read16(_fd[0]); } else { off=read16(_fd[0]); if(off<2) { printf("Offset too short!\n"); return 0; } aprintf("Found tag : %x , jumping %d bytes\n",tag,off); fseek(_fd[0],off-2,SEEK_CUR); } count++; } if(tag!=0xffc0) { printf("Cannot fint start of frame\n"); return 0; } printf("\n %lu x %lu..\n",w,h); } //_______________________________________ // Now build header info //_______________________________________ _isaudiopresent=0; // Remove audio ATM _isvideopresent=1; // Remove audio ATM #define CLR(x) memset(& x,0,sizeof( x)); CLR( _videostream); CLR( _mainaviheader); _videostream.dwScale=1; _videostream.dwRate=25; _mainaviheader.dwMicroSecPerFrame=40000;; // 25 fps hard coded _videostream.fccType=fourCC::get((uint8_t *)"vids"); _video_bih.biBitCount=24; _videostream.dwLength= _mainaviheader.dwTotalFrames=_nb_file; _videostream.dwInitialFrames= 0; _videostream.dwStart= 0; // //_video_bih.biCompression= 24; // _video_bih.biWidth=_mainaviheader.dwWidth =w ; _video_bih.biHeight=_mainaviheader.dwHeight =h; //_video_bih.biPlanes= 24; if(PIC_JPEG==_type) { _video_bih.biCompression=_videostream.fccHandler=fourCC::get((uint8_t *)"MJPG");; } else { _video_bih.biCompression=_videostream.fccHandler=0; } return 1; }
void sirius_v500(std::vector<Element>& the_ring) { int harmonic_number = 864; //double energy = 3e9; // AC10_5 double qaf_strength = 2.536876; double qad_strength = -2.730416; double qbd2_strength = -3.961194; double qbf_strength = 3.902838; double qbd1_strength = -2.966239; double qf1_strength = 2.367821; double qf2_strength = 3.354286; double qf3_strength = 3.080632; double qf4_strength = 2.707639; double sa1_strength = -115.7829759411277/2; double sa2_strength = 49.50386128829739/2; double sb1_strength = -214.5386552515188/2; double sb2_strength = 133.1252391065637/2; double sd1_strength = -302.6188062085843/2; double sf1_strength = 369.5045185071228/2; double sd2_strength = -164.3042864671946/2; double sd3_strength = -289.9270429064217/2; double sf2_strength = 333.7039740852999/2; //""" --- drift spaces --- """ double id_length = 2.0; // [m] Element dia1 = Element::drift("dia", id_length/2); Element dia2 = Element::drift("dia", 3.26920 + 3.65e-3 - id_length/2); Element dib1 = Element::drift("dib", id_length/2); Element dib2 = Element::drift("dib", 2.909200 + 3.65e-3 - id_length/2); Element d10 = Element::drift("d10", 0.100000); Element d11 = Element::drift("d11", 0.110000); Element d12 = Element::drift("d12", 0.120000); Element d13 = Element::drift("d13", 0.130000); Element d15 = Element::drift("d15", 0.150000); Element d17 = Element::drift("d17", 0.170000); Element d18 = Element::drift("d18", 0.180000); Element d20 = Element::drift("d20", 0.200000); Element d22 = Element::drift("d22", 0.220000); Element d23 = Element::drift("d23", 0.230000); Element d26 = Element::drift("d26", 0.260000); Element d32 = Element::drift("d32", 0.320000); Element d44 = Element::drift("d44", 0.440000); //""" --- markers --- """ Element mc = Element::marker("mc"); Element mia = Element::marker("mia"); Element mib = Element::marker("mib"); Element mb1 = Element::marker("mb1"); Element mb2 = Element::marker("mb2"); Element mb3 = Element::marker("mb3"); Element inicio = Element::marker("inicio"); Element fim = Element::marker("fim"); Element mida = Element::marker("id_enda"); Element midb = Element::marker("id_endb"); //""" --- beam position monitors --- """ Element mon = Element::marker("BPM"); //""" --- quadrupoles --- """ Element qaf = Element::quadrupole("qaf", 0.340000, qaf_strength); Element qad = Element::quadrupole("qad", 0.140000, qad_strength); Element qbd2 = Element::quadrupole("qbd2", 0.140000, qbd2_strength); Element qbf = Element::quadrupole("qbf", 0.340000, qbf_strength); Element qbd1 = Element::quadrupole("qbd1", 0.140000, qbd1_strength); Element qf1 = Element::quadrupole("qf1", 0.250000, qf1_strength); Element qf2 = Element::quadrupole("qf2", 0.250000, qf2_strength); Element qf3 = Element::quadrupole("qf3", 0.250000, qf3_strength); Element qf4 = Element::quadrupole("qf4", 0.250000, qf4_strength); //""" --- bending magnets --- """ double deg_2_rad = (M_PI/180.0); std::string dip_nam; double dip_len, dip_ang, dip_K, dip_S; Element h1, h2; //""" -- b1 -- """ dip_nam = "b1"; dip_len = 0.828080; dip_ang = 2.766540 * deg_2_rad; dip_K = -0.78; dip_S = 0; h1 = Element::rbend(dip_nam, dip_len/2, dip_ang/2, 1*dip_ang/2, 0*dip_ang/2, dip_K, dip_S); h2 = Element::rbend(dip_nam, dip_len/2, dip_ang/2, 0*dip_ang/2, 1*dip_ang/2, dip_K, dip_S); std::vector<Element> B1 = {h1, mb1, h2}; //""" -- b2 -- """ dip_nam = "b2"; dip_len = 1.228262; dip_ang = 4.103510 * deg_2_rad; dip_K = -0.78; dip_S = 0.00; h1 = Element::rbend(dip_nam, dip_len/2, dip_ang/2, 1*dip_ang/2, 0*dip_ang/2, dip_K, dip_S); h2 = Element::rbend(dip_nam, dip_len/2, dip_ang/2, 0*dip_ang/2, 1*dip_ang/2, dip_K, dip_S); std::vector<Element> B2 = {h1, mb2, h2}; //""" -- b3 -- """ dip_nam = "b3"; dip_len = 0.428011; dip_ang = 1.429950 * deg_2_rad; dip_K = -0.78; dip_S = 0.00; h1 = Element::rbend(dip_nam, dip_len/2, dip_ang/2, 1*dip_ang/2, 0*dip_ang/2, dip_K, dip_S); h2 = Element::rbend(dip_nam, dip_len/2, dip_ang/2, 0*dip_ang/2, 1*dip_ang/2, dip_K, dip_S); std::vector<Element> B3 = {h1, mb3, h2}; //""" -- bc -- """ dip_nam = "bc"; dip_len = 0.125394; dip_ang = 1.4 * deg_2_rad; dip_K = 0.00; dip_S = -18.93; Element bce = Element::rbend(dip_nam, dip_len/2, dip_ang/2, 1*dip_ang/2, 0*dip_ang/2, dip_K, dip_S); Element bcs = Element::rbend(dip_nam, dip_len/2, dip_ang/2, 0*dip_ang/2, 1*dip_ang/2, dip_K, dip_S); std::vector<Element> BC = {bce, mc, bcs}; //""" --- correctors --- """ Element ch = Element::hcorrector("hcm", 0, 0); Element cv = Element::vcorrector("vcm", 0, 0); Element crhv = Element::corrector ("crhv", 0, 0, 0); //""" --- sextupoles --- """ Element sa1 = Element::sextupole("sa1", 0.150000, sa1_strength); Element sa2 = Element::sextupole("sa2", 0.150000, sa2_strength); Element sb1 = Element::sextupole("sb1", 0.150000, sb1_strength); Element sb2 = Element::sextupole("sb2", 0.150000, sb2_strength); Element sd1 = Element::sextupole("sd1", 0.150000, sd1_strength); Element sf1 = Element::sextupole("sf1", 0.150000, sf1_strength); Element sd2 = Element::sextupole("sd2", 0.150000, sd2_strength); Element sd3 = Element::sextupole("sd3", 0.150000, sd3_strength); Element sf2 = Element::sextupole("sf2", 0.150000, sf2_strength); //""" --- rf cavity --- """ Element cav = Element::rfcavity("cav", 0, 500e6, 2.5e6); //""" lines """ std::vector<Element> insa = { dia1, mida, dia2, crhv, cv, d12, ch, d12, sa2, d12, mon, d12, qaf, d23, qad, d17, sa1, d17}; std::vector<Element> insb = { dib1, midb, dib2, d10, crhv, qbd2, d12, cv, d12, ch, d12, sb2, d12, mon, d12, qbf, d23, qbd1, d17, sb1, d17}; std::vector<Element> cline1 = { d32, cv, d12, ch, d15, sd1, d17, qf1, d12, mon, d11, sf1, d20, qf2, d17, sd2, d12, ch, d10, mon, d10}; std::vector<Element> cline2 = { d18, cv, d26, sd3, d17, qf3, d12, mon, d11, sf2, d20, qf4, d15, ch, crhv, d12, mon, d44}; std::vector<Element> cline3 = { d44, mon, d12, ch, d15, qf4, d20, sf2, d11, mon, d12, qf3, d17, sd3, d26, cv, crhv, d18}; std::vector<Element> cline4 = { d20, ch, d12, sd2, d17, qf2, d20, sf1, d11, mon, d12, qf1, d17, sd1, d15, ch, d12, cv, d22, mon, d10}; //""" Injection Section """ Element dmiainj = Element::drift("dmiainj", 0.3); Element dinjk3 = Element::drift("dinjk3" , 0.3); Element dk3k4 = Element::drift("dk3k4" , 0.6); Element dk4pmm = Element::drift("dk4pmm" , 0.2); Element dpmmcv = Element::drift("dpmmcv" , (3.2692 + 3.65e-3 - 0.3 - 0.3 - 0.6 - 0.2 - 3*0.6)); Element dcvk1 = Element::drift("dcvk1" , (3.2692 + 3.65e-3 - 0.6 - 1.4 - 2*0.6)); Element dk1k2 = Element::drift("dk1k2" , 0.6); Element sef = Element::sextupole("sef", 0.6, 0.0, 5); Element dk2sef = Element::drift("dk2mia" , 0.8); Element kick = Element::corrector("kick", 0.6, 0, 0); Element pmm = Element::sextupole("pmm", 0.6, 0.0, 5); Element inj = Element::marker("inj"); std::vector<Element> insaend = {cv, d12, ch, d12, sa2, d12, mon, d12, qaf, d23, qad, d17, sa1, d17}; std::vector<Element> insainj = latt_join({{dmiainj, inj, dinjk3, kick, dk3k4, kick, dk4pmm, pmm, dpmmcv}, insaend}); std::vector<Element> injinsa = latt_join({latt_reverse(insaend), {dcvk1, kick, dk1k2, kick, dk2sef, sef}}); std::vector<Element> B3BCB3 = latt_join({B3,{d13},BC,{d13},B3}); std::vector<Element> R01 = latt_join({injinsa, {fim, inicio, mia}, insainj}); //#% injection sector, marker of the lattice model starting element std::vector<Element> R03 = latt_join({latt_reverse(insa), {mia, cav}, insa}); //#% sector with cavities std::vector<Element> R05 = latt_join({latt_reverse(insa), {mia}, insa}); std::vector<Element> R07(R05); std::vector<Element> R09(R05); std::vector<Element> R11(R05); std::vector<Element> R13(R05); std::vector<Element> R15(R05); std::vector<Element> R17(R05); std::vector<Element> R19(R05); std::vector<Element> R02 = latt_join({latt_reverse(insb), {mib}, insb}); std::vector<Element> R04(R02); std::vector<Element> R06(R02); std::vector<Element> R08(R02); std::vector<Element> R10(R02); std::vector<Element> R12(R02); std::vector<Element> R14(R02); std::vector<Element> R16(R02); std::vector<Element> R18(R02); std::vector<Element> R20(R02); std::vector<Element> C01 = latt_join({B1, cline1, B2, cline2, B3BCB3, cline3, B2, cline4, B1}); std::vector<Element> C02(C01); std::vector<Element> C03(C01); std::vector<Element> C04(C01); std::vector<Element> C05(C01); std::vector<Element> C06(C01); std::vector<Element> C07(C01); std::vector<Element> C08(C01); std::vector<Element> C09(C01); std::vector<Element> C10(C01); std::vector<Element> C11(C01); std::vector<Element> C12(C01); std::vector<Element> C13(C01); std::vector<Element> C14(C01); std::vector<Element> C15(C01); std::vector<Element> C16(C01); std::vector<Element> C17(C01); std::vector<Element> C18(C01); std::vector<Element> C19(C01); std::vector<Element> C20(C01); the_ring = latt_join({ R01, C01, R02, C02, R03, C03, R04, C04, R05, C05, R06, C06, R07, C07, R08, C08, R09, C09, R10, C10, R11, C11, R12, C12, R13, C13, R14, C14, R15, C15, R16, C16, R17, C17, R18, C18, R19, C19, R20, C20, }); //""" shift lattice to start at the marker "inicio" """ std::vector<int> idx = latt_findcells_fam_name(the_ring, "inicio"); if (idx.size() > 0) { std::vector<Element>::iterator it = the_ring.begin() + idx[0]; std::rotate(the_ring.begin(), it, the_ring.end()); }; //""" check if there are elements with negative lengths """ std::vector<double> lens = latt_getcellstruct<double>(the_ring, "length", latt_range(the_ring)); for(unsigned int i=0; i<lens.size(); ++i) { if (lens[i] < 0) { std::cerr << "negative drift in lattice!" << std::endl; } } //""" sets cavity frequency according to lattice length """ double C = latt_findspos(the_ring, 1+the_ring.size()); double rev_freq = light_speed / C; std::vector<int> rf_idx = latt_findcells_fam_name(the_ring, "cav"); for(unsigned int idx = 0; idx<rf_idx.size(); ++idx) { the_ring[rf_idx[idx]].frequency = rev_freq * harmonic_number; } latt_setcavity(the_ring, "on"); //latt_setradiation(the_ring, "on", 3e9); //""" adjusts number of integraton steps for each element family """ the_ring = latt_set_num_integ_steps(the_ring); }
void AviList::Write16(uint16_t val){ #ifdef ADM_BIG_ENDIAN val=R16(val); #endif _ff->write((uint8_t *)&val,2); }
void process_dvi_data(UINT8* dvi_data, int baseoffset, int regionsize) { DVI_Header DVI; UINT8* currptr = dvi_data + baseoffset; DVI.dv1 = R32(&currptr); DVI.dv2 = R16(&currptr); DVI.dv3 = R16(&currptr); DVI.dv4 = R32(&currptr); dviprintf("DVI Header\n"); dviprintf("Header ID %08x %c%c%c%c\n", DVI.dv1, (DVI.dv1>>24)&0xff, (DVI.dv1>>16)&0xff, (DVI.dv1>>8)&0xff, (DVI.dv1>>0)&0xff); dviprintf("Header Size (or 1) %04x\n", DVI.dv2); dviprintf("Header Version %04x\n", DVI.dv3); dviprintf("Annotation Offset %08x\n", DVI.dv4); if (DVI.dv1 != 0x56445649) { dviprintf("Header Error\n"); return; } dviprintf("\n"); AVSS_Header AVSS; AVSS.av1 = R32(&currptr); AVSS.av2 = R16(&currptr); AVSS.av3 = R16(&currptr); AVSS.av4 = R16(&currptr); AVSS.av5 = R16(&currptr); AVSS.av6 = R32(&currptr); AVSS.av7 = R16(&currptr); AVSS.av8 = R16(&currptr); AVSS.av9 = R16(&currptr); AVSS.av10 = R16(&currptr); AVSS.av11 = R32(&currptr); AVSS.av12 = R32(&currptr); AVSS.av13 = R32(&currptr); AVSS.av14 = R32(&currptr); AVSS.av15 = R16(&currptr); AVSS.av16 = R16(&currptr); AVSS.av17 = R32(&currptr); AVSS.av18 = R16(&currptr); AVSS.av19 = R16(&currptr); AVSS.av20 = R32(&currptr); AVSS.av21 = R32(&currptr); AVSS.av22 = R32(&currptr); AVSS.av23 = R32(&currptr); AVSS.av24 = R16(&currptr); AVSS.av25 = R16(&currptr); AVSS.av26 = R32(&currptr); AVSS.av27 = R16(&currptr); AVSS.av28 = R16(&currptr); AVSS.av29 = R32(&currptr); AVSS.av30 = R32(&currptr); for (int i=0;i<32;i++) { AVSS.av31[i] = R8(&currptr); } dviprintf(" AVSS Header\n"); dviprintf(" Header ID %08x %c%c%c%c\n", AVSS.av1, (AVSS.av1>>24)&0xff, (AVSS.av1>>16)&0xff, (AVSS.av1>>8)&0xff, (AVSS.av1>>0)&0xff); dviprintf(" Header Size %04x\n", AVSS.av2); dviprintf(" Header Version %04x\n", AVSS.av3); dviprintf(" Stream Group Count %04x\n", AVSS.av4); dviprintf(" Stream Group Size %04x\n", AVSS.av5); dviprintf(" Stream Group Offs %08x\n", AVSS.av6); dviprintf(" Stream Group Vers %04x\n", AVSS.av7); dviprintf(" Stream Size %04x\n", AVSS.av8); dviprintf(" Stream Version %04x\n", AVSS.av9); dviprintf(" Stream Count %04x\n", AVSS.av10); dviprintf(" Stream Offset %08x\n", AVSS.av11); dviprintf(" Header Pool Offset %08x\n", AVSS.av12); dviprintf(" Label Count %08x\n", AVSS.av13); dviprintf(" Label Offset %08x\n", AVSS.av14); dviprintf(" Label Size %04x\n", AVSS.av15); dviprintf(" Label Version %04x\n", AVSS.av16); dviprintf(" Vid Seq Hdr Offset %08x\n", AVSS.av17); dviprintf(" Vid Seq Hdr Size %04x\n", AVSS.av18); dviprintf(" Frame Version %04x\n", AVSS.av19); dviprintf(" Frame Count %08x\n", AVSS.av20); dviprintf(" Frame Size %08x\n", AVSS.av21); dviprintf(" First Frame Offset %08x\n", AVSS.av22); dviprintf(" EO Frame Offset %08x\n", AVSS.av23); dviprintf(" Frame Header Size %04x\n", AVSS.av24); dviprintf(" Frame Dir Size %04x\n", AVSS.av25); dviprintf(" Frame Dir Offset %08x\n", AVSS.av26); dviprintf(" Frame Dir Vers %04x\n", AVSS.av27); dviprintf(" Frame PerSec %04x\n", AVSS.av28); dviprintf(" UpdateFlag %08x\n", AVSS.av29); dviprintf(" FreeBlock %08x\n", AVSS.av30); dviprintf(" Patch "); for (int i=0;i<32;i++) { dviprintf("%02x", AVSS.av31[i]); }; dviprintf("\n"); dviprintf("\n"); for (int s=0;s<AVSS.av10;s++) { STRM_Header STRM; STRM.st1 = R32(&currptr); STRM.st2 = R16(&currptr); STRM.st3 = R16(&currptr); STRM.st4 = R16(&currptr); STRM.st5 = R16(&currptr); STRM.st6 = R16(&currptr); STRM.st7 = R16(&currptr); STRM.st8 = R16(&currptr); STRM.st9 = R16(&currptr); STRM.st10 = R32(&currptr); STRM.st11 = R32(&currptr); for (int i=0;i<16;i++) { STRM.st12[i] = R8(&currptr); } dviprintf(" STRM Header\n"); dviprintf(" Header ID %08x %c%c%c%c\n", STRM.st1, (STRM.st1>>24)&0xff, (STRM.st1>>16)&0xff, (STRM.st1>>8)&0xff, (STRM.st1>>0)&0xff); dviprintf(" Header Size %04x\n", STRM.st2); dviprintf(" Type %04x\n", STRM.st3); dviprintf(" SubType %04x\n", STRM.st4); dviprintf(" Header Count %04x\n", STRM.st5); dviprintf(" Next Stream Number %04x\n", STRM.st6); dviprintf(" Stream Group Numbr %04x\n", STRM.st7); dviprintf(" Padding %04x\n", STRM.st8); dviprintf(" Flag %04x\n", STRM.st9); dviprintf(" FrameSize %08x\n", STRM.st10); dviprintf(" FirstHeaderOffset %08x\n", STRM.st11); dviprintf(" Name "); for (int i=0;i<16;i++) { dviprintf("%02x", STRM.st12[i]); }; dviprintf("\n"); dviprintf("\n"); UINT8* subptr = dvi_data+STRM.st11+baseoffset; for (int h=0;h<STRM.st5;h++) { // I believe in these can be either CIMG or AUDI blocks, but we don't have any of the latter CIMG_Header CIMG; CIMG.ci1 = R32(&subptr); CIMG.ci2 = R16(&subptr); CIMG.ci3 = R16(&subptr); for (int i=0;i<80;i++) { CIMG.ci4[i] = R8(&subptr); } CIMG.ci5 = R32(&subptr); CIMG.ci6 = R16(&subptr); CIMG.ci7 = R16(&subptr); CIMG.ci8 = R32(&subptr); CIMG.ci9 = R32(&subptr); CIMG.ci10 = R16(&subptr); CIMG.ci11 = R16(&subptr); CIMG.ci12 = R16(&subptr); CIMG.ci13 = R16(&subptr); CIMG.ci14 = R16(&subptr); CIMG.ci15 = R16(&subptr); CIMG.ci16 = R16(&subptr); CIMG.ci17 = R16(&subptr); CIMG.ci18 = R32(&subptr); CIMG.ci19 = R16(&subptr); CIMG.ci20 = R16(&subptr); CIMG.ci21 = R16(&subptr); CIMG.ci22 = R16(&subptr); CIMG.ci23 = R32(&subptr); dviprintf(" CIMG Header\n"); dviprintf(" Header ID %08x %c%c%c%c\n", CIMG.ci1, (CIMG.ci1>>24)&0xff, (CIMG.ci1>>16)&0xff, (CIMG.ci1>>8)&0xff, (CIMG.ci1>>0)&0xff); dviprintf(" Header Size %04x\n", CIMG.ci2); dviprintf(" Version %04x\n", CIMG.ci3); dviprintf(" Original Name "); for (int i=0;i<80;i++) { dviprintf("%02x", CIMG.ci4[i]); }; dviprintf("\n"); dviprintf(" Original Frame %08x\n", CIMG.ci5); dviprintf(" Original Stream %04x\n", CIMG.ci6); dviprintf(" Padding %04x\n", CIMG.ci7); dviprintf(" Frame Count %08x\n", CIMG.ci8); dviprintf(" Next Header Offset %08x\n", CIMG.ci9); dviprintf(" X Position %04x\n", CIMG.ci10); dviprintf(" Y Position %04x\n", CIMG.ci11); dviprintf(" X Length %04x\n", CIMG.ci12); dviprintf(" Y Length %04x\n", CIMG.ci13); dviprintf(" X Crop %04x\n", CIMG.ci14); dviprintf(" Y Crop %04x\n", CIMG.ci15); dviprintf(" Drop Frame %04x\n", CIMG.ci16); dviprintf(" Drop Phrase %04x\n", CIMG.ci17); dviprintf(" Still Period %08x\n", CIMG.ci18); dviprintf(" Buffer Minimum %04x\n", CIMG.ci19); dviprintf(" Buffer Maximum %04x\n", CIMG.ci20); dviprintf(" Decode Algorithm %04x\n", CIMG.ci21); dviprintf(" Padding(2) %04x\n", CIMG.ci22); dviprintf(" DCFID %08x\n", CIMG.ci23); dviprintf("\n"); subptr = dvi_data+CIMG.ci9+baseoffset; } } /* Frame Dictionaries etc. */ /* is this just a seek table of sorts? the first doesn't have an entry (pointed to by First Frame Offset - AVSS.av22) the first two here are actually bad values, and the last one points to nothing */ /* some entries also seem to point to the wrong places?? I'm guessing this isn't used when playing back the data ... it seems like the upper and lower words are out of sync... */ dviprintf("Frame Dictionaries\n\n"); UINT8* frameptr = dvi_data + AVSS.av26 + 2 + baseoffset; // +2 ?? // UINT8* frameptr = dvi_data + AVSS.av26 + baseoffset; for (int f=0;f<AVSS.av20;f++) { FDICT_Header FDICT; FDICT.fd1 = R32(&frameptr); FDICT.fd1 = ((FDICT.fd1 & 0xffff0000)>>16) | ((FDICT.fd1 & 0x0000ffff)<<16); dviprintf(" %04d Frame Offset %08x\n", f, FDICT.fd1); UINT8* frameptr2 = dvi_data + ((FDICT.fd1 + baseoffset)&(regionsize-1)) ; FHEAD_Header FHEAD; FHEAD.fh1 = R32(&frameptr2); FHEAD.fh2 = R32(&frameptr2); FHEAD.fh3 = R32(&frameptr2); dviprintf(" Frame Num %08x\n", FHEAD.fh1); dviprintf(" Previous Offset %08x\n", FHEAD.fh2); dviprintf(" Frame Checksum %08x\n", FHEAD.fh3); } dviprintf("\n"); }
//________________________________________________ // Beginning of the write process // We fill-in the headers // 3- Write audio headers // That one can be used several times so we pass stuff // as parameter //_______________________________________________ uint8_t aviWrite::writeAudioHeader ( AVDMGenericAudioStream * stream, AVIStreamHeader *header ) { WAVHeader *wav=NULL; // pre compute some headers with extra data in... uint8_t wmaheader[12]; VBRext mp3vbr; uint8_t *extra=NULL; uint32_t extraLen=0; if(!stream) return 1; memset(wmaheader,0,12); memset(&mp3vbr,0,sizeof(mp3vbr)); wmaheader[16-16]=0x0a; wmaheader[19-16]=0x08; wmaheader[22-16]=0x01; wmaheader[24-16]=0x74; wmaheader[25-16]=01; wav = stream->getInfo (); assert (wav); memset (header, 0, sizeof (AVIStreamHeader)); header->fccType = fourCC::get ((uint8_t *) "auds"); header->dwInitialFrames = 0; header->dwStart = 0; header->dwRate = wav->byterate; header->dwSampleSize = 1; header->dwQuality = 0xffffffff; header->dwSuggestedBufferSize = 8000; header->dwLength = stream->getLength (); switch(wav->encoding) { case WAV_MP3: // then update VBR fields mp3vbr.cbsize = R16(12); mp3vbr.wId = R16(1); mp3vbr.fdwflags = R32(2); mp3vbr.nframesperblock = R16(1); mp3vbr.ncodecdelay = 0; wav->bitspersample = 0; mp3vbr.nblocksize=R16(0x180); //383; // ?? header->dwScale = 1; header->dwInitialFrames = 1; if (wav->blockalign ==1152) // VBR audio { // We do like nandub do //assert (audiostream->asTimeTrack ()); wav->blockalign = 1152; // just a try wav->bitspersample = 16; header->dwRate = wav->frequency; //wav->byterate; header->dwScale = wav->blockalign; header->dwLength= _videostream.dwLength; header->dwSampleSize = 0; printf ("\n VBR audio detected\n"); // // use extended headers // // double nb; nb = stream->getLength (); nb/= _videostream.dwLength; // avg value of a block (i.e. a mpeg frame) mp3vbr.nblocksize = (uint32_t) floor (nb); mp3vbr.nblocksize = R16(mp3vbr.nblocksize); } else wav->blockalign=1; extra=(uint8_t *)&mp3vbr; extraLen=sizeof(mp3vbr); break; case WAV_WMA: header->dwScale = wav->blockalign; header->dwSampleSize = wav->blockalign; header->dwInitialFrames =1; header->dwSuggestedBufferSize=10*wav->blockalign; extra=(uint8_t *)&wmaheader; extraLen=12; break; default: header->dwScale = 1; wav->blockalign=1; break; } #ifdef ADM_BIG_ENDIAN // in case of Little endian, do the usual swap crap AVIStreamHeader as; WAVHeader w; memcpy(&as,header,sizeof(as)); Endian_AviStreamHeader(&as); memcpy(&w,wav,sizeof(w)); Endian_WavHeader( &w ); setStreamInfo (_out, (uint8_t *) &as, (uint8_t *)&w,sizeof(WAVHeader), extra,extraLen, 0x1000); #else setStreamInfo (_out, (uint8_t *) header, (uint8_t *) wav, sizeof (WAVHeader), extra,extraLen, 0x1000); #endif return 1; }