Audio issues... Help please!

So, basically I’m creating an Android app in Java, which I want to be able to play audio files (Various simultaneously). They’ll be in the data folder, and are all less than 4 minutes long. I got it all set up with the processing sound library:
image
(plus more obviously)…but then when trying to run on my phone just got errors (It worked perfectly switching out of android mode). So then I tried the Cassete library, which worked, but it doesn’t seem to have the option to individually change sound volumes.
So… anyone have any idea on how I can set this up? (Using 10-20 sound files, of between 1 and 4 minutes, with the ability to play more than one at a time, and the ability to individually change volumes)
I’d really appreciate some help, thanks!!!

What errors are you getting when you run it on your phone?
Where are you declaring the sounds? (if it is outside of a method/setup it wont work)
Can I see a simplified version of your code showing the implementation of sounds?

This is my general implementation of loading sounds, with soundSetup() called in setup()

import processing.sound.*;
SoundFile example;
void soundSetup(){
  example = new SoundFile(this, "audio/example.wav");
}

example would be called anywhere in draw() with example.play();

to change the sound volume’s individually you would do example.volume(float) anywhere after it has been declared, more detail look here

1 Like

Thanks for the reply! Here’s a super simplified version of my code:

import processing.sound.*;
SoundFile[] Sounds = new SoundFile[12];
String[] soundNames = {"Taberna", "Dungeons", "Bosque"};
String[] fileNames = {"Ambience_Tavern.wav", "Ambiance_Dungeon.wav", "Ambience_Forest1.wav"};
int[] music = {2, 3};
boolean musicPlaying[]= new boolean[10];
float volume1=0.5;
PImage backgroundImg;

void setup() {
  //Image setup and stuff in here
}

void draw() {
  image(backgroundImg, 0, 0, width, height);
  if (mousePressed) {
    if (mouseY>height-height/20 && mouseX>width/4 && mouseX<width/4*3) {
      volume1 = map(mouseX, width/4, width/4*3, 0, 1);
      for (int a = 0; a<musicPlaying.length; a++) {
        if (musicPlaying[a]==true)Sounds[music[a]].amp(volume1);
      }
    }
  }
}

void mousePressed() {
  playMusic(music[0], 0);
}

void playMusic(int Soundnum, int Soundpos) {
  if (Sounds[Soundnum]==null) {
    Sounds[Soundnum]= new SoundFile(this, fileNames[Soundnum]);
  }
  if (musicPlaying[Soundpos]) {
    Sounds[Soundnum].stop();
    musicPlaying[Soundpos]=false;
  } else {
    Sounds[Soundnum].loop();
    Sounds[Soundnum].amp(volume1);
    musicPlaying[Soundpos]=true;
  }
}

The error I get is:

Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
org.gradle.tooling.BuildException: Could not execute build using Gradle distribution 'https://services.gradle.org/distributions/gradle-4.3-bin.zip'.
Caused by: com.android.dex.DexException: Multiple dex files define Lfr/delthas/javamp3/Sound;

And the error has a ton more lines, which look like they just say the same things. I’m assuming the error has something to do with processing’s sound library, as it mentions it in the last line.

I thought volume(float) was only for the global volume? Because of that, I’m using example.amp(float) instead…

Thanks for the help!

@F53 After looking into the cassette library it appears it hasn’t been updated for ages, so i guess that’s why there are features missing. If you have any idea about the above I’d really appreciate it! Thanks!

Hi, I am unsure what you are attempting to achieve with the following variables:

SoundFile[] Sounds = new SoundFile[12];
String[] soundNames = {"Taberna", "Dungeons", "Bosque"};
String[] fileNames = {"Ambience_Tavern.wav", "Ambiance_Dungeon.wav", "Ambience_Forest1.wav"};

How are you going about declaring the soundFiles in sounds[], that is kinda what I meant by asking where you were declaring the sounds.

if (Sounds[Soundnum]==null) {
    Sounds[Soundnum]= new SoundFile(this, fileNames[Soundnum]);
}

If the soundFile is null, then I initialise it when pressing play on it. It does therefore have a small delay, but I obviously don’t want to wait for them all to load when starting the app! The soundNames variables are just for displaying instead of a file name.
Thanks for the help @F53 !

In that case, why is your array Sounds 12 in size, when you only have 3 filenames?
Or did you just cut out a few filenames for your code?

@Hubbit200, could you share your full code in a pastebin or something, when I compiled your example code in android I got no errors

@F53 https://pastebin.com/6pJXWGS0 and the error I get: https://pastebin.com/LkX8VXkt
I had just cut a few file names above, just for brevity!
Thanks!

I will compile this tonight and let you know if I get the same error you do.

For now, just to make sure nothing is messed up about your android build: could you try compiling your simplifyed code yourself to see if it causes the same compilation problem we are discussing?
Sorry for not thinking about this idea earlier

Ok, thanks for your help! I tried compiling the simplified version, and it also failed, but when I switched to cassette (taking out the .amp bit of code that isn’t compatible with it) it compiled fine. So I’m thinking it must be a problem with the processing sound library… I’ve also tried re-downloading processing and therefore the sound library, but no difference.
Thanks for your help!

@F53 Did it compile for you in the end? Sorry for the impatience, I just want to make sure i have it working by the 18th, and I like to play it safe!

I completely forgot to do that, on it now

@Hubbit200 Yeah, I got compile errors, I have no experience on the cassette library though, so I can’t really help.

1 Like

@F53 The project I put in Pastebin is using the Processing sound library though… Do you think it’s a problem with that? I’m not going to be able to use the cassette library anyway, as it hasn’t been updated for over 4 years, and is missing a ton of functionality… So I guess my question now is; how can i solve the compile failure? Do I need to change to a different sound library? If so, which would the best one be?
Thanks for all the help!

Without importing the cassette Library the thing compiled fine
I don’t know about any other sound libraries…
What are you using the cassette library for?

@F53 I’m confused… In my code (https://pastebin.com/6pJXWGS0) the cassette library isn’t being imported is it? I commented it out… So without importing the cassette library, just using Processing sound, I got that error. If I switch to cassette, it compiles fine as long as i remove the parts of the code which it doesn’t support.

Hi, I had a recent very similar problem, although not on Android. Multiple sound files, loops, individual start stop, individual volume controls. I also wanted multiple speakers ( USB ) per playing endpoint, and the ability to individually control those as well.

I ended up coding my own daemon on top of PulseAudio, but creating a daemon which would accept REST requests ( which you can do easily from Processing ). Thus, if you look around the included code, you’ll see a system you can use for controlling sound in an art environment from Processing.

Good luck—

1 Like

I managed to solve it like this in the end: Looking through all the lines of the errors I was getting, I found a reference to one of the files in the Processing Sound library folder. So I deleted it, and downloaded it againg form the Github page, and put it in the right place. Now it works fine! I’m assuming there must have been some kind of error or corruption in the Sound library files…
Thank you both for the help!

1 Like