开发者

How does Android sound mixing really work?

Is there any definitive source that explains how Android sound mixing really works? I'm getting a really unexpected behavior using SoundPool on STREAM_NOTIFICATION when it mixes with music on STREAM_MUSIC.

When music is playing, even if its volume is way down, the sounds played by SoundPool are at 50% of the vo开发者_JS百科lume than when no music is playing.

This is roughly the code I'm using:

SoundPool soundPool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 0);

A couple of those:

sound_id = soundPool.load(context, 
                context.getResources().getIdentifier("sound1", 
                      "raw",
                       "com.package.name"),
                1);

And later this:

final AudioManager manager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
final int volume = manager.getStreamVolume(AudioManager.STREAM_MUSIC);

manager.setStreamVolume(AudioManager.STREAM_MUSIC, volume/2, 0);

soundPool.play(sound_id, 1f, 1f, 1, 0, 1);

new Handler().postDelayed(new Runnable() {
       public void run() {
           manager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
       }
   }, 1000);

If no music is currently playing, the sounds are at full volume, nice and clear. If music is playing, the music gets attenuated correctly, but the sound still only plays at 50% volume.

What's the mixing algorithm? Does anyone know anything about this, or a workaround?


Have you tried setting the volume on the NOTIFICATION_STREAM? I has a similar problem when using the MediaPlayer (without the soundpool) and manually setting the notification steam volume while ducking the music stream solved by problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