void SampleAudioSource::init( const String& filename, int loops, SampleTime begin, SampleTime end, SampleTime length, Envelope* gain, Envelope* pan, float sampleRate, int channels) { source_ = getReader(filename, begin, end, sampleRate, channels); if (source_) { length_ = SampleTime(source_->getTotalLength() * loops); if (length >= 0) length_ = jmin(length_, length); } else { const char* error = File(filename).exists() ? "Don't understand file format for " : "File doesn't exist: "; error_ = (error + filename).toStdString(); } panGainPlayer_ = make_unique<PanGainPlayer>(gain, pan); }
void raytrace(int argc, char **argv) { int x, y, *tmpsamp, i, sampleno=CELLX*CELLY; Pixel *tmppix; Float usertime, systime, lasttime, upos, vpos; Float samples[CELLX*CELLY*2]; Pixel acc, tmp; /* * If this is the first frame, * allocate scanlines, etc. */ if (Options.framenum == Options.startframe) RaytraceInit(); /* * The top-level ray TopRay always has as its origin the * eye position and as its medium NULL, indicating that it * is passing through a medium with index of refraction * equal to DefIndex. */ TopRay.pos = Camera.pos; TopRay.media = (Medium *)0; TopRay.depth = 0; lasttime = 0; for (y=0; y < Screen.ysize; y++) { for (x = 0; x < Screen.xsize; x++) { jitter(CELLX, CELLY, samples); acc.r = acc.g = acc.b = acc.alpha = 0; for (i=0 ; i<sampleno ; i++) { vpos = y + Screen.miny + samples[(i<<1)+1]; upos = x + Screen.minx + samples[i<<1]; TopRay.time = SampleTime(0); SampleScreen(upos, vpos, &TopRay, &tmp, 0); acc.r += tmp.r; acc.g += tmp.g; acc.b += tmp.b; } pix[x].r = acc.r/sampleno; /* box filter, or average */ pix[x].g = acc.g/sampleno; pix[x].b = acc.b/sampleno; pix[x].alpha = 0; } PictureWriteLine(pix); /* write the scanline */ if ((y+Screen.miny-1) % Options.report_freq == 0) { fprintf(Stats.fstats,"Finished line %d (%lu rays", y+Screen.miny-1, Stats.EyeRays); if (Options.verbose) { /* * Report total CPU and split times. */ RSGetCpuTime(&usertime, &systime); fprintf(Stats.fstats,", %2.2f sec,", usertime+systime); fprintf(Stats.fstats," %2.2f split", usertime+systime-lasttime); lasttime = usertime+systime; } } fprintf(Stats.fstats,")\n"); (void)fflush(Stats.fstats); } }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // AUPulseDetector::AUPulseDetectorKernel::Process // // pass-through audio // do spike detection //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void AUPulseDetector::AUPulseDetectorKernel::Process(const Float32 *inSourceP, Float32 *inDestP, UInt32 inFramesToProcess, UInt32 inNumChannels, bool &ioSilence ) { if (GetParameter (kDoPulseDetection) == 0) { memset (inDestP, 0, (inFramesToProcess * sizeof(Float32))); return; } switch (mWhichMode) { case kDetectMode: { Float64 now = SampleTime(); Float64 sampleRate = GetSampleRate(); if ((now - mPulseStartTime) > (sampleRate * GetParameter (kPulseRestTime))) { mDoneClean = 0; mWhichMode = kCleanMode; mWasSuccessful = false; mParentObject->PropertyChanged (kAUPulseMetricsPropertyID, kAudioUnitScope_Global, 0); break; } float pulseThreshold = GetParameter (kPulseThreshold); for (unsigned int i = 0; i < inFramesToProcess; ++i) { Float32 inputSample = inSourceP[i]; if(fabs(inputSample) >= pulseThreshold) { mLastMeasurement = UInt32(now + i - mPulseStartTime); mTotalMeasurements += mLastMeasurement; mTotalMeasurementsSquared += pow (mLastMeasurement, 2); mNumMeasurements++; if (mLastMeasurement > mMaxTime) mMaxTime = mLastMeasurement; if (mLastMeasurement < mMinTime) mMinTime = mLastMeasurement; mDoneClean = 0; mWhichMode = kCleanMode; mLastFrames = inFramesToProcess; mWasSuccessful = true; mParentObject->DetectedPulse (mPulseStartTime, mLastMeasurement); break; } } memset (inDestP, 0, (inFramesToProcess * sizeof(Float32))); } break; case kCleanMode: { if (mDoneClean == 0) { float secs = GetParameter (kPulseRestTime); mDoneClean = SInt32(secs * GetSampleRate()); } memset (inDestP, 0, (inFramesToProcess * sizeof(Float32))); ioSilence = true; mDoneClean -= inFramesToProcess; if (mDoneClean <= 0) mWhichMode = kEstablishMode; } break; case kEstablishMode: { memset (inDestP, 0, (inFramesToProcess * sizeof(Float32))); unsigned int pulseLength = (unsigned int)GetParameter (kPulseLength); if (pulseLength > inFramesToProcess) pulseLength = inFramesToProcess; for (unsigned int i = (inFramesToProcess - pulseLength); i < inFramesToProcess; ++i) inDestP[i] = 1.0; ioSilence = false; mWhichMode = kDetectMode; mPulseStartTime = SampleTime() + inFramesToProcess - pulseLength; } break; } }