void WorleyNoise::noise1D(float at, long maxOrder, float *F, float(*delta), unsigned long *ID) { float x2, mx2; float newAt; long intAt, i; // Initialize the F values to "huge" so they will be replaced by the // first real sample tests. Note we'll be storing and comparing the // SQUARED distance from the feature points to avoid lots of slow // sqrt() calls. We'll use sqrt() only on the final answer. for (i = 0; i < maxOrder; i++) F[i] = 999999.9; // Make our own local copy, multiplying to make mean(F[0])==1.0 newAt = DENSITY_ADJUSTMENT * at; // Find the integer cube holding the hit point intAt = int(floor(newAt)); // A simple way to compute the closest neighbors would be to test all // boundary cubes exhaustively. This is simple with code like: // { // long ii, jj, kk; // for (ii=-1; ii<=1; ii++) // addSamples(intAt+ii, maxOrder, newAt, F, delta, ID); // } // But this wastes a lot of time working on cubes which are known to be // too far away to matter! So we can use a more complex testing method // that avoids this needless testing of distant cubes. This doubles the // speed of the algorithm. // Test the central cube for closest point(s). addSamples(intAt, maxOrder, newAt, F, delta, ID); // We test if neighbor cubes are even POSSIBLE contributors by examining the // combinations of the sum of the squared distances from the cube's lower // or upper corners. x2 = newAt - intAt; mx2 = (1.0f - x2) * (1.0f - x2); x2 *= x2; // Test 2 facing neighbors of center cube. if (x2 < F[maxOrder-1]) addSamples(intAt - 1, maxOrder, newAt, F, delta, ID); if (mx2 < F[maxOrder-1]) addSamples(intAt + 1, maxOrder, newAt, F, delta, ID); // We're done! Convert everything to right size scale for (i = 0; i < maxOrder; i++) { F[i] = sqrt(F[i]) * (1.0 / DENSITY_ADJUSTMENT); delta[i] *= (1.0 / DENSITY_ADJUSTMENT); } }
bool OscilloscopeChannel::addSample ( uint8_t value , t_TimeStamp startTimeStamp ) { if ( SamplesType != Original_UINT8 ) return false ; return addSamples ( (void*)&value,1,startTimeStamp) ; }
u16 generateAudioSample(void) { u16 mix_sample = 1; u16 osc1_sample = 1; u16 osc2_sample = 1; u16 noise_sample = 0; OSC1.Env.compteur++; osc1_sample = processOSC(&OSC1); osc1_sample = generateur_enveloppe(osc1_sample, &OSC1.Env); osc1_sample = multiplySample(osc1_sample, cur_preset.MIX_VCO1, 100); OSC2.Env.compteur++; osc2_sample = processOSC(&OSC2); osc2_sample = generateur_enveloppe(osc2_sample, &OSC2.Env); osc2_sample = multiplySample(osc2_sample, cur_preset.MIX_VCO2, 100); // noise_sample = processNoise(); mix_sample = addSamples(osc1_sample, osc2_sample); if (!mix_sample) mix_sample = 1; return (mix_sample); }
void decoder_progress(DecoderProgress dp, const mp3data_struct * mp3data, int iread) { addSamples(dp, iread); console_printf("\rFrame#%6i/%-6i %3i kbps", dp->frame_ctr, dp->frames_total, mp3data->bitrate); /* Programmed with a single frame hold delay */ /* Attention: static data */ /* MP2 Playback is still buggy. */ /* "'00' subbands 4-31 in intensity_stereo, bound==4" */ /* is this really intensity_stereo or is it MS stereo? */ if (mp3data->mode == JOINT_STEREO) { int curr = mp3data->mode_ext; int last = dp->last_mode_ext; console_printf(" %s %c", curr & 2 ? last & 2 ? " MS " : "LMSR" : last & 2 ? "LMSR" : "L R", curr & 1 ? last & 1 ? 'I' : 'i' : last & 1 ? 'i' : ' '); dp->last_mode_ext = curr; } else { console_printf(" "); dp->last_mode_ext = 0; } /* console_printf ("%s", Console_IO.str_clreoln ); */ console_printf(" \b\b\b\b\b\b\b\b"); console_flush(); }
bool OscilloscopeChannel::addSample ( float value , t_TimeStamp startTimeStamp) { if ( SamplesType != Original_FLOAT32 ) return false ; return addSamples ( (void*)&value,1,startTimeStamp) ; }
void AggregatedSample::addSamples(const AggregatedSample* aggSamp) { if (NULL != aggSamp) { addSamples(&(aggSamp->m_sampleMap)); } }
/** USAGE: ./bench [num-of-loops] ** *********************************************************************** **/ int main(int argc, char *argv[]) { // Build benchmark list addSamples(); // Default/arbitrary benchmark loops argc==2 ? bench(atol(argv[1])) : bench(1000000); return 0; }
u16 generateAudioSample(void) { u16 mix_sample = 1; u16 osc1_sample = 1; u16 osc2_sample = 1; u16 noise_sample = 0; static u16 noise = 0; if (cur_preset.ARPG_Type && notesON > 1) arpeggios(); OSC1.Env.compteur++; osc1_sample = processOSC(&OSC1); osc1_sample = generateur_enveloppe(osc1_sample, &OSC1.Env); osc1_sample = multiplySample(osc1_sample, cur_preset.MIX_VCO1, 100); OSC2.Env.compteur++; osc2_sample = processOSC(&OSC2); osc2_sample = generateur_enveloppe(osc2_sample, &OSC2.Env); osc2_sample = multiplySample(osc2_sample, cur_preset.MIX_VCO2, 100); if (noise) noise--; else noise = 1000; cur_preset.Env.compteur++; noise_sample = tab_noi[noise]; noise_sample = (noise_sample > 0x7FFF ? noise_sample - 0x4000 : noise_sample + 0x4000); noise_sample = generateur_enveloppe(noise_sample, &cur_preset.Env); noise_sample = multiplySample(noise_sample, cur_preset.MIX_NOIS, 100); /* osc1_sample = addSamples(osc1_sample, noise_sample); osc2_sample = addSamples(osc2_sample, noise_sample); mix_sample = addSamples(osc1_sample, osc2_sample); */ mix_sample = addSamples(addSamples(osc1_sample, osc2_sample), noise_sample); mix_sample = (mix_sample ? mix_sample : 1); return (mix_sample); }
void WorleyNoise::noise3D(float at[3], long maxOrder, float *F, float(*delta)[3], unsigned long *ID) { float x2, y2, z2, mx2, my2, mz2; float newAt[3]; long intAt[3], i; // Initialize the F values to "huge" so they will be replaced by the // first real sample tests. Note we'll be storing and comparing the // SQUARED distance from the feature points to avoid lots of slow // sqrt() calls. We'll use sqrt() only on the final answer. for (i = 0; i < maxOrder; i++) F[i] = 999999.9; // Make our own local copy, multiplying to make mean(F[0])==1.0 newAt[0] = DENSITY_ADJUSTMENT * at[0]; newAt[1] = DENSITY_ADJUSTMENT * at[1]; newAt[2] = DENSITY_ADJUSTMENT * at[2]; // Find the integer cube holding the hit point intAt[0] = int(floor(newAt[0])); intAt[1] = int(floor(newAt[1])); intAt[2] = int(floor(newAt[2])); // A simple way to compute the closest neighbors would be to test all // boundary cubes exhaustively. This is simple with code like: // { // long ii, jj, kk; // for (ii=-1; ii<=1; ii++) for (jj=-1; jj<=1; jj++) for (kk=-1; kk<=1; kk++) // addSamples(intAt[0]+ii,intAt[1]+jj,intAt[2]+kk, // maxOrder, newAt, F, delta, ID); // } // But this wastes a lot of time working on cubes which are known to be // too far away to matter! So we can use a more complex testing method // that avoids this needless testing of distant cubes. This doubles the // speed of the algorithm. // Test the central cube for closest point(s). addSamples(intAt[0], intAt[1], intAt[2], maxOrder, newAt, F, delta, ID); // We test if neighbor cubes are even POSSIBLE contributors by examining the // combinations of the sum of the squared distances from the cube's lower // or upper corners. x2 = newAt[0] - intAt[0]; y2 = newAt[1] - intAt[1]; z2 = newAt[2] - intAt[2]; mx2 = (1.0 - x2) * (1.0 - x2); my2 = (1.0 - y2) * (1.0 - y2); mz2 = (1.0 - z2) * (1.0 - z2); x2 *= x2; y2 *= y2; z2 *= z2; // Test 6 facing neighbors of center cube. These are closest and most // likely to have a close feature point. if (x2 < F[maxOrder-1]) addSamples(intAt[0] - 1, intAt[1] , intAt[2] , maxOrder, newAt, F, delta, ID); if (y2 < F[maxOrder-1]) addSamples(intAt[0] , intAt[1] - 1, intAt[2] , maxOrder, newAt, F, delta, ID); if (z2 < F[maxOrder-1]) addSamples(intAt[0] , intAt[1] , intAt[2] - 1, maxOrder, newAt, F, delta, ID); if (mx2 < F[maxOrder-1]) addSamples(intAt[0] + 1, intAt[1] , intAt[2] , maxOrder, newAt, F, delta, ID); if (my2 < F[maxOrder-1]) addSamples(intAt[0] , intAt[1] + 1, intAt[2] , maxOrder, newAt, F, delta, ID); if (mz2 < F[maxOrder-1]) addSamples(intAt[0] , intAt[1] , intAt[2] + 1, maxOrder, newAt, F, delta, ID); // Test 12 "edge cube" neighbors if necessary. They're next closest. if (x2 + y2 < F[maxOrder-1]) addSamples(intAt[0] - 1, intAt[1] - 1, intAt[2] , maxOrder, newAt, F, delta, ID); if (x2 + z2 < F[maxOrder-1]) addSamples(intAt[0] - 1, intAt[1] , intAt[2] - 1, maxOrder, newAt, F, delta, ID); if (y2 + z2 < F[maxOrder-1]) addSamples(intAt[0] , intAt[1] - 1, intAt[2] - 1, maxOrder, newAt, F, delta, ID); if (mx2 + my2 < F[maxOrder-1]) addSamples(intAt[0] + 1, intAt[1] + 1, intAt[2] , maxOrder, newAt, F, delta, ID); if (mx2 + mz2 < F[maxOrder-1]) addSamples(intAt[0] + 1, intAt[1] , intAt[2] + 1, maxOrder, newAt, F, delta, ID); if (my2 + mz2 < F[maxOrder-1]) addSamples(intAt[0] , intAt[1] + 1, intAt[2] + 1, maxOrder, newAt, F, delta, ID); if (x2 + my2 < F[maxOrder-1]) addSamples(intAt[0] - 1, intAt[1] + 1, intAt[2] , maxOrder, newAt, F, delta, ID); if (x2 + mz2 < F[maxOrder-1]) addSamples(intAt[0] - 1, intAt[1] , intAt[2] + 1, maxOrder, newAt, F, delta, ID); if (y2 + mz2 < F[maxOrder-1]) addSamples(intAt[0] , intAt[1] - 1, intAt[2] + 1, maxOrder, newAt, F, delta, ID); if (mx2 + y2 < F[maxOrder-1]) addSamples(intAt[0] + 1, intAt[1] - 1, intAt[2] , maxOrder, newAt, F, delta, ID); if (mx2 + z2 < F[maxOrder-1]) addSamples(intAt[0] + 1, intAt[1] , intAt[2] - 1, maxOrder, newAt, F, delta, ID); if (my2 + z2 < F[maxOrder-1]) addSamples(intAt[0] , intAt[1] + 1, intAt[2] - 1, maxOrder, newAt, F, delta, ID); // Final 8 "corner" cubes if (x2 + y2 + z2 < F[maxOrder-1]) addSamples(intAt[0] - 1, intAt[1] - 1, intAt[2] - 1, maxOrder, newAt, F, delta, ID); if (x2 + y2 + mz2 < F[maxOrder-1]) addSamples(intAt[0] - 1, intAt[1] - 1, intAt[2] + 1, maxOrder, newAt, F, delta, ID); if (x2 + my2 + z2 < F[maxOrder-1]) addSamples(intAt[0] - 1, intAt[1] + 1, intAt[2] - 1, maxOrder, newAt, F, delta, ID); if (x2 + my2 + mz2 < F[maxOrder-1]) addSamples(intAt[0] - 1, intAt[1] + 1, intAt[2] + 1, maxOrder, newAt, F, delta, ID); if (mx2 + y2 + z2 < F[maxOrder-1]) addSamples(intAt[0] + 1, intAt[1] - 1, intAt[2] - 1, maxOrder, newAt, F, delta, ID); if (mx2 + y2 + mz2 < F[maxOrder-1]) addSamples(intAt[0] + 1, intAt[1] - 1, intAt[2] + 1, maxOrder, newAt, F, delta, ID); if (mx2 + my2 + z2 < F[maxOrder-1]) addSamples(intAt[0] + 1, intAt[1] + 1, intAt[2] - 1, maxOrder, newAt, F, delta, ID); if (mx2 + my2 + mz2 < F[maxOrder-1]) addSamples(intAt[0] + 1, intAt[1] + 1, intAt[2] + 1, maxOrder, newAt, F, delta, ID); // We're done! Convert everything to right size scale for (i = 0; i < maxOrder; i++) { F[i] = sqrt(F[i]) * (1.0 / DENSITY_ADJUSTMENT); delta[i][0] *= (1.0 / DENSITY_ADJUSTMENT); delta[i][1] *= (1.0 / DENSITY_ADJUSTMENT); delta[i][2] *= (1.0 / DENSITY_ADJUSTMENT); } }
// Performs a single color blending. This function can be repeatedly invoked to // perform multiple color blending. inline void doBlend(const TRasterCM32P &cmIn, RGBMRasterPair &inkLayer, RGBMRasterPair &paintLayer, const SelectionRaster &selRas, const std::vector<BlurPattern> &blurPatterns) { // Declare some vars unsigned int blurPatternsCount = blurPatterns.size(); int lx = cmIn->getLx(), ly = cmIn->getLy(); double totalFactor; TPixelCM32 *cmPix, *cmBegin = (TPixelCM32 *)cmIn->getRawData(); TPixel32 *inkIn = (TPixel32 *)inkLayer.first->getRawData(), *inkOut = (TPixel32 *)inkLayer.second->getRawData(), *paintIn = (TPixel32 *)paintLayer.first->getRawData(), *paintOut = (TPixel32 *)paintLayer.second->getRawData(); const BlurPattern *blurPattern, *blurPatternsBegin = &blurPatterns[0]; bool builtSamples = false; DoubleRGBMPixel samplesSum; // For every cmIn pixel TPoint pos; SelectionData *selData = selRas.data(); cmPix = cmBegin; for (pos.y = 0; pos.y < ly; ++pos.y, cmPix = cmBegin + pos.y * cmIn->getWrap()) for (pos.x = 0; pos.x < lx; ++pos.x, ++inkIn, ++inkOut, ++paintIn, ++paintOut, ++selData, ++cmPix) { blurPattern = blurPatternsBegin + (rand() % blurPatternsCount); // Build the ink blend color if (!selData->m_purePaint && selData->m_selectedInk) { if (!builtSamples) { // Build samples contributes totalFactor = 1.0; samplesSum.r = samplesSum.g = samplesSum.b = samplesSum.m = 0.0; if (!isFlatNeighbourhood(cmPix->getInk(), cmIn, pos, selRas, *blurPattern)) addSamples(cmIn, pos, inkLayer.first, paintLayer.first, selRas, *blurPattern, samplesSum, totalFactor); builtSamples = true; } // Output the blended pixel inkOut->r = (samplesSum.r + inkIn->r) / totalFactor; inkOut->g = (samplesSum.g + inkIn->g) / totalFactor; inkOut->b = (samplesSum.b + inkIn->b) / totalFactor; inkOut->m = (samplesSum.m + inkIn->m) / totalFactor; } else { // If the color is not blended, then just copy the old layer pixel *inkOut = *inkIn; } // Build the paint blend color if (!selData->m_pureInk && selData->m_selectedPaint) { if (!builtSamples) { // Build samples contributes totalFactor = 1.0; samplesSum.r = samplesSum.g = samplesSum.b = samplesSum.m = 0.0; if (!isFlatNeighbourhood(cmPix->getPaint(), cmIn, pos, selRas, *blurPattern)) addSamples(cmIn, pos, inkLayer.first, paintLayer.first, selRas, *blurPattern, samplesSum, totalFactor); builtSamples = true; } // Output the blended pixel paintOut->r = (samplesSum.r + paintIn->r) / totalFactor; paintOut->g = (samplesSum.g + paintIn->g) / totalFactor; paintOut->b = (samplesSum.b + paintIn->b) / totalFactor; paintOut->m = (samplesSum.m + paintIn->m) / totalFactor; } else { // If the color is not blended, then just copy the old layer pixel *paintOut = *paintIn; } builtSamples = false; } }
string StringParserandInvoker::operate(string message) { vector<string> tokens; string buf=""; unsigned int i=0; bool additionalSpace=true; message = removeNewLineCharactersAtEndOfLine(&message); while(i<message.length()) { if(message[i]!=' ') { buf+=message[i]; additionalSpace=false; } else { if(!additionalSpace) { tokens.push_back(buf); buf=""; additionalSpace=true; } } i++; } if(!buf.empty()) { tokens.push_back(buf); } /* for(i=0;i<tokens.size();i++) { cout<<tokens[i]<<endl; } cout << tokens[0] << endl; */ mapValues(); string returnVal; //cout << enumMapping[tokens[0]]<<endl; switch(enumMapping[tokens[0]]) { case putvalue: //cout << "PUT" << endl; returnVal=put(tokens); break; case getvalue: returnVal=get(tokens); break; case incrementvalue: //cout << "INCR" << endl; returnVal=increment(tokens); break; case decrementvalue: //cout << "DECR" << endl; returnVal=decrement(tokens); break; case declsamples: returnVal=declSamples(tokens); break; case declmovavg: returnVal=declMovAvg(tokens); break; case addsamples: returnVal=addSamples(tokens); break; case movavg: returnVal=movingAvg(tokens); break; case retrieve: returnVal = retrieveN(tokens); break; case variance: returnVal=getvariance(tokens); break; case stddev: returnVal=getstddev(tokens); break; case lifetimeavg: returnVal=getlifetimeavg(tokens); break; case histogram: returnVal = getHistogram(tokens); break; default: returnVal="Invalid input"; break; } return returnVal; }