Csound Csound-dev Csound-tekno Search About

Re: [Csnd] A Toggle button for Android Csound?

Date2023-09-07 01:13
FromScott Daughtrey
SubjectRe: [Csnd] A Toggle button for Android Csound?
Hi Art.

As per the Michael's meeting today, here's a simple example that uses the phone accelerometer as control signals. In this case the amp & freq. Try holding the phone flat, facing upwards. Then tilt towards your face, side to side etc. It's sensitive but with practice becomes more intuitive. You can get some "whale sounds" with this one, maybe add an lfo & emulate a theremin.

A novelty, but can be fun, useful or perhaps both.

Here's the code, or you can download it from the link below.



-odac -m2


sr = 48000
ksmps = 32
nchnls = 2
0dbfs  = 1

; initialize global reverb
gaRvb init

instr sine
    kAccelX chnget "accelerometerX"
    kAccelY chnget "accelerometerY"
; printk 1, kAccelX
; printk 1, kAccelY
    iAmp    = .7
    kAmpMod = portk(kAccelX/30, .5)
    iFrq    = 110
    kFrqMod = portk(kAccelY * 100, .5)
    aEnv    = linsegr:a(0, 1, .8, p3, .8, 3, 0)
    aSig    = poscil(iAmp * kAmpMod * aEnv, iFrq + kFrqMod)
    outs(aSig, aSig)
    gaRvb  += aSig * .4
endin

instr reverb
    aRvbL, aRvbR reverbsc gaRvb, gaRvb, 0.94, 12000
    outs aRvbL,aRvbR
    clear gaRvb
endin



i"reverb" 0 z
i"sine"   0 z




https://github.com/ST-Music/csound-examples/blob/main/Android/accelerometer_example.csd

Scott

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2023-09-08 04:45
FromArthur Hunkins <000001e1d761dea2-dmarc-request@LISTSERV.HEANET.IE>
SubjectRe: [Csnd] A Toggle button for Android Csound?
Hi Scott and Michael -

Scott, thanks for this "accelerometer demo". I've adapted your X and Y accels for a new Android Accelerometer Tester .csd.

I want to include the Z accel also. What do you know about this one? I presume it's the third rotation vector sensor, but I can't make much sense of what it's doing. Seems to be a 360 degree, 3D combination of the other two.

Anyone had any experience with the Z accelerometer, or how it might plausibly be used? (All of the Android apps seem to implement it.)

TIA

Art H.



abhunkin@uncg.edu
http://www.arthunkins.com

From: A discussion list for users of Csound <CSOUND@LISTSERV.HEANET.IE> on behalf of Scott Daughtrey <stunes6556@GMAIL.COM>
Sent: Wednesday, September 6, 2023 8:13 PM
To: CSOUND@LISTSERV.HEANET.IE <CSOUND@LISTSERV.HEANET.IE>
Subject: Re: [Csnd] A Toggle button for Android Csound?
 
Hi Art.

As per the Michael's meeting today, here's a simple example that uses the phone accelerometer as control signals. In this case the amp & freq. Try holding the phone flat, facing upwards. Then tilt towards your face, side to side etc. It's sensitive but with practice becomes more intuitive. You can get some "whale sounds" with this one, maybe add an lfo & emulate a theremin.

A novelty, but can be fun, useful or perhaps both.

Here's the code, or you can download it from the link below.

<CsoundSynthesizer>
<CsOptions>
-odac -m2
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 32
nchnls = 2
0dbfs  = 1

; initialize global reverb
gaRvb init

instr sine
    kAccelX chnget "accelerometerX"
    kAccelY chnget "accelerometerY"
; printk 1, kAccelX
; printk 1, kAccelY
    iAmp    = .7
    kAmpMod = portk(kAccelX/30, .5)
    iFrq    = 110
    kFrqMod = portk(kAccelY * 100, .5)
    aEnv    = linsegr:a(0, 1, .8, p3, .8, 3, 0)
    aSig    = poscil(iAmp * kAmpMod * aEnv, iFrq + kFrqMod)
    outs(aSig, aSig)
    gaRvb  += aSig * .4
endin

instr reverb
    aRvbL, aRvbR reverbsc gaRvb, gaRvb, 0.94, 12000
    outs aRvbL,aRvbR
    clear gaRvb
endin

</CsInstruments>
<CsScore>
i"reverb" 0 z
i"sine"   0 z
</CsScore>
</CsoundSynthesizer>


https://github.com/ST-Music/csound-examples/blob/main/Android/accelerometer_example.csd

Scott

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2023-09-08 06:58
FromST Music
SubjectRe: [Csnd] A Toggle button for Android Csound?
Hi Art. 

Strictly speaking, if you hold your phone straight up & down, moving left or right (X-axis) changes the accel.X values. Moving it up or down affects Y. Moving it forwards (towards your face) or away from you affects Z (depth).

This is similar to how 3D art, math plotting & other programs (like CAD) work.

Where it generally gets tricky is that to perceive these changes the movements in this context have to be relatively quick (accelerating) - with the example code I sent if you shift the phone very quickly to either side the volume increases but the pitch doesn't change (or very little if you can keep it straight up & down). However, once motion stops the phone seems to quickly recalibrate this new position as being 0 again (no longer accelerating).

Oddly enough, if you rotate the phone towards the left or right, the X values change similarly but the phone doesn't recalibrate. So if X is set to affect amp values, simply rotating the phone to one side seems a much better way to control the amp than trying to "slide" (accelerate) it L or R.

Rotating the phone also affects the Y axis, but not Z (again if one could hold the phone _perfectly_  flat on the Z axis).
So with the example I sent, if you start it with the phone perfectly upright, you should hear nothing. If you roll the screen away from you towards the sky - nothing as long as the phone is essentially flat like sitting on a table. 

Tilting the screen backwards, away from you towards the sky is the best way to control the Z axis.

This way, subtly tilting the upright phone say 90° to either side or towards the sky gives decent control over all 3 axis. With a little practice it gets quite intuitive.

There are other apps that read the accelerometer, linear accelerometer, gyroscope etc. like Physics Toolbox Suite which is really helpful in terms of visually watching how the sensors react & what values they send; it plots and can record the movement and values of all 3 axis simulaneously using different colors. Easier than reading the console output.


but you have to be careful which mode/meter you use. I suggest using that app, clicking on the hamburger icon and choosing the g-Force Meter.

You'll see it accurately shows what's explained above. Slide your phone to either side quickly then back. Values shift towards the center again. Rotate the phone sideways or rotate the screen towards the sky, the values stay changed as long as the phone is rotated. 

You can also try the Dual Sensor mode of the Physics Suite (hamburger icon, scroll way down near the bottom). Select something like g-Force & Gyroscope - you might understand why I chose to use the X, Y & Z accel. 

Sometimes X & Y are enough, although X & Z can be better at times in which case rotating sideways will only affect X, rotating towards the sky only affects Z.

With the Gyroscope, tilting forward and back affects the X axis plot, not Z, which is quite non-intuitive to those who perceive X as left to right, Y as up and down and Z as depth.

So with the Gyroscope, rotating sideways affects Z, rotating the face of the phone towards the sky (tilting it) affects X, and turning your phone so that your staring at the side and can't see it affects Y, the latter being kind of uncomfortable & impractical.

Hope that helps. If you have more questions let me know.

Scott

On Thu, Sept 7, 2023, 11:45 p.m. Arthur Hunkins <000001e1d761dea2-dmarc-request@listserv.heanet.ie> wrote:
Hi Scott and Michael -

Scott, thanks for this "accelerometer demo". I've adapted your X and Y accels for a new Android Accelerometer Tester .csd.

I want to include the Z accel also. What do you know about this one? I presume it's the third rotation vector sensor, but I can't make much sense of what it's doing. Seems to be a 360 degree, 3D combination of the other two.

Anyone had any experience with the Z accelerometer, or how it might plausibly be used? (All of the Android apps seem to implement it.)

TIA

Art H.



From: A discussion list for users of Csound <CSOUND@LISTSERV.HEANET.IE> on behalf of Scott Daughtrey <stunes6556@GMAIL.COM>
Sent: Wednesday, September 6, 2023 8:13 PM
To: CSOUND@LISTSERV.HEANET.IE <CSOUND@LISTSERV.HEANET.IE>
Subject: Re: [Csnd] A Toggle button for Android Csound?
 
Hi Art.

As per the Michael's meeting today, here's a simple example that uses the phone accelerometer as control signals. In this case the amp & freq. Try holding the phone flat, facing upwards. Then tilt towards your face, side to side etc. It's sensitive but with practice becomes more intuitive. You can get some "whale sounds" with this one, maybe add an lfo & emulate a theremin.

A novelty, but can be fun, useful or perhaps both.

Here's the code, or you can download it from the link below.

<CsoundSynthesizer>
<CsOptions>
-odac -m2
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 32
nchnls = 2
0dbfs  = 1

; initialize global reverb
gaRvb init

instr sine
    kAccelX chnget "accelerometerX"
    kAccelY chnget "accelerometerY"
; printk 1, kAccelX
; printk 1, kAccelY
    iAmp    = .7
    kAmpMod = portk(kAccelX/30, .5)
    iFrq    = 110
    kFrqMod = portk(kAccelY * 100, .5)
    aEnv    = linsegr:a(0, 1, .8, p3, .8, 3, 0)
    aSig    = poscil(iAmp * kAmpMod * aEnv, iFrq + kFrqMod)
    outs(aSig, aSig)
    gaRvb  += aSig * .4
endin

instr reverb
    aRvbL, aRvbR reverbsc gaRvb, gaRvb, 0.94, 12000
    outs aRvbL,aRvbR
    clear gaRvb
endin

</CsInstruments>
<CsScore>
i"reverb" 0 z
i"sine"   0 z
</CsScore>
</CsoundSynthesizer>


https://github.com/ST-Music/csound-examples/blob/main/Android/accelerometer_example.csd

Scott

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2023-09-08 07:16
FromST Music
SubjectRe: [Csnd] A Toggle button for Android Csound?
I should have also mentioned: if you open any meter/mode while in the Physics Toolbox Suite, you can click on the info icon (circled i) and it gives in depth explanations as to how the sensor works. Well worth a look.

There are also links under "Additional Resources" that link to informative YouTube videos.

On Fri, Sept 8, 2023, 1:58 a.m. ST Music <stunes6556@gmail.com> wrote:
Hi Art. 

