Git Product home page Git Product logo

miniaudio's Introduction

miniaudio

An audio playback and capture library in a single source file.

discord mastodon reddit

Features - Examples - Building - Documentation - Supported Platforms - License

miniaudio is written in C with no dependencies except the standard library and should compile clean on all major compilers without the need to install any additional development packages. All major desktop and mobile platforms are supported.

Features

  • Simple build system with no external dependencies.
  • Simple and flexible API.
  • Low-level API for direct access to raw audio data.
  • High-level API for sound management, mixing, effects and optional 3D spatialization.
  • Flexible node graph system for advanced mixing and effect processing.
  • Resource management for loading sound files.
  • Decoding, with built-in support for WAV, FLAC and MP3, in addition to being able to plug in custom decoders.
  • Encoding (WAV only).
  • Data conversion.
  • Resampling, including custom resamplers.
  • Channel mapping.
  • Basic generation of waveforms and noise.
  • Basic effects and filters.

Refer to the Programming Manual for a more complete description of available features in miniaudio.

Examples

This example shows one way to play a sound using the high level API.

#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h"

#include <stdio.h>

int main()
{
    ma_result result;
    ma_engine engine;

    result = ma_engine_init(NULL, &engine);
    if (result != MA_SUCCESS) {
        return -1;
    }

    ma_engine_play_sound(&engine, "sound.wav", NULL);

    printf("Press Enter to quit...");
    getchar();

    ma_engine_uninit(&engine);

    return 0;
}

This example shows how to decode and play a sound using the low level API.

#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h"

#include <stdio.h>

void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
{
    ma_decoder* pDecoder = (ma_decoder*)pDevice->pUserData;
    if (pDecoder == NULL) {
        return;
    }

    ma_decoder_read_pcm_frames(pDecoder, pOutput, frameCount, NULL);

    (void)pInput;
}

int main(int argc, char** argv)
{
    ma_result result;
    ma_decoder decoder;
    ma_device_config deviceConfig;
    ma_device device;

    if (argc < 2) {
        printf("No input file.\n");
        return -1;
    }

    result = ma_decoder_init_file(argv[1], NULL, &decoder);
    if (result != MA_SUCCESS) {
        return -2;
    }

    deviceConfig = ma_device_config_init(ma_device_type_playback);
    deviceConfig.playback.format   = decoder.outputFormat;
    deviceConfig.playback.channels = decoder.outputChannels;
    deviceConfig.sampleRate        = decoder.outputSampleRate;
    deviceConfig.dataCallback      = data_callback;
    deviceConfig.pUserData         = &decoder;

    if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) {
        printf("Failed to open playback device.\n");
        ma_decoder_uninit(&decoder);
        return -3;
    }

    if (ma_device_start(&device) != MA_SUCCESS) {
        printf("Failed to start playback device.\n");
        ma_device_uninit(&device);
        ma_decoder_uninit(&decoder);
        return -4;
    }

    printf("Press Enter to quit...");
    getchar();

    ma_device_uninit(&device);
    ma_decoder_uninit(&decoder);

    return 0;
}

More examples can be found in the examples folder or online here: https://miniaud.io/docs/examples/

Building

Do the following in one source file:

#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h"

Then just compile. There's no need to install any dependencies. On Windows and macOS there's no need to link to anything. On Linux just link to -lpthread, -lm and -ldl. On BSD just link to -lpthread and -lm. On iOS you need to compile as Objective-C.

If you get errors about undefined references to __sync_val_compare_and_swap_8, __atomic_load_8, etc. you need to link with -latomic.

If you prefer separate .h and .c files, you can find a split version of miniaudio in the extras/miniaudio_split folder. From here you can use miniaudio as a traditional .c and .h library - just add miniaudio.c to your source tree like any other source file and include miniaudio.h like a normal header. If you prefer compiling as a single translation unit (AKA unity builds), you can just #include the .c file in your main source file:

#include "miniaudio.c"

Note that the split version is auto-generated using a tool and is based on the main file in the root directory. If you want to contribute, please make the change in the main file.

ABI compatibility is not guaranteed between versions so take care if compiling as a DLL/SO. The suggested way to integrate miniaudio is by adding it directly to your source tree.

Documentation

Online documentation can be found here: https://miniaud.io/docs/

Documentation can also be found at the top of miniaudio.h which is always the most up-to-date and authoritive source of information on how to use miniaudio. All other documentation is generated from this in-code documentation.

Supported Platforms

  • Windows
  • macOS, iOS
  • Linux
  • FreeBSD / OpenBSD / NetBSD
  • Android
  • Raspberry Pi
  • Emscripten / HTML5

miniaudio should compile clean on other platforms, but it will not include any support for playback or capture by default. To support that, you would need to implement a custom backend. You can do this without needing to modify the miniaudio source code. See the custom_backend example.

Backends

  • WASAPI
  • DirectSound
  • WinMM
  • Core Audio (Apple)
  • ALSA
  • PulseAudio
  • JACK
  • sndio (OpenBSD)
  • audio(4) (NetBSD and OpenBSD)
  • OSS (FreeBSD)
  • AAudio (Android 8.0+)
  • OpenSL|ES (Android only)
  • Web Audio (Emscripten)
  • Null (Silence)
  • Custom

License

Your choice of either public domain or MIT No Attribution.

miniaudio's People

Contributors

ayuusweetfish avatar ccawley2011 avatar clownacy avatar cubeleo avatar defaultsamson avatar edubart avatar fabioarnold avatar iarwain avatar ilya-ku avatar jaybaird avatar kgdev avatar mackron avatar marcolizza avatar michealreed avatar morlad avatar mrbrixican avatar oldes avatar oviano avatar patstew avatar raysan5 avatar sahnvour avatar seantolstoyevski avatar sgourichon avatar sheimi avatar sinkingsugar avatar skkbyssk avatar taiko2k avatar thedmd avatar tycho avatar yyamdev 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  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

miniaudio's Issues

3D audio support

Hi,
Excellent work on this library, any plan to add 3D audio support?

Thanks

Weird pop on sound playing

Just updated rFXGen to latest raylib, using latest mini_al (from dev branch).

When a new sound is generated and played or just played, you could notice a small "pop" at the end of the playing, specially noticeable when generating Pickup/Coin sounds. Not sure what is related to but I didn't happen on mid-March release. Sound is exported correctly, it seems to be only a playing issue...

You can check rFXGen on itch.io v1.2 vs v1.3 to notice the issue.

I also upload both files for convenience: rfxgen_120vs130.zip

Also noticed that generated .exe is slightly bigger (~170KB) with latest mini_al version, I imagine is related to new functionality added to the library...

EDIT: I can confirm issue is on sound playing, tried opening some wav sounds with several audio programs (WinAMP, Audacity) and they works ok. Tried playing them with raylib and the "pop" is there, at the end of playing... It could be related to raylib audio module...

vorbis duration

do you have any idea how i could possibly get the duration of a vorbis song without using ma_decoder_init_memory?

mal_enumerate_devices alsa returns only null and pulse

On Manjaro mal_enumerate_devices returns only null and pulse, I looked over your code and I understand what you want to achieve in mal_enumerate_devices__alsa the problem is that on my system this check if (colonPos == -1 || (colonPos == 2 && (NAME[0]=='h' && NAME[1]=='w'))) can only be true for null or pulse because these don't contain : and there's no entry starting with hw:something.
I wrote this function to check my entries:

int enumerateAlsaDevices()
{
    char **hints;
    /* Enumerate sound devices */
    int err = snd_device_name_hint(-1, "pcm", (void***)&hints);
    if (err != 0) return -1;//Error! Just return
    
    char** n = hints;
    while (*n != NULL)
    {
        char *name = snd_device_name_get_hint(*n, "NAME");
        char *desc = snd_device_name_get_hint(*n, "DESC");
        char *ioid = snd_device_name_get_hint(*n, "IOID");
        //printf("name len %lu, desc len %lu ioid len %lu\n", strlen(name), strlen(desc), strlen(ioid)); //There's no terminator...
    
        if (name != NULL && 0 != strcmp("null", name))
        {
            //Copy name to another buffer and then free it
            char hwID[16] = {'\0'};
            if(strcmp(name, "pulse") == 0)
            {
                sprintf(hwID, name);
                printf("Name: %s\nDescription: %s\nIOID: %s\nhwID: %s\n\n", name, desc, ioid, hwID);
            }
            else
            {
                char* aux = strstr(name, ":");
                if(aux != NULL)
                {
                    char* prop = aux + 1;
                    aux = strtok(prop, ",");
                    int cardIndex = snd_card_get_index(aux + 5);
                    aux = strtok(NULL, ",");
                    if(aux != NULL)
                    {
                        sprintf(hwID, "hw:%d,%s", cardIndex, aux + 4);
                    }
                    else
                    {
                        sprintf(hwID, "hw:%d,%d", cardIndex, 0);
                    }
                }
                printf("Name: %s\nDescription: %s\nIOID: %s\nhwID: %s\n\n", name, desc, ioid, hwID);
            }

            free(name);
            free(desc);
            free(ioid);
        }
        n++;
    }
    snd_device_name_free_hint((void**)hints);
    return 0;
}

and they look like this:

...
Name: sysdefault:CARD=U7
Description: Xonar U7, USB Audio
Default Audio Device
IOID: (null)
hwIDhw:1,0

Name: front:CARD=U7
Description: Xonar U7, USB Audio
Front speakers
IOID: (null)
hwIDhw:1,0

