Analyze audio in Ketai or cassette

edited May 2016 in Android Mode

I have an audio player working, an want a level meter graphic. Is there an analyze function to use with these libraries?

Tagged:

Answers

  •     //
        //
    
        import cassette.audiofiles.* ; // SoundFile;
        import ketai.sensors.*;
        import ketai.ui.*;
        import controlP5.*;
    
        ControlP5 cp5;
        SoundFile music;
    
        boolean isplaying = false ; 
    
    
        void setup()
        {
          size(480,700,P2D);
         // orientation(PORTRAIT);
          textSize(28);
          textAlign(CENTER);
    
          cp5 = new ControlP5(this);
    
           PFont ffont = createFont("Arial",20,true); // use true/false for smooth/no-smooth 
            ControlFont gfont = new ControlFont(ffont,241);
    
            cp5.addButton("STOP",0,360, 620, 120, 80).setStringValue("STOP"); 
            cp5.getController("STOP").getCaptionLabel().setFont(gfont).toUpperCase(true).setSize(40); 
            cp5.getController("STOP").setColorBackground(color(255,0,0,255));
    
            cp5.addButton("Min5",0,360, 60, 120, 80).setStringValue("5 min"); 
            cp5.getController("Min5").getCaptionLabel().setFont(gfont).toUpperCase(true).setSize(40); 
            cp5.getController("Min5").setColorBackground(color(10,20,130,140));
    
            cp5.addButton("Min15",0,360, 220, 120, 80).setStringValue("15 min"); 
            cp5.getController("Min15").getCaptionLabel().setFont(gfont).toUpperCase(true).setSize(40); 
            cp5.getController("Min15").setColorBackground(color(10,20,130,140));
    
            // play buttons
             for (int i = 0; i < 8; i++) {
    
            cp5.addButton("P"+i,0,10, 20+(80*i), 240, 70).setCaptionLabel("P"+i); 
            cp5.getController("P"+i).getCaptionLabel().setFont(gfont).toUpperCase(true).setSize(40); 
            cp5.getController("P"+i).setColorBackground(color(10,20,130,140));
            cp5.getController("P"+i).setStringValue("P"+i);
            //
             } 
    
            cp5.getController("P"+0).setCaptionLabel("CHICKEN");
            cp5.getController("P"+1).setCaptionLabel("BEEF");
            cp5.getController("P"+2).setCaptionLabel("PORK");
            cp5.getController("P"+3).setCaptionLabel("LAMB");
            cp5.getController("P"+4).setCaptionLabel("SAUSAGES");
            cp5.getController("P"+5).setCaptionLabel("SCHNITZ");
            cp5.getController("P"+6).setCaptionLabel("SPECIALS1");
            cp5.getController("P"+7).setCaptionLabel("SPECIALS2");
    
    
           music = new SoundFile(this, "RoughMix.mp3");
            music.loop();
        //
        }
    
        void draw() {
          background(255);
          fill(10,20,240,128);
          if ( isplaying ) { text(" Playing...",100,685); }
          if ( !isplaying ) { text(" ALL STOPPED..",100,685); }
    
        }
    
        void mousePressed() {
    
        }
    
        public void STOP(int theValue) {
         println("[ STOP ]");
         cp5.getController("STOP").setColorBackground(color(10,255,30,140));
          //
          allstop();
          //
          cp5.getController("STOP").setColorBackground(color(255,20,30,255));
          isplaying = false;
          if ( !isplaying ) {  text(" ALL STOPPED..",50,680); }
         //
        }
    
        public void Min5(int theValue) {
         println("[ Min5 ]");
         cp5.getController("Min5").setColorBackground(color(10,255,30,140));
          //
          allstop();
         //
         isplaying = false;
         //cp5.getController("Min5").setColorBackground(color(255,20,30,255));
         //
        }
    
        public void Min15(int theValue) {
         println("[ Min15 ]");
         cp5.getController("Min15").setColorBackground(color(10,255,30,140));
          //
          allstop();
         //
         isplaying = false;
         // cp5.getController("Min15").setColorBackground(color(255,20,30,255));
         //
        }
    
        public void P7(int theValue) {
         //
         println("[ p7 ]");
          STOP(0);
         cp5.getController("P7").setColorBackground(color(10,200,30,140));
            music = new SoundFile(this, "RoughMix.mp3");
            music.loop();
            isplaying = true;
            if ( isplaying ) { text(" Playing..P7",10,680); }
    
         //
        }
    
        public void P6(int theValue) {
         //
         println("[ p6 ]");
          STOP(0);
         cp5.getController("P6").setColorBackground(color(10,200,30,140));
           music = new SoundFile(this, "Voice 002.m4a");
            music.loop();
             isplaying = true;
            if ( isplaying ) { text(" Playing..P6",10,680); }
         //
        }
    
        public void P5(int theValue) {
         //
         println("[ p5 ]");
          STOP(0);
         cp5.getController("P5").setColorBackground(color(10,200,30,140));
           music = new SoundFile(this, "Voice Outro Long.mp3");
            music.loop();
             isplaying = true;
            if ( isplaying ) { text(" Playing..P5",10,680); }
         //
        }
    
        public void P4(int theValue) {
         //
         println("[ p4 ]");
          STOP(0);
         cp5.getController("P4").setColorBackground(color(10,200,30,140));
           music = new SoundFile(this, "Beef Porterhouse.mp3");
            music.loop();
             isplaying = true;
            if ( isplaying ) { text(" Playing..P4",10,680); }
         //
        }
    
        public void P3(int theValue) {
         //
         println("[ p3 ]");
          STOP(0);
         cp5.getController("P3").setColorBackground(color(10,200,30,140));
           music = new SoundFile(this, "Chicken Breast.mp3");
            music.loop();
             isplaying = true;
            if ( isplaying ) { text(" Playing..P3",10,680); }
        //
        }
    
        public void P2(int theValue) {
         //
         println("[ p2 ]");
          STOP(0);
         cp5.getController("P2").setColorBackground(color(10,200,30,140));
           music = new SoundFile(this, "Chicken Schnitzel.mp3");
            music.loop();
             isplaying = true;
            if ( isplaying ) { text(" Playing..P2",10,680); }
         //
        }
    
        public void P1(int theValue) {
         //
         println("[ p1 ]");
          STOP(0);
         cp5.getController("P1").setColorBackground(color(10,200,30,140));
           music = new SoundFile(this, "Voice Outro Short.mp3");
            music.loop();
             isplaying = true;
            if ( isplaying ) { text(" Playing..P1",10,680); }
         //
        }
    
        public void P0(int theValue) {
         //
         println("[ p0 ]");
          STOP(0);
         cp5.getController("P0").setColorBackground(color(10,200,30,140));
         //
           music = new SoundFile(this, "groove.mp3");
            music.loop();
             isplaying = true;
            if ( isplaying ) { text(" Playing..P0",10,680); }
        //
        }
    
        void alloffbuttons(){
    
          for (int x = 0; x < 8; x++) {
            cp5.getController("P"+x).setColorBackground(color(10,20,30,140));
          }
          cp5.getController("Min5").setColorBackground(color(10,20,130,140));
          cp5.getController("Min15").setColorBackground(color(10,20,130,140));
        }
    
        void allstop() {
           for (int x = 0; x < 8; x++) {
             music.stop();
             cp5.getController("P"+x).setColorBackground(color(10,20,30,140));
          }
           cp5.getController("Min5").setColorBackground(color(10,20,130,140));
           cp5.getController("Min15").setColorBackground(color(10,20,130,140));
        }
     ``
    
  • Tried to rewrite with natvie android mediaplayer to use visualizer functions, but it started to not start and stop playing correctly. Is there a way to get rms or freq data from cassette soundfile?

Sign In or Register to comment.