mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-24 21:11:39 +00:00
Use a TArray for SoundDecoder::readAll
This commit is contained in:
parent
a16f9d061c
commit
6f8545e694
5 changed files with 16 additions and 15 deletions
|
@ -574,18 +574,18 @@ SoundDecoder *SoundRenderer::CreateDecoder(FileReader *reader)
|
|||
|
||||
|
||||
// Default readAll implementation, for decoders that can't do anything better
|
||||
std::vector<char> SoundDecoder::readAll()
|
||||
TArray<char> SoundDecoder::readAll()
|
||||
{
|
||||
std::vector<char> output;
|
||||
TArray<char> 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;
|
||||
}
|
||||
|
|
|
@ -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<char> readAll();
|
||||
virtual TArray<char> readAll();
|
||||
virtual bool seek(size_t ms_offset) = 0;
|
||||
virtual size_t getSampleOffset() = 0;
|
||||
virtual size_t getSampleLength() { return 0; }
|
||||
|
|
|
@ -1024,11 +1024,11 @@ SoundHandle OpenALSoundRenderer::LoadSound(BYTE *sfxdata, int length)
|
|||
return retval;
|
||||
}
|
||||
|
||||
std::vector<char> data = decoder->readAll();
|
||||
TArray<char> 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)
|
||||
|
|
|
@ -100,17 +100,17 @@ size_t SndFileDecoder::read(char *buffer, size_t bytes)
|
|||
return total * SndInfo.channels * 2;
|
||||
}
|
||||
|
||||
std::vector<char> SndFileDecoder::readAll()
|
||||
TArray<char> SndFileDecoder::readAll()
|
||||
{
|
||||
if(SndInfo.frames <= 0)
|
||||
return SoundDecoder::readAll();
|
||||
|
||||
int framesize = 2 * SndInfo.channels;
|
||||
std::vector<char> output;
|
||||
TArray<char> 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;
|
||||
}
|
||||
|
|
|
@ -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<char> readAll();
|
||||
virtual TArray<char> readAll();
|
||||
virtual bool seek(size_t ms_offset);
|
||||
virtual size_t getSampleOffset();
|
||||
virtual size_t getSampleLength();
|
||||
|
|
Loading…
Reference in a new issue