Example #1
0
vrpn_HapticVector  InstantBuzzEffect::calcEffectForce(void) {
#else
gstVector InstantBuzzEffect::calcEffectForce(void *phantom) {
#endif
    // No force if inactive
    if (!active) {
      return vrpn_HapticVector(0,0,0);
    }

    LARGE_INTEGER counter;
	
    if (currentPerformanceFrequency.HighPart == 0 && currentPerformanceFrequency.LowPart == 0) {
      return vrpn_HapticVector(0,0,0);
    }

#ifdef	_WIN32
    if (QueryPerformanceCounter(&counter) != TRUE){
	fprintf(stderr, "unable to get perfo counter\n");
	return vrpn_HapticVector(0,0,0);
    }
#endif

    double elapsedSec =  (counter.QuadPart - debut.QuadPart) / (double) currentPerformanceFrequency.QuadPart;
    if (elapsedSec < getDuration()) {
	double currentPart = (counter.QuadPart*getFrequency()/currentPerformanceFrequency.QuadPart);
	currentPart = (currentPart-(long)currentPart)*2*PI;
	double currentForce = sin(currentPart);
	double force = currentForce*getAmplitude();
	return vrpn_HapticVector( x*force, y*force, z*force );
    }

      return vrpn_HapticVector(0,0,0);
}
void RandomMovementParticleAffector::changed(ConstFieldMaskArg whichField, 
                            UInt32            origin,
                            BitVector         details)
{
    Inherited::changed(whichField, origin, details);

    if(whichField & PersistanceFieldMask)
    {
        getPerlinDistribution()->setPersistance(getPersistance());
    } 
    else if (whichField & FrequencyFieldMask)
    {
        getPerlinDistribution()->setFrequency(getFrequency());
    } 
    else if (whichField & InterpolationTypeFieldMask)
    {
        getPerlinDistribution()->setInterpolationType(getInterpolationType());
    } 
    else if (whichField & OctavesFieldMask)
    {
        getPerlinDistribution()->setOctaves(getOctaves());
    } 
    else if (whichField & AmplitudeFieldMask )
    {
        getPerlinDistribution()->setAmplitude(getAmplitude());
    }
    else if (whichField & PhaseFieldMask )
    {
        getPerlinDistribution()->setPhase(getPhase()[0]);
    }
}
Example #3
0
float synthesize(Grain* grain){
	//TODO: lerp
	if(grain->samplesRemaining){
		while(grain->readIndex < 0){
			grain->readIndex += (DELAYLINE_SAMPLES);
		}
		while(grain->readIndex >= (DELAYLINE_SAMPLES)){
			grain->readIndex -= (DELAYLINE_SAMPLES);
		}
		float percentageComplete = (float)(grain->samplesRemaining)/(float)(grain->totalSamples);
		float amp = getAmplitude(percentageComplete,grain->envelopeType);
		
		//linear interpolation:
		int floorIndex = floorf(grain->readIndex);
		float r = grain->readIndex - floorIndex;
		float n0 = delayLine[floorIndex];
		float n1 = delayLine[(floorIndex + 1) % DELAYLINE_SAMPLES];
		float out = (((1 - r) * n0) + (r * n1)) * amp;

		grain->readIndex += (1 * grain->direction * grain->speed);
		grain->samplesRemaining--;
		//fprintf(stdout,"Outvalue: %f\n", out);
		return out;
	}
	else{
		return 0;
	}
}
  void processAudio(AudioBuffer& buf){
    float minf = getParameterValue(PARAMETER_A)*0.1 + 0.001;
    float maxf = min(0.4, minf + getParameterValue(PARAMETER_B)*0.2);
    // range should be exponentially related to minf
    //    int tones = getParameterValue(PARAMETER_C)*(TONES-1) + 1;
    int tones = 12;
    float spread = getParameterValue(PARAMETER_C) + 1.0;
    float rate = 1.0 + (getParameterValue(PARAMETER_D) - 0.5)*0.00002;
    int size = buf.getSize();
    FloatArray out = buf.getSamples(LEFT_CHANNEL);
    float amp;
    for(int t=1; t<tones; ++t)
      inc[t] = inc[t-1]*spread;
    for(int i=0; i<size; ++i){
      for(int t=0; t<tones; ++t){
	amp = getAmplitude((inc[t]-minf)/(maxf-minf));
	out[i] += amp * getWave(acc[t]);
        acc[t] += inc[t];
	if(acc[t] > 1.0)
	  acc[t] -= 1.0;
	else if(acc[t] < 0.0)
	  acc[t] += 1.0;
        inc[t] *= rate;
      }
    }
    if(inc[0] > maxf)
      inc[0] = minf;
      // while(inc[0] > minf)
      // 	inc[0] *= 0.5;
    else if(inc[0] < minf)
      inc[0] = maxf;
      // while(inc[0] < maxf)
      // 	inc[0] *= 2.0;
  }
bool TurbulenceParticleAffector::affect(ParticleSystemRefPtr System, Int32 ParticleIndex, const Time& elps)
{
	if(getBeacon() != NULL)
	{	
		Matrix BeaconToWorld(getBeacon()->getToWorld());
		Vec3f translation, tmp;
		Quaternion tmp2;
		BeaconToWorld.getTransform(translation,tmp2,tmp,tmp2);

		Pnt3f particlePos = System->getPosition(ParticleIndex);
		Real32 distanceFromAffector = particlePos.dist(Pnt3f(translation.x(),translation.y(),translation.z())); 

		if((getMaxDistance() < 0.0) || (distanceFromAffector <= getMaxDistance())) //only affect the particle if it is in range
		{	
			Real32 Xparam, Yparam, Zparam;

			Pnt3f pos(System->getPosition(ParticleIndex));
			getPerlinDistribution()->setPhase(getPhase()[0]);
			Xparam = getPerlinDistribution()->generate(pos[0]);
			getPerlinDistribution()->setPhase(getPhase()[1]);
			Yparam = getPerlinDistribution()->generate(pos[1]);
			getPerlinDistribution()->setPhase(getPhase()[2]);
			Zparam = getPerlinDistribution()->generate(pos[2]);

			Vec3f fieldAffect(Vec3f(Xparam, Yparam, Zparam));
			fieldAffect = fieldAffect * (getAmplitude()*
                                          (elps/(OSG::osgClamp<Real32>(1.0f,std::pow(distanceFromAffector,getAttenuation()),TypeTraits<Real32>::getMax()))));

			System->setVelocity(System->getVelocity(ParticleIndex) + fieldAffect, ParticleIndex);

		} // end distance conditional
	} // end null beacon conditional

	return false;
}
bool TurbulenceParticleAffector::distributionIsNotInitialized(void)
{
    PerlinNoiseDistribution1DRefPtr dist(getPerlinDistribution());

    return (1.0f != getAmplitude() ||
            dist->getPersistance() != getPersistance() ||
            dist->getOctaves() != getOctaves() ||
            dist->getInterpolationType() != getInterpolationType() ||
            dist->getFrequency() != getFrequency());
}
Example #7
0
void BatManager::locatePrey(std::vector<Prey*> preys) {
	identifiedPreys.clear();
	for (auto const& prey : preys) {
		double targetStrengthh = prey->targetStrength;

		double soundInt = getAmplitude(prey->currentState.x, prey->currentState.y, prey->targetStrength);
		if (soundInt>=hearingThreshold) {
			double dist = Distance(currentState.x, currentState.y, prey->currentState.x, prey->currentState.y);
			identifiedPreys.insert(std::pair<double, Prey*>(dist, prey));
		}
	}
}
	//-----------------------------------------------------------------------
	void ForceField::setForceFieldType(const ForceField::ForceFieldType forceFieldType)
	{
		if (mForceFieldCalculationFactory)
		{
			Ogre::ushort octaves = getOctaves();
			double frequency = getFrequency();
			double amplitude = getAmplitude();
			double persistence = getPersistence();
			unsigned int forceFieldSize = getForceFieldSize();
			Ogre::Vector3 worldSize = getWorldSize();
			
			initialise(forceFieldType, forceFieldSize, octaves, frequency, amplitude, persistence, worldSize);
		}
	}
void RandomMovementParticleAffector::onCreate(const RandomMovementParticleAffector *source)
{
    if(source != NULL)
    {
        //Shader Chunk
        PerlinNoiseDistribution1DRefPtr TheNoiseDist = PerlinNoiseDistribution1D::create();
        TheNoiseDist->setFrequency(getFrequency());
        TheNoiseDist->setPersistance(getPersistance());
        TheNoiseDist->setOctaves(getOctaves());
        TheNoiseDist->setAmplitude(getAmplitude());
        TheNoiseDist->setInterpolationType(getInterpolationType());
        TheNoiseDist->setPhase(getPhase().x());
        TheNoiseDist->setUseSmoothing(true);

        setPerlinDistribution(TheNoiseDist);
    }
}
void ofxFft::draw(float x, float y, float width, float height) {
	ofPushStyle();
	ofPushMatrix();

	ofTranslate(x, y);
	ofNoFill();
	ofRect(0, 0, width, height);
	ofTranslate(0, height);
	ofScale(width / binSize, -height);
	ofBeginShape();
	getAmplitude();
	for (int i = 0; i < binSize; i++)
		ofVertex(i, amplitude[i]);
	ofEndShape();

	ofPopMatrix();
	ofPopStyle();
}
Example #11
0
/********************************************************************
* Function Name: writeOutputGradient
* Example:		writeOutputGradient( &outputGradient, shift )
* Purpose: 	writes an output gradient for a compound gradient axis
* Input
*	Formal:	outputGradient	- pointer to a output gradient
*				shift
*	Private:	none
*	Public:	none
* Output
*	Return:	none
*	Formal:	none
*	Private:	none
*	Public:	none
* Notes:		none
*********************************************************************/
double writeOutputGradientDBStr(SGL_GRADIENT_T *aOutputGradient,
			double aStartTime, double aDuration, char *aGradParams )
{
   char *gradParams;
   char _tempname[MAX_STR];
   int	_error;
	int _startIdx, _endIdx;
	
	double *_vec;
	long _nPts;
	
	_vec = getDataPoints( aOutputGradient );
	_nPts = getNumPoints( aOutputGradient );
	
	_startIdx = (long)ROUND(aStartTime/GRADIENT_RES);
	_endIdx = (long)ROUND((aStartTime + aDuration)/GRADIENT_RES);

	if( _startIdx >= 0 && _endIdx <= _nPts )
	{
		_vec += _startIdx;
		_nPts = _endIdx - _startIdx;
	}
   
	gradParams = NULL;
	appendFormattedString( &gradParams, "%g %ld", getAmplitude(aOutputGradient), _nPts);

	if( aGradParams != NULL )
	{
		appendFormattedString( &gradParams, " %s", aGradParams );
	}

	if( !gradShapeWritten( getName(aOutputGradient), gradParams, _tempname ) )
	{
		setName( aOutputGradient, _tempname );
		_error = writeToDisk( _vec, _nPts, _vec[0],
      					getResolution(aOutputGradient), 1, getName(aOutputGradient) );
	}
	else
	{
		setName( aOutputGradient, _tempname );
	}
	
	return _nPts*GRADIENT_RES;
}
Example #12
0
float* ofxFftw::fft(float* input, fftMode mode) {
	memcpy(fftIn, input, sizeof(float) * signalSize);
	runWindow(fftIn);

	fftwf_execute(fftPlan);

	// explanation of halfcomplex format:
	// http://www.fftw.org/fftw3_doc/The-Halfcomplex_002dformat-DFT.html
	setReal(fftOut); // will only copy the first half
	imag[0] = 0;
	for(int i = 1; i < bins; i++)
		imag[i] = fftOut[signalSize - i];
	cartesianReady = true;
	polarReady = false;
	if(mode == OF_FFT_CARTESIAN)
		return getReal();
	else if(mode == OF_FFT_POLAR)
		return getAmplitude();
}
Example #13
0
bool BatManager::echolocateBat(BatManager* bat) {
	bool isSeen = false;
	double amplitude = getAmplitude(bat->currentState.x, bat->currentState.y, bat->echo.targetStrength);
	if (amplitude >= hearingThreshold) {
		if (identifiedBats.size()==1000)
			identifiedBats.erase(identifiedBats.begin());
		identifiedBats.insert(std::pair<int, BatManager*>(time + 1, bat));
		isSeen = true;
	}
	std::map<int, BatManager*>::iterator potentialLeader = identifiedBats.find(time+1-delay);
	if (potentialLeader != identifiedBats.end()) {
		flight = 1;
		leader = potentialLeader->second;
	}
	else {
		flight = 0;
		leader = NULL;
	}
	return isSeen;
}
Example #14
0
vrpn_HapticVector  InstantBuzzEffect::calcEffectForce(void) {
#else
gstVector InstantBuzzEffect::calcEffectForce(void *phantom) {
#endif
    // No force if inactive
    if (!active) {
      return vrpn_HapticVector(0,0,0);
    }

// XXX Needs to be implemented on non-Windows platforms.  Use
// the gettimeofday() function to calculate timing on those platforms.
// We might want to switch to vrpn_gettimeofday() on all platforms, since
// that is now implemented on Windows.
#ifdef	_WIN32
    LARGE_INTEGER counter;
	
    if (currentPerformanceFrequency.HighPart == 0 && currentPerformanceFrequency.LowPart == 0) {
      return vrpn_HapticVector(0,0,0);
    }

    if (QueryPerformanceCounter(&counter) != TRUE){
	fprintf(stderr, "unable to get perfo counter\n");
	return vrpn_HapticVector(0,0,0);
    }

    double elapsedSec =  (counter.QuadPart - debut.QuadPart) / (double) currentPerformanceFrequency.QuadPart;
    if (elapsedSec < getDuration()) {
	double currentPart = (counter.QuadPart*getFrequency()/currentPerformanceFrequency.QuadPart);
	currentPart = (currentPart-(long)currentPart)*2*PI;
	double currentForce = sin(currentPart);
	double force = currentForce*getAmplitude();
	return vrpn_HapticVector( x*force, y*force, z*force );
    }
#endif

      return vrpn_HapticVector(0,0,0);
}
Example #15
0
void
Effect::process(const synthclone::Zone &/*zone*/,
                synthclone::SampleInputStream &inputStream,
                synthclone::SampleOutputStream &outputStream)
{
    synthclone::SampleFrameCount frames = inputStream.getFrames();
    float sampleRate = static_cast<float>(inputStream.getSampleRate());
    synthclone::SampleFrameCount fadeInFrames = fadeInEnabled ?
        static_cast<synthclone::SampleFrameCount>(fadeInTime * sampleRate) : 0;
    synthclone::SampleFrameCount fadeOutFrames = fadeOutEnabled ?
        static_cast<synthclone::SampleFrameCount>(fadeOutTime * sampleRate) : 0;
    synthclone::SampleFrameCount totalFadeFrames = fadeInFrames + fadeOutFrames;

    qDebug() << "\tfade in frames:" << fadeInFrames;
    qDebug() << "\t fade out frames:" << fadeOutFrames;

    // If the amount of frames spent fading is greater than the number of total
    // frames, then shorten the fades proportionally.  If anyone has a better
    // suggestion, I'm all ears.
    if (totalFadeFrames > frames) {

        qDebug() << "adjusting fade frames";

        fadeInFrames = static_cast<synthclone::SampleFrameCount>
            (static_cast<float>(fadeInFrames) *
             (static_cast<float>(frames) /
              static_cast<float>(totalFadeFrames)));
        fadeOutFrames = frames - fadeInFrames;

        qDebug() << "\tfade in frames:" << fadeInFrames;
        qDebug() << "\t fade out frames:" << fadeOutFrames;

    }

    synthclone::SampleChannelCount channels = inputStream.getChannels();
    QScopedArrayPointer<float> audioDataPtr(new float[channels]);
    float *audioData = audioDataPtr.data();
    synthclone::SampleFrameCount currentFrame = 0;
    synthclone::SampleFrameCount framesRead;
    float volume;
    if (fadeInFrames) {

        qDebug() << "\tapplying fade in ...";

        emit statusChanged(tr("Creating fade-in of sample ..."));
        for (; currentFrame < fadeInFrames; currentFrame++) {
            framesRead = inputStream.read(audioData, 1);
            assert(framesRead == 1);
            volume = getAmplitude(fadeInStartVolume *
                                  (1.0 - (static_cast<float>(currentFrame + 1) /
                                          static_cast<float>(fadeInFrames))));
            for (int i = 0; i < channels; i++) {
                audioData[i] *= volume;
            }
            outputStream.write(audioData, 1);
            emit progressChanged(static_cast<float>(currentFrame + 1) /
                                 static_cast<float>(frames));
        }
    }
    synthclone::SampleFrameCount fadeOutStartFrame = frames - fadeOutFrames;
    synthclone::SampleFrameCount copyFrames = fadeOutStartFrame - currentFrame;

    qDebug() << "\tcopy frames:" << copyFrames;
    qDebug() << "\tfade out start frame:" << fadeOutStartFrame;

    if (copyFrames) {

        qDebug() << "copying frames ...";

        emit statusChanged(tr("Writing sample ..."));
        copyStartFrame = currentFrame;
        copyTotalFrames = frames;
        synthclone::SampleCopier copier;
        connect(&copier,
                SIGNAL(copyProgress(synthclone::SampleFrameCount,
                                    synthclone::SampleFrameCount)),
                SLOT(handleCopyProgress(synthclone::SampleFrameCount,
                                        synthclone::SampleFrameCount)),
                Qt::DirectConnection);
        copier.copy(inputStream, outputStream, copyFrames);
    }
    currentFrame += copyFrames;
    if (fadeOutFrames) {

        qDebug() << "\tapplying fade out ...";

        emit statusChanged(tr("Creating fade-out of sample ..."));
        for (; currentFrame < frames; currentFrame++) {
            framesRead = inputStream.read(audioData, 1);
            assert(framesRead == 1);
            volume = getAmplitude(fadeOutEndVolume *
                                  (static_cast<float>(currentFrame + 1 -
                                                      fadeOutStartFrame) /
                                   static_cast<float>(fadeOutFrames)));
            for (int i = 0; i < channels; i++) {
                audioData[i] *= volume;
            }
            outputStream.write(audioData, 1);
            emit progressChanged(static_cast<float>(currentFrame + 1) /
                                 static_cast<float>(frames));
        }
    }
    emit progressChanged(0.0);
    emit statusChanged("");

    qDebug() << "/Effect::process";

}
Example #16
0
 void SineSP::inspectAux(std::stringstream& ss, int level) {
   inspectIndent(ss, level); ss << "getAmplitude() = " << getAmplitude() << std::endl;
   inspectIndent(ss, level); ss << "getFrequency() = " << getFrequency() << std::endl;
   inspectIndent(ss, level); ss << "getPhase() = " << getPhase() << std::endl;
 }
Real32 PerlinNoiseDistribution2D::generate(Pnt2f t) const
{	
	return calcPerlinNoise(t,getAmplitude(),getFrequency(),getPhase(),getPersistance(),getOctaves(),getInterpolationType(),getUseSmoothing());
}