Howdy, Stranger!

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

Supported by

Volume control for sampler item

Hello, I am trying to set up an experiment containing four audio events. I want participants to be able to control the volume of each event, while the four audio clips play at the backgorund in a loop. I figured that the volume levels can be adjusted sequentially for each audio event within a seperate loop, which would be distrupted by keypress and followed by the next loop, until all of the four sounds has the desired volume levels.

My questions are;
1- How should I define the variable for the volume level? I want to assign two keys for increasing or decresing the volume level by 0,02. Any tips would help.
2- How can I pass to the next loop, for adjusting the volume of the next event? (already tried break if statements I found on the forum, don't know what went wrong).
3- Is it possible to save the adjusted volume level for the audio file, to be used in the forthcoming loops?

Thanks!

Comments

  • Hi Cagdas,

    Maybe this script here, will help you get started:

    Most importantly, you should note that it doesn't use Opensesame Items (sampler, loop), but all "the magic" happens in an inline_script, by calling those functions directly.

    src1 = exp.pool['a.ogg']
    my_sampler1 = sampler(src1)
    src2 = exp.pool['b.ogg']
    my_sampler2 = sampler(src2)
    src3 = exp.pool['c.ogg']
    my_sampler3 = sampler(src3)
    samplers = [my_sampler1,my_sampler2,my_sampler3]
    kb = keyboard(keylist=['left','right','top','down','return','SPACE'])
    
    cv = canvas()
    sIdx = 0 
    my_sampler1.play()
    my_sampler2.play()
    my_sampler3.play()
    no_sounds = 3
    while True:
        k,t = kb.get_key(timeout=20)
        if k == 'return':
            break
    
        elif k == 'up':
            sIdx -= 1
        elif k == 'down':
            sIdx += 1
        elif k == 'right':
            if samplers[sIdx%no_sounds].volume < 1:
                samplers[sIdx%no_sounds].volume += 0.05
        elif k == 'left':
            if samplers[sIdx%no_sounds].volume > 0:
                samplers[sIdx%no_sounds].volume -= 0.05
    
        text = "Adjust volume of sound %s. \n\n\nCurrent volume  is %s"%(sIdx%no_sounds,samplers[sIdx%no_sounds].volume)
        cv.clear()
        cv.text(text)
        cv.show()
    
    
    #my_sampler1.play()
    

    I hope it makes sense. Let me know if you need more explanation.

    Eduard

    Buy Me A Coffee

  • Thank you Eduard, I will be looking into it.

  • edited June 2017

    Hi again, the code works fine and answered all my above questions. Only I couldn't solve the timing issue. I want certain delays in between the sampler items, so i used the sleep function as below

           my_sampler1.play()
            clock.sleep(750)
            my_sampler2.play()
            clock.sleep(750)
            my_sampler3.play()
            clock.sleep(2000)
    

    The problem is that the volume cannot be adjusted during the loop, but it needs to wait until all the items run once, which makes the session very slow and hard to control. Is there another way that i could put delays and also get faster response to keypresses?

  • Hi Cagdas,

    I don't really get what you mean exactly. You start playing the samplers before the loop, so even if you have those intervals between them, they will overlap once the last sounds begins to play (unless you have very short samples). In the loop itself you can easily adjust the volume online, it will change them right away. At least it does so for me.

    If your version is different, would you mind uploading it, so I can have a look?
    Eduard

    Buy Me A Coffee

  • Hi,
    Actually the code is not different, except that the above code is inserted just after the while true statment. I have very short samples, which are indeed 4x70ms clicks playing continously. Since the volume level ascends and descends in 0.02 steps, I wonder if there is a way to apply several keypresses during the loop, so that the next loop, for example, can start 0.08 step higher. Otherwise, it still works, but each keypress must wait until the the loop is finished.

    One more thing, my advisor said that it is strange that the number of clicks displayed starts from 0. Is there a way to call the first item in the samplers list as 1 instead of 0. Tried to change sIdx to 1 but didn't work.

    Thanks a lot.

  • Hi,

    Is there a way to call the first item in the samplers list as 1 instead of 0

    Change this line: text = "Adjust volume of sound %s. \n\n\nCurrent volume is %s"%(sIdx%no_sounds,samplers[sIdx%no_sounds].volume)

    to:

    text = "Adjust volume of sound %s. \n\n\nCurrent volume is %s"%((sIdx%no_sounds)+1,samplers[sIdx%no_sounds].volume)

    I have very short samples, which are indeed 4x70ms clicks playing continously.

    So, there is no overlap? How about this code below.Instead of sleeping in between the samples, this code samples key strokes. So, in theory you can update the volume almost continuously.

    src1 = exp.pool['a.ogg']
    my_sampler1 = sampler(src1)
    src2 = exp.pool['b.ogg']
    my_sampler2 = sampler(src2)
    src3 = exp.pool['c.ogg']
    my_sampler3 = sampler(src3)
    samplers = [my_sampler1,my_sampler2,my_sampler3]
    kb = keyboard(keylist=['left','right','top','down','return','SPACE'])
    
    cv = canvas()
    sIdx = 0 
    no_sounds = 3
    
    while True: 
        my_sampler1.play()
        t0 = clock.time()
        while clock.time()-t0<750:
            k1,t1 = kb.get_key(timeout=10)
            if k == 'right':
                 if samplers[sIdx%no_sounds].volume < 1:
                     samplers[sIdx%no_sounds].volume += 0.05
            elif k == 'left':
                 if samplers[sIdx%no_sounds].volume > 0:
                     samplers[sIdx%no_sounds].volume -= 0.05
            kb.flush()
        my_sampler2.play()
        t0 = clock.time()
        while clock.time()-t0<750:
            k1,t1 = kb.get_key(timeout=10)
            if k == 'right':
                 if samplers[sIdx%no_sounds].volume < 1:
                     samplers[sIdx%no_sounds].volume += 0.05
            elif k == 'left':
                 if samplers[sIdx%no_sounds].volume > 0:
                     samplers[sIdx%no_sounds].volume -= 0.05
            kb.flush()
        my_sampler3.play()
        t0 = clock.time()
        while clock.time()-t0<2000:
            k1,t1 = kb.get_key(timeout=10)
            if k == 'right':
                 if samplers[sIdx%no_sounds].volume < 1:
                     samplers[sIdx%no_sounds].volume += 0.05
            elif k == 'left':
                 if samplers[sIdx%no_sounds].volume > 0:
                     samplers[sIdx%no_sounds].volume -= 0.05
            kb.flush()
    
        k,t = kb.get_key(timeout=200)
        if k == 'return':
            break
        elif k == 'up':
            sIdx -= 1
        elif k == 'down':
            sIdx += 1
        elif k == 'right':
            if samplers[sIdx%no_sounds].volume < 1:
                samplers[sIdx%no_sounds].volume += 0.05
        elif k == 'left':
            if samplers[sIdx%no_sounds].volume > 0:
                samplers[sIdx%no_sounds].volume -= 0.05
    
        text = "Adjust volume of sound %s. \n\n\nCurrent volume  is %s"%(sIdx%no_sounds,samplers[sIdx%no_sounds].volume)
        cv.clear()
        cv.text(text)
        cv.show()
    

    Hope this works ( I didn't test it).
    Eduard

    Buy Me A Coffee

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