# Sound library no longer works?

**URL:** <https://discourse.processing.org/t/sound-library-no-longer-works/25110>\
**Category:** Processing for Android\
**Created:** [November 1, 2020, 10:25am UTC](https://discourse.processing.org/t/sound-library-no-longer-works/25110 "2020-11-01T10:25:50Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Electronix](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@Electronix](https://discourse.processing.org/u/Electronix)\
**Post date:** [November 1, 2020, 10:25am UTC](https://discourse.processing.org/t/sound-library-no-longer-works/25110/1 "2020-11-01T10:25:50Z")

</div>

Hi everyone,  
I’m looking for a soundlibrary to use in Android mode.  
I use usually Minim library in Java mode but Minim don’t work in Android mode.  
So I would like to use the Sound library because It looks like Sound works with android.  
To begin with Sound I first tried examples provided with the Sound library like “AudioWaveform” and others in the Java mode but without success.  
Here is the error message when I try to run the sketch.

```auto
oct. 29, 2020 1:19:59 PM com.jsyn.devices.javasound.JavaSoundAudioDevice <init>
INFOS: JSyn: default output latency set to 80 msec for Windows 7
javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
	at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(DirectAudioDevice.java:513)
	at com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:121)
	at com.jsyn.devices.javasound.JavaSoundAudioDevice$JavaSoundInputStream.start(Unknown Source)
	at com.jsyn.engine.SynthesisEngine$EngineThread.run(Unknown Source)
java.lang.NullPointerException
	at com.jsyn.devices.javasound.JavaSoundAudioDevice$JavaSoundInputStream.read(Unknown Source)
	at com.jsyn.devices.javasound.JavaSoundAudioDevice$JavaSoundInputStream.read(Unknown Source)
	at com.jsyn.engine.SynthesisEngine$EngineThread.run(Unknown Source)
java.lang.RuntimeException: AudioInput stop attempted when no line created.
	at com.jsyn.devices.javasound.JavaSoundAudioDevice$JavaSoundInputStream.stop(Unknown Source)
	at com.jsyn.engine.SynthesisEngine$EngineThread.run(Unknown Source)

```

And this only with sketches written with the Sound library!  
Sketches written with the Minim or Bead libs works fine.  
I have tried with Java7 : it’s the same.  
I don’t understand what append.  
I’am on Windows7pro, Processing 3.5.4 and Java8.  
Can anyone help me?

Thanks in advance for your replies.

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [November 1, 2020, 8:39pm UTC](https://discourse.processing.org/t/sound-library-no-longer-works/25110/2 "2020-11-01T20:39:42Z")

</div>

Hi @Electronix  
I usually use the [cassete library](https://github.com/shlomihod/cassette) especially made for Android.  
But you can also add a few lines of native code to play a sound file in the data folder.  
More codes [here](https://github.com/EmmanuelPil/Android-java-code-utilities-widgets-for-Processing-for-Android).

```auto
import android.media.MediaPlayer;
import android.content.res.Resources;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.content.Context;
import android.app.Activity;
 
MediaPlayer player = new MediaPlayer();
AssetFileDescriptor fd;
Context context;
Activity activity;
String sound_file_name = "Over_the_horizon.mp3";

void setup() {
  fullScreen();
  background(0, 0, 200);
  orientation(PORTRAIT);
  textSize(60);
  textAlign(CENTER, CENTER);
  activity = this.getActivity();
  context = activity.getApplicationContext();
  try {
    fd = context.getAssets().openFd(sound_file_name);
    player.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
  }
  catch (IOException e) {
    e.printStackTrace();
  }
  text("Press to start", width/2, height/2);
}

void draw() {
}

void mousePressed() {
  try {
    player.prepare();
    player.start();
  }
  catch (Exception e) {
    e.printStackTrace();
  }
}

void onPause() {
  super.onPause();
  if (player!=null) {
    player.release();
    player= null;
  }
}

void onStop() {
  super.onStop();
  if (player!=null) {
    player.release();
    player= null;
  }
}

void onDestroy() {
  super.onDestroy();
  if (player!=null) {
    player.release();
    player= null;
  }
}

```

---

<div class="post-metadata">

**Author:** ![Electronix](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@Electronix](https://discourse.processing.org/u/Electronix)\
**Post date:** [November 2, 2020, 8:10am UTC](https://discourse.processing.org/t/sound-library-no-longer-works/25110/3 "2020-11-02T08:10:37Z")

</div>

Hi @noel  
Thanks for your reply.  
Cassette library is for playing a sound.  
I look for a library to make sounds with functions to control oscillators, envelopes,etc. Therefore cassette lib is not suitable for this.

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [November 2, 2020, 11:25am UTC](https://discourse.processing.org/t/sound-library-no-longer-works/25110/4 "2020-11-02T11:25:53Z")

</div>

> [@Electronix](#):
>
> I look for a library to make sounds with functions to control oscillators, envelopes,etc.

I never saw a working example of these working on Android. Even playing a simple sound file with this library on Android has many issues on the forums. I’ve spent quite some hours now, to get the FFT and waveform data byte array with the [Visualizer class](https://developer.android.com/reference/android/media/audiofx/Visualizer.html), but I still battle with a bunch of errors. I also had a look into frequency generation, which is easier. As soon as I get it working I’ll post it here.

---

<div class="post-metadata">

**Author:** ![Electronix](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@Electronix](https://discourse.processing.org/u/Electronix)\
**Post date:** [November 2, 2020, 2:17pm UTC](https://discourse.processing.org/t/sound-library-no-longer-works/25110/5 "2020-11-02T14:17:00Z")

</div>

@noel  
Ok, thanks.  
But one thing at a time, for the moment I would just like to run the Sound lib in JAVA mode.

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [November 2, 2020, 4:28pm UTC](https://discourse.processing.org/t/sound-library-no-longer-works/25110/6 "2020-11-02T16:28:37Z")

</div>

> [@Electronix](#):
>
> I would just like to run the Sound lib in JAVA mode.

> [@Electronix](#):
>
> I’m looking for a soundlibrary to use in Android mode.

I got confused now…

---

<div class="post-metadata">

**Author:** ![Electronix](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@Electronix](https://discourse.processing.org/u/Electronix)\
**Post date:** [November 3, 2020, 8:29am UTC](https://discourse.processing.org/t/sound-library-no-longer-works/25110/7 "2020-11-03T08:29:49Z")

</div>

@noel  
My starting post was not very clear, my apologies.  
Until now I was only working in Java mode, now I start working in Android mode.  
So far, I have not yet tried code with lib Sound in Android mode. I try first in Java mode because I have never worked with the Sound lib before, only with the Minim lib. The Minim library is better for synthesizing sounds indeed but don’t work on Android.

---

<div class="post-metadata">

**Author:** ![Electronix](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@Electronix](https://discourse.processing.org/u/Electronix)\
**Post date:** [December 1, 2020, 1:20pm UTC](https://discourse.processing.org/t/sound-library-no-longer-works/25110/8 "2020-12-01T13:20:20Z")

</div>

Can’t anyone help me to find a solution to this problem?

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [December 1, 2020, 1:36pm UTC](https://discourse.processing.org/t/sound-library-no-longer-works/25110/9 "2020-12-01T13:36:52Z")

</div>

Does it not work at all?

---

<div class="post-metadata">

**Author:** ![Electronix](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@Electronix](https://discourse.processing.org/u/Electronix)\
**Post date:** [December 1, 2020, 2:15pm UTC](https://discourse.processing.org/t/sound-library-no-longer-works/25110/10 "2020-12-01T14:15:40Z")

</div>

No, see details on my first post at the top.  
To begin, I first tried in the Java mode but without success.

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [December 1, 2020, 2:37pm UTC](https://discourse.processing.org/t/sound-library-no-longer-works/25110/11 "2020-12-01T14:37:49Z")

</div>

Im by no means super knowledgeable about processing but as i would also like to work with android and I will take a look into this as soon as i can. It would be nice for all the pc code to work in android mode, as i think processing could be a great platform for android development, but there are currently a lot of hurdles. Anyways ill post back soon.

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [December 1, 2020, 3:30pm UTC](https://discourse.processing.org/t/sound-library-no-longer-works/25110/12 "2020-12-01T15:30:30Z")

</div>

In principle it should be possible because the lib on Github sound writes:  
(But I still don’t have it working.)

> ### How to build
> 
> 1. `git clone git@github.com:processing/processing-sound.git`
> 2. (optional: copy (or soft-link) `processing-core.zip` from your local [Processing for Android mode](https://github.com/processing/processing-android/releases/tag/latest) as well as your Android SDK’s `android.jar` , API level 26 or higher, into the `library/` folder. If you don’t do this, these will be downloaded from GitHub instead. Note that as of version 2.2 the sound library is compiled against Processing’s Android mode rather than the normal Processing `core.jar` in order to more smoothly support `AudioIn` on Android. Other dependencies, in particular Phil Burk’s [JSyn](http://www.softsynth.com/jsyn/) engine on which this library is based, are also all downloaded automatically by ant.)
> 3. `ant dist` (or, alternatively, run `build.xml` from within Eclipse)  
> The resulting `sound.zip` can be extracted into your Processing installation’s `libraries/` \>folder.

In the meantime, I’m trying to understand how sound frequency is generated. on Android.  
So far I have this code working on my Android 10 device, but strangely it doesn’t work on my Lollipop. Maybe you can help me by running this code on your device, and tell me if there are problems and if you like my song.

```auto
import android.media.AudioTrack; 
import android.media.AudioManager; 
import android.media.AudioFormat; 
import java.lang.SuppressWarnings; 

// Index of notes in in note_frequencies array 
int Gl = 0, A = 1, B = 2, C = 3, D = 4, E = 5, G = 6, Ah = 7, Bh = 8, Ch = 9; 
// Gl, A, B, C, D, E, G, Ah, Bh, Ch 
int[] note_frequencies = {392, 440, 494, 523, 587, 659, 784, 880, 988, 1046}; 
int[] song_notes = {A, A, E, D, C, B, B, B, D, C, B, A, A, Ch, Bh, Ch, Bh, Ch, A, A, C, B, C, B, C}; // The song 
int[] final_notes = {C, C, C, C, E, E, E, E, D, D, D, D, G, G, G, G, Ah, Ah, Ah, Ah, Ah, Ah, Ah, D, C, B, Gl, A, A, A}; 
// index of long notes in notes array 
int[] note = {1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0};

int sample_rate = 44100; 

AudioTrack[] audio_track = new AudioTrack[note_frequencies.length]; 
void setup() { 
  background(0, 0, 200); 
  fill(255); 
  textAlign(CENTER, CENTER); 
  String str = "Click to start song."; 
  textSize(12); 
  float twf = width/textWidth(str);
  ; 
  textSize(9*twf); 
  text(str, width/2, height/2); 
  int note_duration = sample_rate/5; 
  byte long_note[][] = new byte[note_frequencies.length][note_duration]; 
  for (int ln = 0; ln < note_frequencies.length; ln++) { 
    for (int i = 0; i < long_note[ln].length; i++) { 
      byte sample = (byte)(sin(TWO_PI*note_frequencies[ln]*i/sample_rate)*255); 
      long_note[ln][i] = sample;
    }
  } //@SuppressWarnings("deprecation") 
  for (int ln = 0; ln < note_frequencies.length; ln++) { 
    audio_track[ln] = new AudioTrack( AudioManager.STREAM_MUSIC, sample_rate, AudioFormat.CHANNEL_OUT_DEFAULT, AudioFormat.ENCODING_PCM_8BIT, long_note[ln].length, AudioTrack.MODE_STATIC ); 
    audio_track[ln].write(long_note[ln], 0, long_note[0].length);
  }
} 

void draw() {
} 

void mousePressed() { 
  for ( int i = 0; i < 2; i++) { 
    for (int sn = 0; sn < song_notes.length; sn++) { 
      audio_track[song_notes[sn]].play(); 
      int start_time = millis(); 
      int pause_between_notes; 
      if (note[sn] == 1) pause_between_notes = 350; 
      else pause_between_notes = 150; 
      while (millis()-start_time < pause_between_notes) {
      }; 
      if (i == 1 && sn == 18) break; 
      audio_track[song_notes[sn]].stop();
    }
  } 
  for (int fn = 0; fn < final_notes.length; fn++) { 
    int start_time = millis(); 
    int pause_between_notes = 200; 
    audio_track[final_notes[fn]].play(); 
    while (millis()-start_time < pause_between_notes) {
    }; 
    audio_track[final_notes[fn]].stop();
  }
} 

void onStop () { 
  for (int i = 0; i < audio_track.length; i++) { 
    audio_track[i].release(); 
    audio_track[i] = null;
  }
} 

void onPause () { 
  for (int i = 0; i < audio_track.length; i++) { 
    audio_track[i].release(); 
    audio_track[i] = null;
  }
}

```

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [December 1, 2020, 3:47pm UTC](https://discourse.processing.org/t/sound-library-no-longer-works/25110/13 "2020-12-01T15:47:33Z")

</div>

Runs ok on Samsung S2 tablet; Android version 6.0.1. Does crash after song has ended. Don’t recognize the tune.

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [December 1, 2020, 3:59pm UTC](https://discourse.processing.org/t/sound-library-no-longer-works/25110/14 "2020-12-01T15:59:03Z")

</div>

The same happens on my Lollipop.  
You didn’t recognize the song because it doesn’t play all the notes. It’s a popular song.

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [December 1, 2020, 4:23pm UTC](https://discourse.processing.org/t/sound-library-no-longer-works/25110/15 "2020-12-01T16:23:14Z")

</div>

Runs on huawei p30 running android 10 no crashes through apde. Can’t say i recognise the song either…

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [December 1, 2020, 4:51pm UTC](https://discourse.processing.org/t/sound-library-no-longer-works/25110/16 "2020-12-01T16:51:56Z")

</div>

Is it similar to this tune? [https://drive.google.com/file/d/1QqBZc5abkbmc\_8yldhAnvTIZEdBFbx9M/view?usp=sharing](https://drive.google.com/file/d/1QqBZc5abkbmc_8yldhAnvTIZEdBFbx9M/view?usp=sharing)

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [December 1, 2020, 9:32pm UTC](https://discourse.processing.org/t/sound-library-no-longer-works/25110/17 "2020-12-01T21:32:35Z")

</div>

Yup thats it! So i guess sound works on android.

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [December 1, 2020, 10:21pm UTC](https://discourse.processing.org/t/sound-library-no-longer-works/25110/18 "2020-12-01T22:21:51Z")

</div>

> [@Electronix](#):
>
> Can’t anyone help me to find a solution to this problem?

The Android library wizard is @uheinema. Maybe he is willing to figure out, how to build this library.

---

<div class="post-metadata">

**Author:** ![calsign](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/calsign/32/30_2.png) [@calsign](https://discourse.processing.org/u/calsign)\
**Post date:** [December 1, 2020, 11:38pm UTC](https://discourse.processing.org/t/sound-library-no-longer-works/25110/19 "2020-12-01T23:38:30Z")

</div>

I have been using Processing’s sound library for a while, you can download the pre-built sound.zip from the [GitHub releases page](https://github.com/processing/processing-sound/releases). (The same library zip works for both desktop and Android. Tested with APDE.) Even if you have issues using it on desktop (which might warrant filing a bug report) it should still work on Android.

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [December 2, 2020, 4:24am UTC](https://discourse.processing.org/t/sound-library-no-longer-works/25110/20 "2020-12-02T04:24:00Z")

</div>

Hi @calsign great to see you here again!  
I only use APDE, and have tried several releases from the app and the library as well.  
Although the app complains that sound-dex.jar does not exist, the examples are build (App mode) but when installed they all crash without warnings. I’ve also tried to build the library as mentioned on Github and included the dex.jar, but without success on both my phones Lollipop and Android 10. Could you zip your working library folder and post it.  
Thanks.

[Next page](https://discourse.processing.org/t/sound-library-no-longer-works/25110.md?page=2)
