Minim on Raspberry Pi loadFile problems

Hey everyone,
I’m having some problems loading files using the Minim library on a Raspberry Pi.

If I comment out the loading of any one file, and the call of the associated function “playFile()” in the “draw()” loop, the program will run fine, so i know it’s not a typo in the file name or anything.

The audio files are all mp3s that are 6 seconds or less with the largest file being 96kb. Are these files too large? I made a quick mockup using AudioSample instead of AudioPlayer, and the files loaded, but for my purposes, I liked the functions associated with the AudioPlayer better.

Here’s the error I’m getting:

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

=== Minim Error ===
=== Couldn't load the file SpadeFootLoop.mp3

And here’s my 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;
AudioPlayer playerBullfrog;
AudioPlayer playerLeopardFrog;
AudioPlayer playerNarrowMouth;
AudioPlayer playerSpadeFoot;

boolean bullfrogState = false;
boolean leopardFrogState = false;
boolean narrowMouthState = false;
boolean spadeFootState = false;

void setup()
{
  minim = new Minim(this);
  
  //load sounds
  playerBullfrog = minim.loadFile("BullfrogLoop.mp3");
  playerLeopardFrog = minim.loadFile("LeopardFrogLoop.mp3");
  playerNarrowMouth = minim.loadFile("NarrowMouthLoop.mp3");
  playerSpadeFoot = minim.loadFile("SpadeFootLoop.mp3");
}

void draw()
{
  playFile(playerBullfrog, bullfrogState);
  playFile(playerLeopardFrog, leopardFrogState);
  playFile(playerNarrowMouth, narrowMouthState);
  playFile(playerSpadeFoot, spadeFootState);   
}

void keyPressed()
{
  if (keyPressed == true)
    {
       if(key == 'q' || key == 'Q')
       {
          bullfrogState = true;
          println(bullfrogState);
       }
       else if(key == 'w' || key == 'W')
       {
          leopardFrogState = true; 
          println(leopardFrogState);
       }
       else if(key == 'e' || key == 'E')
       {
          narrowMouthState = true; 
          println(narrowMouthState);
       }
       else if(key == 'r' || key == 'R')
       {
          spadeFootState = true;
          println(spadeFootState);
       }
    }  
}

void keyReleased()
{
    if(key == 'q' || key == 'Q')
       {
          bullfrogState = false; 
          println(bullfrogState);
       }
       else if(key == 'w' || key == 'W')
       {
          leopardFrogState = false; 
          println(leopardFrogState);
       }
       else if(key == 'e' || key == 'E')
       {
          narrowMouthState = false; 
          println(narrowMouthState);
       }
       else if(key == 'r' || key == 'R')
       {
          spadeFootState = false; 
          println(spadeFootState);
       }
}

void playFile(AudioPlayer myPlayer, Boolean myState)
{
    if(myState == true)
    {
        if(myPlayer.isLooping() != true)
        {
            myPlayer.loop();
        }
    }
    else
    {
        myPlayer.play();
        myPlayer.pause();
        myPlayer.rewind();
    }
}

Any thoughts on what my problems are? Should I be using a different approach?
Thanks

1 Like

Based in the error you have shown, the problem is the last file you are loading. I suggest you run the sketch attempting to load only that file and see if the error persist. If it is that file, I can only think on regenerating that file if possible, or replacing it with another file.

Just for curiosity and for documenting this problem: If the problem is this single file, do you see the problem running this file in Processing Java?

Kf

Thanks for the reply.

The file, will run if I comment out the loading of one of the sound files and it’s associated “playFile()” call in the “draw()” loop. If I comment out the first file load for instance, the last one will load and play, so i’m pretty sure it is not a problem with the file specifically. It just seems to not like to load all four. I was just wondering if it was a memory limit or something on the Pi. I really didn’t think the files were too big or anything, but I don’t really know the limits of this hardware.

The file runs fine on a PC, but I was hoping to use some of the interface options on the Pi (GPIO), and not require an entire PC to run a simple soundboard mockup for a museum interactive.

Of note, the files will all load correctly when I modified the file to load them as AudioSamples, but I liked the control options for AudioPlayers better.

I see. Would you be paying the files at the same time? Maybe you could load only one at a time, when required.

Kf

When I searched your error string…

I found this Minim issue – possibly relevant?:

Yeah,
I was hoping to make them available to play simultaneously, but I guess if I made them load as called, that might work. I just don’t want it to crash because the fourth sound is played.

Debug questions – I think you have answered these, but just to be sure:

  • If you load / play the fourth file first, do you still get the same error about that file, or does the new last file (e.g. NarrowMouthLoop) become the error file?
  • Is one larger than the others, and do they all have the same format?

If this is a resource issue – and it sounds like it is – then it may be that this is exactly what AudioSampler is designed to deal with – memory efficient multiple simultaneous access to short sound clips. I hope that you are able to get it working with AudioPlayer, but that might turn out to be the best path.

Another option – move your Raspberry PI platform to hardware with more RAM. In testing, does that solve the problem?

Thanks for your replies.

I’ve been exploring some of the solutions presented in your previous reply, specifically using “FilePlayer” instead of “AudioPlayer”, and have been trying to figure out the ins and outs of connecting that up with my current code, but have so far had unrelated errors, so no idea yet if the files have all loaded.

As far as these questions go:

  1. I haven’t tried changing the load order, but just commenting out the first file loaded to see if there’s a problem with the path, file name, or file type specifically. I can take out any one and the other three will load fine. Do you think the order could matter?

  2. They are all mp3s that I exported from Adobe Media Encoder with the same settings. I think that all but one of them started as mp3s. Surprisingly the one that started out as a wav file seems smaller than the others. The largest one is about 96kb. They are short sound clips (less than 6 seconds long).

I created a version that uses AudioSampler and all the files will load, but I think that I am getting multiple triggers because of the way the player was set up to respond to key press and release events. The sound has a weird reverby thing going on which I’m assuming has to do with the number of times the file is quickly triggered before I can let up my finger in even a short press. Ultimately, I wanted to be able to have the sound trigger for as long as the button is pressed. I thought the looping would help make the audio files smaller, but apparently not small enough. I haven’t had a chance to wrap my head around achieving this with the AudioSampler yet.

I built this originally on a Windows PC desktop, and it didn’t have any problems. I was hoping to use the Pi so that I could use the GPIO pins and also not need a dedicated PC for what I thought would be a simple soundboard application.

Thanks for any more suggestions you might have. I’ll let you know if I get any results with the FilePlayer route.

I just realized that you have been talking about AudioSample – not the Ugens Sampler class, which is more recent and generally recommended:

We now recommend using Sampler class from the ugens package because it is more full-featured than AudioSample .

Based on your described use case, it sounds like you want a sample to start looping on keydown and stop on keyup. This is a problem because AudioSample does not have a loop behavior. Is my understanding correct?

Sampler, however, does have a loop behavior. Have you tried seeing if this resolves your memory problems on the PI?

1 Like

Based on your described use case, it sounds like you want a sample to start looping on keydown and stop on keyup. This is a problem because AudioSample does not have a loop behavior. Is my understanding correct?

This is correct.

Sampler, however, does have a loop behavior. Have you tried seeing if this resolves your memory problems on the PI?

I have not tried this yet. I’ll give it a whirl.

Thanks

Well, this seems to work better for me. The sounds all load and sound fine when I set maxVoices to 1. I just need to figure out how to make it trigger when and how I want.

Thanks so much for the direction.