k_audio_format_none4 = 0xE00u,
k_audio_format_bird = 0x1000u,
- k_audio_format_none5 = 0x1200u,
+ k_audio_format_gen = 0x1200u,
k_audio_format_none6 = 0x1400u,
k_audio_format_none7 = 0x1600u,
k_audio_format_none8 = 0x1800u,
union { /* TODO oof.. */
u64 _p64_;
const char *path;
+ void *func;
};
u32 flags;
struct vg_audio_system{
SDL_AudioDeviceID sdl_output_device;
+ char *force_device_name; /* NULL: using default */
void *audio_pool,
*decode_buffer;
audio_lock_checker_store(0);
SDL_AtomicUnlock( &vg_audio.sl_sync );
}
-
static void audio_mixer_callback( void *user, u8 *stream, int frame_count );
-static void vg_audio_init(void)
-{
- /* TODO: Move here? */
- vg_console_reg_var( "debug_audio", &vg_audio.debug_ui,
- k_var_dtype_i32, VG_VAR_CHEAT );
- vg_console_reg_var( "debug_dsp", &vg_audio.debug_dsp,
- k_var_dtype_i32, VG_VAR_CHEAT );
- vg_console_reg_var( "volume", &vg_audio.external_global_volume,
- k_var_dtype_f32, VG_VAR_PERSISTENT );
-
- /* allocate memory */
- /* 32mb fixed */
- vg_audio.audio_pool =
- vg_create_linear_allocator( vg_mem.rtmemory, 1024*1024*32,
- VG_MEMORY_SYSTEM );
-
- /* fixed */
- u32 decode_size = AUDIO_DECODE_SIZE * AUDIO_CHANNELS;
- vg_audio.decode_buffer = vg_linear_alloc( vg_mem.rtmemory, decode_size );
-
- vg_dsp_init();
+static void vg_audio_device_init(void){
SDL_AudioSpec spec_desired, spec_got;
spec_desired.callback = audio_mixer_callback;
spec_desired.channels = 2;
spec_desired.userdata = NULL;
vg_audio.sdl_output_device =
- SDL_OpenAudioDevice( NULL, 0, &spec_desired, &spec_got,0 );
+ SDL_OpenAudioDevice( vg_audio.force_device_name, 0,
+ &spec_desired, &spec_got,0 );
+
+ vg_info( "Start audio device (%u, F32, %u) @%s\n",
+ spec_desired.freq,
+ AUDIO_FRAME_SIZE,
+ vg_audio.force_device_name );
if( vg_audio.sdl_output_device ){
SDL_PauseAudioDevice( vg_audio.sdl_output_device, 0 );
+ vg_success( "Unpaused device %d.\n", vg_audio.sdl_output_device );
}
else{
- vg_fatal_error(
+ vg_error(
"SDL_OpenAudioDevice failed. Your default audio device must support:\n"
" Frequency: 44100 hz\n"
" Buffer size: 512\n"
}
}
+
+static void vg_audio_init(void){
+ vg_console_reg_var( "debug_audio", &vg_audio.debug_ui,
+ k_var_dtype_i32, VG_VAR_CHEAT );
+ vg_console_reg_var( "debug_dsp", &vg_audio.debug_dsp,
+ k_var_dtype_i32, VG_VAR_CHEAT );
+ vg_console_reg_var( "volume", &vg_audio.external_global_volume,
+ k_var_dtype_f32, VG_VAR_PERSISTENT );
+
+ /* allocate memory */
+ /* 32mb fixed */
+ vg_audio.audio_pool =
+ vg_create_linear_allocator( vg_mem.rtmemory, 1024*1024*32,
+ VG_MEMORY_SYSTEM );
+
+ /* fixed */
+ u32 decode_size = AUDIO_DECODE_SIZE * AUDIO_CHANNELS;
+ vg_audio.decode_buffer = vg_linear_alloc( vg_mem.rtmemory, decode_size );
+
+ vg_dsp_init();
+ vg_audio_device_init();
+}
+
static void vg_audio_free(void)
{
vg_dsp_free();
#define AUDIO_EDIT_OWNERSHIP 0x40
#define AUDIO_EDIT_SAMPLING_RATE 0x80
-static void audio_channel_init( audio_channel *ch, audio_clip *clip, u32 flags )
-{
+static void audio_channel_init( audio_channel *ch, audio_clip *clip,
+ u32 flags ){
audio_require_lock();
ch->group = 0;
ch->world_id = 0;
if( (ch->source->flags & AUDIO_FLAG_FORMAT) == k_audio_format_bird )
strcpy( ch->name, "[array]" );
+ else if( (ch->source->flags & AUDIO_FLAG_FORMAT) == k_audio_format_gen )
+ strcpy( ch->name, "[program]" );
else
vg_strncpy( clip->path, ch->name, 32, k_strncpy_always_add_null );
else if( format == k_audio_format_stereo ){
ch->source_length = ch->source->size / 2;
}
+ else if( format == k_audio_format_gen ){
+ ch->source_length = 0xffffffff;
+ }
else{
ch->source_length = ch->source->size;
}
else if( format == k_audio_format_bird ){
synth_bird_generate_samples( ch->bird_handle, dst, samples_this_run );
}
+ else if( format == k_audio_format_gen ){
+ void (*fn)( void *data, f32 *buf, u32 count ) = ch->source->func;
+ fn( ch->source->data, dst, samples_this_run );
+ }
else{
i16 *src_buffer = ch->source->data,
*src = &src_buffer[ch->cursor];
* Debugging
*/
-static void audio_debug_ui( m4x4f mtx_pv )
-{
+static void audio_debug_ui(
+
+#ifdef VG_3D
+ m4x4f
+#else
+ m3x3f
+#endif
+ mtx_pv ){
+
if( !vg_audio.debug_ui )
return;
&vg_prof_audio_mix,
&vg_prof_audio_dsp}, 3,
budget, (ui_rect){ 4, VG_PROFILE_SAMPLE_COUNT*2 + 8,
- 512, 0 }, 3 );
+ 512, 0 }, 3, 0 );
char perf[128];
ui_fill( row, 0xa0000000 | ch->colour );
ui_text( row, perf, 1, k_ui_align_middle_left, 0 );
+#ifdef VG_3D
if( AUDIO_FLAG_SPACIAL_3D ){
v4f wpos;
v3_copy( ch->editable_state.spacial_falloff, wpos );
rect_copy( wr, overlap_buffer[ overlap_length ++ ] );
}
}
+#endif
}
audio_unlock();