Skip to content

Commit

Permalink
Codec: Change out parameter to return value
Browse files Browse the repository at this point in the history
  • Loading branch information
dscharrer committed Aug 17, 2021
1 parent a84a445 commit 67f8b9b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 19 deletions.
18 changes: 9 additions & 9 deletions src/audio/codec/ADPCM.cpp
Expand Up @@ -132,10 +132,10 @@ aalError CodecADPCM::setPosition(size_t position) {

while(i) {
char buffer[256];
size_t nRead;
size_t to_read = std::min(i, size_t(256));
if(aalError error = read(buffer, to_read, nRead)) {
return error;
size_t nRead = read(buffer, to_read);
if(!nRead) {
return AAL_ERROR_FORMAT;
}
i -= nRead;
}
Expand Down Expand Up @@ -178,10 +178,10 @@ void CodecADPCM::getSample(size_t channel, s8 adpcmSample) {
samp1[channel] = s16(pcm_sample);
}

aalError CodecADPCM::read(void * buffer, size_t to_read, size_t & read) {
size_t CodecADPCM::read(void * buffer, size_t bufferSize) {

read = 0;
while(read < to_read) {
size_t read = 0;
while(read < bufferSize) {

// If prefetched bytes are remaining, put the next one into the buffer
if(cache_i < cache_c) {
Expand All @@ -196,8 +196,8 @@ aalError CodecADPCM::read(void * buffer, size_t to_read, size_t & read) {
m_stream->seek(SeekCur, padding);
}

if(aalError error = getNextBlock()) {
return error;
if(getNextBlock() != AAL_OK) {
return 0;
}

} else if(sample_i == 1) {
Expand All @@ -224,7 +224,7 @@ aalError CodecADPCM::read(void * buffer, size_t to_read, size_t & read) {
cache_i = 0;
}

return AAL_OK;
return read;
}

aalError CodecADPCM::getNextBlock() {
Expand Down
2 changes: 1 addition & 1 deletion src/audio/codec/ADPCM.h
Expand Up @@ -67,7 +67,7 @@ class CodecADPCM final : public Codec {
void setStream(PakFileHandle * stream) override;
aalError setPosition(size_t position) override;

aalError read(void * buffer, size_t to_read, size_t & read) override;
size_t read(void * buffer, size_t bufferSize) override;

private:

Expand Down
2 changes: 1 addition & 1 deletion src/audio/codec/Codec.h
Expand Up @@ -64,7 +64,7 @@ class Codec {
//! The stream cursor must be at the beginning of waveform data
virtual aalError setPosition(size_t position) = 0;

virtual aalError read(void * buffer, size_t to_read, size_t & read) = 0;
virtual size_t read(void * buffer, size_t bufferSize) = 0;

};

Expand Down
5 changes: 2 additions & 3 deletions src/audio/codec/RAW.cpp
Expand Up @@ -68,9 +68,8 @@ aalError CodecRAW::setPosition(size_t position) {
return AAL_OK;
}

aalError CodecRAW::read(void * buffer, size_t bufferSize, size_t & read) {
read = m_stream->read(buffer, bufferSize);
return AAL_OK;
size_t CodecRAW::read(void * buffer, size_t bufferSize) {
return m_stream->read(buffer, bufferSize);
}

} // namespace audio
2 changes: 1 addition & 1 deletion src/audio/codec/RAW.h
Expand Up @@ -63,7 +63,7 @@ class CodecRAW final : public Codec {
void setStream(PakFileHandle * stream) override;
aalError setPosition(size_t position) override;

aalError read(void * buffer, size_t bufferSize, size_t & read) override;
size_t read(void * buffer, size_t bufferSize) override;

private:

Expand Down
5 changes: 1 addition & 4 deletions src/audio/codec/WAV.cpp
Expand Up @@ -295,10 +295,7 @@ size_t StreamWAV::read(void * buffer, size_t bufferSize) {

size_t count = cursor + bufferSize > outsize ? outsize - cursor : bufferSize;

size_t read = 0;
if(codec->read(buffer, count, read)) {
return 0;
}
size_t read = codec->read(buffer, count);

cursor += read;

Expand Down

0 comments on commit 67f8b9b

Please sign in to comment.