Exemplo n.º 1
0
void MHmgphy::SolveSystem( vector<double> &X, int nTr )
{
	fflush( stdout );
	clock_t	t0 = StartTiming();

#if 0

	HmgphyFromHmgphy( X, nTr );

#else

	vector<double>	Xin;
	AFromTbl( Xin, nTr );
	clock_t			t2 = StartTiming();

	OnePassTH( _OnePass_HFromA, X, Xin, nTr*8, 16, 0.9 );
	printf( "Just HfromA\n" );
	PrintMagnitude( X );
	fflush( stdout );

	for( gpass = 0; gpass < 2000; ++gpass ) {	// 1000 - 2000 good
		Xin = X;
		OnePassTH( _OnePass_HFromH, X, Xin, nTr*8, 16, 0.9 );
		printf( "Done pass %d\n", gpass + 1 ); fflush( stdout );
	}

	PrintMagnitude( X );
	StopTiming( stdout, "Iters", t2 );
	fflush( stdout );
	myc.clear();

#endif

	StopTiming( stdout, "SolveH", t0 );
}
Exemplo n.º 2
0
// _______________________________________________________________________________________
//
void	CAAudioFile::WritePacketsFromCallback(
								AudioConverterComplexInputDataProc	inInputDataProc,
								void *								inInputDataProcUserData)
{
	while (true) {
		// keep writing until we exhaust the input (temporary stop), or produce no output (EOF)
		UInt32 numEncodedPackets = mIOBufferSizePackets;
		mIOBufferList.mBuffers[0].mDataByteSize = mIOBufferSizeBytes;
#if CAAUDIOFILE_PROFILE
		mInConverter = true;
#endif
		StartTiming(this, fill);
		OSStatus err = AudioConverterFillComplexBuffer(mConverter, inInputDataProc, inInputDataProcUserData,
					&numEncodedPackets, &mIOBufferList, mPacketDescs);
		ElapsedTime(this, fill, mTicksInConverter);
#if CAAUDIOFILE_PROFILE
		mInConverter = false;
#endif
		XThrowIf(err != 0 && err != kNoMoreInputRightNow, err, "convert audio packets (write)");
		if (numEncodedPackets == 0)
			break;
		Byte *buf = (Byte *)mIOBufferList.mBuffers[0].mData;
#if VERBOSE_IO
		printf("CAAudioFile::WritePacketsFromCallback: wrote %ld packets, %ld bytes\n", numEncodedPackets, mIOBufferList.mBuffers[0].mDataByteSize);
		if (mPacketDescs) {
			for (UInt32 i = 0; i < numEncodedPackets; ++i) {
				printf("  write packet %qd : offset %qd, length %ld\n", mPacketMark + i, mPacketDescs[i].mStartOffset, mPacketDescs[i].mDataByteSize);
#if VERBOSE_IO >= 2
				hexdump(buf + mPacketDescs[i].mStartOffset, mPacketDescs[i].mDataByteSize);
#endif
			}
		}
#endif
		StartTiming(this, write);
		XThrowIfError(AudioFileWritePackets(mAudioFile, mUseCache, mIOBufferList.mBuffers[0].mDataByteSize, mPacketDescs, mPacketMark, &numEncodedPackets, buf), "write audio file");
		ElapsedTime(this, write, mTicksInIO);
		mPacketMark += numEncodedPackets;
		//mNumberPackets += numEncodedPackets;
		if (mFileDataFormat.mFramesPerPacket > 0)
			mFrameMark += numEncodedPackets * mFileDataFormat.mFramesPerPacket;
		else {
			for (UInt32 i = 0; i < numEncodedPackets; ++i)
				mFrameMark += mPacketDescs[i].mVariableFramesInPacket;
		}
		if (err == kNoMoreInputRightNow)
			break;
	}
}
Exemplo n.º 3
0
// _______________________________________________________________________________________
//
void	CAAudioFile::Write(UInt32 numPackets, const AudioBufferList *data)
{
	if (mIOBufferList.mBuffers[0].mData == NULL) {
#if DEBUG
		printf("warning: CAAudioFile::AllocateBuffers called from WritePackets\n");
#endif
		AllocateBuffers();
	}

	if (mMode == kPreparingToWrite)
		mMode = kWriting;
	else
		XThrowIf(mMode != kWriting, kExtAudioFileError_InvalidOperationOrder, "can't write to this file");
	if (mConverter != NULL) {
		mWritePackets = numPackets;
		mWriteBufferList->SetFrom(data);
		WritePacketsFromCallback(WriteInputProc, this);
	} else {
		StartTiming(this, write);
		XThrowIfError(AudioFileWritePackets(mAudioFile, mUseCache, data->mBuffers[0].mDataByteSize,
						NULL, mPacketMark, &numPackets, data->mBuffers[0].mData),
						"write audio file");
		ElapsedTime(this, write, mTicksInIO);
#if VERBOSE_IO
		printf("CAAudioFile::WritePackets: wrote %ld packets at %qd, %ld bytes\n", numPackets, mPacketMark, data->mBuffers[0].mDataByteSize);
#endif
		//mNumberPackets =
		mPacketMark += numPackets;
		if (mFileDataFormat.mFramesPerPacket > 0)
			mFrameMark += numPackets * mFileDataFormat.mFramesPerPacket;
		// else: shouldn't happen since we're only called when there's no converter
	}
}
inline 
double RunTestImpl ( const char* title, void (*pfn)(), char* histogramFileName = no_histogram ) {
    double  time = 0, variation = 0, deviation = 0;
    size_t nrep = 1;
    while (true) {
        CalibrateTiming(NRUNS, 1, nrep);
        StartTiming(NRUNS, 1, nrep);
        pfn();
        StopTiming(time, variation, deviation);
        time -= util::base;
        if ( time > 1e-6 )
            break;
        nrep *= 2;
    }
    nrep *= (size_t)ceil(ONE_TEST_DURATION/time);
    CalibrateTiming(NRUNS, 1, nrep);    // sets util::base
    util::durations_t  t;
    StartTimingEx(t, NRUNS, 1, nrep);
        pfn();
    StopTiming(time, variation, deviation);
    if ( histogramFileName != (char*)-1 )
        util::trace_histogram(t, histogramFileName);
    double clean_time = time - util::base;
    if ( title ) {
        // Deviation (in percent) is calulated for the Gross time
        printf ("\n%-34s %.2e  %5.1f      ", title, clean_time, deviation);
        if ( util::sequential_time != 0  )
            //printf ("% .2e  ", clean_time - util::sequential_time);
            printf ("% 10.1f      ", 100*(clean_time - util::sequential_time)/util::sequential_time);
        else
            printf ("%*s ", util::rate_field_len, "");
        printf ("%-9u %1.6f    |", (unsigned)nrep, time * nrep);
    }
    return clean_time;
}
Exemplo n.º 5
0
	  static void *GenericThread(void *a) {
	       RunArgs * args = reinterpret_cast< RunArgs * > (a);
	       unsigned int threadOps = GetOperationCountPerThread();
	       _startBarrier->Join();
	  
	       if (args->id == 0) {
		    StartTiming();
	       }
     
	       _runBarrier->Join();    
     
	       if (threadOps == 0) {     
		    while (!isDone()) {
			 args->op_routine(args->id, args->arg, args->randSeed);
			 threadOps++;
		    }     
	       } else {
		    for (unsigned int j = 0; j < threadOps; j++) {
			 args->op_routine(args->id, args->arg, args->randSeed);
		    }
	       }
     
	       CompletedOperations(threadOps);
	       _runBarrier->Join();
	       return  NULL;
	  }
