B4J Question jAudiorecord2 error.

mzsoft

Member
hi.
i used jAudiorecord2 for record wav.
i run jAudiorecordNonUI sample but in lin TDL.Initialize(InDevice) this error happend.


B4X:
Waiting for debugger to connect...
Program started.
Capture File Initialized
Ready true
Error occurred on line: 18 (TargetDataLineWrapper)
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:132)
    at b4j.example.targetdatalinewrapper._initialize(targetdatalinewrapper.java:69)
    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:629)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    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.BA.raiseEvent2(BA.java:111)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
    at b4j.example.main.main(main.java:30)
Caused by: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 8 bit, mono, 1 bytes/frame,  not supported.
    at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(DirectAudioDevice.java:513)
    at com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:120)
    at com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:412)
    ... 21 more
 

stevel05

Expert
Licensed User
Longtime User
javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 8 bit, mono, 1 bytes/frame, not supported.
It appears that your device does not support 8 bit mono recording.
 
Upvote 0

mzsoft

Member
It appears that your device does not support 8 bit mono recording.
i change to 16 again error.


B4X:
Waiting for debugger to connect...
Program started.
Capture File Initialized
Ready true
Error occurred on line: 18 (TargetDataLineWrapper)
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:132)
    at b4j.example.targetdatalinewrapper._initialize(targetdatalinewrapper.java:69)
    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:629)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    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.BA.raiseEvent2(BA.java:111)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
    at b4j.example.main.main(main.java:30)
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.AbstractDataLine.open(AbstractDataLine.java:120)
    at com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:412)
    ... 21 more
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported

Which device / OS are you using?

Are you loading multiple files?
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Got to ask the obvious questions: Does your PC have a sound card?
Is it in use by any other software?
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
OK, the example is just that. It depends on your computer having a a device called "Primary Sound Capture Driver".

Run this code separately, you will then see which devices are available on your computer, pick one that looks like the generic / mic input and update the CaptureDevice string.

B4X:
Dim AudioSystem As JavaObject
AudioSystem.InitializeStatic("javax.sound.sampled.AudioSystem")
Dim MixerInfo() As Object = AudioSystem.RunMethod("getMixerInfo",Null)
For Each MI As JavaObject In MixerInfo
    Log(MI.RunMethod("getName",Null))
Next

Or change Appstart to:

B4X:
AppStart (Args() As String)
    'Default dataline
    RecordFile1.Initialize(Me,"RecordFile1")
    
    Dim AudioSystem As JavaObject
    AudioSystem.InitializeStatic("javax.sound.sampled.AudioSystem")
    AudioFormat.InitializeNewInstance("javax.sound.sampled.AudioFormat",Array(SampleRateHz,SampleSizeInBits,ChannelConfig, True, False))
    InDevice = AudioSystem.RunMethod("getTargetDataLine",Array(AudioFormat))
    
    
    Dim TDL As TargetDataLineWrapper
    TDL.Initialize(InDevice)
    TDL.AddLineListener(Me,"DataLine")
    
    If RecordFile1.IsInitialized Then
        If RecordFile1.IsRecording Then
            RecordFile1.Stop
        End If
    End If
    If File.Exists(FilePath, FileName) Then File.Delete(FilePath, FileName)
    RecordFile1.Start(TDL, File.Combine(FilePath, FileName))
    
    StartMessageLoop

To record the system default input
 
Last edited:
Upvote 0

mzsoft

Member
OK, the example is just that. It depends on your computer having a a device called "Primary Sound Capture Driver".

Run this code separately, you will then see which devices are available on your computer, pick one that looks like the generic / mic input and update the CaptureDevice string.

B4X:
Dim AudioSystem As JavaObject
AudioSystem.InitializeStatic("javax.sound.sampled.AudioSystem")
Dim MixerInfo() As Object = AudioSystem.RunMethod("getMixerInfo",Null)
For Each MI As JavaObject In MixerInfo
    Log(MI.RunMethod("getName",Null))
Next

Or change Appstart to:

B4X:
AppStart (Args() As String)
    'Default dataline
    RecordFile1.Initialize(Me,"RecordFile1")
   
    Dim AudioSystem As JavaObject
    AudioSystem.InitializeStatic("javax.sound.sampled.AudioSystem")
    AudioFormat.InitializeNewInstance("javax.sound.sampled.AudioFormat",Array(SampleRateHz,SampleSizeInBits,ChannelConfig, True, False))
    InDevice = AudioSystem.RunMethod("getTargetDataLine",Array(AudioFormat))
   
   
    Dim TDL As TargetDataLineWrapper
    TDL.Initialize(InDevice)
    TDL.AddLineListener(Me,"DataLine")
   
    If RecordFile1.IsInitialized Then
        If RecordFile1.IsRecording Then
            RecordFile1.Stop
        End If
    End If
    If File.Exists(FilePath, FileName) Then File.Delete(FilePath, FileName)
    RecordFile1.Start(TDL, File.Combine(FilePath, FileName))
   
    StartMessageLoop

To record the system default input
i used code and change CaptureDevice.

i set Microphone (Conexant SmartAudio for MI.
an this log appear.


B4X:
Waiting for debugger to connect...
Program started.
Capture File Initialized
Port Speakers (Conexant SmartAudio H
Port Microphone (Conexant SmartAudio
Port Stereo Mix (Conexant SmartAudio
Primary Sound Driver
Speakers (Conexant SmartAudio HD)
Primary Sound Capture Driver
Microphone (Conexant SmartAudio
Stereo Mix (Conexant SmartAudio
Ready true
TH Complete
endedOK false
Error Exception : wrong number of arguments
UpdateHeader DataSize 0
Recording Finished
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Are you trying to run in debug mode? The threading library runs in Release mode only.
 
Upvote 0
Top