const char *path;
enum audio_source_mode source_mode;
- void *data;
u32 size;
+ void *data;
};
typedef struct audio_mix_info audio_mix_info;
/* 32mb fixed */
vg_audio.audio_pool =
- vg_create_linear_allocator( vg_mem.rtmemory, 1024*1024*32 );
+ vg_create_linear_allocator( vg_mem.rtmemory, 1024*1024*32,
+ VG_MEMORY_SYSTEM );
/* fixed */
u32 decode_size = AUDIO_DECODE_SIZE * SFX_MAX_SYSTEMS;
{
for( u32 i=0; i<count; i++ )
{
- dst[ i*2 + 0 ] = (float)src[i] * (1.0f/32767.0f);
- dst[ i*2 + 1 ] = (float)src[i] * (1.0f/32767.0f);
+ dst[ i*2 + 0 ] = ((float)src[i]) * (1.0f/32767.0f);
+ dst[ i*2 + 1 ] = ((float)src[i]) * (1.0f/32767.0f);
}
}
* ........ more wrecked code sorry!
*/
VG_STATIC int
-stb_vorbis_get_samples_i16_interleaved_mono( stb_vorbis *f, i16 *buffer,
- int len )
+stb_vorbis_get_samples_i16_downmixed( stb_vorbis *f, i16 *buffer, int len )
{
int n = 0,
c = VG_MIN( 1, f->channels - 1 );
if( source_mode == k_audio_source_mono )
{
- i16 *src = &((i16 *)ent->info.source->data)[ cursor ];
+ i16 *src_buffer = ent->info.source->data,
+ *src = &src_buffer[cursor];
+
audio_decode_uncompressed_mono( src, samples_this_run, dst );
}
else if( source_mode == k_audio_source_compressed )
}
VG_STATIC void audio_entity_mix( aatree_ptr id, float *buffer,
- u32 frame_count )
+ u32 frame_count )
{
audio_entity *ent = &vg_audio.active_players[id].ent;
{
vg_linear_clear( vg_mem.scratch );
u32 fsize;
- void *filedata = vg_file_read( vg_mem.scratch, clip->path, &fsize );
stb_vorbis_alloc alloc = {
.alloc_buffer = vg_linear_alloc( vg_mem.scratch, AUDIO_DECODE_SIZE ),
.alloc_buffer_length_in_bytes = AUDIO_DECODE_SIZE
};
+ void *filedata = vg_file_read( vg_mem.scratch, clip->path, &fsize );
+
int err;
stb_vorbis *decoder = stb_vorbis_open_memory(
filedata, fsize, &err, &alloc );
u32 length_samples = stb_vorbis_stream_length_in_samples( decoder ),
data_size = length_samples * sizeof(i16);
+ audio_lock();
clip->data = vg_linear_alloc( vg_audio.audio_pool, data_size );
clip->size = length_samples;
+ audio_unlock();
- int read_samples = stb_vorbis_get_samples_i16_interleaved_mono(
+ int read_samples = stb_vorbis_get_samples_i16_downmixed(
decoder, clip->data, length_samples );
+ if( read_samples != length_samples )
+ vg_fatal_exit_loop( "Decode error" );
+
float mb = (float)(data_size) / (1024.0f*1024.0f);
- vg_info( "Loaded audio clip '%s' (%.1fmb)\n", clip->path, mb );
+ vg_info( "Loaded audio clip '%s' (%.1fmb) %u samples\n", clip->path, mb,
+ length_samples );
}
/* load in directly */
else if( clip->source_mode == k_audio_source_compressed )
{
+ audio_lock();
clip->data = vg_file_read( vg_audio.audio_pool, clip->path, &clip->size );
+ audio_unlock();
if( !clip->data )
vg_fatal_exit_loop( "Audio failed to load" );
if( sys->enqued )
{
- vg_warn( "Audio commit spamming; already enqued (%s)\n", sys->name );
+ vg_warn( "[2] Audio commit spamming; already enqued (%s)\n", sys->name );
return;
}
return;
}
+ if( player->enqued )
+ {
+ vg_warn( "[1] Audio commit spamming; already enqued (%s)\n",
+ player->name );
+ return;
+ }
+
player->info.source = clip;
audio_player_commit( player );
}