Exemplo n.º 6
0
double MIDASTimer::Start() {
	double current = GetTime();
	base_time = 0.0;
	StartTiming();
	running = true;
	return current;
}
Exemplo n.º 7
0
int main( int argc, char* argv[] )
{
	clock_t		t0 = StartTiming();

/* ------------------ */
/* Parse command line */
/* ------------------ */

	gArgs.SetCmdLine( argc, argv );

	TS.SetLogFile( flog );

	if( !ReadScriptParams( scr, gArgs.script, flog ) )
		goto exit;

	inv_scl = 1.0 / scr.crossscale;

/* ---------------- */
/* Read source data */
/* ---------------- */

	if( gArgs.zb >= 0 && gArgs.za < 0 )
		gArgs.za = gArgs.zb;

	TS.FillFromRgns( gArgs.srcmons, gArgs.idb, gArgs.zb, gArgs.za );

	fprintf( flog, "Got %d images.\n", (int)TS.vtil.size() );

	if( !TS.vtil.size() )
		goto exit;

	TS.SetTileDimsFromImageFile();
	TS.GetTileDims( gW, gH );

	t0 = StopTiming( flog, "ReadFile", t0 );

/* ------------- */
/* Sort by layer */
/* ------------- */

	TS.SortAll_z();

/* ----- */
/* Stuff */
/* ----- */

	ScapeStuff();

/* ---- */
/* Done */
/* ---- */

exit:
	fprintf( flog, "\n" );
	VMStats( flog );
	fclose( flog );

	return 0;
}
Exemplo n.º 8
0
double MIDASTimer::Resume() {
	if (running) return GetTime();
	else {
		running = true;
		StartTiming();
		return base_time;
	}
}
Exemplo n.º 9
0
void BossTimeOut::Fallingstone()
{
	FallingStone* stone = FallingStone::create();
	stone->setTag(20150924);
	stone->setPosition(randPos());
	UIController::getInstance()->getPhysicsLayer()->addChild(stone);

	StartTiming();
}
Exemplo n.º 10
0
void BossTimeOut::Fallingstone()
{
	//³å´Ì²»µôÂä
	bool isSpeedUp = GameData::getInstance()->getisSpeedUp();
	if (isSpeedUp)
	{
		unschedule(schedule_selector(BossTimeOut::speedUp));
		return;
	}

	FallingStone* stone = FallingStone::create();
	stone->setPosition(randPos());
	UIController::getInstance()->getPhysicsLayer()->addChild(stone);

	StartTiming();
}
double GetSeconds()
{
	if ( RecipCyclesPerSecond < 0.0f ) { StartTiming(); }

#ifndef ANDROID
	LARGE_INTEGER T1;
#else
	int64_t T1;
#endif

	QueryPerformanceCounter( &T1 );

#ifndef ANDROID
	return RecipCyclesPerSecond * ( double )( T1.QuadPart );
#else
	return RecipCyclesPerSecond * ( double )( T1 );
#endif
}
Exemplo n.º 12
0
/**
 * The run method is used internally to actually run the commands.
 * @return whether or not the command should stay within the {@link Scheduler}.
 */
