Calling the Port Audio C API via Panama FFI APIs

carl dea carl.dea at gmail.com
Wed Dec 22 04:06:32 UTC 2021


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*
Sr. Developer Advocate  @Azul Systems
  Email: carldea at gmail.com
Website: https://carlfx.wordpress.com
Twitter: @carldea <https://twitter.com/carldea>


More information about the panama-dev mailing list