diff --git a/torchaudio/csrc/sox/effects_chain.cpp b/torchaudio/csrc/sox/effects_chain.cpp index 696dd1adc86..9edf772de38 100644 --- a/torchaudio/csrc/sox/effects_chain.cpp +++ b/torchaudio/csrc/sox/effects_chain.cpp @@ -336,7 +336,7 @@ int fileobj_input_drain(sox_effect_t* effp, sox_sample_t* obuf, size_t* osamp) { const auto num_consumed = sf->tell_off; const auto num_remain = priv->buffer_size - num_consumed; - // 1.1. First, we fetch the data to see if there is data to fill the buffer + // 1.1. Fetch the data to see if there is data to fill the buffer uint64_t num_refill = 0; std::string chunk; if (num_consumed && !priv->read_finished) { @@ -388,7 +388,8 @@ int fileobj_input_drain(sox_effect_t* effp, sox_sample_t* obuf, size_t* osamp) { // store the actual number read back to *osamp *osamp = sox_read(sf, obuf, *osamp); - return (!*osamp && priv->read_finished) ? SOX_EOF : SOX_SUCCESS; + // Decoding is finished when fileobject is exhausted and sox can no longer decode a sample. + return (priv->read_finished && !*osamp) ? SOX_EOF : SOX_SUCCESS; } int fileobj_output_flow(