Android Open Source - DoomPlay Bass Player






From Project

Back to project page DoomPlay.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUC...

If you think the Android project DoomPlay listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.perm.DoomPlay;
//from w w  w  .j a v a2 s.  c  om
import android.content.pm.ApplicationInfo;
import com.un4seen.bass.BASS;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class BassPlayer
{
    public interface OnCompletionListener
    {
        void onCompletion();
    }
    public boolean isPlaying;

    private static int chan;
    private int totalTime;
    private OnCompletionListener completionListener;
    private static int[] fxBands = new int[10];
    private static int fxReverb ;


   public void setOnCompletetion(OnCompletionListener listener)
   {
        this.completionListener = listener;
   }

   private final BASS.SYNCPROC EndSync=new BASS.SYNCPROC()
   {
        public void SYNCPROC(int handle, int channel, int data, Object user)
        {
            isPlaying = false;
            if(completionListener != null)
                completionListener.onCompletion();
        }
    };

    public BassPlayer()
    {
        BASS.BASS_Init(-1, 44100, 0);
        BASS.BASS_SetConfig(BASS.BASS_CONFIG_FLOATDSP, 32);
        chan = 0;
        ApplicationInfo info = MyApplication.getInstance().getApplicationInfo();
        if(info != null)
        {
            String path = info.nativeLibraryDir;
            String[] list = new File(path).list();
            for (String s: list)
            {
                BASS.BASS_PluginLoad(path+"/"+s, 0);
            }
        }
    }
    public void prepareFile(String url) throws IOException
    {
        chan = BASS.BASS_StreamCreateFile(url, 0L, 0L, 0);

        if(chan == 0)
        {
            throw new IOException("prepare exception "+ BASS.BASS_ErrorGetCode());
        }

        long bytes = BASS.BASS_ChannelGetLength(chan, BASS.BASS_POS_BYTE);
        totalTime = (int)BASS.BASS_ChannelBytes2Seconds(chan, bytes);
        BASS.BASS_CHANNELINFO info=new BASS.BASS_CHANNELINFO();
        BASS.BASS_ChannelGetInfo(chan, info);
        BASS.BASS_ChannelSetSync(chan, BASS.BASS_SYNC_END, 0, EndSync, 0);

        setUpEffects();

    }
    private void setUpEffects()
    {
        fxBands[0] = BASS.BASS_ChannelSetFX(chan, BASS.BASS_FX_DX8_PARAMEQ, 0);
        fxBands[1] = BASS.BASS_ChannelSetFX(chan, BASS.BASS_FX_DX8_PARAMEQ, 0);
        fxBands[2] = BASS.BASS_ChannelSetFX(chan, BASS.BASS_FX_DX8_PARAMEQ, 0);
        fxBands[3] = BASS.BASS_ChannelSetFX(chan, BASS.BASS_FX_DX8_PARAMEQ, 0);
        fxBands[4] = BASS.BASS_ChannelSetFX(chan, BASS.BASS_FX_DX8_PARAMEQ, 0);
        fxBands[5] = BASS.BASS_ChannelSetFX(chan, BASS.BASS_FX_DX8_PARAMEQ, 0);
        fxBands[6] = BASS.BASS_ChannelSetFX(chan, BASS.BASS_FX_DX8_PARAMEQ, 0);
        fxBands[7] = BASS.BASS_ChannelSetFX(chan, BASS.BASS_FX_DX8_PARAMEQ, 0);
        fxBands[8] = BASS.BASS_ChannelSetFX(chan, BASS.BASS_FX_DX8_PARAMEQ, 0);
        fxBands[9] = BASS.BASS_ChannelSetFX(chan, BASS.BASS_FX_DX8_PARAMEQ, 0);
        fxReverb = BASS.BASS_ChannelSetFX(chan, BASS.BASS_FX_DX8_REVERB, 0);

        BASS.BASS_DX8_PARAMEQ p = new BASS.BASS_DX8_PARAMEQ();

        p.fGain=0;
        p.fBandwidth = 0.5f;
        p.fCenter=32;
        BASS.BASS_FXSetParameters(fxBands[0], p);
        p.fCenter=64;
        BASS.BASS_FXSetParameters(fxBands[1], p);
        p.fCenter=125;
        BASS.BASS_FXSetParameters(fxBands[2], p);
        p.fBandwidth = 2f;
        p.fCenter=250;
        BASS.BASS_FXSetParameters(fxBands[3], p);
        p.fCenter=500;
        BASS.BASS_FXSetParameters(fxBands[4], p);
        p.fBandwidth = 4f;
        p.fCenter=1000;
        BASS.BASS_FXSetParameters(fxBands[5], p);
        p.fCenter=2000;
        BASS.BASS_FXSetParameters(fxBands[6], p);
        p.fCenter=4000;
        BASS.BASS_FXSetParameters(fxBands[7], p);
        p.fCenter=8000;
        p.fBandwidth = 8f;
        BASS.BASS_FXSetParameters(fxBands[8], p);
        p.fCenter=16000;
        BASS.BASS_FXSetParameters(fxBands[9], p);




        int[] bounds  = EqualizerBandsFragment.getSavedBounds();
        for(int i = 0 ; i < bounds.length ; i++ )
            updateFX(bounds[i], i);

        int[] effecs = EqualizerEffectsFragment.getSavedEffects();
        setLowFreq(effecs[0]);
        setHightFreq(effecs[1]);
        setReverb(effecs[2]);



    }
    public static void updateFX(int progress, int n)
    {
        BASS.BASS_DX8_PARAMEQ p = new BASS.BASS_DX8_PARAMEQ();
        BASS.BASS_FXGetParameters(fxBands[n], p);
        p.fGain = EqualizerBandsFragment.convertProgressToGain(progress);
        BASS.BASS_FXSetParameters(fxBands[n], p);
    }
    public static void setReverb(int progress)
    {
        BASS.BASS_DX8_REVERB p=new BASS.BASS_DX8_REVERB();
        BASS.BASS_FXGetParameters(fxReverb, p);
        p.fReverbMix=(float)(progress > 15 ? Math.log((double)progress/20.0)*20.0:-96.0);
        BASS.BASS_FXSetParameters(fxReverb, p);
    }
    public static void setLowFreq(int progress)
    {
          for(int i = 0 ; i < 5 ; i++)
          {
              BASS.BASS_DX8_PARAMEQ p = new BASS.BASS_DX8_PARAMEQ();
              BASS.BASS_FXGetParameters(fxBands[i], p);

              if(i < 3)
                p.fBandwidth = 0.5f * convertProgressToFreq(progress);
              else
                p.fBandwidth = 2f * convertProgressToFreq(progress);

              BASS.BASS_FXSetParameters(fxBands[i], p);
          }

    }
    public static void setHightFreq(int progress)
    {
        for(int i = 6 ; i < 10 ; i++)
        {
            BASS.BASS_DX8_PARAMEQ p = new BASS.BASS_DX8_PARAMEQ();
            BASS.BASS_FXGetParameters(fxBands[i], p);
            if(i < 8)
                p.fBandwidth = 4f * convertProgressToFreq(progress);
            else
                p.fBandwidth = 8f * convertProgressToFreq(progress);
            BASS.BASS_FXSetParameters(fxBands[i], p);
        }
    }


    public static float convertProgressToFreq(int progress)
    {
        return ((float)progress*3f/100f) + 1;
    }


    private final Object lock = new Object();
    int req;

    public void prepareNet(String url) throws IOException
    {
        int r;
        synchronized(lock)
        {
            r=++req;
        }

        int c = BASS.BASS_StreamCreateURL(url, 0, BASS.BASS_STREAM_STATUS, StatusProc, r);

        synchronized(lock)
        {
            if (r!=req)
            {
                if (c!=0)
                {
                    BASS.BASS_StreamFree(c);
                }
                throw new IOException("prepare exception");
            }
            chan=c;
        }

        if(chan == 0)
        {
            throw new IOException("prepare exception");
        }

        long bytes = BASS.BASS_ChannelGetLength(chan, BASS.BASS_POS_BYTE);
        totalTime = (int)BASS.BASS_ChannelBytes2Seconds(chan, bytes);
        BASS.BASS_CHANNELINFO info=new BASS.BASS_CHANNELINFO();
        BASS.BASS_ChannelGetInfo(chan, info);
        BASS.BASS_ChannelSetSync(chan, BASS.BASS_SYNC_END, 0, EndSync, 0);

        setUpEffects();

        if(SettingActivity.getPreferences("savevkfile"))
            filePath = DownloadingService.getDownloadDir() + url.substring( url.lastIndexOf('/')+1, url.length());
    }


    private FileChannel fc;
    private String filePath;
    private final BASS.DOWNLOADPROC StatusProc=new BASS.DOWNLOADPROC()
    {
        @Override
        public void DOWNLOADPROC(ByteBuffer buffer, int length, Object user)
        {
              //&& (Integer)user == req
            if(filePath != null )
            {
                try
                {
                    if (buffer!=null)
                    {
                        if (fc==null)
                            fc=new FileOutputStream(new File(filePath)).getChannel();
                        fc.write(buffer);
                    }
                    else if (fc!=null)
                    {
                        fc.close();
                        fc = null;
                    }
                }
                catch (IOException e) {}
            }

        }
    };

    public void start()
    {
        BASS.BASS_ChannelPlay(chan, false);
        isPlaying = true;
    }
    public void pause()
    {
        BASS.BASS_ChannelPause(chan);
        isPlaying = false;
    }

    public int getCurrentPosition()
    {
        return (int)BASS.BASS_ChannelBytes2Seconds(chan, BASS.BASS_ChannelGetPosition(chan, BASS.BASS_POS_BYTE));
    }

    public int getTotalTime()
    {
        return totalTime;
    }

    public void seekTo(int to)
    {
        BASS.BASS_ChannelSetPosition(chan, BASS.BASS_ChannelSeconds2Bytes(chan, to), BASS.BASS_POS_BYTE);
    }
    public void releaseTotal()
    {
        BASS.BASS_Free();
        BASS.BASS_PluginFree(0);
    }
    public void release()
    {
        BASS.BASS_MusicFree(chan);
        BASS.BASS_StreamFree(chan);

        assert fc == null;
        filePath = null;
    }
    public int getPercentage()
    {
        if(getTotalTime() == 0)
            return 0;
        return (100*getCurrentPosition())/getTotalTime();
    }
}




Java Source Code List

com.api.Account.java
com.api.Api.java
com.api.AudioAlbum.java
com.api.Auth.java
com.api.Group.java
com.api.IdsPair.java
com.api.KException.java
com.api.Media.java
com.api.Params.java
com.api.PhotoTag.java
com.api.Photo.java
com.api.SearchDialogItem.java
com.api.User.java
com.api.Utils.java
com.api.VkStatus.java
com.api.WrongResponseCodeException.java
com.perm.DoomPlay.AbstractControls.java
com.perm.DoomPlay.AbstractList.java
com.perm.DoomPlay.AbstractReceiver.java
com.perm.DoomPlay.AbstractVkItems.java
com.perm.DoomPlay.AddListDialog.java
com.perm.DoomPlay.AddTrackFromPlaybackDialog.java
com.perm.DoomPlay.AddTrackToAlbumDialog.java
com.perm.DoomPlay.AlbumArtGetter.java
com.perm.DoomPlay.AlbumArtistActivity.java
com.perm.DoomPlay.Audio.java
com.perm.DoomPlay.BassPlayer.java
com.perm.DoomPlay.BigWidget.java
com.perm.DoomPlay.CustomViewPager.java
com.perm.DoomPlay.DirectoryChooserActivity.java
com.perm.DoomPlay.DownloadNotifBuilder.java
com.perm.DoomPlay.Download.java
com.perm.DoomPlay.DownloadingService.java
com.perm.DoomPlay.EqualizerActivity.java
com.perm.DoomPlay.EqualizerBandsFragment.java
com.perm.DoomPlay.EqualizerEffectsFragment.java
com.perm.DoomPlay.ExceptionLog.java
com.perm.DoomPlay.FileSystemActivity.java
com.perm.DoomPlay.FullPlaybackActivity.java
com.perm.DoomPlay.ListTracksActivity.java
com.perm.DoomPlay.ListVkActivity.java
com.perm.DoomPlay.ListsAdapter.java
com.perm.DoomPlay.LoginActivity.java
com.perm.DoomPlay.LyricsDialog.java
com.perm.DoomPlay.MainLocalFragment.java
com.perm.DoomPlay.MainScreenActivity.java
com.perm.DoomPlay.MainVkFragment.java
com.perm.DoomPlay.MediaButtonReceiver.java
com.perm.DoomPlay.MyApplication.java
com.perm.DoomPlay.PageFragment.java
com.perm.DoomPlay.PlayingService.java
com.perm.DoomPlay.PlaylistActivity.java
com.perm.DoomPlay.PlaylistDB.java
com.perm.DoomPlay.PlaylistParser.java
com.perm.DoomPlay.ReportDialog.java
com.perm.DoomPlay.SearchActivity.java
com.perm.DoomPlay.SearchVkActivity.java
com.perm.DoomPlay.Serializator.java
com.perm.DoomPlay.SettingActivity.java
com.perm.DoomPlay.SleepDialog.java
com.perm.DoomPlay.SmallWidget.java
com.perm.DoomPlay.TracksHolder.java
com.perm.DoomPlay.Utils.java
com.perm.DoomPlay.VerticalSeekBar.java
com.perm.DoomPlay.VkAlbumsActivity.java
com.perm.DoomPlay.VkFrActivity.java
com.perm.DoomPlay.VkGrActivity.java
com.perm.DoomPlay.VkPopularActivity.java
com.un4seen.bass.BASSFLAC.java
com.un4seen.bass.BASSMIDI.java
com.un4seen.bass.BASSOPUS.java
com.un4seen.bass.BASSWV.java
com.un4seen.bass.BASS_AAC.java
com.un4seen.bass.BASS_ALAC.java
com.un4seen.bass.BASS_APE.java
com.un4seen.bass.BASS_MPC.java
com.un4seen.bass.BASS.java