mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-01-17 23:36:41 +01:00
Fixed audio buffer overflow for tracks with channels > 2
git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@748 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
parent
179c16856a
commit
28c6dc5d5a
@ -1,6 +1,8 @@
|
||||
#ifndef _FOO_VGMSTREAM_
|
||||
#define _FOO_VGMSTREAM_
|
||||
|
||||
#define OUTBUF_SIZE 1024 /* Samples */
|
||||
|
||||
typedef struct _FOO_STREAMFILE {
|
||||
struct _STREAMFILE sf;
|
||||
abort_callback * p_abort;
|
||||
@ -61,7 +63,7 @@ class input_vgmstream {
|
||||
|
||||
t_filestats stats;
|
||||
|
||||
short sample_buffer[576*2*2]; /* 576 16-bit samples, stereo, possibly doubled in size for DSP */
|
||||
short sample_buffer[OUTBUF_SIZE];
|
||||
|
||||
void getfileinfo(char *filename, char *title, int *length_in_ms, int *sample_rate, int *channels, abort_callback & p_abort);
|
||||
|
||||
@ -72,11 +74,7 @@ class input_vgmstream {
|
||||
STREAMFILE * open_foo_streamfile_buffer_by_file(service_ptr_t<file> m_file,const char * const filename, size_t buffersize, abort_callback * p_abort);
|
||||
STREAMFILE * open_foo_streamfile_buffer(const char * const filename, size_t buffersize, abort_callback * p_abort, t_filestats * stats);
|
||||
STREAMFILE * open_foo_streamfile(const char * const filename, abort_callback * p_abort, t_filestats * stats);
|
||||
//size_t read_the_rest_foo(uint8_t * dest, off_t offset, size_t length, FOO_STREAMFILE * streamfile);
|
||||
//size_t read_foo(FOO_STREAMFILE *streamfile, uint8_t * dest, off_t offset, size_t length);
|
||||
//void close_foo(FOO_STREAMFILE * streamfile);
|
||||
//off_t get_offset_foo(FOO_STREAMFILE *streamFile);
|
||||
//size_t get_size_foo(FOO_STREAMFILE * streamfile);
|
||||
|
||||
|
||||
#define DECLARE_MULTIPLE_FILE_TYPE(NAME,EXTENSION) \
|
||||
namespace { static input_file_type_impl g_filetype_instance_##EXTENSION(NAME,"*." #EXTENSION ,true); \
|
||||
|
@ -33,8 +33,6 @@ extern "C" {
|
||||
#define PLUGIN_VERSION VERSION " " __DATE__
|
||||
#define INI_NAME "plugin.ini"
|
||||
|
||||
#define DECODE_SIZE 1024
|
||||
|
||||
|
||||
/* format detection and VGMSTREAM setup, uses default parameters */
|
||||
VGMSTREAM * input_vgmstream::init_vgmstream_foo(const char * const filename, abort_callback & p_abort) {
|
||||
@ -105,7 +103,7 @@ void input_vgmstream::get_info(file_info & p_info,abort_callback & p_abort ) {
|
||||
p_info.info_set_int("channels", channels);
|
||||
p_info.info_set_int("bitspersample",16);
|
||||
p_info.info_set("encoding","lossless");
|
||||
p_info.info_set_bitrate(16);
|
||||
p_info.info_set_bitrate(samplerate * 16 * channels);
|
||||
|
||||
p_info.set_length(((double)length_in_ms)/1000);
|
||||
}
|
||||
@ -122,15 +120,16 @@ bool input_vgmstream::decode_run(audio_chunk & p_chunk,abort_callback & p_abort)
|
||||
Sleep(10);
|
||||
decoding = true;
|
||||
|
||||
int l = 0, samples_to_do = DECODE_SIZE, t= 0;
|
||||
int max_buffer_samples = sizeof(sample_buffer)/sizeof(sample_buffer[0])/vgmstream->channels;
|
||||
int l = 0, samples_to_do = max_buffer_samples, t= 0;
|
||||
|
||||
if(vgmstream) {
|
||||
if (decode_pos_samples+DECODE_SIZE>stream_length_samples && (!loop_forever || !vgmstream->loop_flag))
|
||||
if (decode_pos_samples+max_buffer_samples>stream_length_samples && (!loop_forever || !vgmstream->loop_flag))
|
||||
samples_to_do=stream_length_samples-decode_pos_samples;
|
||||
else
|
||||
samples_to_do=DECODE_SIZE;
|
||||
samples_to_do=max_buffer_samples;
|
||||
|
||||
l = (samples_to_do*vgmstream->channels*2);
|
||||
l = (samples_to_do*vgmstream->channels * sizeof(sample_buffer[0]));
|
||||
|
||||
if (samples_to_do /*< DECODE_SIZE*/ == 0) {
|
||||
decoding = false;
|
||||
@ -164,7 +163,7 @@ bool input_vgmstream::decode_run(audio_chunk & p_chunk,abort_callback & p_abort)
|
||||
decode_pos_ms=decode_pos_samples*1000LL/vgmstream->sample_rate;
|
||||
|
||||
decoding = false;
|
||||
return samples_to_do==DECODE_SIZE;
|
||||
return samples_to_do==max_buffer_samples;
|
||||
|
||||
}
|
||||
decoding = false;
|
||||
@ -173,6 +172,7 @@ bool input_vgmstream::decode_run(audio_chunk & p_chunk,abort_callback & p_abort)
|
||||
|
||||
void input_vgmstream::decode_seek(double p_seconds,abort_callback & p_abort) {
|
||||
seek_pos_samples = ((int)(p_seconds * (double)vgmstream->sample_rate));
|
||||
int max_buffer_samples = sizeof(sample_buffer)/sizeof(sample_buffer[0])/vgmstream->channels;
|
||||
|
||||
// Reset of backwards seek
|
||||
if(seek_pos_samples < decode_pos_samples) {
|
||||
@ -184,9 +184,9 @@ void input_vgmstream::decode_seek(double p_seconds,abort_callback & p_abort) {
|
||||
// seeking overrun = bad
|
||||
if(seek_pos_samples > stream_length_samples) seek_pos_samples = stream_length_samples;
|
||||
|
||||
while(decode_pos_samples+DECODE_SIZE<seek_pos_samples) {
|
||||
int seek_samples = DECODE_SIZE;
|
||||
if((decode_pos_samples+DECODE_SIZE>=stream_length_samples) && (!loop_forever || !vgmstream->loop_flag))
|
||||
while(decode_pos_samples+max_buffer_samples<seek_pos_samples) {
|
||||
int seek_samples = max_buffer_samples;
|
||||
if((decode_pos_samples+max_buffer_samples>=stream_length_samples) && (!loop_forever || !vgmstream->loop_flag))
|
||||
seek_samples=stream_length_samples-seek_pos_samples;
|
||||
|
||||
decode_pos_samples+=seek_samples;
|
||||
@ -246,7 +246,7 @@ bool input_vgmstream::g_is_our_path(const char * p_path,const char * p_extension
|
||||
if(!stricmp_utf8(p_extension,"afc")) return 1;
|
||||
if(!stricmp_utf8(p_extension,"agsc")) return 1;
|
||||
if(!stricmp_utf8(p_extension,"ahx")) return 1;
|
||||
if(!stricmp_utf8(p_extension,"aifc")) return 1;
|
||||
if(!stricmp_utf8(p_extension,"aic")) return 1;
|
||||
if(!stricmp_utf8(p_extension,"aix")) return 1;
|
||||
if(!stricmp_utf8(p_extension,"amts")) return 1;
|
||||
if(!stricmp_utf8(p_extension,"as4")) return 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user