Strictly speaking, if you hold your phone straight up & down, moving left or right (X-axis) changes the accel.X values. Moving it up or down affects Y. Moving it forwards (towards your face) or away from you affects Z (depth).

This is similar to how 3D art, math plotting & other programs (like CAD) work.

Where it generally gets tricky is that to perceive these changes the movements in this context have to be relatively quick (accelerating) - with the example code I sent if you shift the phone very quickly to either side the volume increases but the pitch doesn't change (or very little if you can keep it straight up & down). However, once motion stops the phone seems to quickly recalibrate this new position as being 0 again (no longer accelerating).

Oddly enough, if you rotate the phone towards the left or right, the X values change similarly but the phone doesn't recalibrate. So if X is set to affect amp values, simply rotating the phone to one side seems a much better way to control the amp than trying to "slide" (accelerate) it L or R.

Rotating the phone also affects the Y axis, but not Z (again if one could hold the phone _perfectly_  flat on the Z axis).
So with the example I sent, if you start it with the phone perfectly upright, you should hear nothing. If you roll the screen away from you towards the sky - nothing as long as the phone is essentially flat like sitting on a table. 

Tilting the screen backwards, away from you towards the sky is the best way to control the Z axis.

This way, subtly tilting the upright phone say 90° to either side or towards the sky gives decent control over all 3 axis. With a little practice it gets quite intuitive.

There are other apps that read the accelerometer, linear accelerometer, gyroscope etc. like Physics Toolbox Suite which is really helpful in terms of visually watching how the sensors react & what values they send; it plots and can record the movement and values of all 3 axis simulaneously using different colors. Easier than reading the console output.


but you have to be careful which mode/meter you use. I suggest using that app, clicking on the hamburger icon and choosing the g-Force Meter.

You'll see it accurately shows what's explained above. Slide your phone to either side quickly then back. Values shift towards the center again. Rotate the phone sideways or rotate the screen towards the sky, the values stay changed as long as the phone is rotated. 

You can also try the Dual Sensor mode of the Physics Suite (hamburger icon, scroll way down near the bottom). Select something like g-Force & Gyroscope - you might understand why I chose to use the X, Y & Z accel. 

Sometimes X & Y are enough, although X & Z can be better at times in which case rotating sideways will only affect X, rotating towards the sky only affects Z.

With the Gyroscope, tilting forward and back affects the X axis plot, not Z, which is quite non-intuitive to those who perceive X as left to right, Y as up and down and Z as depth.

So with the Gyroscope, rotating sideways affects Z, rotating the face of the phone towards the sky (tilting it) affects X, and turning your phone so that your staring at the side and can't see it affects Y, the latter being kind of uncomfortable & impractical.

Hope that helps. If you have more questions let me know.

Scott

On Thu, Sept 7, 2023, 11:45 p.m. Arthur Hunkins <000001e1d761dea2-dmarc-request@listserv.heanet.ie> wrote:
Hi Scott and Michael -

Scott, thanks for this "accelerometer demo". I've adapted your X and Y accels for a new Android Accelerometer Tester .csd.

I want to include the Z accel also. What do you know about this one? I presume it's the third rotation vector sensor, but I can't make much sense of what it's doing. Seems to be a 360 degree, 3D combination of the other two.

Anyone had any experience with the Z accelerometer, or how it might plausibly be used? (All of the Android apps seem to implement it.)

TIA

Art H.



From: A discussion list for users of Csound <CSOUND@LISTSERV.HEANET.IE> on behalf of Scott Daughtrey <stunes6556@GMAIL.COM>
Sent: Wednesday, September 6, 2023 8:13 PM
To: CSOUND@LISTSERV.HEANET.IE <CSOUND@LISTSERV.HEANET.IE>
Subject: Re: [Csnd] A Toggle button for Android Csound?
 
Hi Art.

As per the Michael's meeting today, here's a simple example that uses the phone accelerometer as control signals. In this case the amp & freq. Try holding the phone flat, facing upwards. Then tilt towards your face, side to side etc. It's sensitive but with practice becomes more intuitive. You can get some "whale sounds" with this one, maybe add an lfo & emulate a theremin.

A novelty, but can be fun, useful or perhaps both.

Here's the code, or you can download it from the link below.

<CsoundSynthesizer>
<CsOptions>
-odac -m2
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 32
nchnls = 2
0dbfs  = 1

; initialize global reverb
gaRvb init

instr sine
    kAccelX chnget "accelerometerX"
    kAccelY chnget "accelerometerY"
; printk 1, kAccelX
; printk 1, kAccelY
    iAmp    = .7
    kAmpMod = portk(kAccelX/30, .5)
    iFrq    = 110
    kFrqMod = portk(kAccelY * 100, .5)
    aEnv    = linsegr:a(0, 1, .8, p3, .8, 3, 0)
    aSig    = poscil(iAmp * kAmpMod * aEnv, iFrq + kFrqMod)
    outs(aSig, aSig)
    gaRvb  += aSig * .4
endin

instr reverb
    aRvbL, aRvbR reverbsc gaRvb, gaRvb, 0.94, 12000
    outs aRvbL,aRvbR
    clear gaRvb
endin

</CsInstruments>
<CsScore>
i"reverb" 0 z
i"sine"   0 z
</CsScore>
</CsoundSynthesizer>


https://github.com/ST-Music/csound-examples/blob/main/Android/accelerometer_example.csd

Scott

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2023-09-08 16:28
FromArthur Hunkins <000001e1d761dea2-dmarc-request@LISTSERV.HEANET.IE>
SubjectRe: [Csnd] A Toggle button for Android Csound?
Hi Scott and Michael -

Thanks, Scott, for your excellent example .csd and explanation of the Android accelerometer features. I've come up with a preliminary AndroidAccelerometerTester.csd, included below, inspired by your example, and the virtual meeting hosted by Michael two days ago.

I ask your (Scott) permission to quote substantially from your example at the beginning of my .csd - as much-needed basic guidance for any user.

I'd much appreciate both of you checking this .csd and its introductary commentary for accuracy and your general feedback. I'm still not sure I fully understand what is going on!

(I'll also presently share a companion AndroidWidgetTester.csd I've developed - which I mentioned in our meeting. Both use the same sound source. These .csd's should run on all historical Android Csounds, dating back to CSD Player.)

Art H.
​​​​​​​​​​​​​​​​​​____________________________

CSOUND FOR ANDROID ACCELEROMETER TESTER

; This .csd tests Csound for Android accelerometer functionality - x, y and z axes. These are rotation vector sensors. AccelerometerX controls amplitude, Y controls frequency, and Z, tone color.

; If you hold your phone straight up & down, moving left or right (X-axis) changes the accel.X values. Moving it up or down affects Y. Moving it forwards (towards your face) or away from you affects Z (depth).
; Where it generally gets tricky is that to perceive these changes the movements in this context have to be relatively quick (accelerating). Once motion stops the phone seems to quickly recalibrate this new position as being 0 again (no longer accelerating).

<CsoundSynthesizer>
<CsOptions>

-odac -m0d

</CsOptions>
<CsInstruments>

      sr = 44100
      ksmps = 32
      nchnls = 2
      0dbfs  = 1

      instr 1

kfreq init 400
kamp  init 0
kpw   init .5
kamp  chnget "accelerometerX"
kamp  = kamp * .04
kamp  port kamp, .1
kfreq chnget "accelerometerY"
kfreq = 400 + (kfreq * 40)
kfreq port kfreq, .1
kpw   chnget "accelerometerZ"
kpw   = .5 + (kpw * .045)
kpw   port kpw, .1
a1    vco2 kamp, kfreq, 4, kpw
      outs a1, a1

      endin

</CsInstruments>
<CsScore>

i1 0 z
e

</CsScore>
</CsoundSynthesizer>



abhunkin@uncg.edu
http://www.arthunkins.com

From: A discussion list for users of Csound <CSOUND@LISTSERV.HEANET.IE> on behalf of ST Music <stunes6556@GMAIL.COM>
Sent: Friday, September 8, 2023 1:58 AM
To: CSOUND@LISTSERV.HEANET.IE <CSOUND@LISTSERV.HEANET.IE>
Subject: Re: [Csnd] A Toggle button for Android Csound?
 
Hi Art. 

Strictly speaking, if you hold your phone straight up & down, moving left or right (X-axis) changes the accel.X values. Moving it up or down affects Y. Moving it forwards (towards your face) or away from you affects Z (depth).

This is similar to how 3D art, math plotting & other programs (like CAD) work.

Where it generally gets tricky is that to perceive these changes the movements in this context have to be relatively quick (accelerating) - with the example code I sent if you shift the phone very quickly to either side the volume increases but the pitch doesn't change (or very little if you can keep it straight up & down). However, once motion stops the phone seems to quickly recalibrate this new position as being 0 again (no longer accelerating).

Oddly enough, if you rotate the phone towards the left or right, the X values change similarly but the phone doesn't recalibrate. So if X is set to affect amp values, simply rotating the phone to one side seems a much better way to control the amp than trying to "slide" (accelerate) it L or R.

Rotating the phone also affects the Y axis, but not Z (again if one could hold the phone _perfectly_  flat on the Z axis).
So with the example I sent, if you start it with the phone perfectly upright, you should hear nothing. If you roll the screen away from you towards the sky - nothing as long as the phone is essentially flat like sitting on a table. 

Tilting the screen backwards, away from you towards the sky is the best way to control the Z axis.

This way, subtly tilting the upright phone say 90° to either side or towards the sky gives decent control over all 3 axis. With a little practice it gets quite intuitive.

There are other apps that read the accelerometer, linear accelerometer, gyroscope etc. like Physics Toolbox Suite which is really helpful in terms of visually watching how the sensors react & what values they send; it plots and can record the movement and values of all 3 axis simulaneously using different colors. Easier than reading the console output.


but you have to be careful which mode/meter you use. I suggest using that app, clicking on the hamburger icon and choosing the g-Force Meter.

You'll see it accurately shows what's explained above. Slide your phone to either side quickly then back. Values shift towards the center again. Rotate the phone sideways or rotate the screen towards the sky, the values stay changed as long as the phone is rotated. 

You can also try the Dual Sensor mode of the Physics Suite (hamburger icon, scroll way down near the bottom). Select something like g-Force & Gyroscope - you might understand why I chose to use the X, Y & Z accel. 

Sometimes X & Y are enough, although X & Z can be better at times in which case rotating sideways will only affect X, rotating towards the sky only affects Z.

With the Gyroscope, tilting forward and back affects the X axis plot, not Z, which is quite non-intuitive to those who perceive X as left to right, Y as up and down and Z as depth.

So with the Gyroscope, rotating sideways affects Z, rotating the face of the phone towards the sky (tilting it) affects X, and turning your phone so that your staring at the side and can't see it affects Y, the latter being kind of uncomfortable & impractical.

Hope that helps. If you have more questions let me know.

Scott

On Thu, Sept 7, 2023, 11:45 p.m. Arthur Hunkins <000001e1d761dea2-dmarc-request@listserv.heanet.ie> wrote:
Hi Scott and Michael -

Scott, thanks for this "accelerometer demo". I've adapted your X and Y accels for a new Android Accelerometer Tester .csd.

I want to include the Z accel also. What do you know about this one? I presume it's the third rotation vector sensor, but I can't make much sense of what it's doing. Seems to be a 360 degree, 3D combination of the other two.

Anyone had any experience with the Z accelerometer, or how it might plausibly be used? (All of the Android apps seem to implement it.)

TIA

Art H.



From: A discussion list for users of Csound <CSOUND@LISTSERV.HEANET.IE> on behalf of Scott Daughtrey <stunes6556@GMAIL.COM>
Sent: Wednesday, September 6, 2023 8:13 PM
To: CSOUND@LISTSERV.HEANET.IE <CSOUND@LISTSERV.HEANET.IE>
Subject: Re: [Csnd] A Toggle button for Android Csound?
 
Hi Art.

As per the Michael's meeting today, here's a simple example that uses the phone accelerometer as control signals. In this case the amp & freq. Try holding the phone flat, facing upwards. Then tilt towards your face, side to side etc. It's sensitive but with practice becomes more intuitive. You can get some "whale sounds" with this one, maybe add an lfo & emulate a theremin.

A novelty, but can be fun, useful or perhaps both.

Here's the code, or you can download it from the link below.

<CsoundSynthesizer>
<CsOptions>
-odac -m2
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 32
nchnls = 2
0dbfs  = 1

; initialize global reverb
gaRvb init

instr sine
    kAccelX chnget "accelerometerX"
    kAccelY chnget "accelerometerY"
; printk 1, kAccelX
; printk 1, kAccelY
    iAmp    = .7
    kAmpMod = portk(kAccelX/30, .5)
    iFrq    = 110
    kFrqMod = portk(kAccelY * 100, .5)
    aEnv    = linsegr:a(0, 1, .8, p3, .8, 3, 0)
    aSig    = poscil(iAmp * kAmpMod * aEnv, iFrq + kFrqMod)
    outs(aSig, aSig)
    gaRvb  += aSig * .4
endin

instr reverb
    aRvbL, aRvbR reverbsc gaRvb, gaRvb, 0.94, 12000
    outs aRvbL,aRvbR
    clear gaRvb
endin

</CsInstruments>
<CsScore>
i"reverb" 0 z
i"sine"   0 z
</CsScore>
</CsoundSynthesizer>


https://github.com/ST-Music/csound-examples/blob/main/Android/accelerometer_example.csd

Scott

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2023-09-08 21:55
FromST Music
SubjectRe: [Csnd] A Toggle button for Android Csound?
Hi Art,
   a few observations.

I can't explain exactly why these occur,  I have a basic idea, but suspect someone who understand the physics of how something like an accelerometer for a phone is designed to work might be able to (although it likely wouldn't help me personally in terms of practical use). So this is anecdotal based on trial & error as well as using reported values. 