Name: surround21:CARD=U7
Description: Xonar U7, USB Audio
2.1 Surround output to Front and Subwoofer speakers
IOID: (null)
hwIDhw:1,0
...

Now I agree that it prints every kind of thing every card can do but there must be a middle ground so that you can enumerate and choose at run time what card you want to push sound through.
I am using it with your dr_flac.h and it's pretty solid other than this problem.

Versions

cat /proc/asound/version 
Advanced Linux Sound Architecture Driver Version k4.9.60-1-MANJARO.

aplay --version
aplay: version 1.1.4 by Jaroslav Kysela <[email protected]>

latest mini_al.h and dr_flac.h

Looking for OpenAL libs on Android

When trying to compile for Android, despite defining MAL_NO_OPENAL, it looks for <AL/al.h> libraries.

If those libraries are not available, it fails compilation.

Intelligent default buffer sizes.

For anybody listening, I was needing some feedback on an idea for mini_al.

One of the main goals of mini_al is for everything to Just Work, and one of the techniques I use to achieve this is to support a default buffer size so applications don't need to do it themselves. However, one of the big problems I'm having with this is how to determine an appropriate default amidst the myriad of different hardware configurations. A Raspberry Pi, for example, has very different latency characteristics to a modern desktop. This results in a cat and mouse situation where I need to increase the default buffer size to get it to work on slower devices, but then decrease it to improve latency on more capable devices.

The current system simply uses a compile time constant. This has not worked out so I need to change it to something a bit more robust, but I'm not 100% sure what I should do.

I'm wondering what your thoughts would be to do a quick profiling test at initialization time for cases where the default buffer size is requested. My idea looks something like this:

typedef enum
{
    mal_performance_profile_low_latency = 0,
    mal_performance_profile_conservative
} mal_performance_profile;

// Buffer size of 0 = automatic buffer size based on profiling
deviceConfig.bufferSizeInFrames = 0;
deviceConfig.performanceProfile = mal_performance_profile_low_latency;

Alternatively:

deviceConfig.bufferSizeInFrames = 
    mal_calculate_default_buffer_size(mal_performance_profile_low_latency);

The idea of mal_performance_profile is to give the application a bit of control over the calculated buffer size (mal_performance_profile_low_latency means a smaller buffer).

Here are my questions:

  1. Does this idea sound reasonable?
  2. If so, what kind of profiling test do you think I should use? I was thinking of running a second worth of samples at a frequency of, say, 48000 through mini_al's data conversion pipeline and then use the time taken to calculate the buffer size.
  3. If you don't think it's a good idea, do you have an alternative suggestion(s)?
  4. If I was to implement this, is there anything I should consider to ensure it's as reliable and accurate as possible?

Odd behavior after periodically capturing audio over a long period of time

I didn't know whether or not to post here or over at the repository that has the go bindings.

I ended up creating an issue over there but here seems like an okay place to get help - if someone doesn't mind giving it.

Essentially, I'm capturing one second of audio every five seconds to check if my microphone is on. After a couple hours of doing this continuously, other applications start locking up if they try to access the microphone.

gen2brain/malgo#7

a more advanced player sample

Hello,

Providing a builtin sample with the three dr_flac, dr_wav and stb_vorbis would be great for starters.
Also, 3D mixing some day! :-)

Keep up the good work

  • r-lyeh

Wrong alignment on heap

To work with SIMD the structures are set to be aligned at 64 bits. I have my device allocated in the heap, which results in the following warning in visual studio:

warning C4316: 'mal_device': object allocated on the heap may not be aligned 64

To fix that I added the following functions to the header:

mal_device* mal_device_create()
{
	mal_device* d = (mal_device*)_mm_malloc( sizeof( mal_device ), MAL_SIMD_ALIGNMENT );
	memset( d, 0, sizeof( mal_device ) );
	return d;
}

void mal_device_free( mal_device* d )
{
	_mm_free( d );
}

According to this https://stackoverflow.com/questions/3839922/aligned-malloc-in-gcc _mm_malloc and _mm_free are not standard, but there doesn't seem to be a good standard way to do that until C11 and C++17 so some defines for those cases are needed, I suppose.

dr_flac.h gnu c++ compile error

/include/minial/dr_flac.h:145:43: error: missing binary operator before token "("
#elif (defined(clang) && __has_feature(attribute_deprecated))

CentOS 7 x64
gnu c++ 4.8.5 compile error.

__has_feature is a clang extetion, but it write in one line .
suggest:

#if defined(_MSC_VER) && _MSC_VER >= 1700 // Visual Studio 2012
#define DRFLAC_DEPRECATED   __declspec(deprecated)
#elif (defined(__GNUC__) && __GNUC__ >= 4)
#define DRFLAC_DEPRECATED   __attribute__((deprecated))
#elif (defined(__clang__))
#if __has_feature(attribute_deprecated)
#define DRFLAC_DEPRECATED   __attribute__((deprecated))
#endif
#else
#define DRFLAC_DEPRECATED
#endif

Question: simultaneous capture and playback on the same device

I would like to have an app that does sound capture and playback at the same time through the same device. My approach of making a config with two callbacks (send and recv) doesn't seem to work on Linux/PulseAudio and Linux/Alsa. If I initialize device with Capture mode - only capture happens, if I do it in Playback mode - only playback happends. If I use a bitmask - nothing changes (because Playback mode = 0).

I wonder if this is possible at all and if so - what would be the best way to achieve this?

(I'm using Go bindings, so the original question wais here - gen2brain/malgo#4)

C Standards

First of all, great project. It really shows a lot of promise.

I am not sure exactly what C standard this project is meant to target.

I am trying to add it to my project which is -std=c99, and I have noticed some issues. I am also using -Wall -pedantic:

In file included from shell/audio.c:2:
include/miniaudio.h:906:6: warning: ISO C99 doesn’t support unnamed structs/unions [-Wpedantic]
     };
      ^
include/miniaudio.h:928:6: warning: ISO C99 doesn’t support unnamed structs/unions [-Wpedantic]
     };
      ^
include/miniaudio.h:965:6: warning: ISO C99 doesn’t support unnamed structs/unions [-Wpedantic]
     };
      ^
In file included from shell/audio.c:2:
include/miniaudio.h:1639:6: warning: ISO C99 doesn’t support unnamed structs/unions [-Wpedantic]
     };
      ^
include/miniaudio.h:1661:6: warning: ISO C99 doesn’t support unnamed structs/unions [-Wpedantic]
     };
      ^
include/miniaudio.h:1685:6: warning: ISO C99 doesn’t support unnamed structs/unions [-Wpedantic]
     };
      ^
include/miniaudio.h:1815:6: warning: ISO C99 doesn’t support unnamed structs/unions [-Wpedantic]
     };
      ^
include/miniaudio.h:1809:9: warning: struct has no named members [-Wpedantic]
 typedef struct
         ^~~~~~
include/miniaudio.h:2204:6: warning: ISO C99 doesn’t support unnamed structs/unions [-Wpedantic]
     };
      ^
include/miniaudio.h:2251:6: warning: ISO C99 doesn’t support unnamed structs/unions [-Wpedantic]
     };
      ^
include/miniaudio.h:2502:6: warning: ISO C99 doesn’t support unnamed structs/unions [-Wpedantic]
     };
      ^
In file included from shell/audio.c:2:
include/miniaudio.h: In function ‘ma_timer_init’:
include/miniaudio.h:4230:5: warning: implicit declaration of function ‘clock_gettime’; did you mean ‘localtime’? [-Wimplicit-function-declaration]
     clock_gettime(MA_CLOCK_ID, &newTime);
     ^~~~~~~~~~~~~
     localtime
include/miniaudio.h:4224:25: error: ‘CLOCK_REALTIME’ undeclared (first use in this function)
     #define MA_CLOCK_ID CLOCK_REALTIME
                         ^~~~~~~~~~~~~~
include/miniaudio.h:4230:19: note: in expansion of macro ‘MA_CLOCK_ID’
     clock_gettime(MA_CLOCK_ID, &newTime);
                   ^~~~~~~~~~~
include/miniaudio.h:4224:25: note: each undeclared identifier is reported only once for each function it appears in
     #define MA_CLOCK_ID CLOCK_REALTIME
                         ^~~~~~~~~~~~~~
include/miniaudio.h:4230:19: note: in expansion of macro ‘MA_CLOCK_ID’
     clock_gettime(MA_CLOCK_ID, &newTime);
                   ^~~~~~~~~~~
include/miniaudio.h: In function ‘ma_timer_get_time_in_seconds’:
include/miniaudio.h:4224:25: error: ‘CLOCK_REALTIME’ undeclared (first use in this function)
     #define MA_CLOCK_ID CLOCK_REALTIME
                         ^~~~~~~~~~~~~~
include/miniaudio.h:4238:19: note: in expansion of macro ‘MA_CLOCK_ID’
     clock_gettime(MA_CLOCK_ID, &newTime);
                   ^~~~~~~~~~~
include/miniaudio.h: In function ‘ma_sleep__posix’:
include/miniaudio.h:4494:5: warning: implicit declaration of function ‘usleep’; did you mean ‘sleep’? [-Wimplicit-function-declaration]
     usleep(milliseconds * 1000);    /* <-- usleep is in microseconds. */
     ^~~~~~
     sleep
In file included from shell/audio.c:2:
include/miniaudio.h: At top level:
include/miniaudio.h:11138:18: warning: ISO C forbids zero-size array ‘pos’ [-Wpedantic]
     unsigned int pos[0];
                  ^~~
In file included from shell/audio.c:2:
include/miniaudio.h: In function ‘ma_context_get_device_info__alsa’:
include/miniaudio.h:11936:66: warning: implicit declaration of function ‘alloca’; did you mean ‘calloc’? [-Wimplicit-function-declaration]
     ma_snd_pcm_hw_params_t* pHWParams = (ma_snd_pcm_hw_params_t*)alloca(((ma_snd_pcm_hw_params_sizeof_proc)pContext->alsa.snd_pcm_hw_params_sizeof)());
                                                                  ^~~~~~
                                                                  calloc
include/miniaudio.h:11936:41: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     ma_snd_pcm_hw_params_t* pHWParams = (ma_snd_pcm_hw_params_t*)alloca(((ma_snd_pcm_hw_params_sizeof_proc)pContext->alsa.snd_pcm_hw_params_sizeof)());
                                         ^
include/miniaudio.h:11951:45: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     ma_snd_pcm_format_mask_t* pFormatMask = (ma_snd_pcm_format_mask_t*)alloca(((ma_snd_pcm_format_mask_sizeof_proc)pContext->alsa.snd_pcm_format_mask_sizeof)());
                                             ^
include/miniaudio.h: In function ‘ma_device_init_by_type__alsa’:
include/miniaudio.h:12290:36: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
         ma_snd_pcm_info_t* pInfo = (ma_snd_pcm_info_t*)alloca(((ma_snd_pcm_info_sizeof_proc)pContext->alsa.snd_pcm_info_sizeof)());
                                    ^
include/miniaudio.h:12341:17: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     pHWParams = (ma_snd_pcm_hw_params_t*)alloca(((ma_snd_pcm_hw_params_sizeof_proc)pContext->alsa.snd_pcm_hw_params_sizeof)());
                 ^
include/miniaudio.h:12378:23: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
         pFormatMask = (ma_snd_pcm_format_mask_t*)alloca(((ma_snd_pcm_format_mask_sizeof_proc)pContext->alsa.snd_pcm_format_mask_sizeof)());
                       ^
include/miniaudio.h:12504:17: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     pSWParams = (ma_snd_pcm_sw_params_t*)alloca(((ma_snd_pcm_sw_params_sizeof_proc)pContext->alsa.snd_pcm_sw_params_sizeof)());
                 ^

All issues go away except one when I compile with -std=gnu11 -Wall -pedantic:

include/miniaudio.h:11138:18: warning: ISO C forbids zero-size array ‘pos’ [-Wpedantic]
     unsigned int pos[0];
                  ^~~

Checking >=0 on an unsigned integer

GCC (with -Wall and -Wextra) warns me about it. Apparently it's in this function:

static MAL_INLINE float mal_src_sinc__get_input_sample_from_window(const mal_src* pSRC, mal_uint32 channel, mal_uint32 windowPosInSamples, mal_int32 sampleIndex)
{
    mal_assert(pSRC != NULL);
    mal_assert(channel < pSRC->config.channels);
    mal_assert(sampleIndex >= -(mal_int32)pSRC->config.sinc.windowWidth);
    mal_assert(sampleIndex <   (mal_int32)pSRC->config.sinc.windowWidth);

    // The window should always be contained within the input cache.
    mal_assert(windowPosInSamples >= 0);    <-- This
    mal_assert(windowPosInSamples <  mal_countof(pSRC->sinc.input[0]) - pSRC->config.sinc.windowWidth);
    
    return pSRC->sinc.input[channel][windowPosInSamples + pSRC->config.sinc.windowWidth + sampleIndex];
}

Can't compile miniaudio for iOS

I'm trying to compile miniaudio for iOS on revision 519ea2d. However I get a compilation error:

miniaudio.h:17352:106: Cannot initialize a parameter of type 'AudioComponent' (aka 'OpaqueAudioComponent ') with an lvalue of type 'ma_ptr' (aka 'void ')

Any ideas?

library project for macos/ios

For using mini_al in a cross platform application I need to compile it into a library.
It should be simple on mac ... but I'm unable to create a dynamic library.
Is there anybody who has created a library project for mac / ios?
Alternatively ... is there a way to have precompiled libraries for all supported platforms?

mac os: simple_capture

simple_capture from examples doesn't work

$ ./simple_capture
Recording...
Press Enter to stop recording...

Playing...
Press Enter to quit...
INFO: Output Callback: busNumber=0, frameCount=1760, mNumberBuffers=1
  frameCount=1760, mNumberChannels=2, mDataByteSize=14080
INFO: Output Callback: busNumber=0, frameCount=1760, mNumberBuffers=1
  frameCount=1760, mNumberChannels=2, mDataByteSize=14080

[Resolved] Bad audio cracking with PulseAudio

Hi, I'm having a incredibly bad cracking with anything played trough mini_al.

The code adapted from the sample with a few tweaks to chose the backend (copied from another issue here): https://gist.github.com/fungos/7fa6fb159f8fd260ed5aca17b1c0bc5c
In this gist there is the link for the input mp3 sample and the output recorded from another device, as if I try to record directly from the pulseaudio sink, the sound is perfect.

I've tried with SDL, OpenAL, PluseAudio, ALSA and OSS backends, all these have the same issue.
I don't have any issue at all playing any audio in this desktop with any other software, so I imagine it must be related to some mis-configuration initializing mini_al or some initialization internally.

I want to replace BASS audio in a game port I'm doing, and mini_al sounded ideal for the job, I hope to be able to figure this problem :)

Thanks

Linkage error in linux system + qt creator

Hi. and thank you for this awesome library. i am an arch linux user. and i want to use mini_al in my qt application. so i use qmake as build-tools and as you said, we must add these options to compile properly:
-ldl -lpthread -lm
right?
in qmake there is a variable called: __QMAKE_CFLAGS __ to set link options. so here my .pro file:

TEMPLATE = app
QT += quick quickcontrols2 qml
CONFIG += c++11

QMAKE_CC        = gcc
QMAKE_CFLAGS        += -ldl -lpthread -lm
QMAKE_CFLAGS_WARN_ON    = -Wall
QMAKE_CFLAGS_WARN_OFF   = -w
QMAKE_CFLAGS_RELEASE    = -O2
QMAKE_CFLAGS_DEBUG  = -g

QMAKE_CXX       = g++
QMAKE_CXXFLAGS      = $$QMAKE_CFLAGS # -Wdisabled-macro-expansion
QMAKE_CXXFLAGS_WARN_ON  = $$QMAKE_CFLAGS_WARN_ON
QMAKE_CXXFLAGS_WARN_OFF = $$QMAKE_CFLAGS_WARN_OFF
QMAKE_CXXFLAGS_RELEASE  = $$QMAKE_CFLAGS_RELEASE
QMAKE_CXXFLAGS_DEBUG    = $$QMAKE_CFLAGS_DEBUG
QMAKE_CXXFLAGS_THREAD   = $$QMAKE_CFLAGS_THREAD

