From 8caea521d74ed7cf756da1c7239202e1a80ba948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Wed, 6 May 2026 23:41:10 +0200 Subject: [PATCH] doc: compile tutorial programs The programs in `doc/examples` are not compiled currently, so let's compile them if the `docs` and `examples` options don't disallow it. `tutorial4.c` needs a small modification to avoid `-Wfloat-conversion`. Additionally, install them if `installed_tests` is not disabled. --- doc/examples/meson.build | 23 +++++++++++++++++++++++ doc/examples/tutorial4.c | 2 +- doc/meson.build | 18 +++++++----------- 3 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 doc/examples/meson.build diff --git a/doc/examples/meson.build b/doc/examples/meson.build new file mode 100644 index 000000000..8c1c26101 --- /dev/null +++ b/doc/examples/meson.build @@ -0,0 +1,23 @@ +tutorials = [ + 'tutorial1', + 'tutorial2', + 'tutorial3', + 'tutorial4', + 'tutorial5', + 'tutorial6', + 'tutorial7', +] + +if not get_option('examples').allowed() + subdir_done() +endif + +foreach c : tutorials + executable( + c, + sources: c + '.c', + dependencies: [ pipewire_dep, mathlib ], + install: installed_tests_enabled, + install_dir: installed_tests_execdir / 'examples', + ) +endforeach diff --git a/doc/examples/tutorial4.c b/doc/examples/tutorial4.c index 0b691fefd..65a708313 100644 --- a/doc/examples/tutorial4.c +++ b/doc/examples/tutorial4.c @@ -56,7 +56,7 @@ static void on_process(void *userdata) * Another common method to convert a double to * 16 bits is to multiple by 32768.0 and then clamp to * [-32768 32767] to get the full 16 bits range. */ - val = sin(data->accumulator) * DEFAULT_VOLUME * 32767.0; + val = (int16_t) (sin(data->accumulator) * DEFAULT_VOLUME * 32767.0); for (c = 0; c < DEFAULT_CHANNELS; c++) *dst++ = val; } diff --git a/doc/meson.build b/doc/meson.build index 645b4b26a..e5c2936dc 100644 --- a/doc/meson.build +++ b/doc/meson.build @@ -169,18 +169,14 @@ cssfiles = [ ] # Example files (in order from simple to esoteric) -example_files = [ - 'tutorial1.c', - 'tutorial2.c', - 'tutorial3.c', - 'tutorial4.c', - 'tutorial5.c', - 'tutorial6.c', - 'tutorial7.c', -] +example_files = [] example_dep_files = [] -foreach h : example_files - example_dep_files += ['examples/' + h] + +subdir('examples') + +foreach h : tutorials + example_files += [h + '.c'] + example_dep_files += ['examples/' + h + '.c'] endforeach foreach h : examples example_files += [h + '.c']