Beispiel #1
0
    int perform(jack_nframes_t frames)
    {
        if (unlikely(!time_is_synced)) {
            engine_functor::sync_clock();
            time_is_synced = true;
        }

        /* get port regions */
        jack_default_audio_sample_t ** inputs   = (jack_default_audio_sample_t **)alloca(input_channels * sizeof(jack_default_audio_sample_t*));
        jack_default_audio_sample_t ** outputs  = (jack_default_audio_sample_t **)alloca(output_channels * sizeof(jack_default_audio_sample_t*));
        for (uint16_t i = 0; i != input_channels; ++i)
            inputs[i] = (jack_default_audio_sample_t*) jack_port_get_buffer(input_ports[i], frames);

        for (uint16_t i = 0; i != output_channels; ++i)
            outputs[i] = (jack_default_audio_sample_t*) jack_port_get_buffer(output_ports[i], frames);

        jack_nframes_t processed = 0;
        while (processed != frames) {
            super::fetch_inputs((const float**)inputs, blocksize_, input_channels);
            engine_functor::run_tick();
            super::deliver_outputs(outputs, blocksize_, output_channels);
            processed += blocksize_;
        }

        cpu_time_accumulator.update(jack_cpu_load(client));

        return 0;
    }
Beispiel #2
0
float cpuLoad(void)
{
    if (client != NULL) {
        float load = (float)jack_cpu_load(client);
        return load;
    }
    return 0.0f;
}
Beispiel #3
0
static PyObject* get_cpu_load(PyObject* self, PyObject* args)
{
    pyjack_client_t * client = self_or_global_client(self);
    if(client->pjc == NULL) {
        PyErr_SetString(JackNotConnectedError, "Jack connection has not yet been established.");
        return NULL;
    }

    float cpu_load = jack_cpu_load(client->pjc);

    return Py_BuildValue("f", cpu_load);
}
int
process (jack_nframes_t nframes, void *arg)
{
	jack_default_audio_sample_t *in, *out;
	int i;

	in = jack_port_get_buffer (input_port, nframes);
	out = jack_port_get_buffer (output_port, nframes);

	memcpy (out, in, sizeof (jack_default_audio_sample_t) * nframes);

	for (i = 0; i < loopsize; ++i) {
		fooey (nframes);
	}

	last_load = jack_cpu_load (client);

	if ((at_loop += nframes) >= at_loop_size) {
		if (last_load < 25.0f) {
			loopsize *= 2;
		} else if (last_load < 50.0f) {
			loopsize = (int) (1.5 * loopsize);
		} else if (last_load < 90.0f) {
			loopsize += (int) (0.10 * loopsize);
		} else if (last_load < 95.0f) {
			loopsize += (int) (0.05 * loopsize);
		} else {
			loopsize += (int) (0.001 * loopsize);
		}
		at_loop = 0;
		printf ("loopsize = %d\n", loopsize);
	}

	if (xrun_occured) {
		if (consecutive_xruns == 0) {
			first_xrun = last_load;
		}
		consecutive_xruns++;
	}

	xrun_occured = 0;

	if (consecutive_xruns >= 10) {
		fprintf (stderr, "Stopping with load = %f (first xrun at %f)\n", last_load, first_xrun);
		exit (0);
	}

	return 0;
}
Beispiel #5
0
static int _cpu_load(ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj* const *objv) {
  _t *dp = (_t *)clientData;
  if (argc != 2) return fw_error_str(interp, "jack-client cpu-load");
  Tcl_SetObjResult(interp, Tcl_NewDoubleObj(jack_cpu_load(dp->fw.client)));
  return TCL_OK;
}
Beispiel #6
0
void SC_JackDriver::Run()
{
	jack_client_t* client = mClient;
	World* world = mWorld;

#ifdef SC_JACK_USE_DLL
	mDLL.Update(secondsSinceEpoch(getTime()));
#if SC_JACK_DEBUG_DLL
	static int tick = 0;
	if (++tick >= 10) {
		tick = 0;
		scprintf("DLL: t %.6f p %.9f sr %.6f e %.9f avg(e) %.9f inc %.9f\n",
				 mDLL.PeriodTime(), mDLL.Period(), mDLL.SampleRate(),
				 mDLL.Error(), mDLL.AvgError(), mOSCincrement * kOSCtoSecs);
	}
#endif
#else
	HostTime hostTime = getTime();

	double hostSecs = secondsSinceEpoch(hostTime);
	double sampleTime = (double)(jack_frame_time(client) + jack_frames_since_cycle_start(client));

	if (mStartHostSecs == 0) {
		mStartHostSecs = hostSecs;
		mStartSampleTime = sampleTime;
	} else {
		double instSampleRate = (sampleTime - mPrevSampleTime) / (hostSecs - mPrevHostSecs);
		double smoothSampleRate = mSmoothSampleRate;
		smoothSampleRate = smoothSampleRate + 0.002 * (instSampleRate - smoothSampleRate);
		if (fabs(smoothSampleRate - mSampleRate) > 10.) {
			smoothSampleRate = mSampleRate;
		}
		mOSCincrement = (int64)(mOSCincrementNumerator / smoothSampleRate);
		mSmoothSampleRate = smoothSampleRate;
#if 0
		double avgSampleRate = (sampleTime - mStartSampleTime)/(hostSecs - mStartHostSecs);
		double jitter = (smoothSampleRate * (hostSecs - mPrevHostSecs)) - (sampleTime - mPrevSampleTime);
		double drift = (smoothSampleRate - mSampleRate) * (hostSecs - mStartHostSecs);
#endif
	}

	mPrevHostSecs = hostSecs;
	mPrevSampleTime = sampleTime;
#endif

	try {
		mFromEngine.Free();
		mToEngine.Perform();
		mOscPacketsToEngine.Perform();

		int numInputs = mInputList->mSize;
		int numOutputs = mOutputList->mSize;
		jack_port_t **inPorts = mInputList->mPorts;
		jack_port_t **outPorts = mOutputList->mPorts;
		sc_jack_sample_t **inBuffers = mInputList->mBuffers;
		sc_jack_sample_t **outBuffers = mOutputList->mBuffers;

		int numSamples = NumSamplesPerCallback();
		int bufFrames = mWorld->mBufLength;
		int numBufs = numSamples / bufFrames;

		float *inBuses = mWorld->mAudioBus + mWorld->mNumOutputs * bufFrames;
		float *outBuses = mWorld->mAudioBus;
		int32 *inTouched = mWorld->mAudioBusTouched + mWorld->mNumOutputs;
		int32 *outTouched = mWorld->mAudioBusTouched;

		int minInputs = sc_min(numInputs, (int)mWorld->mNumInputs);
		int minOutputs = sc_min(numOutputs, (int)mWorld->mNumOutputs);

		int bufFramePos = 0;

		// cache I/O buffers
		for (int i = 0; i < minInputs; ++i) {
			inBuffers[i] = (sc_jack_sample_t*)jack_port_get_buffer(inPorts[i], numSamples);
		}

		for (int i = 0; i < minOutputs; ++i) {
			outBuffers[i] = (sc_jack_sample_t*)jack_port_get_buffer(outPorts[i], numSamples);
		}

		// main loop
#ifdef SC_JACK_USE_DLL
		int64 oscTime = mOSCbuftime = (int64)((mDLL.PeriodTime() - mMaxOutputLatency) * kSecondsToOSCunits + .5);
// 		int64 oscInc = mOSCincrement = (int64)(mOSCincrementNumerator / mDLL.SampleRate());
		int64 oscInc = mOSCincrement = (int64)((mDLL.Period() / numBufs) * kSecondsToOSCunits + .5);
		mSmoothSampleRate = mDLL.SampleRate();
		double oscToSamples = mOSCtoSamples = mSmoothSampleRate * kOSCtoSecs /* 1/pow(2,32) */;
#else
		int64 oscTime = mOSCbuftime = OSCTime(hostTime) - (int64)(mMaxOutputLatency * kSecondsToOSCunits + .5);
		int64 oscInc = mOSCincrement;
		double oscToSamples = mOSCtoSamples;
#endif

		for (int i = 0; i < numBufs; ++i, mWorld->mBufCounter++, bufFramePos += bufFrames) {
			int32 bufCounter = mWorld->mBufCounter;
			int32 *tch;

			// copy+touch inputs
			tch = inTouched;
			for (int k = 0; k < minInputs; ++k) {
				sc_jack_sample_t *src = inBuffers[k] + bufFramePos;
				float *dst = inBuses + k * bufFrames;
				for (int n = 0; n < bufFrames; ++n) {
					*dst++ = *src++;
				}
				*tch++ = bufCounter;
			}

			// run engine
			int64 schedTime;
			int64 nextTime = oscTime + oscInc;

			while ((schedTime = mScheduler.NextTime()) <= nextTime) {
				float diffTime = (float)(schedTime - oscTime) * oscToSamples + 0.5;
				float diffTimeFloor = floor(diffTime);
				world->mSampleOffset = (int)diffTimeFloor;
				world->mSubsampleOffset = diffTime - diffTimeFloor;

				if (world->mSampleOffset < 0) world->mSampleOffset = 0;
				else if (world->mSampleOffset >= world->mBufLength) world->mSampleOffset = world->mBufLength-1;

				SC_ScheduledEvent event = mScheduler.Remove();
				event.Perform();
			}

			world->mSampleOffset = 0;
			world->mSubsampleOffset = 0.f;
			World_Run(world);

			// copy touched outputs
			tch = outTouched;
			for (int k = 0; k < minOutputs; ++k) {
				sc_jack_sample_t *dst = outBuffers[k] + bufFramePos;
				if (*tch++ == bufCounter) {
					float *src = outBuses + k * bufFrames;
					for (int n = 0; n < bufFrames; ++n) {
						*dst++ = *src++;
					}
				} else {
					for (int n = 0; n < bufFrames; ++n) {
						*dst++ = 0.0f;
					}
				}
			}

			// advance OSC time
			mOSCbuftime = oscTime = nextTime;
		}
	} catch (std::exception& exc) {
		scprintf("%s: exception in real time: %s\n", kJackDriverIdent, exc.what());
	} catch (...) {
		scprintf("%s: unknown exception in real time\n", kJackDriverIdent);
	}

	double cpuUsage = (double)jack_cpu_load(mClient);
	mAvgCPU = mAvgCPU + 0.1 * (cpuUsage - mAvgCPU);
	if (cpuUsage > mPeakCPU || --mPeakCounter <= 0) {
		mPeakCPU = cpuUsage;
		mPeakCounter = mMaxPeakCounter;
	}

	mAudioSync.Signal();
}
    float JackAudioSystem::dsp_load()
    {
	if( !_client )  return -1;
	return jack_cpu_load(_client)/100.0;
    }
