Recording sound during experiment

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
You could have a background application recording sound while you run
the program. You could start a trial with a beep that would be
recorded in the sound file.

To record sound outside of matlab:
http://audacity.sourceforge.net/
http://www.ambrosiasw.com/utilities/wiretap/

Or you can download this record.m program to record in matlab:
http://math.arizona.edu/~rims/workshops/softwareMATLAB/



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
>
>
>
>
>
>
>
>
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
>
>
>
>
>
>
>
>
dear sandhitsu

i've never recorded sound on a Mac, so i'm not speaking from
experience, but i can suggest four routes you might explore.

1. if audiorecorder is performing poorly you should report that as a
bug to Mathworks. Perhaps they know a work around. companies only
fix things if customers complain.

2. there are very nice small USB boxes that you can plug into your
Mac that provide very high quality sampling of sound. Based on a
suggestion from Frans Cornellisen, I listed several on the USB page.
i haven't tried them, but i assume that the Mac would automatically
recognize it as an Audio device. You would still need to use
audiorecorder to control it, but perhaps that combination works
better. the audio box costs less than $100 so it's a fairly cheap
thing to try.
http://psychtoolbox.org/usb.html
http://www.edirol.com/products/info/ua1x.html
http://www.minidisco.com/transit.html

3. you could use the DAQ toolbox with the Measurement Computing box
that I created for OSX Psychtoolbox. its maximum data rate (2 kHz)
isn't very high, but it might be enough for your purposes. it is
based on PsychHID.
http://psychtoolbox.org/daq.html

4. you could try running under Classic and using the OS9 Psychtoolbox
and MATLAB. there are different sound commands (built into MATLAB,
not in the Psychtoolbox) there and perhaps there is a recording
option that works.

best

denis

On Oct 11, 2005, at 1:40 PM, Sandhitsu Das 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
>>
>>
>
>
>
>
>
>
>
> ------------------------ Yahoo! Groups Sponsor --------------------
> ~-->
> Get fast access to your favorite Yahoo! Groups. Make Yahoo! your
> home page
> http://us.click.yahoo.com/dpRU5A/wUILAA/yQLSAA/BEfwlB/TM
> --------------------------------------------------------------------
> ~->
>
> 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
>
>
>
>
>
>
>
>

Denis Pelli
Professor of Psychology and Neural Science
http://psych.nyu.edu/pelli/
Thanks for your reply, Rob.

The background application option is simple and could work except
that since my experiment loops are running under priority, the
background program may not get enough CPU to run at all - I can't
risk that. In fact, we tried sending sync pulses to the EEG machine
by a simultaneously running background process - but timings were way
off because of this problem.

The record.m program doesn't seem like it would work for Mac OS X.

Sandhitsu

On Oct 11, 2005, at 3:05 PM, Rob Kohr wrote:

> You could have a background application recording sound while you run
> the program. You could start a trial with a beep that would be
> recorded in the sound file.
>
> To record sound outside of matlab:
> http://audacity.sourceforge.net/
> http://www.ambrosiasw.com/utilities/wiretap/
>
> Or you can download this record.m program to record in matlab:
> http://math.arizona.edu/~rims/workshops/softwareMATLAB/
>
>
>
> 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
>>
>>
>>
>>
>>
>>
>>
>>
>>
>
>
>
>
> ------------------------ Yahoo! Groups Sponsor --------------------
> ~-->
> Get fast access to your favorite Yahoo! Groups. Make Yahoo! your
> home page
> http://us.click.yahoo.com/dpRU5A/wUILAA/yQLSAA/BEfwlB/TM
> --------------------------------------------------------------------
> ~->
>
> 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
>
>
>
>
>
>
>
>
dear daniel

i obtained a max input sampling rate of 2 kHz using the DaqAInScan
command.

here's the HELP for that command:

[data,params]=DaqAInScan(device,options)
USB-1208FS: Analog input scan. Clocked analog to digital
conversion. This
command samples several analog input channels at a specified rate and
sends the readings to the host. Use DaqAInScan when you want to
complete
the whole operation in one call, tying up the computer until the
sampling
is done. Use DaqAInScanBegin, DaqAInScanContinue, and DaqAInScanEnd,
instead, when you want to use the computer during sampling.