Sliding/moving the phone left to right isn't a good way to generate control signals, especially with such a low port rate. The changes in audio are almost inaudible as the phone seems to recalibrate the axis baselines very quickly. It's also a little uncomfortable to do so.

The most effective way is to use rotation, for a few reasons. When you rotate the phone, the values do not try to recalibrate - the values hold as long as the phone is in a certain position. It also allows much more subtle control with a minimum amount of movement depending on how you set up the control signals.

The sensors seem extremely sensitive & not likely perfectly calibrated. They probably vary slightly in accuracy for every phone. There appear to be methods to calibrate the accelerometer & perhaps other sensors, as well as apps to assist, if you Google it. I haven't tried but probably will later tonight.

The reason I like the Physics app I linked before is it clearly shows the values as the phone is moved/rotated, or stationary, along a timeline (chart).

With the phone held in a straight up/down position, the value of:
• X is ~ 0
• Y is ~ 1
• Z is ~ .25

At last on my phone as currently calibrated.

If it is flat, such as lying on a table with the screen facing up:
• X is ~ 0
• Y is ~ 0
• Z is ~ 1

If it is flat, lying on a table with the screen facing down:
• X is ~ 0
• Y is ~ 0
• Z is ~ -1

I personally like starting with the phone in the upright position, finding it the most physically advantageous as I'm usually sitting back in a chair. If standing, it might be easier to adjust variables to accommodate startng with the phone in a flat position, as if on a table. 

Assuming one starts with the phone in an upright (vertical) position:

Tilting (rotating) the top of the phone slightly to the left (going from a vertical to a horizontal position) increases X values (> 0). Fully horizontal X = 0. Tilting it to the right, from vertical to horizontal, decreases them (<0). Fully horizontal X = 1.

Tilting (rotating) the top of the phone slightly to the left also decreases Y values < 1 towards 0. Tilting it to the right also decreases them < 1.

Tilting (rotating) the top of the phone slightly away from your face raises Z values towards 1. When it is fully "flat" (the screen is horizontal & facing up) it reaches 1.

Tilting (rotating) the top of the phone slightly away from your face also decreases Y values from 1 towards 0. The opposite values of Z. When it is fully "flat", Y reaches 0.

So, tilting the screen sideways from vertical to horizontal affects both the X & Y values.

Tilting the phone from upright (vertical), facing you, to pointing the screen upwards (moving it towards a flat position facing the sky) affects both the Y & Z values. Y values move from 1 to 0,  Z from ~ .25 to 1.

Therefore careful consideration of these linked values is probably important overall. 

Although my initial example uses pitch as a variable, in practical usage it's often not a great choice as pitch can in many cases be hard to control with any precision. It's fun for effect though. And I'm sure one could set up a toggle switch to activate it when desired.

Amplitude (or other variables) in realtime might be more practical.

I modified your example to demonstrate. In this case, starting in standard vertical position, the amplitude is .5. If you rotate the phone to the left from vertical to horizontal, the amp increases. Rotating right decreases the amp.

If you tilt/rotate the screen from the screen being vertical upright to facing upwards, the PWM increases. On that note I changed the vco2 mode from saw/triangle/ramp to square/PWM as it's easier to hear the PWM.

Since rotating from vertical to horizontal (sideways) affects both the X & Y values, eliminating Y from the equation is helpful.

And as rotating the screen from facing you to facing upwards affects both the Y & Z axis, again eliminating Y removes it from consideration.

In the example below amp (X) & PWM (Z) can be altered independently. They can also work together - if you rotate the screen away from you to a flat position, facing upwards, the PWM increases. From that position, if you tilt the screen towards the left the amp decreases as does the PWM. If you tilt it to the right, the amp increases while the PWM decreases.

Y is the more difficult value to make use of since rotating sideways towards horizontal OR from facing towards you to screen facing up changes the value.

You can see it takes some consideration as to how you set the variables up, depending on usage and whether one chooses to start in an upright position or one in which you start from the phone in a position that is flat, like sitting on a table.

Here's the example:

<CsoundSynthesizer>
<CsOptions>

-odac -m0d

</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

    instr 1

kamp  chnget "accelerometerX"
kamp  = .5 - port(kamp * .05, .1)
; printk .5, kamp
kpw   chnget "accelerometerZ"
kpw   = lfo(.49, .5) * kpw * .1 + .5
kpw   port kpw, .1  
; printk .5, kpw
a1  vco2  kamp, 220, 2, kpw
    outs a1, a1

    endin

</CsInstruments>
<CsScore>
i1 0 z
e

</CsScore>
</CsoundSynthesizer>

If you have more questions let me know. And if you ever want help with a specific use case, again let me know. If you're still not sure about using the accelerometer or just want to discuss it we can always set up a Zoom meeting, it's probably easier to demonstrate it that way. I'm not always the most concise writer.

Hope that helps a bit. If you like I can email you or reply here with the csd attached if that makes things easier. Or put it on github & send a link. I'll do that soon anyways, when I have time to properly add comments to an example and write a description.

Feel free to use, edited or otherwise, anything I've written.

Cheers,
Scott


On Fri, Sept 8, 2023, 11:28 a.m. Arthur Hunkins <000001e1d761dea2-dmarc-request@listserv.heanet.ie> wrote:
Hi Scott and Michael -

Thanks, Scott, for your excellent example .csd and explanation of the Android accelerometer features. I've come up with a preliminary AndroidAccelerometerTester.csd, included below, inspired by your example, and the virtual meeting hosted by Michael two days ago.

I ask your (Scott) permission to quote substantially from your example at the beginning of my .csd - as much-needed basic guidance for any user.

I'd much appreciate both of you checking this .csd and its introductary commentary for accuracy and your general feedback. I'm still not sure I fully understand what is going on!

