×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    5

    Accelerometer, sounds, and horrible lag?

    You may have seen me post earlier about the accelerometer, well after getting it working, i have set it up this way:

    Init the accelerometer
    Get the data
    use data to define if someone is swinging the phone and play a sound.
    Paint the screen.

    I can paint the screen, i've gotten the data, and i've inited the accelerometer. The problem I'm having though is when i start to do this:
    Code:
    if(open){
    	    double force = Math.abs(x_int + y_int + z_int - x_pre - y_pre - z_pre)/2;
    	    if(force > accThresh)
    	    {
    		slashsound();
    	    }
    	}
    The application laggs horribly.

    Code:
    sx -= (x_int/3);
    	sy += (y_int/3);
    
    	createBackground(g);
    	g.setColor(255, 255, 255);
    	g.drawString("x = " + x_int, sx, sy+20, Graphics.TOP|Graphics.LEFT);
    	g.drawString("y = " + y_int, sx, sy+40, Graphics.TOP|Graphics.LEFT);
    	g.drawString("z = " + z_int, sx, sy+60, Graphics.TOP|Graphics.LEFT);
    This is what I'm using to draw. So the coordinates go across the screen, and when open is false, it all runs very smooth. If it's not false, it goes horribly slow. Can anyone help me? Could it be the floating point number?

    And with the sounds, it shouldn't make it lag too much am i correct?

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Accelerometer, sounds, and horrible lag?

    Depends on the code in slashsound(). If you're creating the Player every time you try to play the sound, then there will be a lag. Ideally, you want to create the Player early, and prefetch() it, so it can play quickly when you need it.

    Graham.

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    5

    Re: Accelerometer, sounds, and horrible lag?

    Code:
    public void slashsound()
        {
    	startPlayer(Slash); //Slash is a predefined Player
        }
    
    private void startPlayer(Player p)
        {
            if (p != null)
            {
                try
                {
                    p.stop();
                    p.setMediaTime(0L);
                    p.start();
                }
                catch (MediaException me)
                {
                    // ignore
                }
            }
        }
    Those are my two functions in there. I don't think it should be creating as much lag as it was.

    Also, with this code, if i swing hard twice, and it plays the hard swing twice, will the sound from the first get cut off from the second one if it hasn't finished yet?

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Accelerometer, sounds, and horrible lag?

    Do you prefetch() the player before this point?

    Does the Player have a PlayerListener?

    Graham.

Similar Threads

  1. Replies: 1
    Last Post: 2010-11-16, 05:52
  2. Accelerometer sensors lag
    By ranco in forum [Archived] Flash Lite on Nokia Devices
    Replies: 4
    Last Post: 2010-05-04, 20:41
  3. Nokias Emulators are HORRIBLE!
    By Nixarn in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2007-02-05, 13:56
  4. Horrible behaviour when building in carbide
    By shiva_mani in forum Symbian Tools & SDKs
    Replies: 0
    Last Post: 2006-09-28, 14:25
  5. Horrible noise after using SetRepeats -method
    By Tervueren in forum Symbian
    Replies: 1
    Last Post: 2004-09-01, 17:35

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×