sidechain(ducking)效果android

时间:2015-09-24 06:09:29

标签: java android

我想在我的应用程序中使用侧垫(鸭子)效果在soundpad(踢垫10作为输入),我该如何实现这一目标?基于bool和touchlistener的侧链效果很慢,并且不会立即激活(但是当你继续触摸垫3时它会起作用)。 音频焦点code snippet,据我所知,只关注其他应用作为收益。

也许有人可以帮我这个?

谢谢!

这是代码.java

    import android.app.Activity;
    import android.content.Context;
    import android.os.Bundle;
    import android.media.SoundPool;
    import android.media.AudioManager;
    import android.view.MotionEvent;
    import android.view.View;
    import android.view.WindowManager;
    import android.widget.Button;
    import android.view.View.OnTouchListener;

    import com.google.android.gms.ads.AdRequest;
    import com.google.android.gms.ads.AdView;

    import java.sql.Time;
    import java.util.Timer;

    /**
     * Created by Paul King on 8/16/2015.
     */

public class freejam_preset_1 extends Activity implements OnTouchListener {

    boolean SideChain = false;
    int p1p1;
    int p1p2;
    int p1p3;
    int p1p4;
    int p1p5;
    int p1p6;
    int p1p7;
    int p1p8;
    int p1p9;
    int p1p10;
    int p1p11;
    int p1p12;


    Button PresetOne_Pad1;
    Button PresetOne_Pad2;
    Button PresetOne_Pad3;
    Button PresetOne_Pad4;
    Button PresetOne_Pad5;
    Button PresetOne_Pad6;
    Button PresetOne_Pad7;
    Button PresetOne_Pad8;
    Button PresetOne_Pad9;
    Button PresetOne_Pad10;
    Button PresetOne_Pad11;
    Button PresetOne_Pad12;

    SoundPool mySound;


    @Override
    protected void onCreate(Bundle savedInstanceState) {


        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        super.onCreate(savedInstanceState);

        setContentView(R.layout.freejam_preset_1);


        mySound = new SoundPool(12, AudioManager.STREAM_MUSIC, 0);


        p1p1 = mySound.load(this, R.raw.pone_padone, 1);
        p1p2 = mySound.load(this, R.raw.pone_padtwo, 1);
        p1p3 = mySound.load(this, R.raw.pone_padthree, 1);
        p1p4 = mySound.load(this, R.raw.pone_padfour, 1);
        p1p5 = mySound.load(this, R.raw.pone_padfive, 1);
        p1p6 = mySound.load(this, R.raw.pone_padsix, 1);
        p1p7 = mySound.load(this, R.raw.pone_padseven, 1);
        p1p8 = mySound.load(this, R.raw.pone_padeight, 1);
        p1p9 = mySound.load(this, R.raw.pone_padnine, 1);
        p1p10 = mySound.load(this, R.raw.pone_padten, 1);
        p1p11 = mySound.load(this, R.raw.pone_padeleven, 1);
        p1p12 = mySound.load(this, R.raw.pone_padtwelve, 1);

        PresetOne_Pad1 = (Button) findViewById(R.id.p1p1id);
        PresetOne_Pad2 = (Button) findViewById(R.id.p1p2id);
        PresetOne_Pad3 = (Button) findViewById(R.id.p1p3id);
        PresetOne_Pad4 = (Button) findViewById(R.id.p1p4id);
        PresetOne_Pad5 = (Button) findViewById(R.id.p1p5id);
        PresetOne_Pad6 = (Button) findViewById(R.id.p1p6id);
        PresetOne_Pad7 = (Button) findViewById(R.id.p1p7id);
        PresetOne_Pad8 = (Button) findViewById(R.id.p1p8id);
        PresetOne_Pad9 = (Button) findViewById(R.id.p1p9id);
        PresetOne_Pad10 = (Button) findViewById(R.id.p1p10id);
        PresetOne_Pad11 = (Button) findViewById(R.id.p1p11id);
        PresetOne_Pad12 = (Button) findViewById(R.id.p1p12id);



        PresetOne_Pad10.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                if (event.getAction() == MotionEvent.ACTION_DOWN) {

                    mySound.play(p1p10, 1, 1, 1, 0, 1);

                        SideChain = true;



                }

                if (event.getAction() == MotionEvent.ACTION_UP) {

                    SideChain = false;

                }


                return false;
            }
        });

        PresetOne_Pad3.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                if (event.getAction() == MotionEvent.ACTION_DOWN) {

                    if(SideChain==true) {
                        mySound.play(p1p3, 0.8f, 0.8f, 1, 0, 1);
                        // 0.1f
                    }
                    else
                    {
                        mySound.play(p1p3, 1, 1, 1, 0, 1);
                    }

                }
                return false;
            }
        });



        PresetOne_Pad7.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                if (event.getAction() == MotionEvent.ACTION_DOWN) {

                    mySound.play(p1p7, 1, 1, 1, 0, 1);

                }

                return false;
            }
        });




        PresetOne_Pad1.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                if (event.getAction() == MotionEvent.ACTION_DOWN) {

                    mySound.play(p1p1, 1, 1, 1, 0, 1);

                }

                return false;
            }
        });




        PresetOne_Pad2.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                if (event.getAction() == MotionEvent.ACTION_DOWN) {

                    mySound.play(p1p2, 1, 1, 1, 0, 1);

                }

                return false;
            }
        });



        PresetOne_Pad4.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                if (event.getAction() == MotionEvent.ACTION_DOWN) {

                    mySound.play(p1p4, 1, 1, 1, 0, 1);

                }

                return false;
            }
        });



        PresetOne_Pad5.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                if (event.getAction() == MotionEvent.ACTION_DOWN) {

                    mySound.play(p1p5, 1, 1, 1, 0, 1);

                }

                return false;
            }
        });


        PresetOne_Pad6.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                if (event.getAction() == MotionEvent.ACTION_DOWN) {

                    mySound.play(p1p6, 1, 1, 1, 0, 1);

                }

                return false;
            }
        });




        PresetOne_Pad8.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                if (event.getAction() == MotionEvent.ACTION_DOWN) {

                    mySound.play(p1p8, 1, 1, 1, 0, 1);

                }

                return false;
            }
        });

        PresetOne_Pad9.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                if (event.getAction() == MotionEvent.ACTION_DOWN) {

                    mySound.play(p1p9, 1, 1, 1, 0, 1);

                }

                return false;
            }
        });


        PresetOne_Pad11.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                if (event.getAction() == MotionEvent.ACTION_DOWN) {

                    mySound.play(p1p11, 1, 1, 1, 0, 1);

                }

                return false;
            }
        });

        PresetOne_Pad12.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                if (event.getAction() == MotionEvent.ACTION_DOWN) {

                    mySound.play(p1p12, 1, 1, 1, 0, 1);

                }

                return false;
            }
        });



        AdView mAdView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);


    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return false;
    }



}

0 个答案:

没有答案