(I'll also presently share a companion AndroidWidgetTester.csd I've developed - which I mentioned in our meeting. Both use the same sound source. These .csd's should run on all historical Android Csounds, dating back to CSD Player.)

Art H.
​​​​​​​​​​​​​​​​​​____________________________

CSOUND FOR ANDROID ACCELEROMETER TESTER

; This .csd tests Csound for Android accelerometer functionality - x, y and z axes. These are rotation vector sensors. AccelerometerX controls amplitude, Y controls frequency, and Z, tone color.

; If you hold your phone straight up & down, moving left or right (X-axis) changes the accel.X values. Moving it up or down affects Y. Moving it forwards (towards your face) or away from you affects Z (depth).
; Where it generally gets tricky is that to perceive these changes the movements in this context have to be relatively quick (accelerating). Once motion stops the phone seems to quickly recalibrate this new position as being 0 again (no longer accelerating).

<CsoundSynthesizer>
<CsOptions>

-odac -m0d

</CsOptions>
<CsInstruments>

      sr = 44100
      ksmps = 32
      nchnls = 2
      0dbfs  = 1

      instr 1

kfreq init 400
kamp  init 0
kpw   init .5
kamp  chnget "accelerometerX"
kamp  = kamp * .04
kamp  port kamp, .1
kfreq chnget "accelerometerY"
kfreq = 400 + (kfreq * 40)
kfreq port kfreq, .1
kpw   chnget "accelerometerZ"
kpw   = .5 + (kpw * .045)
kpw   port kpw, .1
a1    vco2 kamp, kfreq, 4, kpw
      outs a1, a1

      endin

</CsInstruments>
<CsScore>

i1 0 z
e

</CsScore>
</CsoundSynthesizer>



From: A discussion list for users of Csound <CSOUND@LISTSERV.HEANET.IE> on behalf of ST Music <stunes6556@GMAIL.COM>
Sent: Friday, September 8, 2023 1:58 AM
To: CSOUND@LISTSERV.HEANET.IE <CSOUND@LISTSERV.HEANET.IE>
Subject: Re: [Csnd] A Toggle button for Android Csound?
 
Hi Art. 

Strictly speaking, if you hold your phone straight up & down, moving left or right (X-axis) changes the accel.X values. Moving it up or down affects Y. Moving it forwards (towards your face) or away from you affects Z (depth).

This is similar to how 3D art, math plotting & other programs (like CAD) work.

Where it generally gets tricky is that to perceive these changes the movements in this context have to be relatively quick (accelerating) - with the example code I sent if you shift the phone very quickly to either side the volume increases but the pitch doesn't change (or very little if you can keep it straight up & down). However, once motion stops the phone seems to quickly recalibrate this new position as being 0 again (no longer accelerating).

Oddly enough, if you rotate the phone towards the left or right, the X values change similarly but the phone doesn't recalibrate. So if X is set to affect amp values, simply rotating the phone to one side seems a much better way to control the amp than trying to "slide" (accelerate) it L or R.

Rotating the phone also affects the Y axis, but not Z (again if one could hold the phone _perfectly_  flat on the Z axis).
So with the example I sent, if you start it with the phone perfectly upright, you should hear nothing. If you roll the screen away from you towards the sky - nothing as long as the phone is essentially flat like sitting on a table. 

Tilting the screen backwards, away from you towards the sky is the best way to control the Z axis.

This way, subtly tilting the upright phone say 90° to either side or towards the sky gives decent control over all 3 axis. With a little practice it gets quite intuitive.

There are other apps that read the accelerometer, linear accelerometer, gyroscope etc. like Physics Toolbox Suite which is really helpful in terms of visually watching how the sensors react & what values they send; it plots and can record the movement and values of all 3 axis simulaneously using different colors. Easier than reading the console output.


but you have to be careful which mode/meter you use. I suggest using that app, clicking on the hamburger icon and choosing the g-Force Meter.

You'll see it accurately shows what's explained above. Slide your phone to either side quickly then back. Values shift towards the center again. Rotate the phone sideways or rotate the screen towards the sky, the values stay changed as long as the phone is rotated. 

You can also try the Dual Sensor mode of the Physics Suite (hamburger icon, scroll way down near the bottom). Select something like g-Force & Gyroscope - you might understand why I chose to use the X, Y & Z accel. 

Sometimes X & Y are enough, although X & Z can be better at times in which case rotating sideways will only affect X, rotating towards the sky only affects Z.

With the Gyroscope, tilting forward and back affects the X axis plot, not Z, which is quite non-intuitive to those who perceive X as left to right, Y as up and down and Z as depth.

So with the Gyroscope, rotating sideways affects Z, rotating the face of the phone towards the sky (tilting it) affects X, and turning your phone so that your staring at the side and can't see it affects Y, the latter being kind of uncomfortable & impractical.

Hope that helps. If you have more questions let me know.

Scott

On Thu, Sept 7, 2023, 11:45 p.m. Arthur Hunkins <000001e1d761dea2-dmarc-request@listserv.heanet.ie> wrote:
Hi Scott and Michael -

Scott, thanks for this "accelerometer demo". I've adapted your X and Y accels for a new Android Accelerometer Tester .csd.

I want to include the Z accel also. What do you know about this one? I presume it's the third rotation vector sensor, but I can't make much sense of what it's doing. Seems to be a 360 degree, 3D combination of the other two.

Anyone had any experience with the Z accelerometer, or how it might plausibly be used? (All of the Android apps seem to implement it.)

TIA

Art H.



From: A discussion list for users of Csound <CSOUND@LISTSERV.HEANET.IE> on behalf of Scott Daughtrey <stunes6556@GMAIL.COM>
Sent: Wednesday, September 6, 2023 8:13 PM
To: CSOUND@LISTSERV.HEANET.IE <CSOUND@LISTSERV.HEANET.IE>
Subject: Re: [Csnd] A Toggle button for Android Csound?
 
Hi Art.

As per the Michael's meeting today, here's a simple example that uses the phone accelerometer as control signals. In this case the amp & freq. Try holding the phone flat, facing upwards. Then tilt towards your face, side to side etc. It's sensitive but with practice becomes more intuitive. You can get some "whale sounds" with this one, maybe add an lfo & emulate a theremin.

A novelty, but can be fun, useful or perhaps both.

Here's the code, or you can download it from the link below.

<CsoundSynthesizer>
<CsOptions>
-odac -m2
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 32
nchnls = 2
0dbfs  = 1

; initialize global reverb
gaRvb init

instr sine
    kAccelX chnget "accelerometerX"
    kAccelY chnget "accelerometerY"
; printk 1, kAccelX
; printk 1, kAccelY
    iAmp    = .7
    kAmpMod = portk(kAccelX/30, .5)
    iFrq    = 110
    kFrqMod = portk(kAccelY * 100, .5)
    aEnv    = linsegr:a(0, 1, .8, p3, .8, 3, 0)
    aSig    = poscil(iAmp * kAmpMod * aEnv, iFrq + kFrqMod)
    outs(aSig, aSig)
    gaRvb  += aSig * .4
endin

instr reverb
    aRvbL, aRvbR reverbsc gaRvb, gaRvb, 0.94, 12000
    outs aRvbL,aRvbR
    clear gaRvb
endin

</CsInstruments>
<CsScore>
i"reverb" 0 z
i"sine"   0 z
</CsScore>
</CsoundSynthesizer>


https://github.com/ST-Music/csound-examples/blob/main/Android/accelerometer_example.csd

Scott

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2023-09-09 07:04
FromST Music
SubjectRe: [Csnd] A Toggle button for Android Csound?
A quick update. I calibrated my accelerometer, similar results as before, although Z changed a fair bit. 

One important thing I forgot to mention - the values I used were based on the Physics app. Apologies for any confusion, that was a bad oversight. 

Csound generally seems to scale the values from -10 to 10, not 0 to 1 (hence the adjustments in the code, usually relating to: * .1).

Approx. values:

X:
• rotated left, fully horizontal = 10
• upright = 0
• rotated right = -10
• upside down = 0

Y:
• upright = 10
• rotated right = 0
• upside down = - 10
• rotated left, fully horizontal = 0

• screen facing up = 0
• screen facing down = 0

Z:
• upright, screen towards you = 0
• rotated, screen facing up = 10
• upside down, screen facing away from view = 0
• screen facing floor = -10

Here's a quick example that uses X, Y & Z.

When upright, amp is .5. Rotating left or right alters the amp. No PWM. When you start tilting the screen towards facing upward the speed of the PWM increases as does the depth:

<CsoundSynthesizer>
<CsOptions>
-odac -m0d
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

    instr 1

kamp  chnget "accelerometerX"
; printk .5, kamp
kamp  = .5 + port(kamp * .05, .1)
klfo  chnget "accelerometerY"
; printk .5, klfo
kpw   chnget "accelerometerZ"
; printk .5, kpw
kpw   = lfo(.49, 1 - (klfo * .1)) * kpw * .1 + .5
kpw   port kpw, .1  
a1    vco2 kamp, 220, 2, kpw
      outs a1, a1

    endin

</CsInstruments>
<CsScore>
i1 0 z
e
</CsScore>
</CsoundSynthesizer>

On Fri, Sept 8, 2023, 4:55 p.m. ST Music <stunes6556@gmail.com> wrote:
Hi Art,
   a few observations.

I can't explain exactly why these occur,  I have a basic idea, but suspect someone who understand the physics of how something like an accelerometer for a phone is designed to work might be able to (although it likely wouldn't help me personally in terms of practical use). So this is anecdotal based on trial & error as well as using reported values. 

Sliding/moving the phone left to right isn't a good way to generate control signals, especially with such a low port rate. The changes in audio are almost inaudible as the phone seems to recalibrate the axis baselines very quickly. It's also a little uncomfortable to do so.

The most effective way is to use rotation, for a few reasons. When you rotate the phone, the values do not try to recalibrate - the values hold as long as the phone is in a certain position. It also allows much more subtle control with a minimum amount of movement depending on how you set up the control signals.

The sensors seem extremely sensitive & not likely perfectly calibrated. They probably vary slightly in accuracy for every phone. There appear to be methods to calibrate the accelerometer & perhaps other sensors, as well as apps to assist, if you Google it. I haven't tried but probably will later tonight.

The reason I like the Physics app I linked before is it clearly shows the values as the phone is moved/rotated, or stationary, along a timeline (chart).

With the phone held in a straight up/down position, the value of:
• X is ~ 0
• Y is ~ 1
• Z is ~ .25

At last on my phone as currently calibrated.

If it is flat, such as lying on a table with the screen facing up:
• X is ~ 0
• Y is ~ 0
• Z is ~ 1

If it is flat, lying on a table with the screen facing down:
• X is ~ 0
• Y is ~ 0
• Z is ~ -1

I personally like starting with the phone in the upright position, finding it the most physically advantageous as I'm usually sitting back in a chair. If standing, it might be easier to adjust variables to accommodate startng with the phone in a flat position, as if on a table. 

Assuming one starts with the phone in an upright (vertical) position:

Tilting (rotating) the top of the phone slightly to the left (going from a vertical to a horizontal position) increases X values (> 0). Fully horizontal X = 0. Tilting it to the right, from vertical to horizontal, decreases them (<0). Fully horizontal X = 1.

Tilting (rotating) the top of the phone slightly to the left also decreases Y values < 1 towards 0. Tilting it to the right also decreases them < 1.

