Author Topic: BASS makes my UI lag after several song loads.  (Read 696 times)

dieppa

  • Posts: 33
Hi everyone,

I am facing an issue with the library and I'm not sure if it's a memory issue. My application has a transaction animation for music thumbnails, but after 3 or 4 songs later it becomes lazy. I have discovered it's related to BASS when loads a song several times. Below I post my code, can someone tell me what's wrong?, Am I missing something?

The lag only occurs when loading another song. Transition animation and song loading occurs at the same time. Setting thread priority won't fix the problem, already checked. :(

if (songPlayerModel == null)
            return LOAD_RESOURCE_ERROR;

        this.playingSong = songPlayerModel;
        String path = songPlayerModel.getPath();

        BASS.BASS_ChannelRemoveSync(playerChannel, BASS.BASS_SYNC_END);

        if (!BASS.BASS_StreamFree(playerChannel))
            BASS.BASS_MusicFree(playerChannel);

        if (path == null)
            return LOAD_RESOURCE_ERROR;
.
. //Load path into BASS
.

Thanks!
« Last Edit: 20 Feb '18 - 16:04 by dieppa »

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: BASS makes my UI lag after several song loads.
« Reply #1 on: 20 Feb '18 - 16:22 »
Please show how you are creating the "playerChannel" handle, eg. a BASS_StreamCreateFile call. Does the UI lag only during that call, or throughout playback?

By the way, that "BASS_SYNC_END" parameter in the BASS_ChannelRemoveSync call is invalid; it should be a handle that was previously returned by a BASS_ChannelSetSync call. But that won't be causing performance issues.

dieppa

  • Posts: 33
Re: BASS makes my UI lag after several song loads.
« Reply #2 on: 20 Feb '18 - 16:44 »
Hi Ian,

Only during that call, in this case the method loadSong. The more I call it the worse it becomes.

Here it is:

Code: [Select]
public class BassPlayer implements IPlayer {
    private int playerChannel;
    private int endSyncHandler;
    private final int frequency = 44100;
    private final int ALLOC_SIZE = 2048;

    /**
     * Player callback listener
     */
    private OnIPlayerCallback onIPlayerCallback;
    /**
     * Current playing song
     */
    private SongPlayerModel playingSong;
    /**
     * Equalizer instance
     */
    private IEqualizer equalizer;

    public BassPlayer() {
        BASS.BASS_SetConfig(BASS.BASS_CONFIG_FLOATDSP, 1);
    }

    public int initialize() {
        if (!BASS.BASS_Init(-1, frequency, 0)) {
            return IPlayer.INVALID_STATE_ERROR;
        }

        BASS.BASS_PluginLoad("libbassflac.so", 0);
        BASS.BASS_PluginLoad("libbassdsd.so", 0);
        BASS.BASS_PluginLoad("libbasswv.so", 0);
        BASS.BASS_PluginLoad("libbassmidi.so", 0);
        BASS.BASS_PluginLoad("libbassalac.so", 0);
        BASS.BASS_PluginLoad("libbassopus.so", 0);

        return IPlayer.SUCCESS;
    }

    @Override
    public int play() {
        if (BASS.BASS_ChannelPlay(this.playerChannel, false)) {
            if (onIPlayerCallback != null)
                onIPlayerCallback.onStartPlaying();
            return SUCCESS;
        }
        else
            return OPERATION_ERROR;
    }

    @Override
    public int pause() {
        if (BASS.BASS_ChannelPause(this.playerChannel)) {
            if (onIPlayerCallback != null)
                onIPlayerCallback.onPaused();
            return SUCCESS;
        }
        else
            return OPERATION_ERROR;
    }

    @Override
    public int stop() {
        if (BASS.BASS_ChannelStop(this.playerChannel)) {
            if (onIPlayerCallback != null)
                onIPlayerCallback.onStopped();
            return SUCCESS;
        }
        else
            return OPERATION_ERROR;
    }

    @Override
    public int seekTo(double time) {
        long amountOfBytes = BASS.BASS_ChannelSeconds2Bytes(this.playerChannel, time / 1000);
        if (BASS.BASS_ChannelSetPosition(this.playerChannel, amountOfBytes, BASS.BASS_POS_BYTE))
            return SUCCESS;
        else
            return OPERATION_ERROR;
    }

    @Override
    public int getCurrentPositionInSong() {
        long currentPosition = BASS.BASS_ChannelGetPosition(this.playerChannel, BASS.BASS_POS_BYTE);
        return  (int) (BASS.BASS_ChannelBytes2Seconds(this.playerChannel, currentPosition) * 1000);
    }

    @Override
    public ByteBuffer getFFT() {
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(ALLOC_SIZE);
        if (this.isPlaying())
            BASS.BASS_ChannelGetData(playerChannel, byteBuffer, BASS.BASS_DATA_FFT1024);
        return byteBuffer;
    }

    @Override
    public boolean isPlaying() {
        return BASS.BASS_ChannelIsActive(playerChannel) == BASS.BASS_ACTIVE_PLAYING;
    }