the virtue of this approach is that the samples are clocked by the
PMD-1208FS clock, autonomously, so you get good timing without tying
up the Mac's cpu.

from previous postings here, it's my impression that the DAQ toolbox
isn't working with the latest OS releases, but i've loaned out my
device and, in any event, haven't had any time lately to program. I
would guess that a bit of tweaking of the source code would get
things working again, but it might require seeking advice from the
Apple USB discussion group.

given the DAQ toolbox's current need for debugging (unconfirmed), you
might want to avoid it and instead try an audio-USB device first
since they are very cheap and have excellent specs.
http://psychtoolbox.org/usb.html
http://www.edirol.net/products/en/UA-1EX/
http://www.m-audio.com/products/en_us/Transit-main.html

best

denis


On Jan 31, 2006, at 9:52 PM, Daniel Shima wrote:

> Dear Denis,
>
> Could you possibly elaborate on your idea in item 3 below of using the
> Measurement Computing USB-1208FS and the DAQ toolbox to collect audio
> input. I do not have a USB-1208FS presently, but I may like to get
> one and try this method.
>
> My best guess is that you would connect the analog output of a
> standard microphone to an analog input of the USB-1208FS. Then, in a
> rapidly-repeating loop, you would use a command in the DAQ toolbox
> (possibly DaqAIn) to sample that analog input (maybe save a timestamp
> of each sample too) and construct a sound signal vector sample by
> sample.
>
> Is that the idea? How does the maximum data rate of 2 kHz apply in
> that situation when surely a while-loop in MATLAB could repeat much
> faster. Or is it that the sampling command (again, possibly DaqAIn)
> is a blocking call for 0.5 ms?
>
> Thanks for any feedback on the matter.
>
> Daniel Shima
> Vanderbilt Vision Research Center
>
>
> On 10/11/05, Denis Pelli <denis.pelli@...> wrote:
>> dear sandhitsu
>>
>> i've never recorded sound on a Mac, so i'm not speaking from
>> experience, but i can suggest four routes you might explore.
>>
>> 1. if audiorecorder is performing poorly you should report that as a
>> bug to Mathworks. Perhaps they know a work around. companies only
>> fix things if customers complain.
>>
>> 2. there are very nice small USB boxes that you can plug into your
>> Mac that provide very high quality sampling of sound. Based on a
>> suggestion from Frans Cornellisen, I listed several on the USB page.
>> i haven't tried them, but i assume that the Mac would automatically
>> recognize it as an Audio device. You would still need to use
>> audiorecorder to control it, but perhaps that combination works
>> better. the audio box costs less than $100 so it's a fairly cheap
>> thing to try.
>> http://psychtoolbox.org/usb.html
>> http://www.edirol.com/products/info/ua1x.html
>> http://www.minidisco.com/transit.html
>>
>> 3. you could use the DAQ toolbox with the Measurement Computing box
>> that I created for OSX Psychtoolbox. its maximum data rate (2 kHz)
>> isn't very high, but it might be enough for your purposes. it is
>> based on PsychHID.
>> http://psychtoolbox.org/daq.html
>>
>> 4. you could try running under Classic and using the OS9 Psychtoolbox
>> and MATLAB. there are different sound commands (built into MATLAB,
>> not in the Psychtoolbox) there and perhaps there is a recording
>> option that works.
>>
>> best
>>
>> denis
>>
>> On Oct 11, 2005, at 1:40 PM, Sandhitsu Das 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
>>>>
>>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> ------------------------ Yahoo! Groups Sponsor --------------------
>>> ~-->
>>> Get fast access to your favorite Yahoo! Groups. Make Yahoo! your
>>> home page
>>> http://us.click.yahoo.com/dpRU5A/wUILAA/yQLSAA/BEfwlB/TM
>>> --------------------------------------------------------------------
>>> ~->
>>>
>>> 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
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>
>> Denis Pelli
>> Professor of Psychology and Neural Science
>> http://psych.nyu.edu/pelli/
>>
>>
>>
>>
>>
>>
>> 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
>>
>>
>>
>>
>>
>>
>>
>>
>>
>
>
>
>
> 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
>
>
>
>
>
>

Denis Pelli
Professor of Psychology and Neural Science
http://psych.nyu.edu/pelli/