Author Topic: How to fade out on Android  (Read 9186 times)

pengsongbai

  • Posts: 6
How to fade out on Android
« on: 21 Jun '14 - 09:18 »
Hi guys,

        I want to play/save my channel with fade in and fade out, but it doesn't work, below is my code, which COULD fade in BUT COULD NOT fade out, could you please give me some advice?
public static int handleSound(int channel, int effect, float volumeRatio, boolean fadein, boolean fadeout) {

        if (effect != 0) {
            BASS.BASS_ChannelRemoveFX(channel, effect);
        }

        final int nodeCount = 4;
        BASS_FX.BASS_BFX_ENV_NODE[] nodes = new BASS_FX.BASS_BFX_ENV_NODE[nodeCount];


        BASS_FX.BASS_BFX_ENV_NODE node0 = new BASS_FX.BASS_BFX_ENV_NODE();
        node0.pos = 0;
        node0.val = fadein ? 0f : volumeRatio;

        BASS_FX.BASS_BFX_ENV_NODE node1 = new BASS_FX.BASS_BFX_ENV_NODE();
        node1.pos = fadein ? 5 : 0;
        node1.val = volumeRatio;

        double duration = BASS.BASS_ChannelBytes2Seconds(channel, BASS.BASS_ChannelGetLength(channel, BASS.BASS_POS_BYTE));
        BASS_FX.BASS_BFX_ENV_NODE node3 = new BASS_FX.BASS_BFX_ENV_NODE();
        node3.pos = duration;
        node3.val = fadeout ? 0.0f : volumeRatio;

        BASS_FX.BASS_BFX_ENV_NODE node2 = new BASS_FX.BASS_BFX_ENV_NODE();
        node2.pos = fadeout ? (node3.pos - 5) : node3.pos;
        node2.val = volumeRatio;
       
        nodes[0] = node0;
        nodes[1] = node1;
        nodes[2] = node2;
        nodes[3] = node3;

        BASS_FX.BASS_BFX_VOLUME_ENV volume = new BASS_FX.BASS_BFX_VOLUME_ENV();
        volume.lChannel = BASS_FX.BASS_BFX_CHANALL;
        volume.lNodeCount = nodeCount;
        volume.pNodes = nodes;
        volume.bFollow = false;
        //volume.bFollow = true;  //if set true, the sound listens so terrible

        effect = BASS.BASS_ChannelSetFX(channel, BASS_FX.BASS_FX_BFX_VOLUME_ENV, 0);
        BASS.BASS_FXSetParameters(effect, volume);

        return effect;
    }

Ian @ un4seen

  • Administrator
  • Posts: 26178
Re: How to fade out on Android
« Reply #1 on: 23 Jun '14 - 17:15 »
The "bFollow" parameter should be set to TRUE, as your envelope positions are based on the channel's position, eg. the fade-out occurs at the end of the channel. I see you have a "if set true, the sound listens so terrible" comment. Please expand on that. Also confirm how you are creating the channel.

pengsongbai

  • Posts: 6
Re: How to fade out on Android
« Reply #2 on: 24 Jun '14 - 03:55 »
if set true, it listens as wave(NOT format): high-low-high-low...-high-low
my channel created by this way :

mBassChannel = BASS.BASS_StreamCreateFile(path, 0, 0, BASS.BASS_STREAM_DECODE | BASS.BASS_SAMPLE_OVER_POS);
if (mBassChannel != 0) {
          mBassChannel = BASS_FX.BASS_FX_TempoCreate(mBassChannel, BASS.BASS_MUSIC_NONINTER);
} else {
          mBassChannel = BASS.BASS_MusicLoad(path, 0, 0, BASS.BASS_STREAM_DECODE | BASS.BASS_SAMPLE_OVER_POS | BASS.BASS_MUSIC_RAMP, 1);
}

Ian @ un4seen

  • Administrator
  • Posts: 26178
Re: How to fade out on Android
« Reply #3 on: 24 Jun '14 - 17:11 »
BASS_SAMPLE_OVER_POS isn't a valid flag for BASS_StreamCreateFile or BASS_MusicLoad, and BASS_MUSIC_NONINTER isn't a valid flag for BASS_FX_TempoCreate (a list of valid flags can be found in each function's documentation). So please first remove those. If the problem still happens, could you make a recording of it? Also confirm what the "duration" value is (from your code above), and whether it's correct.

pengsongbai

  • Posts: 6
Re: How to fade out on Android
« Reply #4 on: 29 Jun '14 - 17:04 »
Lan,

        Thanks a lot, but I still have some issue and failed to fix the issue. As your suggestion, send you the sound copy, but the sound is very unclearly and hard to hear, then, I sent you the test file via message, looking forward for your further advice, thanks in advance!

Ian @ un4seen

  • Administrator
  • Posts: 26178
Re: How to fade out on Android
« Reply #5 on: 30 Jun '14 - 16:07 »
Ah! I see now that there is indeed a bug in the "bFollow" option processing on Android. I'll let the BASS_FX developer know about it.

pengsongbai

  • Posts: 6
Re: How to fade out on Android
« Reply #6 on: 1 Jul '14 - 02:55 »
Okay, waiting for your good news :P

(: JOBnik! :)

  • Posts: 1080
Re: How to fade out on Android
« Reply #7 on: 10 Jul '14 - 22:17 »
Hi ;D

Please try this update:
http://www.jobnik.org/files/beta/bass_fx24108beta-android.zip

The x86 version is still buggy with some effects :)

pengsongbai

  • Posts: 6
Re: How to fade out on Android
« Reply #8 on: 11 Jul '14 - 10:35 »
JOBnik & lan,

    seems the bFollow works fine! Thanks a lot!