    @Override
    public int loadSong(SongPlayerModel songPlayerModel) {
        if (songPlayerModel == null)
            return LOAD_RESOURCE_ERROR;

        this.playingSong = songPlayerModel;
        String path = songPlayerModel.getPath();

        BASS.BASS_ChannelRemoveSync(playerChannel, this.endSyncHandler);

        if (!BASS.BASS_StreamFree(playerChannel))
            BASS.BASS_MusicFree(playerChannel);

        if (path == null)
            return LOAD_RESOURCE_ERROR;

        if ((this.playerChannel = BASS.BASS_StreamCreateFile(path, 0, 0, 0)) == 0
                && (this.playerChannel = BASS.BASS_MusicLoad(path, 0, 0, BASS.BASS_MUSIC_RAMP, 1)) == 0) {
            return LOAD_RESOURCE_ERROR;
        }

        if (onIPlayerCallback != null)
            onIPlayerCallback.onPrepared();
        if (equalizer != null)
            equalizer.attachPlayer(this);

        this.endSyncHandler = BASS.BASS_ChannelSetSync(this.playerChannel, BASS.BASS_SYNC_END, 0, new BASS.SYNCPROC() {
            @Override
            public void SYNCPROC(int i, int i1, int i2, Object o) {
                if (onIPlayerCallback != null)
                    onIPlayerCallback.onSongCompleted(BassPlayer.this.playingSong);
            }
        }, 0);

        return SUCCESS;
    }

    @Override
    @Nullable
    public IBasicMediaPlayer getBasicMediaPlayer() {
        return null;
    }

    @Override
    public int getSessionId() {
        return this.playerChannel;
    }

    @Override
    public void attachEqualizer(IEqualizer equalizer) {
        this.equalizer = equalizer;
    }

    @Override
    public void setOnIPlayerCallback(final OnIPlayerCallback onIPlayerCallback) {
        this.onIPlayerCallback = onIPlayerCallback;
    }

    @Override
    public void release() {
        BASS.BASS_Free();
    }
}

Thanks!
« Last Edit: 21 Feb '18 - 11:31 by dieppa »

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: BASS makes my UI lag after several song loads.
« Reply #3 on: 20 Feb '18 - 17:29 »
Is the UI lag only occuring while the loadSong function is being called, not after it has returned? If so, are you calling it in the main/UI thread? If you are, making the call asynchronously (eg. using the Thread class) should prevent the problem. If the problem happens even after loadSong has returned, perhaps it's the IEqualizer class; does disabling attachEqualizer prevent the problem?

Also, I would suggest simplifying the code by using the plugin system, so that you don't need to call different functions for different file extensions. For example, do this in the initialize function:

Code: [Select]
    public int initialize() {
        if (!BASS.BASS_Init(-1, frequency, 0)) {
            return IPlayer.INVALID_STATE_ERROR;
        }

        BASS.BASS_PluginLoad("libbassflac.so", 0);
        BASS.BASS_PluginLoad("libbassdsd.so", 0);
        BASS.BASS_PluginLoad("libbasswv.so", 0);
        BASS.BASS_PluginLoad("libbassmidi.so", 0);
        BASS.BASS_PluginLoad("libbassalac.so", 0);
        BASS.BASS_PluginLoad("libbassopus.so", 0);

        return IPlayer.SUCCESS;
    }

You can then just do this in loadSong:

