Share My Creation jAsio audio. Simple mixer (Windows only)

This is a demonstration of using ASIO audio drivers with B4j. If you don't know what ASIO drivers are then you may not need this. But ASIO drivers provide low latency audio input and output.

There is a wrapper for the jasiohost project at github which manages most of it's methods and there is inline java in the ASIOSimpleMixer class in the demo app that is required and manages the callbacks with the ASIO buffers to process. This seemed to be the most stable setup after much testing, I did write a java library while testing it but I think it is better inline for this project.

For the WavRandomAccessFile implementation in this example, I have removed dependence on JavaxSound, so it should work on B4a and maybe B4i as well. There is a a b4xlib for it B4xWavRandomAccessFile-b4xlib, which is not required for the demo app.

To run the demo app, you will need a soundcard with ASIO drivers. Alternatively you could download ASIO4ALL which provides ASIO drivers for most soundcards even ones built in to the computers motherboard.

Try it out
There are two folders with tracks available on my google drive for you to try it out. one with 3 Tracks (my creation) and one with 15 which was downloaded from Then Mixing Secrets and converted with the FFMpegconvert utility (available in the jAudioTrack2-Mixer Full post) . Download either or both, unzip them. Run the app and open the folder. These folders are too large to include within the app so unfortunately you will have to download them separately.

1662589853126.png

Dependencies
The demo app requires jASIOHost-b4xlib.
jAsioHost.jar and jasiohost64.dll (or the 32 bit version if you really want to) from the jasiohost git hub page. I copied the dll file to my Windows32 folder and it found it. I think you can also put it in the projects working directory (not the code directory).


You will also need the java code from the ASIOSimpleMixer class in the demo if you want to use it in your own projects.

Note: I have moved the library file to the library thread where it should have been in the first place. Download it from there.

I hope you enjoy it. Let me know how you get on.
 

Attachments

  • JAsio-SimpleMixer.zip
    11.1 KB · Views: 132
Last edited:

kimstudio

Active Member
Licensed User
Longtime User
stevel, I tried it seems it runs but no sound. Motherboard soundcard, default is 24bit 48000, I changed to 16bit 44100 also but without success.
Wav files format is 16bit stereo 44100.

Log:
Asio driver set to ASIO4ALL v2
Playing ASIO
Start & 44100.0Hz : 512
Playing ASIO
Start & 44100.0Hz : 512
 

stevel05

Expert
Licensed User
Longtime User
Hmm, the whole ASIO thing has always been a little temperamental. If it's loaded in another app it would cause a problem, or an app doesn't release the driver. Can you check that the sound card isn't muted on the system. Failing that try rebooting the PC in case anything else has grabbed the ASIO driver. But I would have expected it to throw an error if that were the case.
 

kimstudio

Active Member
Licensed User
Longtime User
My fault. It works now after I turned on the third item in config panel. By default it turns on the second item which has no sound with a red X, but the third one works.
This 512 is a stereo buffer size? then the delay will be almost 5ms, else will be 11ms. I tried buffer size 192 still works, 64 then seems there are some can't hear clearly hiccups, maybe psychological effect. Incredible short delay.

屏幕截图 2022-09-08 203420.png
 

kimstudio

Active Member
Licensed User
Longtime User
Also could change close event as follows, or the wav files will be locked if first stop the playing then close the form as sm.close is not executed.

B4X:
Private Sub MainForm_CloseRequest (EventData As Event)
'    If SM.IsPlaying Then
'        SM.close
'    End If
    
    SM.close
End Sub
 

stevel05

Expert
Licensed User
Longtime User
I tried buffer size 192 still works, 64 then seems there are some can't hear clearly hiccups, maybe psychological effect. Incredible short delay.
Yes, the lower the buffer size, the less time you have to fill it before it gets called. If it's not filled, then you get the clicks and pops. The only time it is really relevant is when you are either recording to tracks that are also being played, or for an instrument, where a large buffer size will cause an audible delay between keypress and the sound being played.

Just for playing files, it is not really relevant as it doesn't matter if the playback starts in 11ms or 300ms.
 

max123

