#include <tscope.h>
#define REALEXP
#define NWORDS 10
char word[NWORDS][20];
void readstim()
{
FILE *fp;
fp = fopen("words.txt", "r");
if (fp == NULL)
ts_fatal("error opening words.txt");
int i;
for (i = 0; i < NWORDS; i++)
fscanf(fp, "%s", word[i]);
fclose(fp);
}
#ifdef TESTSTIM
int main()
{
readstim();
int i;
for (i = 0; i < NWORDS; i++)
printf("%s\n", word[i]);
return 0;
}
END_OF_MAIN();
#endif
#define NSTIM NWORDS
#define NTRIALS NSTIM
struct {
int subj;
int stimnr;
char stim[20];
char resp[20];
int r;
int corr;
int rt;
int re;
} data[NTRIALS];
#define TESTLIST TRUE
void randomize(int subjnr)
{
int i, tmp[NTRIALS];
if (TESTLIST) {
for (i = 0; i < NTRIALS; i++)
tmp[i] = i;
} else
ts_rlist(NTRIALS, 1, tmp);
for (i = 0; i < NTRIALS; i++) {
data[i].subj = subjnr;
data[i].stimnr = tmp[i];
sprintf(data[i].stim, "%s", word[data[i].stimnr]);
data[i].resp[0] = 0;
data[i].r = 0;
data[i].rt = 0;
data[i].re = 0;
}
}
void writedata()
{
char filename[20];
sprintf(filename, "data%d.rtd", data[0].subj);
FILE *outfile;
outfile = fopen(filename, "a+");
if (outfile == NULL)
ts_fatal("error opening output file");
int i;
for (i = 0; i < NTRIALS; i++) {
fprintf(outfile, "%d ", data[i].subj);
fprintf(outfile, "%d ", data[i].stimnr);
fprintf(outfile, "%d ", data[i].r);
fprintf(outfile, "%4d ", data[i].rt);
fprintf(outfile, "%4d ", data[i].re);
fprintf(outfile, "%s ", data[i].stim);
fprintf(outfile, "%s ", data[i].resp);
fprintf(outfile, "\n");
}
fclose(outfile);
}
#ifdef TESTRND
int main()
{
readstim();
int i;
for (i = 0; i < 4; i++) {
randomize(i);
writedata();
}
return 0;
}
END_OF_MAIN();
#endif
#define FIXTM 500
#define BLANKTM 500
#define MAXTM 1500
#define FBTM 200
#define ITI 1500
struct {
__int64 junk;
__int64 t1, e1;
__int64 t2, e2;
} tmp;
void trial(int i)
{
ts_vsync(&tmp.junk, &tmp.junk);
ts_printf_centre(0, 0, "+");
ts_wait(mtt(FIXTM));
ts_vsync(&tmp.junk, &tmp.junk);
ts_clrscr();
ts_vsync(&tmp.t1, &tmp.e1);
ts_printf_centre(0, 0, "%s", data[i].stim);
data[i].r = ts_resp(&tmp.t2, &tmp.e2, mtt(MAXTM));
ts_clrscr();
data[i].rt = ttm(tmp.t2 - tmp.t1);
data[i].re = ttmu(tmp.e2 + tmp.e1);
if (data[i].r == 2)
ts_fatal("aborted by user");
if (!data[i].r)
ts_playstream(mtt(FBTM));
else {
int x;
x = ts_printf(-XMAX + 20, -YMAX + 20, "type the response: ");
ts_scanf(-XMAX + 20 + x, -YMAX + 20, "%s", data[i].resp);
if (!strcmp(data[i].stim, data[i].resp))
data[i].corr = 1;
ts_clrscr();
}
if (!data[i].corr)
ts_playstream(mtt(FBTM));
ts_wait(mtt(ITI));
}
#define TRIALTEST TRUE
#ifdef REALEXP
int main()
{
if (!TRIALTEST) {
ts_scrsize(SIZE3);
ts_scrmode(FULLSCREEN);
} else
ts_scrsize(SIZE1);
ts_init();
ts_defkey(KEY_SPACE);
ts_defkey(KEY_ESC);
int subjnr;
do {
ts_clrscr();
int y = ts_printf(-XMAX + 20, YMAX - 20, "Participant number: ");
ts_scanf(-XMAX + 20 + y, YMAX - 20, "%d", &subjnr);
} while (subjnr < 0 || subjnr > 20);
readstim();
randomize(subjnr);
ts_clrscr();
ts_printf_centre(0, 10,
"name the word into the voice key and press space");
ts_printf_centre(0, 0,
"(the space bar replaces the voice key in this example)");
ts_printf_centre(0, -10, "press escape to stop");
ts_button(XMAX - 20, -YMAX + 20);
ts_clrscr();
ts_wait(mtt(1000));
int i;
for (i = 0; i < NTRIALS; i++)
trial(i);
writedata();
ts_printf_centre(0, 0, "all done, thanks!");
ts_button(XMAX - 20, -YMAX + 20);
return 0;
}
END_OF_MAIN();
#endif