[Csnd] Tracking mouse velocity
Date | 2018-10-27 16:36 |
From | Gerard Rodríguez |
Subject | [Csnd] Tracking mouse velocity |
Hello everyone, I want to create a virtual instrument in which the amplitude is controlled with the mouse. Like bowing a violin, or turning the wheel of a hurdy gurdy or bellowing an accordion, you get the idea. In theory this should be easy enough to do in csound, just get the mouse position and get the derivative which should be the speed. I've tried the diff opcode but it doesn't seem to work. I've also tried the manual way by delaying the mouse signal and substracting it from the last one: instr 1 koutx, kouty, kinside FLxyin 0, 1920, 0, 1080, 0, 1920, 0, 1080 kdely delayk kouty, 0.1, 2 kdelx delayk koutx, 0.1, 2 kdiffy = (kdely - kouty)/0.1 kdiffx = (kdelx - koutx)/0.1 kmag = sqrt(kdiffy^2+kdiffx^2) aout poscil kmag/4000, 220 outs aout, aout endin That kinda works but generates a lot of noise (the velocity is returning lots of 0's for some reason) What am I doing wrong? |
Date | 2018-10-27 18:30 |
From | Mauro Giubileo |
Subject | Re: [Csnd] Tracking mouse velocity |
Hi, the problem with your program is that you change the oscillator amplitude too abruptly => noise. You should change the amplitude in a smooth way. There are many ways to do this, it's up to your imagination and to what you want to achieve. I made some little changes to your code and made a poor man's Theremin in CsoundQT. That's fun... :-D <CsoundSynthesizer> <CsOptions> -odac -d </CsOptions> <CsInstruments>
sr = 44100 ksmps = 32 nchnls = 2 0dbfs = 1
gixres = 1024 giyres = 768
FLpanel "FLxyin", gixres, giyres, -1, -1, 3 FLpanelEnd FLrun
instr 1 koutx, kouty, kinside FLxyin 0, gixres, 0, giyres, 0, gixres, 0, giyres kdely delayk kouty, 0.1, 2 kdelx delayk koutx, 0.1, 2 kdiffy = (kdely - kouty)/0.1 kdiffx = (kdelx - koutx)/0.1 ;kmag = sqrt(kdiffy^2 + kdiffx^2) kmag init 0 kmag = kmag * 0.99 + sqrt(kdiffy^2 + kdiffx^2) * 0.01 kmag = (kmag > 4000)? 4000 : kmag aout poscil kmag/4000, 220 + koutx outs aout, aout endin
</CsInstruments> <CsScore> i1 0 z </CsScore> </CsoundSynthesizer> Regards, Il 2018-10-27 17:36 Gerard Rodríguez ha scritto:
|
Date | 2018-10-27 21:27 |
From | Gerard Rodríguez |
Subject | Re: [Csnd] Tracking mouse velocity |
Huh, well your changes to kmag did the trick. Thank you! The idea is to choose the note with the pc keyboard and "bow it" with the mouse :PMissatge de Mauro Giubileo <mgiubileo@computeraltafed.it> del dia ds., 27 d’oct. 2018 a les 19:30:
|
Date | 2018-10-27 22:26 |
From | Gerard Rodríguez |
Subject | Re: [Csnd] Tracking mouse velocity |
Something like this: <CsoundSynthesizer> <CsOptions> ; Select audio/midi flags here according to platform ; Audio out Audio in -odac -d -iadc -+rtmidi=virtual -M0 </CsOptions> <CsInstruments> sr = 44100 ksmps = 32 nchnls = 2 0dbfs = 1 inote = 440 gaRvbSend init 0 FLpanel "FLxyin",1920, 1080, -1, -1, 5, 1, 1 FLpanelEnd FLrun instr 1 inote cpsmidi koutx, kouty, kinside FLxyin 0, 1920, 0, 1080, 0, 1920, 0, 1080 kdely delayk kouty, 0.01, 2 kdelx delayk koutx, 0.01, 2 kdiff2y = (kdely - kouty)/0.01 kdiff2x = (kdelx - koutx)/0.01 kmag init 0 kmag = kmag * 0.99 + sqrt(kdiff2y^2 + kdiff2x^2) * 0.01 kmag = (kmag > 4000)? 4000 : kmag aout wgbow 0.8*(kmag/4000), inote, 3, 0.127236, 0, 0 outs aout, aout iRvbSendAmt = 0.8 ; reverb send amount (0 - 1) ; add some of the audio from this instrument to the global reverb send variable gaRvbSend = gaRvbSend + (aout * iRvbSendAmt) endin instr 5 ; reverb - always on kroomsize init 0.35 ; room size (range 0 to 1) kHFDamp init 0.5 ; high freq. damping (range 0 to 1) ; create reverberated version of input signal (note stereo input and output) aRvbL,aRvbR freeverb gaRvbSend, gaRvbSend,kroomsize,kHFDamp outs aRvbL, aRvbR ; send audio to outputs clear gaRvbSend ; clear global audio variable endin </CsInstruments> <CsScore> i 5 0 4000 ; start reverb </CsScore> </CsoundSynthesizer> Unfortunately I'm still getting some noise. And the virtual keyboard can't be used outside the window. Missatge de Gerard Rodríguez <binbiniqegabenik@gmail.com> del dia ds., 27 d’oct. 2018 a les 22:27:
|
Date | 2018-10-27 23:53 |
From | Mauro Giubileo |
Subject | Re: [Csnd] Tracking mouse velocity |
Beware of mouse tendinitis... :P P.S.: Inspired from your work I just made a sort of Theremin-clone that soon I will publish somewhere. It doesn't get the amplitude from the speed of the mouse movement, but just from the vertical mouse position, like in the Theremin instrument. Regards, Il 2018-10-27 22:27 Gerard Rodríguez ha scritto:
|
Date | 2018-10-28 00:18 |
From | Mauro Giubileo |
Subject | Re: [Csnd] Tracking mouse velocity |
Hi, instead of this: kmag = kmag * 0.99 + sqrt(kdiff2y^2 + kdiff2x^2) * 0.01 you can try with this one: kmag = kmag * 0.999 + sqrt(kdiff2y^2 + kdiff2x^2) * 0.001 it softens even more the amplitude changes, so you shouldn't have noise anymore. About the virtual keyboard, I don't think it was designed to work while you have focus on another window. Maybe you should try with a real midi keyboard. Regards, Il 2018-10-27 23:26 Gerard Rodríguez ha scritto:
|
Date | 2018-10-28 11:53 |
From | Gerard Rodríguez |
Subject | Re: [Csnd] Tracking mouse velocity |
Thanks. Well, the point is to have a usable instrument with just the keyboard and mouse, using a MIDI keyboard defeats the purpose.Missatge de Mauro Giubileo <mgiubileo@computeraltafed.it> del dia dg., 28 d’oct. 2018 a les 1:18:
|
Date | 2018-10-28 11:54 |
From | Gerard Rodríguez |
Subject | Re: [Csnd] Tracking mouse velocity |
I'll just make my own virtual keyboard by using FLkeyIn, not a big deal. Missatge de Gerard Rodríguez <binbiniqegabenik@gmail.com> del dia dg., 28 d’oct. 2018 a les 12:53:
|
Date | 2018-10-28 12:00 |
From | Mauro Giubileo |
Subject | Re: [Csnd] Tracking mouse velocity |
Yes, I think that's the right way. ;-) P.S.: If you have a little time, you can try my little csd I made for fun. You can download the code here: https://github.com/maurocsound/the-mad-whistler/blob/master/tmw.csd Best regards, Il 2018-10-28 12:54 Gerard Rodríguez ha scritto:
|
Date | 2018-10-28 12:53 |
From | Gerard Rodríguez |
Subject | Re: [Csnd] Tracking mouse velocity |
Sounds good. Incidentally I spent some time researching how to model a theremin, it's a bit of a rabbit hole, harder than you would think. https://theremin.tf/wp-content/uploads/2015/03/wavegen.pdf that's a starting point, but the real moog theremin's sound GOOD, way better than the modeled ones, with that vocal quality. I had some csd's but I can't find them, should have made a git repo like you :P Missatge de Mauro Giubileo <mgiubileo@computeraltafed.it> del dia dg., 28 d’oct. 2018 a les 13:00:
|
Date | 2018-10-28 16:18 |
From | Mauro Giubileo |
Subject | Re: [Csnd] Tracking mouse velocity |
I never used github, so I took the opportunity to learn how it works and share with you this fun instrument I made yesterday. I listened to some real Theremins from youtube and from what I listened, I don't think it should be so difficult to make that sound... It seems to me like a very basic waveform. The vibrato effect is just a frequency movement, like in my whistler. Maybe there is something I'm missing? Anyway, when I have time I should try... Regards, Il 2018-10-28 13:53 Gerard Rodríguez ha scritto:
|
Date | 2018-10-28 16:41 |
From | Gerard Rodríguez |
Subject | Re: [Csnd] Tracking mouse velocity |
It kinda is a simple waveform, however one of the thing that none of the models get right is that it changes based on frequency, which is very noticeable, and without having a real theremin to record the waveform I don't really know how exactly it changes. Also some theremin's have a more vocal timbre like this one: https://www.youtube.com/watch?v=K6KbEnGnymk sounds pretty good. I think that it's one of those things that's deceptively simple and it's easy to make a bad imitation. Anyways be my guest it would be really cool if you get it right ;)Missatge de Mauro Giubileo <mgiubileo@computeraltafed.it> del dia dg., 28 d’oct. 2018 a les 17:18:
|