mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-12-02 18:17:18 +01:00
cleanup: fix leak + sbuf stuff
This commit is contained in:
parent
03d8cb5329
commit
98f795a7d2
@ -1,3 +1,4 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "../util.h"
|
#include "../util.h"
|
||||||
#include "sbuf.h"
|
#include "sbuf.h"
|
||||||
@ -74,3 +75,11 @@ void sbuf_copy_layers(sample_t* dst, int dst_channels, sample_t* src, int src_ch
|
|||||||
void sbuf_silence(sample_t* dst, int samples, int channels, int filled) {
|
void sbuf_silence(sample_t* dst, int samples, int channels, int filled) {
|
||||||
memset(dst + filled * channels, 0, (samples - filled) * channels * sizeof(sample_t));
|
memset(dst + filled * channels, 0, (samples - filled) * channels * sizeof(sample_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef _SBUF_H
|
#ifndef _SBUF_H_
|
||||||
#define _SBUF_H
|
#define _SBUF_H_
|
||||||
|
|
||||||
#include "../streamtypes.h"
|
#include "../streamtypes.h"
|
||||||
|
|
||||||
@ -27,6 +27,11 @@ typedef struct {
|
|||||||
} sbuf_t;
|
} sbuf_t;
|
||||||
|
|
||||||
void sbuf_init16(sbuf_t* sbuf, int16_t* buf, int samples, int channels);
|
void sbuf_init16(sbuf_t* sbuf, int16_t* buf, int samples, int channels);
|
||||||
|
|
||||||
|
void sbuf_clamp(sbuf_t* sbuf, int samples);
|
||||||
|
|
||||||
|
/* skips N samples from current sbuf */
|
||||||
|
void sbuf_consume(sbuf_t* sbuf, int samples);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* it's probably slightly faster to make those inline'd, but aren't called that often to matter (given big enough total samples) */
|
/* it's probably slightly faster to make those inline'd, but aren't called that often to matter (given big enough total samples) */
|
||||||
@ -42,5 +47,6 @@ void sbuf_copy_layers(sample_t* dst, int dst_channels, sample_t* src, int src_ch
|
|||||||
|
|
||||||
void sbuf_silence(sample_t* dst, int samples, int channels, int filled);
|
void sbuf_silence(sample_t* dst, int samples, int channels, int filled);
|
||||||
|
|
||||||
|
bool sbuf_realloc(sample_t** dst, int samples, int channels);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -179,9 +179,8 @@ bool setup_layout_layered(layered_layout_data* data) {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* create internal buffer big enough for mixing all layers */
|
/* create internal buffer big enough for mixing all layers */
|
||||||
sample_t* outbuf_re = realloc(data->buffer, VGMSTREAM_LAYER_SAMPLE_BUFFER * max_input_channels * sizeof(sample_t));
|
if (!sbuf_realloc(&data->buffer, VGMSTREAM_LAYER_SAMPLE_BUFFER, max_input_channels))
|
||||||
if (!outbuf_re) goto fail;
|
goto fail;
|
||||||
data->buffer = outbuf_re;
|
|
||||||
|
|
||||||
data->input_channels = max_input_channels;
|
data->input_channels = max_input_channels;
|
||||||
data->output_channels = max_output_channels;
|
data->output_channels = max_output_channels;
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
* (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_t* outbuf, int32_t sample_count, VGMSTREAM* vgmstream) {
|
void render_vgmstream_segmented(sample_t* outbuf, int32_t sample_count, VGMSTREAM* vgmstream) {
|
||||||
segmented_layout_data* data = vgmstream->layout_data;
|
segmented_layout_data* data = vgmstream->layout_data;
|
||||||
bool use_internal_buffer = 0;
|
bool use_internal_buffer = false;
|
||||||
|
|
||||||
/* normally uses outbuf directly (faster?) but could need internal buffer if downmixing */
|
/* normally uses outbuf directly (faster?) but could need internal buffer if downmixing */
|
||||||
if (vgmstream->channels != data->input_channels || data->mixed_channels) {
|
if (vgmstream->channels != data->input_channels || data->mixed_channels) {
|
||||||
@ -146,7 +146,6 @@ fail:
|
|||||||
|
|
||||||
bool setup_layout_segmented(segmented_layout_data* data) {
|
bool setup_layout_segmented(segmented_layout_data* data) {
|
||||||
int max_input_channels = 0, max_output_channels = 0, mixed_channels = 0;
|
int max_input_channels = 0, max_output_channels = 0, mixed_channels = 0;
|
||||||
sample_t* outbuf_re = NULL;
|
|
||||||
|
|
||||||
|
|
||||||
/* setup each VGMSTREAM (roughly equivalent to vgmstream.c's init_vgmstream_internal stuff) */
|
/* setup each VGMSTREAM (roughly equivalent to vgmstream.c's init_vgmstream_internal stuff) */
|
||||||
@ -211,12 +210,11 @@ bool setup_layout_segmented(segmented_layout_data* data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (max_output_channels > VGMSTREAM_MAX_CHANNELS || max_input_channels > VGMSTREAM_MAX_CHANNELS)
|
if (max_output_channels > VGMSTREAM_MAX_CHANNELS || max_input_channels > VGMSTREAM_MAX_CHANNELS)
|
||||||
goto fail;
|
return false;
|
||||||
|
|
||||||
/* create internal buffer big enough for mixing */
|
/* create internal buffer big enough for mixing */
|
||||||
outbuf_re = realloc(data->buffer, VGMSTREAM_SEGMENT_SAMPLE_BUFFER*max_input_channels*sizeof(sample_t));
|
if (!sbuf_realloc(&data->buffer, VGMSTREAM_SEGMENT_SAMPLE_BUFFER, max_input_channels))
|
||||||
if (!outbuf_re) goto fail;
|
goto fail;
|
||||||
data->buffer = outbuf_re;
|
|
||||||
|
|
||||||
data->input_channels = max_input_channels;
|
data->input_channels = max_input_channels;
|
||||||
data->output_channels = max_output_channels;
|
data->output_channels = max_output_channels;
|
||||||
@ -232,7 +230,7 @@ void free_layout_segmented(segmented_layout_data* data) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
for (int i = 0; i < data->segment_count; i++) {
|
for (int i = 0; i < data->segment_count; i++) {
|
||||||
bool is_repeat = true;
|
bool is_repeat = false;
|
||||||
|
|
||||||
/* segments are allowed to be repeated so don't close the same thing twice */
|
/* segments are allowed to be repeated so don't close the same thing twice */
|
||||||
for (int j = 0; j < i; j++) {
|
for (int j = 0; j < i; j++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user