Minim sequencing play and record functions

edited February 2018 in Library Questions

Hi Folks!

I've been working on a script where in very simple terms I would like a random beep to sound (Audioplayer beep - working!) and after that beep, a sequence of audio tracks to play (currently arranged in the array audio) and eventually audio recordings to be made (not set up yet).

My current issue is that

audio[0].play(); 

is working perfectly but not then playing the second audio track. I've tried setting this up as a separate event (

void playrecord()

) and have found this thread very helpful to get the crux of the code from @GoToLoop: https://forum.processing.org/two/discussion/12966/how-to-play-an-audio-file-sequentially.

Ideally I would like to sequence it as audio 0 play, record audio input 0 through microphone, audio 1 play, record audio input 1 through microphone. All before the next "beep" sound is made.

Can anyone suggest what is going wrong?


import ddf.minim.*;
import ddf.minim.AudioPlayer;
import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress otherSketch;

Minim minim;
AudioPlayer beep;

static final int AUDIO = 2;
final AudioPlayer[] audio = new AudioPlayer [AUDIO];
AudioInput daydream;
AudioRecorder[] recorder = new AudioRecorder [1];

PFont f;
int [] beeps = new int [5];
int ms;
int start = -millis();
int totalBeeps;
int beeptime;
boolean pressEnter;

int current=-1;
int count=0;
 
void setup() {
  size (512, 200, P3D);
  f= createFont ("Georgia", 16);
 
  boolean pressEnter = false;
  totalBeeps = 0;
 
  oscP5 = new OscP5(this,8001); /* start oscP5, listening for incoming messages at port 8001 */
  otherSketch = new NetAddress("xxxxxx",8000); /* Start listening at (IP Address, Port Number) */
  
 
  int fac=1000;
  beeps [0] = int(random(10, 60))*fac;//these numbers aren't right but give an earlier beep!
  beeps [1] = int(random(1260, 1739))*fac;
  beeps [2] = int(random(1860, 2339))*fac;
  beeps [3] = int(random(2460, 2939))*fac;
  beeps [4] = int(random(3060, 3539))*fac;
 
  printArray (beeps);
  
  minim = new Minim(this);
  audio [0] = minim.loadFile ("Audio_01.mp3");
  audio [1] = minim.loadFile ("Audio_02.mp3");
  
  minim = new Minim(this);
  daydream = minim.getLineIn();
 // recorder [0] = minim.createRecorder(daydream, "audio01.mp3");
  
  minim = new Minim(this);
  beep = minim.loadFile ("ping.mp3");
}
 
void keyPressed() { //boolean controlling the start screen.
  if (keyCode == ENTER) { 
    start = millis();
    pressEnter = true;
  }
}
 
void draw () {
 
  background (255);
  textFont (f, 16);
  fill (0);
 
  int ms = millis()-start;
 
  println(ms, start);
  
  startScreen();

  for (int i=0; i beeps[i] && i>current) {
      current=i;
      beeptime=millis();
      beep.rewind();
      beep.play();
      totalBeeps =totalBeeps+1;
      OscMessage myMessage = new OscMessage("time in milliseconds");
      myMessage.add(ms); 
      myMessage.add(millis()); 
      myMessage.add(beeptime); 
      myMessage.add(start); 
      oscP5.send(myMessage, otherSketch);       
playrecord();
    }
  } 
}

void startScreen(){
  
  if (pressEnter)//this boolean controls the start screen and initiates the timer -resetting millis to 0 when ENTER is pressed.
  {
    text("The experiment has begun and these are the random beep times:", 10, 40);
    text(beeps[0], 10, 70);
    text("milliseconds", 80, 70);
    text(beeps[1], 10, 90);
    text("milliseconds", 80, 90);
    text(beeps[2], 10, 110);
    text("milliseconds", 80, 110);
    text(beeps[3], 10, 130);
    text("milliseconds", 80, 130);
    text(beeps[4], 10, 150);
    text("milliseconds", 80, 150);
  } else {
    text("Press Enter to begin", 10, 100);
  }
 
  if (!pressEnter)
    return;
}

void playrecord(){
     audio[0].play();
     if (!audio[count].isPlaying()) audio[count=(count+1)% AUDIO].play(); 
}
Sign In or Register to comment.