Audio Recording sample with NativeCall, Thread, Java-Calls, etc.
Hi fans of Jabaco!
Here is a sample which demonstrates some of the nice features of Jabaco:
- asynchronous threads
- calling external Windows routines via NativeCall
- calling Java framework classes and routines
- manipulating files
- calling user-defined Java routines
The sample is a little recording tool which writes microphone sound input to a WAV file. It was inspired by similar "SimpleAudioRecorder" programs on the net. Just for comparison, it implements the steps for sound processing in two different flavors. One is more oriented to the Microsoft VB style. The other is oriented to the Java sound processing style.
I came along one culprit when I tried to access a public internal class defined within a Java class:
The following does not work!
' Jabaco IDE does not seem to know internal classes of AudioFileFormat
' cf. http://java.sun.com/j2se/1.5.0/docs/api/….Type.html#WAVE
' Call AudioSystem.write(ais, AudioFileFormat.Type.WAVE, f)
To get around this problem, I wrote a small Java wrapper to call the method directly. There might be clever alternative ways to solve this. Who has a suggestion?
To compensate for the lack of documentation in Jabaco, I found Java decompilers useful. My favorite decompiler is http://java.decompiler.free.fr It is a great help to look at Jabaco.jar using this decompiler. Another choice could be "jad".
I'm not quite sure if I understand the exact usage of NativeCall() to access WIN32 API routines in external DLL libraries. However, I noticed that temporary DLL files "temp*.dll" are left behind in directory "%TEMP%" after termination of my demo program. The NativeCall implementation makes use of the File.deleteOnExit mechanism. Something must be strange here.
I hope you enjoy the sample and possibly report some hints and improvements here.
A1880
Here is a sample which demonstrates some of the nice features of Jabaco:
- asynchronous threads
- calling external Windows routines via NativeCall
- calling Java framework classes and routines
- manipulating files
- calling user-defined Java routines
The sample is a little recording tool which writes microphone sound input to a WAV file. It was inspired by similar "SimpleAudioRecorder" programs on the net. Just for comparison, it implements the steps for sound processing in two different flavors. One is more oriented to the Microsoft VB style. The other is oriented to the Java sound processing style.
I came along one culprit when I tried to access a public internal class defined within a Java class:
The following does not work!
' Jabaco IDE does not seem to know internal classes of AudioFileFormat
' cf. http://java.sun.com/j2se/1.5.0/docs/api/….Type.html#WAVE
' Call AudioSystem.write(ais, AudioFileFormat.Type.WAVE, f)
To get around this problem, I wrote a small Java wrapper to call the method directly. There might be clever alternative ways to solve this. Who has a suggestion?
To compensate for the lack of documentation in Jabaco, I found Java decompilers useful. My favorite decompiler is http://java.decompiler.free.fr It is a great help to look at Jabaco.jar using this decompiler. Another choice could be "jad".
I'm not quite sure if I understand the exact usage of NativeCall() to access WIN32 API routines in external DLL libraries. However, I noticed that temporary DLL files "temp*.dll" are left behind in directory "%TEMP%" after termination of my demo program. The NativeCall implementation makes use of the File.deleteOnExit mechanism. Something must be strange here.
I hope you enjoy the sample and possibly report some hints and improvements here.
A1880
Cool sample
Jabaco will support internal java classes in a future version ...
Quoted
' Jabaco IDE does not seem to know internal classes of AudioFileFormat
I'll fix this problem in Jabaco. So you need only a temporary workaround. Your solution is clever (in my mind) but if you don't like it you could try to find another solution with java reflections...
Quoted
There might be clever alternative ways to solve this. Who has a suggestion?
Another solution to save your time:
Quoted
I'm not quite sure if I understand the exact usage of NativeCall() to access WIN32 API routines in external DLL libraries.
|
|
Jabaco Source |
1 2 3 4 5 6 |
Public WinApi Function mciSendString Lib "winmm.dll" _ Alias "mciSendStringA" ( _ ByVal lpstrCommand As String, _ ByVal lpstrReturnString As String, _ ByVal uReturnLength As Long, _ ByVal hwndCallback As Long) As Long |
Hello,
NativeCall seems to have problems :/
The following code when executed do its call byt the returned value that is expected into va(3) gives cabbalistic values, instead of a string content... any idea ?
Thanks
NativeCall seems to have problems :/
The following code when executed do its call byt the returned value that is expected into va(3) gives cabbalistic values, instead of a string content... any idea ?
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
Public Sub main(ByJava args() As String)
Dim retStr As String
Dim va(0 To 5) As Variant
Dim res As Variant , i As Integer
retStr = space(128)
i = 128
va(0) = "TEST"
va(1) = "TEST"
va(2) = "zz"
va(3) = retStr
va(4) = i
va(5) = "C:\test.ini"
res = NativeCall("KERNEL32", "GetPrivateProfileStringA", va)
msgbox va(3)
End Sub
|
Thanks
Output Parameters
Hi,
yes, I also haven't succeeded with output parameters.
see here
"NativeCall" and WINAPI probably need some more thoughts and some testing.
Due to Java's limitations (some would rather call it: "style") it is not directly possible to use output parameters.
One way around would be to pass a container object as parameter and call its setter method from within the called routine.
But this would obviously spoil the WINAPI syntax and would make WINAPI very much different from its VB6 predecessor,
Greetings!
A1880
yes, I also haven't succeeded with output parameters.
see here
"NativeCall" and WINAPI probably need some more thoughts and some testing.
Due to Java's limitations (some would rather call it: "style") it is not directly possible to use output parameters.
One way around would be to pass a container object as parameter and call its setter method from within the called routine.
But this would obviously spoil the WINAPI syntax and would make WINAPI very much different from its VB6 predecessor,
Greetings!
A1880
RE: Output Parameters
Hello,
Hemm... I come here as an original C developer and recently discovered a real use of Java, and have experimented JNI in C.
Just tell me if via a JNI interface one Api call is possible with in out parameters that can be then given back to the Java callee ?
If YES, then I've developped in C + ASM a GENERIC ApiCall engine I use through my language (FBSL) that I can share for the Jabaco project, but before I just want to see with a simple hard coded JNI C sample code how you can manage an in out value (if possible of course!), then I'll be able to help you with my generic api call engine!
Thanks
Hi,
yes, I also haven't succeeded with output parameters.
see here
"NativeCall" and WINAPI probably need some more thoughts and some testing.
Due to Java's limitations (some would rather call it: "style") it is not directly possible to use output parameters.
One way around would be to pass a container object as parameter and call its setter method from within the called routine.
But this would obviously spoil the WINAPI syntax and would make WINAPI very much different from its VB6 predecessor,
Greetings!
A1880
Hemm... I come here as an original C developer and recently discovered a real use of Java, and have experimented JNI in C.
Just tell me if via a JNI interface one Api call is possible with in out parameters that can be then given back to the Java callee ?
If YES, then I've developped in C + ASM a GENERIC ApiCall engine I use through my language (FBSL) that I can share for the Jabaco project, but before I just want to see with a simple hard coded JNI C sample code how you can manage an in out value (if possible of course!), then I'll be able to help you with my generic api call engine!
Thanks
NativeCall Holder Objects
Hi,
if I understand it right, the "NativeCall" mechanism is able to handle input and output parameters.
I looked at the original website of the inventor of NativeCall.
Unfortunately, he does not mention output parameters in his samples. But in the source code I came across "Holder" objects.
Such a Holder object acts as a data container to pass values back and forth between caller and callee.
The caller passes the Holder object to the callee. The callee in turn can call setter methods of the Holder to assign return values for
output parameters. It remains open to write an example to demonstrate and test this.
Jabaco generates NativeCall statement whenever you use WINAPI declarations in your Jabaco code.
My suspicion is that the case of output parameters has been overlooked.
Good luck!
A1880
if I understand it right, the "NativeCall" mechanism is able to handle input and output parameters.
I looked at the original website of the inventor of NativeCall.
Unfortunately, he does not mention output parameters in his samples. But in the source code I came across "Holder" objects.
Such a Holder object acts as a data container to pass values back and forth between caller and callee.
The caller passes the Holder object to the callee. The callee in turn can call setter methods of the Holder to assign return values for
output parameters. It remains open to write an example to demonstrate and test this.
Jabaco generates NativeCall statement whenever you use WINAPI declarations in your Jabaco code.
My suspicion is that the case of output parameters has been overlooked.
Good luck!
A1880
Holder object in Jabaco
Here is an illustrative sample
The Holder object as class clsHolder
And here the code which demonstrates usage of Holder objects to implement two-way parameter passing:
I am wondering why "ByRef" and "ByVal" don't make a difference in this sample.
Any ideas?
A1880
The Holder object as class clsHolder
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Option Explicit Private myValue As Integer Public Sub clsHolder() ' constructor for initialization myValue = -1 End Sub ' we are not using "properties". ' This is just a demo for Holder objects .... Public Function GetValue() As Integer GetValue = myValue End Function Public Sub SetValue(i As Integer) myValue = i End Sub |
And here the code which demonstrates usage of Holder objects to implement two-way parameter passing:
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Public Sub main(ByJava args() As String) Dim holder As clsHolder = New clsHolder Dim holderArray(0 To 5) As String holderArray(1) = "hoo!" out.println "value before calling: " & holder.GetValue & " " & holderArray(1) Call Callee(holder, holderArray) out.println "value after calling: " & holder.GetValue & " " & holderArray(1) msgbox "ciao!" End Sub Private Sub Callee(holder As clsHolder, holderArray() As String) ' "ByRef" nor "ByVal" make no difference here! holder.SetValue 5 holderArray(1) = "ray!" End Sub |
I am wondering why "ByRef" and "ByVal" don't make a difference in this sample.
Any ideas?
A1880
This post has been edited 1 times, last edit by "A1880" (Feb 20th 2009, 4:01pm)
Dear Manuel,
Many thanks!
Here's a complete code if this can help someone :
Many thanks!
Here's a complete code if this can help someone :
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 10 |
Public Sub Command1_Click() Dim o As IntCall Dim i As Integer Dim p(2) As String p(0) = "C:\Test.txt" p(1) = "C:\Test2.txt" com#eaio#nativecall#NativeCall.init() o = New IntCall( "kernel32", "CopyFileA" ) i = o.executeCall( p() ) End Sub |
Similar threads
-
Tips, Tricks, Samples & Tutorials »-
Create a signed Jar-file
(Nov 26th 2008, 1:54pm)
-
Vorschläge »-
Erster Test
(Dec 17th 2008, 11:12pm)
-
Allgemeine Themen, Fragen und Diskussionen »-
Allgemeine Frage zu Webapplets
(Nov 26th 2008, 9:36am)
-
Tips, Tricks, Samples & Tutorials »-
BASIC meet Java (some internals)
(Nov 25th 2008, 9:19am)
-
Tips, Tricks, Samples & Tutorials »-
Threads and Synchronisation
(Aug 21st 2008, 10:41pm)
