Skip to content

Commit

Permalink
Stream: 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 e37929a commit a84a445
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/audio/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Stream {
virtual aalError getFormat(PCMFormat & format) = 0;
virtual size_t getLength() = 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
13 changes: 6 additions & 7 deletions src/audio/codec/WAV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,23 +287,22 @@ size_t StreamWAV::getLength() {
return outsize;
}

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

read = 0;
size_t StreamWAV::read(void * buffer, size_t bufferSize) {

if(cursor >= outsize) {
return AAL_OK;
return 0;
}

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

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

cursor += read;

return AAL_OK;
return read;
}

} // namespace audio
2 changes: 1 addition & 1 deletion src/audio/codec/WAV.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class StreamWAV final : public Stream {
aalError getFormat(PCMFormat & format) override;
size_t getLength() 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: 2 additions & 3 deletions src/audio/openal/OpenALSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ aalError OpenALSource::fillBuffer(size_t i, size_t size) {

arx_assert(size <= sizeof(data));

size_t read;
m_stream->read(data, left, read);
size_t read = m_stream->read(data, left);
if(read != left) {
return AAL_ERROR_SYSTEM;
}
Expand All @@ -324,7 +323,7 @@ aalError OpenALSource::fillBuffer(size_t i, size_t size) {
} else {
m_stream->setPosition(0);
if(size > left) {
m_stream->read(data + left, size - left, read);
read = m_stream->read(data + left, size - left);
if(read != size - left) {
return AAL_ERROR_SYSTEM;
}
Expand Down

0 comments on commit a84a445

Please sign in to comment.