int main(int argc, char **argv) { cutoff_detail = 9; describe_failures = true; describe_successes = true; describe_trivia = true; char *devicename = NULL; bool usage_okay = true; int i; for(i = 1; i < argc; i++) { if(argv[i][0] == '-') { int j; for(j = 1; argv[i][j]; j++) { char c = argv[i][j]; if(isdigit(c)) { cutoff_detail = c - '0'; } else switch(argv[i][j]) { case 'F': describe_failures = true; break; case 'f': describe_failures = false; break; case 'S': describe_successes = true; break; case 's': describe_successes = false; break; case 'T': describe_trivia = true; break; case 't': describe_trivia = false; break; default: usage_okay = false; break; } } } else if(!devicename) { devicename = argv[i]; } else { usage_okay = false; } } if(!devicename) usage_okay = false; if(!usage_okay) { fprintf(stderr, "Usage: gpt-tweak [-fstFST0123456789] device|file\n"); return 1; } printf("Okay, my verbosity is -%c%c%c%i. Just so you know.\n", describe_failures ? 'F' : 'f', describe_successes ? 'S' : 's', describe_trivia ? 'T' : 't', cutoff_detail); current_detail = 1; int fd = open64(devicename, O_RDONLY); if(fd == -1) { fprintf(stderr, "Unable to open %s: %s\n", devicename, strerror(errno)); return 1; } tweak(fd); close(fd); return 0; }
void XTS_Decryption::finish(secure_vector<uint8_t>& buffer, size_t offset) { BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; uint8_t* buf = buffer.data() + offset; BOTAN_ASSERT(sz >= minimum_final_size(), "Have sufficient final input in XTS decrypt"); const size_t BS = cipher().block_size(); if(sz % BS == 0) { update(buffer, offset); } else { // steal ciphertext const size_t full_blocks = ((sz / BS) - 1) * BS; const size_t final_bytes = sz - full_blocks; BOTAN_ASSERT(final_bytes > BS && final_bytes < 2*BS, "Left over size in expected range"); secure_vector<uint8_t> last(buf + full_blocks, buf + full_blocks + final_bytes); buffer.resize(full_blocks + offset); update(buffer, offset); xor_buf(last, tweak() + BS, BS); cipher().decrypt(last); xor_buf(last, tweak() + BS, BS); for(size_t i = 0; i != final_bytes - BS; ++i) { last[i] ^= last[i + BS]; last[i + BS] ^= last[i]; last[i] ^= last[i + BS]; } xor_buf(last, tweak(), BS); cipher().decrypt(last); xor_buf(last, tweak(), BS); buffer += last; } }
TEST(gtest_par_xml_output, main) { // Sample command line initializer const std::string argv_init[]={ std::string("program_name"), // 0 std::string("--some_option"), // 1 std::string("--gtest_other=abc"), // 2 std::string("--gtest_output=xmlsome-other-type"), // 3 std::string("--gtest_output=xml"), // 4 std::string("--gtest_output=xml:/some/dirname/"), // 5 std::string("--gtest_output=xml:/some/filename"), // 6 std::string("--gtest_output=xml:/some/filename.ext"), // 7 std::string("--gtest_output=xml:/some/filename."), // 8 std::string("--some_more_options") // 9 }; const int argc=sizeof(argv_init)/sizeof(*argv_init); // Copy of the command line std::vector<std::string> argv_copy(argc); std::copy(argv_init, argv_init+argc, argv_copy.begin()); // Command line to be scanned char** argv=new char*[argc]; for (int i=0; i<argc; ++i) { argv[i]=const_cast<char*>(argv_copy[i].c_str()); // dirty, but would work here } alps::gtest_par_xml_output tweak; // hold memory tweak(123, argc, argv); // do tweaking { // These arguments should stay intact int idx[]={0, 1, 2, 3, 9}; for (int i=0; i<sizeof(idx)/sizeof(*idx); ++i) { int ii=idx[i]; EXPECT_EQ(argv_init[ii], argv[ii]) << "Unexpected change in argv[" << ii << "]"; } } // These arguments should change: EXPECT_EQ("--gtest_output=xml:test_details123.xml", std::string(argv[4])) << "Wrong \"=xml\""; EXPECT_EQ("--gtest_output=xml:/some/dirname123/", std::string(argv[5])) << "wrong xml=dir/"; EXPECT_EQ("--gtest_output=xml:/some/filename123", std::string(argv[6])) << "wrong xml=file"; EXPECT_EQ("--gtest_output=xml:/some/filename123.ext", std::string(argv[7])) << "wrong xml=file.ext"; EXPECT_EQ("--gtest_output=xml:/some/filename123.", std::string(argv[8])) << "wrong xml=file."; delete[] argv; }
// for testing MPI, we need main() int main(int argc, char**argv) { alps::mpi::environment mpi_env(argc, argv); alps::gtest_par_xml_output tweak; tweak(alps::mpi::communicator().rank(), argc, argv); ::testing::InitGoogleTest(&argc, argv); Mpi_guard guard(MASTER,"four_index_gf_test_mismatched-mpi.dat."); int rc=RUN_ALL_TESTS(); if (!guard.check_sig_files_ok(get_number_of_bcasts())) { MPI_Abort(MPI_COMM_WORLD, 1); // otherwise it may get stuck in MPI_Finalize(). // downside is the test aborts, rather than reports failure! } return rc; }
size_t XTS_Decryption::process(uint8_t buf[], size_t sz) { BOTAN_STATE_CHECK(tweak_set()); const size_t BS = cipher().block_size(); BOTAN_ASSERT(sz % BS == 0, "Input is full blocks"); size_t blocks = sz / BS; const size_t blocks_in_tweak = update_granularity() / BS; while(blocks) { const size_t to_proc = std::min(blocks, blocks_in_tweak); cipher().decrypt_n_xex(buf, tweak(), to_proc); buf += to_proc * BS; blocks -= to_proc; update_tweak(to_proc); } return sz; }
/* PaletteEntryPanel::handleAction * Handles the action [id]. Returns true if the action was handled, * false otherwise *******************************************************************/ bool PaletteEntryPanel::handleAction(string id) { // Ignore if hidden if (!isActivePanel()) return false; // Only interested in "ppal_" events if (!id.StartsWith("ppal_")) return false; // Add to custom palettes if (id == "ppal_addcustom") { addCustomPalette(); return true; } // Test palette else if (id == "ppal_test") { testPalette(); return true; } // Export As else if (id == "ppal_exportas") { exportAs(); return true; } // Import From else if (id == "ppal_importfrom") { importFrom(); return true; } // Generate Palettes if (id == "ppal_generate") { generatePalettes(); return true; } // Generate Colormaps if (id == "ppal_colormap") { generateColormaps(); return true; } // Colourise else if (id == "ppal_colourise") { colourise(); return true; } // Tint else if (id == "ppal_tint") { tint(); return true; } // Tweak else if (id == "ppal_tweak") { tweak(); return true; } // Invert else if (id == "ppal_invert") { invert(); return true; } // Move Up else if (id == "ppal_moveup") { move(true); return true; } // Move Down else if (id == "ppal_movedown") { move(false); return true; } // Duplicate else if (id == "ppal_duplicate") { duplicate(); return true; } // Remove else if (id == "ppal_remove") { clearOne(); return true; } // Remove Others else if (id == "ppal_removeothers") { clearOthers(); return true; } // Some debug/reverse engineering stuff else if (id == "ppal_report") { analysePalettes(); return true; } return false; }
int btrack_pps(WAVDATA *wvd, PPSDATA *pps, long ss, long es) { long seed, period, ibeg, iend, ipt, ifr, nfr; long ns, nc, ic, j, k, l, loc, nwin; float tsc, sr, v, dmin; float avgF0, tf0, f0tmp[5], f0sft[5]; double estF0, vth, navg; short *data, max, *x; ns = wvd->ns; nc = wvd->nc; ic = wvd->active; tsc = wvd->srms; data = wvd->wavdata; sr = (float) (tsc * 1000.0); /* * Estimate F0 & prob of voicing every 20 msec with 40 msec window */ nwin = (int) (40.0 * tsc + 0.5); if ((es - ss) < nwin) return -1; nfr = (int) ((double)(es - ss) / (20.0 * tsc) + 0.5); /* actual nfr should be 1 less than this */ vData = (VOICING *) malloc(sizeof(VOICING)); vData->StartTime = (float) (tsc*(double)ss + 20.0); vData->StepSize = 20.0; vData->F0 = (float *) malloc(nfr * sizeof(float)); vData->Pv = (float *) malloc(nfr * sizeof(float)); x = (short *) malloc(nwin * sizeof(short)); ipt = ss; ifr = 0; avgF0 = (float) 0.0; navg = 0.0; while ((ipt+nwin) < es) { for (j=0; j<nwin; j++) { x[j] = data[(ipt+j)*nc+ic]; } vData->Pv[ifr] = voicingEstimate(sr, x, &estF0, FALSE); avgF0 += (float) estF0 * vData->Pv[ifr] ; navg += vData->Pv[ifr]; vData->F0[ifr++] = (float) estF0; ipt += nwin/2; } vData->nfr = ifr; free(x); if (navg) avgF0 /= (float) navg; else { free(vData->Pv); free(vData->F0); free(vData); return -1; } /* * Do median smoothing of F0 data */ for (k=0; k<4; k++) f0sft[k] = vData->F0[k]; for (j=4; j<vData->nfr; j++) { f0sft[4] = vData->F0[j]; for (k=0; k<5; k++) f0tmp[k] = f0sft[k]; for (k=0; k<4; k++) { for (l=k+1; l<5; l++) { if (f0tmp[l] < f0tmp[k]) { tf0 = f0tmp[l]; f0tmp[l] = f0tmp[k]; f0tmp[k] = tf0; } } } vData->F0[j-2] = f0tmp[2]; for (k=0; k<4; k++) f0sft[k] = f0sft[k+1]; } /* * Estimate seed (Note: NWIN is now redefined for use with PP detector) */ dmin = 1000.0; loc = -1; vth = 0.5; do { for (j=1; j<vData->nfr-1; j++) { if (vData->Pv[j-1] >= vth && vData->Pv[j] >= vth && vData->Pv[j+1] >= vth) { if (fabs(avgF0 - vData->F0[j]) < dmin) { dmin = (float) fabs(avgF0 - vData->F0[j]); loc = j; } } } vth -= 0.05; } while (loc < 0 && vth > .25); if (loc < 0) { free(vData->Pv); free(vData->F0); free(vData); return -1; } ipt = (int) (((double)loc * 20.0 + vData->StartTime) * tsc); nwin = (int) (pitcmn.wlen * tsc + 0.5); nwin = 2 * (nwin/2) + 1; /* nwin should be odd */ ibeg = ipt - (int) (0.5*sr/avgF0); iend = ipt + (int) (0.5*sr/avgF0); if (ibeg < ss) ibeg = ss; if (iend > es) iend = es; if (iend <= ibeg) { free(vData->Pv); free(vData->F0); free(vData); return -1; } for (max=0, j=loc=ibeg; j<=iend; j++) { if (data[j*nc + ic] > max) { loc = j; max = data[j*nc + ic]; } } seed = tweak(loc, nc, ic, data, ns); if (seed < nwin/2 || seed > (ns - nwin/2)) { return -1; } /* * Estimate period */ period = (long) (v = (sr / (pitcmn.F0mean = avgF0))); /* * Now call the regular tracking function with this seed value */ use_vData = TRUE; ipt = track_pps(wvd, pps, seed, period, ss, es); free(vData->F0); free(vData->Pv); free(vData); use_vData = FALSE; return ipt; }
int track_pps(WAVDATA *wvd, PPSDATA *pps, long seed, long period, long ss, long es) { int vstat, navg, fpt; long j, ipt, ibeg, iend, nwin, minPP, maxPP, loc, lc2, npps=0, ns, nc, ic; float time, tlast, max, v, *kernel, *kernelX, tsc, vuv, pavg, pmin, pmax, sr; double rad, rx; short *data; ns = wvd->ns; nc = wvd->nc; ic = wvd->active; tsc = wvd->srms; sr = (float) (tsc * 1000.0); data = wvd->wavdata; /* * get windowed kernel at seed location */ DC = calc_dc(ic, nc, ns, data); seed = tweak(seed, nc, ic, data, ns); nwin = (int) (pitcmn.wlen * tsc + 0.5); nwin = 2 * (nwin/2) + 1; /* nwin should be odd */ if (seed < nwin/2 || seed > (ns - nwin/2)) { return -1; } if (!(kernel = (float *) malloc(nwin * sizeof(float)))) return -1; if (!(kernelX = (float *) malloc(nwin * sizeof(float)))){ free(kernel); return -1; } rx = 2.0 * M_PI/ (float) nwin; ibeg = (seed * nc + ic) - (nc * nwin/2); for (rad=rx/2.0, ipt=ibeg, j=0; j<nwin; j++, ipt+=nc, rad+=rx) kernel[j] = (float) (0.5 - 0.5 * cos(rad)) * (float) (data[ipt] - DC); for (rad=rx/2.0, j=0; j<nwin; j++, rad+=rx) kernelX[j] = (float) ((0.5 - 0.5 * cos(rad)) * -16384.0 * sin(rad)); minPP = (int) (pitcmn.jitlo * (float)period + 0.5); /* allow for acceptable jitter */ maxPP = (int) (pitcmn.jithi * (float)period + 0.5); tlast = (float) seed / tsc; if (seed >= ss && seed <= es) { ppadd(tlast, 1, pps); /* store location of seed as a PP */ npps++; } ibeg = seed + minPP; iend = seed + maxPP; ipt = ibeg; if (pitcmn.vuv == 0.0) vuv = (float) (0.1 * compare(seed*nc + ic, nc, data, nwin, kernelX) / (double) nwin); else vuv = pitcmn.vuv * pitcmn.vuv; pavg = (float) period / tsc; navg = 1; pmin = pmax = pavg; /* * Search from seed location to end of the input waveform */ while ((iend + nwin/2) <= es) { max = compare(ipt*nc + ic, nc, data, nwin, kernel); loc = ipt; for (ipt=ibeg+1; ipt < iend; ipt++) if ((v = compare(ipt*nc+ic, nc, data, nwin, kernel)) > max) { max = v; loc = ipt; } if (use_vData) { fpt = (int) ((((double)loc / tsc) - vData->StartTime) / vData->StepSize + 0.5); if (fpt < 0) fpt = 0; if (fpt >= vData->nfr) fpt = vData->nfr - 1; } max = compare(loc*nc+ic, nc, data, nwin, kernelX) / (float) nwin; /* for voicing decision */ if (max > vuv) { lc2 = tweak(loc, nc, ic, data, ns); if (labs(lc2 - loc) < nwin/4) loc = lc2; time = (float) loc / tsc; if (vstat) { v = time - tlast; pavg += v; navg++; if (v < pmin) pmin = v; if (v > pmax) pmax = v; if (use_vData) { minPP = (long) ((pitcmn.jitlo * sr/vData->F0[fpt]) + 0.5); /* allow -jitlo variation for next period */ maxPP = (long) ((pitcmn.jithi * sr/vData->F0[fpt]) + 0.5); /* allow +jithi variation for next period */ } else { minPP = (long) ((pitcmn.jitlo * v) * tsc + 0.5); /* allow - 10% variation for next period */ maxPP = (long) ((pitcmn.jithi * v) * tsc + 0.5); /* allow + 15% variation for next period */ } } else { if (use_vData) v = (sr/vData->F0[fpt])/tsc; else v = pavg / (float) navg; minPP = (long) ((pitcmn.jitlo * v) * tsc + 0.5); /* allow - 25% variation for next period */ maxPP = (long) ((pitcmn.jithi * v) * tsc + 0.5); /* allow + 50% variation for next period */ } vstat = 1; } else { v = pavg / (float) navg; time = tlast + v; loc = (long) (tsc * time + 0.5f); if (loc > ns) { loc = ns; time = (float) loc / tsc; v = time - tlast; } vstat = 0; minPP = (long) ((pitcmn.jitlo * v) * tsc + 0.5); /* allow - 25% variation for next period */ maxPP = (long) ((pitcmn.jithi * v) * tsc + 0.5); /* allow + 50% variation for next period */ } if (loc >= ss) { ppadd(time, vstat, pps); npps++; } ibeg = (loc * nc + wvd->active) - (nc * nwin/2); if ((ibeg + nwin) < ns) if (vstat) for (rad=rx/2.0f, ipt=ibeg, j=0; j<nwin; j++, ipt+=nc, rad+=rx) kernel[j] = 0.5f * (kernel[j] + ((float) (0.5 - 0.5 * cos(rad)) * (float) (data[ipt] - DC))); else for (j=0; j<nwin; j++) kernel[j] = 0.5f * (kernel[j] + kernelX[j]); ibeg = loc + minPP; iend = loc + maxPP; ipt = ibeg; tlast = time; } tlast = (float) seed / tsc; ibeg = (seed * nc + ic) - (nc * nwin/2); for (rad=rx/2.0, ipt=ibeg, j=0; j<nwin; j++, ipt+=nc, rad+=rx) kernel[j] = (float) (0.5 - 0.5 * cos(rad)) * (float) (data[ipt] - DC); minPP = (int) (pitcmn.jitlo * (float)period + 0.5); /* reset for original period template */ maxPP = (int) (pitcmn.jithi * (float)period + 0.5); ibeg = seed - maxPP; iend = seed - minPP; ipt = ibeg; while ((ibeg >= ss) && (ibeg > nwin/2)) { max = compare(ipt*nc + ic, nc, data, nwin, kernel); loc = ipt; for (ipt=ibeg+1; ipt < iend; ipt++) if ((v = compare(ipt*nc+ic, nc, data, nwin, kernel)) > max) { max = v; loc = ipt; } if (use_vData) { fpt = (int) ((((double)loc / tsc) - vData->StartTime) / vData->StepSize + 0.5); if (fpt < 0) fpt = 0; if (fpt >= vData->nfr) fpt = vData->nfr - 1; } max = compare(loc*nc+ic, nc, data, nwin, kernelX) / (float) nwin; /* for voicing decision */ if (max > vuv) { lc2 = tweak(loc, nc, ic, data, ns); if (labs(lc2 - loc) < nwin/4) loc = lc2; time = (float) loc / tsc; if (vstat) { v = tlast - time; pavg += v; navg++; if (v < pmin) pmin = v; if (v > pmax) pmax = v; if (use_vData) { minPP = (long) ((pitcmn.jitlo * sr/vData->F0[fpt]) + 0.5); /* allow -jitlo variation for next period */ maxPP = (long) ((pitcmn.jithi * sr/vData->F0[fpt]) + 0.5); /* allow +jithi variation for next period */ } else { minPP = (long) ((pitcmn.jitlo * v) * tsc + 0.5); /* allow - 10% variation for next period */ maxPP = (long) ((pitcmn.jithi * v) * tsc + 0.5); /* allow + 15% variation for next period */ } } else { if (use_vData) v = (sr/vData->F0[fpt])/tsc; else v = pavg / (float) navg; minPP = (long) ((pitcmn.jitlo * v) * tsc + 0.5); /* allow - 25% variation for next period */ maxPP = (long) ((pitcmn.jithi * v) * tsc + 0.5); /* allow + 50% variation for next period */ } vstat = 1; } else { v = pavg / (float) navg; time = tlast - v; loc = (long) (tsc * time + 0.5); if (loc < 0) { loc = 0; time = (float) loc / tsc; v = tlast - time; } vstat = 0; minPP = (long) ((pitcmn.jitlo * v) * tsc + 0.5); /* allow - 25% variation for next period */ maxPP = (long) ((pitcmn.jithi * v) * tsc + 0.5); /* allow + 50% variation for next period */ } if (loc >= ss && loc <= es) { ppadd(time, vstat, pps); npps++; } ibeg = (loc * nc + ic) - (nc * nwin/2); if (ibeg >= 0) if (vstat) for (rad=rx/2.0f, ipt=ibeg, j=0; j<nwin; j++, ipt+=nc, rad+=rx) kernel[j] = (float) (0.5 * (kernel[j] + ((0.5 - 0.5 * cos(rad)) * (double) (data[ipt] - DC)))); else for (j=0; j<nwin; j++) kernel[j] = (float) (0.5 * (kernelX[j] + kernel[j])); ibeg = loc - maxPP; iend = loc - minPP; ipt = ibeg; tlast = time; } ppsort(pps); free(kernel); free(kernelX); return (int) npps; }
void AutoMateUi::tweak() { applyAbortToStartButton(); emit tweak(tweaks_model->getSelected()); }