Tscope5
audio04.c
////////////////////////////////////////////////////////////////////////////////
//
// __ ______
// / /_______________ ____ ___ / ____/
// / __/ ___/ ___/ __ \/ __ \/ _ \ /___ )
// / /_(__ ) /__/ /_/ / /_/ / __/ ____/ /
// \__/____/\___/\____/ .___/\___/ /_____/
// /_/
//
// audio04.c
// - Basic response timing example.
// - Use the software voice key as a response device.
////////////////////////////////////////////////////////////////////////////////
#include <tscope5.h>
#include <stdio.h>
#define MAXTIME 2.0
int main()
{
// not too much logging
ts5_set_log_level(TS5_LOGLEVEL_1);
// install a display
// set voice key parameters
// ts5_set_voicekey_rise_delay(0.2);
// ts5_set_voicekey_drop_delay(0.2);
// define voice onset as a response
// define voice offset as a response
// define the escape key
ts5_define_keyboard_button(TS5_KEY_ESCAPE);
// start the audio recorder
// 5 trials, name the number
int i;
for (i = 0; i < 5; i++) {
// some timing varables
double t0, t1, error;
int r;
// allocate an audio sample
TS5_SAMPLE *test = ts5_alloc_sample(MAXTIME);
// fixation point
ts5_printf(0.0, 0.0, "+");
ts5_wait(0.5);
// blank
ts5_wait(0.5);
// set stimulus
ts5_printf(0.0, 0.0, "%d", i);
// start recording
// wait for maximum MAXTIME seconds
while (ts5_get_time() - t0 < MAXTIME) {
r = ts5_check_response(&t1, &error);
if (r) {
printf("trial %d: %d %f %f\n", i, r, t1-t0, error);
}
if (r==3) {
break;
}
}
// save the sample
char fname[50];
sprintf(fname, "trial%02d.wav", i);
ts5_write_sample(fname, test);
// intertrial interval
ts5_wait(0.5);
}
// stop the audio recorder
return 0;
}