bool Command::Run()
{
	if (!m_runWhenDisabled && m_parent == NULL && DriverStation::GetInstance()->IsDisabled())
		Cancel();

	if (IsCanceled())
		return false;

	if (!m_initialized)
	{
		m_initialized = true;
		StartTiming();
		_Initialize();
		Initialize();
	}
	_Execute();
	Execute();
	return !IsFinished();
}
Exemplo n.º 13
0
// _______________________________________________________________________________________
//
void	CAAudioFile::Read(UInt32 &ioNumPackets, AudioBufferList *ioData)
			// May read fewer packets than requested if:
			//		buffer is not big enough
			//		file does not contain that many more packets
			// Note that eofErr is not fatal, just results in 0 packets returned
			// ioData's buffer sizes may be shortened
{
	XThrowIf(mClientMaxPacketSize == 0, kExtAudioFileError_MaxPacketSizeUnknown, "client maximum packet size is 0");
	if (mIOBufferList.mBuffers[0].mData == NULL) {
#if DEBUG
		printf("warning: CAAudioFile::AllocateBuffers called from ReadPackets\n");
#endif
		AllocateBuffers();
	}
	UInt32 bufferSizeBytes = ioData->mBuffers[0].mDataByteSize;
	UInt32 maxNumPackets = bufferSizeBytes / mClientMaxPacketSize;
	// older versions of AudioConverterFillComplexBuffer don't do this, so do our own sanity check
	UInt32 nPackets = std::min(ioNumPackets, maxNumPackets);

	mMaxPacketsToRead = ~0UL;

	if (mClientDataFormat.mFramesPerPacket == 1) {  // PCM or equivalent
		while (mFramesToSkipFollowingSeek > 0) {
			UInt32 skipFrames = std::min(mFramesToSkipFollowingSeek, maxNumPackets);
			UInt32 framesPerPacket;
			if ((framesPerPacket=mFileDataFormat.mFramesPerPacket) > 0)
				mMaxPacketsToRead = (skipFrames + framesPerPacket - 1) / framesPerPacket;

			if (mConverter == NULL) {
				XThrowIfError(ReadInputProc(NULL, &skipFrames, ioData, NULL, this), "read audio file");
			} else {
#if CAAUDIOFILE_PROFILE
				mInConverter = true;
#endif
				StartTiming(this, fill);
				XThrowIfError(AudioConverterFillComplexBuffer(mConverter, ReadInputProc, this, &skipFrames, ioData, NULL), "convert audio packets (pcm read)");
				ElapsedTime(this, fill, mTicksInConverter);
#if CAAUDIOFILE_PROFILE
				mInConverter = false;
#endif
			}
			if (skipFrames == 0) {	// hit EOF
				ioNumPackets = 0;
				return;
			}
			mFrameMark += skipFrames;
#if VERBOSE_IO
			printf("CAAudioFile::ReadPackets: skipped %ld frames\n", skipFrames);
#endif

			mFramesToSkipFollowingSeek -= skipFrames;

			// restore mDataByteSize
			for (int i = ioData->mNumberBuffers; --i >= 0 ; )
				ioData->mBuffers[i].mDataByteSize = bufferSizeBytes;
		}
	}

	if (mFileDataFormat.mFramesPerPacket > 0)
		// don't read more packets than we are being asked to produce
		mMaxPacketsToRead = nPackets / mFileDataFormat.mFramesPerPacket + 1;
	if (mConverter == NULL) {
		XThrowIfError(ReadInputProc(NULL, &nPackets, ioData, NULL, this), "read audio file");
	} else {
#if CAAUDIOFILE_PROFILE
		mInConverter = true;
#endif
		StartTiming(this, fill);
		XThrowIfError(AudioConverterFillComplexBuffer(mConverter, ReadInputProc, this, &nPackets, ioData, NULL), "convert audio packets (read)");
		ElapsedTime(this, fill, mTicksInConverter);
#if CAAUDIOFILE_PROFILE
		mInConverter = false;
#endif
	}
	if (mClientDataFormat.mFramesPerPacket == 1)
		mFrameMark += nPackets;

	ioNumPackets = nPackets;
}
Exemplo n.º 14
0
void BossTimeOut::TimeOut()
{
	schedule(schedule_selector(BossTimeOut::speedUp),0.25f);
	StartTiming();
}
void CDecPerformanceForm::OnStartClick()
{
    StartTiming();
}
Exemplo n.º 16
0
	  static void Init(const std::string & system, int & argc, char ** &argv) 
	  // Call this first thing in your program.  It will parse the standard
	  // commandline options and remove them from the argv.
	  {

	       assert(argc >= 1);
	       std::vector<char*> leftOvers;
	       leftOvers.push_back(argv[0]);

	       if (argc < 2) {
		    std::cerr << "Standard harness options : " << argv[0] << " " << _usage << "\n";
		    exit(1);
	       }

	       _name = argv[1];
	       _system = system;
	       bool durationSet = false;
	       int i=2;
	       while(i < argc) {
		    if (!strcmp(argv[i], "-tc"))
			 _threadCount = atoi(argv[++i]);
		    else if (!strcmp(argv[i], "-foot"))
			 _footPrintB = atoll(argv[++i])*1024*1024;
		    else if (!strcmp(argv[i], "-footMB"))
			 _footPrintB = atoll(argv[++i])*1024*1024;
		    else if (!strcmp(argv[i], "-footKB"))
			 _footPrintB = atoll(argv[++i])*1024;
		    else if (!strcmp(argv[i], "-footB"))
			 _footPrintB = atoll(argv[++i]);
		    else if (!strcmp(argv[i], "-rt")) {
			 durationSet = true;
			 _runTimeSeconds = atoi(argv[++i]);
		    } else if (!strcmp(argv[i], "-max")) {
			 durationSet = true;
			 _opCountSet = true;
			 _operationCount = atoi(argv[++i]);
			 
		    } else if (!strcmp(argv[i], "-file"))
			 _file = argv[++i];
		    else if (!strcmp(argv[i], "-reload"))
			 _reload = true;
		    else if (!strcmp(argv[i], "-create"))
			 _create = true;
		    else if (!strcmp(argv[i], "-hang"))
		         _hang = true;
		    else if (!strcmp(argv[i], "-nondet"))
			 srand(time(NULL));
		    else {
			 leftOvers.push_back(argv[i]);
		    }
		    i++;
	       }
	       

	       if (_footPrintB == 0) {
		    std::cerr << "Footprint must be specified\n";
		    std::cerr << argv[0] << _usage << "\n";
		    exit(-1);
	       }

	       if (!durationSet) {
		    std::cerr << "-rt or -max must be specified\n";
		    std::cerr << argv[0] << _usage << "\n";
		    exit(-1);
	       }

	       if (_runTimeSeconds > 0 && _operationCount > 0) {
		    std::cerr << "only one of -rt or -max\n";
		    std::cerr << argv[0] << _usage << "\n";
		    exit(-1);
	       }

	       if (_create && _reload) {
		    std::cerr << "Either -create or -reload may be specified, but not both\n";
		    std::cerr << argv[0] << _usage << "\n";
		    exit(-1);
	       }

	       _operationsPerThread  = _operationCount/_threadCount;
	       _startTime = GetNow();

	       argc = leftOvers.size();
	       for(unsigned int i = 0; i< leftOvers.size(); i++) {
		    argv[i] = leftOvers[i];
	       }
	       argv[leftOvers.size()] = NULL;
	       

	       struct sigaction act;
	       bzero(&act, sizeof(act));
	       act.sa_handler = GracefulExit;
	       sigaction(SIGINT, &act, NULL);

	       StartTiming();
	  }
