cleanup: misc

This commit is contained in:
bnnm 2024-08-27 17:27:52 +02:00
parent 1d86c2d03e
commit 1ef49e45ce
4 changed files with 14 additions and 20 deletions

View File

@ -79,7 +79,7 @@ size_t wav_make_header(uint8_t* buf, size_t buf_size, wav_header_t* wav) {
if (!wav->sample_size)
wav->sample_size = sizeof(short);
if (wav->sample_size <= 0 || wav->sample_size >= 4)
if (wav->sample_size <= 0x00 || wav->sample_size > 0x04)
return 0;
size_t data_size = wav->sample_count * wav->channels * wav->sample_size;

View File

@ -151,7 +151,7 @@ void sbuf_copy_from_f32(sbuf_t* sbuf, float* src) {
}
}
void sbuf_copy_samples(sample_t* dst, int dst_channels, sample_t* src, int src_channels, int samples_to_do, int samples_filled) {
void sbuf_copy_segments(sample_t* dst, int dst_channels, sample_t* src, int src_channels, int samples_to_do, int samples_filled) {
int pos = samples_filled * dst_channels;
if (src_channels == dst_channels) { /* most common and probably faster */
@ -186,6 +186,14 @@ void sbuf_copy_layers(sample_t* dst, int dst_channels, sample_t* src, int src_ch
}
}
bool sbuf_realloc(sample_t** dst, int samples, int channels) {
sample_t* outbuf_re = realloc(*dst, samples * channels * sizeof(sample_t));
if (!outbuf_re) return false;
*dst = outbuf_re;
return true;
}
void sbuf_silence_s16(sample_t* dst, int samples, int channels, int filled) {
memset(dst + filled * channels, 0, (samples - filled) * channels * sizeof(sample_t));
}
@ -202,14 +210,6 @@ void sbuf_silence_rest(sbuf_t* sbuf) {
sbuf_silence_part(sbuf, sbuf->filled, sbuf->samples - sbuf->filled);
}
bool sbuf_realloc(sample_t** dst, int samples, int channels) {
sample_t* outbuf_re = realloc(*dst, samples * channels * sizeof(sample_t));
if (!outbuf_re) return false;
*dst = outbuf_re;
return true;
}
void sbuf_fadeout(sbuf_t* sbuf, int start, int to_do, int fade_pos, int fade_duration) {
//TODO: use interpolated fadedness to improve performance?
//TODO: use float fadedness?

View File

@ -25,37 +25,31 @@ typedef struct {
int filled; /* samples in buffer */
} sbuf_t;
/* it's probably slightly faster to make some function inline'd, but aren't called that often to matter (given big enough total samples) */
void sbuf_init_s16(sbuf_t* sbuf, int16_t* buf, int samples, int channels);
void sbuf_init_f32(sbuf_t* sbuf, float* buf, int samples, int channels);
int sfmt_get_sample_size(sfmt_t fmt);
//void* sbuf_get_filled_buf(sbuf_t* sbuf);
//void sbuf_clamp(sbuf_t* sbuf, int samples);
/* move buf by samples amount to simplify some code (will lose base buf pointer) */
void sbuf_consume(sbuf_t* sbuf, int count);
/* it's probably slightly faster to make those inline'd, but aren't called that often to matter (given big enough total samples) */
// TODO decide if using float 1.0 style or 32767 style (fuzzy PCM changes when doing that)
void sbuf_copy_to_f32(float* dst, sbuf_t* sbuf);
void sbuf_copy_from_f32(sbuf_t* sbuf, float* src);
void sbuf_copy_samples(sample_t* dst, int dst_channels, sample_t* src, int src_channels, int samples_to_do, int samples_filled);
void sbuf_copy_segments(sample_t* dst, int dst_channels, sample_t* src, int src_channels, int samples_to_do, int samples_filled);
void sbuf_copy_layers(sample_t* dst, int dst_channels, sample_t* src, int src_channels, int samples_to_do, int samples_filled, int dst_ch_start);
bool sbuf_realloc(sample_t** dst, int samples, int channels);
void sbuf_silence_s16(sample_t* dst, int samples, int channels, int filled);
void sbuf_silence_rest(sbuf_t* sbuf);
void sbuf_silence_part(sbuf_t* sbuf, int from, int count);
bool sbuf_realloc(sample_t** dst, int samples, int channels);
void sbuf_fadeout(sbuf_t* sbuf, int start, int to_do, int fade_pos, int fade_duration);
#endif

View File

@ -77,7 +77,7 @@ void render_vgmstream_segmented(sample_t* outbuf, int32_t sample_count, VGMSTREA
render_vgmstream(buf, samples_to_do, data->segments[data->current_segment]);
if (use_internal_buffer) {
sbuf_copy_samples(outbuf, data->output_channels, data->buffer, current_channels, samples_to_do, samples_filled);
sbuf_copy_segments(outbuf, data->output_channels, data->buffer, current_channels, samples_to_do, samples_filled);
}
samples_filled += samples_to_do;