Code: [Select]
            if ((this.playerChannel = BASS.BASS_StreamCreateFile(path, 0, 0, 0)) == 0
                    && (this.playerChannel = BASS.BASS_MusicLoad(path, 0, 0, BASS.BASS_MUSIC_RAMP, 1)) == 0) {
                return LOAD_RESOURCE_ERROR;

dieppa

  • Posts: 33
Re: BASS makes my UI lag after several song loads.
« Reply #4 on: 20 Feb '18 - 17:52 »
Hi Ian,

Thanks for the code for plugin loading, it will save me a lot of lines.

"are you calling it in the main/UI thread?" - No, I am using Reactive and ThreadPool.

Method "attachPlayer" will only apply the bands to the channel. I have already commented the call, no changes.

Code: [Select]
@Override
    public void attachPlayer(IPlayer player) {
        this.playerChannel = player.getSessionId();

        for (int i = 0; i < bands.length; i++) {
            this.bands[i] = BASS.BASS_ChannelSetFX(this.playerChannel, BASS.BASS_FX_DX8_PARAMEQ, 0);
        }

        this.updateFX();
    }

The Equalizer class is just an abstraction that stores the bands and applies FX effects to the channel.

Code: [Select]
/**
     * Applies the effects to the channel
     */
    private void updateFX() {
        this.isEnabled = true;
        for (int i = 0; i < this.params.length; i++) {
            BASS.BASS_FXSetParameters(bands[i], params[i]);
        }

        //Applying gain and bassboost level
        for (int i = 0; i < this.params.length; i++) {
            int newGain = (int) (params[i].fGain + this.gainLevel);
            if (i == 0 || i == 1 || i == 2)
                newGain += this.bassboostLevel;
            BASS.BASS_DX8_PARAMEQ newParam = new BASS.BASS_DX8_PARAMEQ();
            newParam.fCenter = params[i].fCenter;
            newParam.fBandwidth = params[i].fBandwidth;
            if (newGain > MAXDB)
                newGain = MAXDB;
            if (newGain < -MAXDB)
                newGain = -MAXDB;
            newParam.fGain = newGain;
            BASS.BASS_FXSetParameters(bands[i], newParam);
        }
    }

Thanks.

dieppa

  • Posts: 33
Re: BASS makes my UI lag after several song loads.
« Reply #5 on: 20 Feb '18 - 19:00 »
Hi Ian,

I think I have found the cause. Tomorrow I will check the performance once again and tell you how things go. Thank you for the code tips.

Thanks.

EDIT: I thought there was a method that could cause the lag, but its test and the method itself work fine.
« Last Edit: 21 Feb '18 - 07:53 by dieppa »

dieppa

  • Posts: 33
Re: BASS makes my UI lag after several song loads.
« Reply #6 on: 21 Feb '18 - 11:14 »
Hi Ian,

I have forced my player factory to build the default system music player to discard upper layers. The UI isn't affected when using the Android MediaPlayer.

I have discovered that not only the UI lags when load a new song after several song loads, but play/pause actions also lags the visualization. At first 4 or 5 songs everything work perfect. Seems to be that BASS is not releasing resources somehow. Above is my BassPlayer and here below is my BassEqualizer implementation, is there anything that might cause the performance issue?

Thanks.

Code: [Select]
public class BassEqualizer implements IEqualizer {
    /**
     * Sets whether is the equalizer enabled
     */
    private boolean isEnabled = false;
    /**
     * The channel of the player where effects will be applied
     */
    private int playerChannel = 0;
    /**
     * Bands
     */
    private int bands[] = new int[10];
    /**
     * Bass boost level
     */
    private short bassboostLevel;
    /**
     * Gain level
     */
    private short gainLevel;
    /**
     * Current loaded preset
     */
    private short preset;
    /**
     * Band parameters
     */
    private BASS.BASS_DX8_PARAMEQ params[];
    /**
     * Empty parameters used to disable the equalizer
     */
    private BASS.BASS_DX8_PARAMEQ emptyParams[];

    public BassEqualizer() {
        this.bassboostLevel = 0;
        this.gainLevel = 0;
        this.preset = -1;

        params = new BASS.BASS_DX8_PARAMEQ[10];
        emptyParams = new BASS.BASS_DX8_PARAMEQ[10];

        BASS.BASS_DX8_PARAMEQ param = null;
        BASS.BASS_DX8_PARAMEQ emptyParam = null;

        param = new BASS.BASS_DX8_PARAMEQ();
        param.fCenter = 32;
        param.fBandwidth = 12;
        params[0] = param;
        emptyParam = new BASS.BASS_DX8_PARAMEQ();
        emptyParam.fCenter = param.fCenter;
        emptyParam.fBandwidth = param.fBandwidth;
        emptyParam.fGain = 0;
        emptyParams[0] = emptyParam;

        param = new BASS.BASS_DX8_PARAMEQ();
        param.fCenter = 64;
        param.fBandwidth = 12;
        params[1] = param;
        emptyParam = new BASS.BASS_DX8_PARAMEQ();
        emptyParam.fCenter = param.fCenter;
        emptyParam.fBandwidth = param.fBandwidth;
        emptyParam.fGain = 0;
        emptyParams[1] = emptyParam;

        param = new BASS.BASS_DX8_PARAMEQ();
        param.fCenter = 125;
        param.fBandwidth = 12;
        params[2] = param;
        emptyParam = new BASS.BASS_DX8_PARAMEQ();
        emptyParam.fCenter = param.fCenter;
        emptyParam.fBandwidth = param.fBandwidth;
        emptyParam.fGain = 0;
        emptyParams[2] = emptyParam;

        param = new BASS.BASS_DX8_PARAMEQ();
        param.fCenter = 250;
        param.fBandwidth = 12;
        params[3] = param;
        emptyParam = new BASS.BASS_DX8_PARAMEQ();
        emptyParam.fCenter = param.fCenter;
        emptyParam.fBandwidth = param.fBandwidth;
        emptyParam.fGain = 0;
        emptyParams[3] = emptyParam;

        param = new BASS.BASS_DX8_PARAMEQ();
        param.fCenter = 500;
        param.fBandwidth = 12;
        params[4] = param;
        emptyParam = new BASS.BASS_DX8_PARAMEQ();
        emptyParam.fCenter = param.fCenter;
        emptyParam.fBandwidth = param.fBandwidth;
        emptyParam.fGain = 0;
        emptyParams[4] = emptyParam;

        param = new BASS.BASS_DX8_PARAMEQ();
        param.fCenter = 1000;
        param.fBandwidth = 12;
        params[5] = param;
        emptyParam = new BASS.BASS_DX8_PARAMEQ();
        emptyParam.fCenter = param.fCenter;
        emptyParam.fBandwidth = param.fBandwidth;
        emptyParam.fGain = 0;
        emptyParams[5] = emptyParam;

        param = new BASS.BASS_DX8_PARAMEQ();
        param.fCenter = 2000;
        param.fBandwidth = 12;
        params[6] = param;
        emptyParam = new BASS.BASS_DX8_PARAMEQ();
        emptyParam.fCenter = param.fCenter;
        emptyParam.fBandwidth = param.fBandwidth;
        emptyParam.fGain = 0;
        emptyParams[6] = emptyParam;

        param = new BASS.BASS_DX8_PARAMEQ();
        param.fCenter = 4000;
        param.fBandwidth = 12;
        params[7] = param;
        emptyParam = new BASS.BASS_DX8_PARAMEQ();
        emptyParam.fCenter = param.fCenter;
        emptyParam.fBandwidth = param.fBandwidth;
        emptyParam.fGain = 0;
        emptyParams[7] = emptyParam;

        param = new BASS.BASS_DX8_PARAMEQ();
        param.fCenter = 8000;
        param.fBandwidth = 12;
        params[8] = param;
        emptyParam = new BASS.BASS_DX8_PARAMEQ();
        emptyParam.fCenter = param.fCenter;
        emptyParam.fBandwidth = param.fBandwidth;
        emptyParam.fGain = 0;
        emptyParams[8] = emptyParam;

        param = new BASS.BASS_DX8_PARAMEQ();
        param.fCenter = 16000;
        param.fBandwidth = 12;
        params[9] = param;
        emptyParam = new BASS.BASS_DX8_PARAMEQ();
        emptyParam.fCenter = param.fCenter;
        emptyParam.fBandwidth = param.fBandwidth;
        emptyParam.fGain = 0;
        emptyParams[9] = emptyParam;
    }

    /**
     * Applies the effects to the channel
     */
    private void updateFX() {
        this.isEnabled = true;
        for (int i = 0; i < this.params.length; i++) {
            BASS.BASS_FXSetParameters(this.bands[i], this.params[i]);
        }

        //Applying gain and bassboost level
        for (int i = 0; i < this.params.length; i++) {
            int newGain = (int) (this.params[i].fGain + this.gainLevel);
            if (i == 0 || i == 1 || i == 2)
                newGain += this.bassboostLevel;
            BASS.BASS_DX8_PARAMEQ newParam = new BASS.BASS_DX8_PARAMEQ();
            newParam.fCenter = this.params[i].fCenter;
            newParam.fBandwidth = this.params[i].fBandwidth;
            if (newGain > MAXDB)
                newGain = MAXDB;
            if (newGain < -MAXDB)
                newGain = -MAXDB;
            newParam.fGain = newGain;
            BASS.BASS_FXSetParameters(this.bands[i], newParam);
        }
    }

    /**
     * Applies the empty effects to the channel. That way the equalizer will remain disabled
     */
    private void disableEffect() {
        this.isEnabled = false;
        for (int i = 0; i < this.params.length; i++) {
            BASS.BASS_FXSetParameters(this.bands[i], this.emptyParams[i]);
        }
    }

    @Override
    public void attachPlayer(IPlayer player) {
        this.playerChannel = player.getSessionId();

        for (int i = 0; i < bands.length; i++) {
            this.bands[i] = BASS.BASS_ChannelSetFX(this.playerChannel, BASS.BASS_FX_DX8_PARAMEQ,0);
        }

        this.updateFX();
    }

    @Override
    public void setBassBoostLevel(short level) {
        this.bassboostLevel = level;
        this.updateFX();
    }

    @Override
    public short getBassBoostLevel() {
        return this.bassboostLevel;
    }

    @Override
    public void setPreset(short presetId) {
        this.preset = presetId;
    }

    @Override
    public short getCurrentPreset() {
        return this.preset;
    }

    @Override
    public void setBandLevel(short band, short level) {
        params[band].fGain = level;
        this.preset = 0; //Change preset since it won't match
        if (isEnabled)
            this.updateFX();
    }

    @Override
    public int enableEqualizer(boolean enabled) {
        if (enabled) {
            this.updateFX();
        } else {
            this.disableEffect();
        }
        return SUCCESS;
    }

    @Override
    public boolean isEnabled() {
        return this.isEnabled;
    }

    @Override
    public void release() {
        this.params = null;
        this.emptyParams = null;
        this.bands = null;
    }

    @Override
    public Settings getEqualizerSettings() {
        short[] levels = new short[NUMBER_OF_BANDS];
        for (int i = 0; i < this.params.length; i++) {
            levels[i] = (short) (this.params[i].fGain);
        }
        Settings settings = new Settings(levels, this.bassboostLevel, this.gainLevel);
        settings.setCurrentPreset(this.preset);
        return settings;
    }

    @Override
    public void applySettings(Settings settings) {
        for (short i = 0; i < settings.getAmountOfBands(); i++) {
            this.params[i].fGain = settings.getBandLevel(i);
            if (this.params[i].fGain >= 100 || this.params[i].fGain <= -100)
                this.params[i].fGain = this.params[i].fGain / 100; //TODO: until we change server values
        }
        this.gainLevel = settings.getGainLevel();
        this.bassboostLevel = settings.getBassBoostLevel();
        this.preset = settings.getCurrentPreset();
        this.updateFX();
    }

    @Override
    public Map<String, Short> getChoosablePresets() {
        return null;
    }

    @Override
    public void setGainLevel(short level) {
        this.gainLevel = level;
        if (isEnabled)
            this.updateFX();
    }

    @Override
    public short getGainLevel() {
        return this.gainLevel;
    }
}

« Last Edit: 21 Feb '18 - 11:36 by dieppa »

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: BASS makes my UI lag after several song loads.
« Reply #7 on: 21 Feb '18 - 17:06 »
Please try monitoring the BASS_GetCPU return value (eg. in a timer), and see whether it's rising with each loadSong call. Also compare with when the equalizer is disabled, to see what influence that is having.

dieppa

  • Posts: 33
Re: BASS makes my UI lag after several song loads.
« Reply #8 on: 22 Feb '18 - 08:47 »
Hi Ian,

I don't see any difference. Logs are displayed with an interval of one second and tracks order is the same for both.

Please check the link below. I did record the issue. First I skip the songs with BASS until it start freezing. Then I force an Exception in the player builder to build the Android MediaPlayer and skip the song just like with BASS but the UI doesn't lag.  ??? ???

https://vimeo.com/256917393

CPU consumption doesn't show any peak but the device I used to play the music in the video got very warm and depleted it's battery. This last also happened to my LG G6 while having the app in background. I must be doing something wrong or maybe there's any kind of conflict in the library.

Any clue?

Thanks for your support.

No equalizer:

Code: [Select]
D/CPU consumption: 2.1724615
D/CPU consumption: 1.8078493
D/CPU consumption: 2.2824025
D/CPU consumption: 2.7220297
D/CPU consumption: 2.836619
D/CPU consumption: 3.4298687
D/CPU consumption: 3.365215
D/CPU consumption: 3.7764928
D/CPU consumption: 3.8590422
D/CPU consumption: 3.6112175
D/CPU consumption: 3.8396206
D/CPU consumption: 4.066456
D/CPU consumption: 3.645214
D/CPU consumption: 3.6702437
D/CPU consumption: 3.7874265
D/CPU consumption: 3.7290921
D/CPU consumption: Next track
D/CPU consumption: 2.2300425
D/CPU consumption: 1.6501637
D/CPU consumption: 1.8293214
D/CPU consumption: 1.9011676
D/CPU consumption: 1.7920244
D/CPU consumption: 1.7202113
D/CPU consumption: 1.8060644
D/CPU consumption: 1.7557411
D/CPU consumption: 1.7318382
D/CPU consumption: 1.7878693
D/CPU consumption: 1.8547345
D/CPU consumption: 1.7012228
D/CPU consumption: 1.6194549
D/CPU consumption: 1.9633243
D/CPU consumption: 1.8204333
D/CPU consumption: 1.8422489
D/CPU consumption: Next track
D/CPU consumption: 0.6163535
D/CPU consumption: 1.073113
D/CPU consumption: 1.8896911
D/CPU consumption: 1.843541
D/CPU consumption: 1.7615814
D/CPU consumption: 1.83727
D/CPU consumption: 1.8512869
D/CPU consumption: 1.7848825
D/CPU consumption: 1.3347718
D/CPU consumption: 1.1901425
D/CPU consumption: 1.2526481
D/CPU consumption: 1.2699165
D/CPU consumption: 1.379033
D/CPU consumption: 1.337638
D/CPU consumption: 1.8503525
D/CPU consumption: 1.6652117
D/CPU consumption: 1.5863428
D/CPU consumption: 2.5958266
D/CPU consumption: Next track
D/CPU consumption: 0.104276724
D/CPU consumption: 1.1925753
D/CPU consumption: 1.5901673
D/CPU consumption: 1.4195542
D/CPU consumption: 1.7805545
D/CPU consumption: 1.678599
D/CPU consumption: 1.4972613
D/CPU consumption: 1.5595784
D/CPU consumption: 2.0060754
D/CPU consumption: 1.9538488
D/CPU consumption: 1.8559026
D/CPU consumption: 1.9463068
D/CPU consumption: 1.6496192
D/CPU consumption: Next track
D/CPU consumption: 0.11801261
D/CPU consumption: 5.2300777
D/CPU consumption: 7.379523
D/CPU consumption: 9.392853
D/CPU consumption: 9.319614
D/CPU consumption: 10.142369
D/CPU consumption: 11.777019
D/CPU consumption: 11.715074
D/CPU consumption: 12.194622
D/CPU consumption: 8.4096155
D/CPU consumption: Next track
D/CPU consumption: 1.6969625
D/CPU consumption: 11.909771
D/CPU consumption: 18.695007
D/CPU consumption: 21.56761
D/CPU consumption: 22.931122
D/CPU consumption: 23.559282
D/CPU consumption: 24.179014
D/CPU consumption: 24.410473
D/CPU consumption: 24.62752
D/CPU consumption: 24.724728
D/CPU consumption: 24.66685
D/CPU consumption: 24.852205
D/CPU consumption: Next track
D/CPU consumption: 24.231857
D/CPU consumption: 10.706787
D/CPU consumption: 5.9273047
D/CPU consumption: 4.270685
D/CPU consumption: 3.5873396
D/CPU consumption: 3.3194566
D/CPU consumption: 3.3208008
D/CPU consumption: 3.4223976
D/CPU consumption: 3.5555072
D/CPU consumption: 3.3960276
D/CPU consumption: 3.3909912
D/CPU consumption: 3.1858912
D/CPU consumption: 3.4345684
D/CPU consumption: 3.3149014
D/CPU consumption: 3.3278298
D/CPU consumption: 3.2712471
D/CPU consumption: Next track
D/CPU consumption: 0.05502519
D/CPU consumption: 12.440508
D/CPU consumption: 21.785994
D/CPU consumption: 23.340937
D/CPU consumption: 23.419846
D/CPU consumption: 23.446995
D/CPU consumption: 23.39865
D/CPU consumption: 23.541296
D/CPU consumption: 23.798925
D/CPU consumption: 25.925632

With equalizer:

Code: [Select]
D/CPU consumption: 3.1336355
D/CPU consumption: 2.8328676
D/CPU consumption: 2.5063431
D/CPU consumption: 2.455488
D/CPU consumption: 2.3737094
D/CPU consumption: 2.8069062
D/CPU consumption: 3.162533
D/CPU consumption: 2.970715
D/CPU consumption: 3.392496
D/CPU consumption: 2.7429025
D/CPU consumption: 3.45777
D/CPU consumption: 3.4448285
D/CPU consumption: 3.768843
D/CPU consumption: 3.244432
D/CPU consumption: 3.4864392
D/CPU consumption: 3.5062146
D/CPU consumption: Next track
D/CPU consumption: 2.342655
D/CPU consumption: 1.2778821
D/CPU consumption: 1.4350846
D/CPU consumption: 1.4825692
D/CPU consumption: 1.5224707
D/CPU consumption: 1.5846341
D/CPU consumption: 1.52076
D/CPU consumption: 1.5722091
D/CPU consumption: 1.5564957
D/CPU consumption: 1.6824107
D/CPU consumption: Next track
D/CPU consumption: 0.06359538
D/CPU consumption: 0.4424828
D/CPU consumption: 0.878839
D/CPU consumption: 1.0490677
D/CPU consumption: 1.3835318
D/CPU consumption: 1.5577092
D/CPU consumption: 1.5570397
D/CPU consumption: 1.9091239
D/CPU consumption: 2.129203
D/CPU consumption: 1.6639417
D/CPU consumption: 1.5494883
D/CPU consumption: Next track
D/CPU consumption: 1.2793518
D/CPU consumption: 0.88472563
D/CPU consumption: 1.375963
D/CPU consumption: 1.7070113
D/CPU consumption: 2.1053755
D/CPU consumption: 2.0490284
D/CPU consumption: 2.5239055
D/CPU consumption: 2.0652304
D/CPU consumption: 2.2604964
D/CPU consumption: 2.1554809
D/CPU consumption: 1.7770917
D/CPU consumption: 1.6250052
D/CPU consumption: 1.846174
D/CPU consumption: Next track
D/CPU consumption: 0.05617315
D/CPU consumption: 3.457977
D/CPU consumption: 7.7752953
D/CPU consumption: 10.558541
D/CPU consumption: 10.797255
D/CPU consumption: 10.740584
D/CPU consumption: 11.206659
D/CPU consumption: 11.643625
D/CPU consumption: 12.5252495
D/CPU consumption: 10.324631
D/CPU consumption: Next track
D/CPU consumption: 1.0620238
D/CPU consumption: 10.089857
D/CPU consumption: 16.984926
D/CPU consumption: 20.473856
D/CPU consumption: 21.06226
D/CPU consumption: 22.919996
D/CPU consumption: 23.134418
D/CPU consumption: 23.0285
D/CPU consumption: Next track
D/CPU consumption: 0.12988901
D/CPU consumption: 1.2867123
D/CPU consumption: 2.8282676
D/CPU consumption: 2.7147026
D/CPU consumption: 3.1702597
D/CPU consumption: 3.237235
D/CPU consumption: 3.5504143
D/CPU consumption: Next track
D/CPU consumption: 0.32450956
D/CPU consumption: 9.181767
D/CPU consumption: 19.344591
D/CPU consumption: 23.870655
D/CPU consumption: 24.976074
D/CPU consumption: 25.13903
D/CPU consumption: 26.56958
D/CPU consumption: 28.460894
D/CPU consumption: 25.518967
D/CPU consumption: 24.257366
D/CPU consumption: Next track
D/CPU consumption: 22.607069
D/CPU consumption: 9.391091
D/CPU consumption: 5.62961
D/CPU consumption: 4.2660627
D/CPU consumption: 3.4632645
D/CPU consumption: 2.8330603
D/CPU consumption: 2.7253919
D/CPU consumption: Next track
D/CPU consumption: 1.1727334
D/CPU consumption: 1.1667325
D/CPU consumption: 0.9912982
D/CPU consumption: 1.8500748
« Last Edit: 22 Feb '18 - 10:02 by dieppa »

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: BASS makes my UI lag after several song loads.
« Reply #9 on: 22 Feb '18 - 15:15 »
That logging appears to confirm that there is something hogging the CPU at times. BASS_GetCPU doesn't actually measure BASS's CPU usage but rather how timely the buffer update cycles are, so other/unrelated things hogging the CPU or I/O delays can cause the value to rise too.

It looks like the problem may be file-specific because the values go up for one file and then back down for the next. To perhaps get some clues on that, please use BASS_ChannelGetInfo to check the "ctype" value of each stream and note what it is for high CPU file(s). Also upload the high CPU file(s) to have a look at here:

   ftp.un4seen.com/incoming/

dieppa

  • Posts: 33
Re: BASS makes my UI lag after several song loads.
« Reply #10 on: 22 Feb '18 - 16:32 »
Hi Ian,

I have already uploaded the files to the ftp.

There's a zip file with 3 folders that contain sample files with different format, those files produce high cycles. The info of each file is in their respective folder. Then I uploaded you the music I used in the video (It's our corporative music, we own the rights, so no worries). Please note that those don't show many cycles (from 0.5 to 3) but the issue still occur.

