Show HN: Nanoalsa, asoundlib replacement for embedded systems
2 by bzt | 0 comments on Hacker News.
Hi, I wanted to use ALSA in an embedded system, and that's when I realized how bad the official asoundlib library actually is. It is huge, bloated, requires tons of configuration files, tries to load shared libraries in run-time, not thread-safe (due to the use of signals), often segfaults, and leaks memory badly (its developers arrogantly deny that, but valgrind confirms that it really does). Unfortunately the Linux ALSA interface isn't documented at all (there's a doc for sound card driver writers, called "kernel API", and the asoundlib high-level interface for applications, called "library API", but nothing about the ioctl interface, https://ift.tt/PYrHOcG ). So I was curious how much of the asoundlib's bloat we can get rid off. I've spent days figuring out what asoundlib actually does, and strace was my best friend during this experiment. https://ift.tt/iyVmR0B I've concluded my findings in Nano ALSA, an MIT licensed, stb-style single header library (12k, ca. 300 SLoC). It's based on the UNIX philosophy, "do one thing only, but do that right". So it can do one thing, and one thing only. It can be used to easily play PCM data, which is what most applications want. It does not load shared libraries in run-time, it does not use signals, it does not have a mixer nor a sequencer, just good ol' PCM playback all there is. K.I.S.S. Example usage: alsa_t ctx; /* internal state (few bytes only) */ alsa_open(&ctx, 0, 0, SNDRV_PCM_FORMAT_S16_LE, 44100, 2); /* specify requested characteristics */ alsa_write(&ctx, buf, numframes); /* play the audio */ alsa_close(&ctx); /* free resources */ That's all to it. (Also has an async interface too, which is unlike asoundlib's, signal-free and thread-safe.)
2 by bzt | 0 comments on Hacker News.
Hi, I wanted to use ALSA in an embedded system, and that's when I realized how bad the official asoundlib library actually is. It is huge, bloated, requires tons of configuration files, tries to load shared libraries in run-time, not thread-safe (due to the use of signals), often segfaults, and leaks memory badly (its developers arrogantly deny that, but valgrind confirms that it really does). Unfortunately the Linux ALSA interface isn't documented at all (there's a doc for sound card driver writers, called "kernel API", and the asoundlib high-level interface for applications, called "library API", but nothing about the ioctl interface, https://ift.tt/PYrHOcG ). So I was curious how much of the asoundlib's bloat we can get rid off. I've spent days figuring out what asoundlib actually does, and strace was my best friend during this experiment. https://ift.tt/iyVmR0B I've concluded my findings in Nano ALSA, an MIT licensed, stb-style single header library (12k, ca. 300 SLoC). It's based on the UNIX philosophy, "do one thing only, but do that right". So it can do one thing, and one thing only. It can be used to easily play PCM data, which is what most applications want. It does not load shared libraries in run-time, it does not use signals, it does not have a mixer nor a sequencer, just good ol' PCM playback all there is. K.I.S.S. Example usage: alsa_t ctx; /* internal state (few bytes only) */ alsa_open(&ctx, 0, 0, SNDRV_PCM_FORMAT_S16_LE, 44100, 2); /* specify requested characteristics */ alsa_write(&ctx, buf, numframes); /* play the audio */ alsa_close(&ctx); /* free resources */ That's all to it. (Also has an async interface too, which is unlike asoundlib's, signal-free and thread-safe.)