void Meter::UpdateDisplay(int numChannels, int numFrames, float *sampleData) { int i, j; float *sptr = sampleData; int num = intmin(numChannels, mNumBars); MeterUpdateMsg msg; msg.numFrames = numFrames; for(j=0; j<mNumBars; j++) { msg.peak[j] = 0; msg.rms[j] = 0; msg.clipping[j] = false; msg.headPeakCount[j] = 0; msg.tailPeakCount[j] = 0; } for(i=0; i<numFrames; i++) { for(j=0; j<num; j++) { msg.peak[j] = floatMax(msg.peak[j], sptr[j]); msg.rms[j] += sptr[j]*sptr[j]; // In addition to looking for mNumPeakSamplesToClip peaked // samples in a row, also send the number of peaked samples // at the head and tail, in case there's a run of // Send the number of peaked samples at the head and tail, // in case there's a run of peaked samples that crosses // block boundaries if (fabs(sptr[j])>=MAX_AUDIO) { if (msg.headPeakCount[j]==i) msg.headPeakCount[j]++; msg.tailPeakCount[j]++; if (msg.tailPeakCount[j] > mNumPeakSamplesToClip) msg.clipping[j] = true; } else msg.tailPeakCount[j] = 0; } sptr += numChannels; } for(j=0; j<mNumBars; j++) msg.rms[j] = sqrt(msg.rms[j]/numFrames); if (mDB) { for(j=0; j<mNumBars; j++) { msg.peak[j] = ToDB(msg.peak[j], mDBRange); msg.rms[j] = ToDB(msg.rms[j], mDBRange); } } mQueue.Put(msg); }
int SIMD_SUFFIX(mblocks_sub44_mests)( uint8_t *blk, uint8_t *ref, int ilow,int jlow, int ihigh, int jhigh, int h, int rowstride, int threshold, me_result_s *resvec) { int32_t x,y; uint8_t *currowblk = blk; uint8_t *curblk; me_result_s *cres = resvec; int gridrowstride = rowstride; int weight; SIMD_SUFFIX(init_qblock_sad)(ref, h, rowstride); for( y=jlow; y <= jhigh ; y+=4) { curblk = currowblk; // You'd think prefetching curblk+4*rowstride would help here. // I have found *NO* measurable increase in performance... for( x = ilow; x <= ihigh; x += 4) { if( (x & 15) == (ilow & 15) ) { load_blk( curblk, rowstride, h ); curblk += 4; } weight = SIMD_SUFFIX(qblock_sad)(ref, h, rowstride); shift_blk(8); if( weight <= threshold ) { threshold = intmin(weight<<2,threshold); /* Rough and-ready absolute distance penalty */ /* NOTE: This penalty is *vital* to correct operation as otherwise the sub-mean filtering won't work on very uniform images. */ cres->weight = (uint16_t)(weight+(intmax(abs(x),abs(y))<<2)); cres->x = (uint8_t)x; cres->y = (uint8_t)y; ++cres; } } currowblk += gridrowstride; } emms(); return cres - resvec; }
static void qmake_grid(void) { save_undo(); vs.use_grid = 0; if (gcut_out()) { vs.gridx = intmin(grid_x,firstx); vs.gridy = intmin(grid_y,firsty); if ((vs.gridw = intabs(grid_x - firstx)) <= 0) vs.gridw = 1; if ((vs.gridh = intabs(grid_y - firsty)) <= 0) vs.gridh = 1; while (vs.gridx >= 0) vs.gridx -= vs.gridw; vs.gridx += vs.gridw; while (vs.gridy >= 0) vs.gridy -= vs.gridh; vs.gridy += vs.gridh; vs.use_grid = 1; } qsee_grid(); grid_asterisks(); }
static void placer(unsigned char nb_sucre) { int i, j, a; /* Met les fourmis */ printf("Mise en place des fourmis...\n"); for (i=8;i<=11;i++) { for (j=8;j<=11;j++) { kor(i,j)->quoi = 'f'; } } /* Met le nid */ printf("Mise en place du nid...\n"); for (i=9;i<=10;i++) { for (j=9;j<=10;j++) { kor(i,j)->quoi = 'n'; } } /* insere la pheromone nid */ printf("Placement de la pheromone de nid...\n"); for (i=-10; i<=9; i++) { for (j=-10; j<=9; j++) { kor(i,j)->ph_nid = (float)intmin(abs(i<0?i+1:i),abs(j<0?j+1:j)) / 10.0; } } /* met le sucre */ printf("Mise en place du sucre...\n"); /* on place plusieurs morceaux de sucre au hasard */ a = rand() % 15 + 2; for (i=0; i<=3 ; i++) { for (j=0; j>=-1 ; j--) { kor(i+a,j)->quoi = 's'; kor(i+a,j)->sucre = nb_sucre; } } a = rand() % 15 + 2; for (i=0; i>=-1 ; i--) { for (j=0; j<=1 ; j++) { kor(i,j+a)->quoi = 's'; kor(i,j+a)->sucre = nb_sucre; } } }
/** write the data received from curl to the rapid pool. the filename is read from the sdp-list (created at request start) filesize is read from the http-data received (could overlap!) */ static size_t write_streamed_data(const void* tmp, size_t size, size_t nmemb,CSdp *sdp) { char buf[CURL_MAX_WRITE_SIZE]; memcpy(&buf,tmp,CURL_MAX_WRITE_SIZE); if (!sdp->downlooadInitialized){ sdp->list_it=sdp->globalFiles->begin(); sdp->downlooadInitialized=true; sdp->file_handle=NULL; sdp->file_name=""; sdp->skipped=0; } char* buf_start=(char*)&buf; const char* buf_end=buf_start + size*nmemb; char* buf_pos=buf_start; while (buf_pos<buf_end){ //all bytes written? if (sdp->file_handle==NULL){ //no open file, create one while ( (!(*sdp->list_it)->download==true) && (sdp->list_it!=sdp->globalFiles->end())){ //get file sdp->list_it++; } sdp->file_name=fileSystem->getPoolFileName(*sdp->list_it); sdp->file_handle=fopen(sdp->file_name.c_str(),"wb"); //FIXME sdp->setStatsPos(sdp->getStatsPos()+1); if (sdp->file_handle==NULL){ printf("couldn't open %s\n",(*sdp->list_it)->name.c_str()); return -1; } //here comes the init new file stuff sdp->file_pos=0; } if (sdp->file_handle!=NULL){ if ((sdp->skipped>0)&&(sdp->skipped<4)){ // printf("difficulty %d\n",skipped); } if (sdp->skipped<4){ // check if we skipped all 4 bytes, if not so, skip them int toskip=intmin(buf_end-buf_pos,LENGTH_SIZE-sdp->skipped); //calculate bytes we can skip, could overlap received bufs for (int i=0;i<toskip;i++) //copy bufs avaiable sdp->cursize_buf[i]=buf_pos[i]; // printf("toskip: %d skipped: %d\n",toskip,skipped); sdp->skipped=toskip+sdp->skipped; buf_pos=buf_pos+sdp->skipped; if (sdp->skipped==LENGTH_SIZE){ (*sdp->list_it)->compsize=parse_int32(sdp->cursize_buf); } } if (sdp->skipped==LENGTH_SIZE){ int towrite=intmin ((*sdp->list_it)->compsize-sdp->file_pos , //minimum of bytes to write left in file and bytes to write left in buf buf_end-buf_pos); // printf("%s %d %ld %ld %ld %d %d %d %d %d\n",file_name.c_str(), (*list_it)->compsize, buf_pos,buf_end, buf_start, towrite, size, nmemb , skipped, file_pos); int res=0; if (towrite>0){ res=fwrite(buf_pos,1,towrite,sdp->file_handle); if (res!=towrite){ printf("fwrite error\n"); return -1; } if (res<=0){ printf("\nwrote error: %d\n", res); return -1; } }else if (towrite<0){ DEBUG_LINE("%s","Fatal, something went wrong here!"); return -1; } buf_pos=buf_pos+res; sdp->file_pos+=res; if (sdp->file_pos>=(*sdp->list_it)->compsize){ //file finished -> next file fclose(sdp->file_handle); if (!fileSystem->fileIsValid(*sdp->list_it,sdp->file_name.c_str())){ printf("File is broken?!: %s\n",sdp->file_name.c_str()); return -1; } sdp->file_handle=NULL; sdp->list_it++; sdp->file_pos=0; sdp->skipped=0; } } } } return buf_pos-buf_start; }
void Meter::HandleLayout() { int iconWidth = mIcon->GetWidth(); int iconHeight = mIcon->GetHeight(); int menuWidth = 17; int menuHeight = 14; int width = mWidth; int height = mHeight; int left = 0, top = 0; int right, bottom; int barw, barh; int i; mRuler.SetFlip(true); mRuler.SetLabelEdges(true); switch(mStyle) { default: wxPrintf(wxT("Style not handled yet!\n")); break; case VerticalStereo: #if WANT_METER_MENU mMenuRect = wxRect(mWidth - menuWidth - 5, mHeight - menuHeight - 2, menuWidth, menuHeight); if (mHeight < (menuHeight + iconHeight + 8)) mIconPos = wxPoint(-999, -999); // Don't display else #endif // WANT_METER_MENU mIconPos = wxPoint(mWidth - iconWidth - 1, 1); width = intmin(mWidth-(iconWidth+2), mWidth-(menuWidth+3)); if (width >= mLeftSize.x + mRightSize.x + 24) { mLeftTextPos = wxPoint(2, height-2-mLeftSize.y); mRightTextPos = wxPoint(width-mLeftSize.x, height-2-mLeftSize.y); left += mLeftSize.x+4; width -= mLeftSize.x + mRightSize.x + 8; } barw = (width-2)/2; barh = height - 4; mNumBars = 2; mBar[0].vert = true; ResetBar(&mBar[0], false); mBar[0].r = wxRect(left + width/2 - barw - 1, 2, barw, barh); if (mClip) { mBar[0].rClip = mBar[0].r; mBar[0].rClip.height = 3; mBar[0].r.y += 4; mBar[0].r.height -= 4; } mBar[1].vert = true; ResetBar(&mBar[1], false); mBar[1].r = wxRect(left + width/2 + 1, 2, barw, barh); if (mClip) { mBar[1].rClip = mBar[1].r; mBar[1].rClip.height = 3; mBar[1].r.y += 4; mBar[1].r.height -= 4; } mRuler.SetOrientation(wxVERTICAL); mRuler.SetBounds(mBar[1].r.x + mBar[1].r.width + 1, mBar[1].r.y, mBar[1].r.x + width, mBar[1].r.y + mBar[1].r.height); if (mDB) { mRuler.SetRange(0, -mDBRange); mRuler.SetFormat(Ruler::LinearDBFormat); } else { mRuler.SetRange(1, 0); mRuler.SetFormat(Ruler::RealFormat); } #if WANT_METER_MENU mRuler.OfflimitsPixels(mMenuRect.y-mBar[1].r.y, mBar[1].r.height); #endif // WANT_METER_MENU break; case HorizontalStereo: if (mWidth < menuWidth + iconWidth + 8) { mIconPos = wxPoint(-999, -999); // Don't display icon #if WANT_METER_MENU mMenuRect = wxRect(2, mHeight - menuHeight - 2, menuWidth, menuHeight); #endif // WANT_METER_MENU } else { mIconPos = wxPoint(2, mHeight - iconHeight); #if WANT_METER_MENU mMenuRect = wxRect(iconWidth + 2, mHeight - menuHeight - 5, menuWidth, menuHeight); #endif // WANT_METER_MENU } height = intmin(height-(menuHeight+3), height-iconHeight) - 2; left = 2 + intmax(mLeftSize.x, mRightSize.x); width -= left; mLeftTextPos = wxPoint(2, (height)/4 - mLeftSize.y/2); mRightTextPos = wxPoint(2, (height*3)/4 - mLeftSize.y/2); barw = width - 4; barh = (height-2)/2; mNumBars = 2; mBar[0].vert = false; ResetBar(&mBar[0], false); mBar[0].r = wxRect(left+2, height/2 - barh - 1, barw, barh); if (mClip) { mBar[0].rClip = mBar[0].r; mBar[0].rClip.x += mBar[0].rClip.width-3; mBar[0].rClip.width = 3; mBar[0].r.width -= 4; } mBar[1].vert = false; ResetBar(&mBar[1], false); mBar[1].r = wxRect(left+2, height/2 + 1, barw, barh); if (mClip) { mBar[1].rClip = mBar[1].r; mBar[1].rClip.x += mBar[1].rClip.width-3; mBar[1].rClip.width = 3; mBar[1].r.width -= 4; } mRuler.SetOrientation(wxHORIZONTAL); mRuler.SetBounds(mBar[1].r.x, mBar[1].r.y + mBar[1].r.height + 1, mBar[1].r.x + mBar[1].r.width, mWidth); if (mDB) { mRuler.SetRange(-mDBRange, 0); mRuler.SetFormat(Ruler::LinearDBFormat); } else { mRuler.SetRange(0, 1); mRuler.SetFormat(Ruler::RealFormat); } #if WANT_METER_MENU mRuler.OfflimitsPixels(0, mMenuRect.x+mMenuRect.width-4); #endif // WANT_METER_MENU break; case Waveform: mNumBars = 0; break; } if (mNumBars > 0) { // Compute bounding rectangle of all bars (to save time when // blitting just the bars to the screen) left = mBar[0].r.x; top = mBar[0].r.y; right = mBar[0].r.x + mBar[0].r.width; bottom = mBar[0].r.y + mBar[0].r.height; for(i=1; i<mNumBars; i++) { left = intmin(left, mBar[i].r.x); top = intmin(top, mBar[i].r.y); right = intmax(right, mBar[i].r.x + mBar[i].r.width); bottom = intmax(bottom, mBar[i].r.y + mBar[i].r.height); left = intmin(left, mBar[i].rClip.x); top = intmin(top, mBar[i].rClip.y); right = intmax(right, mBar[i].rClip.x + mBar[i].rClip.width); bottom = intmax(bottom, mBar[i].rClip.y + mBar[i].rClip.height); } mAllBarsRect = wxRect(left, top, right-left+1, bottom-top+1); } CreateIcon(mIconPos.y % 4); mLayoutValid = true; }
/** write the data received from curl to the rapid pool. the filename is read from the sdp-list (created at request start) filesize is read from the http-data received (could overlap!) */ static size_t write_streamed_data(const void* tmp, size_t size, size_t nmemb,CSdp *sdp) { char buf[CURL_MAX_WRITE_SIZE]; memcpy(&buf,tmp,CURL_MAX_WRITE_SIZE); if (!sdp->downloadInitialized) { sdp->list_it=sdp->globalFiles->begin(); sdp->downloadInitialized=true; sdp->file_handle=NULL; sdp->file_name=""; sdp->skipped=0; } char* buf_start=(char*)&buf; const char* buf_end=buf_start + size*nmemb; char* buf_pos=buf_start; while (buf_pos<buf_end) { //all bytes written? if (sdp->file_handle==NULL) { //no open file, create one while ( (!(*sdp->list_it)->download==true) && (sdp->list_it!=sdp->globalFiles->end())) { //get file sdp->list_it++; } HashMD5 md5; md5.Set((*sdp->list_it)->md5, sizeof((*sdp->list_it)->md5)); fileSystem->getPoolFilename(md5.toString(), sdp->file_name); sdp->file_handle=new AtomicFile(sdp->file_name); // LOG_DEBUG("opened %s, size: %d", sdp->file_name.c_str(), (*sdp->list_it)->size); //FIXME sdp->setStatsPos(sdp->getStatsPos()+1); if (sdp->file_handle==NULL) { LOG_ERROR("couldn't open %s",(*sdp->list_it)->name.c_str()); return -1; } //here comes the init new file stuff sdp->file_pos=0; } if (sdp->file_handle!=NULL) { if (sdp->skipped<LENGTH_SIZE) { // check if we skipped all 4 bytes, if not so, skip them int toskip=intmin(buf_end-buf_pos,LENGTH_SIZE-sdp->skipped); //calculate bytes we can skip, could overlap received bufs for (int i=0; i<toskip; i++) { //copy bufs avaiable sdp->cursize_buf[sdp->skipped+i]=buf_pos[i]; // if (sdp->skipped>0) { // LOG_DEBUG("copy %d to %d ", i, sdp->skipped+i); // } } // LOG_DEBUG("toskip: %d skipped: %d",toskip,sdp->skipped); sdp->skipped=toskip+sdp->skipped; buf_pos=buf_pos+toskip; if (sdp->skipped==LENGTH_SIZE) { (*sdp->list_it)->compsize=parse_int32(sdp->cursize_buf); // LOG_DEBUG("%s %hhu %hhu %hhu %hhu", sdp->file_name.c_str(), sdp->cursize_buf[0], sdp->cursize_buf[1], sdp->cursize_buf[2], sdp->cursize_buf[3]); // LOG_DEBUG("(data read from sdp)uncompressed size: %d (data read from net)compressed size: %d", (*sdp->list_it)->size, (*sdp->list_it)->compsize); assert((*sdp->list_it)->size+2000 >= (*sdp->list_it)->compsize); } } if (sdp->skipped==LENGTH_SIZE) { int towrite=intmin ((*sdp->list_it)->compsize-sdp->file_pos , //minimum of bytes to write left in file and bytes to write left in buf buf_end-buf_pos); // LOG_DEBUG("%s %d %ld %ld %ld %d %d %d %d %d",sdp->file_name.c_str(), (*sdp->list_it).compsize, buf_pos,buf_end, buf_start, towrite, size, nmemb , sdp->skipped, sdp->file_pos); int res=0; if (towrite>0) { res=sdp->file_handle->Write(buf_pos,towrite); if (res!=towrite) { LOG_ERROR("fwrite error"); return -1; } if (res<=0) { LOG_ERROR("wrote error: %d", res); return -1; } } else if (towrite<0) { LOG_DEBUG("Fatal, something went wrong here! %d", towrite); return -1; } buf_pos=buf_pos+res; sdp->file_pos+=res; if (sdp->file_pos>=(*sdp->list_it)->compsize) { //file finished -> next file sdp->file_handle->Close(); delete sdp->file_handle; sdp->file_handle = NULL; if (!fileSystem->fileIsValid(*sdp->list_it,sdp->file_name.c_str())) { LOG_ERROR("File is broken?!: %s",sdp->file_name.c_str()); remove(sdp->file_name.c_str()); return -1; } sdp->file_handle=NULL; sdp->list_it++; sdp->file_pos=0; sdp->skipped=0; } } } } return buf_pos-buf_start; }