Class daisy::WavPlayer¶
template <size_t workspace_bytes>
#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¶
Close a file, and clear the data
function GetChannels¶
Return the number of audio channels in the open audio file
function GetDurationInSamples¶
Return the number of samples in the open audio file
function GetLooping¶
Return whether the player is looping or not.
function GetNormalizedPosition¶
Returns a 0-1 representation of the playhead position within the file.
function GetPlaying¶
function GetPosition¶
Returns the position of the playhead in samples from the start of the file
function Init¶
Initialize, and open a single file by name for playback
function Open¶
Open a file, and prepare audio for streaming
function 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¶
Clear all playback samples, and return to the beginning of the audio file immediately
function SetLooping¶
Set whether the audio file will automatically continue playing from the beginning after reaching the end of file.
function SetPlaybackSpeedRatio¶
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¶
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¶
function Stream¶
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:
samplesbuffer of floats to fill with audio samples from disknum_channelsnumber of channels provided to fill. This can be different from the number of channels in the file.
function WavPlayer¶
function ~WavPlayer¶
The documentation for this class was generated from the following file external-docs/libDaisy/src/util/WavPlayer.h