I have some experience with using the RECORD command to record vocal
responses in Windows MATLAB. Maybe it applies to OSX MATLAB as well?
But I will qualify that I am only relaying my experience on the Dell
Dimension 4800 with Windows XP Pro and MATLAB 7.0.4 used. Your system
might behave very differently. And I am summarizing below in order to
be helpful. The code and external hardware used to calibrate and make
real-world measurement of the study we developed were much more
rigorous.
First, for my particular microphone, the amount of time needed to
execute the RECORD command varied between 0.025 and 0.040 seconds.
That was measured in repeated loops like this:
start_trial_time_stamp = GetSecs;
record(vocal_response_device);
post_record_time_stamp = GetSecs;
record_command_duration = post_record_time_stamp - start_trial_time_stamp;
Additionally, with the microphone very close to the keyboard and
hitting a single key with a quick light tap, I was able to compare the
event time of that key hit as reported by KbCheck to the time
extracted from the sound trace produced by the RECORD command. (i.e.,
I selected the sample point N in the RECORD output vector that best
represented the start of the key hit, basically using a percentage of
peak magnitude threshold.)
true_vocal_response_time = kbcheck_time_stamp - start_trial_time_stamp;
measured_vocal_reposnse_time = (N - 1)/vocal_record_sampling_rate;
After numerous repetitions, I found a very consistent result:
true_vocal_response_time = measured_vocal_reposnse_time +
record_command_duration - 0.005; % In seconds.
The most important thing to remember is that record_command_duration
is not constant. You need to sandwich your RECORD command between
two GetSecs calls and save a record_command_duration for each trial
for analysis later. But with that adjustment, you can directly
compare times recorded with KbCheck (i.e., what I have called true
response times) in your trial loop with times extracted from your
sound trace.
record(vocal_response_device);
start_pause = GetSecs;
while (GetSecs - start_pause < 0.100)
% Do nothing.
end
stop(vocal_response_device);
vocal_response_vector = getaudiodata(vocal_response_device);
Regarding your other big issue and referring to the code fragment
above, the STOP command (and probably also PAUSE as you state in your
message) take a long to executue because they both wait for the
current full second of audio recording to complete. MathWorks
confirmed that for me. So vocal_response_vector above will always
have a number of samples equal to the sampling rate (i.e., 1 second of
data) even though I only wanted 100 milliseconds. The closer your
STOP or PAUSE command is to a whole second of data without going over,
the more instantaneouly those commands will seem to executue. Best
thing to do is to leave record running while you do other things like
collect keyboard response of whatever, then STOP or PAUSE and truncate
your vocal_response_vector as necessary.
Remember, this was all about MATLAB for Windows. I have no idea if
the same can be expected from OSX with your particular computer and
hardware. Good luck.
Daniel Shima
Vanderbilt Vision Research Center
On 10/11/05, Sandhitsu Das <sudas@...> wrote:
> I'm posting again in hopes of an answer - so far nobody responded. I want to do the
> following:
>
> On every trial of a prioritized (with Priority) loop, I want to record the voice response from
> the subject. The recording will begin as soon as the stimulus display is over, and pause at
> the press of a key. I can't use any special hardware because the experiment has to be run
> at the patient's bedside in a hospital with a notebook running Mac OS X. So, my input
> device has to be the laptop mic. Seems like a simple thing to do but so far I haven't found
> a reliable way to do it.
>
> I tried the audiorecorder object - it doesn't work well in OS X, and takes a long time to
> pause or stop recording. The DAQ toolbox is only available for Windows. Can anything be
> done using PsychHID ? Or perhaps there are mex files someone has written that directly
> uses C routines provided by Apple for audio interfacing ?
>
> I need to find a solution soon, failing which I may have to abandon MATLAB/PTB and
> rewrite my experiments on another platform - which I'd hate to do at this point.
>
> Thanks for any suggestions,
> Sandhitsu Das
> University of Pennsylvania
>
> --- In psychtoolbox@yahoogroups.com, "Sandhitsu Das" <sudas@s...> wrote:
> >
> > If I want to run a prioritized main experiment loop with PTB on OS X, and at the same
> time
> > record voice responses from the subject without sacrificing timing precision of stimulus
> > presentation, what are my options ? What do people use for voice recording ?
> >
> > Any ideas would be helpful.
> >
> > Sandhitsu Das
> > University of Pennsylvania
> >
>
>
>
>
>
>
>
>
> Post your message to: psychtoolbox@yahoogroups.com
> Please indicate OS9, OSX, or WIN version, and include your full name.
> Denis Pelli, David Brainard, and Allen Ingling.
> http://psychtoolbox.org
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>