Changes to example sketches

Outer audio block loop variable name changed from "i" to "s" to avoid confusion.
main
Rich Heslip 4 years ago
parent c55d05128b
commit 999e6df99a
  1. 4
      README.md
  2. 4
      examples/modal/modal.ino
  3. 8
      examples/polysynth/polysynth.ino
  4. 10
      examples/teensyaudio/teensyaudio.ino

@ -31,7 +31,7 @@ Teensy Audio processes 128 16 bit integer samples at a time and uses a pool of s
In contrast, DaisySP processes one sample at a time using floating point and each function allocates its memory statically. Simple, but uses a lot of memory for things like reverbs and delays and its pretty CPU intensive. In contrast, DaisySP processes one sample at a time using floating point and each function allocates its memory statically. Simple, but uses a lot of memory for things like reverbs and delays and its pretty CPU intensive.
To use DaisySP with Teensy Audio we process 128 samples at a time, convert the floating point results to integer and pass them to the next Teensy audio object in the patch. The DaisySP audio object has a callback function called AudioSynthDaisySP::update which does this. You must have this function in your sketch and this is where you call DaisySP library functions. Look at the example sketch to see how this works. To use DaisySP with Teensy Audio we process 128 samples at a time, convert the floating point results to integer and pass them to the next Teensy audio object in the patch. The DaisySP audio object has a callback function called AudioSynthDaisySP::update which does this. You must have this function in your sketch and this is where you call DaisySP library functions. Look at the example sketches to see how this works.
Installing the library: Installing the library:
@ -39,7 +39,7 @@ Copy the contents of the DaisySP folder to your arduino/library folder
Copy the file Teensy/Audio/synth_daisysp.h (the DaisySP audio object) to your Teensy audio library - usually this will be your_Arduino_installation_directory/hardware/teensy/avr/libraries/audio. Copy the file Teensy/Audio/synth_daisysp.h (the DaisySP audio object) to your Teensy audio library - usually this will be your_Arduino_installation_directory/hardware/teensy/avr/libraries/audio.
Teensy/Audio/Audio.h has been modified to include synth_daisysp.h. You may want to do this manually since I can't guarantee I will be tracking changes to the Teensy Audio library. Teensy/Audio/Audio.h has a #include synth_daisysp.h so you can replace your Teensy audio library Audio.h with this file. Its probably better edit your existing Audio.h file - I can't guarantee I will be tracking future changes to the Teensy Audio library.
I decided to structure the library so you have to manually include the DaisySP *.cpp files you are using in your sketch vs compiling the whole library into the sketch. This is a bit of a pain but including the whole library uses almost 500k of program memory and close to 500k of RAM which leaves very little RAM for the rest of your code. There is currently no provision for using the optional PSRAM on the Teensy 4.1. I decided to structure the library so you have to manually include the DaisySP *.cpp files you are using in your sketch vs compiling the whole library into the sketch. This is a bit of a pain but including the whole library uses almost 500k of program memory and close to 500k of RAM which leaves very little RAM for the rest of your code. There is currently no provision for using the optional PSRAM on the Teensy 4.1.

@ -46,7 +46,7 @@ void AudioSynthDaisySP::update(void)
return; return;
} }
for (int i=0; i < AUDIO_BLOCK_SAMPLES; i++) { for (int s=0; s < AUDIO_BLOCK_SAMPLES; s++) {
//**** insert daisySP generators here //**** insert daisySP generators here
@ -62,7 +62,7 @@ void AudioSynthDaisySP::update(void)
// convert generated float value -1.0 to +1.0 to int16 used by Teensy Audio // convert generated float value -1.0 to +1.0 to int16 used by Teensy Audio
int32_t val = out*MULT_16; int32_t val = out*MULT_16;
block->data[i] = val >> 16; block->data[s] = val >> 16;
} }
transmit(block); transmit(block);
release(block); release(block);

@ -7,7 +7,7 @@
#include <Audio.h> #include <Audio.h>
#include <Metro.h> #include <Metro.h>
//#define DEBUG // comment out to remove debug code #define DEBUG // comment out to remove debug code
#ifdef DEBUG #ifdef DEBUG
Metro five_sec=Metro(5000); // Set up a 5 second Metro for performance stats Metro five_sec=Metro(5000); // Set up a 5 second Metro for performance stats
@ -46,7 +46,7 @@ float lfofreqdepth=0;
float lfofilterdepth=0; float lfofilterdepth=0;
// create daisySP processing objects // create daisySP processing objects
#define OSCSPERVOICE 3 // note - the detune code is set up for 3 oscillators #define OSCSPERVOICE 4 // note - the detune code is set up for 3 oscillators
Oscillator osc[VOICES * OSCSPERVOICE]; Oscillator osc[VOICES * OSCSPERVOICE];
Oscillator lfo; Oscillator lfo;
@ -66,7 +66,7 @@ void AudioSynthDaisySP::update(void)
return; return;
} }
for (int i=0; i < AUDIO_BLOCK_SAMPLES; i++) { for (int s=0; s < AUDIO_BLOCK_SAMPLES; s++) {
//**** insert daisySP generators here //**** insert daisySP generators here
@ -94,7 +94,7 @@ void AudioSynthDaisySP::update(void)
// convert generated float value -1.0 to +1.0 to int16 used by Teensy Audio // convert generated float value -1.0 to +1.0 to int16 used by Teensy Audio
int32_t val = out*MULT_16; int32_t val = out*MULT_16;
block->data[i] = val >> 16; block->data[s] = val >> 16;
} }
transmit(block); transmit(block);
release(block); release(block);

@ -35,15 +35,15 @@ ReverbSc verb;
AudioOutputI2S out; AudioOutputI2S out;
AudioOutputUSB outUSB; //AudioOutputUSB outUSB;
AudioControlSGTL5000 audioShield; AudioControlSGTL5000 audioShield;
AudioSynthDaisySP synth; // create the daisysp synth audio object AudioSynthDaisySP synth; // create the daisysp synth audio object
AudioConnection patchCord20(synth,0,out,0); AudioConnection patchCord20(synth,0,out,0);
AudioConnection patchCord21(synth,0,out,1); AudioConnection patchCord21(synth,0,out,1);
AudioConnection patchCord22(synth,0,outUSB,0); //AudioConnection patchCord22(synth,0,outUSB,0);
AudioConnection patchCord23(synth,0,outUSB,1); //AudioConnection patchCord23(synth,0,outUSB,1);
@ -58,7 +58,7 @@ void AudioSynthDaisySP::update(void)
return; return;
} }
for (int i=0; i < AUDIO_BLOCK_SAMPLES; i++) { for (int s=0; s < AUDIO_BLOCK_SAMPLES; s++) {
//**** insert daisySP generators here //**** insert daisySP generators here
@ -80,7 +80,7 @@ void AudioSynthDaisySP::update(void)
// convert generated float value -1.0 to +1.0 to int16 used by Teensy Audio // convert generated float value -1.0 to +1.0 to int16 used by Teensy Audio
int32_t val = out*MULT_16; int32_t val = out*MULT_16;
block->data[i] = val >> 16; block->data[s] = val >> 16;
} }
transmit(block); transmit(block);
release(block); release(block);

Loading…
Cancel
Save