Portaudio4j - An exploratory project to interact with the PortAudio C library using Java's FFI (Panama) APIs

Overview

Examples of PortAudio called by Java's Panama APIs JEP 412.

At the moment this is purely exploratory (still kicking the tires) as it progresses in the future it may be a port of accessing PortAudio completely in Java.

Go to: http://portaudio.com/docs/v19-doxydocs/tutorial_start.html

Getting started

  1. As of this writting the download of Java 19 JDK with jextract tool isn't released: https://jdk.java.net/panama/ So, new to this project it to clone Panama's project and build it! *To get this working go and clone https://github.com/openjdk/panama-foreign
  $ # download LLVM to your MacOS clang+llvm-9.x
  $ git clone [email protected]:openjdk/panama-foreign.git
  $ cd panama-foreign
  $ make clean
  $ bash configure --with-libclang=/<install_directory_path_to>/clang+llvm-9.0.1-x86_64-apple-darwin/
  $ make images 

After creating your new OpenJDK 19 containing jextract set your JAVA_HOME and path to the new images. Make sure the file setup.sh contains the new path to the newly built openjdk!

 $ export JAVA_HOME=$HOME/projects/panama-foreign/build/macosx-x86_64-server-release/images/jdk
  1. Set your JAVA_HOME and PATH
    • Note: If installed in $HOME/sdks directory you can do the following: This assumes you're at Step 6 below
      $ cd ~/projects/portaudio4j
      $ source setup.sh
  2. Set your LD_LIBRARY_PATH or DYLD_LIBRARY_PATH
  3. Clone and build PortAudio library: [email protected]:PortAudio/portaudio.git
  4. Compile and run the first example paex_saw.c https://github.com/PortAudio/portaudio/blob/master/examples/paex_saw.c
  5. Clone portaudio4j (this) project at: [email protected]:carldea/portaudio4j.git
  6. Jextract header includes
  7. Compile and run Java port of the example.

Clone PortAudio

Create a projects folder that contains both PortAudio and later portaudio4j

$ cd ~
$ mkdir ~/projects
$ cd ~/projects
$ git clone [email protected]:PortAudio/portaudio.git
$ cd portaudio

Create port audio library

$ ./configure && make

Compile the first example called pae_saw.c

$ cd examples

# MacOS you'll need to include frameworks 
$ gcc -Wall \
   -I ../include \
   -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include \
   paex_saw.c \
   -o paex_saw ../lib/.libs/libportaudio.a \
   -framework CoreServices \
   -framework CoreFoundation \
   -framework AudioUnit \
   -framework AudioToolbox \
   -framework CoreAudio

Run compiled example app.

$ ./paex_saw

Keep the executable handy as you will run it again to listen to the sound. To test whether it sounds like the Java Panama version!

Run as the Java Panama version

Assuming the Port Audio library is build from the prior step you'll want to point the library path to the directory.

# MacOS
$ export DYLD_LIBRARY_PATH=.:~/projects/portaudio/lib/.libs/
# Linux
$ export LD_LIBRARY_PATH=.:~/projects/portaudio/lib/.libs/

$ cd ~/projects
$ git clone [email protected]:carldea/portaudio4j.git
$ cd portaudio4j

Run jextract tool against foo.h containing stdio.h, math.h, portaudio.h

JExtract only works against one header (include) file so a trick is to create a foo.h containing the multiple includes.

$ ./jextract_foo.h.sh

Compile Java PaexSaw.java

Will create Java classes locally.

$ ./compile_paex_saw.java.sh

# Or the following:
$ javac -cp .:classes \
   -d . \
   --add-modules jdk.incubator.foreign \
   src/PaexSaw.java

Run PaexSaw.java

Will run the example PaexSaw.java

$ ./run_paex_saw.java.sh

# Or the following:
java -cp .:classes \
  --enable-native-access=ALL-UNNAMED \
  --add-modules jdk.incubator.foreign \
  PaexSaw

Known issues:

  1. (fixed) The Panama version (this file), is too loud and may have some timing issue as the sound doesn't sound the same as the high pitch of the native C version.
  2. This version is for MacOS and Linux at the moment.
  3. (fixed) One setting is different. To have the same settings for SAMPLE_RATE the example would be too loud!!! So, it's currently at 22050 hz.
You might also like...

Weatherapp is a simple weather forecast app that uses some APIs to retrieve forecast data from OpenWeatherMap.

WeatherMobileApp Weatherapp is a simple weather forecast app that uses some APIs to retrieve forecast data from OpenWeatherMap. Table of Contents Tech

Jan 17, 2022

The Distributed Application Runtime (Dapr) provides APIs that simplify microservice connectivity

The Distributed Application Runtime (Dapr) provides APIs that simplify microservice connectivity

