Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ma_device_init with non default config + ma_device_start = valgrind problem #893

Open
mulle-nat opened this issue Sep 5, 2024 · 0 comments

Comments

@mulle-nat
Copy link

Boiling it down to the smallest setup, I am on ubuntu/gnome/linux using pulseaudio here, I ran into problems with this code:

   device_config                   = ma_device_config_init( ma_device_type_playback);
   device_config.playback.format   = ma_format_f32;
   device_config.playback.channels = 2;
   device_config.sampleRate        = ma_standard_sample_rate_48000;

   ma_device_init( NULL, &device_config, &device);
   ma_device_start( &device);
  • judging from the documentation I expected ma_device_init( NULL, NULL, &_device) to work, but it doesn't. I need a ma_device_config. It's no biggie
  • when I run the test program an unpleasant sound occurs, not silence as I would expect
  • when I valgrind the test program (see below) I get some uninitialised value reports, which explain the noise I guess.
  • when I keep the ma_device_config as returned from ma_device_config_init all problems vanish

This is my full source:

#import <MulleAudio/miniaudio.h> 

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

//#define HAVE_RESOURCE_MANAGER
//#define HAVE_CONTEXT
#define HAVE_DEVICE_CONFIG
#define HAVE_NON_DEFAULT_DEVICE_CONFIG
// MEMO: have no luck with ma_device_init( NULL, NULL, &_device)


int   main( int argc, char *argv[])
{
#ifdef HAVE_CONTEXT
   ma_context                   _context;
   ma_result                    _context_state;
#endif
   ma_context                   *context_p;
#ifdef HAVE_RESOURCE_MANAGER
   ma_resource_manager          _resource_manager;
   ma_result                    _resource_manager_state;
   ma_resource_manager_config   resource_config;
#endif
   ma_device                    _device;
   ma_result                    _device_state;
#ifdef HAVE_DEVICE_CONFIG
   ma_device_config             device_config;
#endif
   ma_device_config             *device_config_p;
   ma_uint32                    i;
   ma_uint32                    play_count;
   ma_device_info               *play_infos;

   device_config_p = NULL;
   context_p       = NULL;

#ifdef HAVE_CONTEXT
   // ** context **
   _context_state = ma_context_init( NULL, 0, NULL, &_context);
   if( _context_state != MA_SUCCESS)
      abort();
   context_p = &_context;
#endif

#if HAVE_RESOURCE_MANAGER
   // ** resource manager **
   resource_config                   = ma_resource_manager_config_init();
   resource_config.decodedFormat     = ma_format_f32;
   resource_config.decodedChannels   = 2;
   resource_config.decodedSampleRate = ma_standard_sample_rate_48000;

   _resource_manager_state = ma_resource_manager_init( &resource_config, &_resource_manager);
   if( _resource_manager_state != MA_SUCCESS)
    abort();
#endif

   // ** device **
#ifdef HAVE_DEVICE_CONFIG
   device_config                   = ma_device_config_init( ma_device_type_playback);
#ifdef HAVE_NON_DEFAULT_DEVICE_CONFIG
   device_config.playback.format   = ma_format_f32;
   device_config.playback.channels = 2;
   device_config.sampleRate        = ma_standard_sample_rate_48000;
#endif
   device_config_p                 = &device_config;

# ifdef HAVE_CONTEXT
   if( ma_context_get_devices( &_context, &play_infos, &play_count, NULL, NULL) != MA_SUCCESS)
   {
      abort();
   }

   for( i = 0; i < play_count; i++)
      if( play_infos[ i].isDefault)
      {
         device_config.playback.pDeviceID = &play_infos[ i].id;
         fprintf( stderr, "Found default device\n");
         break;
      }
# endif
#endif

   _device_state = ma_device_init( context_p, device_config_p, &_device);
   if( _device_state != MA_SUCCESS)
   {
      fprintf( stderr, "Could not init device (context: %p, config: %p)\n", context_p, device_config_p);
      abort();
   }

   ma_device_start( &_device);
   fprintf( stderr, "Started device\n");

   sleep(2);
   return( 0);
}
==89834== Thread 2:
==89834== Conditional jump or move depends on uninitialised value(s)
==89834==    at 0x48A15FE: ma_pcm_f32_to_s24__reference (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:44785)
==89834==    by 0x48A15FE: ma_pcm_f32_to_s24__optimized (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:44808)
==89834==    by 0x48A15FE: ma_pcm_f32_to_s24__sse2 (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:44814)
==89834==    by 0x48A15FE: ma_pcm_f32_to_s24 (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:44831)
==89834==    by 0x48A211A: ma_pcm_convert (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:45039)
==89834==    by 0x48A21E2: ma_convert_pcm_frames_format (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:45051)
==89834==    by 0x48BD37A: ma_data_converter_process_pcm_frames__format_only (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:54329)
==89834==    by 0x48BCEB5: ma_data_converter_process_pcm_frames (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:54933)
==89834==    by 0x4893AB4: ma_device__read_frames_from_client (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:18935)
==89834==    by 0x4892C56: ma_device_handle_backend_data_callback (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:42531)
==89834==    by 0x4905E35: ma_device_write_to_stream__pulse (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:30145)
==89834==    by 0x4904257: ma_device_start__pulse (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:30758)
==89834==    by 0x4891C60: ma_worker_thread (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:40888)
==89834==    by 0x4902455: ma_thread_entry_proxy (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:16508)
==89834==    by 0x4CFAAC2: start_thread (pthread_create.c:442)
==89834== 
==89834== Conditional jump or move depends on uninitialised value(s)
==89834==    at 0x48A1629: ma_pcm_f32_to_s24__reference (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:44785)
==89834==    by 0x48A1629: ma_pcm_f32_to_s24__optimized (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:44808)
==89834==    by 0x48A1629: ma_pcm_f32_to_s24__sse2 (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:44814)
==89834==    by 0x48A1629: ma_pcm_f32_to_s24 (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:44831)
==89834==    by 0x48A211A: ma_pcm_convert (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:45039)
==89834==    by 0x48A21E2: ma_convert_pcm_frames_format (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:45051)
==89834==    by 0x48BD37A: ma_data_converter_process_pcm_frames__format_only (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:54329)
==89834==    by 0x48BCEB5: ma_data_converter_process_pcm_frames (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:54933)
==89834==    by 0x4893AB4: ma_device__read_frames_from_client (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:18935)
==89834==    by 0x4892C56: ma_device_handle_backend_data_callback (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:42531)
==89834==    by 0x4905E35: ma_device_write_to_stream__pulse (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:30145)
==89834==    by 0x4904257: ma_device_start__pulse (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:30758)
==89834==    by 0x4891C60: ma_worker_thread (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:40888)
==89834==    by 0x4902455: ma_thread_entry_proxy (src/srcO/MulleUI/MulleAudio/src/miniaudio.h:16508)
==89834==    by 0x4CFAAC2: start_thread (pthread_create.c:442)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant