No sound in exported java with Beads

Hi,

I have been using the Beads library in my sketches in MacOS Mojave and Windows 10 with Processing 3.5.3. Everything works fine until I export the sketch to a Java applet. The Java applet no longer has audio ouput. In the particular example I’m working with the audio is played using the SamplePlayer object. Has anyone had issues with this?

Regards,
Phillip

1 Like

on
win 7 / 64bit/
processing 3.5.3
install lib BEADS
run example

Lesson04_SamplePlayer

save as own project
export
start /Lesson04_SamplePlayer\application.windows64\Lesson04_SamplePlayer.exe
OK

1 Like

Hmm,

I exported all the sampler examples and still no audio. I’m wondering if Windows 10 is the issue. I’ll test this on a Windows 7 machine later.

Thanks for the suggestion.

pls confirm that for export, you were using “embed JAVA”

1 Like

Yes, I was using the Embed Java. I tried playing the exported app on Windows 7 and still no sound.

ok, no good idea,

well you might first confirm that there is nothing special about your code,
by running/testing that mentioned example ONLY,

oh and verify that the sketch running in the IDE produce sound !!!
( only the exported not ? ) hmmm

There’s no issue playing sound in the IDE. Exported code that has uses the WavePlayer object class have sound when exported, but not my code that uses the SamplePlayer object class. It may be how I’m loading the audio files. I will have to test a different method of constructing the path perhaps. In my setup block I have this code to load the sample file names into an array from a directory:

// this block of code counts the number of samples in the /DrumMachince subfolder
  File folder = new File(sketchPath("") + "DrumMachine/");
  File[] listOfFiles = folder.listFiles();
  for (int i = 0; i < listOfFiles.length; i++)
  {
    if (listOfFiles[i].isFile())
    {
      if (listOfFiles[i].getName().endsWith(".wav"))
      {
        numSamples++;
      }
    }
  }
  
  // if no samples are found, then end
  if (numSamples <= 0)
  {
    println("no samples found in " + sketchPath("") + "DrumMachine/");
    println("exiting...");
    exit();
  }
  
  // this block of code reads and stores the filename for each sample
  sampleSourceFile = new String[numSamples];
  int count = 0;
  for (int i = 0; i < listOfFiles.length; i++)
  {
    if (listOfFiles[i].isFile())
    {
      if (listOfFiles[i].getName().endsWith(".wav"))
      {
        sampleSourceFile[count] = listOfFiles[i].getName();
        //println(sampleSourceFile[count]);
        count++;
      }
    }
  }

This is the class I am using to load the sample files.

  // Connstructor for the MusicPlayer
  MusicPlayer(String tempSourceFile)
  {
    //sourceFile = sketchPath("") + "DrumMachine/Snaredrum 1.wav";
    sourceFile = tempSourceFile;
    
    try {
      // initialize SamplePlayer, loading the file indicated by the sourceFile string
      sp = new SamplePlayer(ac, new Sample(sketchPath("") + "DrumMachine/" + sourceFile));
    }
    catch(Exception e)
    {
      println("Exception while attempting to load sample!");
      e.printStackTrace();
      exit();
    }
   
    
    sp.setKillOnEnd(false);
  
    gainValue = new Glide(ac, 0.0, 20);
    g = new Gain(ac, 1, gainValue);
    g.addInput(sp);
    
    ac.out.addInput(g);
    ac.start();
    
  } // end of constructor MusicPlayer()
  
  void play()
  {
    gainValue.setValue(20);
    sp.setToLoopStart();
    sp.start();
    delay(125);
  }
  
} // end of class MusicPlayer

I then construct the object with this within the draw block:

myMusicPlayer = new MusicPlayer(sampleSourceFile[int(note)]);
    myMusicPlayer.play();
int(note)

is a variable to index the array of sample file names.

1 Like

sorry,
you test sound from IDE run / good but what code?

  • your code
  • the example

you not answer the question if the export of that BEADS example
produce sound ( on any of your computers ).

-a- above i show that it works here from WIN7
-b- just now do same procedure from Raspian OS, also works

1 Like

Actually, both the example code and my code play audio fine in the IDE, but when I export to Java in MacOS and Windows 7 and 10 both code samples don’t play. In fact, it never seems to complete the draw block as I have other graphic elements in my code that is synchronized with the sampler. Anyhow, I am going to test it on my Raspberry Pi to see if it works in Linux.

-a- pls lets put your code aside ( i understand that you already doubt it,
but also that makes no sense, as long the
Lesson04_SamplePlayer.pde export not even run
( not open the canvas or not open the file manager?)

-b- now i must doubt your procedure:
i described in detail how i did it, try again:
-1- load and run example
-2- save as an own project
( for better identification i called it here BEADS_Lesson04_SamplePlayer )
-3- export ( with embed JAVA enabled )
-4- automatically get the file explorer open that directory
-5- double click on the path like
/application.windows64/
-6- double click on BEADS_Lesson04_SamplePlayer.exe
-7- the canvas show and is then behind
the file open menu
-8- walk to a sound file ( i use untitled.mp3 from the minim examples ) and double click it
-9- the file manager closes and the canvas show
make sound and show graph.
( and just play the song one time, so it should not be a too short one )
-10- now song finished and still see the canvas, but can not do anything as close it.


i repeat that it works here on Win7 && Raspbian

1 Like

Ah, I misunderstood which Beads example sample player to test. I was looking in the beads library folder for the example sample player. It’s the one where I specify the file interactively. Okay, that one works as an exported Java app in Windows and Raspian.

So, I can rule out any issues with the operating system sound subsystem. Thus it looks like it is a problem within my code. I suspect it has something to do with the way the path to the sample files is coded. But it seems the try and catch method is not executing if that is the case, so perhaps that is not it. I will need to re-think how the samples are loaded into the program.

1 Like

Great walkthrough of a debugging test, @kll. Thanks for all you do on the forum.

@Peachy – glad you are narrowing the problem down. If you need to check a path or file, keep in mind .exists() on File objects, and that all Processing API load functions return null if the path is not found:

1 Like

I’m not sure it’s a file loading problem. I made other sketches with the Sound library and a simple SinOsc, TriOsc and none of them produced sound when exported. In each case the draw window just freezes at a grey screen. Would installing a Java SDK help? I only have the JRE installed in each OS.

probably not, if you are using the embed java feature on export. You can have you sketch print its java version / location to test – it is almost certainly using the java you embedded…