Skip to content

Commit

Permalink
Fix decoding for m4a and ogg
Browse files Browse the repository at this point in the history
  • Loading branch information
Greedysky committed Jan 9, 2023
1 parent 4a66f99 commit dbe0129
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions spek-audio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ std::unique_ptr<AudioFile> Audio::open(const std::string& file_name, int stream)
AudioError error = AudioError::OK;

AVFormatContext *format_context = nullptr;
if (avformat_open_input(&format_context, file_name.c_str(), nullptr, nullptr) != 0) {
if (avformat_open_input(&format_context, file_name.c_str(), nullptr, nullptr) < 0) {
error = AudioError::CANNOT_OPEN_FILE;
}

Expand Down Expand Up @@ -284,8 +284,12 @@ int AudioFileImpl::read()
// No data yet, get more frames.
continue;
}
const int samples = m_frame->nb_samples;
// Occasionally the frame has no samples, move on to the next one.
if (samples == 0) {
continue;
}
// We have data, return it and come back for more later.
int samples = this->frame->nb_samples;
if (samples > this->buffer_len) {
this->buffer = static_cast<float*>(
av_realloc(this->buffer, samples * sizeof(float))
Expand Down

0 comments on commit dbe0129

Please sign in to comment.