Utility function for playing audio on Linux or MacOS.
- Author
- Edward A. Lee
-
Soroush Bateni
- Copyright
- (c) 2020-2023, The University of California at Berkeley and UT Dallas. License in BSD 2-clause
Audio functions for Linux or MacOS. To start an audio loop, call lf_start_audio_loop()
, passing it the logical time at which you would like the loop to start. To play a waveform, call lf_play_audio_waveform()
. A waveform may be synthesized or read from a .wav file using read_wave_file()
(see wave_file_reader.h).
To use this, include the following in your target properties:
files: [
"/lib/c/reactor-c/util/audio_loop_mac.c",
"/lib/c/reactor-c/util/audio_loop.h",
"/lib/c/reactor-c/util/audio_loop_linux.c",
],
cmake-include: [
"/lib/c/reactor-c/util/audio_loop.cmake"
]
In addition, you need this in your Lingua Franca file:
preamble {=
#include "audio_loop.h"
=}
Play the specified waveform with the specified emphasis at the specified time. If the waveform is null, play a simple tick (an impulse). If the waveform has length zero or volume 0, play nothing.
If the time is too far in the future (beyond the window of the current audio write buffer), then block until the audio output catches up. If the audio playback has already passed the specified point, then play the waveform as soon as possible and return 1. Otherwise, return 0.
- Parameters
-
waveform | The waveform to play or NULL to just play a tick. |
emphasis | The emphasis (0.0 for silence, 1.0 for waveform volume). |
start_time | The time to start playing the waveform. |