Skip to content

Unable to play short WAV files (tested 170ms@96kHz) #99

@eyuan-creare

Description

@eyuan-creare

Problem

First off, this is a very minor issue when playing a reallly short file. For example, at a default SD Read buffer of 131,072B, sample rate of 96kHz, 1-chan, 16-bit, the min audio duration would be 0.68s. Perhaps not worth addressing.

Unable to play the attached WAV file (0.17s long), unless I extend it to a longer duration (5.17s).
Sinc_Factor_16x_65-pts-02.wav

Setup

-Example script from preunification branch was modified to play the attached file:

  • AudioSDPlayer_F32::fillBufferFromSD() modified to report file position and error code during readFromSDtoBuffer()
  • Debug print statements turned on for AudioSDPlayer_F32 clas

Error

18:31:50.838 -> AudioSDPlayer_F32::open:fillBufferFromSD
18:31:50.838 -> File pos=44
18:31:50.838 -> Read size=4096
18:31:50.838 -> Error_code= 0
18:31:50.838 -> File pos=4140
18:31:50.838 -> Read size=4096
18:31:50.838 -> Error_code= 0
....
18:31:50.838 -> File pos=28716
18:31:50.838 -> Read size=4096
18:31:50.838 -> Error_code= 0
18:31:50.838 -> File pos=32812
18:31:50.838 -> Read size=4096
18:31:50.838 -> Error_code= -1

Cause

This while statement expects enough audio data to fill the entire buffer. When it runs out, check for file.available() fails and returns an error code.

while ((error_code == 0) && (space_to_fill_in_buffer > MIN_READ_SIZE_BYTES)) { //only continue of there is space

Proposed solution

Perhaps this is intended behavior, to return an error if the buffer is not completely full? However, is there any downside to gracefully handling the audio data running out first? Note that this fill method could end up loading metadata located after the audio data.

In open()...

if(fillBufferFromSD() < 0) {

  • Mark current position `fillStartPos = file.position();
  • IffillBufferFromSD() returns an error:
    • Calculate bytesLoaded = file.position()-fillStartPos
    • If error, check if all the audio bytes were loaded: `if (bytesLoaded file.position() == total_length). If so, then squash the error.

Note that besides open() there are several other functions that call fillBufferFromSD().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions