Calling the Port Audio C API via Panama FFI APIs
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Wed Dec 22 22:18:49 UTC 2021
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).
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.
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.
4. On a very quick look, the pointer arithmetic in the upcall seems fine
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
>
More information about the panama-dev
mailing list