{"id":13430250,"url":"https://github.com/andrewrk/libsoundio","last_synced_at":"2025-05-14T05:10:47.635Z","repository":{"id":41293843,"uuid":"38333501","full_name":"andrewrk/libsoundio","owner":"andrewrk","description":"C library for cross-platform real-time audio input and output","archived":false,"fork":false,"pushed_at":"2025-01-13T00:38:33.000Z","size":633,"stargazers_count":2005,"open_issues_count":129,"forks_count":238,"subscribers_count":56,"default_branch":"master","last_synced_at":"2025-04-11T00:45:42.045Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://libsound.io/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andrewrk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-06-30T21:14:56.000Z","updated_at":"2025-04-08T14:10:21.000Z","dependencies_parsed_at":"2024-01-31T09:01:08.029Z","dependency_job_id":"87ef619f-8cb6-4ee3-8c25-02172834acf8","html_url":"https://github.com/andrewrk/libsoundio","commit_stats":{"total_commits":351,"total_committers":33,"mean_commits":"10.636363636363637","dds":"0.16809116809116809","last_synced_commit":"49a1f78b50eb0f5a49d096786a95a93874a2592a"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewrk%2Flibsoundio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewrk%2Flibsoundio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewrk%2Flibsoundio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewrk%2Flibsoundio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrewrk","download_url":"https://codeload.github.com/andrewrk/libsoundio/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254076850,"owners_count":22010611,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T02:00:51.459Z","updated_at":"2025-05-14T05:10:47.568Z","avatar_url":"https://github.com/andrewrk.png","language":"C","funding_links":[],"categories":["C","Audio"],"sub_categories":[],"readme":"# libsoundio\n\nC library providing cross-platform audio input and output. The API is\nsuitable for real-time software such as digital audio workstations as well\nas consumer software such as music players.\n\nThis library is an abstraction; however in the delicate balance between\nperformance and power, and API convenience, the scale is tipped closer to\nthe former. Features that only exist in some sound backends are exposed.\n\n## Features and Limitations\n\n * Supported operating systems:\n   - Windows 7+\n   - MacOS 10.10+\n   - Linux 3.7+\n * Supported backends:\n   - [JACK](http://jackaudio.org/)\n   - [PulseAudio](http://www.freedesktop.org/wiki/Software/PulseAudio/)\n   - [ALSA](http://www.alsa-project.org/)\n   - [CoreAudio](https://developer.apple.com/library/mac/documentation/MusicAudio/Conceptual/CoreAudioOverview/Introduction/Introduction.html)\n   - [WASAPI](https://msdn.microsoft.com/en-us/library/windows/desktop/dd371455%28v=vs.85%29.aspx)\n   - Dummy (silence)\n * Exposes both raw devices and shared devices. Raw devices give you the best\n   performance but prevent other applications from using them. Shared devices\n   are default and usually provide sample rate conversion and format\n   conversion.\n * Exposes both device id and friendly name. id you could save in a config file\n   because it persists between devices becoming plugged and unplugged, while\n   friendly name is suitable for exposing to users.\n * Supports optimal usage of each supported backend. The same API does the\n   right thing whether the backend has a fixed buffer size, such as on JACK and\n   CoreAudio, or whether it allows directly managing the buffer, such as on\n   ALSA, PulseAudio, and WASAPI.\n * C library. Depends only on the respective backend API libraries and libc.\n   Does *not* depend on libstdc++, and does *not* have exceptions, run-time type\n   information, or [setjmp](http://latentcontent.net/2007/12/05/libpng-worst-api-ever/).\n * Errors are communicated via return codes, not logging to stdio.\n * Supports channel layouts (also known as channel maps), important for\n   surround sound applications.\n * Ability to monitor devices and get an event when available devices change.\n * Ability to get an event when the backend is disconnected, for example when\n   the JACK server or PulseAudio server shuts down.\n * Detects which input device is default and which output device is default.\n * Ability to connect to multiple backends at once. For example you could have\n   an ALSA device open and a JACK device open at the same time.\n * Meticulously checks all return codes and memory allocations and uses\n   meaningful error codes.\n * Exposes extra API that is only available on some backends. For example you\n   can provide application name and stream names which is used by JACK and\n   PulseAudio.\n\n## Synopsis\n\nComplete program to emit a sine wave over the default device using the best\nbackend:\n\n```c\n#include \u003csoundio/soundio.h\u003e\n\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \u003cstring.h\u003e\n#include \u003cmath.h\u003e\n\nstatic const float PI = 3.1415926535f;\nstatic float seconds_offset = 0.0f;\nstatic void write_callback(struct SoundIoOutStream *outstream,\n        int frame_count_min, int frame_count_max)\n{\n    const struct SoundIoChannelLayout *layout = \u0026outstream-\u003elayout;\n    float float_sample_rate = outstream-\u003esample_rate;\n    float seconds_per_frame = 1.0f / float_sample_rate;\n    struct SoundIoChannelArea *areas;\n    int frames_left = frame_count_max;\n    int err;\n\n    while (frames_left \u003e 0) {\n        int frame_count = frames_left;\n\n        if ((err = soundio_outstream_begin_write(outstream, \u0026areas, \u0026frame_count))) {\n            fprintf(stderr, \"%s\\n\", soundio_strerror(err));\n            exit(1);\n        }\n\n        if (!frame_count)\n            break;\n\n        float pitch = 440.0f;\n        float radians_per_second = pitch * 2.0f * PI;\n        for (int frame = 0; frame \u003c frame_count; frame += 1) {\n            float sample = sinf((seconds_offset + frame * seconds_per_frame) * radians_per_second);\n            for (int channel = 0; channel \u003c layout-\u003echannel_count; channel += 1) {\n                float *ptr = (float*)(areas[channel].ptr + areas[channel].step * frame);\n                *ptr = sample;\n            }\n        }\n        seconds_offset = fmodf(seconds_offset +\n            seconds_per_frame * frame_count, 1.0f);\n\n        if ((err = soundio_outstream_end_write(outstream))) {\n            fprintf(stderr, \"%s\\n\", soundio_strerror(err));\n            exit(1);\n        }\n\n        frames_left -= frame_count;\n    }\n}\n\nint main(int argc, char **argv) {\n    int err;\n    struct SoundIo *soundio = soundio_create();\n    if (!soundio) {\n        fprintf(stderr, \"out of memory\\n\");\n        return 1;\n    }\n\n    if ((err = soundio_connect(soundio))) {\n        fprintf(stderr, \"error connecting: %s\", soundio_strerror(err));\n        return 1;\n    }\n\n    soundio_flush_events(soundio);\n\n    int default_out_device_index = soundio_default_output_device_index(soundio);\n    if (default_out_device_index \u003c 0) {\n        fprintf(stderr, \"no output device found\");\n        return 1;\n    }\n\n    struct SoundIoDevice *device = soundio_get_output_device(soundio, default_out_device_index);\n    if (!device) {\n        fprintf(stderr, \"out of memory\");\n        return 1;\n    }\n\n    fprintf(stderr, \"Output device: %s\\n\", device-\u003ename);\n\n    struct SoundIoOutStream *outstream = soundio_outstream_create(device);\n    outstream-\u003eformat = SoundIoFormatFloat32NE;\n    outstream-\u003ewrite_callback = write_callback;\n\n    if ((err = soundio_outstream_open(outstream))) {\n        fprintf(stderr, \"unable to open device: %s\", soundio_strerror(err));\n        return 1;\n    }\n\n    if (outstream-\u003elayout_error)\n        fprintf(stderr, \"unable to set channel layout: %s\\n\", soundio_strerror(outstream-\u003elayout_error));\n\n    if ((err = soundio_outstream_start(outstream))) {\n        fprintf(stderr, \"unable to start device: %s\", soundio_strerror(err));\n        return 1;\n    }\n\n    for (;;)\n        soundio_wait_events(soundio);\n\n    soundio_outstream_destroy(outstream);\n    soundio_device_unref(device);\n    soundio_destroy(soundio);\n    return 0;\n}\n```\n\n### Backend Priority\n\nWhen you use `soundio_connect`, libsoundio tries these backends in order.\nIf unable to connect to that backend, due to the backend not being installed,\nor the server not running, or the platform is wrong, the next backend is tried.\n\n 0. JACK\n 0. PulseAudio\n 0. ALSA (Linux)\n 0. CoreAudio (OSX)\n 0. WASAPI (Windows)\n 0. Dummy\n\nIf you don't like this order, you can use `soundio_connect_backend` to\nexplicitly choose a backend to connect to. You can use `soundio_backend_count`\nand `soundio_get_backend` to get the list of available backends.\n\n[API Documentation](http://libsound.io/doc)\n\n### Building\n\nInstall the dependencies:\n\n * cmake\n * ALSA library (optional)\n * libjack2 (optional)\n * libpulseaudio (optional)\n\n```\nmkdir build\ncd build\ncmake ..\nmake\nsudo make install\n```\n\n### Building for Windows\n\nYou can build libsoundio with [mxe](http://mxe.cc/). Follow the\n[requirements](http://mxe.cc/#requirements) section to install the\npackages necessary on your system. Then somewhere on your file system:\n\n```\ngit clone https://github.com/mxe/mxe\ncd mxe\nmake MXE_TARGETS='x86_64-w64-mingw32.static i686-w64-mingw32.static' gcc\n```\n\nThen in the libsoundio source directory (replace \"/path/to/mxe\" with the\nappropriate path):\n\n```\nmkdir build-win32\ncd build-win32\ncmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/mxe/usr/i686-w64-mingw32.static/share/cmake/mxe-conf.cmake\nmake\n```\n\n```\nmkdir build-win64\ncd build-win64\ncmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/mxe/usr/x86_64-w64-mingw32.static/share/cmake/mxe-conf.cmake\nmake\n```\n\n### Testing\n\nFor each backend, do the following:\n\n 0. Run the unit tests: `./unit_tests`. To see test coverage, install lcov, run\n   `make coverage`, and then view `coverage/index.html` in a browser.\n 0. Run the example `./sio_list_devices` and make sure it does not crash, and\n    the output looks good. If valgrind is available, use it.\n 0. Run `./sio_list_devices --watch` and make sure it detects when you plug and\n    unplug a USB microphone.\n 0. Run `./sio_sine` and make sure you hear a sine wave. For backends with raw\n    devices, run `./sio_sine --device id --raw` (where 'id' is a device id you\n    got from `sio_list_devices` and make sure you hear a sine wave.\n    - Use 'p' to test pausing, 'u' to test unpausing, 'q' to test cleanup.\n    - 'c' for clear buffer. Clear buffer should not pause the stream and it\n      should also not cause an underflow.\n    - Use 'P' to test pausing from the callback, and then 'u' to unpause.\n 0. Run `./underflow` and read the testing instructions that it prints.\n 0. Run `./sio_microphone` and ensure that it is both recording and playing\n    back correctly. If possible use the `--in-device` and `--out-device`\n    parameters to test a USB microphone in raw mode.\n 0. Run `./backend_disconnect_recover` and read the testing instructions that\n    it prints.\n 0. Run `./latency` and make sure the printed beeps line up with the beeps that\n    you hear.\n\n### Building the Documentation\n\nEnsure that [doxygen](http://www.stack.nl/~dimitri/doxygen/) is installed,\nthen:\n\n```\nmake doc\n```\n\nThen look at `html/index.html` in a browser.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewrk%2Flibsoundio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrewrk%2Flibsoundio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewrk%2Flibsoundio/lists"}