Is there any way to play a sound on a bare-bone linux distribution without any external libraries in c/c++
14:03 29 Apr 2025

I would like to know how to play a sound in linux c/c++ code (by no external library I mean using things that are either in libc/libgcc/libstdc++ or in the linux kernel & include directories) which also means NOT using neither libasound.so or PulseAudio or PipeWire (which from what I know depend on libasound)

From what I found you in the past could write to /dev/dsp but now (or in the nearer past) you had to load a special module for that to still work which is not ideal in my case, because I want my program to not require any setup from the user and to make as little changes to the system as possible

I also found a header file #include (which from what I know is a header file for Alsa Kernel API) but I haven't found any examples and the I can't find anything about playing a sound in it's documentation (ALSA Kernel API Documentation) & I believe that it's possible this way since from what I understand this is how asoundlib works

I tried analizing asoundlib, for how it works, but it's just such a large codebase, that I just can't comprehend it enouth to learn how exactly it works

I also know of a simpler audio library called tinyalsa, but I cannot get it to work (I think it's outdated (last release is from 2021)), so I can't learn from it's code 'cause it doesn't work

I'm would like to know a way that could play .wav files (I know that they're mostly raw sound bytes, or however they are called) but I'll accept hard-coded sound if there's no other option

I have read the answer to this question that is practicly the same, but the (only) answer there says to use asoundlib or pulseaudio or pipewire, whitch I don't want, and there it's accepted, so it probably won't recieve any other answer, that could answer my exact question

c linux linux-kernel