C Code for Psychologists

(the files to be downloaded are not set as dowload types, you need to hold down the cursor and select "SaveThisLinkAs...")

On this page you will find links to several Macintosh frameworks that take care of many of the details of programming a Mac. The first is just some source code. It has no documentation, but there is an entire sample program provided for you to try out.

A general C source file for dealing with the Mac interface is available below. It isn't terribly well documented yet. And, it does some things that you normally would not expect while leaving out things you would. For example, there is a function to use a standard Mac dialog for opening and saving text files. But, your program only needs to know about using ANSI commands for dealing with file I/O. On the other hand, there is no video buffering. This is left out because that part of my code is currently being ported to VideoToolbox. And, because people over use this capability and make things too complex. Simple drawings, and text should be drawn direct to the screen on modern Macs (68040 or better). It makes the construction of the experiment much easier (while the program may be more or less complex). In general, this code can be used to bypass most of the Macintosh routines and will allow you to program in straight ANSI C.

download JohnUnit.c and JohnUnit.h.

Another file available here is called VoiceKey.c. This file contains the code necessary to use the Mac's microphone input as a VoiceKey. However, the calibration code for that key will have to be implemented on your own. Sometimes it is easiest to write a simple ANSI console project to set the sensitivity and then use the code in your experiment. A more elaborate control for the voice key sensitivity can be found in JohnsUnit.c

I have included a Stroop Negative Priming experiment based on the above code (including an interface to VoiceKey.c) to download. It includes an example of the use of JohnsUnit.c and many of the functions I have not yet moved into that file. As things stand I will be moving many of the functions in the main file for this project into JohnsUnit.c.

download StroopNP.hqx

In addition to VoiceKey.c I have included ExperimentSR.c. This is necessary for any projects that use Apple's voice recognition technology. It is necessary for the ImageFlipper project described below.

Another project based heavily on the above code, and that uses JohnUnit.c is called ImageFlipper. For now, it presents one image/trial and has variable options you can set. It does voice keying, voice recording, or voice recognition! Unfortunately, due to hardware limitations it CANNOT do any of those at the same time. I would be happy to work with someone who had a sound card with multiple inputs or USB sound input hardware to work on a solution to having simultaneous recording and recognition. If you want to double check the recognition you are going to have to record to tape. A recent experiment we tried had better than 95% recognition accuracy. Reduce all noise as much as possible in order to increase recognition accuracy. This program has many powerful features such as on the fly image loading, rotation, and scaling; there is the ability to handle any QuickTime formatted image including GIF, JPG, Photoshop, and TIFF (more formats are available if you have newer versions of QuickTime); and the data files contain REAL timing results that are refresh rate independent. I calculate screen presentation times in milliseconds, subtract 2, and then wait for the next refresh.

download ImageFlipper.hqx (requires Apple Speech Recognition, and QuickTime 3 or better). Using the source code requires all of the source files above.

Matt Peterson kindly volunteered to put his own programming framework called Psychology APIs (PAPI). It includes documentation in PDF format and is significantly more robust than the code above.

download PAPI 1.1

Matt has also done some cool stuff with the EyeLink eye tracker and the Mac. ( Matt's EyeLink page)

Billy Schmidt has offered up a Macintosh programming framework. This one is called SplayPicts. It makes extensive use of color palette manipulation in order to display images quickly. If you present drawings on older Mac hardware then this is the framework for you. It is also documented.

download SplayPicts

I have provided, an example of an experiment written using Carbon API's in C for Mac OS X. It runs a negative priming experiment using word stimuli with vocal responses. You need to use the space bar to advance trials, and at the beginning you use the "F" and "V" keys to adjust the sensitivity of the voice key. The stimulus control files get put into the package when it is compiled and it automatically creates the data file in the same directory as the application. Please enjoy this. download

.

That is all for now. If anyone else wishes to contribute reviews or further code feel free. If you write a program using one of the above frameworks please send it in and we'll include it in the package with proper attribution. If you find a bug in one of the frameworks or code files please contact me and the appropriate author. All correspondence should be sent to John Christie at the email address, jc@or.psychology.dal.ca.

Home