<div dir="auto"><span style="">Hello,</span><br>
<span style="">this is my first post in this list and I hope it is the appropriate place to discuss the issue but in case it's not I express my apologies.</span>
<br><br><span style="">I will try to describe in detail the needs and current limitations of the JDK in terms of public API.</span><br>
<span style="">A common scenario in GUI MIDI applications consists in let the user choose some form of "resources" (e.g. soundfonts) to produce actual waveforms from the symbolic MIDI representation with the goal of both playback and saving to disk. While in the JDK the former is available, it seems that it lacks the second possibility.</span><br>
<span style="">In my specific case the JavaFX application allows to load a (possibly high quality) .sf2 soundfonds file and playback midi sequences graphically in a pianoroll editor and common practice notation viewer. Unfortunately there isn't yet a "Save as .wav" functionality since at the moment (but let me know if I'm wrong) there is no way to render the midi sequence to audio wave using other than the default emergency Soundbank. (a low quality, DSP generated, sf2 )</span><br>
<span style=""><a href="http://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/com/sun/media/sound/EmergencySoundbank.java">github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/com/sun/media/sound/EmergencySoundbank.java</a></span><div dir="auto"><br>
<span style="">In my opinion this is a severe lack of functionality in these cases and creates an inconsistent behaviour: what you actually hear during playback is not what you save.</span>
<br><br><span style="">Currently, for what I know, the only way to render a midi sequence relies on the method:</span><br>
<span style="">AudioSystem.getAudioInputStream</span><br>
<span style="">that for MIDI files chooses as provider the SoftMidiAudioFileReader that creates an AudioSynthesizer (SoftSynthesizer) as the Receiver of time-stamped MIDI events and exploits its openStream method.</span><br>
<span style=""><a href="http://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/com/sun/media/sound/SoftMidiAudioFileReader.java#L64">github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/com/sun/media/sound/SoftMidiAudioFileReader.java#L64</a></span><br>
<span style=""><br></span></div><div dir="auto"><span style="">Unfortunately to conform to the strict interface signature this implementation doesn't provide a way to pass a Soundbank as a parameter.</span>
<br><br><span style="">Anyway in the original Gervill project there was also an illustrative example named Midi2WavRender with the added ability to select a custom Soundbank before processing the events. Now there is no way to circumvent this mechanism since the "key point" of the process is the openStream method of the AudioSynthesizer interface that surprisingly is not public.</span><br>
<span style="">I've found two RF almost identical in scope (respectively from 2010 and 2016) that propose to make the interface public:</span>
<br><br><span style="">Make the AudioSynthesizer interface public</span><br>
<span style=""><a href="http://bugs.openjdk.org/browse/JDK-8170518">bugs.openjdk.org/browse/JDK-8170518</a></span><br>
<span style="">make public new synthesizer (gervill) functionality</span><br>
<span style=""><a href="http://bugs.openjdk.org/browse/JDK-6938913">bugs.openjdk.org/browse/JDK-6938913</a></span>
<br><br><span style="">however since there is no real activities in more than a decade my expectations they move forward are quite low.</span>
<br><br><span style="">The current architecture of java sound is nice to get resources based on the current hardware at hand, but often the desire of the developer it's just using the default software synthesizer implementation (present in all the JDKs regardless of specific hardware) with all the benefits it has to offer.</span>
<br><br><span style="">Is there any real chance that in future releases of the JDK the AudioSynthesizer will finally find its way into the public API?</span>
<br><br><span style="">Thanks in advance,</span><br>
Mirco<br><br><span style="">P.S. forgive me but let me further express some feelings regarding parts of the java sound internal API.</span><br>
<span style="">The Gervill software synthesizer (even before the integration of its code in the upstream branch of the JDK) has always had amazing capabilities.</span><br>
<span style="">Using it's API it is possible to create virtual MIDI instruments using DSP (e.g. DoubleFM, Additive/Subtrative synthesis) with just few lines of code (thanks to the ModelAbstractOscillator class) or create .sf2 soundfonts files from scratch using only a bunch of wave files (using the classes SF2Soundbank, SF2Layer, SF2LayerRegion, SF2Instrument, SF2InstrumentRegion, SF2Sample). Not counting the usual utilities common in almost every audio library like FFT, iFFT, etc...</span><br>
<span style="">Moreover most of these internal classes are pure software with no specific hardware requirements, pure math (DSP) and implement well established and stable standards (e.g. Soundfonts specification).</span><br>
<span style="">After the JPMS it is possible to use them only with the usual hack:</span><br>
<span style="">--add-exports=java.desktop/com.sun.media.sound=ALL-UNNAMED  // or <MYMODULENAME></span><br>
<span style="">but of course this workaround is not advisable since later versions of the JDK could completely prevent their inclusion.</span><br>
<span style="">It is really sad that such precious gems are concealed and not part of the public API. What a waste.</span><br></div></div>