play 16-bit PCM raw or wav audio samples at variable playback rates on teensy
play 16-bit audio samples at variable playback rates on teensy
* **Note** : this library only works with signed 16-bit integer samples. Floating point samples will not play.
* for best performance, use SDXC UHS 30MB/sec Application Performance Class 2 (A2) class micro sd-card.
* for best performance, use SDXC UHS 30MB/sec Application Performance Class 2 (A2) class micro sd-card.
* [sd classes on wikipedia](https://en.wikipedia.org/wiki/SD_card#cite_ref-93)
* [sd classes on wikipedia](https://en.wikipedia.org/wiki/SD_card#cite_ref-93)
## updates
## updates
* 16/06/2022: v1.0.14:
* refactored code to generic classes
* improve memory leaks
* remove calls to StartUsingSPI(), StopUsingSPI(), __disable_irq(), __enable_irq()
* intergated with SerialFlash and LittleFS
* 25/09/2021: v1.0.13: positionMillis() implemented for AudioPlaySdResmp
* 25/08/2021: v1.0.12: Skip over RIFF tags in .wav header
* 12/08/2021: v1.0.11: When playing a mono sample, transmit on both channels (credit to @atoktoto)
* 12/08/2021: v1.0.11: When playing a mono sample, transmit on both channels (credit to @atoktoto)
* 28/07/2021: v1.0.10: Fix issues when starting playback in reverse
* 28/07/2021: v1.0.10: Fix issues when starting playback in reverse
* 23/07/2021: v1.0.9: Fix issue which crashes teensy when playing multiple files from SD card using array of filenames
* 23/07/2021: v1.0.9: Fix issue which crashes teensy when playing multiple files from SD card using array of filenames
@ -108,11 +100,10 @@ graph G {
<details>
<details>
<summary>linux</summary>
<summary>linux</summary>
You can run and test this code on your linux computer. You can write a teensy sketch, and with a few modifications, you can redirect the audio input and output to and from your soundcard. [Soundio](https://github.com/newdigate/teensy-audio-x86-stubs/tree/main/extras/soundio) bindings are optional, you can also run sketches and tests with no audio input or output.
You will need to install the following libraries.
```cmake``` ```gcc or llvm``` ```teensy-x86-stubs```[^](https://github.com/newdigate/teensy-x86-stubs) ```teensy-audio-x86-stubs```[^](https://github.com/newdigate/teensy-audio-x86-stubs) ```teensy-x86-sd-stubs```[^](https://github.com/newdigate/teensy-x86-sd-stubs) ```boost-test```
```cmake``` ```gcc or llvm``` ```teensy-x86-stubs```[^](https://github.com/newdigate/teensy-x86-stubs) ```teensy-audio-x86-stubs```[^](https://github.com/newdigate/teensy-audio-x86-stubs) ```teensy-x86-sd-stubs```[^](https://github.com/newdigate/teensy-x86-sd-stubs) ```boost-test```
By using stub libraries, we can compile teensy code to native device architecture. To a certain extent, this allows sketches and libraries to be developed, emulated, debugged and unit-tested using linux, on your local device or a build server. In this case I have a few basic tests for the ResamplingSdReader class.
// Serial.printf("Needs 16 bit audio! Aborting.... (got %d)", wav_header.bit_depth);
Serial.printf("Needs 16 bit audio! Aborting.... (got %d)",wav_header.bit_depth);
returnfalse;
returnfalse;
}
}
setNumChannels(wav_header.num_channels);
setNumChannels(wav_header.num_channels);
_header_offset=22;
_header_offset=22;
_file_size=wav_header.data_bytes+44;//2 bytes per sample
_file_size=wav_header.data_bytes+44;//2 bytes per sample
if(_file_size>length*2){
if(_file_size>length*2){
// Serial.printf("TeensyVariablePlayback: warning: length of array in bytes (%d) is smaller than the file data size in bytes (%d) according to the header - defaulting length to filesize...", length * 2, _file_size);
Serial.printf("TeensyVariablePlayback: warning: length of array in bytes (%d) is smaller than the file data size in bytes (%d) according to the header - defaulting length to filesize...",length*2,_file_size);