matlab sound 播出 不对,matlab中使用sound函数,为什么总是会导致连接的数位板采点延迟?...

s=1

while 1

while s <= 1

CurrentPos=zeros(500,2);

%画中心注视cross

Screen('DrawTexture',theWindow,cross);

Screen('Flip',theWindow);

target = 1;

trialnum = s;    %刺激编号

%读取声音文件

fName = strcat('writemodesoundfiles\du100ms','.wav') ;

[y,freq]=audioread(char(fName));

sound(y,freq);

t1 = GetSecs;

[clicks,xpos,ypos,whichButton]=GetClicks;

k = 1;

if clicks==1

restarttime = GetSecs;

rt = restarttime - t1;

flag = 1;

end

%但关于采点的问题:1.总是陆续采到连续相同的坐标;2.可能是因为音频播放的问题,总是延迟采点,声音播放后3~5s之内被试画线,但数位板不能显示并记录,声音停止播放后3~5s可以显示并记录被试画的线

while flag==1

[MouseX,MouseY,button]=GetMouse(theWindow);

if (MouseX>0||MouseX<0||MouseY>0||MouseY<0)       %控制开始采点的条件

flag=3;

lastX=MouseX;

lastY=MouseY;

while flag==3     %控制采点的位置和采点结束的条件

[MouseX,MouseY,button]=GetMouse(theWindow);

CurrentPos(k,1)=MouseX;

CurrentPos(k,2)=MouseY;

[MouseX,MouseY,button]=GetMouse(theWindow);

showX=MouseX;

showY=MouseY;

DrawEachLine(lastX,lastY,showX,showY,scale,ovalR,blue,theWindow);

Screen('Flip',theWindow,[],1);

lastX=showX;

lastY=showY;

k=k+1;

[kD,secs, keyCode] = KbCheck();

if  keyCode(Etr)

flag=4;

end

end

%记录采点结束时的鼠标位置,给出声音提示,画线

[MouseX,MouseY,button]=GetMouse(theWindow);

CurrentPos(k,1)=MouseX;

CurrentPos(k,2)=MouseY;

k=k+1;

showX=MouseX;

showY=MouseY;

DrawEachLine(lastX,lastY,showX,showY,scale,ovalR,blue,theWindow);

Screen('Flip',theWindow,[],1);

end

%检测到按空格键时跳出while flag=1循环

[kD,secs,keyCode] = KbCheck();

if  keyCode(Etr)

end

end

Screen('DrawTexture',theWindow,cross);

Screen('Flip',theWindow);

%记录k>2时,所有鼠标位置的坐标,输出并保存文件

if k>=2

for temp=1:k-1

fprintf(fp,'%d\t%.2f\t%.2f\t%d\t%d\t%.2f\n',trialnum,GoalPosition(target,1),GoalPosition(target,2),CurrentPos(temp,1),CurrentPos(temp,2),rt);

end

fprintf(fp2,'%d\t%.2f\t%.2f\t%d\t%d\t%.2f\n',trialnum,GoalPosition(target,1),GoalPosition(target,2),CurrentPos(k-1,1),CurrentPos(k-1,2),rt);

s=s+1;

end

end

Screen('DrawTexture',theWindow,endpic);

Screen('Flip',theWindow);

while KbCheck; end     %确认按键释放完毕

[secs, keyCode, deltaSecs] = KbWait();     %等待按键

Screen('CloseAll');

end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值