From 1ef49e45ce26e4e69fd90e2976ce1e0e047c1f00 Mon Sep 17 00:00:00 2001 From: bnnm Date: Tue, 27 Aug 2024 17:27:52 +0200 Subject: [PATCH] cleanup: misc --- cli/wav_utils.c | 2 +- src/base/sbuf.c | 18 +++++++++--------- src/base/sbuf.h | 12 +++--------- src/layout/segmented.c | 2 +- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/cli/wav_utils.c b/cli/wav_utils.c index 42559458..2ab07384 100644 --- a/cli/wav_utils.c +++ b/cli/wav_utils.c @@ -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; diff --git a/src/base/sbuf.c b/src/base/sbuf.c index d575a9c0..81549120 100644 --- a/src/base/sbuf.c +++ b/src/base/sbuf.c @@ -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? diff --git a/src/base/sbuf.h b/src/base/sbuf.h index c9ac7fb0..cede7bcd 100644 --- a/src/base/sbuf.h +++ b/src/base/sbuf.h @@ -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 diff --git a/src/layout/segmented.c b/src/layout/segmented.c index af1518c2..c7df74aa 100644 --- a/src/layout/segmented.c +++ b/src/layout/segmented.c @@ -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;