VideoToolbox Advice
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
- To that I would add only that you might want to occasionally catch up on Macintosh-software news by looking at Ric Ford's MacInTouch daily news column, which appeared after Peter Lewis wrote that list. - Denis
ESSENTIAL BOOKS AND SOFTWARE
- Metrowerks CodeWarrior Professional C Compiler, on CD-ROM, first released (without the adjective "Professional") in January '94, and would now be at version 12 (June '97), but they added "Professional" to the name and reset the version counter back to 1. It's very popular, and deservedly gets rave reviews. It costs $399 ($119 academic) and generates 68k, PowerPC, and Intel x86/Pentium code. New versions are now issued twice a year; the purchase price includes one year of updates. (Major updates are published as CD-ROMs; minor updates are distributed only electronically.) It comes without any paper documentation; it's all on the CD-ROM, which you can print yourself, but I prefer to buy the printed and bound manual: Inside CodeWarrior Professional book $34.95. More...
- The C Programming Language, Second Edition by Brian Kernighan and Dennis Ritchie, Prentice Hall, 1988. This book describes the new Standard C, which most commercial compilers conform to.
- Numerical Recipes in C Set for Macintosh $90. Useful book and mathematical library in source form. You can read the code, understand what's going on, and modify it if necessary.
- You can now read Apple's Inside Macintosh books on the web or download them.
- Inside Macintosh, 2nd edition: Imaging with QuickDraw, Advanced Color Imaging Reference, ...
- Inside Macintosh CD-ROM $99.95 (includes 25 books in electronic form).
- Designing Cards and Drivers, 3rd edition
- Designing PCI cards and Drivers for Power Mac Computers $35
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
- Symantec C/C++ $299, was the second-most popular compiler, after CodeWarrior. Their THINK C used to dominate, but was overtaken by CodeWarrior. Symantec C and C++ 8 are pretty good compilers but never overtook CodeWarrior. Due to poor sales, Symantec has announced (8/96) that there will be no further C/C++ development, just maintenance releases, so they can concentrate on Java. More...
- MPW (Macintosh Programmer's Workbench) free from Apple. This is no longer being developed; that's why they now give it away. A complete development environment (MPW, C, Pascal, and Assembler; 68k and PowerPC). Most people find MPW slow and clumsy, and prefer CodeWarrior.
MAGAZINES, WEB SITES, & SUBSCRIPTIONS
- Ric Ford's MacInTouch daily news column.
- Version Tracker to find the current version of any program.
- CVNet is the Color and Vision Network. To join just send an email message to the moderator, explaining your interest in vision. If you're accepted, your email addresswill be added to the email distribution list. CVNet sends out about a message a day about events of interest to people doing vision research: mostly jobs, conferences, and solicitations of advice. There's an archive. Free.
- TidBITS. A weekly email newsletter about Macintosh software and hardware published by Adam and Tonya Engst. Free.
- MacTech Magazine. The only paper Mac magazine for programmers. [develop: The Apple Technical Journal became part of MacTech magazine in April 1997.] $39.95/year
- Apple Developer Mailing Subscription. Each month you receive a CD-ROM. $149??/year. These CDs provide useful documentation and sample code for anyone developing Mac software.
- Macintosh Select/Premier Developer Program. $500??/$3,000?? per year. Apple engineers will answer several questions per year, for free, and more at $300 each. "Premier" is only for people producing commercial products for Mac. Includes developer mailings.
- Who can answer your Macintosh programming question? You can try posting it on UseNet comp.sys.mac.programming.codewarrior. Somebody knowledgeable might jump in. (Apple engineers often participate in UseNet.) For $500 you can become an Apple Associate Plus (above) and ask 10 questions (over a year) of Apple engineers, who will answer your questions by email, provided you've already consulted the relevant manuals.
- The comp.sys.mac.programming.codewarrior UseNet news group has knowledgeable active discussion. Experts often jump in with helpful answers to thorny questions.
SOFTWARE ARCHIVES ON CD-ROM
- Apprentice CD-ROM- Mac source code and utilities. $35
Celestin Company, Inc.
5652 NE Meadow Road
Kingston, WA 98346-9505
360 297 8091
Fax 360 297 8092
info@celestin.com
C STYLE
There are three things that I've read on C coding style, over the years, that I've taken to heart.
- 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.)
- I read somewhere a quote of Brian Kernighan, I think, that comments should not duplicate what is obvious from the code.
- 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