Home

Awesome

variable rate playback for teensy audio library

Teensy 4.1 lib-teensy41 Ubuntu-x64 MIT license CMake made-for-VSCode Contributors Commits s

play 16-bit PCM raw or wav audio samples at variable playback rates on teensy

updates

contents

code structure

foldertargetdescription
examplesteensybasic example how to use
extraslinuxsome utils to make life easier
srcteensy / linuxextends teensy audio library<br/> * adds AudioPlaySdResmp <br/> * adds AudioPlayArrayResmp
testlinuxunit tests that run on linux

requirements

<details> <summary>teensy 3.x & 4.x boards</summary> <details> <summary>with Teensyduino</summary>

Teensyduino^

</details> <details> <summary>without Teensyduino (for development)</summary>

cmake gcc-arm-none-eabi^ teensy-cmake-macros^ cores^ Audio^ SD^ Wire^ SPI^ SerialFlash^ arm_math^ SDFat^

<details> <summary>dependencies (click to expand image) </summary>

dependencies

<details> <summary>graphvis (click to expand) </summary>
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"
}
</details> </details> </details> </details> <details> <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^ teensy-audio-x86-stubs^ teensy-x86-sd-stubs^ boost-test

</details>

usage

<details> <summary>Using with Teensyduino</summary> </details> <details> <summary>Developing with vscode</summary>

clone repo

> git clone https://github.com/newdigate/teensy-variable-playback.git
> cd teensy-variable-playback

teensy build

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).

<details> <summary>clone dependencies (click to expand) </summary>
 > 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
</details> <details> <summary>update COMPILERPATH and DEPSPATH in cmake/toolchains/teensy41.cmake</summary>
set(COMPILERPATH "/Applications/Arm/bin/")
set(DEPSPATH "/home/nic/teensy_libraries")
set(COREPATH "${DEPSPATH}/cores/teensy4/")
</details> <details> <summary>build hex file</summary>
> 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
</details>

linux build

build tests on linux

> ./build-linux.sh

build tests on win

> mkdir cmake-build-debug
> cd cmake-build-debug
> cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE:FILEPATH="../cmake/toolchains/linux.cmake" ..
> make

run tests

> cmake-build-debug/test/test_suite1

visual studio code

</details>

example usage

<details> <summary>example (click to expand) </summary>
#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)
    }
}
</details>

credits