Giter Club home page Giter Club logo

libsoundio's Introduction

libsoundio

C library providing cross-platform audio input and output. The API is suitable for real-time software such as digital audio workstations as well as consumer software such as music players.

This library is an abstraction; however in the delicate balance between performance and power, and API convenience, the scale is tipped closer to the former. Features that only exist in some sound backends are exposed.

Features and Limitations

  • Supported operating systems:
    • Windows 7+
    • MacOS 10.10+
    • Linux 3.7+
  • Supported backends:
  • Exposes both raw devices and shared devices. Raw devices give you the best performance but prevent other applications from using them. Shared devices are default and usually provide sample rate conversion and format conversion.
  • Exposes both device id and friendly name. id you could save in a config file because it persists between devices becoming plugged and unplugged, while friendly name is suitable for exposing to users.
  • Supports optimal usage of each supported backend. The same API does the right thing whether the backend has a fixed buffer size, such as on JACK and CoreAudio, or whether it allows directly managing the buffer, such as on ALSA, PulseAudio, and WASAPI.
  • C library. Depends only on the respective backend API libraries and libc. Does not depend on libstdc++, and does not have exceptions, run-time type information, or setjmp.
  • Errors are communicated via return codes, not logging to stdio.
  • Supports channel layouts (also known as channel maps), important for surround sound applications.
  • Ability to monitor devices and get an event when available devices change.
  • Ability to get an event when the backend is disconnected, for example when the JACK server or PulseAudio server shuts down.
  • Detects which input device is default and which output device is default.
  • Ability to connect to multiple backends at once. For example you could have an ALSA device open and a JACK device open at the same time.
  • Meticulously checks all return codes and memory allocations and uses meaningful error codes.
  • Exposes extra API that is only available on some backends. For example you can provide application name and stream names which is used by JACK and PulseAudio.

Synopsis

Complete program to emit a sine wave over the default device using the best backend:

#include <soundio/soundio.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

static const float PI = 3.1415926535f;
static float seconds_offset = 0.0f;
static void write_callback(struct SoundIoOutStream *outstream,
        int frame_count_min, int frame_count_max)
{
    const struct SoundIoChannelLayout *layout = &outstream->layout;
    float float_sample_rate = outstream->sample_rate;
    float seconds_per_frame = 1.0f / float_sample_rate;
    struct SoundIoChannelArea *areas;
    int frames_left = frame_count_max;
    int err;

    while (frames_left > 0) {
        int frame_count = frames_left;

        if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count))) {
            fprintf(stderr, "%s\n", soundio_strerror(err));
            exit(1);
        }

        if (!frame_count)
            break;

        float pitch = 440.0f;
        float radians_per_second = pitch * 2.0f * PI;
        for (int frame = 0; frame < frame_count; frame += 1) {
            float sample = sinf((seconds_offset + frame * seconds_per_frame) * radians_per_second);
            for (int channel = 0; channel < layout->channel_count; channel += 1) {
                float *ptr = (float*)(areas[channel].ptr + areas[channel].step * frame);
                *ptr = sample;
            }
        }
        seconds_offset = fmodf(seconds_offset +
            seconds_per_frame * frame_count, 1.0f);

        if ((err = soundio_outstream_end_write(outstream))) {
            fprintf(stderr, "%s\n", soundio_strerror(err));
            exit(1);
        }

        frames_left -= frame_count;
    }
}

int main(int argc, char **argv) {
    int err;
    struct SoundIo *soundio = soundio_create();
    if (!soundio) {
        fprintf(stderr, "out of memory\n");
        return 1;
    }

    if ((err = soundio_connect(soundio))) {
        fprintf(stderr, "error connecting: %s", soundio_strerror(err));
        return 1;
    }

    soundio_flush_events(soundio);

    int default_out_device_index = soundio_default_output_device_index(soundio);
    if (default_out_device_index < 0) {
        fprintf(stderr, "no output device found");
        return 1;
    }

    struct SoundIoDevice *device = soundio_get_output_device(soundio, default_out_device_index);
    if (!device) {
        fprintf(stderr, "out of memory");
        return 1;
    }

    fprintf(stderr, "Output device: %s\n", device->name);

    struct SoundIoOutStream *outstream = soundio_outstream_create(device);
    outstream->format = SoundIoFormatFloat32NE;
    outstream->write_callback = write_callback;

    if ((err = soundio_outstream_open(outstream))) {
        fprintf(stderr, "unable to open device: %s", soundio_strerror(err));
        return 1;
    }

    if (outstream->layout_error)
        fprintf(stderr, "unable to set channel layout: %s\n", soundio_strerror(outstream->layout_error));

    if ((err = soundio_outstream_start(outstream))) {
        fprintf(stderr, "unable to start device: %s", soundio_strerror(err));
        return 1;
    }

    for (;;)
        soundio_wait_events(soundio);

    soundio_outstream_destroy(outstream);
    soundio_device_unref(device);
    soundio_destroy(soundio);
    return 0;
}

Backend Priority

When you use soundio_connect, libsoundio tries these backends in order. If unable to connect to that backend, due to the backend not being installed, or the server not running, or the platform is wrong, the next backend is tried.

  1. JACK
  2. PulseAudio
  3. ALSA (Linux)
  4. CoreAudio (OSX)
  5. WASAPI (Windows)
  6. Dummy

If you don't like this order, you can use soundio_connect_backend to explicitly choose a backend to connect to. You can use soundio_backend_count and soundio_get_backend to get the list of available backends.

API Documentation

Building

Install the dependencies:

  • cmake
  • ALSA library (optional)
  • libjack2 (optional)
  • libpulseaudio (optional)
mkdir build
cd build
cmake ..
make
sudo make install

Building for Windows

You can build libsoundio with mxe. Follow the requirements section to install the packages necessary on your system. Then somewhere on your file system:

git clone https://github.com/mxe/mxe
cd mxe
make MXE_TARGETS='x86_64-w64-mingw32.static i686-w64-mingw32.static' gcc

Then in the libsoundio source directory (replace "/path/to/mxe" with the appropriate path):

mkdir build-win32
cd build-win32
cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/mxe/usr/i686-w64-mingw32.static/share/cmake/mxe-conf.cmake
make
mkdir build-win64
cd build-win64
cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/mxe/usr/x86_64-w64-mingw32.static/share/cmake/mxe-conf.cmake
make

Testing

