andrewrk / andrewrk/libsoundio

Amalgamated variant

Aperta
#151 1 commento 8 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C
Stelle
2.1k
Fork
254
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

I dare to ask if there is a plan to distribute an amalgamated variant of soundio?

So far my preference for dealing with audio has been RtAudio.cpp/RtMidi.cpp. They are easy to integrate into any project because they are just one cpp file and one header. However, I would love to replace those with anything written in C. Portaudio code looks like a mess, while libsoundio makes a very pleasant first impression.

I've ended up with the following bash script to produce an amalgamated version of libsoundio:

```bash
#!/bin/sh

AMALG_H=soundio_amalg.h
AMALG_C=soundio_amalg.c

cat soundio/endian.h soundio/soundio.h | sed 's!\(#include "endian.h"\)!// (amalg) \1!' > $AMALG_H

echo "#include \"$AMALG_H\"" > $AMALG_C
# I just didn't want to define versions manually
echo '#define SOUNDIO_VERSION_STRING ""' >> $AMALG_C
echo '#define SOUNDIO_VERSION_MAJOR 0' >> $AMALG_C
echo '#define SOUNDIO_VERSION_MINOR 0' >> $AMALG_C
echo '#define SOUNDIO_VERSION_PATCH 0' >> $AMALG_C

sed 's!\(#include ".*.h"\)!// (amalg) \1!' >> $AMALG_C << EOF
$(cat src/soundio_internal.h)
$(cat src/os.h)
$(cat src/atomics.h)
$(cat src/list.h)
$(cat src/ring_buffer.h)
$(cat src/util.h)
$(cat src/dummy.h)

#if SOUNDIO_HAVE_JACK
$(cat src/jack.h)
#endif
#if SOUNDIO_HAVE_ALSA
$(cat src/alsa.h)
#endif
#if SOUNDIO_HAVE_PULSEAUDIO
$(cat src/pulseaudio.h)
#endif
#if SOUNDIO_HAVE_COREAUDIO
$(cat src/coreaudio.h)
#endif
#if SOUNDIO_HAVE_WASAPI
$(cat src/wasapi.h)
#endif

$(cat src/soundio_private.h)

$(cat src/os.c)
$(cat src/ring_buffer.c)
$(cat src/util.c)
$(cat src/dummy.c)
$(cat src/soundio.c)
$(cat src/channel_layout.c)

#if SOUNDIO_HAVE_JACK
$(sed \
-e 's!refresh_devices(!jack_refresh_devices(!' \
-e 's!my_flush_events(!jack_my_flush_events(!' \
src/jack.c)
#endif
#if SOUNDIO_HAVE_ALSA
$(sed \
-e 's!refresh_devices(!alsa_refresh_devices(!' \
-e 's!my_flush_events(!alsa_my_flush_events(!' \
src/alsa.c)
#endif
#if SOUNDIO_HAVE_PULSEAUDIO
$(sed \
-e 's!set_all_device_channel_layouts(!pa_set_all_device_channel_layouts(!' \
-e 's!set_all_device_formats(!pa_set_all_device_formats(!' \
-e 's!refresh_devices(!pa_refresh_devices(!' \
-e 's!my_flush_events(!pa_my_flush_events(!' \
src/pulseaudio.c)
#endif
#if SOUNDIO_HAVE_COREAUDIO
$(cat src/coreaudio.c)
#endif
#if SOUNDIO_HAVE_WASAPI
$(cat src/wasapi.c)
#endif
EOF
```

I've tried to compile it with `-DSOUNDIO_HAVE_ALSA=1`, as well as jack/pulseaudio, and the most basic example seemed to work, so I hope I haven't broken too many things.

As you can see from the above snippet, amalgamation is a trivial process because libsoundio if very well structured (however there are some name collisions, but they are easy to resolve).

I strongly vote for amalgamation becasue I can now just drop in two files into my code base and I can use makefile, autotools, cmake or scons or just some handwritten build.sh.

So I wonder if there are any plans to distribute libsoundio in the amalgamated form as well?

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.