Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 脑电实验中不规则延迟的心理变态播放声音_Python_Real Time_Delay_Eventtrigger_Psychopy - Fatal编程技术网

Python 脑电实验中不规则延迟的心理变态播放声音

Python 脑电实验中不规则延迟的心理变态播放声音,python,real-time,delay,eventtrigger,psychopy,Python,Real Time,Delay,Eventtrigger,Psychopy,我用心理变态来准备一个奇怪的范例,在这个范例中,我在屏幕上预设了一张图片7秒钟,在图片展示过程中,每半秒钟显示14个连续的声音。对于每个声音开始,我都会向并行端口发送一个触发器。然后,我运行计时测试,查看声音是否与触发器同时播放 虽然触发器似乎很好,每半秒钟就会出现一次,但声音却不是这样。触发后,声音以100ms-200ms的延迟播放,连续声音的启动时间相差不到半秒。声音文件的大小没有什么区别,对于非常短的声音(10ms)和更长的声音(250ms),延迟似乎都是如此。我试图在每次试验开始时添加I

我用心理变态来准备一个奇怪的范例,在这个范例中,我在屏幕上预设了一张图片7秒钟,在图片展示过程中,每半秒钟显示14个连续的声音。对于每个声音开始,我都会向并行端口发送一个触发器。然后,我运行计时测试,查看声音是否与触发器同时播放

虽然触发器似乎很好,每半秒钟就会出现一次,但声音却不是这样。触发后,声音以100ms-200ms的延迟播放,连续声音的启动时间相差不到半秒。声音文件的大小没有什么区别,对于非常短的声音(10ms)和更长的声音(250ms),延迟似乎都是如此。我试图在每次试验开始时添加ISI,并在此期间加载图片和声音,但没有任何帮助

我还尝试在每个声音之前添加ISI,并在这些短片ISI期间加载声音,但也没有帮助。你知道如何解决这个问题吗?ISI有什么办法可以帮忙吗?我应该在试验开始时有一个ISI来加载该试验的所有刺激物,还是每个试验有多个ISI,每个刺激物一个

视觉刺激(即图片)的延迟很小,在整个试验中是恒定的

下面的代码只播放两种声音,但很好地演示了这个问题

from __future__ import absolute_import, division
from psychopy import locale_setup, sound, gui, visual, core, data, event, logging, parallel
from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
                                STOPPED, FINISHED, PRESSED, RELEASED, FOREVER)

# Setup the Window
win = visual.Window(
    size=(1920, 1080), fullscr=True, screen=0,
    allowGUI=True, allowStencil=False,
    monitor='testMonitor', color=[-1, -1, -1], colorSpace='rgb',
    blendMode='avg', useFBO=True)
snd_2_tr = 'sound1.wav'
snd_3_tr = 'sound2.wav'
picture_tr = 'pic.jpg'
win.setRecordFrameIntervals(True)
win._refreshThreshold = 1 / 60.0 + 0.004
image_tr = visual.ImageStim(
    win=win, name='image_tr',
    image='sin', mask=None,
    ori=0, pos=(0, 0), size=None,
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=128, interpolate=True, depth=0.0)
sound_2_tr = sound.Sound('A', secs=-1)
sound_2_tr.setVolume(1)
sound_3_tr = sound.Sound('A', secs=-1)
sound_3_tr.setVolume(1)
image_port_tr = parallel.ParallelPort(address='0xD010')
sound_2_port_tr = parallel.ParallelPort(address='0xD010')
sound_3_port_tr = parallel.ParallelPort(address='0xD010')
ISI_17 = core.StaticPeriod(win=win, screenHz=60, name='ISI_17')

# ------Prepare to start Routine "main_tr"-------
main_trClock = core.Clock()
t = 0
main_trClock.reset()  # clock
frameN = -1
continueRoutine = True
# keep track of which components have finished
main_trComponents = [image_tr, sound_2_tr, sound_3_tr, image_port_tr, sound_2_port_tr, sound_3_port_tr, ISI_17]
for thisComponent in main_trComponents:
    if hasattr(thisComponent, 'status'):
        thisComponent.status = NOT_STARTED

