mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-12 01:30:49 +01:00
Redundant stuff between interleave and nolayout moved into vgmstream. Other layouts should also be able to use this for common things.
git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@18 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
parent
d80919154b
commit
00c1a3abdb
@ -16,71 +16,14 @@ void render_vgmstream_interleave(sample * buffer, int32_t sample_count, VGMSTREA
|
||||
}
|
||||
|
||||
while (samples_written<sample_count) {
|
||||
int samples_to_do;
|
||||
int chan;
|
||||
int samples_left_this_block;
|
||||
|
||||
/*samples_this_block -= vgmstream->samples_into_block;*/
|
||||
samples_left_this_block = samples_this_block - vgmstream->samples_into_block;
|
||||
samples_to_do = samples_left_this_block;
|
||||
|
||||
/* fun loopy crap */
|
||||
/* Why did I think this would be any simpler? */
|
||||
if (vgmstream->loop_flag) {
|
||||
/* is this the loop end? */
|
||||
if (vgmstream->current_sample==vgmstream->loop_end_sample) {
|
||||
/* depending on the codec we may not want to copy all of the state */
|
||||
/*
|
||||
switch (vgmstream->coding_type) {
|
||||
case coding_CRI_ADX:
|
||||
case coding_NGC_DSP:
|
||||
{
|
||||
int i;
|
||||
for (i=0;i<vgmstream->channels;i++) {
|
||||
vgmstream->loop_ch[i].adpcm_history1_32 = vgmstream->ch[i].adpcm_history1_32;
|
||||
vgmstream->loop_ch[i].adpcm_history2_32 = vgmstream->ch[i].adpcm_history2_32;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
*/
|
||||
/* restore! */
|
||||
memcpy(vgmstream->ch,vgmstream->loop_ch,sizeof(VGMSTREAMCHANNEL)*vgmstream->channels);
|
||||
vgmstream->current_sample=vgmstream->loop_sample;
|
||||
vgmstream->samples_into_block=vgmstream->loop_samples_into_block;
|
||||
|
||||
samples_this_block = vgmstream->interleave_block_size / frame_size * samples_per_frame;
|
||||
continue; /* recalculate stuff */
|
||||
}
|
||||
|
||||
|
||||
/* is this the loop start? */
|
||||
if (!vgmstream->hit_loop && vgmstream->current_sample==vgmstream->loop_start_sample) {
|
||||
/* save! */
|
||||
memcpy(vgmstream->loop_ch,vgmstream->ch,sizeof(VGMSTREAMCHANNEL)*vgmstream->channels);
|
||||
|
||||
vgmstream->loop_sample=vgmstream->current_sample;
|
||||
vgmstream->loop_samples_into_block=vgmstream->samples_into_block;
|
||||
vgmstream->hit_loop=1;
|
||||
}
|
||||
|
||||
/* are we going to hit the loop end during this block? */
|
||||
if (vgmstream->current_sample+samples_left_this_block > vgmstream->loop_end_sample) {
|
||||
/* only do to just before it */
|
||||
samples_to_do = vgmstream->loop_end_sample-vgmstream->current_sample;
|
||||
}
|
||||
|
||||
/* are we going to hit the loop start during this block? */
|
||||
if (!vgmstream->hit_loop && vgmstream->current_sample+samples_left_this_block > vgmstream->loop_start_sample) {
|
||||
/* only do to just before it */
|
||||
samples_to_do = vgmstream->loop_start_sample-vgmstream->current_sample;
|
||||
}
|
||||
int samples_to_do;
|
||||
|
||||
if (vgmstream->loop_flag && vgmstream_do_loop(vgmstream)) {
|
||||
samples_this_block = vgmstream->interleave_block_size / frame_size * samples_per_frame;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (samples_per_frame>1 && (vgmstream->samples_into_block%samples_per_frame)+samples_to_do>samples_per_frame) samples_to_do=samples_per_frame-(vgmstream->samples_into_block%samples_per_frame);
|
||||
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;
|
||||
@ -92,6 +35,7 @@ void render_vgmstream_interleave(sample * buffer, int32_t sample_count, VGMSTREA
|
||||
vgmstream->samples_into_block+=samples_to_do;
|
||||
|
||||
if (vgmstream->samples_into_block==samples_this_block) {
|
||||
int chan;
|
||||
if (vgmstream->layout_type == layout_interleave_shortblock &&
|
||||
vgmstream->current_sample + samples_this_block > vgmstream->num_samples) {
|
||||
|
||||
|
@ -9,51 +9,12 @@ void render_vgmstream_nolayout(sample * buffer, int32_t sample_count, VGMSTREAM
|
||||
|
||||
while (samples_written<sample_count) {
|
||||
int samples_to_do;
|
||||
int chan;
|
||||
int samples_left_this_block;
|
||||
|
||||
samples_left_this_block = samples_this_block - vgmstream->samples_into_block;
|
||||
samples_to_do = samples_left_this_block;
|
||||
|
||||
/* fun loopy crap */
|
||||
/* Why did I think this would be any simpler? */
|
||||
if (vgmstream->loop_flag) {
|
||||
/* is this the loop end? */
|
||||
if (vgmstream->current_sample==vgmstream->loop_end_sample) {
|
||||
/* restore! */
|
||||
memcpy(vgmstream->ch,vgmstream->loop_ch,sizeof(VGMSTREAMCHANNEL)*vgmstream->channels);
|
||||
vgmstream->current_sample=vgmstream->loop_sample;
|
||||
vgmstream->samples_into_block=vgmstream->loop_samples_into_block;
|
||||
|
||||
continue; /* recalculate stuff */
|
||||
}
|
||||
|
||||
|
||||
/* is this the loop start? */
|
||||
if (!vgmstream->hit_loop && vgmstream->current_sample==vgmstream->loop_start_sample) {
|
||||
/* save! */
|
||||
memcpy(vgmstream->loop_ch,vgmstream->ch,sizeof(VGMSTREAMCHANNEL)*vgmstream->channels);
|
||||
|
||||
vgmstream->loop_sample=vgmstream->current_sample;
|
||||
vgmstream->loop_samples_into_block=vgmstream->samples_into_block;
|
||||
vgmstream->hit_loop=1;
|
||||
}
|
||||
|
||||
/* are we going to hit the loop end during this block? */
|
||||
if (vgmstream->current_sample+samples_left_this_block > vgmstream->loop_end_sample) {
|
||||
/* only do to just before it */
|
||||
samples_to_do = vgmstream->loop_end_sample-vgmstream->current_sample;
|
||||
}
|
||||
|
||||
/* are we going to hit the loop start during this block? */
|
||||
if (!vgmstream->hit_loop && vgmstream->current_sample+samples_left_this_block > vgmstream->loop_start_sample) {
|
||||
/* only do to just before it */
|
||||
samples_to_do = vgmstream->loop_start_sample-vgmstream->current_sample;
|
||||
}
|
||||
|
||||
if (vgmstream->loop_flag && vgmstream_do_loop(vgmstream)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (samples_per_frame > 1 && (vgmstream->samples_into_block%samples_per_frame)+samples_to_do>samples_per_frame) samples_to_do=samples_per_frame-(vgmstream->samples_into_block%samples_per_frame);
|
||||
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;
|
||||
|
@ -188,3 +188,60 @@ void decode_vgmstream(VGMSTREAM * vgmstream, int samples_written, int samples_to
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int vgmstream_samples_to_do(int samples_this_block, int samples_per_frame, VGMSTREAM * vgmstream) {
|
||||
int samples_to_do;
|
||||
int samples_left_this_block;
|
||||
|
||||
samples_left_this_block = samples_this_block - vgmstream->samples_into_block;
|
||||
samples_to_do = samples_left_this_block;
|
||||
|
||||
/* fun loopy crap */
|
||||
/* Why did I think this would be any simpler? */
|
||||
if (vgmstream->loop_flag) {
|
||||
/* are we going to hit the loop end during this block? */
|
||||
if (vgmstream->current_sample+samples_left_this_block > vgmstream->loop_end_sample) {
|
||||
/* only do to just before it */
|
||||
samples_to_do = vgmstream->loop_end_sample-vgmstream->current_sample;
|
||||
}
|
||||
|
||||
/* are we going to hit the loop start during this block? */
|
||||
if (!vgmstream->hit_loop && vgmstream->current_sample+samples_left_this_block > vgmstream->loop_start_sample) {
|
||||
/* only do to just before it */
|
||||
samples_to_do = vgmstream->loop_start_sample-vgmstream->current_sample;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* if it's a framed encoding don't do more than one frame */
|
||||
if (samples_per_frame>1 && (vgmstream->samples_into_block%samples_per_frame)+samples_to_do>samples_per_frame) samples_to_do=samples_per_frame-(vgmstream->samples_into_block%samples_per_frame);
|
||||
|
||||
return samples_to_do;
|
||||
}
|
||||
|
||||
/* return 1 if we just looped */
|
||||
int vgmstream_do_loop(VGMSTREAM * vgmstream) {
|
||||
/* if (vgmstream->loop_flag) {*/
|
||||
/* is this the loop end? */
|
||||
if (vgmstream->current_sample==vgmstream->loop_end_sample) {
|
||||
/* restore! */
|
||||
memcpy(vgmstream->ch,vgmstream->loop_ch,sizeof(VGMSTREAMCHANNEL)*vgmstream->channels);
|
||||
vgmstream->current_sample=vgmstream->loop_sample;
|
||||
vgmstream->samples_into_block=vgmstream->loop_samples_into_block;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* is this the loop start? */
|
||||
if (!vgmstream->hit_loop && vgmstream->current_sample==vgmstream->loop_start_sample) {
|
||||
/* save! */
|
||||
memcpy(vgmstream->loop_ch,vgmstream->ch,sizeof(VGMSTREAMCHANNEL)*vgmstream->channels);
|
||||
|
||||
vgmstream->loop_sample=vgmstream->current_sample;
|
||||
vgmstream->loop_samples_into_block=vgmstream->samples_into_block;
|
||||
vgmstream->hit_loop=1;
|
||||
}
|
||||
/*}*/
|
||||
return 0;
|
||||
}
|
||||
|
@ -139,14 +139,26 @@ VGMSTREAM * allocate_vgmstream(int channel_count, int looped);
|
||||
/* deallocate, close, etc. */
|
||||
void close_vgmstream(VGMSTREAM * vgmstream);
|
||||
|
||||
/* calculate the number of samples to be played based on looping parameters */
|
||||
int32_t get_vgmstream_play_samples(double looptimes, double fadetime, VGMSTREAM * vgmstream);
|
||||
|
||||
/* render! */
|
||||
void render_vgmstream(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstream);
|
||||
|
||||
/* smallest self-contained group of samples is a frame */
|
||||
int get_vgmstream_samples_per_frame(VGMSTREAM * vgmstream);
|
||||
/* number of bytes per frame */
|
||||
int get_vgmstream_frame_size(VGMSTREAM * vgmstream);
|
||||
|
||||
/* Assume that we have written samples_written into the buffer already, and we have samples_to_do consecutive
|
||||
* samples ahead of us. Decode those samples into the buffer. */
|
||||
void decode_vgmstream(VGMSTREAM * vgmstream, int samples_written, int samples_to_do, sample * buffer);
|
||||
|
||||
/* calculate number of consecutive samples to do (taking into account stopping for loop start and end) */
|
||||
int vgmstream_samples_to_do(int samples_this_block, int samples_per_frame, VGMSTREAM * vgmstream);
|
||||
|
||||
/* Detect start and save values, also detect end and restore values. Only works on exact sample values.
|
||||
* Returns 1 if loop was done. */
|
||||
int vgmstream_do_loop(VGMSTREAM * vgmstream);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user