Showing posts with label midi. Show all posts
Showing posts with label midi. Show all posts

Tuesday, February 28, 2017

WildMidi for Android: Compiling WildMidi using Android NDK rev 13

Android had no standard midi protocol before Marshmallow. Even after a standard MIDI event API for a developer to build android app which does midi synthesis by itself is a great feature!. In 2016 i compiled FluidSynth 1.6 for Android and created a SoundFont Midi Player with USB keyboard support. This app can play midi, rmi files and can send midi events via USB MIDI Keyboard, Normal USB keyboard to fluidsynth to synthesize sound. Due to latency and high CPU consumption issues i decided to look at other options. One good option was WildMidi.


WildMidi - https://www.mindwerks.net/projects/wildmidi/


It says -

"The WildMIDI library uses Gravis Ultrasound patch files to convert MIDI files into audio which is then passed back to the calling application for further processing or output

Library Features

  • RIFF MIDI file support
  • MIDI format 0, 1 and 2 support
  • MIDI-like formats: KAR, HMI, HMP, MUS and XMI
  • Cross Platform: Linux, Windows, OSX, FreeBSD and etc.
  • Thread safe
  • host-Endian native streaming
  • WAV file output
  • Linear and gauss re-sampling
  • Final output reverb engine
  • Timidity.cfg compatibility
Player Features

  • OSS and Alsa Output (Linux/FreeBSD)
  • Windows Sound System support (Windows)
  • OpenAL (OSX/Others)
  • SoundBlaster 16 (DOS)"


In Player features Android sound system is not mentioned and that doesn't mean it cannot be used in Android. I compiled WildMidi for Android and the link to download the binary package is mentioned later in this page. I tested WildMidi on Ubuntu-Studio which had inbuilt "FreePats". The Gravis Ultrasound Patch files are used by WildMidi to synthesize sound. We can use WildMidi player to play midi files on Android by modifying its player code by sending PCM buffer to Android OpenSLES or AudioTrack.

Can wildmidi be used for sending MIDI events to build piano like app with fast response? Currently NO as per wildmidi source!


Looking at source code of wildmidi inside wildmidi_lib.h. It says "Not Yet Implemented". That "latency" thing! everywhere.

Preview:
/* NOTE: Not Yet Implemented Or Tested Properly */
/* Due to delay in audio output in the player, this is not being developed
   futher at the moment. Further Development will occur when output latency
   has been reduced enough to "appear" instant.
WM_SYMBOL int WildMidi_Live (midi * handle, uint32_t midi_event);
 */

/* reserved for future coding
 * need to change these to use a time for cmd_pos and new_cmd_pos

WM_SYMBOL int WildMidi_InsertMidiEvent (midi * handle, uint8_t char midi_cmd, *char midi_cmd_data, unsigned long int midi_cmd_data_size, unsigned long int *cmd_pos);
WM_SYMBOL int WildMidi_DeleteMidiEvent (midi * handle, uint8_t char midi_cmd, unsigned long int *cmd_pos);
WM_SYMBOL int WildMidi_MoveMidiEvent (midi * handle, , uint8_t char midi_cmd, unsigned long int *cmd_pos, unsigned long int *new_cmd_pos);
 */



This can be used to build a midi player for android using wildmidi synthesizer. The build script is same as libpng build script mentioned on my other article.



Download wildmidi arm binary from here:
https://github.com/bindeshkumarsingh/android-native-libs




Monday, June 27, 2016

Android app to extract soundfont (SF2) from sfArk

Update:

This project is now also archived. I will not work on it and removed from my playstore account. I am abandoning many of my projects because on Android its getting very tough to maintain them to work on all devices and updating them to newer Android versions. However i can republish it to my archived project's PlayStore profile. For now the apk can be download from apk websites which have copy of the playstore version. However non-playstore versions are not recommended because they have chances of being hacked and with malicious code. You at your own risk.



