LWJGL Forum

Programming => OpenAL => Topic started by: codifies on November 08, 2015, 22:01:28

Title: real time audio creation
Post by: codifies on November 08, 2015, 22:01:28
Does anyone know how to do real time audio output...?

basically I want to have a continuously playing ring buffer, and be able to query at any particular time where the current output pointer is (so I can fill the buffer up behind it)

I'd like to be able to mix different signal sources in real time to create a simple synthesiser, I've made a simple logic editor where the gates are wired together with nice curvy "wires" rendered in javafx, and thought it might be nice to use the graphics part of the application to make a synth gui...

If anyone can show me code to fill an audio output buffer in real time I'd really appreciate it...

Tia!
Title: Re: real time audio creation
Post by: abcdef on November 09, 2015, 09:09:04
Lets break down your problem a bit as you ask quite a few things

1) How do you do real time audio output

This is accomplished with openal,

Check out some examples here :
https://github.com/LWJGL/lwjgl3/tree/master/modules/core/src/test/java/org/lwjgl/demo/openal

3) I'd like to have a continuously playing ring buffer

In openal load all you data in initially and then set the below for the source

alSourcei(source, AL_LOOPING, 1); enables it for a source and
alSourcei(source, AL_LOOPING, 0); disables it.

4) I'd like to be able to mix different signal sources in real time to create a simple synthesiser

You just need to create different sources and play them at the same time. If you wish to mix the signal's at the binary data level then I am unable to help you.

5) If anyone can show me code to fill an audio output buffer in real time

You need to have the data in PCM format. The STB extension of LWJGL has a way to load Ogg Vorbis file. The link above has an example of how to do this. If you wish to load other types or load other libraries you will need to see if a 3rd party API does this or do this yourself.
Title: Re: real time audio creation
Post by: philfrei on June 15, 2016, 02:01:26
[EDIT: I just found this (http://forum.lwjgl.org/index.php?topic=6011.0) followup post by codifies that looks like it is an answer to this question.]