2008-05-06 03:35:37 +00:00
|
|
|
#include "layout.h"
|
2008-03-04 07:15:25 +00:00
|
|
|
#include "../vgmstream.h"
|
|
|
|
|
2018-04-12 22:51:24 +02:00
|
|
|
static void block_update(VGMSTREAM * vgmstream);
|
|
|
|
|
2008-03-04 07:15:25 +00:00
|
|
|
void render_vgmstream_blocked(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstream) {
|
|
|
|
int samples_written=0;
|
|
|
|
|
|
|
|
int frame_size = get_vgmstream_frame_size(vgmstream);
|
|
|
|
int samples_per_frame = get_vgmstream_samples_per_frame(vgmstream);
|
|
|
|
int samples_this_block;
|
|
|
|
|
2017-11-18 02:22:57 +01:00
|
|
|
/* get samples in the current block */
|
2017-07-01 23:02:24 +02:00
|
|
|
if (vgmstream->current_block_samples) {
|
|
|
|
samples_this_block = vgmstream->current_block_samples;
|
2017-11-18 02:22:57 +01:00
|
|
|
} else if (frame_size == 0) { /* assume 4 bit */ //TODO: get_vgmstream_frame_size() really should return bits... */
|
2008-07-03 02:20:52 +00:00
|
|
|
samples_this_block = vgmstream->current_block_size * 2 * samples_per_frame;
|
|
|
|
} else {
|
|
|
|
samples_this_block = vgmstream->current_block_size / frame_size * samples_per_frame;
|
|
|
|
}
|
2008-03-04 07:15:25 +00:00
|
|
|
|
2017-11-18 02:22:57 +01:00
|
|
|
/* decode all samples */
|
|
|
|
while (samples_written < sample_count) {
|
2008-03-04 07:15:25 +00:00
|
|
|
int samples_to_do;
|
|
|
|
|
|
|
|
if (vgmstream->loop_flag && vgmstream_do_loop(vgmstream)) {
|
2017-11-18 02:22:57 +01:00
|
|
|
/* on loop those values are changed */
|
2017-07-01 23:02:24 +02:00
|
|
|
if (vgmstream->current_block_samples) {
|
|
|
|
samples_this_block = vgmstream->current_block_samples;
|
2017-11-18 02:22:57 +01:00
|
|
|
} else if (frame_size == 0) { /* assume 4 bit */ //TODO: get_vgmstream_frame_size() really should return bits... */
|
2008-07-03 02:20:52 +00:00
|
|
|
samples_this_block = vgmstream->current_block_size * 2 * samples_per_frame;
|
|
|
|
} else {
|
|
|
|
samples_this_block = vgmstream->current_block_size / frame_size * samples_per_frame;
|
|
|
|
}
|
2008-03-04 07:15:25 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-11-18 02:22:57 +01:00
|
|
|
/* probably block bug or EOF, next calcs would give wrong values and buffer segfaults */
|
2018-04-12 22:51:24 +02:00
|
|
|
if (samples_this_block < 0) {
|
|
|
|
VGM_LOG("layout_blocked: wrong block at 0x%lx\n", vgmstream->current_block_offset);
|
2017-11-18 02:22:57 +01:00
|
|
|
memset(buffer + samples_written*vgmstream->channels, 0, (sample_count - samples_written) * vgmstream->channels * sizeof(sample));
|
2018-04-12 22:51:24 +02:00
|
|
|
break; /* probable infinite loop otherwise */
|
2017-11-18 02:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
samples_to_do = vgmstream_samples_to_do(samples_this_block, samples_per_frame, vgmstream);
|
|
|
|
if (samples_written + samples_to_do > sample_count)
|
|
|
|
samples_to_do = sample_count - samples_written;
|
2008-03-04 07:15:25 +00:00
|
|
|
|
2017-11-18 02:22:57 +01:00
|
|
|
if (vgmstream->current_block_offset >= 0) {
|
2018-06-17 01:04:16 +02:00
|
|
|
/* samples_this_block = 0 is allowed (empty block): do nothing then move to next block */
|
|
|
|
if (samples_to_do > 0)
|
|
|
|
decode_vgmstream(vgmstream, samples_written, samples_to_do, buffer);
|
2017-11-18 02:22:57 +01:00
|
|
|
}
|
2008-03-04 07:15:25 +00:00
|
|
|
else {
|
2018-04-12 22:51:24 +02:00
|
|
|
/* block end signal (used in halpst): partially 0-set buffer */
|
2008-03-04 07:15:25 +00:00
|
|
|
int i;
|
2017-11-18 02:22:57 +01:00
|
|
|
for (i = samples_written*vgmstream->channels; i < (samples_written+samples_to_do)*vgmstream->channels; i++) {
|
|
|
|
buffer[i]=0;
|
|
|
|
}
|
2008-03-04 07:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
samples_written += samples_to_do;
|
|
|
|
vgmstream->current_sample += samples_to_do;
|
2017-11-18 02:22:57 +01:00
|
|
|
vgmstream->samples_into_block += samples_to_do;
|
2008-03-04 07:15:25 +00:00
|
|
|
|
2017-11-18 02:22:57 +01:00
|
|
|
|
|
|
|
/* move to next block when all samples are consumed */
|
2017-08-20 02:18:48 +02:00
|
|
|
if (vgmstream->samples_into_block==samples_this_block
|
|
|
|
/*&& vgmstream->current_sample < vgmstream->num_samples*/) { /* don't go past last block */
|
2018-04-12 22:51:24 +02:00
|
|
|
block_update(vgmstream);
|
2008-03-04 07:15:25 +00:00
|
|
|
|
2008-07-03 21:21:01 +00:00
|
|
|
/* for VBR these may change */
|
2018-04-12 22:51:24 +02:00
|
|
|
frame_size = get_vgmstream_frame_size(vgmstream);
|
2008-07-03 21:21:01 +00:00
|
|
|
samples_per_frame = get_vgmstream_samples_per_frame(vgmstream);
|
|
|
|
|
2017-11-18 02:22:57 +01:00
|
|
|
/* get samples in the current block */
|
2017-07-01 23:02:24 +02:00
|
|
|
if (vgmstream->current_block_samples) {
|
|
|
|
samples_this_block = vgmstream->current_block_samples;
|
2017-11-18 02:22:57 +01:00
|
|
|
} else if (frame_size == 0) { /* assume 4 bit */ //TODO: get_vgmstream_frame_size() really should return bits... */
|
2008-07-03 02:20:52 +00:00
|
|
|
samples_this_block = vgmstream->current_block_size * 2 * samples_per_frame;
|
|
|
|
} else {
|
|
|
|
samples_this_block = vgmstream->current_block_size / frame_size * samples_per_frame;
|
|
|
|
}
|
2017-11-18 02:22:57 +01:00
|
|
|
|
|
|
|
vgmstream->samples_into_block = 0;
|
2008-03-04 07:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2018-04-12 22:51:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
static void block_update(VGMSTREAM * vgmstream) {
|
|
|
|
switch (vgmstream->layout_type) {
|
|
|
|
case layout_blocked_ast:
|
|
|
|
block_update_ast(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_mxch:
|
|
|
|
block_update_mxch(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_halpst:
|
|
|
|
if (vgmstream->next_block_offset>=0)
|
|
|
|
block_update_halpst(vgmstream->next_block_offset,vgmstream);
|
|
|
|
else
|
|
|
|
vgmstream->current_block_offset = -1;
|
|
|
|
break;
|
|
|
|
case layout_blocked_xa:
|
|
|
|
block_update_xa(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_ea_schl:
|
|
|
|
block_update_ea_schl(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_ea_1snh:
|
|
|
|
block_update_ea_1snh(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_caf:
|
|
|
|
block_update_caf(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_wsi:
|
|
|
|
block_update_wsi(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_str_snds:
|
|
|
|
block_update_str_snds(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_ws_aud:
|
|
|
|
block_update_ws_aud(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_matx:
|
|
|
|
block_update_matx(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_dec:
|
|
|
|
block_update_dec(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_emff_ps2:
|
|
|
|
block_update_emff_ps2(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_emff_ngc:
|
|
|
|
block_update_emff_ngc(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_gsb:
|
|
|
|
block_update_gsb(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_vs:
|
|
|
|
block_update_vs(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_xvas:
|
|
|
|
block_update_xvas(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_thp:
|
|
|
|
block_update_thp(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_filp:
|
|
|
|
block_update_filp(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_ivaud:
|
|
|
|
block_update_ivaud(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_ea_swvr:
|
|
|
|
block_update_ea_swvr(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_adm:
|
|
|
|
block_update_adm(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_bdsp:
|
|
|
|
block_update_bdsp(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_tra:
|
|
|
|
block_update_tra(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_ps2_iab:
|
|
|
|
block_update_ps2_iab(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_ps2_strlr:
|
|
|
|
block_update_ps2_strlr(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_rws:
|
|
|
|
block_update_rws(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_hwas:
|
|
|
|
block_update_hwas(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_ea_sns:
|
|
|
|
block_update_ea_sns(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_awc:
|
|
|
|
block_update_awc(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_vgs:
|
|
|
|
block_update_vgs(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_vawx:
|
|
|
|
block_update_vawx(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_xvag_subsong:
|
|
|
|
block_update_xvag_subsong(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_ea_wve_au00:
|
|
|
|
block_update_ea_wve_au00(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_ea_wve_ad10:
|
|
|
|
block_update_ea_wve_ad10(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_blocked_sthd:
|
|
|
|
block_update_sthd(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
2018-06-03 13:08:41 +02:00
|
|
|
case layout_blocked_h4m:
|
|
|
|
block_update_h4m(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
2018-07-22 23:13:03 +02:00
|
|
|
case layout_blocked_xa_aiff:
|
|
|
|
block_update_xa_aiff(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
2018-04-12 22:51:24 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|