N7SD logo

HOME      INDEX

OpenAL_GtkAda_GUI_Doppler_Effect_1_Linear


This program is a GUI GtkAda application that demonstrates the Doppler effect using OpenAL-Ada.

Released 9/02/2025

Tested environment:
Ubuntu: 24.04.2 LTS, gcc:13.3.0, Gtkada:25.0.1

GNAT Studio 25.0w, Pulseaudio (pavucontrol)
OpenAL-Ada(Coreland) 1.1.1, Alire 2.0.2
PC1: OMEN 17-ck2095cl, i9-13900HX, 32GB, RTX-4080

PC2: HP ENVY 17t-S100, i7-6700HQ, 16GB, Intel HD Graphics 530

Audio source file: Mono, 44.1kHz, 16bit, WAV file

 

1. Tone Audio Doppler Effect Demo

You can listen to the Doppler effect as a 1000 Hz tone source moves from left to right or right to left relative to the listener.

As the source moves, the audio frequency shifts according to the Doppler effect, and you can hear the sound transition from your left ear to your right ear.

 

2. Passing Train Sound Doppler Effect Demo

This demo reproduces the sound of a passing train as if you were standing near a railroad crossing.

Similar to the tone demo, you can hear both the change in audio frequency due to movement and the shift in volume from left to right as the train passes.

The duration of the sound is adjusted based on the train’s length.

 

3. Additional Features

Select an audio WAV file

Choose direction of movement and enable looping

Adjust volume

Set source speed

Set listener distance from the track

Set source (train) length

Source files: https://github.com/moriyasum/OpenAL-Ada-GUI-Doppler-Effect-1-Linear

Gui-Doppler-app-1-tone-screen

Gui-Doppler-app-1-tone-screen

Original tone signal file

Input 1000Hz Tone Mono

 

 

4. Setup Environment

~$ cd ada/oal
~/ada/oal$ alr init gui_doppler_linear_1 –bin (Note: dash, dash)
Enter, Enter, Enter, Enter, Enter, Enter, Enter (all default)

 

~/ada/oal$ cd gui_doppler_linear_1

~/ada/oal/gui_doppler_linear_1$ alr with gtkada

Updating index... remote: Enumerating objects: 21, done.
remote: Counting objects: 100% (21/21), done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 18 (delta 7), reused 8 (delta 1), pack-reused 0 (from 0)
Unpacking objects: 100% (18/18), 4.92 KiB | 840.00 KiB/s, done.
From https://github.com/alire-project/alire-index
   24078a2..ac45ff6  stable-1.4.0 -> origin/stable-1.4.0
Updating 24078a2..ac45ff6
Fast-forward
 index/bf/bfdada/bfdada-1.3.1.toml     | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 index/cz/czmq_ada/czmq_ada-0.1.0.toml | 18 ++++++++++++++++++
 index/li/libbfd/libbfd-external.toml  | 16 ++++++++++++++++
 3 files changed, 96 insertions(+)
 create mode 100644 index/bf/bfdada/bfdada-1.3.1.toml
 create mode 100644 index/cz/czmq_ada/czmq_ada-0.1.0.toml
 create mode 100644 index/li/libbfd/libbfd-external.toml
◵ Solving dependencies: 0.00% solved (0/0 deps, 0/1 solutions left)... Looking for external crate: libgtk3..
◵ Solving dependencies: 0.00% solved (0/0 deps, 0/1 solutions left)... Looking for external crate: libgtk3..
◵ Solving dependencies: 0.00% solved (0/0 deps, 0/1 solutions left)... Looking for external crate: libgtk3..
◵ Solving dependencies: 25.00% solved (1/4 deps, 5/11 solutions left)... Looking for external crate: make…
◵ Solving dependencies: 25.00% solved (1/4 deps, 5/11 solutions left)... Looking for external crate: make…
◵ Solving dependencies: 25.00% solved (1/4 deps, 5/11 solutions left)... Looking for external crate: make…
◵ Solving dependencies: 25.00% solved (1/4 deps, 5/14 solutions left)... Looking for external crate: pkg_con
◵ Solving dependencies: 25.00% solved (1/4 deps, 5/14 solutions left)... Looking for external crate: pkg_con
◵ Solving dependencies: 25.00% solved (1/4 deps, 5/14 solutions left)... Looking for external crate: pkg_con
Requested changes:

   ✓ gtkada ^25.0.1 (add)

