Component: WAV Player FAT (Storage)
Author | Matrix TSL |
Version | 1.0 (Release) |
Category | Storage |
Contents
WAV Player FAT component
Contains component macros to allow the WAV file to be streamed from a .wav file loaded on an SD card. Complete with buffer to allow for uninterrupted playback when performing other tasks. Compatible with analogue outputs such as DAC or PWM.
Examples
Simple playback example - allows a wav file to be streamed out using PWM. Repeats the playback in a loop.
Simple recording example - allows a wav file to be recorded from a microphone connected to an ADC input pin. Records for approx 10 seconds.
Downloadable macro reference
StartPlayback
Start playing a WAV file from the SD card.
Use the GetNextSample and EndOfFile macros to read out the contents of the file.
Use the ProcessBuffer macro to maintain the local buffer.
Returns 1 if file found and opened, else returns 0.
Parameters
- <- STRING Filename
- WAV Filename e.g. "Test.wav"
- This parameter may be returned back to the caller
Return value
EndOfFile
A simple check to see if we are at the end of the file.
Returns 0 if we and not yet at the end fo the file.
Returns 1 if we are at the end of the file.
Parameters
- This macro has no parameters
Return value
- BOOL : Returns true if the operation is a success, else false
ProcessBuffer
When Playing a WAV File - Fills the local data buffer from the SD card.
When Recording a WAV File - Writes the local data buffer to the SD card.
Must be called often enough to maintain playback or recording.
Returns 0 for buffer OK 1 for buffer overrun
Parameters
- This macro has no parameters
Return value
StopRecording
No additional information
Parameters
- This macro has no parameters
Return value
- This call does not return a value
PutNextSample
Writes the value for the next sample and auto increments the file pointer.
Ideally this function should be called as part of a timer interrupt at the sample rate.
The value written should be collected using an analogue input such as a Mic.
Parameters
- UINT Sample
Return value
- This call does not return a value
GetNumChannels
Returns the number of audio channels stored in the WAV file during playback.
Parameters
- This macro has no parameters
Return value
StartRecording
Start recording a WAV file to the SD card.
Use the WritetNextSample macro to write the contents of the file.
Use the ProcessBuffer macro to maintain the local buffer.
Returns 1 if file created and opened, else returns 0.
Parameters
- <- STRING Filename
- WAV Filename e.g. "Test.wav"
- This parameter may be returned back to the caller
- BYTE BitsPerSample
- Number of bits per sample - 8 or 16
- ULONG SampleRate
- Sample Rate in Hz e.g. 8000 for 8KHz
Return value
GetBitsPerSample
Returns the number of bits per sample during playback.
Parameters
- This macro has no parameters
Return value
GetNextSample
Retreives the value for the next sample and auto increments the file pointer.
Ideally this function should be called as part of a timer interrupt at the sample rate.
The value returned should be passed onto a means of analogue output e.g. a DAC or PWM.
Parameters
- This macro has no parameters
Return value
Simulation macro reference
This component does not contain any simulation macros
Property reference
FAT Component
This property is of type Panel object and can be referenced with the variable name Component.
Pointer to the FAT component in your program.
Buffer Size
This property is of type Unsigned integer and can be referenced with the variable name BufferSize.
The number of RAM bytes to allocate to the WAV buffer.
The buffer must be big enough to store enough WAV audio samples to maintain playback or recording
when doing other program tasks or performing SD card read/write operations.
Memory Type
This property is of type Fixed list of ints and can be referenced with the variable name CircularBuffer1::MemType.
No additional information