void polygonize(const XForm& xform, const RGrid<float>& grid, std::vector<CGLA::Vec3d>& quad_vertices, float tau) { quad_vertices.clear(); for(int i=0;i<xform.get_dims()[0];++i) for(int j=0;j<xform.get_dims()[1];++j) for(int k=0;k<xform.get_dims()[2];++k) { Vec3i vox(i,j,k); if(grid[vox] <= tau) { if(grid.in_domain(Vec3i(i+1,j,k)) && grid[Vec3i(i+1,j,k)] > tau) for(int n=0;n<4;++n) quad_vertices.push_back(xform.inverse(Vec3d(i+0.5, j,k) + xpf[n])); if(grid.in_domain(Vec3i(i-1,j,k)) && grid[Vec3i(i-1,j,k)] > tau) for(int n=0;n<4;++n) quad_vertices.push_back(xform.inverse(Vec3d(i-0.5, j,k) + xmf[n])); if(grid.in_domain(Vec3i(i,j+1,k)) && grid[Vec3i(i,j+1,k)] > tau) for(int n=0;n<4;++n) quad_vertices.push_back(xform.inverse(Vec3d(i, j+0.5,k) + ypf[n])); if(grid.in_domain(Vec3i(i,j-1,k)) && grid[Vec3i(i,j-1,k)] > tau) for(int n=0;n<4;++n) quad_vertices.push_back(xform.inverse(Vec3d(i, j-0.5,k) + ymf[n])); if(grid.in_domain(Vec3i(i,j,k+1)) && grid[Vec3i(i,j,k+1)] > tau) for(int n=0;n<4;++n) quad_vertices.push_back(xform.inverse(Vec3d(i, j,k+0.5) + zpf[n])); if(grid.in_domain(Vec3i(i,j,k-1)) && grid[Vec3i(i,j,k-1)] > tau) for(int n=0;n<4;++n) quad_vertices.push_back(xform.inverse(Vec3d(i, j,k-0.5) + zmf[n])); } } }
void test_squareBL() { SquareBL vox(220); vox.set_scale(0.1); logMsg("playing squareBL wave..."); run_test(vox); logMsg("squareBL done."); }
void test_saw() { Sawtooth vox(220); vox.set_scale(0.1); logMsg("playing sawtooth..."); run_test(vox); logMsg("sin done."); }
void test_FIR() { PinkNoise noise; FIR vox(noise, "../../Data/test.flt"); logMsg("playing noise..."); run_test(noise); logMsg("noise done."); logMsg("playing FIR filter..."); run_test(vox); logMsg("FIR done."); }
void test_long_ifft() { logMsg("playing long IFFT..."); IFFT vox(2048, kFFTMeasure); // put in an explicit block resizer here vox.set_bin_mag_phase(4, 0.5, 0); vox.set_bin_mag_phase(12, 0.25, 0); vox.set_bin_mag_phase(20, 0.05, 0); vox.set_bin_mag_phase(36, 0.01, 0); run_test(vox); logMsg("long IFFT done."); }
void test_fm_sin2() { Sine vox(261), mod(261); mod.set_scale(240); mod.set_offset(261); vox.set_frequency(mod); vox.set_scale(0.1); logMsg("playing FM 2 sin..."); run_test(vox); logMsg("FM sin done."); }
void test_am_sin() { Sine vox(220), mod(6); MulOp mul(vox, mod); // AM with MulOp logMsg("playing AM sin..."); run_test(mul); logMsg("AM sin done."); Sine vox2(220), mod2(6); vox2.set_scale(mod2); // AM using set_scale() logMsg("playing AM sin..."); run_test(vox2); logMsg("AM sin done."); }
void test_panning_sin() { Sine vox(330); MulOp mul(vox, 0.2); LineSegment lin(6, -1, 1); // L-to-R sweep over 6 sec Panner pan(mul, lin); logMsg("playing panning sin 1..."); run_test(pan, 6.0); logMsg("panning sin done."); Sine pos(0.5); // LFO panning Panner pan2(mul, pos); logMsg("playing panning sin 2..."); run_test(pan2, 5.0); logMsg("panning sin done."); }
void test_FIR2() { PinkNoise noise; double resp[2] = { 1, 0 }; // these are the amplitudes in the 2 freq bands (i.e., lo-pass double freq[4] = { 0, 500, 800, 22050 }; // these are the corner freqs of the pass, transition, and stop bands double weight[2] = { 10, 20 }; // these are the weights for error (ripple) in the 2 bands FilterSpecification fs(64, 2, freq, resp, weight); // 64 taps (64-step IR), 2 bands fs.plan_filter(); FIR vox(noise, fs); logMsg("playing noise..."); run_test(noise); logMsg("noise done."); logMsg("playing FIR filter..."); run_test(vox); logMsg("FIR done."); }
void test_wavetable() { WavetableOscillator vox(220); logMsg("playing sine wavetable..."); run_test(vox); logMsg("wavetable done."); // now open a test file, read a buffer, and copy that into the wavetable SoundFile fi("../../Data/oo_table.aiff"); // a cycle of the vowel "oo" from "moon" fi.open_for_read(); unsigned frames = fi.duration(); fi.read_buffer_from_file(frames); WavetableOscillator vox2(fi._sampleBuffer, frames); // create a wavetable reader on the sample read in form the file vox2.set_frequency(110); logMsg("playing file wavetable..."); run_test(vox2); logMsg("wavetable done."); }
void test_scaled_sin() { Sine vox(220); vox.set_scale(0.1); // simplest: scale the sine directly logMsg("playing quiet sin..."); run_test(vox); logMsg("quiet sin done."); Sine vox2(220); MulOp mul(vox2, 0.1); // using a MulOp with a constant logMsg("playing quiet sin..."); run_test(mul); logMsg("quiet sin done."); Sine vox3(220); StaticVariable var(0.1); // using a MulOp with a StaticVariable MulOp mul2(vox3, var); logMsg("playing quiet sin..."); run_test(mul2); logMsg("quiet sin done."); }
void test_SHARC() { SumOfSines vox(65); SHARCLibrary * lib; SHARCSpectrum * spect; lib = new SHARCLibrary("../../sharc"); // lib->dump_stats(); spect = lib->spectrum_named("tuba", "c2"); // spect = lib->spectrum_named("Bach_trumpet", "c4"); // spect->dump_example(); vox.set_scale(0.1); vox.add_partials(spect->_num_partials, spect->_partials); vox.create_cache(); // cache the waveform (since it's a harmonic overtone spectrum) Triangle tri(3, 1); vox.set_scale(tri); logMsg("playing SumOfSines (%d partials)...", spect->_num_partials); tri.trigger(); run_test(vox, 3); // play a whole note logMsg("SumOfSines done."); }
void test_envelope() { Sine vox(220); float duration = 3.0; // time float attack = 0.06; // time float decay = 0.1; // time float sustain = 0.1; // value float release = 1.5; // time ADSR adsr(duration, attack, decay, sustain, release); MulOp mul(vox, adsr); logMsg("playing sin ADSR envelope."); adsr.trigger(); run_test(mul); logMsg("sin ADSR evelope done."); Sine vox2(220); ADSR adsr2(duration, attack, decay, sustain, release); vox2.set_scale(adsr2); logMsg("playing sin ADSR envelope."); // adsr.dump(); adsr2.trigger(); run_test(vox2); logMsg("sin ADSR evelope done."); }
OP_ERROR SOP_PointsFromVoxels::cookMySop(OP_Context &context) { bool cull, store; fpreal now, value; int rx, ry, rz; unsigned primnum; GA_Offset ptOff; GA_ROAttributeRef input_attr_gah; GA_RWAttributeRef attr_gah; GA_ROHandleS input_attr_h; GA_RWHandleF attr_h; const GU_Detail *input_geo; const GEO_Primitive *prim; const GEO_PrimVolume *vol; UT_String attr_name; UT_Vector3 pos; UT_VoxelArrayIteratorF vit; now = context.getTime(); if (lockInputs(context) >= UT_ERROR_ABORT) { return error(); } // Get the primitive number. primnum = PRIM(now); // Check for culling. cull = CULL(now); store = STORE(now); // Clear out the detail since we only want our new points. gdp->clearAndDestroy(); // Get the input geometry as read only. GU_DetailHandleAutoReadLock gdl(inputGeoHandle(0)); input_geo = gdl.getGdp(); // Primitive number is valid. if (primnum < input_geo->getNumPrimitives()) { // Get the primitive we need. prim = input_geo->primitives()(primnum); // The primitive is a volume primitive. if (prim->getTypeId().get() == GEO_PRIMVOLUME) { // Get the actual PrimVolume. vol = (const GEO_PrimVolume *)prim; // Get a voxel read handle from the primitive. UT_VoxelArrayReadHandleF vox(vol->getVoxelHandle()); // Attach the voxel iterator to the handle. vit.setHandle(vox); if (store) { // Try to find a 'name' attribute. input_attr_gah = input_geo->findPrimitiveAttribute("name"); if (input_attr_gah.isValid()) { // Get this primitive's name. input_attr_h.bind(input_attr_gah.getAttribute()); attr_name = input_attr_h.get(primnum); } // No name, so just use 'value'. else { attr_name = "value"; } // Add a float point attribute to store the values. attr_gah = gdp->addFloatTuple(GA_ATTRIB_POINT, attr_name, 1); // Attach an attribute handle. attr_h.bind(attr_gah.getAttribute()); } // Culling empty voxels. if (cull) { // Iterate over all the voxels. for (vit.rewind(); !vit.atEnd(); vit.advance()) { // The voxel value. value = vit.getValue(); // Skip voxels with a value of 0. if (value == 0) { continue; } // Convert the voxel index to a position. vol->indexToPos(vit.x(), vit.y(), vit.z(), pos); // Create a point and set it to the position of the // voxel. ptOff = gdp->appendPointOffset(); gdp->setPos3(ptOff, pos); // Store the value if necessary. if (store) { attr_h.set(ptOff, value); } } } else { // Get the resolution of the volume. vol->getRes(rx, ry, rz); // Add points for each voxel. ptOff = gdp->appendPointBlock(rx * ry * rz); // Iterate over all the voxels. for (vit.rewind(); !vit.atEnd(); vit.advance()) { // Convert the voxel index to a position. vol->indexToPos(vit.x(), vit.y(), vit.z(), pos); // Set the position for the current offset. gdp->setPos3(ptOff, pos); // Get and store the value if necessary. if (store) { value = vit.getValue(); attr_h.set(ptOff, value); } // Increment the offset since the block of points we // created is guaranteed to be contiguous. ptOff++; } } } // Primitive isn't a volume primitive. else { addError(SOP_MESSAGE, "Not a volume primitive."); } } // Picked a primitive number that is out of range. else { addWarning(SOP_MESSAGE, "Invalid source index. Index out of range."); } unlockInputs(); return error(); }
void Player::traceView() { World* w = (World*)getGame()->getObjectByName("world"); float tMax = 10; //View radius vec3f cpos(cam->getWorldPos()), dir(cam->getForward()), vox(floor(cpos.x), floor(cpos.y), floor(cpos.z)), step(0,0,0), next(0,0,0), tMaxc(tMax,tMax,tMax), tDelta(tMax,tMax,tMax); if (!w->outOfBounds(cpos.x,cpos.y,cpos.z) && w->getCube(cpos.x,cpos.y,cpos.z) != 0) { targetsBlock = true; targetedBlock = vec3f(floor(cpos.x),floor(cpos.y),floor(cpos.z)); return; } if (dir.x < 0) step.x = -1; else step.x = 1; if (dir.y < 0) step.y = -1; else step.y = 1; if (dir.z < 0) step.z = -1; else step.z = 1; next.x = vox.x + (step.x > 0 ? 1 : 0); next.y = vox.y + (step.y > 0 ? 1 : 0); next.z = vox.z + (step.z > 0 ? 1 : 0); if (dir.x != 0) { tDelta.x = step.x/dir.x; tMaxc.x = (next.x - cpos.x)/dir.x; } if (dir.y != 0) { tDelta.y = step.y/dir.y; tMaxc.y = (next.y - cpos.y)/dir.y; } if (dir.z != 0) { tDelta.z = step.z/dir.z; tMaxc.z = (next.z - cpos.z)/dir.z; } float tCurr = 0; while (tCurr < tMax) { targetedBlockEnter = vox; if(tMaxc.x < tMaxc.y) { if(tMaxc.x < tMaxc.z) { tCurr = tMaxc.x; tMaxc.x = tMaxc.x + tDelta.x; vox.x = vox.x + step.x; } else { tCurr = tMaxc.z; vox.z = vox.z + step.z; tMaxc.z = tMaxc.z + tDelta.z; } } else { if(tMaxc.y < tMaxc.z) { tCurr = tMaxc.y; vox.y = vox.y + step.y; tMaxc.y = tMaxc.y + tDelta.y; } else { tCurr = tMaxc.z; vox.z = vox.z + step.z; tMaxc.z= tMaxc.z + tDelta.z; } } if(!w->outOfBounds(vox.x,vox.y,vox.z) && w->getCube(vox.x,vox.y,vox.z) != 0) { targetsBlock = true; targetedBlock = vox; return; } } targetsBlock = false; }
void test_sin() { Sine vox(220); logMsg("playing sin..."); run_test(vox, 3.0); logMsg("sin done."); }