seems like I was wrong. Profiling shows 60% is spent on getting the
audio service and setting up the volume. Only 40% is spent on the
actual play function. So would seem like I setting up the volume
before hand is the way to go. I'll try that out and see how things go.

On Dec 19, 7:46 pm, rukiman <[email protected]> wrote:
> I cannot quatify it but it is very noticeable and feels "wrong" when
> playing my game. for example I play a sound when a piece is selected
> however due to the lag the sound feel a bit out of place.
> I will try to profile whats going on here. But I thought perhaps
> someone may have had experienced this issue and come up with a
> solution or workaround. I will try Matts idea of calculating the
> volume before hand etc so I have to simply call soundPool.play(). Only
> issue is that creates extra work i.e the sound volume might have
> changed by the user meanwhile and also I'm very doubtful if it will
> improve the lag.
>
> On Dec 19, 6:37 am, Robert Green <[email protected]> wrote:
>
> > Can you quantify the lag?  How much is it lagging?  Lately I've been
> > seeing my footstep sounds, which are individually triggered right and
> > left steps, take 2-50ms to trigger for some reason.  I'm not sure if
> > it has something to do with the way the OGG is encoded, but I feel
> > like it could.  Perhaps the SoundPool author would like to chime in
> > and give us some hints?
>
> > On Dec 18, 3:45 am, rukiman <[email protected]> wrote:
>
> > > I am using the SoundPool as follows:
>
> > > Caching my sounds:
> > >                         // loadsoundeffects
> > >                         soundPool = new SoundPool(2, 
> > > AudioManager.STREAM_MUSIC, 0);
> > >                         soundPoolMap = new HashMap<Integer, Integer>();
> > >                         AssetFileDescriptor afd;
> > >                         try {
> > >                                 afd = 
> > > context.getAssets().openFd("sounds/piecemove.ogg");
> > >                                 soundPoolMap.put(SOUND_PIECEMOVE, 
> > > soundPool.load(afd, 1));
>
> > >                                 afd = 
> > > context.getAssets().openFd("sounds/piecestop.ogg");
> > >                                 soundPoolMap.put(SOUND_PIECESTOP, 
> > > soundPool.load(afd, 1));
>
> > >                                 afd = 
> > > context.getAssets().openFd("sounds/pieceattack.ogg");
> > >                                 soundPoolMap.put(SOUND_PIECEATTACK, 
> > > soundPool.load(afd, 1));
>
> > >                                 afd = 
> > > context.getAssets().openFd("sounds/pieceselect.ogg");
> > >                                 soundPoolMap.put(SOUND_PIECESELECT, 
> > > soundPool.load(afd, 1));
>
> > >                                 afd = 
> > > context.getAssets().openFd("sounds/selection.ogg");
> > >                                 soundPoolMap.put(SOUND_MENUSELECTION, 
> > > soundPool.load(afd, 1));
>
> > >                                 afd = 
> > > context.getAssets().openFd("sounds/pageturn.ogg");
> > >                                 soundPoolMap.put(SOUND_PAGETURN, 
> > > soundPool.load(afd, 1));
> > >                         } catch (IOException e) {
> > >                                 e.printStackTrace();
> > >                         }
>
> > > Function to play sounds:
>
> > >         public static int playSound(Context context, intsound) {
>
> > >                 AudioManager mgr = (AudioManager) context
> > >                                 .getSystemService(Context.AUDIO_SERVICE);
> > >                 float streamVolumeCurrent = mgr
> > >                                 
> > > .getStreamVolume(AudioManager.STREAM_MUSIC);
> > >                 float streamVolumeMax = mgr
> > >                                 
> > > .getStreamMaxVolume(AudioManager.STREAM_MUSIC);
> > >                 float volume = streamVolumeCurrent / streamVolumeMax;
> > >                 /* Play thesoundwith the correct volume */
> > >                 return soundPool
> > >                                 .play(soundPoolMap.get(sound), volume, 
> > > volume, 1, 0, 1f);
> > >         }
>
> > > Playing asoundeffect i.e when button is clicked:
>
> > >       Resources.playSound(context, Resources.SOUND_PIECESELECT);
>
> > > However as I said thesoundis lagging. What can I do to improve this?
> > > All my sounds are OGG file format.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to