Here is my damper.

HOWEVER: IT DOES NOT SOLVE THIS PROBLEM.
I am going to set the damping windows size to 3 or 4,
however i will disable sound because gameplay is practically
impossible with sounds on.


So Google Developers:  What is causing this problem,
and how is it solved.???



Here my sensor damper:



package com.tjerk.util;


/**
 * Class that adapts the sensor output values
 * by damping them over an window of previous sensor values.
 *
 * The new sensor values are the average over all sensor values
 * in the window.
 *
 * This class can be used as a workaround for the
 * accelerometer sensor+sound bug in Android.
 *
 * A biger window means less fluctuation in the sensor values.
 * However a side-effect of a large window is that it takes
 * there is a delay in movement detection.
 *
 * @author Tjerk Wolterink
 * @date June 9, 2009
 */
public class SensorAverageDamper {
        private float[] window0;
        private float[] window1;
        private float[] window2;
        private int i;
        private int windowSize;

        /**
         * Creates an sensor damper with a specific window size.
         *
         * @param windowSize the of the average window
         */
        public SensorAverageDamper(int windowSize) {
                this(windowSize, true, true, true);
        }


        /**
         * Creates a new damper with a specific window size.
         *
         * @param windowSize the of the average window
         * @param damp0 wether to damp sensor value values[0]
         * @param damp1 wether to damp sensor value values[1]
         * @param damp1 wether to damp sensor value values[1]
         */
        public SensorAverageDamper(int windowSize, boolean damp0, boolean
damp1, boolean damp2) {
                this.windowSize=windowSize;
                if(damp0) window0=createWindow();
                if(damp1) window1=createWindow();
                if(damp2) window2=createWindow();
        }

        protected float[] createWindow() {
                float[] w=new float[windowSize];
                for(int i=0;i<w.length;i++) w[i]=-1;
                return w;
        }

        protected float average(float[] w) {
                int l=0;
                int j=i;
                float sum=0;
                while(true) {
                        if(w[j]!=-1) {
                                l++;
                                sum+=w[j];
                        }
                        j=(j+1)%w.length;
                        if(j==i) break;
                }
                return sum/l;
        }

        /**
         * Adds the values to the window and
         * returns the damped values (average in the window)
         * @param values
         * @return
         */
        public float[] damp(float[] values) {
                i=(i+1)%windowSize;
                if(window0!=null) {
                        window0[i]=values[0];
                        values[0]=average(window0);
                }
                if(window1!=null) {
                        window1[i]=values[1];
                        values[1]=average(window1);
                }
                if(window2!=null) {
                        window2[i]=values[2];
                        values[2]=average(window2);
                }
                return values;
        }
}




On 9 jun, 20:08, TjerkW <tje...@gmail.com> wrote:
> I am developing a game.
> In which the user controls movement using the accelerometer.
> Sounds effects can also be enabled.
>
> However when laying the phone flat down and playing the game without
> the accelerometer gives nice 0,0,0 values.
>
> However when play WITH SOUNDS on, i get a buch of weird values: while
> the phone is NOT moving.
>
> This is really a big bug that makes life hard for Game Developers.
> I tried to take an avarge of the last 5 values from the sensor.. but
> this is not enough..
>
> The harder the sounds plays: the higher the weird sensor values.
>
> When using the headphones: almost no weird values.
>
> Seems that sounds interferes with the accelerometer sensor.
>
> BTW: more developers posted this issue but no reactions at all from
> google!!http://groups.google.com/group/android-developers/browse_thread/threa...http://groups.google.com/group/android-developers/browse_thread/threa...
>
> Is this is hardware problem?
> How do i solve it?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to