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) {
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_ast:
|
|
|
|
block_update_ast(vgmstream->next_block_offset,vgmstream);
|
2008-03-04 07:15:25 +00:00
|
|
|
break;
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_mxch:
|
|
|
|
block_update_mxch(vgmstream->next_block_offset,vgmstream);
|
2009-09-02 12:18:23 +00:00
|
|
|
break;
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_halpst:
|
2008-03-04 07:15:25 +00:00
|
|
|
if (vgmstream->next_block_offset>=0)
|
2018-03-29 19:00:04 +02:00
|
|
|
block_update_halpst(vgmstream->next_block_offset,vgmstream);
|
2008-03-04 07:15:25 +00:00
|
|
|
else
|
2017-11-18 02:22:57 +01:00
|
|
|
vgmstream->current_block_offset = -1;
|
|
|
|
break;
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_xa:
|
|
|
|
block_update_xa(vgmstream->next_block_offset,vgmstream);
|
2017-11-18 02:22:57 +01:00
|
|
|
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;
|
2018-03-08 23:26:10 +01:00
|
|
|
case layout_blocked_caf:
|
|
|
|
block_update_caf(vgmstream->next_block_offset,vgmstream);
|
2017-11-18 02:22:57 +01:00
|
|
|
break;
|
2018-03-23 18:34:37 +01:00
|
|
|
case layout_blocked_wsi:
|
|
|
|
block_update_wsi(vgmstream->next_block_offset,vgmstream);
|
2008-06-29 01:30:13 +00:00
|
|
|
break;
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_str_snds:
|
|
|
|
block_update_str_snds(vgmstream->next_block_offset,vgmstream);
|
2008-07-02 03:57:21 +00:00
|
|
|
break;
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_ws_aud:
|
|
|
|
block_update_ws_aud(vgmstream->next_block_offset,vgmstream);
|
2008-08-10 20:08:03 +00:00
|
|
|
break;
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_matx:
|
|
|
|
block_update_matx(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;
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_emff_ps2:
|
|
|
|
block_update_emff_ps2(vgmstream->next_block_offset,vgmstream);
|
2008-12-15 04:37:43 +00:00
|
|
|
break;
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_emff_ngc:
|
|
|
|
block_update_emff_ngc(vgmstream->next_block_offset,vgmstream);
|
2008-12-09 18:16:51 +00:00
|
|
|
break;
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_gsb:
|
|
|
|
block_update_gsb(vgmstream->next_block_offset,vgmstream);
|
2008-12-16 15:48:21 +00:00
|
|
|
break;
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_vs:
|
|
|
|
block_update_vs(vgmstream->next_block_offset,vgmstream);
|
2008-07-03 02:20:52 +00:00
|
|
|
break;
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_xvas:
|
|
|
|
block_update_xvas(vgmstream->next_block_offset,vgmstream);
|
2017-11-18 02:22:57 +01:00
|
|
|
break;
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_thp:
|
|
|
|
block_update_thp(vgmstream->next_block_offset,vgmstream);
|
2017-11-18 02:22:57 +01:00
|
|
|
break;
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_filp:
|
|
|
|
block_update_filp(vgmstream->next_block_offset,vgmstream);
|
2017-11-18 02:22:57 +01:00
|
|
|
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;
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_bdsp:
|
|
|
|
block_update_bdsp(vgmstream->next_block_offset,vgmstream);
|
2017-11-18 02:22:57 +01:00
|
|
|
break;
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_tra:
|
|
|
|
block_update_tra(vgmstream->next_block_offset,vgmstream);
|
2017-11-18 02:22:57 +01:00
|
|
|
break;
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_ps2_iab:
|
|
|
|
block_update_ps2_iab(vgmstream->next_block_offset,vgmstream);
|
2017-11-18 02:22:57 +01:00
|
|
|
break;
|
2018-03-29 19:00:04 +02:00
|
|
|
case layout_blocked_ps2_strlr:
|
|
|
|
block_update_ps2_strlr(vgmstream->next_block_offset,vgmstream);
|
2017-06-10 02:25:49 +02:00
|
|
|
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;
|
2018-03-29 15:39:33 +02:00
|
|
|
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;
|
2018-03-29 17:01:46 +02:00
|
|
|
case layout_blocked_sthd:
|
|
|
|
block_update_sthd(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
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|