AIR doesn’t seem to have support for a accurate high resolution timer for implementing MIDI playback?
Is native ANE the alternative for this?
Are there any existing ANE’s that achieve this functionality for MIDI file parsing and playback?
There seems to be an existing AS3 lib https://github.com/heyfrench/as3midilib but its seems to be dated. Another way to accomplish this would be via a socket connection to a java app running externally.
What would be the best route to take over here?
Thanks in advance.
you are underestimating MIDI and you don’t say what you try to do
if you just try to play .mid files (or any other kind of MIDI files)
the simplest thing to do is to find a nice MIDI player with the capability to save to .mp3
and just play that MP3 in Flash/AIR and be done with it
for all the other use cases like dynamically generating sound/WAV from midi files, real-time connection to MIDI instruments, etc.
but if it is really, but really, about generating sound from MIDI files
look at AS3-SoundFont-Parser
An as3 utility library for reading SoundFont (sf2) files and extracting their samples as wavs. The project contains a demo application “SoundFontParserDemo.mxml” in the demo folder. It shows how to use the library to extract the sample waveforms as WAV files. It also show a crude way to generate music from MIDI files, based on the DemoMidi appli…
The SiON (pronounced as “scion”) is an ActionScript3 software synthesizer library works on the Flash Player 10.
SiON provides a simple sound synchronization with DisplayObject and an easy dynamic sound generation. You can generate various sounds without any mp3 files and wave data.The musical sequence is represented as Music Macro Language (a simple text data) or Standard MIDI Files. It makes your sounding SWF file very very small.
Yes, MIDI is very tempting, small file format and most computer can generate pretty good sound out of it, but it is a hell lot of hard work.
You will have to trade the small file format (size) for the time it takes to generate the sound (time).
MIDI is not magic, it is mainly about the sound library or sound font, in most case you would want that to be pre-generated, as off course it takes some time to “render it dynamically”.
And yeah you could go with an ANE, there your could profit from the hardware acceleration etc.
you can check that library to get you started RtMidi
RtMidi is a set of C++ classes (RtMidiIn, RtMidiOut and API-specific classes) that provides a common API (Application Programming Interface) for realtime MIDI input/output across Linux (ALSA & JACK), Macintosh OS X (CoreMIDI & JACK), and Windows (Multimedia Library) operating systems. RtMidi significantly simplifies the process of interacting with computer MIDI hardware and software.
Thanks for the extended reply, that was very useful!
I’m currently looking into RtMidi.
Basically I need to scroll a sheet music score and be in sync with the midi clock as the sound plays, I’m trying to use the midi clock as the reference for that. I would need to have call backs from native ANE to AS3 correct, but these callbacks would be called at a high rate at faster tempos, I don’t know what kind of latency the ANE to flash bridge currently has.
you’re asking yourself too much detailed questions on something you can’t know
or anyone else for that matter
do a spike, do a test etc. then measure
if you sync the MIDI device with socket you will suffer socket latency
but if all happen on the same machine it could be very low like 10th of millisec
but it could be completely different than that
so first thing is to setup a test environment, a way to test in similar running condition
and whatever command-line / C / C++ / Python / .NET / etc. sample you run
you can then test and measure the latency
run those a good 100 times, do a medium average of that latency
and when you implement the AS3 / ANE / whatever then you got a reference to compare to
so you know if you get similar latency results or you are way off