Skip to content

Failed assertion when calling calling ma_device_start #1047

@TiLogic

Description

@TiLogic

Failed assertion on macOS (0.12-dev branch) when calling ma_device_start after calling ma_device_stop.

Demo

#define MA_DEBUG_OUTPUT
#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio/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_data_source_read_pcm_frames(pDecoder, pOutput, frameCount, NULL);

  (void)pInput;
}

int main(int argc, char **argv) {
  ma_result result;
  ma_decoder_config decoderConfig;
  ma_decoder decoder;
  ma_device_config deviceConfig;
  ma_device device;
  ma_format format;
  ma_uint32 channels;
  ma_uint32 sampleRate;
  ma_uint32 ms;

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

  if (argc < 3) {
    ms = 1000;
  } else {
    ms = strtol(argv[2], NULL, 10);
  }

  decoderConfig = ma_decoder_config_init_default();

  result = ma_decoder_init_file(argv[1], &decoderConfig, &decoder);
  if (result != MA_SUCCESS) {
    printf("Failed to initialize decoder.");
    return -1;
  }

  result = ma_data_source_get_data_format(&decoder, &format, &channels, &sampleRate, NULL, 0);
  if (result != MA_SUCCESS) {
    printf("Failed to retrieve decoder data format.");
    ma_decoder_uninit(&decoder);
    return -1;
  }

  deviceConfig = ma_device_config_init(ma_device_type_playback);
  deviceConfig.playback.format = format;
  deviceConfig.playback.channels = channels;
  deviceConfig.sampleRate = sampleRate;
  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 -1;
  }

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

  printf("Waiting %u ms before calling ma_device_stop ...\n", ms);
  ma_sleep(ms);

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

  printf("Waiting %u ms before calling ma_device_start ...\n", ms);
  ma_sleep(ms);

  printf("ma_device_status: %u \n", ma_device_get_status(&device));

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

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

  return 0;
}

Output

DEBUG: Attempting to initialize Core Audio backend...
DEBUG: Loading library: /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation

DEBUG: Loading symbol: CFStringGetCString

DEBUG: Loading symbol: CFRelease

DEBUG: Loading library: /System/Library/Frameworks/CoreAudio.framework/CoreAudio

DEBUG: Loading symbol: AudioObjectGetPropertyData

DEBUG: Loading symbol: AudioObjectGetPropertyDataSize

DEBUG: Loading symbol: AudioObjectSetPropertyData

DEBUG: Loading symbol: AudioObjectAddPropertyListener

DEBUG: Loading symbol: AudioObjectRemovePropertyListener

DEBUG: Loading library: /System/Library/Frameworks/AudioUnit.framework/AudioUnit

DEBUG: Loading symbol: AudioComponentFindNext

DEBUG: Loading symbol: AudioComponentFindNext

DEBUG: Loading symbol: AudioComponentInstanceDispose

DEBUG: Loading symbol: AudioComponentInstanceNew

DEBUG: Loading symbol: AudioOutputUnitStart

DEBUG: Loading symbol: AudioOutputUnitStop

DEBUG: Loading symbol: AudioUnitAddPropertyListener

DEBUG: Loading symbol: AudioUnitGetPropertyInfo

DEBUG: Loading symbol: AudioUnitGetProperty

DEBUG: Loading symbol: AudioUnitSetProperty

DEBUG: Loading symbol: AudioUnitInitialize

DEBUG: Loading symbol: AudioUnitRender

DEBUG: Successfully initialized Core Audio backend.
DEBUG: System Architecture:
DEBUG:   Endian: LE
DEBUG:   SSE2:   NO
DEBUG:   AVX2:   NO
DEBUG:   NEON:   YES
INFO: [Core Audio]
INFO:   MacBook Air Speakers (Playback)
INFO:     Format:      32-bit IEEE Floating Point -> 32-bit IEEE Floating Point
INFO:     Channels:    2 -> 2
INFO:     Sample Rate: 44100 -> 48000n
INFO:     Buffer Size: 480*3 (1440)
INFO:     Conversion:
INFO:       Pre Format Conversion:  NO
INFO:       Post Format Conversion: NO
INFO:       Channel Routing:        NO
INFO:       Resampling:             YES
INFO:       Passthrough:            NO
INFO:       Channel Map In:         {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT}
INFO:       Channel Map Out:        {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT}
Waiting 1000 ms before calling ma_device_stop ...
Waiting 1000 ms before calling ma_device_start ...
ma_device_status: 4
Assertion failed: (ma_device_get_status(pDevice) == ma_device_status_stopped), function ma_device_start, file miniaudio.h, line 45626.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions