Calling the Port Audio C API via Panama FFI APIs
carl dea
carl.dea at gmail.com
Sun Dec 26 17:12:06 UTC 2021
Maurizio,
Thank you for the quick response. Because I'm still using the same build as
before I still wanted to respond to some of your suggestions and later
follow-up once I can/able to resync to the correct build.
My responses are below:
On Wed, Dec 22, 2021 at 5:19 PM Maurizio Cimadamore <
maurizio.cimadamore at oracle.com> wrote:
> Hi Carl,
> I can't test this right now, but after having a brief look at your code,
> few things jumped to mind:
>
> 1. you don't seem to be doing anything really expensive, enough to cause
> the program to misbehave. The most expensive operation is probably the
> shared scope closure, but that happens when bringing things down (so
> it's immaterial).
>
My build is from the public download https://jdk.java.net/panama/
shown as Build
17-panama+3-167 (2021/5/18)
I chose the shared scope because when using newConfinedScope() it crashes. try
(var scope = ResourceScope.newConfinedScope())
:-)
Not sure if upcalls/callbacks handle scope differently.
> 2. You are not using a recent Panama build (I see the MemoryAccess
> static methods are used). I think few issues with upcalls have been
> fixed - might be worth to give latest Panama a try.
>
> I'm assuming the latest build of the main branch 'origin/foreign-jextract'
I'm still in the process, for some reason the configure is complaining
about the following:
checking if libclang should be enabled... no, not found
configure: error: Cannot locate libclang! You can download pre-built llvm
binary from http://llvm.org/releases/download.html, then
specify the
location using --with-libclang
/Users/cdea/projects/panama/panama-foreign/build/.configure-support/generated-configure.sh:
line 84: 5: Bad file descriptor
configure exiting with result code 1
> 3. I see a call to PaSleep. Now, while that _shouldn't_ cause issue, I
> wonder if putting your thread to sleep in native-land instead of Java
> land might cause issues.
>
> Hmm.. Did you mean a C lang sleep?
I changed it to Java land (sleep) and no change.
PortAudio library has a function called Pa_Sleep()...
> 4. On a very quick look, the pointer arithmetic in the upcall seems fine
>
>
Is there a more elegant way to express this?
Thank you!,
Carl
> That's all I have for now, sorry!
>
> Cheers
> Maurizio
>
> On 22/12/2021 04:06, carl dea wrote:
> > Hello friends of JEP 412,
> >
> >
> > I hope I'm not being too forward, but I would love it if I could get a
> > second opinion of my *port* of an example from the folks from the
> PortAudio
> > C API project using Project Panama's FFI APIs.
> >
> >
> > I created the project called *portaudio4j* to simply port their first
> > example called *examples/paex_saw.c*.
> >
> > https://github.com/carldea/portaudio4j
> >
> >
> > *My version:*
> > https://github.com/carldea/portaudio4j/blob/main/src/PaexSaw.java
> >
> >
> > *(Their version) Port Audio C API 's beginner example paex_saw.c is
> here:*
> > https://github.com/PortAudio/portaudio/blob/master/examples/paex_saw.c
> >
> >
> >
> > *The Problem (Issue)*
> >
> > For some reason the C version (*paex_saw.c*) of the example compared to
> the
> > Panama example (*PaexSaw.java*) doesn't sound the same. Sometimes it's
> too
> > loud as if something isn't cleaning up from the prior run. The only
> thing
> > I've changed afaik is the SAMPLE_RATE, because it's so frighteningly
> loud.
> > Maybe I'm not properly doing pointer arithmetic. Or something I'm doing
> > that is overly expensive (operation wise) when accessing a
> > MemoryAddress/MemorySegment.
> >
> >
> > So, I thought I'd reach out to those who might be able to shed some light
> > on the issues I'm running into.
> >
> >
> > *Why did I choose this C library?*
> >
> > --------------------------------
> >
> > It is a relatively simple and small example that can exercise most
> aspects
> > of Panama (downcall, upcall, typedef void variables, handles, pointers,
> > structs, etc.) Everyone has a speaker and mic, so it would be a nice way
> to
> > use the library for all OSes.
> >
> >
> > Of course if there's a way I can pinpoint the cause, I'd be happy to
> report
> > the bug so we can keep an eye on it. Also, it might be a good example to
> > add to Sundar's examples here:
> > https://github.com/sundararajana/panama-jextract-samples.
> >
> > Thank you, Happy holidays!
> >
> >
> > Carl
> >
>
--
*Carl Dea*
Principal Software Engineer
Email: carldea at gmail.com
Website: https://carlfx.wordpress.com
Twitter: @carldea <https://twitter.com/carldea>
More information about the panama-dev
mailing list