Quarkus - Dapr Introduction What is Quarkus? Traditional Java stacks were engineered for monolithic applications with long startup times and large mem

Jan 5, 2023

Source code of course - Building Real-Time REST APIs with Spring Boot

springboot-blog-rest-api Learn how to build real-time REST APIs with Spring Boot by building a complete Blog App. Source code of Popular Building Real

Jan 6, 2023

Projeto criado no Santander Dev Week 2022 + DIO com o intuito de desenvolver uma camada de APIs (backend) que será utilizada pelo frontend.

Santader Dev Week + DIO 2022 - APIs Backend da aplicação de movimentação financeira Este repositório contém o backend da aplicação que foi desenvolvid

Sep 7, 2022

Library App - Using Android studio / Final project

Library-App Library App - Using Android studio / Final project Screens SplashScreen: it’s launcher activity will be moved to MainActivity auto after 2

Feb 2, 2022

This project is a simple messaging application made using React-Native framework, Gifted-Chat library and Firebase database

This project is a simple messaging application made using React-Native framework, Gifted-Chat library and Firebase database. The example that will be shown here focuses on the ability of two people to message each other in a chat room.

Jan 30, 2022

The project aim at easier to start a spring boot/cloud project.

easy-starters 是一个公共 starter 集合,旨在帮助 java 开发者快速构建 Springboot 与 Spring Cloud 项目. lx-starters的环境要求 JDK requirement: JDK 1.8+ Spring booter 2.x,+ 如何引用lx-s

Jul 11, 2022

This project is an Android Studio plugin version of BlackObfuscator, it supports obfuscating code automatically. More information about this project are in BlackObfuscator.

DEX控制流混淆插件版 · BlackObfuscator-ASPlugin English Version 本项目为 BlackObfuscator 的Android Studio插件版,支持打包自动化混淆。功能及介绍方面请查看 BlackObfuscator 源项目 注意事项 首要注意:Blac

Dec 31, 2022
Owner
Carl Dea
Developer Advocate
Carl Dea
An assistance platform made using Spring framework that analyses your code, and helps you either to start a devops project, or to turn an existing project into a devops project using open source software (Git, Docker, Jenkins..)

DevOpsify Description An assistance platform made using Spring framework that analyses your code, and helps you either to start a devops project, or t

obaydah bouifadene 14 Nov 8, 2022
High level api to interact with maven form within the jvm

maven-utils High level api to interact with maven from within the jvm Use it by adding the dependency to your maven pom: <dependency> <groupId>se.

Alipsa 5 Sep 29, 2022
This project demonstrates usage of Captcha, OTP APIs to access Offline eKYC XML.

Client Application to simulate offline eKYC wrapper API flow Introduction This is a Spring boot application which can be used to download offline eKYC

UIDAI 4 Oct 29, 2021
Rate limiting private REST APIs using Java Spring-boot, spring-security and bucket4j

Rate limiting REST APIs using Spring-security filter and Bucket4J Deployed Application (Swagger-ui on heroku) Inspired from: Baeldung Article Applicat

null 20 Jul 18, 2022
Java library that integrates to SAP Mobile Services Backend APIs

Java integration for SAP Mobile Services is a client library to integrate your application with the backend-facing APIs of SAP Mobile Services. As this project only started, it at the moment only provides the integration to the Notification Backend services, which allows you to send push notifications to your mobile devices. Other integrated APIs may be added to this library in the future.

SAP 7 Dec 15, 2022
BurritoSpigot is a fork of TacoSpigot 1.8.9 that offers several enhancements to performance as well as bug fixes. while offer extra APIs and support for plugins

?? BurritoSpigot ?? BurritoSpigot is a fork of TacoSpigot 1.8.8 that offers several enhancements to performance as well as bug fixes. while offer extr

Cobble Sword Services 44 Dec 20, 2022
APIKit:Discovery, Scan and Audit APIs Toolkit All In One.

APIKit:Discovery, Scan and Audit APIs Toolkit All In One.

APISecurity Community 976 Jan 9, 2023
Lightweight service-based PubSub, RPC and public APIs in Java

kite - service-based RPC, public APIs and PubSub in Java kite is a collection of reactive application messaging libraries that aim at providing high l

teris.io 3 Feb 17, 2022
This repository is related to the Java Web Developer (ND035), Course - Web Services and APIs

About this Repository This repository is related to the Java Web Developer (ND035), Course - Web Services and APIs It contains the following folders:

Rasha Omran 1 Jan 28, 2022
Squadio-App is a Users-Accounts financial system. exposes Rest APIs with JWT authentication/Authorization process .

squadio-app Description Squadio-App is a Users-Accounts financial system. exposes Rest APIs with JWT authentication/Authorization process . How to Run

Bashar Othman 1 Jan 29, 2022