# Audio issues... Help please!

**URL:** <https://discourse.processing.org/t/audio-issues-help-please/14402>\
**Category:** Processing for Android\
**Created:** [October 3, 2019, 6:59pm UTC](https://discourse.processing.org/t/audio-issues-help-please/14402 "2019-10-03T18:59:26Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hubbit200](https://avatars.discourse-cdn.com/v4/letter/h/ecb155/32.png) [@Hubbit200](https://discourse.processing.org/u/Hubbit200)\
**Post date:** [October 3, 2019, 6:59pm UTC](https://discourse.processing.org/t/audio-issues-help-please/14402/1 "2019-10-03T18:59:26Z")

</div>

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](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/0825f11308083f764237d5dca42793a56903928a.png)  
(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!!!

---

<div class="post-metadata">

**Author:** ![F53](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/f53/32/7118_2.png) [@F53](https://discourse.processing.org/u/F53)\
**Post date:** [October 4, 2019, 3:06am UTC](https://discourse.processing.org/t/audio-issues-help-please/14402/2 "2019-10-04T03:06:08Z")

</div>

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()`

```auto
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](https://processing.org/reference/libraries/sound/Sound_volume_.html)

---

<div class="post-metadata">

**Author:** ![Hubbit200](https://avatars.discourse-cdn.com/v4/letter/h/ecb155/32.png) [@Hubbit200](https://discourse.processing.org/u/Hubbit200)\
**Post date:** [October 4, 2019, 5:34am UTC](https://discourse.processing.org/t/audio-issues-help-please/14402/3 "2019-10-04T05:34:02Z")

</div>

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

```auto
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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![Hubbit200](https://avatars.discourse-cdn.com/v4/letter/h/ecb155/32.png) [@Hubbit200](https://discourse.processing.org/u/Hubbit200)\
**Post date:** [October 7, 2019, 6:05pm UTC](https://discourse.processing.org/t/audio-issues-help-please/14402/4 "2019-10-07T18:05:41Z")

</div>

@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!

---

<div class="post-metadata">

**Author:** ![F53](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/f53/32/7118_2.png) [@F53](https://discourse.processing.org/u/F53)\
**Post date:** [October 7, 2019, 8:08pm UTC](https://discourse.processing.org/t/audio-issues-help-please/14402/5 "2019-10-07T20:08:01Z")

</div>

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

```auto
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 `soundFile`s in `sounds[]`, that is kinda what I meant by asking where you were declaring the sounds.

---

<div class="post-metadata">

**Author:** ![Hubbit200](https://avatars.discourse-cdn.com/v4/letter/h/ecb155/32.png) [@Hubbit200](https://discourse.processing.org/u/Hubbit200)\
**Post date:** [October 7, 2019, 11:04pm UTC](https://discourse.processing.org/t/audio-issues-help-please/14402/6 "2019-10-07T23:04:27Z")

</div>

```auto
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 !

---

<div class="post-metadata">

**Author:** ![F53](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/f53/32/7118_2.png) [@F53](https://discourse.processing.org/u/F53)\
**Post date:** [October 7, 2019, 11:21pm UTC](https://discourse.processing.org/t/audio-issues-help-please/14402/7 "2019-10-07T23:21:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![F53](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/f53/32/7118_2.png) [@F53](https://discourse.processing.org/u/F53)\
**Post date:** [October 8, 2019, 2:12am UTC](https://discourse.processing.org/t/audio-issues-help-please/14402/8 "2019-10-08T02:12:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Hubbit200](https://avatars.discourse-cdn.com/v4/letter/h/ecb155/32.png) [@Hubbit200](https://discourse.processing.org/u/Hubbit200)\
**Post date:** [October 8, 2019, 5:38am UTC](https://discourse.processing.org/t/audio-issues-help-please/14402/9 "2019-10-08T05:38:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![F53](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/f53/32/7118_2.png) [@F53](https://discourse.processing.org/u/F53)\
**Post date:** [October 8, 2019, 3:27pm UTC](https://discourse.processing.org/t/audio-issues-help-please/14402/10 "2019-10-08T15:27:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Hubbit200](https://avatars.discourse-cdn.com/v4/letter/h/ecb155/32.png) [@Hubbit200](https://discourse.processing.org/u/Hubbit200)\
**Post date:** [October 8, 2019, 5:02pm UTC](https://discourse.processing.org/t/audio-issues-help-please/14402/11 "2019-10-08T17:02:23Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Hubbit200](https://avatars.discourse-cdn.com/v4/letter/h/ecb155/32.png) [@Hubbit200](https://discourse.processing.org/u/Hubbit200)\
**Post date:** [October 9, 2019, 7:22pm UTC](https://discourse.processing.org/t/audio-issues-help-please/14402/12 "2019-10-09T19:22:38Z")

</div>

@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!

---

<div class="post-metadata">

**Author:** ![F53](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/f53/32/7118_2.png) [@F53](https://discourse.processing.org/u/F53)\
**Post date:** [October 9, 2019, 8:45pm UTC](https://discourse.processing.org/t/audio-issues-help-please/14402/13 "2019-10-09T20:45:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Hubbit200](https://avatars.discourse-cdn.com/v4/letter/h/ecb155/32.png) [@Hubbit200](https://discourse.processing.org/u/Hubbit200)\
**Post date:** [October 9, 2019, 9:01pm UTC](https://discourse.processing.org/t/audio-issues-help-please/14402/14 "2019-10-09T21:01:34Z")

</div>

@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!

---

<div class="post-metadata">

**Author:** ![F53](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/f53/32/7118_2.png) [@F53](https://discourse.processing.org/u/F53)\
**Post date:** [October 9, 2019, 9:04pm UTC](https://discourse.processing.org/t/audio-issues-help-please/14402/15 "2019-10-09T21:04:56Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Hubbit200](https://avatars.discourse-cdn.com/v4/letter/h/ecb155/32.png) [@Hubbit200](https://discourse.processing.org/u/Hubbit200)\
**Post date:** [October 9, 2019, 9:13pm UTC](https://discourse.processing.org/t/audio-issues-help-please/14402/16 "2019-10-09T21:13:13Z")

</div>

@F53 I’m confused… In my code ([https://pastebin.com/6pJXWGS0](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.

---

<div class="post-metadata">

**Author:** ![bbulkow](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bbulkow/32/635_2.png) [@bbulkow](https://discourse.processing.org/u/bbulkow)\
**Post date:** [October 10, 2019, 10:37pm UTC](https://discourse.processing.org/t/audio-issues-help-please/14402/17 "2019-10-10T22:37:00Z")

</div>

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—

> **[FlamingLotusGirls/Serenity](https://github.com/FlamingLotusGirls/Serenity/tree/master/sound/SerenityAudio)**
>
> Things related to our flaming fireflies. Contribute to FlamingLotusGirls/Serenity development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![Hubbit200](https://avatars.discourse-cdn.com/v4/letter/h/ecb155/32.png) [@Hubbit200](https://discourse.processing.org/u/Hubbit200)\
**Post date:** [October 12, 2019, 4:29pm UTC](https://discourse.processing.org/t/audio-issues-help-please/14402/18 "2019-10-12T16:29:35Z")

</div>

**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!