Well-Known Member
Licensed User
Longtime User
I missed out this post. Now that I read it, I'm impressed by your work. I wanted in past to wrap jasiohost, I just downloaded it and put on my hard disk to study it and manage low latency audio like in Cubase or any ASIO Host. But I had no time...and I don't have much experience with JavaObject. Now you wrapped it. Many many thanks @steveL for this great library. I will study it and may I try to combine with a Processing MidiBus library I wrapped for B4J, using java.
 
Last edited:

max123

Well-Known Member
Licensed User
Longtime User
Try it out
There are two folders with tracks available on my google drive for you to try it out. one with 3 Tracks (my creation) and one with 15 which was downloaded from Then Mixing Secrets and converted with the FFMpegconvert utility (available in the jAudioTrack2-Mixer Full post)
Hi @stevel05 I wanted to try it out, but both Google Drive links returns unavailable link.
I would also like to listen your creation, since I am also a musician :D

And what about wrap this library ?
https://github.com/mhroth/jvsthost

I want to ask you another question, not sure if this is the right place, eventually I will start another thread if not.

I need to make a low level midi driver loopback like MidiYoke, LoopBe1 or loopMidi by Tobias Erichsen
http://www.midiox.com/index.htm?http://www.midiox.com/myoke.htm
https://www.tobias-erichsen.de/software/virtualmidi.html

Did you know if it is possible using Java ? May using JNI ?

I think it should work like ASIOHost, so may to have a packaged jar file and a dll in System32.
I want to do this but I've no experience to do this.... the most I tried is to wrap (in java) some simple
Java and Processing libraries, and wrap a MidiBus that is not simple to me, but I payed an engineer
to help me port it. And at the end I will release opensource the library with all java library source code.
This even because the author request me this in change to use MidiBus royalty free in commercial projects.

May you can do it so after I will study your code ? :D

Thanks
 

Attachments

  • Screenshot 2023-12-21 104414.png
    Screenshot 2023-12-21 104414.png
    67.7 KB · Views: 38
Last edited:

stevel05

Expert
Licensed User
Longtime User
Sorry Max, I tidied my google drive and accidently deleted the audio files. I have put them back and changed the links in the first post of this thread.

Let me know if they are now available.

As for your other suggestions, I have not looked at them, and don't have time right now. But, they will not be simple to implement.

JNA is a simpler version of JNI as a lot of libraries have been wrapped for use with it, but it is unlikely that midi is included, but worth checking.
 

max123

Well-Known Member
Licensed User
Longtime User
Hi @stevel05 , I apologize for the late response.

Thank you so much for posting the download links for the audio tracks.

Yes the links in the other thread work correctly, I think you can edit the links in this thread to those, so other people won't have again the same my problem.

As for jVstHost, maybe I can do something, I took a look and at first glance it doesn't seem complicated (hopefully).

For JNA I never managed it, I will search on the web.
For now I took into this:
https://en.wikipedia.org/wiki/Java_Native_Access

Here I found this java code:
Java:
The program below loads the Kernel32.dll and uses it to call the Beep and Sleep functions.

Note: The following code works only on Windows platforms.

import com.sun.jna.Library;
import com.sun.jna.Native;

/** Simple example of Windows native library declaration and usage. */
public class BeepExample {
    public interface Kernel32 extends Library {
        // FREQUENCY is expressed in hertz and ranges from 37 to 32767
        // DURATION is expressed in milliseconds
        public boolean Beep(int FREQUENCY, int DURATION);
        public void Sleep(int DURATION);
    }

    public static void main(String[] args) {
        Kernel32 lib = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);
        lib.Beep(698, 500);
        lib.Sleep(500);
        lib.Beep(698, 500);
    }
}
What I don't like is that JNA is 10 times slower than JNI. Now I do not know if that can slow down complex midi streams.

Performance​

Benchmarks show JNA averages ten times slower than JNI.
What you think on this ?

But the main problem here is that may it just load a third-party dll library, for midi may need to write some C++ code and compile to dynamic linked library.
And another problem is that is platform dependant. My goal is to have it working on Win, Linux and MacOS, just on top of Java. I have to search better on the web....

I want to thank you for your advices and great support.
I wish you Happy Holidays and Happy New Year.

Sincerely
Max
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
This midi standard has a data transfer speed of 31250 bits per second. I can't see the speed of JNA being an issue when compared with this.
 
Top