Change some sample to sample_t

This commit is contained in:
bnnm 2019-02-23 02:54:23 +01:00
parent 5bdc575f29
commit 111c4dd97c
10 changed files with 43 additions and 43 deletions

View File

@ -313,7 +313,7 @@ static void apply_config(VGMSTREAM * vgmstream, cli_config *cfg) {
} }
} }
void apply_fade(sample * buf, VGMSTREAM * vgmstream, int to_get, int i, int len_samples, int fade_samples, int channels) { void apply_fade(sample_t * buf, VGMSTREAM * vgmstream, int to_get, int i, int len_samples, int fade_samples, int channels) {
int is_fade_on = vgmstream->loop_flag; int is_fade_on = vgmstream->loop_flag;
if (is_fade_on && fade_samples > 0) { if (is_fade_on && fade_samples > 0) {
@ -324,7 +324,7 @@ void apply_fade(sample * buf, VGMSTREAM * vgmstream, int to_get, int i, int len_
if (samples_into_fade > 0) { if (samples_into_fade > 0) {
double fadedness = (double)(fade_samples - samples_into_fade) / fade_samples; double fadedness = (double)(fade_samples - samples_into_fade) / fade_samples;
for (k = 0; k < channels; k++) { for (k = 0; k < channels; k++) {
buf[j*channels + k] = (sample)buf[j*channels + k] * fadedness; buf[j*channels + k] = (sample_t)buf[j*channels + k] * fadedness;
} }
} }
} }
@ -339,7 +339,7 @@ int main(int argc, char ** argv) {
FILE * outfile = NULL; FILE * outfile = NULL;
char outfilename_temp[PATH_LIMIT]; char outfilename_temp[PATH_LIMIT];
sample * buf = NULL; sample_t * buf = NULL;
int channels; int channels;
int32_t len_samples; int32_t len_samples;
int32_t fade_samples; int32_t fade_samples;
@ -459,7 +459,7 @@ int main(int argc, char ** argv) {
/* last init */ /* last init */
channels = vgmstream->channels; channels = vgmstream->channels;
buf = malloc(BUFFER_SAMPLES * sizeof(sample) * channels); buf = malloc(BUFFER_SAMPLES * sizeof(sample_t) * channels);
if (!buf) { if (!buf) {
fprintf(stderr,"failed allocating output buffer\n"); fprintf(stderr,"failed allocating output buffer\n");
goto fail; goto fail;
@ -488,10 +488,10 @@ int main(int argc, char ** argv) {
swap_samples_le(buf, channels * to_get); /* write PC endian */ swap_samples_le(buf, channels * to_get); /* write PC endian */
if (cfg.only_stereo != -1) { if (cfg.only_stereo != -1) {
for (j = 0; j < to_get; j++) { for (j = 0; j < to_get; j++) {
fwrite(buf + j*channels + (cfg.only_stereo*2), sizeof(sample), 2, outfile); fwrite(buf + j*channels + (cfg.only_stereo*2), sizeof(sample_t), 2, outfile);
} }
} else { } else {
fwrite(buf, sizeof(sample) * channels, to_get, outfile); fwrite(buf, sizeof(sample_t) * channels, to_get, outfile);
} }
} }
@ -509,10 +509,10 @@ int main(int argc, char ** argv) {
swap_samples_le(buf, channels * to_get); /* write PC endian */ swap_samples_le(buf, channels * to_get); /* write PC endian */
if (cfg.only_stereo != -1) { if (cfg.only_stereo != -1) {
for (j = 0; j < to_get; j++) { for (j = 0; j < to_get; j++) {
fwrite(buf + j*channels + (cfg.only_stereo*2), sizeof(sample), 2, outfile); fwrite(buf + j*channels + (cfg.only_stereo*2), sizeof(sample_t), 2, outfile);
} }
} else { } else {
fwrite(buf, sizeof(sample) * channels, to_get, outfile); fwrite(buf, sizeof(sample_t) * channels, to_get, outfile);
} }
} }
@ -522,13 +522,13 @@ int main(int argc, char ** argv) {
/* try again with (for testing reset_vgmstream, simulates a seek to 0) */ /* try again with (for testing reset_vgmstream, simulates a seek to 0) */
if (cfg.test_reset) { if (cfg.test_reset) {
char outfilename_temp[PATH_LIMIT]; char outfilename_reset[PATH_LIMIT];
strcpy(outfilename_temp, cfg.outfilename); strcpy(outfilename_reset, cfg.outfilename);
strcat(outfilename_temp, ".reset.wav"); strcat(outfilename_reset, ".reset.wav");
outfile = fopen(outfilename_temp,"wb"); outfile = fopen(outfilename_reset,"wb");
if (!outfile) { if (!outfile) {
fprintf(stderr,"failed to open %s for output\n",outfilename_temp); fprintf(stderr,"failed to open %s for output\n",outfilename_reset);
goto fail; goto fail;
} }
@ -564,10 +564,10 @@ int main(int argc, char ** argv) {
swap_samples_le(buf, channels * to_get); /* write PC endian */ swap_samples_le(buf, channels * to_get); /* write PC endian */
if (cfg.only_stereo != -1) { if (cfg.only_stereo != -1) {
for (j = 0; j < to_get; j++) { for (j = 0; j < to_get; j++) {
fwrite(buf + j*channels + (cfg.only_stereo*2), sizeof(sample), 2, outfile); fwrite(buf + j*channels + (cfg.only_stereo*2), sizeof(sample_t), 2, outfile);
} }
} else { } else {
fwrite(buf, sizeof(sample) * channels, to_get, outfile); fwrite(buf, sizeof(sample_t) * channels, to_get, outfile);
} }
} }
fclose(outfile); fclose(outfile);
@ -615,7 +615,7 @@ static void make_smpl_chunk(uint8_t * buf, int32_t loop_start, int32_t loop_end)
static size_t make_wav_header(uint8_t * buf, size_t buf_size, int32_t sample_count, int32_t sample_rate, int channels, int smpl_chunk, int32_t loop_start, int32_t loop_end) { static size_t make_wav_header(uint8_t * buf, size_t buf_size, int32_t sample_count, int32_t sample_rate, int channels, int smpl_chunk, int32_t loop_start, int32_t loop_end) {
size_t data_size, header_size; size_t data_size, header_size;
data_size = sample_count*channels*sizeof(sample); data_size = sample_count * channels * sizeof(sample_t);
header_size = 0x2c; header_size = 0x2c;
if (smpl_chunk && loop_end) if (smpl_chunk && loop_end)
header_size += 0x3c+ 0x08; header_size += 0x3c+ 0x08;
@ -633,9 +633,9 @@ static size_t make_wav_header(uint8_t * buf, size_t buf_size, int32_t sample_cou
put_16bitLE(buf+0x14, 1); /* compression code 1=PCM */ put_16bitLE(buf+0x14, 1); /* compression code 1=PCM */
put_16bitLE(buf+0x16, channels); /* channel count */ put_16bitLE(buf+0x16, channels); /* channel count */
put_32bitLE(buf+0x18, sample_rate); /* sample rate */ put_32bitLE(buf+0x18, sample_rate); /* sample rate */
put_32bitLE(buf+0x1c, sample_rate*channels*sizeof(sample)); /* bytes per second */ put_32bitLE(buf+0x1c, sample_rate*channels*sizeof(sample_t)); /* bytes per second */
put_16bitLE(buf+0x20, (int16_t)(channels*sizeof(sample))); /* block align */ put_16bitLE(buf+0x20, (int16_t)(channels*sizeof(sample_t))); /* block align */
put_16bitLE(buf+0x22, sizeof(sample)*8); /* significant bits per sample */ put_16bitLE(buf+0x22, sizeof(sample_t)*8); /* significant bits per sample */
if (smpl_chunk && loop_end) { if (smpl_chunk && loop_end) {
make_smpl_chunk(buf+0x24, loop_start, loop_end); make_smpl_chunk(buf+0x24, loop_start, loop_end);

View File

@ -2,7 +2,7 @@
#include "../vgmstream.h" #include "../vgmstream.h"
#include "../coding/coding.h" #include "../coding/coding.h"
void render_vgmstream_aix(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstream) { void render_vgmstream_aix(sample_t * buffer, int32_t sample_count, VGMSTREAM * vgmstream) {
int samples_written=0; int samples_written=0;
aix_codec_data *data = vgmstream->codec_data; aix_codec_data *data = vgmstream->codec_data;

View File

@ -5,7 +5,7 @@
/* Decodes samples for blocked streams. /* Decodes samples for blocked streams.
* Data is divided into headered blocks with a bunch of data. The layout calls external helper functions * Data is divided into headered blocks with a bunch of data. The layout calls external helper functions
* when a block is decoded, and those must parse the new block and move offsets accordingly. */ * when a block is decoded, and those must parse the new block and move offsets accordingly. */
void render_vgmstream_blocked(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstream) { void render_vgmstream_blocked(sample_t * buffer, int32_t sample_count, VGMSTREAM * vgmstream) {
int samples_written = 0; int samples_written = 0;
int frame_size, samples_per_frame, samples_this_block; int frame_size, samples_per_frame, samples_this_block;
@ -41,14 +41,14 @@ void render_vgmstream_blocked(sample * buffer, int32_t sample_count, VGMSTREAM *
if (samples_this_block < 0) { if (samples_this_block < 0) {
/* probably block bug or EOF, next calcs would give wrong values/segfaults/infinite loop */ /* probably block bug or EOF, next calcs would give wrong values/segfaults/infinite loop */
VGM_LOG("layout_blocked: wrong block samples at 0x%x\n", (uint32_t)vgmstream->current_block_offset); VGM_LOG("layout_blocked: wrong block samples at 0x%x\n", (uint32_t)vgmstream->current_block_offset);
memset(buffer + samples_written*vgmstream->channels, 0, (sample_count - samples_written) * vgmstream->channels * sizeof(sample)); memset(buffer + samples_written*vgmstream->channels, 0, (sample_count - samples_written) * vgmstream->channels * sizeof(sample_t));
break; break;
} }
if (vgmstream->current_block_offset < 0 || vgmstream->current_block_offset == 0xFFFFFFFF) { if (vgmstream->current_block_offset < 0 || vgmstream->current_block_offset == 0xFFFFFFFF) {
/* probably block bug or EOF, block functions won't be able to read anything useful/infinite loop */ /* probably block bug or EOF, block functions won't be able to read anything useful/infinite loop */
VGM_LOG("layout_blocked: wrong block offset found\n"); VGM_LOG("layout_blocked: wrong block offset found\n");
memset(buffer + samples_written*vgmstream->channels, 0, (sample_count - samples_written) * vgmstream->channels * sizeof(sample)); memset(buffer + samples_written*vgmstream->channels, 0, (sample_count - samples_written) * vgmstream->channels * sizeof(sample_t));
break; break;
} }

View File

@ -4,7 +4,7 @@
/* Decodes samples for flat streams. /* Decodes samples for flat streams.
* Data forms a single stream, and the decoder may internally skip chunks and move offsets as needed. */ * Data forms a single stream, and the decoder may internally skip chunks and move offsets as needed. */
void render_vgmstream_flat(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstream) { void render_vgmstream_flat(sample_t * buffer, int32_t sample_count, VGMSTREAM * vgmstream) {
int samples_written = 0; int samples_written = 0;
int samples_per_frame, samples_this_block; int samples_per_frame, samples_this_block;
@ -26,7 +26,7 @@ void render_vgmstream_flat(sample * buffer, int32_t sample_count, VGMSTREAM * vg
if (samples_to_do == 0) { if (samples_to_do == 0) {
VGM_LOG("layout_flat: wrong samples_to_do found\n"); VGM_LOG("layout_flat: wrong samples_to_do found\n");
memset(buffer + samples_written*vgmstream->channels, 0, (sample_count - samples_written) * vgmstream->channels * sizeof(sample)); memset(buffer + samples_written*vgmstream->channels, 0, (sample_count - samples_written) * vgmstream->channels * sizeof(sample_t));
break; break;
} }

View File

@ -6,7 +6,7 @@
* Data has interleaved chunks per channel, and once one is decoded the layout moves offsets, * Data has interleaved chunks per channel, and once one is decoded the layout moves offsets,
* skipping other chunks (essentially a simplified variety of blocked layout). * skipping other chunks (essentially a simplified variety of blocked layout).
* Incompatible with decoders that move offsets. */ * Incompatible with decoders that move offsets. */
void render_vgmstream_interleave(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstream) { void render_vgmstream_interleave(sample_t * buffer, int32_t sample_count, VGMSTREAM * vgmstream) {
int samples_written = 0; int samples_written = 0;
int frame_size, samples_per_frame, samples_this_block; int frame_size, samples_per_frame, samples_this_block;
int has_interleave_last = vgmstream->interleave_last_block_size && vgmstream->channels > 1; int has_interleave_last = vgmstream->interleave_last_block_size && vgmstream->channels > 1;
@ -49,7 +49,7 @@ void render_vgmstream_interleave(sample * buffer, int32_t sample_count, VGMSTREA
if (samples_to_do == 0) { /* happens when interleave is not set */ if (samples_to_do == 0) { /* happens when interleave is not set */
VGM_LOG("layout_interleave: wrong samples_to_do found\n"); VGM_LOG("layout_interleave: wrong samples_to_do found\n");
memset(buffer + samples_written*vgmstream->channels, 0, (sample_count - samples_written) * vgmstream->channels * sizeof(sample)); memset(buffer + samples_written*vgmstream->channels, 0, (sample_count - samples_written) * vgmstream->channels * sizeof(sample_t));
break; break;
} }

View File

@ -10,10 +10,10 @@
* Similar to interleave layout, but decodec samples are mixed from complete vgmstreams, each * Similar to interleave layout, but decodec samples are mixed from complete vgmstreams, each
* with custom codecs and different number of channels, creating a single super-vgmstream. * with custom codecs and different number of channels, creating a single super-vgmstream.
* Usually combined with custom streamfiles to handle data interleaved in weird ways. */ * Usually combined with custom streamfiles to handle data interleaved in weird ways. */
void render_vgmstream_layered(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstream) { void render_vgmstream_layered(sample_t * buffer, int32_t sample_count, VGMSTREAM * vgmstream) {
int samples_written = 0; int samples_written = 0;
layered_layout_data *data = vgmstream->layout_data; layered_layout_data *data = vgmstream->layout_data;
sample interleave_buf[LAYER_BUF_SIZE*LAYER_MAX_CHANNELS]; sample_t interleave_buf[LAYER_BUF_SIZE*LAYER_MAX_CHANNELS];
while (samples_written < sample_count) { while (samples_written < sample_count) {

View File

@ -5,7 +5,7 @@
#include "../vgmstream.h" #include "../vgmstream.h"
/* blocked layouts */ /* blocked layouts */
void render_vgmstream_blocked(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstream); void render_vgmstream_blocked(sample_t * buffer, int32_t sample_count, VGMSTREAM * vgmstream);
void block_update(off_t block_offset, VGMSTREAM * vgmstream); void block_update(off_t block_offset, VGMSTREAM * vgmstream);
void block_update_ast(off_t block_ofset, VGMSTREAM * vgmstream); void block_update_ast(off_t block_ofset, VGMSTREAM * vgmstream);
@ -48,19 +48,19 @@ void block_update_xa_aiff(off_t block_offset, VGMSTREAM * vgmstream);
void block_update_vs_square(off_t block_offset, VGMSTREAM * vgmstream); void block_update_vs_square(off_t block_offset, VGMSTREAM * vgmstream);
/* other layouts */ /* other layouts */
void render_vgmstream_interleave(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstream); void render_vgmstream_interleave(sample_t * buffer, int32_t sample_count, VGMSTREAM * vgmstream);
void render_vgmstream_flat(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstream); void render_vgmstream_flat(sample_t * buffer, int32_t sample_count, VGMSTREAM * vgmstream);
void render_vgmstream_aix(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstream); void render_vgmstream_aix(sample_t * buffer, int32_t sample_count, VGMSTREAM * vgmstream);
void render_vgmstream_segmented(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstream); void render_vgmstream_segmented(sample_t * buffer, int32_t sample_count, VGMSTREAM * vgmstream);
segmented_layout_data* init_layout_segmented(int segment_count); segmented_layout_data* init_layout_segmented(int segment_count);
int setup_layout_segmented(segmented_layout_data* data); int setup_layout_segmented(segmented_layout_data* data);
void free_layout_segmented(segmented_layout_data *data); void free_layout_segmented(segmented_layout_data *data);
void reset_layout_segmented(segmented_layout_data *data); void reset_layout_segmented(segmented_layout_data *data);
void render_vgmstream_layered(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstream); void render_vgmstream_layered(sample_t * buffer, int32_t sample_count, VGMSTREAM * vgmstream);
layered_layout_data* init_layout_layered(int layer_count); layered_layout_data* init_layout_layered(int layer_count);
int setup_layout_layered(layered_layout_data* data); int setup_layout_layered(layered_layout_data* data);
void free_layout_layered(layered_layout_data *data); void free_layout_layered(layered_layout_data *data);

View File

@ -5,7 +5,7 @@
/* Decodes samples for segmented streams. /* Decodes samples for segmented streams.
* Chains together sequential vgmstreams, for data divided into separate sections or files * Chains together sequential vgmstreams, for data divided into separate sections or files
* (like one part for intro and other for loop segments, which may even use different codecs). */ * (like one part for intro and other for loop segments, which may even use different codecs). */
void render_vgmstream_segmented(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstream) { void render_vgmstream_segmented(sample_t * buffer, int32_t sample_count, VGMSTREAM * vgmstream) {
int samples_written = 0, loop_samples_skip = 0; int samples_written = 0, loop_samples_skip = 0;
segmented_layout_data *data = vgmstream->layout_data; segmented_layout_data *data = vgmstream->layout_data;

View File

@ -1080,7 +1080,7 @@ void render_vgmstream(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstre
/* swap channels if set, to create custom channel mappings */ /* swap channels if set, to create custom channel mappings */
if (vgmstream->channel_mappings_on) { if (vgmstream->channel_mappings_on) {
int ch_from,ch_to,s; int ch_from,ch_to,s;
sample temp; sample_t temp;
for (s = 0; s < sample_count; s++) { for (s = 0; s < sample_count; s++) {
for (ch_from = 0; ch_from < vgmstream->channels; ch_from++) { for (ch_from = 0; ch_from < vgmstream->channels; ch_from++) {
if (ch_from > 32) if (ch_from > 32)
@ -1492,7 +1492,7 @@ int get_vgmstream_shortframe_size(VGMSTREAM * vgmstream) {
/* Decode samples into the buffer. Assume that we have written samples_written into the /* Decode samples into the buffer. Assume that we have written samples_written into the
* buffer already, and we have samples_to_do consecutive samples ahead of us. */ * buffer already, and we have samples_to_do consecutive samples ahead of us. */
void decode_vgmstream(VGMSTREAM * vgmstream, int samples_written, int samples_to_do, sample * buffer) { void decode_vgmstream(VGMSTREAM * vgmstream, int samples_written, int samples_to_do, sample_t * buffer) {
int ch; int ch;
switch (vgmstream->coding_type) { switch (vgmstream->coding_type) {

View File

@ -1066,21 +1066,21 @@ typedef struct {
#ifdef VGM_USE_G7221 #ifdef VGM_USE_G7221
typedef struct { typedef struct {
sample buffer[640]; sample_t buffer[640];
g7221_handle *handle; g7221_handle *handle;
} g7221_codec_data; } g7221_codec_data;
#endif #endif
#ifdef VGM_USE_G719 #ifdef VGM_USE_G719
typedef struct { typedef struct {
sample buffer[960]; sample_t buffer[960];
void *handle; void *handle;
} g719_codec_data; } g719_codec_data;
#endif #endif
#ifdef VGM_USE_MAIATRAC3PLUS #ifdef VGM_USE_MAIATRAC3PLUS
typedef struct { typedef struct {
sample *buffer; sample_t *buffer;
int channels; int channels;
int samples_discard; int samples_discard;
void *handle; void *handle;
@ -1112,7 +1112,7 @@ typedef struct {
#define AIX_BUFFER_SIZE 0x1000 #define AIX_BUFFER_SIZE 0x1000
/* AIXery */ /* AIXery */
typedef struct { typedef struct {
sample buffer[AIX_BUFFER_SIZE]; sample_t buffer[AIX_BUFFER_SIZE];
int segment_count; int segment_count;
int stream_count; int stream_count;
int current_segment; int current_segment;
@ -1340,7 +1340,7 @@ int get_vgmstream_shortframe_size(VGMSTREAM * vgmstream);
/* Decode samples into the buffer. Assume that we have written samples_written into the /* Decode samples into the buffer. Assume that we have written samples_written into the
* buffer already, and we have samples_to_do consecutive samples ahead of us. */ * buffer already, and we have samples_to_do consecutive samples ahead of us. */
void decode_vgmstream(VGMSTREAM * vgmstream, int samples_written, int samples_to_do, sample * buffer); void decode_vgmstream(VGMSTREAM * vgmstream, int samples_written, int samples_to_do, sample_t * buffer);
/* Calculate number of consecutive samples to do (taking into account stopping for loop start and end) */ /* 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); int vgmstream_samples_to_do(int samples_this_block, int samples_per_frame, VGMSTREAM * vgmstream);