B4J Question jAudioRecord and JaudioTrack : LineUnavailable

ludogomez

Member
Licensed User
Longtime User
Hi,

I try to use these 2 librairies : jAudioRecord and JaudioTrack with a raspberry pi.

When I use internal sound card, I can use JaudioTrack without problem, I can't use JaudioRecord because the pi board don't have audio input.
That's why I want to use an USB soundcard with headphone out and Mic IN.

When I initialize jaudioTrack or JaudioRecord with the USB soundcard, I have this message : lineUnavailable and I can't record or play something.

Do you have an idea ?
I try 2 different USB soundCard.

thanks
 

stevel05

Expert
Licensed User
Longtime User
jAudiorecord and jAudiotrack only work with the default audio in and out. If you can change the system default to the USB device it should work.
 
Upvote 0

ludogomez

Member
Licensed User
Longtime User
I try to change the system default to the USB device, but I have the same behaviour even if I desactivate the internal soundcard.

Thanks for your response.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Can you play audio through the USB device using the PI OS?
 
Upvote 0

ludogomez

Member
Licensed User
Longtime User
Hi,

it's impossible because Java don't provide ARM javafx.

I can't use GUI, only console.

Thanks
Regards
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Here is a non Gui version to try
 

Attachments

  • AudioSystemNoGui.zip
    149.4 KB · Views: 306
Upvote 0

ludogomez

Member
Licensed User
Longtime User
This is the result :


Waiting for debugger to connect...
Program started.
Set [default]

Here I have a trumpet sound, just 2 second

ALSA [plughw:0,0]
ALSA [plughw:0,1]
Une erreur s'est produite en ligne : 31 (Main)
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
at b4j.example.main._appstart(main.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:625)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeM
ethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:94)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
at b4j.example.main.main(main.java:29)
Caused by: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(DirectAudioDevice.java:513)
at com.sun.media.sound.DirectAudioDevice$DirectClip.implOpen(DirectAudioDevice.java:1304)
at com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:121)
at com.sun.media.sound.DirectAudioDevice$DirectClip.open(DirectAudioDevice.java:1085)
at com.sun.media.sound.DirectAudioDevice$DirectClip.open(DirectAudioDevice.java:1175)
... 21 more
Program terminated (StartMessageLoop was not called).

Thanks
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
OK this is the problem :
Caused by: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.

What is the USB device you are using?
 
Upvote 0

ludogomez

Member
Licensed User
Longtime User
I use a generic USB sound card :
Bus 001 Device 004: ID 0d8c:000c C-Media Electronics, Inc. Audio Adapter

I try with another usnb sound card with the same problem.

I initialize the player with at.Initialize(22050,16,2).

is it possible to try all parameters to know the good one.

Thanks
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
It is possible that it will need a sample rate of 48000, some cards only work with this rate. Although it is possible that the playback will be a different speed and pitch.
 
Upvote 0

ludogomez

Member
Licensed User
Longtime User
I try with 44100, 16, 2, it works, I don't have lineUnavailable with jaudiotrack and jaudiorecord.

I use your librairies to make an video home interphone between my external door and a tablet. I need to stream in 2 ways the audio. I want to limit the bandwith between the devices, 44100, 16 bits is too high. I'll try other frequency and sampling parameters.

Thanks a lot for debuging my problem
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You could try making it mono 44100,16,1
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…