Android Soundpool problems

后端 未结 1 1835
伪装坚强ぢ
伪装坚强ぢ 2021-01-12 15:04

I\'ve got an app on the Android Market and have been using the SoundPool classes for the sound effects. I\'ve noticed that, of all the parts of the Android API, this seems t

相关标签:
1条回答
  • 2021-01-12 15:24

    It seems AudioFlinger can have up to 1 Mb worth of audio going on at any given time. The heap errors occur if this limit is exceeded. This guess is based on some code I found in AudioFlinger source code:

    AudioFlinger::Client::Client(const sp<AudioFlinger>& audioFlinger, pid_t pid) 
         :   RefBase(), 
             mAudioFlinger(audioFlinger), 
             mMemoryDealer(new MemoryDealer(1024*1024)), 
             mPid(pid) 
    { 
         // 1 MB of address space is good for 32 tracks, 8 buffers each, 4 KB/buffer 
    } 
    

    And this:

    size_t size = sizeof(audio_track_cblk_t); 
    size_t bufferSize = frameCount*channelCount*sizeof(int16_t); 
    if (sharedBuffer == 0) { 
        size += bufferSize; 
    } 
    mCblkMemory = client->heap()->allocate(size); 
    if (mCblkMemory != 0) {
        ...
    } else {
        LOGE("not enough memory for AudioTrack size=%u", size); 
        client->heap()->dump("AudioTrack"); 
    }
    

    Anyone else better informed?

    0 讨论(0)
提交回复
热议问题