# -------Start Routine "main_tr"-------
while continueRoutine:
    # get current time
    t = main_trClock.getTime()
    frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
    # update/draw components on each frame

    # *image_tr* updates
    if frameN >= 60 and image_tr.status == NOT_STARTED:
        # keep track of start time/frame for later
        image_tr.tStart = t
        image_tr.frameNStart = frameN  # exact frame index
        image_tr.setAutoDraw(True)
    if image_tr.status == STARTED and frameN >= (image_tr.frameNStart + 420):
        image_tr.setAutoDraw(False)

    # start/stop sound_2_tr
    if frameN >= 90 and sound_2_tr.status == NOT_STARTED:
        # keep track of start time/frame for later
        sound_2_tr.tStart = t
        sound_2_tr.frameNStart = frameN  # exact frame index
        sound_2_tr.play()  # start the sound (it finishes automatically)
    if sound_2_tr.status == STARTED and t >= (sound_2_tr.tStart + 0.25):
        sound_2_tr.stop()  # stop the sound (if longer than duration)
    # start/stop sound_3_tr
    if frameN >= 120 and sound_3_tr.status == NOT_STARTED:
        # keep track of start time/frame for later
        sound_3_tr.tStart = t
        sound_3_tr.frameNStart = frameN  # exact frame index
        sound_3_tr.play()  # start the sound (it finishes automatically)
    if sound_3_tr.status == STARTED and t >= (sound_3_tr.tStart + 0.25):
        sound_3_tr.stop()  # stop the sound (if longer than duration)
    # *sound_1_port_tr* updates
    if frameN >= 60 and image_port_tr.status == NOT_STARTED:
        # keep track of start time/frame for later
        image_port_tr.tStart = t
        image_port_tr.frameNStart = frameN  # exact frame index
        image_port_tr.status = STARTED
        win.callOnFlip(image_port_tr.setData, int(triggers_image_tr))
    if image_port_tr.status == STARTED and frameN >= (image_port_tr.frameNStart + 15):
        image_port_tr.status = STOPPED
        win.callOnFlip(image_port_tr.setData, int(0))
    # *sound_2_port_tr* updates
    if frameN >= 90 and sound_2_port_tr.status == NOT_STARTED:
        # keep track of start time/frame for later
        sound_2_port_tr.tStart = t
        sound_2_port_tr.frameNStart = frameN  # exact frame index
        sound_2_port_tr.status = STARTED
        win.callOnFlip(sound_2_port_tr.setData, int(triggers_sound_2_tr))
    if sound_2_port_tr.status == STARTED and frameN >= (sound_2_port_tr.frameNStart + 15):
        sound_2_port_tr.status = STOPPED
        win.callOnFlip(sound_2_port_tr.setData, int(0))
    # *sound_3_port_tr* updates
    if frameN >= 120 and sound_3_port_tr.status == NOT_STARTED:
        # keep track of start time/frame for later
        sound_3_port_tr.tStart = t
        sound_3_port_tr.frameNStart = frameN  # exact frame index
        sound_3_port_tr.status = STARTED
        win.callOnFlip(sound_3_port_tr.setData, int(triggers_sound_3_tr))
    if sound_3_port_tr.status == STARTED and frameN >= (sound_3_port_tr.frameNStart + 15):
        sound_3_port_tr.status = STOPPED
        win.callOnFlip(sound_3_port_tr.setData, int(0))
    # *ISI_17* period
    if frameN >= 0 and ISI_17.status == NOT_STARTED:
        # keep track of start time/frame for later
        ISI_17.tStart = t
        ISI_17.frameNStart = frameN  # exact frame index
        ISI_17.start(60 * frameDur)
    elif ISI_17.status == STARTED:  # one frame should pass before updating params and completing
        # updating other components during *ISI_17*
        image_tr.setImage(picture_tr)
        sound_2_tr.setSound(snd_2_tr, secs=0.25)
        sound_3_tr.setSound(snd_3_tr, secs=0.25)
        # component updates done
        ISI_17.complete()  # finish the static period

    # check if all components have finished
    if not continueRoutine:  # a component has requested a forced-end of Routine
        break
    continueRoutine = False  # will revert to True if at least one component still running
    for thisComponent in main_trComponents:
        if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
            continueRoutine = True
            break  # at least one component has not yet finished

    # check for quit (the Esc key)
    if endExpNow or event.getKeys(keyList=["escape"]):
        core.quit()

    # refresh the screen
    if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
        win.flip()

您应该发布一些代码。这种问题可能更适合在论坛上提出,在论坛上有机会就您的情况进行更多的来回讨论(因此更适合于特定的编程问题)。e、 g.此线程解决了一些可能与您相关的问题: