virtual void onSound(AudioIOData& io) { static cuttlebone::Stats fps("onSound()"); static float currentNoiseAmplitude = 0; fps(io.secondsPerBuffer()); float maxInputAmplitude = 0.0f; // set the pose of our audio source tap.pose(Pose(state->p[state->pokedVertex], Quatf())); // "f" is the desired noise amplitude based on the state float f = (state->p[state->pokedVertex] - state->pokedVertexRest).mag() - 0.45; if (f > 0.99) f = 0.99; if (f < 0) f = 0; while (io()) { // find largest input amplitude of block // float in = fabs(io.in(0)); if (in > maxInputAmplitude) maxInputAmplitude = in; // Make this 0.0001 so it will sound good float ProportionOfErrorToEliminateOnThisAudioSample = 0.0001; currentNoiseAmplitude += (f-currentNoiseAmplitude) * ProportionOfErrorToEliminateOnThisAudioSample; // output sample directly or write sample to output through our audio source // io.out(0) = io.out(1) = pinkNoise() * f * state->audioGain; tap.writeSample( pinkNoise() * currentNoiseAmplitude * state->audioGain ); } // poke the blob if the largest amplitude is above some threshold // if (maxInputAmplitude > 0.707f) shouldPoke = true; // set listener pose and render audio sources listener()->pose(state->pose); scene()->render(io); }
virtual void onSound(AudioIOData& io) { static cuttlebone::Stats fps("onSound()"); fps(io.secondsPerBuffer()); tap.pose(Pose(state->p[state->pokedVertex], Quatd(1, 0, 0, 0))); int popCount = taker.get(*state); float f = (state->p[state->pokedVertex] - state->pokedVertexRest).mag() - 0.304134 /* mean */; if (f > 0.8) f = 0.8; if (f < 0) f = 0; while (io()) { // XXX rnd::uniformS() should be gamma noise // XXX use interpolation on gain tap.writeSample(rnd::uniformS() * f); // io.out(0) = rnd::uniformS() * f; } listener()->pose(state->pose); scene()->render(io); }