VideoToolbox Advice

VideoToolbox
PsychToolbox
Tips
 
about
advice
bugs
changes
contents
download

visitors since September 17, 1996.
April 12, 2000

STARTING

PORTABILITY

ADVICE TO BEGINNERS

You might want to start by reading my recent article:

Pelli, D.G. (1997) The VideoToolbox software for visual psychophysics: Transforming numbers into movies. Spatial Vision 10:437-442 (HTML)

I no longer think C programming is the best way to set up vision research experiments. David Brainard has made it possible to use the key VideoToolbox routines from within MATLAB, a high-level language and programming environment. To me MATLAB is what you'd get if BASIC were reinvented by an engineer who likes linear algebra (i.e. matrices). MATLAB turns out to be a very nice environment for creating images and running experiments. Since March '96, I've been writing all my experiments in MATLAB, using David Brainard's PsychophysicsToolbox for MATLAB. And I've been contributing various things, in C and MATLAB, to David's code, based on what I'm used to being able to do in C. C still seems to be the language of choice for low-level hardware control, but I prefer the high-level environment of MATLAB for the rest of it. The MATLAB environment would be useless for vision research without David's MEX files (external resource files of compiled C code--many based on the VideoToolbox--that are read in at runtime by MATLAB). Other high-level packages, including Psychophysica for Mathematica, are described in Hans Strasburger's and Faith Florer's annotated lists of visual psychophysics software.

The other pages in this VideoToolbox site discuss the general issue of how to use computers in visual testing (see Video synch, Displays, Attenuator, How to, Rec. software), but this page is focussed on C programming. So, if you still want to write C, read on.

If you want to do vision experiments on your Macintosh computer, and haven't programmed a Mac before, there are various things you should get for yourself. I've listed what I consider essential. The stuff I use. There are lots of baby books that hold your hand while you learn, but the ones that I've looked at weren't helpful for setting up vision experiments. They're oriented towards producing Mac-like applications with the right look and feel, which is unimportant when the experimenter is the only person that will ever run the program. Be warned that the bible, Inside Macintosh, is intimidating at first. The classic comment about Inside Mac is that you have to have read the rest to understand any part. Fortunately, the second edition is much more readily assimilable. Mac programming is tough going at first, but I've come to like it, as the Apple routines are generally intelligent solutions to complicated problems. Anyway, by looking at the sources for the various demos in the VideoToolbox you should be able to get going much more quickly than I did. Good luck. - Denis Pelli

The entire VideoToolbox now runs native on the PowerPC. We're very happy with the PowerMacs and the Metrowerks CodeWarrior Professional C Compiler ($119 academic). The compiler and your code both run native and fast. I recommend the PowerMac 7500 (best specs) or 7200 (best buy) over other models to anyone that wants to buy a mac to show movies (i.e. copy images to the screen in real time)--see the Video synch document.

The famous shareware author, Peter Lewis, gives this advice to the "newbie Mac programmer: Find yourself (in order of necessity):

"Now you can start writing. It takes about a year of writing code to really get up to speed writing Macintosh applications. You can cut this down by using a framework, but I'm dubious as to whether this is a better long term solution. No matter what you do, one of the most important things is to develop your own set of reusable modules and routines that you can build upon. Any time you find your self writing the same chunk of code a few times, package it up in to a routine and call it instead of duplicating the code--that way you can reuse it in multiple projects and if there are any bugs, you can fix it in one place." - Peter Lewis


ESSENTIAL BOOKS AND SOFTWARE

The books and CD-ROM are from Addison-Wesley. You'll need access to these books (whether online or in hand), especially Imaging with QuickDraw, Advanced Color Imaging on the Mac OS, and Advanced Color Imaging Reference. The 2nd edition of Inside Macintosh is significantly easier to read than the first (which is now obsolete) and includes examples in C, not just Pascal.

OTHER C COMPILERS

MAGAZINES, WEB SITES, & SUBSCRIPTIONS

SOFTWARE ARCHIVES ON CD-ROM

C STYLE

There are three things that I've read on C coding style, over the years, that I've taken to heart.

  1. The new compilers really do conform to Standard C. There are now professional test suites that test this quite rigorously and the up-to-date compiler companies (i.e. writing for PC and Mac, but not unix) all use these suites to check themselves out. That still leaves some room for differences between compilers because the Standard leaves a few things "implementation defined", e.g. the size of int. Thus, provided you set the compiler to require prototypes, explicit casting of arguments to subroutines is rarely necessary. (One exception is the various flavors of handle and window pointer that are equivalent, but not covertible by the compiler.)
  2. I read somewhere a quote of Brian Kernighan, I think, that comments should not duplicate what is obvious from the code.
  3. The Numerical Recipes book argues that one should learn the order of precedence of the operators, *, +, <<, etc., instead of relying on lots of parentheses, because more than a few parentheses become very hard to read.

OTHER SOURCES OF ADVICE