2008-05-06 03:35:37 +00:00
|
|
|
#include "layout.h"
|
2008-03-04 07:15:25 +00:00
|
|
|
#include "../vgmstream.h"
|
|
|
|
|
|
|
|
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 */
|
|
|
|
if (samples_this_block <= 0) {
|
|
|
|
VGM_LOG("layout_blocked: empty/wrong block\n");
|
|
|
|
memset(buffer + samples_written*vgmstream->channels, 0, (sample_count - samples_written) * vgmstream->channels * sizeof(sample));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-03-04 07:15:25 +00:00
|
|
|
|
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) {
|
2008-03-04 07:15:25 +00:00
|
|
|
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 {
|
2017-11-18 02:22:57 +01:00
|
|
|
/* block end signal (used below): 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 */
|
2008-03-04 07:15:25 +00:00
|
|
|
switch (vgmstream->layout_type) {
|
|
|
|
case layout_ast_blocked:
|
|
|
|
ast_block_update(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
2017-11-18 02:22:57 +01:00
|
|
|
case layout_mxch_blocked:
|
2009-09-02 12:18:23 +00:00
|
|
|
mxch_block_update(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
2008-03-04 07:15:25 +00:00
|
|
|
case layout_halpst_blocked:
|
|
|
|
if (vgmstream->next_block_offset>=0)
|
|
|
|
halpst_block_update(vgmstream->next_block_offset,vgmstream);
|
|
|
|
else
|
2017-11-18 02:22:57 +01:00
|
|
|
vgmstream->current_block_offset = -1;
|
|
|
|
break;
|
|
|
|
case layout_xa_blocked:
|
|
|
|
xa_block_update(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
2017-11-25 01:18:27 +01:00
|
|
|
case layout_blocked_ea_schl:
|
|
|
|
block_update_ea_schl(vgmstream->next_block_offset,vgmstream);
|
2017-11-18 02:22:57 +01:00
|
|
|
break;
|
|
|
|
case layout_blocked_ea_1snh:
|
|
|
|
block_update_ea_1snh(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_caf_blocked:
|
|
|
|
caf_block_update(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
2008-06-29 01:30:13 +00:00
|
|
|
case layout_wsi_blocked:
|
|
|
|
wsi_block_update(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
2008-07-02 13:39:51 +00:00
|
|
|
case layout_str_snds_blocked:
|
|
|
|
str_snds_block_update(vgmstream->next_block_offset,vgmstream);
|
2008-07-02 03:57:21 +00:00
|
|
|
break;
|
2008-07-03 02:20:52 +00:00
|
|
|
case layout_ws_aud_blocked:
|
|
|
|
ws_aud_block_update(vgmstream->next_block_offset,vgmstream);
|
2008-08-10 20:08:03 +00:00
|
|
|
break;
|
|
|
|
case layout_matx_blocked:
|
|
|
|
matx_block_update(vgmstream->next_block_offset,vgmstream);
|
2008-08-11 07:19:44 +00:00
|
|
|
break;
|
2017-11-23 22:48:11 +01:00
|
|
|
case layout_blocked_dec:
|
|
|
|
block_update_dec(vgmstream->next_block_offset,vgmstream);
|
2008-12-04 20:11:45 +00:00
|
|
|
break;
|
2008-12-15 04:37:43 +00:00
|
|
|
case layout_emff_ps2_blocked:
|
|
|
|
emff_ps2_block_update(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_emff_ngc_blocked:
|
|
|
|
emff_ngc_block_update(vgmstream->next_block_offset,vgmstream);
|
2008-12-09 18:16:51 +00:00
|
|
|
break;
|
2008-12-16 15:48:21 +00:00
|
|
|
case layout_gsb_blocked:
|
|
|
|
gsb_block_update(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
2008-12-04 20:11:45 +00:00
|
|
|
case layout_vs_blocked:
|
|
|
|
vs_block_update(vgmstream->next_block_offset,vgmstream);
|
2008-07-03 02:20:52 +00:00
|
|
|
break;
|
2017-11-18 02:22:57 +01:00
|
|
|
case layout_xvas_blocked:
|
|
|
|
xvas_block_update(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_thp_blocked:
|
|
|
|
thp_block_update(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_filp_blocked:
|
|
|
|
filp_block_update(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
2017-11-25 01:18:27 +01:00
|
|
|
case layout_blocked_ivaud:
|
|
|
|
block_update_ivaud(vgmstream->next_block_offset,vgmstream);
|
2017-11-18 02:22:57 +01:00
|
|
|
break;
|
2018-02-17 21:15:21 +01:00
|
|
|
case layout_blocked_ea_swvr:
|
|
|
|
block_update_ea_swvr(vgmstream->next_block_offset,vgmstream);
|
2017-11-18 02:22:57 +01:00
|
|
|
break;
|
2018-02-25 16:52:57 +01:00
|
|
|
case layout_blocked_adm:
|
|
|
|
block_update_adm(vgmstream->next_block_offset,vgmstream);
|
2017-11-18 02:22:57 +01:00
|
|
|
break;
|
|
|
|
case layout_dsp_bdsp_blocked:
|
|
|
|
dsp_bdsp_block_update(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_tra_blocked:
|
|
|
|
tra_block_update(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
|
|
|
case layout_ps2_iab_blocked:
|
|
|
|
ps2_iab_block_update(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
2017-06-10 02:25:49 +02:00
|
|
|
case layout_ps2_strlr_blocked:
|
|
|
|
ps2_strlr_block_update(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
2018-02-25 16:52:57 +01:00
|
|
|
case layout_blocked_rws:
|
|
|
|
block_update_rws(vgmstream->next_block_offset,vgmstream);
|
2017-07-23 13:16:59 +02:00
|
|
|
break;
|
2018-02-25 16:52:57 +01:00
|
|
|
case layout_blocked_hwas:
|
|
|
|
block_update_hwas(vgmstream->next_block_offset,vgmstream);
|
2017-08-20 02:18:48 +02:00
|
|
|
break;
|
2017-11-25 01:18:27 +01:00
|
|
|
case layout_blocked_ea_sns:
|
|
|
|
block_update_ea_sns(vgmstream->next_block_offset,vgmstream);
|
2017-08-28 16:07:09 +02:00
|
|
|
break;
|
|
|
|
case layout_blocked_awc:
|
|
|
|
block_update_awc(vgmstream->next_block_offset,vgmstream);
|
2017-08-28 20:05:03 +02:00
|
|
|
break;
|
|
|
|
case layout_blocked_vgs:
|
|
|
|
block_update_vgs(vgmstream->next_block_offset,vgmstream);
|
2017-06-10 02:25:49 +02:00
|
|
|
break;
|
2017-12-09 19:01:36 +01:00
|
|
|
case layout_blocked_vawx:
|
|
|
|
block_update_vawx(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
2018-01-13 11:36:35 +01:00
|
|
|
case layout_blocked_xvag_subsong:
|
|
|
|
block_update_xvag_subsong(vgmstream->next_block_offset,vgmstream);
|
|
|
|
break;
|
2017-11-18 02:22:57 +01:00
|
|
|
default:
|
2008-03-04 07:15:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-07-03 21:21:01 +00:00
|
|
|
/* for VBR these may change */
|
2017-11-18 02:22:57 +01:00
|
|
|
frame_size = get_vgmstream_frame_size(vgmstream); /* for VBR these may change */
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|