Skip to content

Class daisy::WavPlayer

template <size_t workspace_bytes>

ClassList > daisy > WavPlayer

More...

  • #include <WavPlayer.h>

Classes

Type Name
struct FileInfo

Public Types

Type Name
enum Result

Public Functions

Type Name
Result Close ()
size_t GetChannels () const
size_t GetDurationInSamples () const
bool GetLooping () const
float GetNormalizedPosition () const
bool GetPlaying () const
uint32_t GetPosition () const
Result Init (const char * name)
Result Open (const char * name)
Result Prepare ()
void Restart ()
void SetLooping (bool state)
void SetPlaybackSpeedRatio (const float speed)
void SetPlaybackSpeedSemitones (const float semitones)
void SetPlaying (bool state)
Result Stream (float * samples, size_t num_channels)
WavPlayer ()
~WavPlayer ()

Detailed Description

WAV file Streaming Playback

At this time, this class only supports streaming of 16-bit WAV Files The output of this class will be in float converted from 16-bit integers and linearly interpolated for non-integer playback speeds.

Due to the implementation, reverse playback is not possible with this class.

The workspace_bytes template parameter is used to set the size in bytes of audio samples within the FIFO.

The bulk of amount of memory used by this class is approximately: (2 * workspace_bytes); This could hypothetically be reduced by half by directly accessing the FIFO's inner array (requires modifications to FIFO class), or making a new type of queue data structure

Whenever the Stream function results in a the samples FIFO being less than 75% full, it will generate a request for new data. So the average disk i/o transaction will be the workspace_bytes / 4. However, There are times, like when restarting playback, or opening a different file, that will trigger the entire buffer to be filled.

Public Types Documentation

enum Result

enum daisy::WavPlayer::Result {
    Ok,
    FileNotFoundError,
    PlaybackUnderrun,
    PrepareOverrun,
    NewSamplesRequested,
    DiskError
};

Return values for status, and errors.


Public Functions Documentation

function Close

inline Result daisy::WavPlayer::Close () 

Close a file, and clear the data


function GetChannels

inline size_t daisy::WavPlayer::GetChannels () const

Return the number of audio channels in the open audio file


function GetDurationInSamples

inline size_t daisy::WavPlayer::GetDurationInSamples () const

Return the number of samples in the open audio file


function GetLooping

inline bool daisy::WavPlayer::GetLooping () const

Return whether the player is looping or not.


function GetNormalizedPosition

inline float daisy::WavPlayer::GetNormalizedPosition () const

Returns a 0-1 representation of the playhead position within the file.


function GetPlaying

inline bool daisy::WavPlayer::GetPlaying () const

function GetPosition

inline uint32_t daisy::WavPlayer::GetPosition () const

Returns the position of the playhead in samples from the start of the file


function Init

inline Result daisy::WavPlayer::Init (
    const  char * name
) 

Initialize, and open a single file by name for playback


function Open

inline Result daisy::WavPlayer::Open (
    const  char * name
) 

Open a file, and prepare audio for streaming


function Prepare

inline Result daisy::WavPlayer::Prepare () 

To be executed in the main while loop, or other interruptable areas of code. This will perform the actual Disk I/O for streaming audio into the buffers used for playback.


function Restart

inline void daisy::WavPlayer::Restart () 

Clear all playback samples, and return to the beginning of the audio file immediately


function SetLooping

inline void daisy::WavPlayer::SetLooping (
    bool state
) 

Set whether the audio file will automatically continue playing from the beginning after reaching the end of file.


function SetPlaybackSpeedRatio

inline void daisy::WavPlayer::SetPlaybackSpeedRatio (
    const  float speed
) 

Direct setter of playback speed as a ratio compared to original speed. For example, 1.0 equals original speed, 0.5 is half-speed, etc.


function SetPlaybackSpeedSemitones

inline void daisy::WavPlayer::SetPlaybackSpeedSemitones (
    const  float semitones
) 

Sets playback speed as a number of semitones offset from original pitch For example, +7 a ratio of 1.5, +12 a ratio of 2, -12 a ratio of 0.5, etc.


function SetPlaying

inline void daisy::WavPlayer::SetPlaying (
    bool state
) 

function Stream

inline Result daisy::WavPlayer::Stream (
    float * samples,
    size_t num_channels
) 

Stream Audio from disk at the current playback speed.

Each call to this will increment the playback position's internal accumulator by the playback speed. Anytime this accumulator exceeds 1.0, it will update it's position tracker, and pop the next sample from the FIFO of audio samples. Whenever the contents of the audio sample FIFO fall below 75% of it's capacity, a request is generated to refill it. The maximum playback speed possible is limited to the following factors: * SD Card Bus-width * SD Card Clock Speed * workspace_bytes setting (consequently, transfer sizes)

It is possible to allow higher playback speeds, and improve bandwidth by using higher workspace sizes, with the trade-offs being memory, and latency with certain transactions.

Parameters:

  • samples buffer of floats to fill with audio samples from disk
  • num_channels number of channels provided to fill. This can be different from the number of channels in the file.

function WavPlayer

inline daisy::WavPlayer::WavPlayer () 

function ~WavPlayer

inline daisy::WavPlayer::~WavPlayer () 


The documentation for this class was generated from the following file external-docs/libDaisy/src/util/WavPlayer.h