Changes to dependency solution:

   +   gtkada     25.0.1  (new)
   +📦 libgtk3    3.24.41 (new,indirect,system package)
   +📦 make       4.3.0   (new,indirect,system package)
   +📦 pkg_config 1.8.1   (new,indirect,system package)

Do you want to proceed?
[Y] Yes  [N] No  (default is Yes) Yes

~/ada/oal/gui_doppler_linear_1$ ls -al

total 36
drwxrwxr-x  6 mm mm 4096 Nov  5 11:05 .
drwxrwxr-x 15 mm mm 4096 Nov  5 11:05 ..
drwxrwxr-x  2 mm mm 4096 Nov  5 11:08 alire
-rw-rw-r--  1 mm mm  293 Nov  5 11:08 alire.toml
drwxrwxr-x  2 mm mm 4096 Nov  5 11:05 config
-rw-rw-r--  1 mm mm   29 Nov  5 11:05 .gitignore
-rw-rw-r--  1 mm mm  648 Nov  5 11:05 gui_doppler_linear_1.gpr
drwxrwxr-x  3 mm mm 4096 Nov  5 11:05 share
drwxrwxr-x  2 mm mm 4096 Nov  5 11:05 src

 

 

5. Download files from GitHub

Download files from here

Code – Download zip

Extract zip file

~/Downloads/OpenAL-Ada-GUI-Doppler-Effect-1-Linear-main$ ls -al

total 12944
drwxrwxr-x  2 mm mm    4096 Nov  4 23:56 .
drwxr-xr-x 12 mm mm    4096 Nov  5 11:19 ..
-rw-rw-r--  1 mm mm   26642 Nov  4 23:56 audio.adb
-rw-rw-r--  1 mm mm     396 Nov  4 23:56 audio.ads
-rw-rw-r--  1 mm mm 1619130 Nov  4 23:56 Doppler-Tone-42sec.webm
-rw-rw-r--  1 mm mm 1908531 Nov  4 23:56 Doppler-Train-51sec.webm
-rw-rw-r--  1 mm mm    3967 Nov  4 23:56 gui.adb
-rw-rw-r--  1 mm mm     361 Nov  4 23:56 gui.ads
-rw-rw-r--  1 mm mm 8228680 Nov  4 23:56 gui_doppler_linear_1
-rw-rw-r--  1 mm mm   13013 Nov  4 23:56 gui_doppler_linear_1.adb
-rw-rw-r--  1 mm mm    1328 Nov  4 23:56 gui_doppler_linear_1.gpr
-rw-rw-r--  1 mm mm    6351 Nov  4 23:56 gval.ads
-rw-rw-r--  1 mm mm   16460 Nov  4 23:56 process.adb
-rw-rw-r--  1 mm mm    3577 Nov  4 23:56 process.ads
-rw-rw-r--  1 mm mm    1393 Nov  4 23:56 README.md
-rw-rw-r--  1 mm mm     823 Nov  4 23:56 sourcefiles.txt
-rw-rw-r--  1 mm mm  441044 Nov  4 23:56 testsound.wav
-rw-rw-r--  1 mm mm  939886 Nov  4 23:56 train-testsound-44100-Mono-Original.wav

Copy the extracted files into the respective directories as shown below.

$ cp *.adb ~/ada/oal/gui_doppler_linear_1/src

$ cp *.ads ~/ada/oal/gui_doppler_linear_1/src

$ cp *.gpr ~/ada/oal/gui_doppler_linear_1/

$ cp *.txt ~/ada/oal/gui_doppler_linear_1/

$ mkdir ~/ada/oal/gui_doppler_linear_1/bin

$ cp *.wav ~/ada/oal/gui_doppler_linear_1/bin

 

6. Build

~/ada/oal/gui_doppler_linear_1$ alr build