Decades ago Soundfont files were packed to reduce their size to manage for storage limited devices. Many developers came up with tools to compress SF2 files. Major of them are sfArk & sfpack formats. Now we have lots of space and those formats are mostly abandoned by their makers. Also the software support from 3rd party is almost dead. Some PC apps like Polyphone support extraction of sfark and sfpack files.

I have ported unsfark & sfArkXtm to Android which handles both sfArk formats. Simple advice is to just stay away from these formats. Convert them to sf2 files and use latest methods to compress them or use sf3 if supported.


Android sfArk extractor port link (n/a right now):

http://play.google.com/store/apps/details?id=org.greh.sfarkextractor


It detects old sfArk (unsfark) & new sfArk (sfArkXtm) and extracts sf2 to destination directory. If you are a developer and you need source of android lib files please mail me i will either upload here or mail you. There is not much of changes done to the code.

Monday, May 23, 2016

Play midi files without midi driver using soundfonts on Android

Audience: Normal user
Platform:  Android


After trying to setup midi in Linux i decided to use Software Synthesis based players with custom soundfonts. Before that i will give basics of midi. Skip to APPs section if you don't want to read about midi system below.


How MIDI works?
Suppose you have memorized a pattern on piano notes and playing it on piano. Unfortunately there is no synthesizer (synth) & speaker attached. So before setting it up with synth you wrote every piano key activity on a paper or a file. You saved it like "C4 C4 D4# ... PITCH_WHEEL ... VOLUME_UP etc". Now you know the pattern, raga or rhythm of your music. Midi file is exactly this saved record!. Means there is no SOUND DATA. You write on paper that you payed a sitar or guitar. But how does that sound? To save that we really need sound file itself. That is the reason midi files are very small because there is no sound data inside mid files.

Now we know what is MID file. Now comes Synthesizer. That missing sound is produced by synth that is why the name. Midi tells a synth to play an instrument named guitar. Therefore depending upon a synth midi sound different. The big problem is that we create a music with our instruments and assume mid file will play same but if instruments are of low quality or even different in timbre may give totally different music. There are many solutions to this. Easiest solution is to produce stream music like mp3 ogg. However what is there are 1000 midi musics but very less disk space?. Its always recommended to keep midi files with original set of instruments so that in future we can reuse them for editing, remixing or other work. What we do is collect all the instruments sounds recorded and save in a bundle called SoundFont. Just like a font which contains set of Alphabets of a language.



So we have a solution.
Midi + SoundFont = Low size & preserved quality of OST (original sound track). 
More details about the topics covered can be found on wiki or tutorials on web.



APPs:

For windows, Mac related midi can be found on this link http://adamrehn.com/articles/playing-midi-soundfonts/


Android Version:
There are some apps which play midi using soundfont viz -

DroindSound, Timidity AE Player, LiveMidi, Midi Voyager, SoundFont-Midi-Player


SoundFont-Midi-Player is my own player i developed to play midi files with different soundfonts fast. It can change soundfonts easily and fast!. Do try it here -

https://play.google.com/store/apps/details?id=org.greh.soundfontmidiplayer

  • Switches between SoundFonts fast
  • Test SoundFont instruments using piano & USB MIDI Keyboard
  • Play Piano together with Midi music. However it also changes the instrument being played in Midi music.
  • Supports USB MIDI keyboard. Supports PITCH BEND messages, Pedal, Volume, Key events. AFAIK not all android apps do this. Tested M-AUDIO KeyRig 49 on Moto-G phone. Doing pitch bend on Android phone using USB Midi keyboard needs good response. I tested this app on some low end phones and it works fine.
  • Samplerates from 22050 to 96000Hz
  • Reverb & Chorus effects
  • Crystalizer audio effect. (Currently disabled)
  • FluidSynth is powerful and i think my app is the only one using latest FluidSynth 1.1.6 with GLIB Android build. Powered by Unmodified FluidSynth 1.1.6 Android Version. If modified source is used i will make the source available here.
  • More features described in PlayStore page.


Features to add:
- Hack Soundfont instrument without altering soundfont files to test midi music


Pro version i am planning to build with more useful features:
- Export as streaming music to ogg- Export self contained midi music i.e. rmid, (mod?)