OpenAL-Ada CLI Doppler Effect 1 Linear
This program is a CLI Ada application that demonstrates the Doppler effect using OpenAL-Ada
Released 8/20/2025
Tested environment:
Ubuntu: 24.04.2 LTS, Gnat: 14.2.1, Gtkada:25.0.1
OpenAL-Ada(Coreland) 1.1.1, Alire 2.0.2
PC: OMEN 17-ck2095cl, i9-13900HX, RTX-4080
Audio source file
Tone: Mono, 44.1kHz, 16bit, 5sec, WAV file
Train: Mono, 44.1kHz, 16bit, 10sec, WAV file
Audio output device selection: PulseAudio Output Device captured with Audacity
You can hear stereo audio as the source moves from the listener’s left side, passes directly in front, and continues to the right side. A 1kHz tone is used to make the frequency changes more noticeable. The waveform below shows the left and right audio changes during this movement.
Project name: Cli_Doppler_1
The source code and project files are available on GitHub
Doppler Effect Tone Audio Output (11 sec)
Original Train Audio Input: train-testsound-44100-Mono-Original.wav
Doppler Effect Train Audio Output: train-doppler-effect-stereo.wav
A tone signal with 1-second interval markers is used as input.
The Audacity screenshot shows the Doppler effect results, where markers become compressed when the source approaches and stretched when it moves away.
Text screen output
Make the project with Alire command
~/ada/oal$ alr init cli_doppler_1 –bin
~/ada/oal$ alr init cli_doppler_1 --bin
Alire needs some user information to initialize the crate author and maintainer,
for eventual submission to the Alire community index. This information will be
interactively requested now.
You can edit this information at any time with 'alr config'
Enter a short description of the crate: (default: '')
>
Using default: ''
Please enter your email address: (default: 'example@example.com')
>
Using default: 'example@example.com'
Select a software license for the crate?
1. MIT OR Apache-2.0 WITH LLVM-exception
2. MIT
3. Apache-2.0 WITH LLVM-exception
4. Apache-2.0
5. BSD-3-Clause
6. LGPL-3.0-or-later
7. GPL-3.0-or-later WITH GCC-exception-3.1
8. GPL-3.0-or-later
9. Other...
Enter your choice index (first is default):
>
Enter a comma (',') separated list of tags to help people find your crate: (default: '')
>
Using default: ''
Enter an optional Website URL for the crate: (default: '')
>
Using default: ''
✓ cli_doppler_1 initialized successfully.
/ada/oal$ cd cli_doppler_1/
Create the following text file in the working directory
Source files list
./sourcefiles.txt
cli_doppler_1.adb
openal.ads
openal-alc_thin.ads
openal-buffer.adb
openal-buffer.ads
openal-context.adb
openal-context.ads
openal-context-capture.adb
openal-context-capture.ads
openal-context-error.adb
openal-context-error.ads
openal-error.adb
openal-error.ads
openal-extension.ads
openal-extension-efx.adb
openal-extension-efx.ads
openal-extension-efx_thin.adb
openal-extension-efx_thin.ads
openal-extension-float32.adb
openal-extension-float32.ads
openal-extension-float32_thin.ads
openal-global.adb
openal-global.ads
openal_info.adb
openal_info.ads
openal_info_main.adb
openal-list.adb
openal-list.ads
openal-listener.adb
openal-listener.ads
openal-load.adb
openal-load.ads
openal-source.adb
openal-source.ads
openal-thin.ads
openal-types.ads
NOTE:
The top file name is this project name.
The other files are all common for OpenAL-Ada.
Copy testsound.wav file
When running this application, the placement location of testsound.wav file varies depending on how the application is executed.
Therefore, place the same files in two locations until debugging is complete.
- GnatStudio Run button: Project root: ./ directory
- When executing from console: ./bin directory
Use GnatStudio to edit and build project
~/ada/oal/cli_doppler_1$ alr edit
GnatStudio
Display the default source code and update
Copy the source code to cli_doppler_1.adb
Edit project file: al_info.gpr with GnatStudio Wizard
Press “Edit” – ”Project Properties”
Setup OpenAL source files directory
“Directories” – “+” – “navigate usr” – “local” – “include” – “coreland” – “openal-ada” – “OK”
Press “Files” – “source list file” Radio button
“Browse” – choose “sourcefiles.txt” which you created – “OK”
“Build”—”Switches”—”Ada Linker” tab: Enter this line into the bottom rectangular box.
-lopenal -lalut
“Save” to close the properties window.
Press “Reload”
New project file: ./cli_doppler_1.gpr was created:
with "config/cli_doppler_1_config.gpr";
project Cli_Doppler_1 is
for Source_Dirs use ("src", "config", "../../../../../usr/local/include/coreland/openal-ada");
for Object_Dir use "obj/" & Cli_Doppler_1_Config.Build_Profile;
for Create_Missing_Dirs use "True";
for Exec_Dir use "bin";
for Main use ("cli_doppler_1.adb");
package Compiler is
for Default_Switches ("ada") use Cli_Doppler_1_Config.Ada_Compiler_Switches;
end Compiler;
package Binder is
for Switches ("Ada") use ("-Es"); -- Symbolic traceback
end Binder;
package Install is
for Artifacts (".") use ("share");
end Install;
for Source_List_File use "sourcefiles.txt";
package Linker is
for Switches ("ada") use ("-lopenal", "-lalut");
end Linker;
end Cli_Doppler_1;
Build Al_Info project
Build result message:Execution
The resulting executable file is created in the bin directory.
-rwxrwxr-x 1 mm mm 2271448 Aug 20 15:52 bin/cli_doppler_1
Build command just for reference:
gprbuild -d -P/home/mm/ada/oal/cli_doppler_1/cli_doppler_1.gpr -XADAFLAGS= /home/mm/ada/oal/cli_doppler_1/src/cli_doppler_1.adb |
Execution file was created in bin/ directory
Execution
Console Message
When running, the following messages are displayed in my environment:
$ ./bin/cli_doppler_1
OpenAL Test Program1
Default Playback=OpenAL Soft
Playback Devices N= 1
Playback Devices Length= 11
Playback Device# 1=OpenAL Soft
UB_Playback_Device=OpenAL Soft
GOOD, Open Output Device Success
GOOD, Create Context Success
Set_Active_Context GOOD: SUCCESS
File Open done
Sound File=testsound.wav
Format= 1 PCM
WAV Data Length= 441000 Byte
Sampling Freq= 44100Hz
Channel= 1
Sample= 16bit
Generated Buffer, WAV_Length= 441000 Byte
Generate-Sources (Sound_Source_Array) GOOD: SUCCESS
1 Number of Processed buffers= 0
Number of Processed buffers Queued= 0
Is_Vlaid=True
Attached buffer to Source
2 Number of Processed buffers= 0
Number of Processed buffers Queued= 1
Is_Vlaid=True
Set Source Set_Position_Float_List GOOD: SUCCESS
Set Source Set_Velocity_Float_List GOOD: SUCCESS
Set Source Set_Direction_Float_List GOOD: SUCCESS
Set Listener Set_Position_Float_List GOOD: SUCCESS
Set Listener Set_Velocity_Float_List GOOD: SUCCESS
Set Listener Orientation Fwd/Up GOOD: SUCCESS
Play(Sound_Source)
Last TimeCnt= 59
Audio Output