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:
-odac -m0d
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
i1 0 z
e
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