Implement custom Java audio devices for AudioChain

Since AudioChain version 1.1.4, you can easily implement and integrate self made audio devices. Take a look at the following example classes which build a totally usable and complete audio device named 'Gain'. This device simply provides the feature to boost the whole audio level.

To build an audio device, there have to be implemented just two classes: the device and the reader. The device is a storable representation of the audio device. It holds all values and manages the creation of the reader. The reader makes the audio processing and implements the actual logic.

Class 1: the audio device

To build a very basic and generic audio device with no special user interface features, you can simply extend the AbstractChainableAudioDevice as stated below:

Class 2: the audio data reader

The audio data reader makes all the work while audio data becomes processed. The simplest way is to extend the class AbstractAudioDataReaderChainLink which remains you to implement the read method only. Take a look at the following example implementation:

Running the self made audio device

To run the self implemented audio device, it has to be compiled. For compilation you need to append the audiochain jar file to the classpath. One way to compile the classes is to copy the audiochain-x.x.x.jar and the audio device package (org/audiochain/devices/gain) to a single directory, then compile the classes on the command line as follows:

javac -d . -classpath audiochain-1.1.4.jar org/audiochain/devices/gain/*.java

The classes will be compiled into the current directory (as given by -d .). To integrate this compiled audio device into AudioChain, run the JVM with the parameter 'additionalAudioDeviceClasses'. For example:

java -DadditionalAudioDeviceClasses=org.audiochain.devices.gain.GainAudioDevice \
  -cp .:audiochain-1.1.4.jar org.audiochain.ui.gui.mixer.GuiAudioRecorder

Where the classpath (-cp) has to be set to the directory of the self compiled audio device classes. For this example this directory would contain the subdirectory 'org' where the class files belong. Find more detail information about this by searching the internet for "setting java classpath". The backslash means that the above displayed command has to be executed as one single line.

After the UI has started you can choose and add the custom device to any audio track. But notice: these new audio device classes form a dependency when the audio device is used and saved to a project file. The saved project cannot be opened, when the class files are not present on the classpath. If you want to work with the network synchronization, you have to distribute these classes to each AudioChain instance. If you accidentally have stored the project, you can remove the audio device entry from the file by editing it by hand. You may want to make a backup of your project file if you are unsure.

Audio Device Factory (since 1.1.5)

In some cases you might want to provide multiple different audio devices of the same implementation class. In this case you can implement the AudioDeviceFactory interface, that can create and return instances of distinct device types. The implemented factory must be stated by the runtime environment variable 'audioDeviceFactoryClasses'. The concrete AudioDevice implementation class can be kept encapsulated behind the factory and may not be stated additionally.