Visualizing audio on Android (Minim-alternative)

edited June 2017 in Android Mode

Hello, I wrote a sketch in which multiple audio files are being visually represented by a waveform in real time. The whole thing was written using Minim, but apparently Minim is not supported on Android.

Is there a way to visualize audio on Android?

I googled around the web, seems like the android-compatible library "APwidgets" is not working in newer processing versions, also I didn't find any solution with "Cassette" so far...

Thanks in advance! :)

Here is the original code using Minim:

import ddf.minim.*;
Minim minim;
AudioPlayer player;
AudioPlayer player2;
AudioPlayer player3;
AudioPlayer player4;
AudioPlayer player5;
AudioPlayer player6;
AudioPlayer player7;
AudioPlayer player8;
AudioPlayer player9;

void setup()
{
  size(1128, 575, P2D);
  minim = new Minim(this); 
  player = minim.loadFile("track1.mp3");
  player2 = minim.loadFile("track2.mp3");
  player3 = minim.loadFile("track3.mp3");
  player4 = minim.loadFile("track4.mp3");
  player5 = minim.loadFile("track5.mp3");
  player6 = minim.loadFile("track6.mp3");
  player7 = minim.loadFile("track7.mp3");
  player8 = minim.loadFile("track8.mp3");
  player9 = minim.loadFile("track9.mp3");
}

void draw()
{
  background(240);
  stroke(150, 100, 40); 

  //WAVEFORMS
  for (int i = 0; i < player.bufferSize() - 1; i++)
  {
    float x1 = map( i, 0, player.bufferSize(), 0, width);
    float x2 = map( i+1, 0, player.bufferSize(), 0, width);
    line( x1, 75 + player.left.get(i)*50, x2, 75 + player.left.get(i+1)*50 );
    line( x1, 100 + player.right.get(i)*50, x2, 75 + player.right.get(i+1)*50 );
  }

  stroke(20, 150, 90); 

  for (int i = 0; i < player2.bufferSize() - 1; i++)
  {
    float x1 = map( i, 0, player2.bufferSize(), 0, width);
    float x2 = map( i+1, 0, player2.bufferSize(), 0, width);
    line( x1, 125 + player2.left.get(i)*50, x2, 125 + player2.left.get(i+1)*50 );
    line( x1, 150 + player2.right.get(i)*50, x2, 125 + player2.right.get(i+1)*50 );
  }

  stroke(0, 70, 130); 

  for (int i = 0; i < player3.bufferSize() - 1; i++)
  {
    float x1 = map( i, 0, player3.bufferSize(), 0, width );
    float x2 = map( i+1, 0, player3.bufferSize(), 0, width );
    line( x1, 175 + player3.left.get(i)*50, x2, 175 + player3.left.get(i+1)*50 );
    line( x1, 200 + player3.right.get(i)*50, x2, 175 + player3.right.get(i+1)*50 );
  }

  stroke(80, 70, 130); 

  for (int i = 0; i < player4.bufferSize() - 1; i++)
  {
    float x1 = map( i, 0, player4.bufferSize(), 0, width);
    float x2 = map( i+1, 0, player4.bufferSize(), 0, width );
    line( x1, 225 + player4.left.get(i)*50, x2, 225 + player4.left.get(i+1)*50 );
    line( x1, 250 + player4.right.get(i)*50, x2, 225 + player4.right.get(i+1)*50 );
  }

  stroke(#9CC6A1); 

  for (int i = 0; i < player5.bufferSize() - 1; i++)
  {
    float x1 = map( i, 0, player5.bufferSize(), 0, width );
    float x2 = map( i+1, 0, player5.bufferSize(), 0, width );
    line( x1, 275 + player5.left.get(i)*50, x2, 275 + player5.left.get(i+1)*50 );
    line( x1, 300 + player5.right.get(i)*50, x2, 275 + player5.right.get(i+1)*50 );
  }


  stroke(#FA8A56); 

  for (int i = 0; i < player6.bufferSize() - 1; i++)
  {
    float x1 = map( i, 0, player6.bufferSize(), 0, width);
    float x2 = map( i+1, 0, player6.bufferSize(), 0, width );
    line( x1, 325 + player6.left.get(i)*50, x2, 325 + player6.left.get(i+1)*50 );
    line( x1, 350 + player6.right.get(i)*50, x2, 325 + player6.right.get(i+1)*50 );
  }

  stroke(#1ACFFF);

  for (int i = 0; i < player7.bufferSize() - 1; i++)
  {
    float x1 = map( i, 0, player7.bufferSize(), 0, width );
    float x2 = map( i+1, 0, player7.bufferSize(), 0, width );
    line( x1, 375 + player7.left.get(i)*50, x2, 375 + player7.left.get(i+1)*50 );
    line( x1, 400 + player7.right.get(i)*50, x2, 375 + player7.right.get(i+1)*50 );
  }

  stroke(#D567DE); 

  for (int i = 0; i < player8.bufferSize() - 1; i++)
  {
    float x1 = map( i, 0, player8.bufferSize(), 0, width );
    float x2 = map( i+1, 0, player8.bufferSize(), 0, width );
    line( x1, 425 + player8.left.get(i)*50, x2, 425 + player8.left.get(i+1)*50 );
    line( x1, 450 + player8.right.get(i)*50, x2, 425 + player8.right.get(i+1)*50 );
  }

  stroke(#5A555A);

  for (int i = 0; i < player9.bufferSize() - 1; i++)
  {
    float x1 = map( i, 0, player9.bufferSize(), 0, width);
    float x2 = map( i+1, 0, player9.bufferSize(), 0, width );
    line( x1, 475 + player9.left.get(i)*50, x2, 475 + player9.left.get(i+1)*50 );
    line( x1, 500 + player9.right.get(i)*50, x2, 475 + player9.right.get(i+1)*50 );
  }
}

void keyPressed()
{

    player.rewind();
    player.play();
    player2.rewind();
    player2.play();
    player3.rewind();
    player3.play();
    player4.rewind();
    player4.play();
    player5.rewind();
    player5.play();
    player6.rewind();
    player6.play();
    player7.rewind();
    player7.play();
    player8.rewind();
    player8.play();
    player9.rewind();
    player9.play();
}
Sign In or Register to comment.