https://codeberg.org/pkw/smplr/src/branch/win_draw/sound.c#L88

This is how I am currently playing sound files (wav) using
#sndio on #OpenBSD

(if you start browsing make sure to stay on the 'win_draw' branch)

smplr/sound.c at win_draw

smplr

Codeberg.org
I'm trying to figure out how to play multiple wav
files at the same time or over each other using sndio and C.

What I am going to try is this:

Create like 5 threads using pthreads.
Each of these threads is like a voice, so
you can have as many simultaneous sounds as
the number of threads.

Each thread calls sio_open(...) and acquires
a sndio PLAYBACK device handle.

The wav files will be opened ahead of time
and stored in an array. (they are libsndfile ojects)

I will try to use pthread_cond_init and pthread_cond_wait.
To signal the thread to start playback and which wav
file to play. (this will probably just be the array index of
the preloaded wave file array)

IDK if this will work, but it seems a reasonable thing
to try first.

* I was gonna do signals , but there's that whole thing
about what to do in the signal handler when you recieve
another signal ...

#openbsd #sndio #c #libsndfile

smplr

What you don't see is that ACS_BULLET symbol (the dot)
next to the word "smplr" is blinking VERY FAST to show
how I async I am.

#C #ncurses #sndio #openbsd #libevent
Super serious audio sampling tools:

this is my POC terminal audio sampler.

The noises are those three samples. The UI is you just press
the number of the sample and it plays it.
I am showing off the audio part.

The audio wav files are playing from scratch each
time, (like the sndio handle and the libsndfile handle
are not re-used). If I keep going on this I will
fix that so there is like a static list of wav files.
And I will re-use the sndio handle or i will
have like a sndio handle "pool".

I have previous curses programs where I use libevent
to make them not "one thing at a time".

So like you could play wav files over each other up
to the amount of sndio handles you have.
(theoretically)

A long shot goal is I could have the program be able
to record a wav file for you O_o.

#openbsd #sndio #chicken #scheme #c


I can play WAV files using C code on OpenBSD
using sndio and libsndfile !!!!

I am very happy.
If I can do it in C then I can do it from my chicken scheme
thing using FFI :)

#OpenBSD #sndio #libsndfile

https://github.com/libsndfile/libsndfile/blob/master/programs/sndfile-play.c#L358

Nice! This is an example from libsndfile repo playing
thru sndio :)

I am kinda too noodle-brain to look now, but this seems
the ticket.

I have like 8000 random search tabs open right now
about anything libsndfile sndio sio_open or openbsd.
I am closing them all and it's a relief. It's always
a relief to step back after trying stuff over and over.
And from different angles. It works pretty good.
It also works for guitar playing and skateboarding.
make progress , take a break, make progress, take a break ...


#sndio


libsndfile/programs/sndfile-play.c at master · libsndfile/libsndfile

A C library for reading and writing sound files containing sampled audio data. - libsndfile/libsndfile

GitHub
https://man.openbsd.org/sio_open

I am plodding thru playing a wav file using sndio on OpenBSD ...

#sndio #openbsd

I can call sio_open successfully so I think my next steps is
to attempt to read bytes from the wav file and write them
to the sndio decvice.

I assume that won't "just work" but it's something I can do
as I poke around in the dark with a candle :P


sio_open(3) - OpenBSD manual pages

I've been looking for a sound library like SDL to play
sound from a commandline app.

I have not found anything that I'm really happy with.
SDL3 sound libs aren't available yet (I don't want to package
them myself.)
I don't want to use SDL2 if sound is one of the biggest changes
in 3.
I was looking at allegro, but my OS packages an older version.
I had some working code using libao but it is pretty niche too.
Like I might as well just use the OS libs to do it...

https://man.openbsd.org/sio_open.3

I was surprised and not surprised to find this.
I like the OpenBSD audio stack, it's maintained and
modern. And if my app is successfull enuf to be ported
to another BSD or linux then someone else can
figure out the audio there.
(or SDL3 will be ubiquitous by then.)

#openbsd #sndio
sio_open(3) - OpenBSD manual pages

I learned some sndio and did some FFI in Scheme

This snippet plays a sine wave, and if you structure the code differently it allows you to livecode audio (directly on the audio thread, bytebeat-style). There is a crappy example at the bottom, for use with guile --listen + geiser-connect in another terminal window

I've got some more thoughts in the README, about livecoding audio synthesis approaches

https://patpatpat.xyz/data/schism/

#sndio #scheme #guile #livecoding

I'm still planning a rewrite of #Xsunaba, my #Xephyr #X11 #sandbox utility, and make it less #OpenBSD specific. In the meantime, I've updated the README re:correctly sharing the #sndio #cookie with the sandbox user if you want it to be able to play audio:

https://github.com/morgant/Xsunaba?tab=readme-ov-file#audio

GitHub - morgant/Xsunaba: Sandbox X11 applications on OpenBSD

Sandbox X11 applications on OpenBSD. Contribute to morgant/Xsunaba development by creating an account on GitHub.

GitHub