Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

2 CallBack functions ? - SOLVED

edited March 2017 in Expyriment

Dear Expyriment experts,

I want to create a design where people have to follow a rhythm (at a specific frequency) using a keyboard. What would be the best approach to code this? I need to log the key (rt) and the rt tones as well.
So far I don't know how I can use two callback functions to get info from keyboard and keep playing the tone. It seems that I cant use keyboard.wait() and using keyboard.check() doesn't give me rt.

Thank you in advance for your help
Arnaud

Comments

  • Oops I think I already have my answer. Everything is already logged even using keyboard.check.

  • Hi there,

    can you give a code example?

    In general, though, if you need very stable and precise audio timing, I would suggest to have the audio played by a dedicated hardware audio sampler, triggered via MIDI from the PC that records the responses.

  • edited April 2017

    So far I was just testing some basic code, but I notice that it may miss a tone sometime. What would be your suggestion ? Thank you in advance.

    from expyriment import control, stimuli, io, design, misc
    from expyriment.misc import constants
    from expyriment.misc._timer import get_time
    
    from config import *
    
    if not windowMode:  # Check WindowMode and Resolution
        control.defaults.window_mode = windowMode
        control.defaults.window_size = misc.get_monitor_resolution()
        windowSize = control.defaults.window_size
    else:
        control.defaults.window_mode = windowMode
        control.defaults.window_size = windowSize
    
    exp = design.Experiment('test')  
    
    trigger = io.Keyboard()
    control.initialize(exp)
    
    tone1 = stimuli.Tone(50, 675)
    tone1.preload()
    
    def my_callback():
        """Quit all event loop with mouse press"""
        global exp
        key = trigger.check([49,50,51,52])
    
    control.register_wait_callback_function(my_callback)
    control.start(exp, auto_create_subject_id=True, skip_ready_screen=True)
    
    while True:
        tone1.play(maxtime=50)
        exp.clock.wait(2000)
    
  • To be honest, I do not understand what you are aiming to do in that code. The my_callback function does not do anything it seems (well, it checks for the keys, but it does nothing with the results of that check).

    If I do understand correctly what you are trying to achieve, then here are two ways to achieve this:

    1)

    from expyriment import control, stimuli, io, design, misc
    
    
    control.set_develop_mode()
    exp = control.initialize()
    
    tone1 = stimuli.Tone(50, 675)
    tone1.preload()
    
    control.start(exp, auto_create_subject_id=True, skip_ready_screen=True)
    
    times = []
    while True:
        tone1.play()
        duration = 2000
        while True:
            key, rt = exp.keyboard.wait([49,50,51,52], duration=duration)
            if rt is None:
                break
            else:
                times.append(exp.clock.time)
                duration -= rt
    

    2)

    from expyriment import control, stimuli, io, design, misc
    
    control.set_develop_mode()
    exp = control.initialize()
    
    tone1 = stimuli.Tone(50, 675)
    tone1.preload()
    
    def callback():
        global exp
        global times
        key = exp.keyboard.check([49,50,51,52])
        if key is not None:
            times.append(exp.clock.time)
    
    control.register_wait_callback_function(callback)
    control.start(exp, auto_create_subject_id=True, skip_ready_screen=True)
    
    times = []
    while True:
        tone1.play()
        exp.clock.wait(2000)
    

    I want to stress again, though, that if you need perfect timing, an external device is the way to go.

  • I know that nothing has been written as a data file but everything is logged in the events folder and it's what I was looking for. Thank you for your advice.

  • I don't think I need perfect timing but what would be the worst case scenario if I keep this kind of script ?

  • The worst case scenario is that you have a jitter of unknown size, leading to (a) you not knowing when exactly the sound was actually played via the speakers, and (b) an unstable rhythm, when playing back sounds consecutively like you do.

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games