### Compile and Install libsoundio Source: https://github.com/andrewrk/libsoundio/wiki/Compiling-for-Windows Compiles and installs libsoundio using the 'make install' command after CMake configuration. ```bash make install ``` -------------------------------- ### Header File Installation Source: https://github.com/andrewrk/libsoundio/blob/master/CMakeLists.txt Installs the library header files to the specified include directory. ```cmake install(FILES ${LIBSOUNDIO_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/soundio") ``` -------------------------------- ### Static Library Build and Installation Source: https://github.com/andrewrk/libsoundio/blob/master/CMakeLists.txt Builds a static library if BUILD_STATIC_LIBS is enabled, sets its properties, and installs it. ```cmake if(BUILD_STATIC_LIBS) add_library(libsoundio_static STATIC ${LIBSOUNDIO_SOURCES}) set_target_properties(libsoundio_static PROPERTIES OUTPUT_NAME ${SOUNDIO_STATIC_LIBNAME} COMPILE_FLAGS ${LIB_CFLAGS} LINKER_LANGUAGE C ) install(TARGETS libsoundio_static DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() ``` -------------------------------- ### Build Documentation Source: https://github.com/andrewrk/libsoundio/blob/master/README.md Run this command to build the documentation for libsoundio. Ensure doxygen is installed beforehand. ```bash make doc ``` -------------------------------- ### Shared Library Build and Installation Source: https://github.com/andrewrk/libsoundio/blob/master/CMakeLists.txt Builds a shared library (soundio) if BUILD_DYNAMIC_LIBS is enabled, sets its properties, links libraries, and installs it. ```cmake if(BUILD_DYNAMIC_LIBS) add_library(libsoundio_shared SHARED ${LIBSOUNDIO_SOURCES}) set_target_properties(libsoundio_shared PROPERTIES OUTPUT_NAME soundio SOVERSION ${LIBSOUNDIO_VERSION_MAJOR} VERSION ${LIBSOUNDIO_VERSION} COMPILE_FLAGS ${LIB_CFLAGS} LINKER_LANGUAGE C ) target_link_libraries(libsoundio_shared LINK_PUBLIC ${LIBSOUNDIO_LIBS}) install(TARGETS libsoundio_shared DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() ``` -------------------------------- ### Install MinGW-w64 GCC on Linux Source: https://github.com/andrewrk/libsoundio/wiki/Compiling-for-Windows Installs the MinGW-w64 GCC compiler and pkg-config on Debian/Ubuntu-based systems for cross-compilation. ```bash sudo apt-get install mingw64-x-gcc mingw64-x-pkgconfig # ^-- or mingw32-x-gcc mingw32-x-pkgconfig, or both ``` -------------------------------- ### Build libsoundio for Windows with MXE Source: https://github.com/andrewrk/libsoundio/blob/master/README.md Build instructions for Windows using the MXE cross-compilation environment. This example shows how to set up MXE and then configure CMake for 32-bit Windows targets. ```bash git clone https://github.com/mxe/mxe cd mxe make MXE_TARGETS='x86_64-w64-mingw32.static i686-w64-mingw32.static' gcc ``` ```bash mkdir build-win32 cd build-win32 cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/mxe/usr/i686-w64-mingw32.static/share/cmake/mxe-conf.cmake make ``` ```bash 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 ``` -------------------------------- ### Install Build Tools in MSYS2 Source: https://github.com/andrewrk/libsoundio/wiki/Compiling-for-Windows Installs essential build tools like make, cmake, and pkgconfig, along with optional utilities, within the MSYS2 environment. ```bash pacman -S make cmake pkgconfig ``` ```bash pacman -S p7zip gzip tar wget vim # ^-- optional, may come in handy :) ``` -------------------------------- ### Build libsoundio with CMake Source: https://github.com/andrewrk/libsoundio/blob/master/README.md Standard build process for libsoundio using CMake. Assumes necessary dependencies are installed. ```bash mkdir build cd build cmake .. make sudo make install ``` -------------------------------- ### Update MSYS2 and Install MinGW-w64 GCC on Windows Source: https://github.com/andrewrk/libsoundio/wiki/Compiling-for-Windows Updates MSYS2 packages and installs the MinGW-w64 GCC compiler for native Windows compilation. ```bash pacman -Sy; pacman --needed -S bash pacman pacman-mirrors msys2-runtime ``` ```bash pacman -Su; pacman -S mingw-w64-x86_64-gcc # ^-- or mingw-w64-i686-gcc, or both ``` -------------------------------- ### Configure libsoundio Build with CMake Source: https://github.com/andrewrk/libsoundio/wiki/Compiling-for-Windows Configures the libsoundio project using CMake, specifying the toolchain file and installation prefix. ```bash cd libsoundio; mkdir build out; cd build; cmake .. -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake -DCMAKE_INSTALL_PREFIX=../out ``` -------------------------------- ### Platform-Specific Compiler Flags (MSVC) Source: https://github.com/andrewrk/libsoundio/blob/master/CMakeLists.txt Sets compiler flags for MSVC, including /Wall for debug builds and specific flags for libraries, examples, and tests. ```cmake if(MSVC) set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Wall") set(LIB_CFLAGS "/TP /W4") set(EXAMPLE_CFLAGS "/W4") set(TEST_CFLAGS "${LIB_CFLAGS}") set(TEST_LDFLAGS " ") set(LIBM " ") else() set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Werror -pedantic") set(LIB_CFLAGS "-std=c11 -fvisibility=hidden -Wall -Werror=strict-prototypes -Werror=old-style-definition -Werror=missing-prototypes -D_REENTRANT -D_POSIX_C_SOURCE=200809L -Wno-missing-braces") set(EXAMPLE_CFLAGS "-std=c99 -Wall") set(TEST_CFLAGS "${LIB_CFLAGS} -fprofile-arcs -ftest-coverage") set(TEST_LDFLAGS "-fprofile-arcs -ftest-coverage") set(LIBM "m") endif() ``` -------------------------------- ### Include Directories Configuration Source: https://github.com/andrewrk/libsoundio/blob/master/CMakeLists.txt Sets up include directories for the project, including source, binary, test, and src directories. ```cmake include_directories( ${libsoundio_SOURCE_DIR} ${libsoundio_BINARY_DIR} "${libsoundio_SOURCE_DIR}/test" "${libsoundio_SOURCE_DIR}/src" ) ``` -------------------------------- ### Configuration File Generation Source: https://github.com/andrewrk/libsoundio/blob/master/CMakeLists.txt Generates configuration header and Doxygen configuration files from input templates. ```cmake configure_file( "${libsoundio_SOURCE_DIR}/src/config.h.in" ${CONFIGURE_OUT_FILE} ) set(DOXYGEN_CONF_FILE "${libsoundio_BINARY_DIR}/doxygen.conf") configure_file( "${libsoundio_SOURCE_DIR}/doc/doxygen.conf.in" ${DOXYGEN_CONF_FILE} ) ``` -------------------------------- ### Emit Sine Wave with libsoundio Source: https://github.com/andrewrk/libsoundio/blob/master/README.md A complete C program that generates a sine wave and plays it through the default audio output device. It handles device connection, stream creation, and audio data writing. ```c #include #include #include #include #include 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; } ``` -------------------------------- ### Library Linking Configuration Source: https://github.com/andrewrk/libsoundio/blob/master/CMakeLists.txt Defines the list of libraries to be linked against, including backend-specific and system libraries. ```cmake set(LIBSOUNDIO_LIBS ${JACK_LIBRARY} ${PULSEAUDIO_LIBRARY} ${ALSA_LIBRARIES} ${COREAUDIO_LIBRARY} ${COREFOUNDATION_LIBRARY} ${AUDIOUNIT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ) ``` -------------------------------- ### Clean Previous Build and Configure for Debug Source: https://github.com/andrewrk/libsoundio/wiki/Compiling-for-Windows Cleans the build artifacts and CMake cache, then reconfigures the project to build a debug version of libsoundio. ```bash make clean; rm CMakeCache.txt # cleanup previous builds ``` ```diff - cmake .. -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake -DCMAKE_INSTALL_PREFIX=../out + cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake -DCMAKE_INSTALL_PREFIX=../out ``` -------------------------------- ### Clone libsoundio Source Code Source: https://github.com/andrewrk/libsoundio/wiki/Compiling-for-Windows Clones the libsoundio master branch from GitHub using Git. ```bash git clone -b master https://andrewrk/libsoundio ``` -------------------------------- ### Conditional Source File Inclusion Source: https://github.com/andrewrk/libsoundio/blob/master/CMakeLists.txt Includes source files based on the availability of audio backends like ALSA, CoreAudio, and WASAPI. ```cmake if(SOUNDIO_HAVE_ALSA) set(LIBSOUNDIO_SOURCES ${LIBSOUNDIO_SOURCES} "${libsoundio_SOURCE_DIR}/src/alsa.c" ) endif() if(SOUNDIO_HAVE_COREAUDIO) set(LIBSOUNDIO_SOURCES ${LIBSOUNDIO_SOURCES} "${libsoundio_SOURCE_DIR}/src/coreaudio.c" ) endif() if(SOUNDIO_HAVE_WASAPI) set(LIBSOUNDIO_SOURCES ${LIBSOUNDIO_SOURCES} "${libsoundio_SOURCE_DIR}/src/wasapi.c" ) endif() ``` -------------------------------- ### CMake Toolchain File for MinGW Source: https://github.com/andrewrk/libsoundio/wiki/Compiling-for-Windows This CMake toolchain file configures the build environment for cross-compiling with MinGW on Linux. It sets system names, processor architectures, tool prefixes, and compiler paths. ```cmake # Required by cmake if `uname -s` is inadaquate set(CMAKE_SYSTEM_NAME Windows) set(CMAKE_SYSTEM_VERSION 1) # Mingw architecture default is 64-bit # To override: # $ export MINGW_ARCH=32 if(DEFINED ENV{MINGW_ARCH}) set(MINGW_ARCH "$ENV{MINGW_ARCH}") else() set(MINGW_ARCH "64") endif() if(${MINGW_ARCH} STREQUAL "32") set(CMAKE_SYSTEM_PROCESSOR "i686") elseif(${MINGW_ARCH} STREQUAL "64") set(CMAKE_SYSTEM_PROCESSOR "x86_64") else() message(FATAL_ERROR "Unknown system architecture specified") endif() # Path to mingw set(MINGW_PREFIX "/opt/mingw${MINGW_ARCH}") # Linux mingw requires explicitly defined tools to prevent clash with native system tools set(MINGW_TOOL_PREFIX ${MINGW_PREFIX}/bin/${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32-) # Windows msys mingw ships with a mostly suitable preconfigured environment if(DEFINED ENV{MSYSCON}) set(CMAKE_GENERATOR "MSYS Makefiles" CACHE STRING "" FORCE) set(MINGW_PREFIX "/mingw${MINGW_ARCH}") set(MINGW_TOOL_PREFIX "${MINGW_PREFIX}/bin/") # Msys compiler does not support @CMakeFiles/Include syntax set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES OFF) set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES OFF) endif() # The target environment set(CMAKE_FIND_ROOT_PATH ${MINGW_PREFIX}) set(CMAKE_INSTALL_PREFIX ${MINGW_PREFIX}) # which compilers to use for C and C++ set(CMAKE_C_COMPILER ${MINGW_TOOL_PREFIX}gcc) set(CMAKE_CXX_COMPILER ${MINGW_TOOL_PREFIX}g++) set(CMAKE_RC_COMPILER ${MINGW_TOOL_PREFIX}windres) # adjust the default behaviour of the FIND_XXX() commands: # search headers and libraries in the target environment, search # programs in the host environment set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) # Fix header finds set(WASAPI_INCLUDE_DIR ${MINGW_PREFIX}/include) # Set release to be defaut if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Defaulting to Release build type for mingw") endif() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.