Ilja KO
Ilja KO

Reputation: 1616

Strange Error with SoundPool on Android

I have trouble with my SoundPool in my Android App.

It was working all find until I played around with the parameters in the play() method of my Soundpool. I have set the playback rate to 2f and got this warning:

06-17 19:53:13.359: W/AudioTrack(11526): AUDIO_OUTPUT_FLAG_FAST denied by client

After setting it back again to 1f I got these errors now:

06-17 19:53:13.359: W/AudioTrack(11526): AUDIO_OUTPUT_FLAG_FAST denied by client
06-17 19:53:13.359: E/AudioTrack(11526): AudioFlinger could not create track, status: -12
06-17 19:53:13.359: E/SoundPool(11526): Error creating AudioTrack

It all happens on my Samsung Note 4 with Android L and in Eclipse. On my Samsung s3 it runs ok but on that I didn't install via USB the App while the rate was still set to 2f.

Here's all the necessary Code:

setting up the sound pool

public void setUpSounds()
{
    soundPool=new SoundPool(20,AudioManager.STREAM_MUSIC,0);
    soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener()
    {
        @Override
        public void onLoadComplete(SoundPool soundPool, int sampleId,int status)
        {
            if(sampleId==beepID)
            {
                if(status==0)
                {
                    beepLoaded=true;
                }
            }
            else if(sampleId==buttonClickID)
            {
                if(status==0)
                {
                    buttonClickLoaded=true;
                }
            }
            else if(sampleId==menuEnterID)
            {
                if(status==0)
                {
                    menuEnterLoaded=true;
                }
            }
            else if(sampleId==menuExitID)
            {
                if(status==0)
                {
                    menuExitLoaded=true;
                }
            }
        }

    });
    buttonClickID=soundPool.load(this,R.raw.buttonclick, 0);
    beepID=soundPool.load(this, R.raw.beep,0);
    menuEnterID=soundPool.load(this, R.raw.menuenter,0);
    menuExitID=soundPool.load(this, R.raw.menuexit,0);
}

playing the sounds:

/**
 * play the menu exit sound
 */
public void playMenuExitSound()
{
    if(soundFXOn&&mAct.menuExitLoaded)
    {
        mAct.soundPool.play(mAct.menuExitID, 0.2f, 0.2f, 0, 0, 1.0f);
    }
}


/**
 * play the menu entered sound
 */
public void playMenuEnterSound()
{
    if(soundFXOn&&mAct.menuEnterLoaded)
    {
        mAct.soundPool.play(mAct.menuEnterID, 0.2f, 0.2f, 0, 0, 1.0f);
    }
}


/**
 * plays the button click sound
 */
public void playButtonClick()
{
    if(soundFXOn&&mAct.buttonClickLoaded)
    {
        mAct.soundPool.play(mAct.buttonClickID, 1f, 1f, 0, 0, 1.0f);
    }
}

the beep sound inside the thread

if(mView.soundFXOn&&mView.mAct.beepLoaded)
                {
                    mView.mAct.soundPool.play(mView.mAct.beepID, 0.05f, 0.05f, 0, 0, 1);
                }

I just dont see what is wrong, it must be sth internally inside my Note that won't play the sound anymore!

Or something in Eclipse is going totally wrong so that it sends false flags or sth like that

Upvotes: 2

Views: 4645

Answers (1)

Michael Chav
Michael Chav

Reputation: 439

Android is denying the flag and then the subsequent error messages come as result of removing the flag from the SoundPool. The iniital error is the one you should pay close attention to.

Depending on what Android version you're running your software on the error message could be specific or generic (yours seems generic). But the error you received is usually due to a mismatch in sampling rate between the device's hardware and the soundpool. Some other causes could be: The factors that impact the decision include:

  • Presence of a fast mixer thread for this output (see below)
  • Track sample rate
  • Presence of a client thread to execute callback handlers for this track
  • Track buffer size
  • Available fast track slots (see below)

Two possible solutions: First try using the sample rate provided by AudioManager.getProperty(PROPERTY_OUTPUT_SAMPLE_RATE). Otherwise your buffers take a detour through the system resampler.

Or try setting you SoundPool via the Builder and setting all the attributes manually like this:

AudioAttributes attributes = new AudioAttributes.Builder()
                .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
                .setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED)
                .setUsage(AudioAttributes.USAGE_GAME)
                .build();
        pool = new SoundPool.Builder().setAudioAttributes(attributes).setMaxStreams(2).build()

;

This is a miscellany of all the pages I read trying to solve the same issue.

https://code.google.com/p/android/issues/detail?id=160879 AudioTrack: AUDIO_OUTPUT_FLAG_FAST denied by client due to mismatching sample rate https://code.google.com/p/android/issues/detail?id=58113

Upvotes: 3

Related Questions