Building gui_doppler_linear_1=0.1.0-dev/gui_doppler_linear_1.gpr...    
Setup
   [mkdir]        object directory for project Gui_Doppler_Linear_1
Compile
   [Ada]          gui_doppler_linear_1.adb
   [Ada]          gui.adb
   [Ada]          gval.ads
   [Ada]          process.adb
   [Ada]          openal.ads
   [Ada]          openal-buffer.adb
   [Ada]          openal-context.adb
   [Ada]          openal-error.adb
   [Ada]          openal-source.adb
   [Ada]          openal-types.ads
openal.ads:2:03: (style) bad indentation [-gnaty0]
openal-error.ads:19:03: (style) bad indentation [-gnaty0]
   [Ada]          openal-thin.ads
openal-types.ads:5:03: (style) bad indentation [-gnaty0]

   [Ada]          openal-alc_thin.ads
   [Ada]          openal-list.adb
openal-alc_thin.ads:1:04: (style) space required [-gnatyc]
openal-list.adb:7:03: (style) bad indentation [-gnaty0]
process.adb:18:23: warning: use clause for package "Source" has no effect [-gnatwu]
   [Ada]          audio.adb
   [Ada]          openal-listener.adb
openal-listener.adb:9:03: (style) bad indentation [-gnaty0]
   [Ada]          openal-global.adb
openal-global.adb:6:03: (style) bad indentation [-gnaty0]
Bind
   [gprbind]      gui_doppler_linear_1.bexch
   [Ada]          gui_doppler_linear_1.ali
Link
   [link]         gui_doppler_linear_1.adb
✓ Build finished successfully in 6.78 seconds.

At this point, a large number of “bad indentation”, “this line is too long”, “in should be omitted” and the other (style) warnings will be displayed, but you can ignore them all. 

Finally, if the link is completed and “Build finished successfully” is displayed, the build was successful.

check ./bin directory

/ada/oal/gui_doppler_linear_1$ cd bin

~/ada/oal/gui_doppler_linear_1/bin$ ls -al

total 9396
drwxrwxr-x 2 mm mm    4096 Nov  5 11:33 .
drwxrwxr-x 8 mm mm    4096 Nov  5 11:33 ..
-rwxrwxr-x 1 mm mm 8228688 Nov  5 11:33 gui_doppler_linear_1
-rw-rw-r-- 1 mm mm  441044 Nov  5 11:26 testsound.wav
-rw-rw-r-- 1 mm mm  939886 Nov  5 11:26 train-testsound-44100-Mono-Original.wav

 

7. Execution

~/ada/oal/gui_doppler_linear_1/bin$ ./gui_doppler_linear_1

Doppler Effect demo windows

 

8. How to Use

 

  1. Play Button
    Starts execution.
  2. Pause Button
    Temporarily pauses execution at the current position, but the audio output continues.
    You can resume with the Play button or end the process with the Stop button.
    The terminal displays the internal values at that moment.
  3. Stop Button
    Ends execution. The audio stops.
  4. File Chooser
    Selects the WAV file to be played.
    The default is a tone sound, but it can be switched to a train sound.
  5. Rightward / Leftward / Repeat Radio Buttons
    Set the movement pattern of the sound source.
    The default is Rightward — the source moves from the left end to the right end and then stops.
  6. Volume Slider
    Adjusts the playback volume.
  7. Source Speed
    Sets the movement speed of the sound source.
    Default: 100 km/h
  8. Distance End-to-End
    Sets the total travel distance of the source from the left end to the right end.
    Default: 200 meters
  9. Listener Offset
    The shortest distance between the listener and the source.
    Default: 2 meters
  10.  Source Length
    Sets the physical length of the source.
    Default: 4 meters
    Use this when the source has a significant length (e.g., a train) and takes time to pass by the listener.

 

9. Using GnatStudio

The build was first executed from the terminal, but you can also use GnatStudio for editing and building.

However, execution cannot be performed from GnatStudio — please run the program from the terminal.

~/ada/oal/gui_doppler_linear_1/bin$ cd ../

~/ada/oal/gui_doppler_linear_1$ alr edit

Gnatstudio screen for gui_doppler_1