Thanks for your support.

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: BASS makes my UI lag after several song loads.
« Reply #11 on: 23 Feb '18 - 17:37 »
Are the high BASS_GetCPU values only happening when playing the AMR and AAC files, not the MP3 files? If so, that may be a clue, as the AMR and AAC files will be using Android's decoders (ctype=BASS_CTYPE_STREAM_AM). BASS will be decoding the MP3 files.

Trying those files here, I do see higher BASS_GetCPU readings for the Android-decoded AAC/AMR files than the BASS-decoded MP3 files, but nowhere near as high as in your readings (around 8-9%). That isn't with an especially powerful CPU either, so I'm not sure why they're so high in your case. What device are you testing on, and are you seeing those 20+ numbers on other devices too? If you monitor the overall CPU usage of your app and the entire device, does that also show high numbers? It's possible that the high BASS_GetCPU readings for the Android decoders are due to delays/waits rather than CPU hogging.

dieppa

  • Posts: 33
Re: BASS makes my UI lag after several song loads.
« Reply #12 on: 26 Feb '18 - 09:28 »
Hi Ian,

Are the high BASS_GetCPU values only happening when playing the AMR and AAC files, not the MP3 files? - Seems to be, at least in those files I ahve for testing.

What device are you testing on, and are you seeing those 20+ numbers on other devices too? - LG G6 with Qualcomm MSM8996 Snapdragon 821 and an Energy Phone Pro 3 (our company's device) with a MediaTek MT6750, this last isn't fast actually (not compared to LG's) but curiously we have almost same readings.

With a 3ga file:

MT6750:

Code: [Select]
D/getCPU: 12.537051
D/getCPU: 16.620338
D/getCPU: 17.833221
D/getCPU: 22.95729
D/getCPU: 23.277695
D/getCPU: 22.186909
D/getCPU: 21.951422
D/getCPU: 23.727547
D/getCPU: 23.42521
D/getCPU: 21.3653
D/getCPU: 23.89547
D/getCPU: 20.024372
D/getCPU: 16.23041
D/getCPU: 18.218674
D/getCPU: 17.28783
D/getCPU: 15.184305
D/getCPU: 19.78133
D/getCPU: 25.17712
D/getCPU: 19.793392
D/getCPU: 24.346989
D/getCPU: 26.70484
D/getCPU: 20.249868
D/getCPU: 17.134415
D/getCPU: 22.745605

Snapdragon 821:

Code: [Select]
D/getCPU: 21.999765
D/getCPU: 18.891127
D/getCPU: 18.951986
D/getCPU: 18.06383
D/getCPU: 18.262106
D/getCPU: 16.591204
D/getCPU: 17.368486
D/getCPU: 16.2394
D/getCPU: 17.441122
D/getCPU: 15.54768
D/getCPU: 21.600431
D/getCPU: 24.259247
D/getCPU: 25.71389
D/getCPU: 24.700863
D/getCPU: 22.525803
D/getCPU: 26.252237
D/getCPU: 24.988947
D/getCPU: 26.047293
D/getCPU: 24.145308
D/getCPU: 26.69164
D/getCPU: 26.626064
D/getCPU: 25.330574
D/getCPU: 25.696209
D/getCPU: 23.346245


If you monitor the overall CPU usage of your app and the entire device, does that also show high numbers? - MT6750 get peaks of 32% with avg of 19% CPU usage (app), Snapdragon 821 get peaks of 20% with avg of 11% CPU usage (app). Overall CPU usage is quite high for both devices, peaks over 60% in MTK and 50% in Qualcomm.

Thanks for your support,

Dieppa.

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: BASS makes my UI lag after several song loads.
« Reply #13 on: 26 Feb '18 - 15:17 »
For comparison, here's a version of the PLUGINS example from the BASS package with a BASS_GetCPU value display added, for you to try:

   www.un4seen.com/stuff/plugins.apk

Do you see the same high numbers, and overall CPU usage, with that?

dieppa

  • Posts: 33
Re: BASS makes my UI lag after several song loads.
« Reply #14 on: 26 Feb '18 - 16:13 »
Hi Ian,

For 3GA file format:

Snapdragon 321 - https://imgur.com/a/W8kiB

MT6750 - https://imgur.com/a/6mzzl

----------------------------------------------

For AAC file format:

Snapdragon 321 - https://imgur.com/a/T6aKo

MT6750 - https://imgur.com/a/0w4of

----------------------------------------------

The overall CPU usage goes most of the time from 30% to  40% for both devices.

Please check the video in the link  below:

https://vimeo.com/257518663

I think this app shows what's going on. I have noted that when you do several song loads (just like in the issue we are trying to fix) you can see that CPU value goes kinda unstable. There might be 2 possibilities:

1.- In your Android implementation you forgot to clear the SYNC event that spams GetCPU and everytime you load a song it puts a new one.
2.- It's an issue inside BASS that might be the root cause of the problem.

Thanks for your support,
Dieppa.
« Last Edit: 26 Feb '18 - 16:36 by dieppa »

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: BASS makes my UI lag after several song loads.
« Reply #15 on: 26 Feb '18 - 17:33 »
Oops. The example is missing a Handler.removeCallbacks call, which is causing the display to be refreshed faster after each file. Here's a corrected version:

   www.un4seen.com/stuff/plugins.apk

I don't think that will be really affecting CPU usage though, so that's still a mystery. The numbers in your images are very high. I suspect there must be delays/waits involved in that, as the CPU in your devices are reasonably powerful. What does the CPU monitor say about it? Please also confirm what Android version(s) the devices are running. If you happen to have any other Android devices to hand, please also see what results you get with them too, to perhaps find a pattern (eg. Android version).

dieppa

  • Posts: 33
Re: BASS makes my UI lag after several song loads.
« Reply #16 on: 27 Feb '18 - 10:31 »
Please check this video with several Android devices. On each device you can see Android version, CPU model, clock speed, usage, etc. while playing acc and 3ga files.

https://mega.nz/#!lpxAiC5I!6aqa3PW7BhoL31ozz7Ln0XxE8C6pwBnurgszTLXU08M

It's a bit large, I had to upload it to Mega.nz, I am affraid you have to download it to watch it.

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: BASS makes my UI lag after several song loads.
« Reply #17 on: 27 Feb '18 - 17:13 »
Thanks for that effort! I notice in the worst case (the 1st phone) that the CPU appears to stay running at minimum speed according to CPU-Z. Perhaps some sort of energy saving mode is enabled, and is contributing to the problem? Are you having the UI lag issue on all of these devices, even the ones with lower BASS_GetCPU values?

I'm looking into updating the PLUGINS example to also display what the system says the app's CPU usage is, so that can be compared with what BASS_GetCPU says.

dieppa

  • Posts: 33
Re: BASS makes my UI lag after several song loads.
« Reply #18 on: 28 Feb '18 - 16:14 »
Hi Ian,

I can asure you this issue happens to all devices even with simple mp3 files. As I showed you in a previous video by forcing the app to use the Android MediaPlayer the UI works fluid.

Please check it yourself. Both APK have EQ, FFT visualization and timer features deactivated.

BASS player version:

https://mega.nz/#!htA3WARA!IL8qJz3E2Hxg4kCZ0tvMzZYpWzg6XKRAG8W2jNvTOTQ

Android Mediaplayer version:

https://mega.nz/#!AtQXVL6C!FhAx3tgAnBRTfU95uDV36Vi8sjZ7mSs3mYjN1RdKTYo

This issue is driving me nuts, many users complain about performance issues.

Thanks for your support.

Dieppa.


Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: BASS makes my UI lag after several song loads.
« Reply #19 on: 28 Feb '18 - 17:15 »
I can asure you this issue happens to all devices even with simple mp3 files.

OK. I'm not really sure what could be causing that, but here are a few things you can try.

Enable non-stop output via the BASS_CONFIG_DEV_NONSTOP option:

Code: [Select]
BASS.BASS_SetConfig(BASS.BASS_CONFIG_DEV_NONSTOP, 1);

Use AudioTrack output via the BASS_DEVICE_AUDIOTRACK flag:

Code: [Select]
BASS.BASS_Init(-1, 44100, BASS.BASS_DEVICE_AUDIOTRACK);

Raise the device output period via the BASS_CONFIG_DEV_PERIOD option:

Code: [Select]
BASS.BASS_SetConfig(BASS.BASS_CONFIG_DEV_PERIOD, 15);

That needs to be done before calling BASS_Init. The default is 10ms, so you can try going up from that.

dieppa

  • Posts: 33
Re: BASS makes my UI lag after several song loads.
« Reply #20 on: 1 Mar '18 - 22:07 »
Hi Ian,

I am glad to tell you I've solved the issue. I want to thank all the effort answering our questions and helping us, and the great job you are doing with BASS. It wasn't BASS issue but our player's custom notification. For some reason I don't know yet, the custom notification was leaking memory and getting stuck freezing the devices, what is a mystery is that this didn't happen with Android's Mediaplayer. I decided to use the default Android notification until I find out what's going on.

Thanks.

Ian @ un4seen

  • Administrator
  • Posts: 21133
Re: BASS makes my UI lag after several song loads.
« Reply #21 on: 2 Mar '18 - 14:04 »
Great to hear that you found the problem. I was running out of ideas :)