For each backend, do the following:

  1. Run the unit tests: ./unit_tests. To see test coverage, install lcov, run make coverage, and then view coverage/index.html in a browser.
  2. Run the example ./sio_list_devices and make sure it does not crash, and the output looks good. If valgrind is available, use it.
  3. Run ./sio_list_devices --watch and make sure it detects when you plug and unplug a USB microphone.
  4. Run ./sio_sine and make sure you hear a sine wave. For backends with raw devices, run ./sio_sine --device id --raw (where 'id' is a device id you got from sio_list_devices and make sure you hear a sine wave.
    • Use 'p' to test pausing, 'u' to test unpausing, 'q' to test cleanup.
    • 'c' for clear buffer. Clear buffer should not pause the stream and it should also not cause an underflow.
    • Use 'P' to test pausing from the callback, and then 'u' to unpause.
  5. Run ./underflow and read the testing instructions that it prints.
  6. Run ./sio_microphone and ensure that it is both recording and playing back correctly. If possible use the --in-device and --out-device parameters to test a USB microphone in raw mode.
  7. Run ./backend_disconnect_recover and read the testing instructions that it prints.
  8. Run ./latency and make sure the printed beeps line up with the beeps that you hear.

Building the Documentation

Ensure that doxygen is installed, then:

make doc

Then look at html/index.html in a browser.

libsoundio's People

Contributors

andrewrk avatar aoeu avatar atsushieno avatar avitex avatar capr avatar cgutman avatar clehner avatar crunkle avatar diogocp avatar goalitium avatar hasufell avatar icedragon200 avatar ideoforms avatar inolen avatar jacquesh avatar ligfx avatar masonremaley avatar misterda avatar naftoreiclag avatar nyorain avatar peteck avatar peterino2 avatar rsubtil avatar slin avatar tokyovigilante avatar ul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libsoundio's Issues

ALSA cleanup deadlock

Sometimes when destroying an ALSA outstream, one thread is waiting on a poll while the other thread is waiting on the first thread to exit. The poll should include another fd which the second thread can activate to ensure that the first thread's poll will return.

iOS support

It would be immensely useful and brilliant to have libsoundio support the iOS platform.

Compatibility with older ALSA

Hi,

Older ALSA (Ubuntu 10) does not have support for channel mapping. Could we have an #ifdef for that? A runtime check would be even better if at all possible.

Thanks.

Format differences between portaudio and libsoundio

Hi Andrew,

Thanks for your great soundio library. I’ve been looking for a good replacement for port audio and libsoundio look really really nice.

I’m listing the capabilities of a device, but a device for which portaudio tells me to have a 16bit format is not found by libsoundio. How is it possible that there is a difference between formats?

Thanks
roxlu

Compile time error in JACK back end

The error as printed by the compiler is thus:

/home/zistack/Program_Files/libsoundio-1.0.0/src/jack.cpp: In function ‘int soundio_jack_init(SoundIoPrivate*)’:
/home/zistack/Program_Files/libsoundio-1.0.0/src/jack.cpp:919:84: error: invalid conversion from ‘void (*)(jack_port_id_t, const char*, const char*, void*) {aka void (*)(unsigned int, const char*, const char*, void*)}’ to ‘JackPortRenameCallback {aka int (*)(unsigned int, const char*, const char*, void*)}’ [-fpermissive]
     if ((err = jack_set_port_rename_callback(sij->client, port_rename_calllback, si))) {
                                                                                    ^
In file included from /home/zistack/Program_Files/libsoundio-1.0.0/src/jack.hpp:15:0,
                 from /home/zistack/Program_Files/libsoundio-1.0.0/src/jack.cpp:8:
/usr/include/jack/jack.h:523:5: note:   initializing argument 2 of ‘int jack_set_port_rename_callback(jack_client_t*, JackPortRenameCallback, void*)’
 int jack_set_port_rename_callback (jack_client_t *client,
     ^

It would appear that you're trying to hand a void returning function into a place that expects an int returning function.

The compiler also complains about one of the flags passed to it.

At global scope:
cc1plus: error: unrecognized command line option ‘-Wno-c99-extensions’ [-Werror]

This may or may not be related.

I am running Arch Linux. The first thing that I did when I saw this was sync my machine and try again, thinking that a header on the system could be wrong. This did not work. I'm not sure what other information you're going to need. I am knowledgable about my system, so just ask.

Can't compile on MacOSX

Here's what I've tried, and error:

cmake .

-- The C compiler identification is AppleClang 6.1.0.6020053
-- The CXX compiler identification is AppleClang 6.1.0.6020053
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Configuring libsoundio version 1.0.0
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE  
-- Found JACK: /usr/local/lib/libjack.dylib  
-- Could NOT find PULSEAUDIO (missing:  PULSEAUDIO_LIBRARY PULSEAUDIO_INCLUDE_DIR) 
-- Could NOT find ALSA (missing:  ALSA_LIBRARY ALSA_INCLUDE_DIR) 
-- Found COREAUDIO: /System/Library/Frameworks/CoreAudio.framework  
-- Could NOT find WASAPI (missing:  WASAPI_INCLUDE_DIR) 
-- Check if the system is big endian
-- Searching 16 bit integer
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of unsigned short
-- Check size of unsigned short - done
-- Using unsigned short
-- Check if the system is big endian - little endian

Installation Summary
--------------------
* Install Directory            : /usr/local
* Build Type                   : Debug
* Build static libs            : ON
* Build examples               : ON
* Build tests                  : ON

System Dependencies
-------------------
* threads                      : OK
* JACK       (optional)        : OK
* PulseAudio (optional)        : not found
* ALSA       (optional)        : not found
* CoreAudio  (optional)        : OK
* WASAPI     (optional)        : not found

-- Configuring done
-- Generating done
-- Build files have been written to: /Users/seth/workspace/libsoundio

make

Scanning dependencies of target libsoundio_shared
[  1%] Building CXX object CMakeFiles/libsoundio_shared.dir/src/soundio.cpp.o
[  3%] Building CXX object CMakeFiles/libsoundio_shared.dir/src/util.cpp.o
[  5%] Building CXX object CMakeFiles/libsoundio_shared.dir/src/os.cpp.o
[  7%] Building CXX object CMakeFiles/libsoundio_shared.dir/src/dummy.cpp.o
[  9%] Building CXX object CMakeFiles/libsoundio_shared.dir/src/channel_layout.cpp.o
[ 11%] Building CXX object CMakeFiles/libsoundio_shared.dir/src/ring_buffer.cpp.o
[ 13%] Building CXX object CMakeFiles/libsoundio_shared.dir/src/jack.cpp.o
[ 15%] Building CXX object CMakeFiles/libsoundio_shared.dir/src/coreaudio.cpp.o
[ 17%] Linking C shared library libsoundio.dylib
ld: file not found: /usr/local/lib/libdb-5.3.dylib for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libsoundio.1.0.0.dylib] Error 1
make[1]: *** [CMakeFiles/libsoundio_shared.dir/all] Error 2
make: *** [all] Error 2

What is libdb? Berkeley DB, right? I did a check and couldn't find where it was being used in this library, but maybe I missed it. Do I need to install 5.3 Berkeley DB or do I have something strange going on in my environment?

Thanks!

OS X crash in unit test 'create output stream'

I'm seeing two persistent crashes on my machine (10.11.2, early-2008 MacBook Pro). When running unit_tests I get either a malloc error (incorrect checksum for freed object) with this backtrace:

frame #0: 0x00007fff8bcafbfb libsystem_malloc.dylib`tiny_malloc_from_free_list + 1327
frame #1: 0x00007fff8bcae715 libsystem_malloc.dylib`szone_malloc_should_clear + 292
frame #2: 0x00007fff8bcae5b1 libsystem_malloc.dylib`malloc_zone_malloc + 71
frame #3: 0x00007fff8d7da5ed CoreFoundation`_CFRuntimeCreateInstance + 301
frame #4: 0x00007fff8d7dcaf0 CoreFoundation`__CFStringCreateImmutableFunnel3 + 2672
frame #5: 0x00007fff8d7efe41 CoreFoundation`CFStringCreateCopy + 433
frame #6: 0x00007fff8d921836 CoreFoundation`_CFURLCreateWithURLString + 2326
frame #7: 0x00007fff8d7f0dc0 CoreFoundation`CFURLCopyAbsoluteURL + 544
frame #8: 0x00007fff8d90e220 CoreFoundation`_CFBundleCopyLProjDirectoriesForURL + 64
frame #9: 0x00007fff8d8298c1 CoreFoundation`CFBundleCopyBundleLocalizations + 369
frame #10: 0x00007fff8d90ddcf CoreFoundation`_CFBundleCopyLanguageSearchListInBundle + 47
frame #11: 0x00007fff8d8e8893 CoreFoundation`_copyQueryTable + 51
frame #12: 0x00007fff8d8e8072 CoreFoundation`_copyResourceURLsFromBundle + 370
frame #13: 0x00007fff8d8282e6 CoreFoundation`_CFBundleCopyFindResources + 1206
frame #14: 0x00007fff8d827e20 CoreFoundation`CFBundleCopyResourceURL + 64
frame #15: 0x00007fff8d827cc3 CoreFoundation`CFBundleGetLocalInfoDictionary + 83
frame #16: 0x00007fff8d827c31 CoreFoundation`CFBundleGetValueForInfoDictionaryKey + 33
frame #17: 0x00007fff8e2c2e6f AudioToolbox`AudioComponentPluginLoader::QueryBundle(__CFURL const*, std::__1::function<void (__CFURL const*, __CFBundle*, AudioComponentRegistrationInfo const&, __CFArray const*&)>) + 101
frame #18: 0x00007fff8e1b99e9 AudioToolbox`AudioComponentPluginLoader::ScanForPluginsInDirectory(char const*) + 307
frame #19: 0x00007fff8e2c2d45 AudioToolbox`AudioComponentPluginLoader::ScanForPlugins(unsigned int, bool) + 281
frame #20: 0x00007fff8e2c1bed AudioToolbox`AudioComponentPluginMgr::initLoader(unsigned int) + 73
frame #21: 0x00007fff8e2c1b7b AudioToolbox`AudioComponentPluginMgr::prepare(unsigned int) + 137
frame #22: 0x00007fff8e1bf743 AudioToolbox`AudioComponentPluginMgr::FindNext(OpaqueAudioComponent*, AudioComponentDescription const&) + 471
frame #23: 0x00007fff8e2bc53d AudioToolbox`AudioComponentFindNext + 140
frame #24: 0x000000010001c1f5 unit_tests`outstream_open_ca(si=0x0000000100100200, os=0x000000010022a6e0) + 405 at coreaudio.c:937
frame #25: 0x000000010000b247 unit_tests`soundio_outstream_open(outstream=0x000000010022a6e0) + 1271 at soundio.c:517
frame #26: 0x00000001000027d9 unit_tests`test_create_outstream + 713 at unit_tests.c:48
frame #27: 0x0000000100002346 unit_tests`exec_test(test=0x000000010002c7a0) + 102 at unit_tests.c:231
frame #28: 0x000000010000228d unit_tests`main(argc=1, argv=0x00007fff5fbffb08) + 477 at unit_tests.c:245
frame #29: 0x00007fff8593c5ad libdyld.dylib`start + 1
frame #30: 0x00007fff8593c5ad libdyld.dylib`start + 1

Or an assert fires:

testing create output stream...Assertion failed: (device->ref_count >= 0), function soundio_device_unref, file /Users/aidan/programming/audio/libsoundio-1.1.0/src/soundio.c, line 394.

<frames 0-3 are the assert>
frame #4: 0x000000010000a558 unit_tests`soundio_device_unref(device=0x000000010011f410) + 296 at soundio.c:394
frame #5: 0x0000000100008dd8 unit_tests`soundio_destroy_devices_info(devices_info=0x000000010011df70) + 280 at soundio.c:680
frame #6: 0x0000000100008385 unit_tests`soundio_disconnect(soundio=0x0000000100200170) + 341 at soundio.c:258
frame #7: 0x000000010000821d unit_tests`soundio_destroy(soundio=0x0000000100200170) + 77 at soundio.c:168
frame #8: 0x00000001000027fb unit_tests`test_create_outstream + 747 at unit_tests.c:52
frame #9: 0x0000000100002346 unit_tests`exec_test(test=0x000000010002c7a0) + 102 at unit_tests.c:231
frame #10: 0x000000010000228d unit_tests`main(argc=1, argv=0x00007fff5fbffb08) + 477 at unit_tests.c:245

Happens every time, in 'create output stream'. My audio setup is standard, except that I have Soundflower installed, and have created an aggregate device going out to Soundflower and the headphones. However, the output is set to the default in System Preferences.

Build obstacle on debian stable

Here, I will describe a build problem that happens when I try to compile libsoundio under a debian stable environment.

= Background

Here's my system:
memlab$ uname -a
Linux memlab 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt20-1+deb8u3 (2016-01-17) x86_64 GNU/Linux
memlab$ apt-cache show clang | grep Version
Version: 1:3.5-25
memlab$

I downloaded libsoundio-1.1.0.tar.gz and unpacked it.

= Cmake steps

$ cd libsoundio-1.1.0; mkdir build; cd build; cmake ..
-- The C compiler identification is Clang 3.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
Configuring libsoundio version 1.1.0
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found JACK: /usr/lib/x86_64-linux-gnu/libjack.so
-- Found PULSEAUDIO: /usr/lib/x86_64-linux-gnu/libpulse.so
-- Found ALSA: /usr/lib/x86_64-linux-gnu/libasound.so (found version "1.0.28")
-- Could NOT find COREAUDIO (missing: COREAUDIO_LIBRARY COREAUDIO_INCLUDE_DIR)
-- Could NOT find WASAPI (missing: WASAPI_INCLUDE_DIR)

Installation Summary

  • Install Directory : /usr/local
  • Build Type : Debug
  • Build static libs : ON
  • Build examples : ON
  • Build tests : ON

System Dependencies

  • threads : OK
  • JACK (optional) : OK
  • PulseAudio (optional) : OK
  • ALSA (optional) : OK
  • CoreAudio (optional) : not found
  • WASAPI (optional) : not found

-- Configuring done
-- Generating done
-- Build files have been written to: /home/cturner/saga/20160304.memlab.cturner.ad.libsoundio/000.poc/libsoundio-1.1.0/build
$

= Make

memlab$ make
Scanning dependencies of target libsoundio_shared
[ 2%] Building C object CMakeFiles/libsoundio_shared.dir/src/soundio.c.o
/home/cturner/saga/20160304.memlab.cturner.ad.libsoundio/000.poc/libsoundio-1.1.0/src/soundio.c:180:47: error: illegal initializer type 'atomic_flag' (aka
'_Atomic(struct (anonymous struct at /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/include/stdatomic.h:232:17))')
static struct SoundIoAtomicFlag rtprio_seen = SOUNDIO_ATOMIC_FLAG_INIT;
^
/home/cturner/saga/20160304.memlab.cturner.ad.libsoundio/000.poc/libsoundio-1.1.0/src/atomics.h:68:35: note: expanded from macro 'SOUNDIO_ATOMIC_FLAG_INIT'

define SOUNDIO_ATOMIC_FLAG_INIT {ATOMIC_FLAG_INIT}

                              ^

/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/include/stdatomic.h:241:26: note: expanded from macro 'ATOMIC_FLAG_INIT'

define ATOMIC_FLAG_INIT { 0 }

                            ^

1 error generated.
CMakeFiles/libsoundio_shared.dir/build.make:54: recipe for target 'CMakeFiles/libsoundio_shared.dir/src/soundio.c.o' failed
make[2]: *** [CMakeFiles/libsoundio_shared.dir/src/soundio.c.o] Error 1
CMakeFiles/Makefile2:192: recipe for target 'CMakeFiles/libsoundio_shared.dir/all' failed
make[1]: *** [CMakeFiles/libsoundio_shared.dir/all] Error 2
Makefile:117: recipe for target 'all' failed
make: *** [all] Error 2
memlab$

= Notes

I'd be happy to be a part of the solution for this, but I'm not particularly skilled with compiler tool-chains and would benefit from guidance.

Shortly after building this, I also tried to build zig language. Zig failed because debian stable is running an older version of LLVM than is required by zig.

This makes me think - an approach to fixing this might be for me to create a compiler toolchain in isolation. For example, a barebones linux under qemu, and then install tools from source towards being able to build this. I could put some towards this, but - again - would appreciate guidance on what to focus on.

cannot compile with gcc 4.4.7

Can't compile. Is there a file missing from the git repo?

libsoundio/src/atomics.h:14:10: fatal error: 'stdatomic.h' file not found

ability to compile libsoundio source with MSVC

@hotgloupi says

What is the use case for compiling libsoundio with visual c++?

Well, there can be many use cases for the users:

  • Seamlessly build libsoundio as part of the project
  • Honor the build variants (threading mode, debug mode, static vs dynamic
    runtime, debug runtime mode)
  • Being able to compile the HEAD in a windows environment (without waiting
    for an external cross-compiled binary)
  • Using the VS debugger
  • Being able to hack libsoundio in VS (like to make Windows store
    friendly, or to build for IOS/Android from VS, etc.)

There might be more advantages, I'm not a windows guys, but I know that
many multimedia guys are working / targeting a windows environment.

Stating that the project only compiles using gcc will stop many windows
users to use/contribute to libsoundio.

That being said, I will make it compile on visual c++, I was only asking
for some guidance, even if my work won't ever be merged back.

ability to open a duplex stream

The concept of opening a stream simultaneously for input and output exists, but libsoundio does not support it. It's one thing that PortAudio currently does better than libsoundio.

This likely entails an API overhaul and 2.0.0.

Once this is done and works correctly, the microphone example no longer would need a ring buffer, so it would be that much more efficient. And then the only usage of a ring buffer would be the dummy backend, and that can be easily replaced by something trivial (and doesn't waste time actually copying memory).

So this probably means deleting the ring buffer from the API and deleting the internal implementation. This is in service of libsoundio's goal of being a lightweight abstraction.

Create a test for the latency / synchronization API.

  • Input is an audio file and some events indexed at particular frame - when
    listening the events should line up exactly with a beat or visual
    indicator, even when the latency is large.
  • Play the audio file, have the user press an input right at the beat. Find
    out what the frame index it thinks the user pressed it at and make sure
    that is correct.
  • JACK
  • PulseAudio
  • ALSA
  • CoreAudio
  • WASAPI
  • Dummy

Can't build libsoundio 1.0.3

I wanted to build libsoudio version 1.0.3 under Arch Linux but make failed with the following message:

/home/andreas/personal/dev/c/libsoundio/src/jack.cpp: In function ‘int soundio_jack_init(SoundIoPrivate*)’:
/home/andreas/personal/dev/c/libsoundio/src/jack.cpp:919:84: error: invalid conversion from ‘void (*)(jack_port_id_t, const char*, const char*, void*) {aka void (*)(unsigned int, const char*, const char*, void*)}’ to ‘JackPortRenameCallback {aka int (*)(unsigned int, const char*, const char*, void*)}’ [-fpermissive]
     if ((err = jack_set_port_rename_callback(sij->client, port_rename_calllback, si))) {
                                                                                    ^
In file included from /home/andreas/personal/dev/c/libsoundio/src/jack.hpp:15:0,
                 from /home/andreas/personal/dev/c/libsoundio/src/jack.cpp:8:
/usr/include/jack/jack.h:523:5: note:   initializing argument 2 of ‘int jack_set_port_rename_callback(jack_client_t*, JackPortRenameCallback, void*)’
 int jack_set_port_rename_callback (jack_client_t *client,
     ^
At global scope:
cc1plus: error: unrecognized command line option ‘-Wno-c99-extensions’ [-Werror]
cc1plus: all warnings being treated as errors
CMakeFiles/libsoundio_shared.dir/build.make:206: recipe for target 'CMakeFiles/libsoundio_shared.dir/src/jack.cpp.o' failed
make[2]: *** [CMakeFiles/libsoundio_shared.dir/src/jack.cpp.o] Error 1
CMakeFiles/Makefile2:205: recipe for target 'CMakeFiles/libsoundio_shared.dir/all' failed
make[1]: *** [CMakeFiles/libsoundio_shared.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

Steps to reproduce the error:

  • git clone [email protected]:andrewrk/libsoundio.git && cd libsoundio && git checkout 1.0.3
  • mkdir build && cd build
  • cmake ..
  • make

The cmake output looks fine:

-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is GNU 5.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Configuring libsoundio version 1.0.3
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found JACK: /usr/lib64/libjack.so  
-- Found PULSEAUDIO: /usr/lib64/libpulse.so  
-- Found ALSA: /usr/lib64/libasound.so (found version "1.1.0") 
-- Could NOT find COREAUDIO (missing:  COREAUDIO_LIBRARY COREAUDIO_INCLUDE_DIR) 
-- Could NOT find WASAPI (missing:  WASAPI_INCLUDE_DIR) 

Installation Summary
--------------------
* Install Directory            : /usr/local
* Build Type                   : Debug
* Build static libs            : ON
* Build examples               : ON
* Build tests                  : ON

System Dependencies
-------------------
* threads                      : OK
* JACK       (optional)        : OK
* PulseAudio (optional)        : OK
* ALSA       (optional)        : OK
* CoreAudio  (optional)        : not found
* WASAPI     (optional)        : not found

-- Configuring done
-- Generating done
-- Build files have been written to: /home/andreas/personal/dev/c/libsoundio/build

Build recommendations for portability on linux

This is not really an issue, but as there is no mention of it in the docs ...

When building against the three available linux backends (alsa, pulseaudio and jack), the binaries have de facto a dependency to these libraries.

I'm about to try to build them statically to avoid package dependencies and/or different builds for every linux distribution flavor. But would you recommend it ?

I could also try to dlopen those, which would have the benefit of using the packaged version, but at the risk of a mismatch of ABIs.

Also, what are you planning to do for your other project Genesis ?

OSX not working with sample rates other than the default 44100

OSX 10.9 on a MacBook reports 3 sample rate ranges on the default output device (called "Built-in Output"): 44100-44100, 48000-48000 and 96000-96000. I set stream->sample_rate = 48000 right before opening the stream (I set the format to Float32NE - the only reported format).

If I set the sample rate to anything other than 44100 (including 0), the callback is not called.

What am I missing?

[Unrelated: Windows reports a single sample rate range 8000 - 5644800 but it only works with 44100 and 48000 - 52800 -- should I complain about it in another issue or you had enough of me? :)]

unable to build against deprecated JACK version

When trying to compile version 1.0.2 on Arch Linux I get the following error:

$ uname -a
Linux localhost 4.1.6-1-ARCH #1 SMP PREEMPT Mon Aug 17 08:52:28 CEST 2015 x86_64 GNU/Linux

$ whereis jack
jack: /usr/lib/jack /usr/include/jack
+++ cmake -DCMAKE_INSTALL_PREFIX=/home/roxlu/Documents/programming/polytrope/build/dependencies/../../extern/linux-gcc-x86_64 -DCMAKE_BUILD_TYPE=Release ..
Configuring libsoundio version 1.0.2
-- Could NOT find COREAUDIO (missing:  COREAUDIO_LIBRARY COREAUDIO_INCLUDE_DIR)
-- Could NOT find WASAPI (missing:  WASAPI_INCLUDE_DIR)

Installation Summary
--------------------
* Install Directory            : /home/roxlu/Documents/programming/polytrope/extern/linux-gcc-x86_64
* Build Type                   : Release
* Build static libs            : ON
* Build examples               : ON
* Build tests                  : ON

System Dependencies
-------------------
* threads                      : OK
* JACK       (optional)        : OK
* PulseAudio (optional)        : OK
* ALSA       (optional)        : OK
* CoreAudio  (optional)        : not found
* WASAPI     (optional)        : not found

-- Configuring done
-- Generating done
-- Build files have been written to: /home/roxlu/Documents/programming/polytrope/build/sources/soundio/build.release
+++ make -j 10
[ 17%] Built target libsoundio_static
[ 23%] Linking C executable unit_tests
[ 23%] Linking C executable latency
[ 39%] Built target libsoundio_shared
[ 41%] Linking C executable backend_disconnect_recover
[ 42%] Linking C executable sio_list_devices
[ 44%] Linking C executable overflow
[ 48%] Linking C executable underflow
[ 48%] Linking C executable sio_microphone
[ 50%] Linking C executable sio_record
[ 51%] Linking C executable sio_sine
CMakeFiles/unit_tests.dir/src/jack.cpp.o: In function `soundio_jack_init(SoundIoPrivate*)':
jack.cpp:(.text+0x2e60): undefined reference to `jack_set_port_rename_callback'
collect2: error: ld returned 1 exit status
CMakeFiles/unit_tests.dir/build.make:331: recipe for target 'unit_tests' failed
make[2]: *** [unit_tests] Error 1
CMakeFiles/Makefile2:501: recipe for target 'CMakeFiles/unit_tests.dir/all' failed
make[1]: *** [CMakeFiles/unit_tests.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
CMakeFiles/latency.dir/src/jack.cpp.o: In function `soundio_jack_init(SoundIoPrivate*)':
jack.cpp:(.text+0x1a89): undefined reference to `jack_set_port_rename_callback'
collect2: error: ld returned 1 exit status
CMakeFiles/latency.dir/build.make:331: recipe for target 'latency' failed
make[2]: *** [latency] Error 1
CMakeFiles/Makefile2:168: recipe for target 'CMakeFiles/latency.dir/all' failed
make[1]: *** [CMakeFiles/latency.dir/all] Error 2
libsoundio.so.1.0.2: undefined reference to `jack_set_port_rename_callback'
collect2: error: ld returned 1 exit status
CMakeFiles/sio_list_devices.dir/build.make:98: recipe for target 'sio_list_devices' failed
make[2]: *** [sio_list_devices] Error 1
CMakeFiles/Makefile2:316: recipe for target 'CMakeFiles/sio_list_devices.dir/all' failed
make[1]: *** [CMakeFiles/sio_list_devices.dir/all] Error 2
libsoundio.so.1.0.2: undefined reference to `jack_set_port_rename_callback'
collect2: error: ld returned 1 exit status
CMakeFiles/sio_sine.dir/build.make:98: recipe for target 'sio_sine' failed
make[2]: *** [sio_sine] Error 1
CMakeFiles/Makefile2:427: recipe for target 'CMakeFiles/sio_sine.dir/all' failed
make[1]: *** [CMakeFiles/sio_sine.dir/all] Error 2
libsoundio.so.1.0.2: undefined reference to `jack_set_port_rename_callback'
collect2: error: ld returned 1 exit status
CMakeFiles/sio_microphone.dir/build.make:98: recipe for target 'sio_microphone' failed
make[2]: *** [sio_microphone] Error 1
CMakeFiles/Makefile2:353: recipe for target 'CMakeFiles/sio_microphone.dir/all' failed
make[1]: *** [CMakeFiles/sio_microphone.dir/all] Error 2
libsoundio.so.1.0.2: undefined reference to `jack_set_port_rename_callback'
collect2: error: ld returned 1 exit status
CMakeFiles/overflow.dir/build.make:98: recipe for target 'overflow' failed
make[2]: *** [overflow] Error 1
CMakeFiles/Makefile2:279: recipe for target 'CMakeFiles/overflow.dir/all' failed
make[1]: *** [CMakeFiles/overflow.dir/all] Error 2
libsoundio.so.1.0.2: undefined reference to `jack_set_port_rename_callback'
collect2: error: ld returned 1 exit status
CMakeFiles/underflow.dir/build.make:98: recipe for target 'underflow' failed
make[2]: *** [underflow] Error 1
CMakeFiles/Makefile2:464: recipe for target 'CMakeFiles/underflow.dir/all' failed
make[1]: *** [CMakeFiles/underflow.dir/all] Error 2
libsoundio.so.1.0.2: undefined reference to `jack_set_port_rename_callback'
collect2: error: ld returned 1 exit status
CMakeFiles/backend_disconnect_recover.dir/build.make:98: recipe for target 'backend_disconnect_recover' failed
make[2]: *** [backend_disconnect_recover] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/backend_disconnect_recover.dir/all' failed
make[1]: *** [CMakeFiles/backend_disconnect_recover.dir/all] Error 2
libsoundio.so.1.0.2: undefined reference to `jack_set_port_rename_callback'
collect2: error: ld returned 1 exit status
CMakeFiles/sio_record.dir/build.make:98: recipe for target 'sio_record' failed
make[2]: *** [sio_record] Error 1
CMakeFiles/Makefile2:390: recipe for target 'CMakeFiles/sio_record.dir/all' failed
make[1]: *** [CMakeFiles/sio_record.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
+++ make install
[ 17%] Built target libsoundio_shared
[ 19%] Linking C executable backend_disconnect_recover
libsoundio.so.1.0.2: undefined reference to `jack_set_port_rename_callback'
collect2: error: ld returned 1 exit status
CMakeFiles/backend_disconnect_recover.dir/build.make:98: recipe for target 'backend_disconnect_recover' failed
make[2]: *** [backend_disconnect_recover] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/backend_disconnect_recover.dir/all' failed
make[1]: *** [CMakeFiles/backend_disconnect_recover.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
+++ exit

high CPU usage and underruns occurring on the Raspberry Pi

  1. Compile in RelWithDebInfo mode to get -O2 optimization level.
  2. Run ./sio_sine.
  3. Notice the CPU usage is high, about 30%, and the sine wave is often interrupted with overflows.
  4. Try aplay /usr/share/sounds/alsa/Front_Center.wav. Notice that it sounds fine, and in fact you can even play 2 at the same time, so it's not opening in raw mode.

convert source to C

As seen in #40, C++ is still rearing its ugly head. So let us convert the source to pure C11 code.

The c11 branch has everything compiling successfully with GCC. However the unit tests are failing, so I need to figure out what broke.

Also, strangely, clang's support for C11 atomics does not include lock-free atomic long, unlike for clang's C++11 atomic support. So I need to figure out what to do about that. One possibility is finishing #27, which would eliminate the need for a ring buffer, which would eliminate the need for a lock-free atomic long.

unable to open raw ALSA device when latency is 0.35

$ ./sio_sine --backend alsa --device hw:0,0 --raw  --latency 0.035
Backend: ALSA
Output device: HDA Intel PCH ALC892 Analog
'p\n' - pause
'u\n' - unpause
'c\n' - clear buffer
'q\n' - quit
unable to open device: unable to open device

Any other latency works fine. This has got to be an ALSA bug. I sent a message to alsa-devel mailing list.

add ASIO backend

It looks like WASAPI is not always better than ASIO and some people would benefit from ASIO support. However since it always takes over the sound devices, it will be prioritized after WASAPI, meaning that API users will have to explicitly connect to ASIO to utilize it.

how to handle write_callback API when creating language bindings

I've noticed that the write callback is called from a different thread (using WASAPI on a Win7 x64 here). This makes it difficult to bind to dynamic languages (I was about to attempt a LuaJIT binding for instance). Is there anything that can be done about that, like, say a lock/write/unlock API like DirectSound?

How do you push data in the write callback if you can't even use locking primitives?

Thanks,
Cosmin.

Compilation Problems with jack2 JackPortRenameCallback

Hi,
trying to compile libsoundio i get this error:

..
System Dependencies
-------------------
* threads                      : OK
* JACK       (optional)        : OK
* PulseAudio (optional)        : OK
* ALSA       (optional)        : OK
* CoreAudio  (optional)        : not found
* WASAPI     (optional)        : not found

..
[  2%] Building CXX object CMakeFiles/libsoundio_shared.dir/src/jack.cpp.o
/libsoundio/src/jack.cpp: In function ‘int soundio_jack_init(SoundIoPrivate*)’:
/mnt/data/gb1/home/srv/source/git/libsoundio/src/jack.cpp:919:84: error: invalid conversion from ‘void (*)(jack_port_id_t, const char*, const char*, void*) {aka void (*)(unsigned int, const char*, const char*, void*)}’ to ‘JackPortRenameCallback {aka int (*)(unsigned int, const char*, const char*, void*)}’ [-fpermissive]
     if ((err = jack_set_port_rename_callback(sij->client, port_rename_calllback, si))) {
                                                                                    ^
At global scope:
cc1plus: error: unrecognized command line option "-Wno-c99-extensions" [-Werror]
cc1plus: all warnings being treated as errors
make[2]: *** [CMakeFiles/libsoundio_shared.dir/src/jack.cpp.o] Error 1
make[1]: *** [CMakeFiles/libsoundio_shared.dir/all] Error 2
make: *** [all] Error 2

gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2
How could this be resolved?
Thanks
Thomas

mingw support

I've started this via: master...tresf:master

cd libsoundio
mkdir build out; cd build
export MINGW_ARCH=32 # defaults to 64
cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/MingwToolchain.cmake \
-DCMAKE_INSTALL_PREFIX=../out
make install

I'm not a C/C++ programmer, so I'm having difficulties with the compilation issues. I'm sure these are all very basic. Help appreciated...

Scanning dependencies of target libsoundio_shared
[  3%] Building C object CMakeFiles/libsoundio_shared.dir/src/soundio.c.obj
[  6%] Building C object CMakeFiles/libsoundio_shared.dir/src/util.c.obj
[  9%] Building C object CMakeFiles/libsoundio_shared.dir/src/os.c.obj
[ 12%] Building C object CMakeFiles/libsoundio_shared.dir/src/dummy.c.obj
[ 15%] Building C object CMakeFiles/libsoundio_shared.dir/src/channel_layout.c.obj
[ 18%] Building C object CMakeFiles/libsoundio_shared.dir/src/ring_buffer.c.obj
Linking C shared library libsoundio.dll
CMakeFiles/libsoundio_shared.dir/objects.a(soundio.c.obj):soundio.c:(.data+0x14): undefined reference to `soundio_wasapi_init'
collect2: error: ld returned 1 exit status
make[2]: *** [libsoundio.dll] Error 1
make[1]: *** [CMakeFiles/libsoundio_shared.dir/all] Error 2
make: *** [all] Error 2

Build failure with JACK 0.121.3

Scanning dependencies of target libsoundio_shared
[  2%] Building CXX object CMakeFiles/libsoundio_shared.dir/src/soundio.cpp.o
[  5%] Building CXX object CMakeFiles/libsoundio_shared.dir/src/util.cpp.o
[  8%] Building CXX object CMakeFiles/libsoundio_shared.dir/src/os.cpp.o
[ 10%] Building CXX object CMakeFiles/libsoundio_shared.dir/src/dummy.cpp.o
[ 13%] Building CXX object CMakeFiles/libsoundio_shared.dir/src/channel_layout.cpp.o
[ 16%] Building CXX object CMakeFiles/libsoundio_shared.dir/src/ring_buffer.cpp.o
[ 18%] Building CXX object CMakeFiles/libsoundio_shared.dir/src/jack.cpp.o
/tmp/soundio/libsoundio-1.0.0/src/jack.cpp: In function 'int soundio_jack_init(SoundIoPrivate*)':
/tmp/soundio/libsoundio-1.0.0/src/jack.cpp:919:84: error: 'jack_set_port_rename_callback' was not declared in this scope
     if ((err = jack_set_port_rename_callback(sij->client, port_rename_calllback, si))) {
                                                                                    ^
At global scope:
cc1plus: error: unrecognized command line option "-Wno-c99-extensions" [-Werror]
cc1plus: all warnings being treated as errors
CMakeFiles/libsoundio_shared.dir/build.make:192: recipe for target 'CMakeFiles/libsoundio_shared.dir/src/jack.cpp.o' failed
make[2]: *** [CMakeFiles/libsoundio_shared.dir/src/jack.cpp.o] Error 1
CMakeFiles/Makefile2:192: recipe for target 'CMakeFiles/libsoundio_shared.dir/all' failed
make[1]: *** [CMakeFiles/libsoundio_shared.dir/all] Error 2
Makefile:116: recipe for target 'all' failed
make: *** [all] Error 2

Linking with JACK 0.124.1: undefined reference to jack_set_port_rename_callback

Still having trouble with JACK. Now it's a linker error.

Scanning dependencies of target backend_disconnect_recover
[ 21%] Building C object CMakeFiles/backend_disconnect_recover.dir/test/backend_disconnect_recover.c.o
Linking C executable backend_disconnect_recover
libsoundio.so.1.0.0: undefined reference to `jack_set_port_rename_callback'
collect2: error: ld returned 1 exit status

Full build log: https://gist.github.com/diogocp/d606f66c50a649d4da5c

I suppose this is the problem:

$ nm -D /usr/lib/libjack.so | grep jack_set_port
000000000000b820 T jack_set_port_connect_callback
000000000000b7a0 T jack_set_port_registration_callback

No rename. JACK bug?

sio_record creates overflows

testing

./sio_record --backend jack a.wav

with JACK (dummy backend) running at different period sizes creates storms of overflows (grouped from a few to many, depending on period size), in intervals.
i.e. 10 overflows, silent, 10 overflows, etc.
JACK tells

JackAudioDriver::ProcessGraphAsyncMaster: Process error
JackEngine::XRun: client = SoundIoInStream was not finished, state = Triggered

I couldn't find parts in the code that would testwise create these xruns so i suppose they aren't intentional.

a related note, running

./sio_sine --backend jack

works without any xruns at very low period sizes.

unit_tests hangs with --backend jack

with a running jack:

./unit_tests --backend jack
testing os_get_time...OK
testing create output stream...

(hangs here)

./sio_list_devices --backend jack

(hangs here)

It seems to work with --backend pulseaudio
What is happening?
Greetings

segfault on atomic operations when using non standard stdatomic.h

./sio_list_devices
Segmentation fault

gdb ./sio_list_devices
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7df039a in soundio_alsa_init (si=0x603010) at libsoundio/src/alsa.c:1860
1860 atomic_flag_test_and_set(&sia->abort_flag);

(gdb) bt
#0 0x00007ffff7df039a in soundio_alsa_init (si=0x603010) at libsoundio/src/alsa.c:1860
#1 0x00007ffff7deab1e in soundio_connect_backend (soundio=0x603010, backend=SoundIoBackendAlsa) at libsoundio/src/soundio.c:231
#2 0x00007ffff7deaa27 in soundio_connect (soundio=0x603010) at libsoundio/src/soundio.c:206
#3 0x00000000004010bd in main (argc=1, argv=0x7fffffffd928) at libsoundio/example/sio_list_devices.c:163

Build error in jack.cpp

[  2%] Building CXX object CMakeFiles/libsoundio_shared.dir/src/jack.cpp.o
/usr/bin/c++   -Dlibsoundio_shared_EXPORTS -g -Werror -pedantic -fPIC -I/home/ianmacs/dev/libsoundio -I/home/ianmacs/dev/libsoundio/build -I/home/ianmacs/dev/libsoundio/test -I/home/ianmacs/dev/libsoundio/src    -std=c++11 -fno-exceptions -fno-rtti -fvisibility=hidden -Wall -Werror=strict-prototypes -Werror=old-style-definition -Werror=missing-prototypes -Wno-c99-extensions -o CMakeFiles/libsoundio_shared.dir/src/jack.cpp.o -c /home/ianmacs/dev/libsoundio/src/jack.cpp
/home/ianmacs/dev/libsoundio/src/jack.cpp: In function ‘int soundio_jack_init(SoundIoPrivate*)’:
/home/ianmacs/dev/libsoundio/src/jack.cpp:913:84: error: invalid conversion from ‘void (*)(jack_port_id_t, const char*, const char*, void*) {aka void (*)(unsigned int, const char*, const char*, void*)}’ to ‘JackPortRenameCallback {aka int (*)(unsigned int, const char*, const char*, void*)}’ [-fpermissive]
     if ((err = jack_set_port_rename_callback(sij->client, port_rename_calllback, si))) {
                                                                                    ^
At global scope:
cc1plus: error: unrecognized command line option "-Wno-c99-extensions" [-Werror]
cc1plus: all warnings being treated as errors
make[2]: *** [CMakeFiles/libsoundio_shared.dir/src/jack.cpp.o] Error 1
make[2]: Leaving directory `/home/ianmacs/dev/libsoundio/build'
make[1]: *** [CMakeFiles/libsoundio_shared.dir/all] Error 2
make[1]: Leaving directory `/home/ianmacs/dev/libsoundio/build'
make: *** [all] Error 2

This is on ubuntu 14.04, jack development package is libjack-jackd2-dev version 1.9.9.5+20130622git7de15e7a-1ubuntu1, compiler is g++-4.8.4

Node bindings?

Andrew, hi!

Are there any plans on creating bindings for nodejs?
For now, neither mpg123, portaudio1 nor portaudio2 work (on windows at least), and no one seems to be willing to do anything about that. The situation is quite sorrowful for those who want to just output sound in nodejs.
If no, can you give any advice on what it is required to get the binding of libsoundio done for node? Skimming the node-addons tutorial gives an outline of how to compile C++ things, but what are the steps to be done to compile libsoundio?

Thank you for any response.

MacOS 10.9: non-default latency and non-current sample rate prevent sound output

I built libsoundio on a Macbook Pro (OS X 10.9.5). The output of sio_list_devices is

$ ./sio_list_devices
--------Input Devices--------

Built-in Microphone (default)
  id: AppleHDAEngineInput:1B,0,1,0:1
  channel layouts:
    Stereo
  current layout: Stereo
  sample rates:
    44100 - 44100
  current sample rate: 44100
  formats: float 32-bit LE
  min software latency: 0.00031746 sec
  max software latency: 0.20897959 sec
  current software latency: 0.01160998 sec


--------Output Devices--------

Built-in Output (default)
  id: AppleHDAEngineOutput:1B,0,1,1:0
  channel layouts:
    Stereo
  current layout: Stereo
  sample rates:
    44100 - 44100
    48000 - 48000
    88200 - 88200
    96000 - 96000
  current sample rate: 44100
  formats: float 32-bit LE
  min software latency: 0.00031746 sec
  max software latency: 0.41795918 sec
  current software latency: 0.01160998 sec


2 devices found

When I run sio_sine, the program runs, but there is no sound generated. Here's the output shown when I try the various keyboard commands:

$ ./sio_sine 
Backend: CoreAudio
Output device: Built-in Output
'p\n' - pause
'u\n' - unpause
'c\n' - clear buffer
'q\n' - quit
p
pausing result: (no error)
u
unpausing result: (no error)
c
clear buffer result: incompatible backend
q

I assume I have to configure something, but I don't know what it is.

Using libsoundio in a VOIP like application

I have been playing around with the library and samples, and have had much success, but I now have an use case of this library and would like to understand how best to implement it with libsoundio.
As the title suggests, my end goal is sending encoded audio over the net, in my case using the opus project and UDP. My application also has a requirement of having a practical low latency for environments say, like gaming.

  • Where would a encoder, best be implemented. For example, the read callback, or in the main loop?
  • Would it be appropriate to send the encoded opus audio (UDP) from the read callback or within the main loop?
  • How best should the data be read from the read callback to feed straight into the encoder?
    For example, the examples provided for libsoundio iterates over the frames and samples, and copies them into a ring buffer. Would there be a better method that uses the data straight off the bat, rather than encoding it?

Thanks in advance.

JACK pausing deadlock

Calling soundio_outstream_pause from inside the write_callback causes a deadlock. According to the documentation, you're supposed to be allowed to call soundio_outstream_pause from anywhere, including inside the write_callback.

Build errors on Slackware 14.1

I am currently trying to build libsoundio on Slackware. I already had to remove the "-wno-c99-extensions" as my version of GCC didn't seem to have that option. After fixing that issues, I'm left with this error I can't seem to get past:

/home/paul/playground/libsoundio/src/jack.cpp: In function 'int soundio_jack_init(SoundIoPrivate_)':
/home/paul/playground/libsoundio/src/jack.cpp:917:84: error: invalid conversion from 'void ()(jack_port_id_t, const char, const char_, void_) {aka void ()(unsigned int, const char, const char_, void_)}' to 'JackPortRenameCallback {aka int ()(unsigned int, const char, const char_, void_)}' [-fpermissive]
if ((err = jack_set_port_rename_callback(sij->client, port_rename_calllback, si))) {
^
make[2]: *_* [CMakeFiles/libsoundio_shared.dir/src/jack.cpp.o] Error 1
make[1]: *** [CMakeFiles/libsoundio_shared.dir/all] Error 2
make: *** [all] Error 2

Some more info:

Linux: Slackware 14.1 (64 bit)
GCC 4.8.2
JACK 1.9.10

Thanks!

Push latency as far down as possible

I'm noticing appreciable latency when running the sio_microphone example using MacOSX Built-In microphone and outputs, and wanted to see if it would be possible to reduce the latency.

I tried this:

--- a/example/sio_microphone.c
+++ b/example/sio_microphone.c
@@ -332,6 +332,7 @@ int main(int argc, char **argv) {
     instream->layout = *layout;
     instream->software_latency = microphone_latency;
     instream->read_callback = read_callback;
+    instream->software_latency = .001;

     if ((err = soundio_instream_open(instream))) {
         fprintf(stderr, "unable to open input stream: %s", soundio_strerror(err));
@@ -347,12 +348,15 @@ int main(int argc, char **argv) {
     outstream->software_latency = microphone_latency;
     outstream->write_callback = write_callback;
     outstream->underflow_callback = underflow_callback;
-
+    outstream->software_latency = .001;
     if ((err = soundio_outstream_open(outstream))) {
         fprintf(stderr, "unable to open output stream: %s", soundio_strerror(err));
         return 1;
     }

Is this the right approach?

Use symbol versioning

If libsoundio is to become a widely used library, it would be great if symbol versioning was provided. Symbol versioning is a more fine grained version of allowing multiple (ABI-incompatible) libraries to coexist in the same system.

Under the current scheme, you have libsoundio.so.1. If an ABI-breaking change needed to be made, then libsoundio.so.2 would be able to exist side by side with libsoundio.so.1. However, there is still potential for trouble:

  1. App foo is compiled against version 2.
  2. foo loads a plugin bar, which is linked to version 1.
  3. Errors occur as the linker somehow determines it needs to use only one version of the library for any given symbol that exists in both libraries, but it can only choose one.

Using a version script tags each function with a trailing string (arbitrary). If a version 2 is released that changes that string, then the runtime linker can use that trailing string to disambiguate between the versions, and so both libraries can coexist in the same process. The version can be inspected via objdump -T $library. You can check eg libpulse has all functions tagged with PULSE_0

Symbol versioning can also be used to avoid bumping the version even while making ABI-breaking changes. This is a more advanced usage that is overkill in many cases, but is eg used by glibc (check out objdump -T /lib/x86_64-linux-gnu/libc.so.6|grep strtod on a debian system).

The basic usage is fairly simple. All that is needed is that a list of all the exported symbols be listed in a file that then is passed to the linker via the -Wl,--version-script=$file flag:

LIBSOUNDIO_1 {
global:
    soundio_backend_count;
    soundio_backend_name;
    soundio_best_matching_channel_layout;
    soundio_channel_layout_builtin_count;
    soundio_channel_layout_detect_builtin;
    soundio_channel_layout_equal;
    soundio_channel_layout_find_channel;
    soundio_channel_layout_get_builtin;
    soundio_channel_layout_get_default;
    soundio_connect;
    soundio_connect_backend;
    soundio_create;
    soundio_default_input_device_index;
    soundio_default_output_device_index;
    soundio_destroy;
    soundio_device_equal;
    soundio_device_nearest_sample_rate;
    soundio_device_ref;
    soundio_device_sort_channel_layouts;
    soundio_device_supports_format;
    soundio_device_supports_layout;
    soundio_device_supports_sample_rate;
    soundio_device_unref;
    soundio_disconnect;
    soundio_flush_events;
    soundio_force_device_scan;
    soundio_format_string;
    soundio_get_backend;
    soundio_get_bytes_per_sample;
    soundio_get_channel_name;
    soundio_get_input_device;
    soundio_get_output_device;
    soundio_have_backend;
    soundio_input_device_count;
    soundio_instream_begin_read;
    soundio_instream_create;
    soundio_instream_destroy;
    soundio_instream_end_read;
    soundio_instream_get_latency;
    soundio_instream_open;
    soundio_instream_pause;
    soundio_instream_start;
    soundio_output_device_count;
    soundio_outstream_begin_write;
    soundio_outstream_clear_buffer;
    soundio_outstream_create;
    soundio_outstream_destroy;
    soundio_outstream_end_write;
    soundio_outstream_get_latency;
    soundio_outstream_open;
    soundio_outstream_pause;
    soundio_outstream_start;
    soundio_parse_channel_id;
    soundio_ring_buffer_advance_read_ptr;
    soundio_ring_buffer_advance_write_ptr;
    soundio_ring_buffer_capacity;
    soundio_ring_buffer_clear;
    soundio_ring_buffer_create;
    soundio_ring_buffer_destroy;
    soundio_ring_buffer_fill_count;
    soundio_ring_buffer_free_count;
    soundio_ring_buffer_read_ptr;
    soundio_ring_buffer_write_ptr;
    soundio_sort_channel_layouts;
    soundio_strerror;
    soundio_wait_events;
    soundio_wakeup;
local: *;
};

Then, if a change is made that requires bumping SONAME, all you need to do is change the version script to LIBSOUNDIO_2.

More information in the ld manual

Raspberry Pi - incorrect categorization of input/output device, and unknown default device

@czxJAVA2009 writes:

I can't build the libsoundio.After I make it.following error:

[ 2%] Building CXX object CMakeFiles/libsoundio_shared.dir/src/soundio.cpp.o
In file included from /home/orangepi/libsoundio/src/alsa.hpp:13:0,
from /home/orangepi/libsoundio/src/soundio.hpp:23,
from /home/orangepi/libsoundio/src/soundio.cpp:8:
/home/orangepi/libsoundio/src/atomics.hpp:27:2: error: #error "require atomic_bool to be lock free"
#error "require atomic_bool to be lock free"
^
In file included from /home/orangepi/libsoundio/src/soundio.hpp:23:0,
from /home/orangepi/libsoundio/src/soundio.cpp:8:
/home/orangepi/libsoundio/src/alsa.hpp:48:5: error: ‘snd_pcm_chmap_t’ does not name a type
snd_pcm_chmap_t chmap;
^
/home/orangepi/libsoundio/src/alsa.hpp:68:5: error: ‘snd_pcm_chmap_t’ does not name a type
snd_pcm_chmap_t *chmap;
^
cc1plus: error: unrecognized command line option "-Wno-c99-extensions" [-Werror]
cc1plus: all warnings being treated as errors
CMakeFiles/libsoundio_shared.dir/build.make:62: recipe for target 'CMakeFiles/libsoundio_shared.dir/src/soundio.cpp.o' failed
make[2]: ** [CMakeFiles/libsoundio_shared.dir/src/soundio.cpp.o] Error 1
CMakeFiles/Makefile2:205: recipe for target 'CMakeFiles/libsoundio_shared.dir/all' failed
make[1]: *** [CMakeFiles/libsoundio_shared.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.