Firmware library: variable playback rate for teensy audio library
play 16-bit PCM raw or wav 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.
typedef enum play_start {
play_start_sample,
play_start_loop,
};
wave.setPlayStart(play_start::play_start_loop);
AudioPlaySdResmp wave;
wave.setUseDualPlaybackHead(true);
wave.setCrossfadeDurationInSamples(1000);
wave.playRaw((int16_t*)kick_raw, kick_raw_len / 2, numberOfChannels);
wave.setLoopStart(0);
wave.setLoopFinish(3000);
AudioPlaySdRawResmp
and AudioPlaySdWaveResmp
merged into a single class AudioPlaySdResmp
play(...)
method changed to playRaw(...)
and playWav(...)
, specify number of channels in parameters of playRawfolder | target | description |
---|---|---|
examples |
teensy |
basic example how to use |
extras |
linux |
some utils to make life easier |
src |
teensy / linux |
extends teensy audio library * adds AudioPlaySdResmp * adds AudioPlayArrayResmp |
test |
linux |
unit tests that run on linux |
Teensyduino
^
TeensyVariablePlayback
cmake
gcc-arm-none-eabi
^ teensy-cmake-macros
^ cores
^ Audio
^ SD
^ Wire
^ SPI
^ SerialFlash
^ arm_math
^ SDFat
^
graph G {
graph[rankdir="LR"]
"teensy variable playback" -- "teensy-cmake-macros" -- "cmake" [label="dev"]
"teensy-cmake-macros" -- "arm-none-eabi-gcc" [label="dev"]
"PaulStoffregen/Audio.git" -- "PaulStoffregen/cores.git"
"teensy variable playback" -- "PaulStoffregen/Audio.git"
"PaulStoffregen/Audio.git" -- "PaulStoffregen/SD.git@Juse_Use_SdFat"
"PaulStoffregen/SD.git@Juse_Use_SdFat" -- "PaulStoffregen/SPI.git"
"PaulStoffregen/SD.git@Juse_Use_SdFat" -- "greiman/SdFat.git"
"PaulStoffregen/Audio.git" -- "PaulStoffregen/Wire.git"
"PaulStoffregen/Audio.git" -- "PaulStoffregen/SerialFlash.git"
"PaulStoffregen/Audio.git" -- "PaulStoffregen/arm_math.git"
}
cmake
gcc or llvm
teensy-x86-stubs
^ teensy-audio-x86-stubs
^ teensy-x86-sd-stubs
^ boost-test
sudo apt-get install -yq libboost-test-dev
brew install boost
To install the library, use the library manager in Teensyduino (search for TeensyVariablePlayback
). Teensyduino should already have all the necessary dependencies pre-installed.
Have a look at the examples in the file menu to get started...
> git clone https://github.com/newdigate/teensy-variable-playback.git
> cd teensy-variable-playback
You don't need to download or install Teensyduino or Arduino to build the library or examples. Just clone the cores library and any dependencies to a common folder, denoted by DEPSPATH
(in this case /home/nic/teensy_libraries
).
> cd /home/nic/teensy_libraries
> git clone https://github.com/PaulStoffregen/cores.git
> git clone https://github.com/PaulStoffregen/Audio.git
> git clone -b Juse_Use_SdFat https://github.com/PaulStoffregen/SD.git
> git clone https://github.com/PaulStoffregen/Wire.git
> git clone https://github.com/PaulStoffregen/SPI.git
> git clone https://github.com/PaulStoffregen/SerialFlash.git
> git clone https://github.com/PaulStoffregen/arm_math.git
> git clone https://github.com/greiman/SdFat.git
set(COMPILERPATH "/Applications/Arm/bin/")
set(DEPSPATH "/home/nic/teensy_libraries")
set(COREPATH "${DEPSPATH}/cores/teensy4/")
-DCMAKE_TOOLCHAIN_FILE:FILEPATH
below)> cd /home/nic/teensy-variable-playback
> mkdir cmake-build-debug
> cd cmake-build-debug
> cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE:FILEPATH="../cmake/toolchains/teensy41.cmake" ..
> make
> ./build-linux.sh
> mkdir cmake-build-debug
> cd cmake-build-debug
> cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE:FILEPATH="../cmake/toolchains/linux.cmake" ..
> make
> cmake-build-debug/test/test_suite1
#include <Arduino.h>
#include <Audio.h>
#include <TeensyVariablePlayback.h>
// GUItool: begin automatically generated code
AudioPlayArrayResmp rraw_a1; //xy=321,513
AudioOutputI2S i2s1; //xy=675,518
AudioConnection patchCord1(rraw_a1, 0, i2s1, 0);
AudioConnection patchCord2(rraw_a1, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=521,588
// GUItool: end automatically generated code
unsigned char kick_raw[] = {
// ... little-endian 16-bit mono 44100 raw data, generated using linux cmd 'xxd -i kick.raw', raw file saved in Audacity
0x99, 0x02, 0xd7, 0x02, 0xfa, 0x02, 0x5f, 0x03, 0xc1, 0x03, 0x2a, 0x04,
0xad, 0x04, 0xa5, 0x05, 0x76, 0x06, 0x2f, 0x07, 0x9e, 0x07, 0xe2, 0x07,
0x43, 0x08, 0x92, 0x08, 0xb2, 0x08, 0xe8, 0x08, 0x16, 0x09, 0xda, 0x08,
// ... continued ...
};
unsigned int kick_raw_len = 6350; // length in bytes == numsamples * 2
void setup() {
AudioMemory(20);
sgtl5000_1.enable();
sgtl5000_1.volume(0.5f, 0.5f);
rraw_a1.setPlaybackRate(0.5);
rraw_a1.enableInterpolation(true);
}
void loop() {
if (!rraw_a1.isPlaying()) {
delay(1000);
rraw_a1.playRaw((int16_t *)kick_raw, kick_raw_len/2, 1); //note: we give number of samples - NOT number of bytes!!!! 1 is for mono (2 for stereo, etc)
}
}