#pragma GCC optimize ("O3")
#endif
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
#define STB_VORBIS_MAX_CHANNELS 2
#include "stb/stb_vorbis.h"
+#pragma GCC diagnostic pop
+
#ifdef __GNUC__
#pragma GCC pop_options
#endif
{
u32 new_current = vg_audio.mem_current + size;
if( new_current > vg_audio.mem_total )
- {
- vg_error( "audio pool over budget!\n" );
- free( vg_audio.mem );
- return NULL;
- }
+ vg_fatal_exit_loop( "Audio pool ran out of memory" );
void *ptr = vg_audio.mem + vg_audio.mem_current;
vg_audio.mem_current = new_current;
static void audio_mixer_callback( ma_device *pDevice, void *pOutBuf,
const void *pInput, ma_uint32 frameCount );
-static int vg_audio_init(void)
+static void vg_audio_init(void)
{
vg_mutex_init( &vg_audio.mux_checker );
vg_mutex_init( &vg_audio.mux_sync );
u32 decode_region = AUDIO_DECODE_SIZE * SFX_MAX_SYSTEMS;
vg_audio.mem_total = 1024*1024*32;
vg_audio.mem_current = 0;
- vg_audio.mem = malloc( vg_audio.mem_total + decode_region );
+ vg_audio.mem = vg_alloc( vg_audio.mem_total + decode_region );
vg_audio.decode_mem = &((u8 *)vg_audio.mem)[vg_audio.mem_total];
/* setup pool */
if( ma_device_init( NULL, dconf, device) != MA_SUCCESS )
{
- vg_error( "ma_device failed to initialize" );
- return 0;
+ vg_fatal_exit_loop( "(audio) ma_device failed to initialize" );
}
else
{
if( ma_device_start( device ) != MA_SUCCESS )
{
ma_device_uninit( device );
- vg_error( "ma_device failed to start" );
- return 0;
+ vg_fatal_exit_loop( "(audio) ma_device failed to start" );
}
}
vg_success( "Ready\n" );
- return 1;
}
static void vg_audio_free(void * nothing)
ma_device *device = &vg_audio.miniaudio_device;
ma_device_uninit( device );
- free( vg_audio.mem );
-
- vg_mutex_free( &vg_audio.mux_checker );
- vg_mutex_free( &vg_audio.mux_sync );
+ vg_free( vg_audio.mem );
+ vg_audio.mem = NULL;
}
/*
if( player->init )
return;
- vg_error( "Must init before playing! (%s)\n", player->name );
- abort();
+ vg_fatal_exit_loop( "Must init audio player before playing! \n" );
+}
+
+static void audio_require_clip_loaded( audio_clip *clip )
+{
+ if( clip->data )
+ return;
+
+ vg_fatal_exit_loop( "Must load audio clip before playing! \n" );
}
/* Play a clip using player. If its already playing something, it will
{
audio_require_lock();
audio_require_init( player );
+ audio_require_clip_loaded( clip );
player->info.source = clip;
audio_player_commit( player );
static void audio_play_oneshot( audio_clip *clip, float volume )
{
audio_require_lock();
+ audio_require_clip_loaded( clip );
if( vg_audio.queue_len >= vg_list_size( vg_audio.entity_queue ) )
{