Minim On RPI FilePlayer only can load 6 wav files


#1

I’m writing code for an arcade game which involves taking in sensor input and playing sound during certain stages of the game. I’m using the Minim library to handle all of the sound. I’ve run into an issue when trying to use more than 6 audio clips.

I started by creating FilePlayer instances for each of my sound files. There are 8 in total. It seems all is fine when I call 6 instances of loadFileSream(), but on the 7th, I get this error:

=== =JavaSound Minim Error ====
==== Unable to return a SourceDataLine: unsupported format - PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian

Things I’ve tried:
-Tested code on Windows machine. Code works fine with all 8 sound files.

  • Googled error and found solutions for Ubuntu, not Raspbian
  • I’ve tripled checked all the sound files to make sure they are in the correct format. I imported all sound clips into Audacity via raw data and exported making sure all settings were what Minim is expecting.
  • For the 7th instance of loadFileStream(), I tried using the same sound file as the 1st. Still get error.
  • I tried putting all sound files into an FilePlayer array. Get error when I try to fill the 7th element of this array.
  • AudioPlayer gets an error after the 3rd call of loadFile().

All of this makes me think it has to do with how the Raspberry Pi handles sound files. I’ve read about moving of files around inside the JavaSound folders, but again, that was for Ubuntu. Raspbian does not seem to have the same files/folders.

What I did as a work around is to call loadFileStream(), setup the patch out, play the file then close the file only where I need the sound to play. It works but I’m curious to know why I need to do this on the RPi. Below are the sketches for the first try and the working code.

Code which gives error:

import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;

Minim minim = new Minim(this);
AudioOutput out;
FilePlayer file1;
FilePlayer file2;
FilePlayer file3;
FilePlayer file4;
FilePlayer file5;
FilePlayer file6;
FilePlayer file7;
FilePlayer file8;

//For the wav files, I used the groove.mp3 from the AudioPlayer example
//I converted it to wav using Audacity
String file1String = "file1.wav";
String file2String = "file2.wav";
String file3String = "file3.wav";
String file4String = "file4.wav";
String file5String = "file5.wav";
String file6String = "file6.wav";
String file7String = "file7.wav";
String file8String = "file8.wav";



void setup() {
  size(400, 200);

  file1 = new FilePlayer(minim.loadFileStream(file1String));
  file2 = new FilePlayer(minim.loadFileStream(file2String));
  file3 = new FilePlayer(minim.loadFileStream(file3String));
  file4 = new FilePlayer(minim.loadFileStream(file4String));
  file5 = new FilePlayer(minim.loadFileStream(file5String));
  file6 = new FilePlayer(minim.loadFileStream(file6String));  
  file7 = new FilePlayer(minim.loadFileStream(file7String));
  file8 = new FilePlayer(minim.loadFileStream(file8String));

  out = minim.getLineOut();

  file1.patch(out);
  file2.patch(out); 
  file3.patch(out);     
  file4.patch(out);
  file5.patch(out);
  file6.patch(out);
  file7.patch(out);
  file8.patch(out);
}

void draw() {
//Nothing here because the sketch wouldn't get past setup().
}

Working code:


import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;

Minim minim = new Minim(this);
AudioOutput out;
FilePlayer file1;
FilePlayer file2;
FilePlayer file3;
FilePlayer file4;
FilePlayer file5;
FilePlayer file6;
FilePlayer file7;
FilePlayer file8;

String file1String = "file1.wav";
String file2String = "file2.wav";
String file3String = "file3.wav";
String file4String = "file4.wav";
String file5String = "file5.wav";
String file6String = "file6.wav";
String file7String = "file7.wav";
String file8String = "file8.wav";

void setup() {
  size(400, 200);
  out = minim.getLineOut();
}

int gameState = 0;
int currentTime = 0;
int previousTime = 0;
int interval = 10000;

void draw() {

  background(255);  
  currentTime = millis();

  if (currentTime - previousTime > interval) {

    previousTime = currentTime;
    gameState+=1; 
    if (gameState == 1) {
      println("STATE 1");
      file1 = new FilePlayer(minim.loadFileStream(file1String));
      file1.patch(out);
      file1.play();
    } else if ( gameState == 2) {
      println("STATE 2");
      file2 = new FilePlayer(minim.loadFileStream(file2String));
      file2.patch(out);
      file1.pause();
      file1.close();
      file2.play();
    } else if ( gameState == 3) {
      println("STATE 3");
      file3 = new FilePlayer(minim.loadFileStream(file3String));
      file3.patch(out);
      file2.pause();
      file2.close();
      file3.play();
    } else if ( gameState == 4) {
      println("STATE 4");
      file4 = new FilePlayer(minim.loadFileStream(file4String));
      file4.patch(out);
      file3.pause();
      file3.close();
      file4.play();
    } else if ( gameState ==5) {
      println("STATE 5");
      file5 = new FilePlayer(minim.loadFileStream(file5String));
      file5.patch(out);
      file4.pause();
      file4.close();
      file5.play();
    } else if ( gameState == 6) {
      println("STATE 6");
      file6 = new FilePlayer(minim.loadFileStream(file6String)); 
      file6.patch(out);
      file5.pause();
      file5.close();
      file6.play();
    } else if ( gameState ==7) {
      println("STATE 7");
      file7 = new FilePlayer(minim.loadFileStream(file7String));
      file7.patch(out);
      file6.pause();
      file6.close();
      file7.play();
    } else if ( gameState == 8) {
      println("STATE 8");
      file8 = new FilePlayer(minim.loadFileStream(file8String)); 
      file8.patch(out);
      file7.pause();
      file7.close();
      file8.play();
    } else if ( gameState >= 9) {
      println("RESET STATE");
      gameState = 0;
      file8.pause();
      file8.close();
    }
  }
}

Thanks for reading.  I'm going to post this on the Minim Gitub as well.  


#2

i try also, confirm
RPI 3B+ Raspbian
Processing 3.5.3
Minim 2.2.2

6 file ok, 7 file get this error:

try:


#3

Yup. I was getting the same thing. Are you recommending using Processing 2? Or are you saying to go to the old forum page?


#4

no, could test the sampler minim method from @Grumpy_Mike

/* Sampler method  */
 
import ddf.minim.*;
import ddf.minim.ugens.*;
 
Minim minim;
AudioOutput out;
Sampler [] note = new Sampler[9];
 
void setup()
{
  size(512, 200);
  minim = new Minim(this);
  out   = minim.getLineOut();
  for(int i=0;i<9;i++){
  note[i] = new Sampler( "groove"+str(i)+".mp3", 4, minim );
  note[i].patch( out );
  }
}
 
void draw() {  }
 
void keyPressed()
{
  if(key >= '0' && key <'9'){
    int s = 0xf & int(key);
    note[s].trigger();
  }
}

note: if you press a key from 0 … 8
that song will be started but
! this will not stop the already playing songs!
try
note[i] = new Sampler( “groove”+str(i)+".mp3", 1, minim );

and i note that there is a big delay at start, so possibly it is NOT a preloading??


#5

Ah I see. OK. The delay would be an issue. The timing of the sounds is very important as it works with the flow of the game. A break would be noticeable and take away from the experience.

I’m more curious as to why the issue exists. I found by loading the sound when I want to play it then closing it when I’m finished works well enough but I guess I’m just being picky about wanting cleaner code. Also, 6 seems to be an arbitrary number. Why only 6 sound clips and not a power of 2 like 8 or 16?

Thanks for the comments though.


#6

well in the old forum was it reported for Raspberry Pi too,
but for 5 ( short ) files already.
anyhow
report it at


but find a way around it for now,
looks like they blame JavaSound for it so it might not be solved at this java version.


#7

Will do. Thanks for the help.