Exemplo n.º 17
0
int main( int argc, char **argv )
{
	clock_t	t0 = StartTiming();

/* ---------- */
/* Parameters */
/* ---------- */

	MPIInit( argc, argv );

	if( !gArgs.SetCmdLine( argc, argv ) ||
		!gArgs.GetRanges() ) {

		MPIExit();
		exit( 42 );
	}

/* ------------ */
/* Initial data */
/* ------------ */

	if( !LayerCat( vL, gArgs.tempdir, gArgs.cachedir,
			gArgs.zolo, gArgs.zohi, false ) ) {

		MPIExit();
		exit( 42 );
	}

	InitTables( gArgs.zilo, gArgs.zihi );

	{
		CLoadPoints	*LP = new CLoadPoints;
		LP->Load( gArgs.tempdir, gArgs.cachedir );
		delete LP;
	}

/* ----- */
/* Solve */
/* ----- */

	printf( "\n---- Solve ----\n" );

	SetSolveParams( gArgs.regtype, gArgs.Wr, gArgs.Etol );

	XArray	Xevn, Xodd;

	if( !strcmp( gArgs.mode, "A2A" ) ) {

		Xevn.Load( gArgs.prior );

		if( gArgs.untwist )
			UntwistAffines( Xevn );

		Xodd.Resize( 6 );
		Solve( Xevn, Xodd, gArgs.iters );
	}
	else if( !strcmp( gArgs.mode, "A2H" ) ) {

		Xevn.Resize( 8 );

		{	// limit A lifetime
			XArray	*A = new XArray;
			A->Load( gArgs.prior );

			if( gArgs.untwist )
				UntwistAffines( *A );

			Solve( *A, Xevn, 1 );
			delete A;
		}

		Xodd.Resize( 8 );
		Solve( Xevn, Xodd, gArgs.iters );
	}
	else if( !strcmp( gArgs.mode, "H2H" ) ) {

		Xevn.Load( gArgs.prior );
		Xodd.Resize( 8 );
		Solve( Xevn, Xodd, gArgs.iters );
	}
	else if( !strcmp( gArgs.mode, "eval" ) ) {

		Xevn.Load( gArgs.prior );

		if( gArgs.untwist )
			UntwistAffines( Xevn );

		gArgs.iters = 0;
	}
	else {	// split

		Xevn.Load( gArgs.prior );
		gArgs.iters = 0;
	}

	const XArray& Xfinal = ((gArgs.iters & 1) ? Xodd : Xevn);

/* ----------- */
/* Postprocess */
/* ----------- */

	if( gArgs.mode[0] == 's' ) {

		Split	S( Xfinal, gArgs.splitmin );

		S.Run();
	}
	else {

		Evaluate( Xfinal );

		if( gArgs.mode[0] != 'e' )
			Xfinal.Save();
	}

/* ------- */
/* Cleanup */
/* ------- */

	if( !wkid ) {
		printf( "\n" );
		StopTiming( stdout, "Lsq", t0 );
	}

	MPIExit();
	VMStats( stdout );

	return 0;
}
Exemplo n.º 18
0
// The strip alignment from S.DenovoBestAngle (followed by SetXY)
// produces a transform A->B = best.T for the scaled down scapes.
// Here's how to convert that to a transform between the original
// montages:
//
// Recapitulate total process...
//	TAffine	Rbi, Ra, t;
//
// Scale back up
//	best.T.MulXY( scr.crossscale );
//	A.x0 *= scr.crossscale;
//	A.y0 *= scr.crossscale;
//	B.x0 *= scr.crossscale;
//	B.y0 *= scr.crossscale;
//
// A-montage -> A-oriented
//	Ra.NUSetRot( A.deg*PI/180 );
//
// A-oriented -> A-scape
//	Ra.AddXY( -A.x0, -A.y0 );
//
// A-scape -> B-scape
//	t = best.T * Ra;
//
// B-scape -> B-oriented
//	t.AddXY( B.x0, B.y0 );
//
// B-oriented -> B-montage
//	Rbi.NUSetRot( -B.deg*PI/180 );
//	best.T = Rbi * t;
//
static void ScapeStuff()
{
	clock_t		t0 = StartTiming();
	CSuperscape	A, B;
	ThmRec		thm;
	CThmScan	S;
	CorRec		best;

	B.FindLayerIndices( gArgs.zb );
	B.OrientLayer();

	if( gArgs.ismb ) {

		char	buf[256];

		B.MakeWholeRaster();
		sprintf( buf, "montages/M_%d_0.png", gArgs.zb );
		B.DrawRas( buf );
		B.KillRas();
		B.WriteMeta( 'M', gArgs.zb );
		t0 = StopTiming( flog, "MakeMontage", t0 );
	}

	if( !gArgs.isab )
		return;

	A.FindLayerIndices( gArgs.za );
	A.OrientLayer();

	MakeStripRasters( A, B );
	t0 = StopTiming( flog, "MakeStrips", t0 );

	A.MakePoints( thm.av, thm.ap );
	A.WriteMeta( 'A', gArgs.za );

	B.MakePoints( thm.bv, thm.bp );
	B.WriteMeta( 'B', gArgs.zb );

	thm.ftc.clear();
	thm.reqArea	= int(gW * gH * inv_scl * inv_scl);
	thm.olap1D	= int(gW * inv_scl * 0.5);
	thm.scl		= 1;

	S.Initialize( flog, best );
	S.SetRThresh( scr.stripmincorr );
	S.SetNbMaxHt( 0.99 );
	S.SetSweepConstXY( false );
	S.SetSweepPretweak( true );
	S.SetSweepNThreads( scr.stripslots );
	S.SetUseCorrR( true );
	S.SetNewAngProc( NewAngProc );

	gA = &A;
	gB = &B;
	gS = &S;

	if( gArgs.abdbg ) {

		//S.RFromAngle( best, gArgs.abctr, thm );
		//S.Pretweaks( best.R, gArgs.abctr, thm );
		dbgCor = true;
		S.RFromAngle( best, gArgs.abctr, thm );
	}
	else {

		if( scr.stripsweepspan && scr.stripsweepstep ) {

			S.DenovoBestAngle( best,
				0, scr.stripsweepspan / 2, scr.stripsweepstep,
				thm, true );
		}
		else {
			best.A = 0;
			S.PeakHunt( best, 0, thm );
		}

		best.T.Apply_R_Part( A.Opts );

		best.X += B.Opts.x - A.Opts.x;
		best.Y += B.Opts.y - A.Opts.y;

		best.T.SetXY( best.X, best.Y );

		fprintf( flog, "*T: [0,1,2,3,4,5] (strip-strip)\n" );
		fprintf( flog, "[%f,%f,%f,%f,%f,%f]\n",
		best.T.t[0], best.T.t[1], best.T.t[2],
		best.T.t[3], best.T.t[4], best.T.t[5] );
	}

	t0 = StopTiming( flog, "Corr", t0 );
}
Exemplo n.º 19
0
// _______________________________________________________________________________________
//
OSStatus CAAudioFile::ReadInputProc(	AudioConverterRef				inAudioConverter,
										UInt32*							ioNumberDataPackets,
										AudioBufferList*				ioData,
										AudioStreamPacketDescription**	outDataPacketDescription,
										void*							inUserData)
{
	CAAudioFile *This = static_cast<CAAudioFile *>(inUserData);

#if 0
	SInt64 remainingPacketsInFile = This->mNumberPackets - This->mPacketMark;
	if (remainingPacketsInFile <= 0) {
		*ioNumberDataPackets = 0;
		ioData->mBuffers[0].mDataByteSize = 0;
		if (outDataPacketDescription)
			*outDataPacketDescription = This->mPacketDescs;
#if VERBOSE_IO
		printf("CAAudioFile::ReadInputProc: EOF\n");
#endif
		return noErr;	// not eofErr; EOF is signified by 0 packets/0 bytes
	}
#endif

	// determine how much to read
	AudioBufferList *readBuffer;
	UInt32 readPackets;
	if (inAudioConverter != NULL) {
		// getting called from converter, need to use our I/O buffer
		readBuffer = &This->mIOBufferList;
		readPackets = This->mIOBufferSizePackets;
	} else {
		// getting called directly from ReadPackets, use supplied buffer
		if (This->mFileMaxPacketSize == 0)
			return kExtAudioFileError_MaxPacketSizeUnknown;
		readBuffer = ioData;
		readPackets = std::min(*ioNumberDataPackets, readBuffer->mBuffers[0].mDataByteSize / This->mFileMaxPacketSize);
			// don't attempt to read more packets than will fit in the buffer
	}
	// don't try to read past EOF
//	if (readPackets > remainingPacketsInFile)
//		readPackets = remainingPacketsInFile;
	// don't read more packets than necessary to produce the requested amount of converted data
	if (readPackets > This->mMaxPacketsToRead) {
#if VERBOSE_IO
		printf("CAAudioFile::ReadInputProc: limiting read to %ld packets (from %ld)\n", This->mMaxPacketsToRead, readPackets);
#endif
		readPackets = This->mMaxPacketsToRead;
	}

	// read
	UInt32 bytesRead;
	OSStatus err;

	StartTiming(This, read);
	StartTiming(This, readinconv);
	err = AudioFileReadPackets(This->mAudioFile, This->mUseCache, &bytesRead, This->mPacketDescs, This->mPacketMark, &readPackets, readBuffer->mBuffers[0].mData);
#if CAAUDIOFILE_PROFILE
	if (This->mInConverter) ElapsedTime(This, readinconv, This->mTicksInReadInConverter);
#endif
	ElapsedTime(This, read, This->mTicksInIO);

	if (err) {
		DebugMessageN1("Error %ld from AudioFileReadPackets!!!\n", err);
		return err;
	}

#if VERBOSE_IO
	printf("CAAudioFile::ReadInputProc: read %ld packets (%qd-%qd), %ld bytes, err %ld\n", readPackets, This->mPacketMark, This->mPacketMark + readPackets, bytesRead, err);
#if VERBOSE_IO >= 2
	if (This->mPacketDescs) {
		for (UInt32 i = 0; i < readPackets; ++i) {
			printf("  read packet %qd : offset %qd, length %ld\n", This->mPacketMark + i, This->mPacketDescs[i].mStartOffset, This->mPacketDescs[i].mDataByteSize);
		}
	}
	printf("  read buffer:"); CAShowAudioBufferList(readBuffer, 0, 4);
#endif
#endif
	if (readPackets == 0) {
		*ioNumberDataPackets = 0;
		ioData->mBuffers[0].mDataByteSize = 0;
		return noErr;
	}

	if (outDataPacketDescription)
		*outDataPacketDescription = This->mPacketDescs;
	ioData->mBuffers[0].mDataByteSize = bytesRead;
	ioData->mBuffers[0].mData = readBuffer->mBuffers[0].mData;

	This->mPacketMark += readPackets;
	if (This->mClientDataFormat.mFramesPerPacket != 1) {	// for PCM client formats we update in Read
		// but for non-PCM client format (weird case) we must update here/now
		if (This->mFileDataFormat.mFramesPerPacket > 0)
			This->mFrameMark += readPackets * This->mFileDataFormat.mFramesPerPacket;
		else {
			for (UInt32 i = 0; i < readPackets; ++i)
				This->mFrameMark += This->mPacketDescs[i].mVariableFramesInPacket;
		}
	}
	*ioNumberDataPackets = readPackets;
	return noErr;
}
bool PixPair::Load(
	const char	*apath,
	const char	*bpath,
	int			order,
	int			bDoG,
	int			r1,
	int			r2,
	FILE*		flog )
{
	printf( "\n---- Image loading ----\n" );

	clock_t		t0 = StartTiming();

/* ----------------------------- */
/* Load and sanity check rasters */
/* ----------------------------- */

	uint8	*aras, *bras;
	uint32	wa, ha, wb, hb;
	int		ok = false;

	aras = Raster8FromAny( apath, wa, ha, flog );
	bras = Raster8FromAny( bpath, wb, hb, flog );

	if( !aras || !bras ) {
		fprintf( flog,
		"PixPair: Picture load failure.\n" );
		goto exit;
	}

	if( wa != wb || ha != hb ) {
		fprintf( flog,
		"PixPair: Nonmatching picture dimensions.\n" );
		goto exit;
	}

	ok		= true;
	wf		= wa;
	hf		= ha;
	ws		= wa;
	hs		= ha;
	scl		= 1;

/* -------------- */
/* Resin removal? */
/* -------------- */

	//if( dbgCor ) {
	//	ZeroResin( "bloba.tif", aras );
	//	ZeroResin( "blobb.tif", bras );
	//}
	//else {
	//	ZeroResin( NULL, aras );
	//	ZeroResin( NULL, bras );
	//}

	//StopTiming( flog, "Resin removal", t0 );

/* ------- */
/* Flatten */
/* ------- */

	LegPolyFlatten( _avf, aras, wf, hf, order );
	RasterFree( aras );

	LegPolyFlatten( _bvf, bras, wf, hf, order );
	RasterFree( bras );

	avs_vfy	= avs_aln = avf_vfy	= avf_aln = &_avf;
	bvs_vfy	= bvs_aln = bvf_vfy	= bvf_aln = &_bvf;

/* ------------- */
/* Apply filters */
/* ------------- */

//{
//	vector<CD>	kfft;
//	double		K[] = {
//				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
//				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
//				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
//				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
//				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
//				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
//				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
//				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
//				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
//				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
//				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
//		Convolve( _avf, _avf, wf, hf, K, 11, 11, true, true, kfft );
//		Normalize( _avf );
//		Convolve( _bvf, _bvf, wf, hf, K, 11, 11, true, true, kfft );
//		Normalize( _bvf );
//}

#if 0
{
	vector<CD>	kfft;
	double		K[] = {
				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
				1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
		Convolve( _avfflt, _avf, wf, hf, K, 11, 11, true, true, kfft );
		Normalize( _avfflt );
		Convolve( _bvfflt, _bvf, wf, hf, K, 11, 11, true, true, kfft );
		Normalize( _bvfflt );

		avs_aln = avf_aln = &_avfflt;
		bvs_aln = bvf_aln = &_bvfflt;

		bDoG = true;
}
#endif

	if( bDoG ) {

		vector<double>	DoG;
		vector<CD>		kfft;
		int				dim = MakeDoGKernel( DoG, r1, r2, flog );

		Convolve( _avfflt, _avf, wf, hf,
			&DoG[0], dim, dim, true, true, kfft );
		Normalize( _avfflt );

		Convolve( _bvfflt, _bvf, wf, hf,
			&DoG[0], dim, dim, true, true, kfft );
		Normalize( _bvfflt );

		avs_aln = avf_aln = &_avfflt;
		bvs_aln = bvf_aln = &_bvfflt;
	}

/* --------------------- */
/* Downsample all images */
/* --------------------- */

	if( ws > 2048 || hs >= 2048 ) {

		do {
			ws		/= 2;
			hs		/= 2;
			scl		*= 2;
		} while( ws > 2048 || hs > 2048 );

		fprintf( flog, "PixPair: Scaling by %d\n", scl );

		if( ws * scl != wf || hs * scl != hf ) {

			fprintf( flog,
			"PixPair: Dimensions not multiple of scale!\n" );
			goto exit;
		}

		Downsample( _avs, _avf );
		Downsample( _bvs, _bvf );

		avs_vfy = avs_aln = &_avs;
		bvs_vfy = bvs_aln = &_bvs;

		if( bDoG ) {

			if( _avfflt.size() ) {
				Downsample( _avsflt, _avfflt );
				avs_aln = &_avsflt;
			}

			if( _bvfflt.size() ) {
				Downsample( _bvsflt, _bvfflt );
				bvs_aln = &_bvsflt;
			}
		}
	}
	else
		fprintf( flog, "PixPair: Using image scale=1.\n" );

/* ------------------------------ */
/* Write DoG images for debugging */
/* ------------------------------ */

#if 0
	if( bDoG ) {
		VectorDblToTif8( "DoGa.tif", avs_aln, ws, hs );
		VectorDblToTif8( "DoGb.tif", bvs_aln, ws, hs );
	}
#endif

/* -------- */
/* Clean up */
/* -------- */

exit:
	if( aras )
		RasterFree( aras );

	if( bras )
		RasterFree( bras );

	StopTiming( flog, "Image conditioning", t0 );

	return ok;
}