Tilting (rotating) the top of the phone slightly away from your face raises Z values towards 1. When it is fully "flat" (the screen is horizontal & facing up) it reaches 1.

Tilting (rotating) the top of the phone slightly away from your face also decreases Y values from 1 towards 0. The opposite values of Z. When it is fully "flat", Y reaches 0.

So, tilting the screen sideways from vertical to horizontal affects both the X & Y values.

Tilting the phone from upright (vertical), facing you, to pointing the screen upwards (moving it towards a flat position facing the sky) affects both the Y & Z values. Y values move from 1 to 0,  Z from ~ .25 to 1.

Therefore careful consideration of these linked values is probably important overall. 

Although my initial example uses pitch as a variable, in practical usage it's often not a great choice as pitch can in many cases be hard to control with any precision. It's fun for effect though. And I'm sure one could set up a toggle switch to activate it when desired.

Amplitude (or other variables) in realtime might be more practical.

I modified your example to demonstrate. In this case, starting in standard vertical position, the amplitude is .5. If you rotate the phone to the left from vertical to horizontal, the amp increases. Rotating right decreases the amp.

If you tilt/rotate the screen from the screen being vertical upright to facing upwards, the PWM increases. On that note I changed the vco2 mode from saw/triangle/ramp to square/PWM as it's easier to hear the PWM.

Since rotating from vertical to horizontal (sideways) affects both the X & Y values, eliminating Y from the equation is helpful.

And as rotating the screen from facing you to facing upwards affects both the Y & Z axis, again eliminating Y removes it from consideration.

In the example below amp (X) & PWM (Z) can be altered independently. They can also work together - if you rotate the screen away from you to a flat position, facing upwards, the PWM increases. From that position, if you tilt the screen towards the left the amp decreases as does the PWM. If you tilt it to the right, the amp increases while the PWM decreases.

Y is the more difficult value to make use of since rotating sideways towards horizontal OR from facing towards you to screen facing up changes the value.

You can see it takes some consideration as to how you set the variables up, depending on usage and whether one chooses to start in an upright position or one in which you start from the phone in a position that is flat, like sitting on a table.

Here's the example:

<CsoundSynthesizer>
<CsOptions>

-odac -m0d

</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

    instr 1

kamp  chnget "accelerometerX"
kamp  = .5 - port(kamp * .05, .1)
; printk .5, kamp
kpw   chnget "accelerometerZ"
kpw   = lfo(.49, .5) * kpw * .1 + .5
kpw   port kpw, .1  
; printk .5, kpw
a1  vco2  kamp, 220, 2, kpw
    outs a1, a1

    endin

</CsInstruments>
<CsScore>
i1 0 z
e

</CsScore>
</CsoundSynthesizer>

If you have more questions let me know. And if you ever want help with a specific use case, again let me know. If you're still not sure about using the accelerometer or just want to discuss it we can always set up a Zoom meeting, it's probably easier to demonstrate it that way. I'm not always the most concise writer.

Hope that helps a bit. If you like I can email you or reply here with the csd attached if that makes things easier. Or put it on github & send a link. I'll do that soon anyways, when I have time to properly add comments to an example and write a description.

Feel free to use, edited or otherwise, anything I've written.

Cheers,
Scott


On Fri, Sept 8, 2023, 11:28 a.m. Arthur Hunkins <000001e1d761dea2-dmarc-request@listserv.heanet.ie> wrote:
Hi Scott and Michael -

Thanks, Scott, for your excellent example .csd and explanation of the Android accelerometer features. I've come up with a preliminary AndroidAccelerometerTester.csd, included below, inspired by your example, and the virtual meeting hosted by Michael two days ago.

I ask your (Scott) permission to quote substantially from your example at the beginning of my .csd - as much-needed basic guidance for any user.

I'd much appreciate both of you checking this .csd and its introductary commentary for accuracy and your general feedback. I'm still not sure I fully understand what is going on!

