//清屏 void CleanLCD() { unsigned int i =0; unsigned int j=0; // timer(4); for(j=0;j<8;j++) { LCD_LED= ~LCD_LED; wlc(0xb0+j);//1011 0000 //1011 0001 wlc(0x00);//0000 0000 //0000 0000 wlc(0x10);//0001 0000 //0001 0000 wlc(0x40);//0100 0000 //0100 0000 for(i=0;i < 128+4;i++) { wld(0x00); } } // CS = 1; // timer(1); // CS = 0; for(j=0;j<8;j++) { LCD_LED= ~LCD_LED; wlc(0xb0+j);//1011 0000 //1011 0111 wlc(0x04);//0000 0100 wlc(0x10);//0001 0000 wlc(0x40);//0100 0000 for(i=0;i < 128+4;i++) { wld(0x01); } } SDAT = SCLK =CD =LCD_LED =0; // CS = 1; while(1); }
//清屏 void CleanLCD(unsigned char dat) { unsigned int i =0; unsigned int j=0; for(j=0;j<8;j++) { LCD_LED= ~LCD_LED; wlc(0xb0+j);//1011 0000 1011 0111 wlc(0x10); //0001 0000 wlc(0x00); //0000 0000 for(i=0;i < 128+0;i++) { wld(dat); } } // wlc(0xe3); }
Move com_move(Board* b, int max_depth, int time_ms) { Move move; int score = 100; quiet = true; move = opening_move(b); if (move == INVALID_MOVE) { SearchResult r; if (b->turn() < 25) r = search_negascout(b, max_depth, time_ms / 2, time_ms); else if (b->turn() < 27) r = wld(b, 1000); else r = perfect(b); move = r.first; score = r.second; } return move; }
bool GdalAdapter::loadImage(const QString& fn) { if (alreadyLoaded(fn)) return true; QFileInfo fi(fn); GdalImage img; QRectF bbox; poDataset = (GDALDataset *) GDALOpen( QDir::toNativeSeparators(fi.absoluteFilePath()).toUtf8().constData(), GA_ReadOnly ); if( poDataset == NULL ) { qDebug() << "GDAL Open failed: " << fn; return false; } bool hasGeo = false; QDir dir(fi.absoluteDir()); QString f = fi.baseName(); QStringList wldFilter; wldFilter << f+".tfw" << f+".tifw" << f+".tiffw" << f+".wld"; QFileInfoList fil = dir.entryInfoList(wldFilter); if (fil.count()) { QFile wld(fil[0].absoluteFilePath()); if (wld.open(QIODevice::ReadOnly)) { int i; for (i=0; i<6; ++i) { if (wld.atEnd()) break; QString l = wld.readLine(); bool ok; double d = l.toDouble(&ok); if (!ok) break; switch (i) { case 0: img.adfGeoTransform[1] = d; break; case 1: img.adfGeoTransform[4] = d; break; case 2: img.adfGeoTransform[2] = d; break; case 3: img.adfGeoTransform[5] = d; break; case 4: img.adfGeoTransform[0] = d; break; case 5: img.adfGeoTransform[3] = d; break; } } if (i == 6) hasGeo = true; } } if(!hasGeo) if ( poDataset->GetGeoTransform( img.adfGeoTransform ) != CE_None ) { GDALClose((GDALDatasetH)poDataset); return false; } qDebug( "Origin = (%.6f,%.6f)\n", img.adfGeoTransform[0], img.adfGeoTransform[3] ); qDebug( "Pixel Size = (%.6f,%.6f)\n", img.adfGeoTransform[1], img.adfGeoTransform[5] ); bbox.setTopLeft(QPointF(img.adfGeoTransform[0], img.adfGeoTransform[3])); bbox.setWidth(img.adfGeoTransform[1]*poDataset->GetRasterXSize()); bbox.setHeight(img.adfGeoTransform[5]*poDataset->GetRasterYSize()); isLatLon = false; if( strlen(poDataset->GetProjectionRef()) != 0 ) { qDebug( "Projection is `%s'\n", poDataset->GetProjectionRef() ); OGRSpatialReference* theSrs = new OGRSpatialReference(poDataset->GetProjectionRef()); if (theSrs && theSrs->Validate() == OGRERR_NONE) { theSrs->morphFromESRI(); char* theProj4; if (theSrs->exportToProj4(&theProj4) == OGRERR_NONE) { qDebug() << "GDAL: to proj4 : " << theProj4; } else { qDebug() << "GDAL: to proj4 error: " << CPLGetLastErrorMsg(); GDALClose((GDALDatasetH)poDataset); return false; } QString srsProj = QString(theProj4); if (!srsProj.isEmpty() && theProjection != srsProj) { cleanup(); theProjection = srsProj; } isLatLon = (theSrs->IsGeographic() == TRUE); } } if (theProjection.isEmpty()) { theProjection = ProjectionChooser::getProjection(QCoreApplication::translate("ImportExportGdal", "Unable to set projection; please specify one")); if (theProjection.isEmpty()) { GDALClose((GDALDatasetH)poDataset); return false; } } qDebug( "Driver: %s/%s\n", poDataset->GetDriver()->GetDescription(), poDataset->GetDriver()->GetMetadataItem( GDAL_DMD_LONGNAME ) ); qDebug( "Size is %dx%dx%d\n", poDataset->GetRasterXSize(), poDataset->GetRasterYSize(), poDataset->GetRasterCount() ); GdalAdapter::ImgType theType = GdalAdapter::Unknown; int bandCount = poDataset->GetRasterCount(); int ixA = -1; int ixR, ixG, ixB; int ixH, ixS, ixL; int ixC, ixM, ixY, ixK; int ixYuvY, ixYuvU, ixYuvV; double adfMinMax[2]; double UnknownUnit; GDALColorTable* colTable = NULL; for (int i=0; i<bandCount; ++i) { GDALRasterBand *poBand = poDataset->GetRasterBand( i+1 ); GDALColorInterp bandtype = poBand->GetColorInterpretation(); qDebug() << "Band " << i+1 << " Color: " << GDALGetColorInterpretationName(poBand->GetColorInterpretation()); switch (bandtype) { case GCI_Undefined: theType = GdalAdapter::Unknown; int bGotMin, bGotMax; adfMinMax[0] = poBand->GetMinimum( &bGotMin ); adfMinMax[1] = poBand->GetMaximum( &bGotMax ); if( ! (bGotMin && bGotMax) ) GDALComputeRasterMinMax((GDALRasterBandH)poBand, TRUE, adfMinMax); UnknownUnit = (adfMinMax[1] - adfMinMax[0]) / 256; break; case GCI_GrayIndex: theType = GdalAdapter::GrayScale; break; case GCI_RedBand: theType = GdalAdapter::Rgb; ixR = i; break; case GCI_GreenBand: theType = GdalAdapter::Rgb; ixG = i; break; case GCI_BlueBand : theType = GdalAdapter::Rgb; ixB = i; break; case GCI_HueBand: theType = GdalAdapter::Hsl; ixH = i; break; case GCI_SaturationBand: theType = GdalAdapter::Hsl; ixS = i; break; case GCI_LightnessBand: theType = GdalAdapter::Hsl; ixL = i; break; case GCI_CyanBand: theType = GdalAdapter::Cmyk; ixC = i; break; case GCI_MagentaBand: theType = GdalAdapter::Cmyk; ixM = i; break; case GCI_YellowBand: theType = GdalAdapter::Cmyk; ixY = i; break; case GCI_BlackBand: theType = GdalAdapter::Cmyk; ixK = i; break; case GCI_YCbCr_YBand: theType = GdalAdapter::YUV; ixYuvY = i; break; case GCI_YCbCr_CbBand: theType = GdalAdapter::YUV; ixYuvU = i; break; case GCI_YCbCr_CrBand: theType = GdalAdapter::YUV; ixYuvV = i; break; case GCI_AlphaBand: ixA = i; break; case GCI_PaletteIndex: colTable = poBand->GetColorTable(); switch (colTable->GetPaletteInterpretation()) { case GPI_Gray : theType = GdalAdapter::Palette_Gray; break; case GPI_RGB : theType = GdalAdapter::Palette_RGBA; break; case GPI_CMYK : theType = GdalAdapter::Palette_CMYK; break; case GPI_HLS : theType = GdalAdapter::Palette_HLS; break; } break; } } QSize theImgSize(poDataset->GetRasterXSize(), poDataset->GetRasterYSize()); QImage theImg = QImage(theImgSize, QImage::Format_ARGB32); // Make sure that lineBuf holds one whole line of data. float *lineBuf; lineBuf = (float *) CPLMalloc(theImgSize.width() * bandCount * sizeof(float)); int px, py; //every row loop for (int row = 0; row < theImgSize.height(); row++) { py = row; poDataset->RasterIO( GF_Read, 0, row, theImgSize.width(), 1, lineBuf, theImgSize.width(), 1, GDT_Float32, bandCount, NULL, sizeof(float) * bandCount, 0, sizeof(float) ); // every pixel in row. for (int col = 0; col < theImgSize.width(); col++){ px = col; switch (theType) { case GdalAdapter::Unknown: { float* v = lineBuf + (col*bandCount); float val = (*v - adfMinMax[0]) / UnknownUnit; theImg.setPixel(px, py, qRgb(val, val, val)); break; } case GdalAdapter::GrayScale: { float* v = lineBuf + (col*bandCount); theImg.setPixel(px, py, qRgb(*v, *v, *v)); break; } case GdalAdapter::Rgb: { float* r = lineBuf + (col*bandCount) + ixR; float* g = lineBuf + (col*bandCount) + ixG; float* b = lineBuf + (col*bandCount) + ixB; int a = 255; if (ixA != -1) { float* fa = lineBuf + (col*bandCount) + ixA; a = *fa; } theImg.setPixel(px, py, qRgba(*r, *g, *b, a)); break; } #if QT_VERSION >= 0x040600 case GdalAdapter::Hsl: { float* h = lineBuf + (col*bandCount) + ixH; float* s = lineBuf + (col*bandCount) + ixS; float* l = lineBuf + (col*bandCount) + ixL; int a = 255; if (ixA != -1) { float* fa = lineBuf + (col*bandCount) + ixA; a = *fa; } QColor C = QColor::fromHsl(*h, *s, *l, a); theImg.setPixel(px, py, C.rgba()); break; } #endif case GdalAdapter::Cmyk: { float* c = lineBuf + (col*bandCount) + ixC; float* m = lineBuf + (col*bandCount) + ixM; float* y = lineBuf + (col*bandCount) + ixY; float* k = lineBuf + (col*bandCount) + ixK; int a = 255; if (ixA != -1) { float* fa = lineBuf + (col*bandCount) + ixA; a = *fa; } QColor C = QColor::fromCmyk(*c, *m, *y, *k, a); theImg.setPixel(px, py, C.rgba()); break; } case GdalAdapter::YUV: { // From http://www.fourcc.org/fccyvrgb.php float* y = lineBuf + (col*bandCount) + ixYuvY; float* u = lineBuf + (col*bandCount) + ixYuvU; float* v = lineBuf + (col*bandCount) + ixYuvV; int a = 255; if (ixA != -1) { float* fa = lineBuf + (col*bandCount) + ixA; a = *fa; } float R = 1.164*(*y - 16) + 1.596*(*v - 128); float G = 1.164*(*y - 16) - 0.813*(*v - 128) - 0.391*(*u - 128); float B = 1.164*(*y - 16) + 2.018*(*u - 128); theImg.setPixel(px, py, qRgba(R, G, B, a)); break; } case GdalAdapter::Palette_Gray: { float* ix = (lineBuf + (col*bandCount)); const GDALColorEntry* color = colTable->GetColorEntry(*ix); theImg.setPixel(px, py, qRgb(color->c1, color->c1, color->c1)); break; } case GdalAdapter::Palette_RGBA: { float* ix = (lineBuf + (col*bandCount)); const GDALColorEntry* color = colTable->GetColorEntry(*ix); theImg.setPixel(px, py, qRgba(color->c1, color->c2, color->c3, color->c4)); break; } #if QT_VERSION >= 0x040600 case GdalAdapter::Palette_HLS: { float* ix = (lineBuf + (col*bandCount)); const GDALColorEntry* color = colTable->GetColorEntry(*ix); QColor C = QColor::fromHsl(color->c1, color->c2, color->c3, color->c4); theImg.setPixel(px, py, C.rgba()); break; } #endif case GdalAdapter::Palette_CMYK: { float* ix = (lineBuf + (col*bandCount)); const GDALColorEntry* color = colTable->GetColorEntry(*ix); QColor C = QColor::fromCmyk(color->c1, color->c2, color->c3, color->c4); theImg.setPixel(px, py, C.rgba()); break; } } } QCoreApplication::processEvents(); } img.theFilename = fn; img.theImg = QPixmap::fromImage(theImg); theImages.push_back(img); theBbox = theBbox.united(bbox); GDALClose((GDALDatasetH)poDataset); return true; }
main(int argc, char *argv[]) { FILE *fp; int fd,arg; snd_pcm_t *handle; snd_pcm_hw_params_t *hw_params; int rate=8000; float f[WINDOW],hann[WINDOW],w[WINDOW],w2[WINDOW],s0,s1=0,tot; float ac[ORDER+1],lcp[ORDER+1],lsp[ORDER],l[ORDER],weight[ORDER],delta,d; short sample,s[160],buf[2000]; int i,j,n,b,toggle=1; float e,laste=0; int ebit=ETOPBIT, ebuff=0; int sound=0; // boolean start/stop float f2[FFT],min; float real[FFT],imag[FFT]; int dummy[100000]; float amp[WINDOW],pha[WINDOW]; int frame=0; SpeexPreprocessState *st; for (i=0; i<8; i++) report[i]=0; st = speex_preprocess_state_init(160, 8000); i=1; speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DENOISE, &i); // i=1; // speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DEREVERB, &i); // e=.0; // speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DEREVERB_DECAY, &e); // e=.0; // speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &e); setup_twiddles(realtwiddle,imtwiddle,FFT); for (i=0; i<WINDOW; i++) f[i]=0; for (i=0; i<ORDER; i++) {last[i]=0; last2[i]=0;} for(i=0; i<WINDOW; i++) hann[i]=0.5-0.5*cos(2.0*M_PI*i/(WINDOW-1)); if (argc==2) training=atoi(argv[1]); fprintf(stderr,"training=%i\n",training); // exit(0); cbsize=0; start[0]=0; size[0]=0; if (training==0) if (fp=fopen("cb.txt","r")) { while(!feof(fp)) { fscanf(fp,"%i\n",&size[cbsize]); for (i=start[cbsize]; i<start[cbsize]+size[cbsize]; i++) { for (n=1; n<FF2-1; n++) fscanf(fp,"%f,",&cb[i][n]); fscanf(fp,"\n"); } start[cbsize+1]=start[cbsize]+size[cbsize]; cbsize++; } fclose(fp); } //for (i=0; i<cbsize; i++) printf("%i,\n",size[i]); exit(0); //--------------------------------- fp=fopen("/tmp/b.raw","w"); snd_pcm_open(&handle, "default", SND_PCM_STREAM_CAPTURE, 0); snd_pcm_hw_params_malloc(&hw_params); snd_pcm_hw_params_any(handle, hw_params); snd_pcm_hw_params_set_access(handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED); snd_pcm_hw_params_set_format(handle, hw_params, SND_PCM_FORMAT_S16_LE); snd_pcm_hw_params_set_rate_near(handle, hw_params, &rate, 0); snd_pcm_hw_params_set_channels(handle, hw_params, 2); snd_pcm_hw_params(handle, hw_params); snd_pcm_hw_params_free(hw_params); snd_pcm_prepare(handle); //printf("sleep 1...\n"); sleep(1); printf("OK, go....\n"); while(1) { for (i=0; i<WINDOW-STEP; i++) f[i]=f[i+STEP]; // shift samples down if (toggle) { //read(fd,s,160*2); snd_pcm_readi(handle, buf, 160); for (i=0; i<160; i++) s[i]=buf[i*2]; speex_preprocess_run(st, s); } else bcopy(&s[80],s,80*2); toggle=!toggle; for (i=WINDOW-STEP,j=0; i<WINDOW; i++,j++) { sample=s[j]; s0=(float)sample; f[i]=s0-s1*EMPH; s1=s0; // 1.0 pre-emphasis fwrite(&sample,2,1,fp); } for (i=0; i<WINDOW; i++) w[i]=f[i]; // remove any DC level.... tot=0; for (i=0; i<WINDOW; i++) tot+=w[i]; tot/=WINDOW; for (i=0; i<WINDOW; i++) w[i]-=tot; for (i=0; i<WINDOW; i++) w[i]*=hann[i]; // window data autocorrelate(w,ac,WINDOW,ORDER); wld(&lpc[1],ac,ORDER); lpc[0]=1.0; // e=ac[0]; e=0;for(i=0; i<=ORDER; i++) e+=ac[i]*lpc[i]; if (e<0) e=0; if (e>TOL_OFF) ebuff|=ebit; else ebuff&=~ebit; // update energy bit-buffer ebit>>=1; if (ebit==0) ebit=ETOPBIT; // circular shift for (i=0; i<FFT; i++) {real[i]=0; imag[i]=0;} for (i=0; i<=ORDER; i++) real[i]=lpc[i]; simple_fft(real,imag,realtwiddle,imtwiddle,FFT); for (i=0; i<FF2; i++) { b=bin[i]; f2[i]=powf(real[b]*real[b]+imag[b]*imag[b],-0.5); //f2[i]=powf(f2[i],0.333333); //f2[i]=powf(f2[i],1.2); f2[i]=logf(f2[i]); } // spectral tilt compensation... for (i=1; i<FF2; i++) f2[i]=f2[i]*(float)(i+TILT)/TILT; // fold down to 9 bins... /* if (f2[FF2-2]>f2[FF2-3]) f2[FF2-3]=f2[FF2-2]; f2[FF2-2]=0; if (f2[FF2-4]>f2[FF2-5]) f2[FF2-5]=f2[FF2-4]; f2[FF2-4]=0; if (f2[FF2-9]>f2[FF2-10]) f2[FF2-10]=f2[FF2-9]; f2[FF2-9]=0; if (f2[FF2-11]>f2[FF2-12]) f2[FF2-12]=f2[FF2-11]; f2[FF2-11]=0; if (f2[FF2-13]>f2[FF2-14]) f2[FF2-14]=f2[FF2-13]; f2[FF2-13]=0; if (f2[FF2-15]>f2[FF2-16]) f2[FF2-16]=f2[FF2-15]; f2[FF2-15]=0; */ for (i=0; i<FF2; i++) { if (f2[i]>6.0) f2[i]=6.0; f2[i]*=100.0; } if (TRACE) { fprintf(stderr,"%.f,",e); for (i=1; i<FF2-1; i++) fprintf(stderr,"%.f,",f2[i]); fprintf(stderr,"\n");} // calculate frame delta.... delta=0; for (i=1; i<FF2-1; i++) {d=f2[i]-last[i]; delta+=d*d;} //printf("delta=%f\n",delta); if (sound==0 && e>TOL_ON && frame>200) { // start recording... bcopy(last2,&word[wsize],FF2*4); wsize++; bcopy(last,&word[wsize],FF2*4); wsize++; sound=1; wsize=0; bcopy(f2,&word[wsize],FF2*4); wsize++; bcopy(last,last2,FF2*4); bcopy(f2,last,FF2*4); } else if (sound==1 && e>TOL_OFF) { // continue reading word... bcopy(f2,&word[wsize],FF2*4); wsize++; if (wsize>200) wsize=200; bcopy(last,last2,FF2*4); bcopy(f2,last,FF2*4); } else if (sound==1 && ebuff==0) { // finised reading word // wsize-=8; // remove training silence (2 frame buffer) if (wsize>4 && wsize<50) { if (training>0) train(); else closest(); } sound=0; wsize=0; bcopy(last,last2,FF2*4); bcopy(f2,last,FF2*4); } //for (i=1; i<FF2-1; i++) printf("%.0f,",f2[i]); printf(" e=%f\n",e); laste=e; frame++; if (frame==37800) exit(0); } }