From 6f8545e694ae334184dff5181e24ddce0dd41683 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 27 Jun 2014 21:51:05 -0700 Subject: [PATCH] Use a TArray for SoundDecoder::readAll --- src/sound/i_sound.cpp | 12 ++++++------ src/sound/i_soundinternal.h | 3 ++- src/sound/oalsound.cpp | 4 ++-- src/sound/sndfile_decoder.cpp | 10 +++++----- src/sound/sndfile_decoder.h | 2 +- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/sound/i_sound.cpp b/src/sound/i_sound.cpp index 9d45ebc68..97267d62c 100644 --- a/src/sound/i_sound.cpp +++ b/src/sound/i_sound.cpp @@ -574,18 +574,18 @@ SoundDecoder *SoundRenderer::CreateDecoder(FileReader *reader) // Default readAll implementation, for decoders that can't do anything better -std::vector SoundDecoder::readAll() +TArray SoundDecoder::readAll() { - std::vector output; + TArray output; size_t total = 0; size_t got; - output.resize(total+32768); - while((got=read(&output[total], output.size()-total)) > 0) + output.Resize(total+32768); + while((got=read(&output[total], output.Size()-total)) > 0) { total += got; - output.resize(total*2); + output.Resize(total*2); } - output.resize(total); + output.Resize(total); return output; } diff --git a/src/sound/i_soundinternal.h b/src/sound/i_soundinternal.h index 499fe80a6..218c6724b 100644 --- a/src/sound/i_soundinternal.h +++ b/src/sound/i_soundinternal.h @@ -6,6 +6,7 @@ #include "basictypes.h" #include "vectors.h" +#include "tarray.h" class FileReader; @@ -123,7 +124,7 @@ struct SoundDecoder virtual void getInfo(int *samplerate, ChannelConfig *chans, SampleType *type) = 0; virtual size_t read(char *buffer, size_t bytes) = 0; - virtual std::vector readAll(); + virtual TArray readAll(); virtual bool seek(size_t ms_offset) = 0; virtual size_t getSampleOffset() = 0; virtual size_t getSampleLength() { return 0; } diff --git a/src/sound/oalsound.cpp b/src/sound/oalsound.cpp index db4c459eb..0b0dd5f59 100644 --- a/src/sound/oalsound.cpp +++ b/src/sound/oalsound.cpp @@ -1024,11 +1024,11 @@ SoundHandle OpenALSoundRenderer::LoadSound(BYTE *sfxdata, int length) return retval; } - std::vector data = decoder->readAll(); + TArray data = decoder->readAll(); ALuint buffer = 0; alGenBuffers(1, &buffer); - alBufferData(buffer, format, &data[0], data.size(), srate); + alBufferData(buffer, format, &data[0], data.Size(), srate); ALenum err; if((err=getALError()) != AL_NO_ERROR) diff --git a/src/sound/sndfile_decoder.cpp b/src/sound/sndfile_decoder.cpp index 26f9fd91d..0cf6a5fa8 100644 --- a/src/sound/sndfile_decoder.cpp +++ b/src/sound/sndfile_decoder.cpp @@ -100,17 +100,17 @@ size_t SndFileDecoder::read(char *buffer, size_t bytes) return total * SndInfo.channels * 2; } -std::vector SndFileDecoder::readAll() +TArray SndFileDecoder::readAll() { if(SndInfo.frames <= 0) return SoundDecoder::readAll(); int framesize = 2 * SndInfo.channels; - std::vector output; + TArray output; - output.resize(SndInfo.frames * framesize); - size_t got = read(&output[0], output.size()); - output.resize(got); + output.Resize(SndInfo.frames * framesize); + size_t got = read(&output[0], output.Size()); + output.Resize(got); return output; } diff --git a/src/sound/sndfile_decoder.h b/src/sound/sndfile_decoder.h index 6c4dd3eda..f53f7e52a 100644 --- a/src/sound/sndfile_decoder.h +++ b/src/sound/sndfile_decoder.h @@ -12,7 +12,7 @@ struct SndFileDecoder : public SoundDecoder virtual void getInfo(int *samplerate, ChannelConfig *chans, SampleType *type); virtual size_t read(char *buffer, size_t bytes); - virtual std::vector readAll(); + virtual TArray readAll(); virtual bool seek(size_t ms_offset); virtual size_t getSampleOffset(); virtual size_t getSampleLength();