(I'll also presently share a companion AndroidWidgetTester.csd I've developed - which I mentioned in our meeting. Both use the same sound source. These .csd's should run on all historical Android Csounds, dating back to CSD Player.)

Art H.
​​​​​​​​​​​​​​​​​​____________________________

CSOUND FOR ANDROID ACCELEROMETER TESTER

; This .csd tests Csound for Android accelerometer functionality - x, y and z axes. These are rotation vector sensors. AccelerometerX controls amplitude, Y controls frequency, and Z, tone color.

; If you hold your phone straight up & down, moving left or right (X-axis) changes the accel.X values. Moving it up or down affects Y. Moving it forwards (towards your face) or away from you affects Z (depth).
; Where it generally gets tricky is that to perceive these changes the movements in this context have to be relatively quick (accelerating). Once motion stops the phone seems to quickly recalibrate this new position as being 0 again (no longer accelerating).

<CsoundSynthesizer>
<CsOptions>

-odac -m0d

</CsOptions>
<CsInstruments>

      sr = 44100
      ksmps = 32
      nchnls = 2
      0dbfs  = 1

      instr 1

kfreq init 400
kamp  init 0
kpw   init .5
kamp  chnget "accelerometerX"
kamp  = kamp * .04
kamp  port kamp, .1
kfreq chnget "accelerometerY"
kfreq = 400 + (kfreq * 40)
kfreq port kfreq, .1
kpw   chnget "accelerometerZ"
kpw   = .5 + (kpw * .045)
kpw   port kpw, .1
a1    vco2 kamp, kfreq, 4, kpw
      outs a1, a1

      endin

</CsInstruments>
<CsScore>

i1 0 z
e

</CsScore>
</CsoundSynthesizer>



From: A discussion list for users of Csound <CSOUND@LISTSERV.HEANET.IE> on behalf of ST Music <stunes6556@GMAIL.COM>
Sent: Friday, September 8, 2023 1:58 AM
To: CSOUND@LISTSERV.HEANET.IE <CSOUND@LISTSERV.HEANET.IE>
Subject: Re: [Csnd] A Toggle button for Android Csound?
 
Hi Art. 

Strictly speaking, if you hold your phone straight up & down, moving left or right (X-axis) changes the accel.X values. Moving it up or down affects Y. Moving it forwards (towards your face) or away from you affects Z (depth).

This is similar to how 3D art, math plotting & other programs (like CAD) work.

Where it generally gets tricky is that to perceive these changes the movements in this context have to be relatively quick (accelerating) - with the example code I sent if you shift the phone very quickly to either side the volume increases but the pitch doesn't change (or very little if you can keep it straight up & down). However, once motion stops the phone seems to quickly recalibrate this new position as being 0 again (no longer accelerating).

Oddly enough, if you rotate the phone towards the left or right, the X values change similarly but the phone doesn't recalibrate. So if X is set to affect amp values, simply rotating the phone to one side seems a much better way to control the amp than trying to "slide" (accelerate) it L or R.

Rotating the phone also affects the Y axis, but not Z (again if one could hold the phone _perfectly_  flat on the Z axis).
So with the example I sent, if you start it with the phone perfectly upright, you should hear nothing. If you roll the screen away from you towards the sky - nothing as long as the phone is essentially flat like sitting on a table. 

Tilting the screen backwards, away from you towards the sky is the best way to control the Z axis.

This way, subtly tilting the upright phone say 90° to either side or towards the sky gives decent control over all 3 axis. With a little practice it gets quite intuitive.

There are other apps that read the accelerometer, linear accelerometer, gyroscope etc. like Physics Toolbox Suite which is really helpful in terms of visually watching how the sensors react & what values they send; it plots and can record the movement and values of all 3 axis simulaneously using different colors. Easier than reading the console output.


but you have to be careful which mode/meter you use. I suggest using that app, clicking on the hamburger icon and choosing the g-Force Meter.

You'll see it accurately shows what's explained above. Slide your phone to either side quickly then back. Values shift towards the center again. Rotate the phone sideways or rotate the screen towards the sky, the values stay changed as long as the phone is rotated. 

You can also try the Dual Sensor mode of the Physics Suite (hamburger icon, scroll way down near the bottom). Select something like g-Force & Gyroscope - you might understand why I chose to use the X, Y & Z accel. 

Sometimes X & Y are enough, although X & Z can be better at times in which case rotating sideways will only affect X, rotating towards the sky only affects Z.

With the Gyroscope, tilting forward and back affects the X axis plot, not Z, which is quite non-intuitive to those who perceive X as left to right, Y as up and down and Z as depth.

So with the Gyroscope, rotating sideways affects Z, rotating the face of the phone towards the sky (tilting it) affects X, and turning your phone so that your staring at the side and can't see it affects Y, the latter being kind of uncomfortable & impractical.

Hope that helps. If you have more questions let me know.

Scott

On Thu, Sept 7, 2023, 11:45 p.m. Arthur Hunkins <000001e1d761dea2-dmarc-request@listserv.heanet.ie> wrote:
Hi Scott and Michael -

Scott, thanks for this "accelerometer demo". I've adapted your X and Y accels for a new Android Accelerometer Tester .csd.

I want to include the Z accel also. What do you know about this one? I presume it's the third rotation vector sensor, but I can't make much sense of what it's doing. Seems to be a 360 degree, 3D combination of the other two.

Anyone had any experience with the Z accelerometer, or how it might plausibly be used? (All of the Android apps seem to implement it.)

TIA

Art H.



From: A discussion list for users of Csound <CSOUND@LISTSERV.HEANET.IE> on behalf of Scott Daughtrey <stunes6556@GMAIL.COM>
Sent: Wednesday, September 6, 2023 8:13 PM
To: CSOUND@LISTSERV.HEANET.IE <CSOUND@LISTSERV.HEANET.IE>
Subject: Re: [Csnd] A Toggle button for Android Csound?
 
Hi Art.

As per the Michael's meeting today, here's a simple example that uses the phone accelerometer as control signals. In this case the amp & freq. Try holding the phone flat, facing upwards. Then tilt towards your face, side to side etc. It's sensitive but with practice becomes more intuitive. You can get some "whale sounds" with this one, maybe add an lfo & emulate a theremin.

A novelty, but can be fun, useful or perhaps both.

Here's the code, or you can download it from the link below.

<CsoundSynthesizer>
<CsOptions>
-odac -m2
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 32
nchnls = 2
0dbfs  = 1

; initialize global reverb
gaRvb init

instr sine
    kAccelX chnget "accelerometerX"
    kAccelY chnget "accelerometerY"
; printk 1, kAccelX
; printk 1, kAccelY
    iAmp    = .7
    kAmpMod = portk(kAccelX/30, .5)
    iFrq    = 110
    kFrqMod = portk(kAccelY * 100, .5)
    aEnv    = linsegr:a(0, 1, .8, p3, .8, 3, 0)
    aSig    = poscil(iAmp * kAmpMod * aEnv, iFrq + kFrqMod)
    outs(aSig, aSig)
    gaRvb  += aSig * .4
endin

instr reverb
    aRvbL, aRvbR reverbsc gaRvb, gaRvb, 0.94, 12000
    outs aRvbL,aRvbR
    clear gaRvb
endin

</CsInstruments>
<CsScore>
i"reverb" 0 z
i"sine"   0 z
</CsScore>
</CsoundSynthesizer>


https://github.com/ST-Music/csound-examples/blob/main/Android/accelerometer_example.csd

Scott

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2023-09-15 22:38
FromArthur Hunkins <000001e1d761dea2-dmarc-request@LISTSERV.HEANET.IE>
SubjectRe: [Csnd] A Toggle button for Android Csound?
Hello, Scott -

Thanks for all the time, energy and expertise you've put into this accelerometer project.

I've decided not to go into the weeds any further. Having tinkered with it this far, I don't see any immediate relevance to the creative work I'm doing; there is no real place for it.

OTOH you seem very invested and knowledgeable about Android Csound, and I'd like to encourage you to develop this work - certainly to put it into an article (and perhaps video demonstration?) It should make a great conference/seminar presentation.

As for me, I've been working with Michael's v39 Csound for Android as you probably know. An article about the problem of its unavailability on the Google Play Store, and especially the stumbling block that creates for the Chromebook, that's what I'll presently be putting out. (Chromebooks don't readily download third-party apps.)

I much enjoyed your contributions during the virtual meeting recently. They were very on point and cogent.

Best wishes -

Art H.

abhunkin@uncg.edu
http://www.arthunkins.com

From: A discussion list for users of Csound <CSOUND@LISTSERV.HEANET.IE> on behalf of ST Music <stunes6556@GMAIL.COM>
Sent: Friday, September 8, 2023 4:55 PM
To: CSOUND@LISTSERV.HEANET.IE <CSOUND@LISTSERV.HEANET.IE>
Subject: Re: [Csnd] A Toggle button for Android Csound?
 
Hi Art,
   a few observations.

I can't explain exactly why these occur,  I have a basic idea, but suspect someone who understand the physics of how something like an accelerometer for a phone is designed to work might be able to (although it likely wouldn't help me personally in terms of practical use). So this is anecdotal based on trial & error as well as using reported values. 

Sliding/moving the phone left to right isn't a good way to generate control signals, especially with such a low port rate. The changes in audio are almost inaudible as the phone seems to recalibrate the axis baselines very quickly. It's also a little uncomfortable to do so.

The most effective way is to use rotation, for a few reasons. When you rotate the phone, the values do not try to recalibrate - the values hold as long as the phone is in a certain position. It also allows much more subtle control with a minimum amount of movement depending on how you set up the control signals.

The sensors seem extremely sensitive & not likely perfectly calibrated. They probably vary slightly in accuracy for every phone. There appear to be methods to calibrate the accelerometer & perhaps other sensors, as well as apps to assist, if you Google it. I haven't tried but probably will later tonight.

The reason I like the Physics app I linked before is it clearly shows the values as the phone is moved/rotated, or stationary, along a timeline (chart).

With the phone held in a straight up/down position, the value of:
• X is ~ 0
• Y is ~ 1
• Z is ~ .25

At last on my phone as currently calibrated.

If it is flat, such as lying on a table with the screen facing up:
• X is ~ 0
• Y is ~ 0
• Z is ~ 1

If it is flat, lying on a table with the screen facing down:
• X is ~ 0
• Y is ~ 0
• Z is ~ -1

I personally like starting with the phone in the upright position, finding it the most physically advantageous as I'm usually sitting back in a chair. If standing, it might be easier to adjust variables to accommodate startng with the phone in a flat position, as if on a table. 

Assuming one starts with the phone in an upright (vertical) position:

Tilting (rotating) the top of the phone slightly to the left (going from a vertical to a horizontal position) increases X values (> 0). Fully horizontal X = 0. Tilting it to the right, from vertical to horizontal, decreases them (<0). Fully horizontal X = 1.

Tilting (rotating) the top of the phone slightly to the left also decreases Y values < 1 towards 0. Tilting it to the right also decreases them < 1.

Tilting (rotating) the top of the phone slightly away from your face raises Z values towards 1. When it is fully "flat" (the screen is horizontal & facing up) it reaches 1.

Tilting (rotating) the top of the phone slightly away from your face also decreases Y values from 1 towards 0. The opposite values of Z. When it is fully "flat", Y reaches 0.

So, tilting the screen sideways from vertical to horizontal affects both the X & Y values.

Tilting the phone from upright (vertical), facing you, to pointing the screen upwards (moving it towards a flat position facing the sky) affects both the Y & Z values. Y values move from 1 to 0,  Z from ~ .25 to 1.

Therefore careful consideration of these linked values is probably important overall. 

Although my initial example uses pitch as a variable, in practical usage it's often not a great choice as pitch can in many cases be hard to control with any precision. It's fun for effect though. And I'm sure one could set up a toggle switch to activate it when desired.

Amplitude (or other variables) in realtime might be more practical.

I modified your example to demonstrate. In this case, starting in standard vertical position, the amplitude is .5. If you rotate the phone to the left from vertical to horizontal, the amp increases. Rotating right decreases the amp.

If you tilt/rotate the screen from the screen being vertical upright to facing upwards, the PWM increases. On that note I changed the vco2 mode from saw/triangle/ramp to square/PWM as it's easier to hear the PWM.

Since rotating from vertical to horizontal (sideways) affects both the X & Y values, eliminating Y from the equation is helpful.

And as rotating the screen from facing you to facing upwards affects both the Y & Z axis, again eliminating Y removes it from consideration.

In the example below amp (X) & PWM (Z) can be altered independently. They can also work together - if you rotate the screen away from you to a flat position, facing upwards, the PWM increases. From that position, if you tilt the screen towards the left the amp decreases as does the PWM. If you tilt it to the right, the amp increases while the PWM decreases.

Y is the more difficult value to make use of since rotating sideways towards horizontal OR from facing towards you to screen facing up changes the value.

You can see it takes some consideration as to how you set the variables up, depending on usage and whether one chooses to start in an upright position or one in which you start from the phone in a position that is flat, like sitting on a table.

Here's the example:

<CsoundSynthesizer>
<CsOptions>

-odac -m0d

</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

    instr 1

kamp  chnget "accelerometerX"
kamp  = .5 - port(kamp * .05, .1)
; printk .5, kamp
kpw   chnget "accelerometerZ"
kpw   = lfo(.49, .5) * kpw * .1 + .5
kpw   port kpw, .1  
; printk .5, kpw
a1  vco2  kamp, 220, 2, kpw
    outs a1, a1

    endin

</CsInstruments>
<CsScore>
i1 0 z
e

</CsScore>
</CsoundSynthesizer>

If you have more questions let me know. And if you ever want help with a specific use case, again let me know. If you're still not sure about using the accelerometer or just want to discuss it we can always set up a Zoom meeting, it's probably easier to demonstrate it that way. I'm not always the most concise writer.

Hope that helps a bit. If you like I can email you or reply here with the csd attached if that makes things easier. Or put it on github & send a link. I'll do that soon anyways, when I have time to properly add comments to an example and write a description.

Feel free to use, edited or otherwise, anything I've written.

Cheers,
Scott


On Fri, Sept 8, 2023, 11:28 a.m. Arthur Hunkins <000001e1d761dea2-dmarc-request@listserv.heanet.ie> wrote:
Hi Scott and Michael -

Thanks, Scott, for your excellent example .csd and explanation of the Android accelerometer features. I've come up with a preliminary AndroidAccelerometerTester.csd, included below, inspired by your example, and the virtual meeting hosted by Michael two days ago.

I ask your (Scott) permission to quote substantially from your example at the beginning of my .csd - as much-needed basic guidance for any user.

I'd much appreciate both of you checking this .csd and its introductary commentary for accuracy and your general feedback. I'm still not sure I fully understand what is going on!

(I'll also presently share a companion AndroidWidgetTester.csd I've developed - which I mentioned in our meeting. Both use the same sound source. These .csd's should run on all historical Android Csounds, dating back to CSD Player.)

Art H.
​​​​​​​​​​​​​​​​​​____________________________

CSOUND FOR ANDROID ACCELEROMETER TESTER

; This .csd tests Csound for Android accelerometer functionality - x, y and z axes. These are rotation vector sensors. AccelerometerX controls amplitude, Y controls frequency, and Z, tone color.

; If you hold your phone straight up & down, moving left or right (X-axis) changes the accel.X values. Moving it up or down affects Y. Moving it forwards (towards your face) or away from you affects Z (depth).
; Where it generally gets tricky is that to perceive these changes the movements in this context have to be relatively quick (accelerating). Once motion stops the phone seems to quickly recalibrate this new position as being 0 again (no longer accelerating).

<CsoundSynthesizer>
<CsOptions>

-odac -m0d

</CsOptions>
<CsInstruments>

      sr = 44100
      ksmps = 32
      nchnls = 2
      0dbfs  = 1

      instr 1

kfreq init 400
kamp  init 0
kpw   init .5
kamp  chnget "accelerometerX"
kamp  = kamp * .04
kamp  port kamp, .1
kfreq chnget "accelerometerY"
kfreq = 400 + (kfreq * 40)
kfreq port kfreq, .1
kpw   chnget "accelerometerZ"
kpw   = .5 + (kpw * .045)
kpw   port kpw, .1
a1    vco2 kamp, kfreq, 4, kpw
      outs a1, a1

      endin

</CsInstruments>
<CsScore>

i1 0 z
e

</CsScore>
</CsoundSynthesizer>



From: A discussion list for users of Csound <CSOUND@LISTSERV.HEANET.IE> on behalf of ST Music <stunes6556@GMAIL.COM>
Sent: Friday, September 8, 2023 1:58 AM
To: CSOUND@LISTSERV.HEANET.IE <CSOUND@LISTSERV.HEANET.IE>
Subject: Re: [Csnd] A Toggle button for Android Csound?
 
Hi Art. 

Strictly speaking, if you hold your phone straight up & down, moving left or right (X-axis) changes the accel.X values. Moving it up or down affects Y. Moving it forwards (towards your face) or away from you affects Z (depth).

This is similar to how 3D art, math plotting & other programs (like CAD) work.

Where it generally gets tricky is that to perceive these changes the movements in this context have to be relatively quick (accelerating) - with the example code I sent if you shift the phone very quickly to either side the volume increases but the pitch doesn't change (or very little if you can keep it straight up & down). However, once motion stops the phone seems to quickly recalibrate this new position as being 0 again (no longer accelerating).

Oddly enough, if you rotate the phone towards the left or right, the X values change similarly but the phone doesn't recalibrate. So if X is set to affect amp values, simply rotating the phone to one side seems a much better way to control the amp than trying to "slide" (accelerate) it L or R.

Rotating the phone also affects the Y axis, but not Z (again if one could hold the phone _perfectly_  flat on the Z axis).
So with the example I sent, if you start it with the phone perfectly upright, you should hear nothing. If you roll the screen away from you towards the sky - nothing as long as the phone is essentially flat like sitting on a table. 

Tilting the screen backwards, away from you towards the sky is the best way to control the Z axis.

This way, subtly tilting the upright phone say 90° to either side or towards the sky gives decent control over all 3 axis. With a little practice it gets quite intuitive.

There are other apps that read the accelerometer, linear accelerometer, gyroscope etc. like Physics Toolbox Suite which is really helpful in terms of visually watching how the sensors react & what values they send; it plots and can record the movement and values of all 3 axis simulaneously using different colors. Easier than reading the console output.


but you have to be careful which mode/meter you use. I suggest using that app, clicking on the hamburger icon and choosing the g-Force Meter.

You'll see it accurately shows what's explained above. Slide your phone to either side quickly then back. Values shift towards the center again. Rotate the phone sideways or rotate the screen towards the sky, the values stay changed as long as the phone is rotated. 

You can also try the Dual Sensor mode of the Physics Suite (hamburger icon, scroll way down near the bottom). Select something like g-Force & Gyroscope - you might understand why I chose to use the X, Y & Z accel. 

Sometimes X & Y are enough, although X & Z can be better at times in which case rotating sideways will only affect X, rotating towards the sky only affects Z.

With the Gyroscope, tilting forward and back affects the X axis plot, not Z, which is quite non-intuitive to those who perceive X as left to right, Y as up and down and Z as depth.

So with the Gyroscope, rotating sideways affects Z, rotating the face of the phone towards the sky (tilting it) affects X, and turning your phone so that your staring at the side and can't see it affects Y, the latter being kind of uncomfortable & impractical.

Hope that helps. If you have more questions let me know.

Scott

On Thu, Sept 7, 2023, 11:45 p.m. Arthur Hunkins <000001e1d761dea2-dmarc-request@listserv.heanet.ie> wrote:
Hi Scott and Michael -

Scott, thanks for this "accelerometer demo". I've adapted your X and Y accels for a new Android Accelerometer Tester .csd.

I want to include the Z accel also. What do you know about this one? I presume it's the third rotation vector sensor, but I can't make much sense of what it's doing. Seems to be a 360 degree, 3D combination of the other two.

Anyone had any experience with the Z accelerometer, or how it might plausibly be used? (All of the Android apps seem to implement it.)

TIA

Art H.



From: A discussion list for users of Csound <CSOUND@LISTSERV.HEANET.IE> on behalf of Scott Daughtrey <stunes6556@GMAIL.COM>
Sent: Wednesday, September 6, 2023 8:13 PM
To: CSOUND@LISTSERV.HEANET.IE <CSOUND@LISTSERV.HEANET.IE>
Subject: Re: [Csnd] A Toggle button for Android Csound?
 
Hi Art.

As per the Michael's meeting today, here's a simple example that uses the phone accelerometer as control signals. In this case the amp & freq. Try holding the phone flat, facing upwards. Then tilt towards your face, side to side etc. It's sensitive but with practice becomes more intuitive. You can get some "whale sounds" with this one, maybe add an lfo & emulate a theremin.

A novelty, but can be fun, useful or perhaps both.

Here's the code, or you can download it from the link below.

<CsoundSynthesizer>
<CsOptions>
-odac -m2
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 32
nchnls = 2
0dbfs  = 1

; initialize global reverb
gaRvb init

instr sine
    kAccelX chnget "accelerometerX"
    kAccelY chnget "accelerometerY"
; printk 1, kAccelX
; printk 1, kAccelY
    iAmp    = .7
    kAmpMod = portk(kAccelX/30, .5)
    iFrq    = 110
    kFrqMod = portk(kAccelY * 100, .5)
    aEnv    = linsegr:a(0, 1, .8, p3, .8, 3, 0)
    aSig    = poscil(iAmp * kAmpMod * aEnv, iFrq + kFrqMod)
    outs(aSig, aSig)
    gaRvb  += aSig * .4
endin

instr reverb
    aRvbL, aRvbR reverbsc gaRvb, gaRvb, 0.94, 12000
    outs aRvbL,aRvbR
    clear gaRvb
endin

</CsInstruments>
<CsScore>
i"reverb" 0 z
i"sine"   0 z
</CsScore>
</CsoundSynthesizer>


https://github.com/ST-Music/csound-examples/blob/main/Android/accelerometer_example.csd

Scott

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2023-09-17 19:15
FromST Music
SubjectRe: [Csnd] A Toggle button for Android Csound?
Hi Art, thanks for the kind words & perhaps as you suggest I'll update my github with a little section demoing the accelerometer.

Like you, at this moment I don't have a particularly strong case to use it but I like that it's an option. I haven't yet used Csound live much, but I can imagine certain situations where gesture like movement would be fun to take advantage of. I've been meaning to test it with filter cutoff, resonance etc. I imagine the sliders are more efficient where a higher degree of control is desired. 

Anyways that's a different topic so will leave it at that for now.

Take care, will surely see you soon in one of Michael's monthly meetings.

Scott

On Fri, Sept 15, 2023, 5:38 p.m. Arthur Hunkins <000001e1d761dea2-dmarc-request@listserv.heanet.ie> wrote:
Hello, Scott -

Thanks for all the time, energy and expertise you've put into this accelerometer project.

I've decided not to go into the weeds any further. Having tinkered with it this far, I don't see any immediate relevance to the creative work I'm doing; there is no real place for it.

OTOH you seem very invested and knowledgeable about Android Csound, and I'd like to encourage you to develop this work - certainly to put it into an article (and perhaps video demonstration?) It should make a great conference/seminar presentation.

As for me, I've been working with Michael's v39 Csound for Android as you probably know. An article about the problem of its unavailability on the Google Play Store, and especially the stumbling block that creates for the Chromebook, that's what I'll presently be putting out. (Chromebooks don't readily download third-party apps.)

I much enjoyed your contributions during the virtual meeting recently. They were very on point and cogent.

Best wishes -

Art H.

From: A discussion list for users of Csound <CSOUND@LISTSERV.HEANET.IE> on behalf of ST Music <stunes6556@GMAIL.COM>
Sent: Friday, September 8, 2023 4:55 PM
To: CSOUND@LISTSERV.HEANET.IE <CSOUND@LISTSERV.HEANET.IE>
Subject: Re: [Csnd] A Toggle button for Android Csound?
 
Hi Art,
   a few observations.

I can't explain exactly why these occur,  I have a basic idea, but suspect someone who understand the physics of how something like an accelerometer for a phone is designed to work might be able to (although it likely wouldn't help me personally in terms of practical use). So this is anecdotal based on trial & error as well as using reported values. 

Sliding/moving the phone left to right isn't a good way to generate control signals, especially with such a low port rate. The changes in audio are almost inaudible as the phone seems to recalibrate the axis baselines very quickly. It's also a little uncomfortable to do so.

The most effective way is to use rotation, for a few reasons. When you rotate the phone, the values do not try to recalibrate - the values hold as long as the phone is in a certain position. It also allows much more subtle control with a minimum amount of movement depending on how you set up the control signals.

The sensors seem extremely sensitive & not likely perfectly calibrated. They probably vary slightly in accuracy for every phone. There appear to be methods to calibrate the accelerometer & perhaps other sensors, as well as apps to assist, if you Google it. I haven't tried but probably will later tonight.

The reason I like the Physics app I linked before is it clearly shows the values as the phone is moved/rotated, or stationary, along a timeline (chart).

With the phone held in a straight up/down position, the value of:
• X is ~ 0
• Y is ~ 1
• Z is ~ .25

At last on my phone as currently calibrated.

If it is flat, such as lying on a table with the screen facing up:
• X is ~ 0
• Y is ~ 0
• Z is ~ 1

If it is flat, lying on a table with the screen facing down:
• X is ~ 0
• Y is ~ 0
• Z is ~ -1

I personally like starting with the phone in the upright position, finding it the most physically advantageous as I'm usually sitting back in a chair. If standing, it might be easier to adjust variables to accommodate startng with the phone in a flat position, as if on a table. 

Assuming one starts with the phone in an upright (vertical) position:

Tilting (rotating) the top of the phone slightly to the left (going from a vertical to a horizontal position) increases X values (> 0). Fully horizontal X = 0. Tilting it to the right, from vertical to horizontal, decreases them (<0). Fully horizontal X = 1.

Tilting (rotating) the top of the phone slightly to the left also decreases Y values < 1 towards 0. Tilting it to the right also decreases them < 1.

Tilting (rotating) the top of the phone slightly away from your face raises Z values towards 1. When it is fully "flat" (the screen is horizontal & facing up) it reaches 1.

Tilting (rotating) the top of the phone slightly away from your face also decreases Y values from 1 towards 0. The opposite values of Z. When it is fully "flat", Y reaches 0.

So, tilting the screen sideways from vertical to horizontal affects both the X & Y values.

Tilting the phone from upright (vertical), facing you, to pointing the screen upwards (moving it towards a flat position facing the sky) affects both the Y & Z values. Y values move from 1 to 0,  Z from ~ .25 to 1.

Therefore careful consideration of these linked values is probably important overall. 

Although my initial example uses pitch as a variable, in practical usage it's often not a great choice as pitch can in many cases be hard to control with any precision. It's fun for effect though. And I'm sure one could set up a toggle switch to activate it when desired.

Amplitude (or other variables) in realtime might be more practical.

I modified your example to demonstrate. In this case, starting in standard vertical position, the amplitude is .5. If you rotate the phone to the left from vertical to horizontal, the amp increases. Rotating right decreases the amp.

If you tilt/rotate the screen from the screen being vertical upright to facing upwards, the PWM increases. On that note I changed the vco2 mode from saw/triangle/ramp to square/PWM as it's easier to hear the PWM.

Since rotating from vertical to horizontal (sideways) affects both the X & Y values, eliminating Y from the equation is helpful.

And as rotating the screen from facing you to facing upwards affects both the Y & Z axis, again eliminating Y removes it from consideration.

In the example below amp (X) & PWM (Z) can be altered independently. They can also work together - if you rotate the screen away from you to a flat position, facing upwards, the PWM increases. From that position, if you tilt the screen towards the left the amp decreases as does the PWM. If you tilt it to the right, the amp increases while the PWM decreases.

Y is the more difficult value to make use of since rotating sideways towards horizontal OR from facing towards you to screen facing up changes the value.

You can see it takes some consideration as to how you set the variables up, depending on usage and whether one chooses to start in an upright position or one in which you start from the phone in a position that is flat, like sitting on a table.

Here's the example:

<CsoundSynthesizer>
<CsOptions>

-odac -m0d

</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

    instr 1

kamp  chnget "accelerometerX"
kamp  = .5 - port(kamp * .05, .1)
; printk .5, kamp
kpw   chnget "accelerometerZ"
kpw   = lfo(.49, .5) * kpw * .1 + .5
kpw   port kpw, .1  
; printk .5, kpw
a1  vco2  kamp, 220, 2, kpw
    outs a1, a1

    endin

</CsInstruments>
<CsScore>
i1 0 z
e

</CsScore>
</CsoundSynthesizer>

If you have more questions let me know. And if you ever want help with a specific use case, again let me know. If you're still not sure about using the accelerometer or just want to discuss it we can always set up a Zoom meeting, it's probably easier to demonstrate it that way. I'm not always the most concise writer.

Hope that helps a bit. If you like I can email you or reply here with the csd attached if that makes things easier. Or put it on github & send a link. I'll do that soon anyways, when I have time to properly add comments to an example and write a description.

Feel free to use, edited or otherwise, anything I've written.

Cheers,
Scott


On Fri, Sept 8, 2023, 11:28 a.m. Arthur Hunkins <000001e1d761dea2-dmarc-request@listserv.heanet.ie> wrote:
Hi Scott and Michael -

Thanks, Scott, for your excellent example .csd and explanation of the Android accelerometer features. I've come up with a preliminary AndroidAccelerometerTester.csd, included below, inspired by your example, and the virtual meeting hosted by Michael two days ago.

I ask your (Scott) permission to quote substantially from your example at the beginning of my .csd - as much-needed basic guidance for any user.

I'd much appreciate both of you checking this .csd and its introductary commentary for accuracy and your general feedback. I'm still not sure I fully understand what is going on!

(I'll also presently share a companion AndroidWidgetTester.csd I've developed - which I mentioned in our meeting. Both use the same sound source. These .csd's should run on all historical Android Csounds, dating back to CSD Player.)

Art H.
​​​​​​​​​​​​​​​​​​____________________________

CSOUND FOR ANDROID ACCELEROMETER TESTER

; This .csd tests Csound for Android accelerometer functionality - x, y and z axes. These are rotation vector sensors. AccelerometerX controls amplitude, Y controls frequency, and Z, tone color.

; If you hold your phone straight up & down, moving left or right (X-axis) changes the accel.X values. Moving it up or down affects Y. Moving it forwards (towards your face) or away from you affects Z (depth).
; Where it generally gets tricky is that to perceive these changes the movements in this context have to be relatively quick (accelerating). Once motion stops the phone seems to quickly recalibrate this new position as being 0 again (no longer accelerating).

<CsoundSynthesizer>
<CsOptions>

-odac -m0d

</CsOptions>
<CsInstruments>

      sr = 44100
      ksmps = 32
      nchnls = 2
      0dbfs  = 1

      instr 1

kfreq init 400
kamp  init 0
kpw   init .5
kamp  chnget "accelerometerX"
kamp  = kamp * .04
kamp  port kamp, .1
kfreq chnget "accelerometerY"
kfreq = 400 + (kfreq * 40)
kfreq port kfreq, .1
kpw   chnget "accelerometerZ"
kpw   = .5 + (kpw * .045)
kpw   port kpw, .1
a1    vco2 kamp, kfreq, 4, kpw
      outs a1, a1

      endin

</CsInstruments>
<CsScore>

i1 0 z
e

</CsScore>
</CsoundSynthesizer>



From: A discussion list for users of Csound <CSOUND@LISTSERV.HEANET.IE> on behalf of ST Music <stunes6556@GMAIL.COM>
Sent: Friday, September 8, 2023 1:58 AM
To: CSOUND@LISTSERV.HEANET.IE <CSOUND@LISTSERV.HEANET.IE>
Subject: Re: [Csnd] A Toggle button for Android Csound?
 
Hi Art. 

Strictly speaking, if you hold your phone straight up & down, moving left or right (X-axis) changes the accel.X values. Moving it up or down affects Y. Moving it forwards (towards your face) or away from you affects Z (depth).

This is similar to how 3D art, math plotting & other programs (like CAD) work.

Where it generally gets tricky is that to perceive these changes the movements in this context have to be relatively quick (accelerating) - with the example code I sent if you shift the phone very quickly to either side the volume increases but the pitch doesn't change (or very little if you can keep it straight up & down). However, once motion stops the phone seems to quickly recalibrate this new position as being 0 again (no longer accelerating).

Oddly enough, if you rotate the phone towards the left or right, the X values change similarly but the phone doesn't recalibrate. So if X is set to affect amp values, simply rotating the phone to one side seems a much better way to control the amp than trying to "slide" (accelerate) it L or R.

Rotating the phone also affects the Y axis, but not Z (again if one could hold the phone _perfectly_  flat on the Z axis).
So with the example I sent, if you start it with the phone perfectly upright, you should hear nothing. If you roll the screen away from you towards the sky - nothing as long as the phone is essentially flat like sitting on a table. 

Tilting the screen backwards, away from you towards the sky is the best way to control the Z axis.

This way, subtly tilting the upright phone say 90° to either side or towards the sky gives decent control over all 3 axis. With a little practice it gets quite intuitive.

There are other apps that read the accelerometer, linear accelerometer, gyroscope etc. like Physics Toolbox Suite which is really helpful in terms of visually watching how the sensors react & what values they send; it plots and can record the movement and values of all 3 axis simulaneously using different colors. Easier than reading the console output.


but you have to be careful which mode/meter you use. I suggest using that app, clicking on the hamburger icon and choosing the g-Force Meter.

You'll see it accurately shows what's explained above. Slide your phone to either side quickly then back. Values shift towards the center again. Rotate the phone sideways or rotate the screen towards the sky, the values stay changed as long as the phone is rotated. 

You can also try the Dual Sensor mode of the Physics Suite (hamburger icon, scroll way down near the bottom). Select something like g-Force & Gyroscope - you might understand why I chose to use the X, Y & Z accel. 

Sometimes X & Y are enough, although X & Z can be better at times in which case rotating sideways will only affect X, rotating towards the sky only affects Z.

With the Gyroscope, tilting forward and back affects the X axis plot, not Z, which is quite non-intuitive to those who perceive X as left to right, Y as up and down and Z as depth.

So with the Gyroscope, rotating sideways affects Z, rotating the face of the phone towards the sky (tilting it) affects X, and turning your phone so that your staring at the side and can't see it affects Y, the latter being kind of uncomfortable & impractical.

Hope that helps. If you have more questions let me know.

Scott

On Thu, Sept 7, 2023, 11:45 p.m. Arthur Hunkins <000001e1d761dea2-dmarc-request@listserv.heanet.ie> wrote:
Hi Scott and Michael -

Scott, thanks for this "accelerometer demo". I've adapted your X and Y accels for a new Android Accelerometer Tester .csd.

I want to include the Z accel also. What do you know about this one? I presume it's the third rotation vector sensor, but I can't make much sense of what it's doing. Seems to be a 360 degree, 3D combination of the other two.

Anyone had any experience with the Z accelerometer, or how it might plausibly be used? (All of the Android apps seem to implement it.)

TIA

Art H.



From: A discussion list for users of Csound <CSOUND@LISTSERV.HEANET.IE> on behalf of Scott Daughtrey <stunes6556@GMAIL.COM>
Sent: Wednesday, September 6, 2023 8:13 PM
To: CSOUND@LISTSERV.HEANET.IE <CSOUND@LISTSERV.HEANET.IE>
Subject: Re: [Csnd] A Toggle button for Android Csound?
 
Hi Art.

As per the Michael's meeting today, here's a simple example that uses the phone accelerometer as control signals. In this case the amp & freq. Try holding the phone flat, facing upwards. Then tilt towards your face, side to side etc. It's sensitive but with practice becomes more intuitive. You can get some "whale sounds" with this one, maybe add an lfo & emulate a theremin.

A novelty, but can be fun, useful or perhaps both.

Here's the code, or you can download it from the link below.

<CsoundSynthesizer>
<CsOptions>
-odac -m2
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 32
nchnls = 2
0dbfs  = 1

; initialize global reverb
gaRvb init

instr sine
    kAccelX chnget "accelerometerX"
    kAccelY chnget "accelerometerY"
; printk 1, kAccelX
; printk 1, kAccelY
    iAmp    = .7
    kAmpMod = portk(kAccelX/30, .5)
    iFrq    = 110
    kFrqMod = portk(kAccelY * 100, .5)
    aEnv    = linsegr:a(0, 1, .8, p3, .8, 3, 0)
    aSig    = poscil(iAmp * kAmpMod * aEnv, iFrq + kFrqMod)
    outs(aSig, aSig)
    gaRvb  += aSig * .4
endin

instr reverb
    aRvbL, aRvbR reverbsc gaRvb, gaRvb, 0.94, 12000
    outs aRvbL,aRvbR
    clear gaRvb
endin

</CsInstruments>
<CsScore>
i"reverb" 0 z
i"sine"   0 z
</CsScore>
</CsoundSynthesizer>


https://github.com/ST-Music/csound-examples/blob/main/Android/accelerometer_example.csd

Scott

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here