Howdy, Stranger!

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

Supported by

Logging multiple variables during audio playback

Hello,

I am designing an experiment where the subject is asked to press the spacebar "in time" with the 20 music stimuli presented in order to measure their pulse synchronicity. So, there are multiple key presses during the stimulus presentation. I can't seem to figure out how to allow for multiple keyboard responses and how to allow for the responses and (most important) their timing to be logged while the audio file is playing.
Things I want to log:
-timing of first spacebar press in relation to the start of the audio stimulus
-timing of each space bar press
-number of space bar presses during the audio stimulus

How might I go about doing this? Thank you,

Kevie

Comments

  • edited September 2017

    Something like this might work:

    timeout         = 5000 
    c               = canvas()
    c.text('test here some keypresses for %s seconds' %timeout)
    
    from openexp.keyboard import keyboard
    import pygame
    kb              = keyboard(exp, keylist = [],timeout=0)
    press_times         = []
    
    c.show()
    start_t         = self.time()
    start_key   = 0
    while True:
        current_t   = self.time()
        duration        = current_t-start_t
        events      = pygame.event.get()
        for event in events:
            if event.type == pygame.KEYDOWN:
                start_key       = self.time()
            if event.type == pygame.KEYUP:
                end_key             = self.time()
                duration_key        = end_key - start_key
                press_times.append((duration_key, event.key))
        if duration > timeout:
            break`
    

    Hope this helps,
    Roelof

  • Roelof,
    Thank you so much for your help. I got the code to work in my experiment, but the log files aren't logging each individual spacebar press. I'm not entirely sure where to/how to define that. I tried including a bit of code I found from a post on this website (albeit, from 2011) to define/rename each individual space press, but that just got me redundant values rather than the actual response times (It doesn't help that I am a beginner when it comes to coding).
    Example:
    self.experiment.set("response_1", self.get("response"))
    self.experiment.set("response_2", self.get("response"))
    self.experiment.set("response_3", self.get("response"))
    self.experiment.set("response_time_1", self.get("response_time"))
    self.experiment.set("response_time_2", self.get("response_time"))
    self.experiment.set("response_time_3", self.get("response_time"))

    Is there something I'm missing in the code you already provided me? Thank you.
    Side note: The number of times the space bar is pressed in each stimulus is variable, as the tempos are different.
    -Kevie

  • Hi Kevie,

    there are several ways in which you can log the variables. I guess since timing is important, it might be best to record all the key presses in one while loop and then set the responses to be logged afterwards, since logging a variable during the while loop might take some time (e.g.:var.responses = press_times).

    Another problem is that there might be a different number of responses for different participants, right?
    This means that if you log each response as a variable, two log files for different participants
    will have different amount of columns, which is a pain in the .. if you want to merge them.

    There are some ways around this:
    1. log the entire list as a single variable, this way each participant has a single response column, but the response is a complete list.
    2. create dummy variables set to 'none' and change those specific responses for which the participant actually gave a response: this means creating many dummies, so many in fact that it is impossible to run out, otherwise the experiment will crash (for 20 seconds maybe 40/50 responses? guess that might be doable)
    3. create a separate log file only for these timing responses, log the rest in the regular log file

    These are not the most elegant solutions, and each has their (dis)advantage, I would suggest trying to figure out which works best in conjunction with your analysis.

    Roelof

  • Thank you so much for your help! Got it working no problem now!

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