How to program a simple music sequencer for Android (Java)

What I want to do:

I would like to program a very simple music sequencer for Android. But I have never worked with audio on Android or Java, respectively.

What the application should do:

  • sample playback (WAVE / OGG files)
  • play multiple audio channels at the same time (for example, a trumpet and a flute must be played simultaneously, maximum 10 instruments).
  • change the sample height (for example, the WABE file of the pipe should be played in the normal step (c4) and lower / higher step (e2 / g6), etc.)

This is what the application should do at all.

What components do I need? Normal media player (AudioManager?) Wont work, right?

There are already applications that do what I'm thinking of:

  • FingerBeat for iOS
  • FL Studio Mobile for iOS
  • Uloops Studio for Android

Thanks in advance for your help!

+6
source share
5 answers

There is a very simple open source sequencer for Android called SoundFuse . They have a description and screenshots on the page.

Here is the github repository.

+6
source

You do not have one simple requirement, but three very different requirements.

  • WAV playback should be supported by the JRE using the classes in javax.sound.sampled, this jsut requires some code to connect it (not too sure about android). A.

  • OGG is not supported out of the box. There is an open source implementation for OGG called jOrbis, see Web site. Again, this may require some connection code.

  • For a sequencer, you can simply use MIDI. Again, it must be supported by the JRE, and if it's not on your platform, you can use Gervill, the pure Java Java sequencer ( project website ).

  • There is also ModPlayer, which can play the good old soundtrack and some others. It can also be used as a sequencer if you know the format of the Soundtracker or Screamtracker module (an ancient format, but descriptions are still available on the network). The player with the source can be found here . Tracker formats are not all so ancient, by the way, some of the modern game engines still use them.

  • If you really want, you can prepare your own sequencer, all the basic things, if in javax.sound.sampled. It just requires some basic knowledge of digital sound and a lot of wiring code.

There is no single solution for all your needs, you will have to sew you together from freely available building blocks.

+2
source

I cannot provide a complete answer, but I will point you in the right direction.

Android supports decoding of .wav and .ogg. According to: http://developer.android.com/guide/appendix/media-formats.html

I have no experience in audio, but your best bet seems to be the SoundPool class, it allows you to adjust the pitch and volume, and it looks like it can play several sounds at the same time: "Please note that calling the game () may lead to termination play another sound if the maximum number of active streams is exceeded. " http://developer.android.com/reference/android/media/SoundPool.html

There is also a MediaPlayer class, but for easier use. I do not think that it allows you to control the steps.

+2
source

I did something similar for my application (trombone sample). After many experiences, I found that using AudioTrack was the best solution. Take a look at my source code: http://code.google.com/p/trombonino/source/browse/trunk/src/com/trombonino

Special

http://code.google.com/p/trombonino/source/browse/trunk/src/com/trombonino/Trombone.java http://code.google.com/p/trombonino/source/browse/trunk/src /com/trombonino/WavFile.java

+2
source

You will have problems with your time on the Android system. To avoid interrupting the sequencer sequence with garbage collection, you probably need to write the sequencer in native using ndk.

Sound reproduction is probably best done with ndk.

Take a look at https://code.google.com/p/high-performance-audio/

In the Soundfuse example above, the sequencer uses SystemClock.sleep (), which is never a good idea. Check Why using System.Threading.Thread.Sleep () is bad practice? .

I realized that this question is really old, but it will answer it one way or another, since not one answer mentions NDK.

+1
source

Source: https://habr.com/ru/post/899617/


All Articles