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: 55
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.
 
Top