SOURCES += main.cpp \
    $$files(modules/*.cpp, true) \
    $$files(utility/cpp/*.cpp, true)

HEADERS += $$files(modules/*.h, true) \
           $$files(utility/cpp/*.h, true) \
           $$files(libraries/common/mini_al/*.h, true)

RESOURCES += qml.qrc

linux:!android{
    message("Linux building...")

    # cUrl
    LIBS += -L$$PWD/libraries/linux/curl/lib/ -lcurl
    INCLUDEPATH += $$PWD/libraries/linux/curl/include
    DEPENDPATH += $$PWD/libraries/linux/curl/include

    LIBS += -L/usr/lib -lpthread
    LIBS += -L/usr/lib -lm
    LIBS += -L/usr/lib -ldl

    INCLUDEPATH += /usr/include/c++
    DEPENDPATH += /usr/include/c++
}

but application can not compile and linke properly. part of compile output:

23:18:40: Starting: "/usr/bin/make" 
/mnt/E/QtLinux/5.11.1/gcc_64/bin/qmake -o Makefile ../Naghme/Naghme.pro -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug
Project MESSAGE: Linux building...
g++ -c -pipe -ldl -lpthread -lm -g -std=gnu++11 -Wall -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_QUICKCONTROLS2_LIB -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I../Naghme -I. -I../Naghme/libraries/linux/curl/include -isystem /usr/include/c++ -I/mnt/E/QtLinux/5.11.1/gcc_64/include -I/mnt/E/QtLinux/5.11.1/gcc_64/include/QtQuickControls2 -I/mnt/E/QtLinux/5.11.1/gcc_64/include/QtQuick -I/mnt/E/QtLinux/5.11.1/gcc_64/include/QtGui -I/mnt/E/QtLinux/5.11.1/gcc_64/include/QtQml -I/mnt/E/QtLinux/5.11.1/gcc_64/include/QtNetwork -I/mnt/E/QtLinux/5.11.1/gcc_64/include/QtCore -I. -isystem /usr/include/libdrm -I/mnt/E/QtLinux/5.11.1/gcc_64/mkspecs/linux-g++ -o main.o ../Naghme/main.cpp
.
.
.
/mnt/E/QtLinux/5.11.1/gcc_64/bin/moc -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_QUICKCONTROLS2_LIB -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB --include ./moc_predefs.h -I/mnt/E/QtLinux/5.11.1/gcc_64/mkspecs/linux-g++ -I/mnt/D/Document/WorkSpace/Qt/Project/Naghme -I/mnt/D/Document/WorkSpace/Qt/Project/Naghme/libraries/linux/curl/include -I/usr/include/c++ -I/mnt/E/QtLinux/5.11.1/gcc_64/include -I/mnt/E/QtLinux/5.11.1/gcc_64/include/QtQuickControls2 -I/mnt/E/QtLinux/5.11.1/gcc_64/include/QtQuick -I/mnt/E/QtLinux/5.11.1/gcc_64/include/QtGui -I/mnt/E/QtLinux/5.11.1/gcc_64/include/QtQml -I/mnt/E/QtLinux/5.11.1/gcc_64/include/QtNetwork -I/mnt/E/QtLinux/5.11.1/gcc_64/include/QtCore -I. -I/usr/include/c++/8.2.0 -I/usr/include/c++/8.2.0/x86_64-pc-linux-gnu -I/usr/include/c++/8.2.0/backward -I/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/include -I/usr/local/include -I/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.0/include-fixed -I/usr/include ../Naghme/utility/cpp/NetworkUtil/networkUtil.h -o moc_networkUtil.cpp
g++ -c -pipe -ldl -lpthread -lm -g -std=gnu++11 -Wall -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_QUICKCONTROLS2_LIB -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I../Naghme -I. -I../Naghme/libraries/linux/curl/include -isystem /usr/include/c++ -I/mnt/E/QtLinux/5.11.1/gcc_64/include -I/mnt/E/QtLinux/5.11.1/gcc_64/include/QtQuickControls2 -I/mnt/E/QtLinux/5.11.1/gcc_64/include/QtQuick -I/mnt/E/QtLinux/5.11.1/gcc_64/include/QtGui -I/mnt/E/QtLinux/5.11.1/gcc_64/include/QtQml -I/mnt/E/QtLinux/5.11.1/gcc_64/include/QtNetwork -I/mnt/E/QtLinux/5.11.1/gcc_64/include/QtCore -I. -isystem /usr/include/libdrm -I/mnt/E/QtLinux/5.11.1/gcc_64/mkspecs/linux-g++ -o moc_networkUtil.o moc_networkUtil.cpp
g++ -Wl,-rpath,/mnt/E/QtLinux/5.11.1/gcc_64/lib -Wl,-rpath-link,/mnt/E/QtLinux/5.11.1/gcc_64/lib -o Naghme main.o GhmnConfigs.o dispatcher.o launcher.o jsonUtil.o networkUtil.o qrc_qml.o moc_GhmnConfigs.o moc_dispatcher.o moc_launcher.o moc_jsonUtil.o moc_networkUtil.o   -L/mnt/D/Document/WorkSpace/Qt/Project/Naghme/libraries/linux/curl/lib/ -lcurl -L/usr/lib -lm -ldl -L/mnt/E/QtLinux/5.11.1/gcc_64/lib -lQt5QuickControls2 -lQt5Quick -lQt5Gui -lQt5Qml -lQt5Network -lQt5Core -lGL -lpthread 
/usr/bin/ld: /mnt/E/QtLinux/5.11.1/gcc_64/lib/libQt5QuickTemplates2.so.5: undefined reference to `operator delete(void*, unsigned long)@Qt_5'
collect2: error: ld returned 1 exit status
make: *** [Makefile:290: Naghme] Error 1
23:19:05: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project Naghme (kit: Desktop Qt 5.11.1 GCC 64bit)
When executing step "Make"

and in issue panel(in qt creator) he says:

:-1: error: /mnt/E/QtLinux/5.11.1/gcc_64/lib/libQt5QuickTemplates2.so.5: undefined reference to `operator delete(void*, unsigned long)@Qt_5'

why?

mal_device_write__alsa() raising assert mal_assert(frameCount > 0);

What's happening?

MiniGBS successfully launches and plays two notes before segfaulting. The backtrace (below) appears to reveal that the crash is in mini_al with mal_device_write__alsa() passing a frameCount of 0 to mal_device__read_frames_from_client(), thus triggering the mal_assert(frameCount > 0). I'm not sure of the relevance of this, but I am on plain ALSA (i.e. without PulseAudio) using the dmix plugin for mixing.

Do you have enough information here, or any suggestions for further information I can provide to help us get to the bottom of this?

Versions

mini-al: 0.4
MiniGBS: commit baines/MiniGBS@ef080da
alsa: 1.1.4.1
Linux: 4.13.11

Backtrace

Thread 2 (Thread 0x7f0e666485c0 (LWP 886)):
#0  0x00007f0e655b7d4b in poll () from /usr/lib/libc.so.6
#1  0x000055e65a34fabf in main (argc=2, argv=0x7fffe2e63e38) at minigbs.c:847

Thread 1 (Thread 0x7f0e64331700 (LWP 887)):
#0  0x00007f0e655008a0 in raise () from /usr/lib/libc.so.6
#1  0x00007f0e65501f09 in abort () from /usr/lib/libc.so.6
#2  0x00007f0e654f90dc in __assert_fail_base () from /usr/lib/libc.so.6
#3  0x00007f0e654f9153 in __assert_fail () from /usr/lib/libc.so.6
#4  0x000055e65a350fe0 in mal_device__read_frames_from_client (pDevice=0x55e65a567d00 <audio>, frameCount=0, pSamples=0x55e65adf85d8) at mini_al.h:2200
#5  0x000055e65a35258d in mal_device_write__alsa (pDevice=0x55e65a567d00 <audio>) at mini_al.h:5187
#6  0x000055e65a353ef4 in mal_device__main_loop__alsa (pDevice=0x55e65a567d00 <audio>) at mini_al.h:5758
#7  0x000055e65a355f7a in mal_device__main_loop (pDevice=0x55e65a567d00 <audio>) at mini_al.h:7710
#8  0x000055e65a356153 in mal_worker_thread (pData=0x55e65a567d00 <audio>) at mini_al.h:7790
#9  0x00007f0e6588a08a in start_thread () from /usr/lib/libpthread.so.0
#10 0x00007f0e655c224f in clone () from /usr/lib/libc.so.6

Locking the callback function ala SDL.

I am just wondering with mini_al, is it possible to call something like SDL_LockAudio/SDL_UnlockAudio to have control when the audio playback callback is fired?

Compilation of Simple Playback example as C++ fails in VS2017

In the latest version of MS Visual Studio Simple Playback example fails to compile as C++17.
The errors are:

  • a few E0546 "transfer of control bypasses initialization (mini_al.h, 3816, 3824, 3831, 3840, 3958)"
  • C2362 "initialization of 'bufferDurationInMicroseconds' is skipped by 'goto done' (mini_al.h, 4083)"
  • C2362 "initialization of 'pBestFormatTemp' is skipped by 'goto done' (mini_al.h, 4083)"
    The code compiles as C though.
    P.s. Also linkage fails with clang on Windows both as C and C++17 but I'm not certain whether this is an issue with the code, or an issue with my clang installation.

The library looks great anyway, thank you for your work.

in dr_flac.h, dozens of warnings: "this statement may fall through"

Hi.

Context

Compiling on Xubuntu 18.04 (GCC 7.3.0) with

gcc -W -Wall -Wextra simple_mixing.c -lpthread -lm -ldl -o simple_mixing

Observed

A number of warnings, including dozens of:

../extras/dr_flac.h:1322:17: warning: this statement may fall through [-Wimplicit-fallthrough=]
     case 8: crc = drflac_crc16_byte(crc, (drflac_uint8)((data >> 56) & 0xFF));
             ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expected

No warning.

Additional information

It's the well-known quirk of C.

Solutions are suggested e.g. on c++ - GCC 7, -Wimplicit-fallthrough warnings, and portable way to clear them? - Stack Overflow

Suggestion

I can offer a PR.

Thank you for your attention.

Affected code locations

https://github.com/dr-soft/miniaudio/blob/0694af403207e72b9fb999207bbd3a47511f1eb7/extras/dr_flac.h#L1319-L1331

https://github.com/dr-soft/miniaudio/blob/0694af403207e72b9fb999207bbd3a47511f1eb7/extras/dr_flac.h#L1300-L1306

https://github.com/dr-soft/miniaudio/blob/0694af403207e72b9fb999207bbd3a47511f1eb7/extras/dr_flac.h#L2115-L2149

Issue when pausing and resuming

I have the following functions I am using to pause the audio thread when my iOS app is going background and to resume audio when it is back to foreground.

void Audio::Pause()
{
   if (mal_device_is_started(&device))
   {
       mal_result r = mal_device_stop(&device);
       NS_ASSERT(r == MAL_SUCCESS);
   }
}

void Audio::Resume()
{
   if (!mal_device_is_started(&device))
   {
       mal_result r = mal_device_start(&device);
       NS_ASSERT(r == MAL_SUCCESS);
   }
}

The audio is paused correctly but in the next resume I get the following error when calling mal_device_start:

mal_device_start() called while another thread is in the process of stopping it.. I verified that after calling Pause() the function mal_device_is_started returns false.

The same approach is working on Android, although sometimes (5% of times) the audio is not resumed. No errors this time, just silence.

Thanks!

[macOS] Deadlock on mal_device_uninit

Hello,

Problem: We seem to have intermittent deadlock while trying to cleanup device when closing our application.
OS: macOS Mojave 10.14
Context: Our app is using input device to capture audio and do some FFT calculations.
Project: https://github.com/Gargaj/Bonzomatic

Upon closure we do:

  • mal_device_stop
  • mal_device_uninit
  • mal_context_uninit

as seen here: https://github.com/Gargaj/Bonzomatic/blob/master/src/platform_common/FFT.cpp#L92
(The use of mini_al is entirely comprised in this file).

On macOS Mojave (at least) this results in a deadlock as seen on this stack trace:

Stack Trace

Failed attempts: Trying to not call mal_device_stop before mal_device_uninit didn't solve the problem and still resulted in a deadlock.

Ugly workaround: I could find a temporary workaround by actually putting a sleep(1) between mal_device_stop and mal_device_uninit, to try to give a chance for the lock to be removed.

flac tags bug

playing a flac file from memory that contains a new line value in tags skips the beginning of the song

Emscripten: Unsupported audio callback buffer size 0!

I just tried today enabling audio in our HTML5 build. I am getting the following error:

Initializing SDL audio threw an exception: "Unsupported audio callback buffer size 0!"! Continuing without audio.

I tried without enabling any special flag (so no SDL2 for now).

State of the library in comparison to OpenAL Soft?

Hi @mackron, congrats for such an amazing lib, I've been looking for a library like this for long time now.

I'm thinking about replacing current raylib audio module backend (OpenAL Soft) by mini_al and I would like to know how mini_al compares to OpenAL Soft in features... Actually, I'm mostly just using audio playback for complete loaded sounds and music streaming.

My final goal would be to remove any external library dependency for raylib, I mean, include with raylib basecode all required dependencies.

Memory leak from advanced_config

Hi valgrind reports some memory leaks

Compiled: clang -g -O1 -o advanced_config advanced_config.c -ldl

 valgrind ./advanced_config 
==2346== Memcheck, a memory error detector
==2346== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==2346== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==2346== Command: ./advanced_config
==2346== 
Playback Devices (24)
    0: Playback/recording through the PulseAudio sound server
    1: PulseAudio Sound Server
    2: HDA Intel PCH, ALC665 Analog (Default Audio Device)
    3: HDA Intel PCH, ALC665 Analog (Front speakers)
    4: HDA Intel PCH, ALC665 Analog (2.1 Surround output to Front and Subwoofer speakers)
    5: HDA Intel PCH, ALC665 Analog (4.0 Surround output to Front and Rear speakers)
    6: HDA Intel PCH, ALC665 Analog (4.1 Surround output to Front, Rear and Subwoofer speakers)
    7: HDA Intel PCH, ALC665 Analog (5.0 Surround output to Front, Center and Rear speakers)
    8: HDA Intel PCH, ALC665 Analog (5.1 Surround output to Front, Center, Rear and Subwoofer speakers)
    9: HDA Intel PCH, ALC665 Analog (7.1 Surround output to Front, Center, Side, Rear and Woofer speakers)
    10: HDA Intel PCH, ALC665 Digital (IEC958 (S/PDIF) Digital Audio Output)
    11: HDA Intel PCH, HDMI 0 (HDMI Audio Output)
    12: HDA Intel PCH, ALC665 Analog (Direct sample mixing device)
    13: HDA Intel PCH, ALC665 Digital (Direct sample mixing device)
    14: HDA Intel PCH, HDMI 0 (Direct sample mixing device)
    15: HDA Intel PCH, ALC665 Analog (Direct sample snooping device)
    16: HDA Intel PCH, ALC665 Digital (Direct sample snooping device)
    17: HDA Intel PCH, HDMI 0 (Direct sample snooping device)
    18: HDA Intel PCH, ALC665 Analog (Direct hardware device without any conversions)
    19: HDA Intel PCH, ALC665 Digital (Direct hardware device without any conversions)
    20: HDA Intel PCH, HDMI 0 (Direct hardware device without any conversions)
    21: HDA Intel PCH, ALC665 Analog (Hardware device with all software conversions)
    22: HDA Intel PCH, ALC665 Digital (Hardware device with all software conversions)
    23: HDA Intel PCH, HDMI 0 (Hardware device with all software conversions)

Capture Devices (2)
    0: Playback/recording through the PulseAudio sound server
    1: PulseAudio Sound Server
Press Enter to quit...
Device stopped
==2346== 
==2346== HEAP SUMMARY:
==2346==     in use at exit: 138,058 bytes in 1,558 blocks
==2346==   total heap usage: 136,898 allocs, 135,340 frees, 5,515,796 bytes allocated
==2346== 
==2346== LEAK SUMMARY:
==2346==    definitely lost: 13,312 bytes in 2 blocks
==2346==    indirectly lost: 0 bytes in 0 blocks
==2346==      possibly lost: 43,506 bytes in 1,324 blocks
==2346==    still reachable: 81,240 bytes in 232 blocks
==2346==         suppressed: 0 bytes in 0 blocks
==2346== Rerun with --leak-check=full to see details of leaked memory
==2346== 
==2346== For counts of detected and suppressed errors, rerun with: -v
==2346== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
razor@m:~/Documents/mini_al/examples$ valgrind --leak-check=full ./advanced_config 
==2367== Memcheck, a memory error detector
==2367== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==2367== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==2367== Command: ./advanced_config
==2367== 
Playback Devices (24)
    0: Playback/recording through the PulseAudio sound server
    1: PulseAudio Sound Server
    2: HDA Intel PCH, ALC665 Analog (Default Audio Device)
    3: HDA Intel PCH, ALC665 Analog (Front speakers)
    4: HDA Intel PCH, ALC665 Analog (2.1 Surround output to Front and Subwoofer speakers)
    5: HDA Intel PCH, ALC665 Analog (4.0 Surround output to Front and Rear speakers)
    6: HDA Intel PCH, ALC665 Analog (4.1 Surround output to Front, Rear and Subwoofer speakers)
    7: HDA Intel PCH, ALC665 Analog (5.0 Surround output to Front, Center and Rear speakers)
    8: HDA Intel PCH, ALC665 Analog (5.1 Surround output to Front, Center, Rear and Subwoofer speakers)
    9: HDA Intel PCH, ALC665 Analog (7.1 Surround output to Front, Center, Side, Rear and Woofer speakers)
    10: HDA Intel PCH, ALC665 Digital (IEC958 (S/PDIF) Digital Audio Output)
    11: HDA Intel PCH, HDMI 0 (HDMI Audio Output)
    12: HDA Intel PCH, ALC665 Analog (Direct sample mixing device)
    13: HDA Intel PCH, ALC665 Digital (Direct sample mixing device)
    14: HDA Intel PCH, HDMI 0 (Direct sample mixing device)
    15: HDA Intel PCH, ALC665 Analog (Direct sample snooping device)
    16: HDA Intel PCH, ALC665 Digital (Direct sample snooping device)
    17: HDA Intel PCH, HDMI 0 (Direct sample snooping device)
    18: HDA Intel PCH, ALC665 Analog (Direct hardware device without any conversions)
    19: HDA Intel PCH, ALC665 Digital (Direct hardware device without any conversions)
    20: HDA Intel PCH, HDMI 0 (Direct hardware device without any conversions)
    21: HDA Intel PCH, ALC665 Analog (Hardware device with all software conversions)
    22: HDA Intel PCH, ALC665 Digital (Hardware device with all software conversions)
    23: HDA Intel PCH, HDMI 0 (Hardware device with all software conversions)

Capture Devices (2)
    0: Playback/recording through the PulseAudio sound server
    1: PulseAudio Sound Server
Press Enter to quit...
Device stopped
==2367== 
==2367== HEAP SUMMARY:
==2367==     in use at exit: 139,002 bytes in 1,568 blocks
==2367==   total heap usage: 136,976 allocs, 135,408 frees, 5,529,088 bytes allocated
==2367== 
==2367== 3 bytes in 1 blocks are possibly lost in loss record 1 of 205
==2367==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2367==    by 0x5A509E4: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A5101D: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A51109: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A52FF3: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A53224: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A53224: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A5383C: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A5569A: snd_config_hook_load (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A561B8: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A56874: snd_config_update_r (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367== 
==2367== 3 bytes in 1 blocks are possibly lost in loss record 2 of 205
==2367==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2367==    by 0x5A509E4: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A5101D: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A51109: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A52FF3: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A53224: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A53224: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A5383C: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A55565: snd_config_hook_load (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x6236B75: ???
==2367==    by 0x5A561B8: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367== 
==2367== 4 bytes in 2 blocks are possibly lost in loss record 4 of 205
==2367==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2367==    by 0x50C9489: strdup (strdup.c:42)
==2367==    by 0x5A53370: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A52F61: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A567EA: snd_config_update_r (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A56D14: snd_config_update (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A60AAB: snd_ctl_open (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A5774B: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A5852E: snd_determine_driver (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A55816: snd_config_hook_load_for_all_cards (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A561B8: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367== 
==2367== 4 bytes in 2 blocks are possibly lost in loss record 5 of 205
==2367==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2367==    by 0x50C9489: strdup (strdup.c:42)
==2367==    by 0x5A53370: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A52F61: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A53524: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A52F61: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A567EA: snd_config_update_r (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A56D14: snd_config_update (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A60AAB: snd_ctl_open (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A5774B: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A5852E: snd_determine_driver (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367== 
==2367== 12 bytes in 2 blocks are possibly lost in loss record 7 of 205
==2367==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2367==    by 0x5A509E4: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A5101D: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A51109: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A52FF3: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A53224: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A5383C: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A55565: snd_config_hook_load (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x6236B75: ???
==2367==    by 0x5A561B8: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A56E05: snd_config_searcha_hooks (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367== 
==2367== 12 bytes in 2 blocks are possibly lost in loss record 8 of 205
==2367==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2367==    by 0x5A509E4: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A5101D: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A51109: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A52FF3: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A53224: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A5383C: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A5569A: snd_config_hook_load (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A561B8: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A56874: snd_config_update_r (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A56D14: snd_config_update (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367== 
==2367== 12 bytes in 6 blocks are possibly lost in loss record 9 of 205
==2367==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2367==    by 0x50C9489: strdup (strdup.c:42)
==2367==    by 0x5A53370: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A52F61: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A53524: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A52F61: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A53524: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A52F61: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A567EA: snd_config_update_r (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A56D14: snd_config_update (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A60AAB: snd_ctl_open (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367== 
==2367== 14 bytes in 2 blocks are possibly lost in loss record 10 of 205
==2367==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2367==    by 0x5A509E4: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A5101D: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A51109: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A52FF3: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A53524: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A52F61: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A53524: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A52F61: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A567EA: snd_config_update_r (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A56D14: snd_config_update (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367== 
==2367== 14 bytes in 2 blocks are possibly lost in loss record 11 of 205
==2367==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2367==    by 0x5A509E4: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A50C96: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A50F5C: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A51109: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A52FF3: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A567EA: snd_config_update_r (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A56D14: snd_config_update (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A60AAB: snd_ctl_open (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A5774B: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A5852E: snd_determine_driver (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367== 
==2367== 15 bytes in 3 blocks are possibly lost in loss record 12 of 205
==2367==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2367==    by 0x5A509E4: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A5101D: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A52DDE: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A53224: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A5383C: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A55565: snd_config_hook_load (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x6236B75: ???
==2367==    by 0x5A561B8: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A56E05: snd_config_searcha_hooks (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A56F00: snd_config_searchva_hooks (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367== 
==2367== 16 bytes in 2 blocks are possibly lost in loss record 25 of 205
==2367==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2367==    by 0x5A509E4: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A5101D: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A52DDE: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A5383C: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A55565: snd_config_hook_load (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x6236B75: ???
==2367==    by 0x5A561B8: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A56E05: snd_config_searcha_hooks (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A56F00: snd_config_searchva_hooks (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367==    by 0x5A57015: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==2367== 


==2367== 
==2367== 12,288 bytes in 1 blocks are definitely lost in loss record 204 of 205
==2367==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2367==    by 0x407118: main (advanced_config.c:76)
==2367== 

Memory leak from simple_enumeration

Hi valgrind reports some memory leaks

Compiled: clang -g -O1 -o simple_enumeration simple_enumeration.c -ldl

valgrind --leak-check=full ./simple_enumeration


Playback Devices
    0: Playback/recording through the PulseAudio sound server
    1: Discard all samples (playback) or generate zero samples (capture)
    2: PulseAudio Sound Server
    3: HDA Intel PCH, ALC665 Analog
    4: HDA Intel PCH, ALC665 Digital
    5: HDA Intel PCH, HDMI 0

Capture Devices
    0: Playback/recording through the PulseAudio sound server
    1: Discard all samples (playback) or generate zero samples (capture)
    2: PulseAudio Sound Server
==895== 
==895== HEAP SUMMARY:
==895==     in use at exit: 109,980 bytes in 1,485 blocks
==895==   total heap usage: 55,880 allocs, 54,395 frees, 2,334,273 bytes allocated
==895== 
==895== 3 bytes in 1 blocks are possibly lost in loss record 1 of 126
==895==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==895==    by 0x5A509E4: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5101D: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A51109: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A52FF3: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A53224: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A53224: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5383C: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5569A: snd_config_hook_load (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A561B8: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A56874: snd_config_update_r (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895== 
==895== 3 bytes in 1 blocks are possibly lost in loss record 2 of 126
==895==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==895==    by 0x5A509E4: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5101D: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A51109: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A52FF3: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A53224: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A53224: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5383C: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A55565: snd_config_hook_load (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x6236B75: ???
==895==    by 0x5A561B8: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895== 
==895== 4 bytes in 2 blocks are possibly lost in loss record 3 of 126
==895==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==895==    by 0x50C9489: strdup (strdup.c:42)
==895==    by 0x5A53370: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A52F61: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A567EA: snd_config_update_r (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A56D14: snd_config_update (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A60AAB: snd_ctl_open (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5774B: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5852E: snd_determine_driver (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A55816: snd_config_hook_load_for_all_cards (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A561B8: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895== 
==895== 4 bytes in 2 blocks are possibly lost in loss record 4 of 126
==895==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==895==    by 0x50C9489: strdup (strdup.c:42)
==895==    by 0x5A53370: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A52F61: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A53524: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A52F61: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A567EA: snd_config_update_r (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A56D14: snd_config_update (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A60AAB: snd_ctl_open (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5774B: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5852E: snd_determine_driver (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895== 
==895== 12 bytes in 2 blocks are possibly lost in loss record 6 of 126
==895==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==895==    by 0x5A509E4: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5101D: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A51109: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A52FF3: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A53224: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5383C: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A55565: snd_config_hook_load (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x6236B75: ???
==895==    by 0x5A561B8: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A56E05: snd_config_searcha_hooks (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895== 
==895== 12 bytes in 2 blocks are possibly lost in loss record 7 of 126
==895==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==895==    by 0x5A509E4: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5101D: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A51109: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A52FF3: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A53224: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5383C: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5569A: snd_config_hook_load (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A561B8: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A56874: snd_config_update_r (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A56D14: snd_config_update (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895== 
==895== 12 bytes in 6 blocks are possibly lost in loss record 8 of 126
==895==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==895==    by 0x50C9489: strdup (strdup.c:42)
==895==    by 0x5A53370: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A52F61: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A53524: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A52F61: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A53524: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A52F61: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A567EA: snd_config_update_r (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A56D14: snd_config_update (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A60AAB: snd_ctl_open (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895== 
==895== 14 bytes in 2 blocks are possibly lost in loss record 9 of 126
==895==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==895==    by 0x5A509E4: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5101D: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A51109: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A52FF3: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A53524: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A52F61: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A53524: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A52F61: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A567EA: snd_config_update_r (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A56D14: snd_config_update (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895== 
==895== 14 bytes in 2 blocks are possibly lost in loss record 10 of 126
==895==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==895==    by 0x5A509E4: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A50C96: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A50F5C: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A51109: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A52FF3: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A567EA: snd_config_update_r (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A56D14: snd_config_update (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A60AAB: snd_ctl_open (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5774B: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5852E: snd_determine_driver (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895== 
==895== 15 bytes in 3 blocks are possibly lost in loss record 11 of 126
==895==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==895==    by 0x5A509E4: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5101D: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A52DDE: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A53224: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5383C: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A55565: snd_config_hook_load (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x6236B75: ???
==895==    by 0x5A561B8: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A56E05: snd_config_searcha_hooks (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A56F00: snd_config_searchva_hooks (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895== 
==895== 16 bytes in 2 blocks are possibly lost in loss record 15 of 126
==895==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==895==    by 0x5A509E4: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5101D: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A52DDE: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5383C: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A55565: snd_config_hook_load (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x6236B75: ???
==895==    by 0x5A561B8: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A56E05: snd_config_searcha_hooks (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A56F00: snd_config_searchva_hooks (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A57015: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895== 
==895== 16 bytes in 8 blocks are possibly lost in loss record 16 of 126
==895==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==895==    by 0x50C9489: strdup (strdup.c:42)
==895==    by 0x5A53370: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A52F61: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A53224: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A53224: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A535F2: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A567EA: snd_config_update_r (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A56D14: snd_config_update (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A60AAB: snd_ctl_open (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5774B: ??? (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)
==895==    by 0x5A5852E: snd_determine_driver (in /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0)

simple_playback blocks (no sound) on Ubuntu 18.04 / pulseaudio.

Hi.

Context

Ubuntu 18.04 (actually Xubuntu, practically the same) with regular pulseaudio server (version 1:11.1-1ubuntu7.2), no specific tweak. gcc 7.3.0 .

Compile with

gcc -W -Wall -Wextra -g simple_playback.c -lpthread -lm -ldl -o simple_playback

I started with current https://github.com/dr-soft/miniaudio/tree/master a.k.a. e184644

Expected

Sound is heard.

Observed

No sound.
No output besides Press Enter to quit.... Then I added more output.

Additional information.

I have not noticed any other sound problem on the machine : applications work, audio, video, full duplex, everything. There's only an occasional sound corruption on pulseaudio output, solved with a pulseaudio -k and autospawn, but that seems unrelated.

Debug information

For comfort I fixed unrelated warnings and re-enabled the printf in the pulseaudio code. The exact code I now use is pushed to https://github.com/fidergo-stephane-gourichon/miniaudio/tree/test_on_ubuntu1804_pulseaudio

Here's a full output:

./simple_playback /usr/share/orage/sounds/Wall_c.wav

Using device: Audio interne Stéréo analogique
DECODER: 16-bit Signed Integer / 1 / 11025
DEVICE:  16-bit Signed Integer / 2 / 44100 / PulseAudio
Press Enter to quit...TRACE: Outer loop.
TRACE: Inner loop.
TRACE: Playback: pa_mainloop_iterate(). writableSizeInBytes=4228, periodSizeInBytes=5280

I also tried with a 44100Hz 2 channel WAV file, with flac file, same result.

I traced with gdb.
Execution blocks inside call to pa_mainloop_iterate:

int error = ((ma_pa_mainloop_iterate_proc)pDevice->pContext->pulse.pa_mainloop_iterate)((ma_pa_mainloop*)pDevice->pulse.pMainLoop, 1, NULL);

Here's a backtrace:

(gdb) bt
#0  ma_device_write__pulse (pDevice=0x7ffffffe6480, pPCMFrames=0x7fffe40adee0, frameCount=1024) at ../miniaudio.h:14677
#1  0x00005555555983c9 in ma_worker_thread (pData=0x7ffffffe6480) at ../miniaudio.h:22471
#2  0x00007ffff7bbd6db in start_thread (arg=0x7fffe40b0700) at pthread_create.c:463
#3  0x00007ffff734488f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

When stuck, I sometimes have a more complete backtrace:

#0  0x00007ffff7337cf6 in __GI_ppoll (fds=0x5555557d3ea0, nfds=3, timeout=<optimized out>, sigmask=0x0) at ../sysdeps/unix/sysv/linux/ppoll.c:39
#1  0x00007ffff6ff6ec1 in pa_mainloop_poll () from /usr/lib/x86_64-linux-gnu/libpulse.so
#2  0x00007ffff6ff74d0 in pa_mainloop_iterate () from /usr/lib/x86_64-linux-gnu/libpulse.so
#3  0x00005555555939f0 in ma_device_write__pulse (pDevice=0x7ffffffe6480, pPCMFrames=0x7fffe40adee0, frameCount=1024) at ../miniaudio.h:14677
#4  0x00005555555983c9 in ma_worker_thread (pData=0x7ffffffe6480) at ../miniaudio.h:22471
#5  0x00007ffff7bbd6db in start_thread (arg=0x7fffe40b0700) at pthread_create.c:463
#6  0x00007ffff734488f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Also, here's the end of an strace output:

[pid 16582] write(1, "Press Enter to quit...", 22Press Enter to quit...) = 22
[pid 16582] read(0,  <unfinished ...>
[pid 16583] getpid()                    = 16582
[pid 16583] getpid()                    = 16582
[pid 16583] write(5, "W", 1)            = 1
[pid 16583] mmap(NULL, 134217728, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = 0x7fc52fa60000
[pid 16583] munmap(0x7fc52fa60000, 5898240) = 0
[pid 16583] munmap(0x7fc534000000, 61210624) = 0
[pid 16583] mprotect(0x7fc530000000, 135168, PROT_READ|PROT_WRITE) = 0
[pid 16583] write(5, "W", 1)            = 1
[pid 16583] read(4, "WW", 10)           = 2
[pid 16583] write(6, "\1\0\0\0\0\0\0\0", 8) = 8
[pid 16583] read(4, 0x7fc53825bbde, 10) = -1 EAGAIN (Resource temporarily unavailable)
[pid 16583] ppoll([{fd=4, events=POLLIN}, {fd=7, events=POLLIN}, {fd=8, events=POLLIN}], 3, {tv_sec=29, tv_nsec=999777000}, NULL, 8) = 1 ([{fd=8, revents=POLLIN}], left {tv_sec=29, tv_nsec=999694603})
[pid 16583] read(8, "\1\0\0\0\0\0\0\0", 8) = 8
[pid 16583] write(1, "TRACE: Outer loop.\n", 19TRACE: Outer loop.
) = 19
[pid 16583] write(1, "TRACE: Inner loop.\n", 19TRACE: Inner loop.
) = 19
[pid 16583] getpid()                    = 16582
[pid 16583] getpid()                    = 16582
[pid 16583] write(1, "TRACE: Playback: pa_mainloop_ite"..., 89TRACE: Playback: pa_mainloop_iterate(). writableSizeInBytes=4932, periodSizeInBytes=5280
) = 89
[pid 16583] read(4, 0x7fc53825bc8e, 10) = -1 EAGAIN (Resource temporarily unavailable)
[pid 16583] ppoll([{fd=4, events=POLLIN}, {fd=7, events=POLLIN}, {fd=8, events=POLLIN}], 3, NULL, NULL, 8

File descriptor 4 may the a communication pipe between threads as shown below.

stat --format="%N"  /proc/16582/fd/* /proc/16583/fd/*

'/proc/16582/fd/0' -> '/dev/pts/10'
'/proc/16582/fd/1' -> '/dev/pts/10'
'/proc/16582/fd/2' -> '/dev/pts/10'
'/proc/16582/fd/3' -> '/usr/share/orage/sounds/Wall_c.wav'
'/proc/16582/fd/4' -> 'pipe:[823676]'
'/proc/16582/fd/5' -> 'pipe:[823676]'
'/proc/16582/fd/6' -> 'anon_inode:[eventfd]'
'/proc/16582/fd/7' -> 'socket:[824606]'
'/proc/16582/fd/8' -> 'anon_inode:[eventfd]'
'/proc/16583/fd/0' -> '/dev/pts/10'
'/proc/16583/fd/1' -> '/dev/pts/10'
'/proc/16583/fd/2' -> '/dev/pts/10'
'/proc/16583/fd/3' -> '/usr/share/orage/sounds/Wall_c.wav'
'/proc/16583/fd/4' -> 'pipe:[823676]'
'/proc/16583/fd/5' -> 'pipe:[823676]'
'/proc/16583/fd/6' -> 'anon_inode:[eventfd]'
'/proc/16583/fd/7' -> 'socket:[824606]'
'/proc/16583/fd/8' -> 'anon_inode:[eventfd]'

$ grep -a . /proc/16582/cmdline /proc/16583/cmdline 

/proc/16582/cmdline:./simple_playback/usr/share/orage/sounds/Wall_c.wav
/proc/16583/cmdline:./simple_playback/usr/share/orage/sounds/Wall_c.wav

Can I do something more to help you figuring out what's wrong?

Thanks.

Testing New Backends: Web Audio and AAudio

I've gone ahead and pushed an update to the dev branch which includes two new backends: Web Audio (Emscripten) and AAudio (the new Android audio API). These will be the new priority backends for web and Android respectively, so I was hoping to get some testing in before merging into master.

Calling @raysan5, @jesusdesantos and @digitalgust (in addition to anybody else who'd be able to donate some time) since I think you guys are using one or both of these platforms which will be affected. Doesn't matter if you can't get to it, and no rush or anything - just trying to get some more coverage before merging is all.

Thanks!

Audio crackling on some machines on WASAPI

We've tried using this for our game, and multiple people are reporting crackling on their machines with WASAPI. DirectSound is fine. We've tried upping the buffer duration to 200ms and the period count to 4, but the crackling persists.

Using default duration/period, one machine had issues when using the following native format: 48000Hz, f32, 5.1. These are the values of the device:

device.internalChannels: 6
device.internalSampleRate: 48000
device.internalFormat: 5
device.format: 5
device.channels: 2
device.sampleRate: 44100
device.bufferSizeInFrames: 1197
device.periods: 2

Android openSLES mal_device_uninit deadlock

init a playback mal_device , then playback audio success
but uninit the device encounter a deadlock:
deadlock at line.18250
if (pDevice->opensl.pAudioPlayerObj) MAL_OPENSL_OBJ(pDevice->opensl.pAudioPlayerObj)->Destroy((SLObjectItf)pDevice->opensl.pAudioPlayerObj);

12-15 02:09:27.078 30702-31005/org.minijvm.activity I/libOpenSLES: Emulating old channel mask behavior (ignoring positional mask 0x3, using default mask 0x3 based on channel count of 2)
12-15 02:09:27.084 30702-31005/org.minijvm.activity W/AudioTrack: AUDIO_OUTPUT_FLAG_FAST denied by client; transfer 1, track 22050 Hz, output 48000 Hz
12-15 02:09:27.087 30702-31005/org.minijvm.activity D/AudioTrack: Client defaulted notificationFrames to 296 for frameCount 890
12-15 02:09:43.381 30702-31005/org.minijvm.activity E/libOpenSLES: Object::Destroy(0x7f68ba9000) for engine ignored; 2 total active objects
12-15 02:09:43.381 30702-31005/org.minijvm.activity E/libOpenSLES: Object::Destroy(0x7f68ba9000) for engine ignored; active object ID 2 at 0x7f68dd1000
12-15 02:09:43.381 30702-31005/org.minijvm.activity E/libOpenSLES: Object::Destroy(0x7f68ba9000) for engine ignored; active object ID 3 at 0x7f68a89c00
12-15 02:13:09.824 30702-31005/org.minijvm.activity E/libOpenSLES: frameworks/wilhelm/src/itf/IObject.c:556: pthread_mutex_lock_timeout_np returned 110
12-15 02:13:09.845 30702-31005/org.minijvm.activity E/libOpenSLES: frameworks/wilhelm/src/itf/IObject.c:556: pthread_mutex_lock_timeout_np returned 110
12-15 02:13:09.875 30702-31005/org.minijvm.activity E/libOpenSLES: frameworks/wilhelm/src/itf/IObject.c:556: pthread_mutex_lock_timeout_np returned 110
12-15 02:13:09.915 30702-31005/org.minijvm.activity E/libOpenSLES: frameworks/wilhelm/src/itf/IObject.c:556: pthread_mutex_lock_timeout_np returned 110
12-15 02:13:09.966 30702-31005/org.minijvm.activity E/libOpenSLES: frameworks/wilhelm/src/itf/IObject.c:556: pthread_mutex_lock_timeout_np returned 110
12-15 02:13:10.067 30702-31005/org.minijvm.activity E/libOpenSLES: frameworks/wilhelm/src/itf/IObject.c:556: pthread_mutex_lock_timeout_np returned 110
12-15 02:13:10.067 30702-31005/org.minijvm.activity W/libOpenSLES: frameworks/wilhelm/src/itf/IObject.c:556: pthread 0x7f6a27a450 (tid 31005) sees object 0x7f68ba9000 was locked by pthread 0x7f6a27a450 (tid 31005) at frameworks/wilhelm/src/itf/IObject.c:411

VS2019 optimising away pDevice in ma_device_init

When compiling in Release mode with VS2019, it seems we got the ma_device* pDevice passed in parameter to ma_device_init() optimised out.

The code then crashes at
https://github.com/dr-soft/miniaudio/blob/master/miniaudio.h#L23182
Giving some read access violation on the ma_zero_object(pDevice);
Everything seems fine and correctly setup, up to that line.

Trying to find a solution on our client code, where the pDevice we pass (as ref) is a global, we did attempt to use heap allocated version, or r/w some random members from our code, but it didn't solve the problem.

We found a workaround by switching to SecureZeroMemory instead of ZeroMemory at line
https://github.com/dr-soft/miniaudio/blob/master/miniaudio.h#L3483
(so in miniaudio / mini_al)

I dont know if you can reproduce it. I hope it's not something we overlooked on our side.
All I know is that it runs fine when built with all our other targets, with previous VS compilers, and even with VS2019 (in Debug mode).

issue on switching output device

OS: Windows 10 x64

mal_backend_wasapi // crashes on switching the output device
mal_backend_winmm // doesnt change the output on switching device
mal_backend_dsound // works on first switch but after that it doesnt switch anymore

Warnings about unused parameters

Hi.

Context

Compiling any of the examples on Xubuntu 18.04 (GCC 7.3.0), e.g.

gcc -W -Wall -Wextra simple_enumeration.c -lpthread -lm -ldl -o simple_enumeration

Observed

Warnings like this, 9 per target:

gcc -W -Wall -Wextra simple_enumeration.c -lpthread -lm -ldl -o simple_enumeration
In file included from simple_enumeration.c:2:0:
../miniaudio.h: In function ‘ma_context_enumerate_devices_sink_callback__pulse’:
../miniaudio.h:13793:71: warning: unused parameter ‘pPulseContext’ [-Wunused-parameter]
 void ma_context_enumerate_devices_sink_callback__pulse(ma_pa_context* pPulseContext, const ma_pa_sink_info* pSinkInfo, int endOfList, void* pUserData)

Expected

No warning.

Additional information

I can offer a PR.

Thank you for your attention.

build fail in xcode10.1 for ios platform

mini_al - v0.8.10 - 2018-10-21

line 13632 : #include <AVFoundation/AVFoundation.h>

build error : Could not build module 'AVFoundation'
i have already add the AVFoundation.framework

i test it and success on macOS, but ios cant compile

my work that export minial to java throuth jni.

Ring Buffer Documentation/Example

I'm attempting to use the built-in ring buffer rather than use my own (which was not originally designed for audio and this creates problems, since it is non-atomic), but can't seem to figure it out. Maybe I'm just low-IQ and shouldn't be programming. Either way, I think a usage example or clearer documentation on it would help out a lot.
Thanks!

CoInitializeEx issue

mini_al is initializing the COM library using COINIT_MULTITHREADED but sometimes applications need a different value for this. For example, in our case we need COINIT_APARTMENTTHREADED. I made the following change to the library to properly support this.

#ifndef MAL_COINIT_VALUE
    #define MAL_COINIT_VALUE 0  // 0 = COINIT_MULTITHREADED
#endif

mal_CoInitializeEx(pContext, NULL, MAL_COINIT_VALUE);

Note that this is only needed for the main thread.

Sound Layering and Volume Adjustment Example?

I am trying to learn to use mini_al to layer looping (streamed) background music with one-shot sound effects (e.g. footsteps), but there don't seem to be examples for layering sounds--only opening a single audio file. Also, it is unclear how one would modify volume. I am sure that all of this is doable, but are there more advanced examples floating around?

windows.h dependency level

On Windows mini_al includes windows.h, that's a really big header that includes ALL Win32 API. Probably mini_al does not require all those definitions just to deal with audio driver.

The following defines could be added before windows.h inclusion to avoid LOT of unnecesary types and headers:

#ifdef MAL_WIN32

//----------------------------------------------------------------------------------
// Undefine any conflicting windows.h symbols
// If defined, the following flags inhibit definition of the indicated items.
//----------------------------------------------------------------------------------
#define NOGDICAPMASKS     // CC_*, LC_*, PC_*, CP_*, TC_*, RC_
#define NOVIRTUALKEYCODES // VK_*
#define NOWINMESSAGES     // WM_*, EM_*, LB_*, CB_*
#define NOWINSTYLES       // WS_*, CS_*, ES_*, LBS_*, SBS_*, CBS_*
#define NOSYSMETRICS      // SM_*
#define NOMENUS           // MF_*
#define NOICONS           // IDI_*
#define NOKEYSTATES       // MK_*
#define NOSYSCOMMANDS     // SC_*
#define NORASTEROPS       // Binary and Tertiary raster ops
#define NOSHOWWINDOW      // SW_*
#define OEMRESOURCE       // OEM Resource values
#define NOATOM            // Atom Manager routines
#define NOCLIPBOARD       // Clipboard routines
#define NOCOLOR           // Screen colors
#define NOCTLMGR          // Control and Dialog routines
#define NODRAWTEXT        // DrawText() and DT_*
#define NOGDI             // All GDI defines and routines
#define NOKERNEL          // All KERNEL defines and routines
#define NOUSER            // All USER defines and routines
//#define NONLS             // All NLS defines and routines
#define NOMB              // MB_* and MessageBox()
#define NOMEMMGR          // GMEM_*, LMEM_*, GHND, LHND, associated routines
#define NOMETAFILE        // typedef METAFILEPICT
#define NOMINMAX          // Macros min(a,b) and max(a,b)
#define NOMSG             // typedef MSG and associated routines
#define NOOPENFILE        // OpenFile(), OemToAnsi, AnsiToOem, and OF_*
#define NOSCROLL          // SB_* and scrolling routines
#define NOSERVICE         // All Service Controller routines, SERVICE_ equates, etc.
#define NOSOUND           // Sound driver routines
#define NOTEXTMETRIC      // typedef TEXTMETRIC and associated routines
#define NOWH              // SetWindowsHook and WH_*
#define NOWINOFFSETS      // GWL_*, GCL_*, associated routines
#define NOCOMM            // COMM driver routines
#define NOKANJI           // Kanji support stuff.
#define NOHELP            // Help engine interface.
#define NOPROFILER        // Profiler interface.
#define NODEFERWINDOWPOS  // DeferWindowPos routines
#define NOMCX             // Modem Configuration Extensions

// Type required before windows.h inclusion
typedef struct tagMSG *LPMSG;

#include <windows.h>

// Type required by some unused function...
typedef struct tagBITMAPINFOHEADER {
  DWORD biSize;
  LONG  biWidth;
  LONG  biHeight;
  WORD  biPlanes;
  WORD  biBitCount;
  DWORD biCompression;
  DWORD biSizeImage;
  LONG  biXPelsPerMeter;
  LONG  biYPelsPerMeter;
  DWORD biClrUsed;
  DWORD biClrImportant;
} BITMAPINFOHEADER, *PBITMAPINFOHEADER;

#else
#include <stdlib.h> // For malloc()/free()
#include <string.h> // For memset()
#endif

I know it could be a bit ugly, specially the case of needing some specific types defined before/after including the header... so I understand if this change is not being included in the official mini_al.

I'm posting it here just in case it could be useful for someone and because it took me some time to figure it out... it also serves my pourpose of allowing #include "mini_al.h" in raylib with no conflicting symbols.

Monkeys Audio

would you mind adding support for ape, Monekys Audio?

simple_playback from examples does not work on mac os

simple_playback from examples doesn't output any sound unless i add backends:

mal_backend backends[] = {
	mal_backend_winmm,
	mal_backend_dsound,
	mal_backend_wasapi,
	mal_backend_alsa,
	mal_backend_oss,
	mal_backend_opensl,
	mal_backend_openal,
	mal_backend_sdl,
	mal_backend_null
};

macOS High Sierra, 10.13.3

Compilation error on VS2017

With a copy of the master branch I tried to create a cpp where it included the following and nothing else:

#define STB_VORBIS_IMPLEMENTATION
#include <mini_al/extras/stb_vorbis.h>
#define DR_MP3_IMPLEMENTATION
#include <mini_al/extras/dr_mp3.h>
#define MINI_AL_IMPLEMENTATION
#include <mini_al/mini_al.h>

But it failed to compile, complaining about several windows typedefs such as LPUNKNOWN being undefined.

To fix it, I moved the #include <objbase.h> from line 5028 to line 3839, so now it looks like

#ifdef MAL_WIN32
#include <objbase.h>
typedef HRESULT (WINAPI * MAL_PFN_CoInitializeEx)(LPVOID pvReserved, DWORD  dwCoInit);
...

And this fixed the problem.

Incorrect device name in iOS

Just trying the latest version (v0.8.11) in iOS, everything is working fine so far! Just a minor detail, the device.name is wrong, I am getting the value '\354' when printing in.

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.