Beispiel #8
0
    int JackProfiler::Process(jack_nframes_t nframes, void* arg)
    {
        JackProfiler* profiler = static_cast<JackProfiler*>(arg);
        
        if (profiler->fCPULoadPort) {
            float* buffer_cpu_load = (float*)jack_port_get_buffer(profiler->fCPULoadPort, nframes);
            float cpu_load = jack_cpu_load(profiler->fClient);
            for (unsigned int i = 0; i < nframes; i++) {
                buffer_cpu_load[i] = cpu_load / 100.f;
            }
        }
 
    #ifdef JACK_MONITOR      
        
        JackEngineControl* control = JackServerGlobals::fInstance->GetEngineControl();
        JackEngineProfiling* engine_profiler = &control->fProfiler;
        JackTimingMeasure* measure = engine_profiler->GetCurMeasure();
        
       if (profiler->fLastMeasure && profiler->fMutex.Trylock()) {
        
            if (profiler->fDriverPeriodPort) {
                float* buffer_driver_period = (float*)jack_port_get_buffer(profiler->fDriverPeriodPort, nframes);
                float value1 = (float(measure->fPeriodUsecs) - float(measure->fCurCycleBegin - profiler->fLastMeasure->fCurCycleBegin)) / float(measure->fPeriodUsecs);
                for (unsigned int i = 0; i < nframes; i++) {
                    buffer_driver_period[i] = value1;
                }
            }
            
            if (profiler->fDriverEndPort) {
                float* buffer_driver_end_time = (float*)jack_port_get_buffer(profiler->fDriverEndPort, nframes);
                float value2 = (float(measure->fPrevCycleEnd - profiler->fLastMeasure->fCurCycleBegin)) / float(measure->fPeriodUsecs);
                for (unsigned int i = 0; i < nframes; i++) {
                    buffer_driver_end_time[i] = value2;
                }
            }
            
            std::map<std::string, JackProfilerClient*>::iterator it;
            for (it = profiler->fClientTable.begin(); it != profiler->fClientTable.end(); it++) {
                int ref = (*it).second->fRefNum;
                long d5 = long(measure->fClientTable[ref].fSignaledAt - profiler->fLastMeasure->fCurCycleBegin);
                long d6 = long(measure->fClientTable[ref].fAwakeAt - profiler->fLastMeasure->fCurCycleBegin);
                long d7 = long(measure->fClientTable[ref].fFinishedAt - profiler->fLastMeasure->fCurCycleBegin);
                  
                float* buffer_scheduling = (float*)jack_port_get_buffer((*it).second->fSchedulingPort, nframes);
                float value3 = float(d6 - d5) / float(measure->fPeriodUsecs);
                jack_log("Scheduling %f", value3);
                for (unsigned int i = 0; i < nframes; i++) {
                    buffer_scheduling[i] = value3;
                }
                  
                float* buffer_duration = (float*)jack_port_get_buffer((*it).second->fDurationPort, nframes);
                float value4 = float(d7 - d6) / float(measure->fPeriodUsecs);
                jack_log("Duration %f", value4);
                for (unsigned int i = 0; i < nframes; i++) {
                    buffer_duration[i] = value4;
                }
            }
            
            profiler->fMutex.Unlock();
        }
        profiler->fLastMeasure = measure;
    #endif
        return 0;
    }
Beispiel #9
0
float JackCpp::AudioIO::getCpuLoad(){
	return jack_cpu_load(mJackClient);
}
Beispiel #10
0
static SCM get_duty_cycle() {
	if (use_jack)
		return scm_from_double((double)jack_cpu_load(jack_client));
	return scm_from_double(duty_cycle * 100);
	}
Beispiel #11
0
float luajack_cpu_load(luajack_t *client) 
	{
	cud_t *cud = get_cud(client);	
	if(!cud) return 0;
	return jack_cpu_load(cud->client);
	}