├── .gitignore ├── gui ├── favicon.ico ├── icons │ ├── db.png │ ├── feed.png │ ├── file.png │ ├── hash.png │ ├── rpi.png │ ├── swap.png │ ├── alert.png │ ├── arduino.png │ ├── bridge.png │ ├── comment.png │ ├── debug.png │ ├── inject.png │ ├── leveldb.png │ ├── light.png │ ├── mongodb.png │ ├── range.png │ ├── redis.png │ ├── serial.png │ ├── switch.png │ ├── timer.png │ ├── trigger.png │ ├── twitter.png │ ├── watch.png │ ├── arrow-in.png │ ├── bluetooth.png │ ├── envelope.png │ ├── function.png │ ├── template.png │ ├── bridge-dash.png │ ├── node-changed.png │ ├── node-error.png │ └── white-globe.png ├── img │ ├── grip.png │ ├── biquad.png │ ├── dacpin.jpg │ ├── dahdsr.png │ ├── delay.png │ ├── adcpins1.jpg │ ├── adcpins2.jpg │ ├── multiply.png │ ├── node-red.png │ ├── w25q128fv.jpg │ ├── adccircuit.png │ ├── fir_filter.png │ ├── memoryboard.jpg │ ├── spdif_proto.jpg │ ├── whitenoise.png │ ├── pw_maze_white.png │ ├── pwmdualcircuit.jpg │ ├── sgtl5000closeup.jpg │ ├── audioshield_inputs.jpg │ ├── audioshield_outputs.jpg │ └── audioshield_backside.jpg ├── font-awesome │ └── fonts │ │ ├── FontAwesome.otf │ │ ├── fontawesome-webfont.eot │ │ ├── fontawesome-webfont.ttf │ │ └── fontawesome-webfont.woff ├── bootstrap │ └── img │ │ ├── glyphicons-halflings.png │ │ └── glyphicons-halflings-white.png ├── jquery │ ├── css │ │ └── smoothness │ │ │ └── images │ │ │ ├── animated-overlay.gif │ │ │ ├── ui-icons_222222_256x240.png │ │ │ ├── ui-icons_2e83ff_256x240.png │ │ │ ├── ui-icons_454545_256x240.png │ │ │ ├── ui-icons_888888_256x240.png │ │ │ ├── ui-icons_cd0a0a_256x240.png │ │ │ ├── ui-bg_flat_0_aaaaaa_40x100.png │ │ │ ├── ui-bg_flat_75_ffffff_40x100.png │ │ │ ├── ui-bg_glass_55_fbf9ee_1x400.png │ │ │ ├── ui-bg_glass_65_ffffff_1x400.png │ │ │ ├── ui-bg_glass_75_dadada_1x400.png │ │ │ ├── ui-bg_glass_75_e6e6e6_1x400.png │ │ │ ├── ui-bg_glass_95_fef1ec_1x400.png │ │ │ └── ui-bg_highlight-soft_75_cccccc_1x100.png │ └── js │ │ └── jquery.ui.touch-punch.min.js └── red │ ├── ui │ ├── state.js │ ├── notifications.js │ └── keyboard.js │ └── storage.js ├── multiplier.md ├── extras └── wav2sketch │ └── wav2sketch.exe ├── examples ├── Effects │ ├── Filter_FIR │ │ ├── screencap_bandpass.jpg │ │ ├── screencap_lowpass.jpg │ │ ├── filters.h │ │ ├── filters.cpp │ │ ├── lopass_1000_44100.h │ │ └── bandp_1200_1700.h │ ├── Filter │ │ └── Filter.ino │ ├── Delay │ │ └── Delay.ino │ ├── Chorus │ │ └── effects_info.h │ └── Flange │ │ └── effects_info.h ├── SamplePlayer │ ├── AudioSampleKick.h │ ├── AudioSampleGong.h │ ├── AudioSampleHihat.h │ ├── AudioSampleSnare.h │ ├── AudioSampleTomtom.h │ └── AudioSampleCashregister.h ├── Tutorial │ ├── Part_2_03_Samples │ │ ├── AudioSampleGong.h │ │ ├── AudioSampleKick.h │ │ ├── AudioSampleHihat.h │ │ ├── AudioSampleSnare.h │ │ ├── AudioSampleTomtom.h │ │ ├── AudioSampleCashregister.h │ │ └── Part_2_03_Samples.ino │ ├── Part_3_02_Fourier_Transform │ │ └── AudioSampleGuitar.h │ ├── Part_2_04_Microphone_Check │ │ └── Part_2_04_Microphone_Check.ino │ ├── Part_2_01_First_Design_Tool_Use │ │ └── Part_2_01_First_Design_Tool_Use.ino │ ├── Part_2_06_Feedback_Delay │ │ └── Part_2_06_Feedback_Delay.ino │ ├── Part_2_05_Simple_Delay │ │ └── Part_2_05_Simple_Delay.ino │ ├── Part_1_03_Playing_Music │ │ └── Part_1_03_Playing_Music.ino │ ├── Part_2_02_Mixers │ │ └── Part_2_02_Mixers.ino │ ├── Part_3_01_Peak_Detection │ │ └── Part_3_01_Peak_Detection.ino │ ├── Part_1_04_Blink_While_Playing │ │ └── Part_1_04_Blink_While_Playing.ino │ ├── Part_1_05_Do_More_While_Playing │ │ └── Part_1_05_Do_More_While_Playing.ino │ └── Part_3_03_TFT_Display │ │ └── Part_3_03_TFT_Display.ino ├── Synthesis │ ├── PlaySynthMusic │ │ └── miditones │ │ │ └── Makefile │ └── pulseWidth │ │ └── pulseWidth.ino ├── HardwareTesting │ ├── PassThroughMono │ │ └── PassThroughMono.ino │ ├── WM8731MikroSine │ │ └── WM8731MikroSine.ino │ ├── PassThroughStereo │ │ └── PassThroughStereo.ino │ ├── SGTL5000 │ │ ├── balanceHP │ │ │ └── balanceHP.ino │ │ ├── balanceDAC │ │ │ └── balanceDAC.ino │ │ ├── dap_avc_agc │ │ │ └── dap_avc_agc.ino │ │ ├── dap_bass_enhance │ │ │ └── dap_bass_enhance.ino │ │ └── CalcBiquadToneControlDAP │ │ │ └── CalcBiquadToneControlDAP.ino │ └── ToneSweep │ │ └── ToneSweep.ino └── Analysis │ ├── PeakMeterMono │ └── PeakMeterMono.ino │ ├── PeakMeterStereo │ └── PeakMeterStereo.ino │ └── FFT │ └── FFT.ino ├── library.properties ├── library.json ├── filter_fir.md ├── matrix_mixer.h ├── effect_sh.h ├── spi_interrupt.cpp ├── effect_waveshaper.h ├── synth_waveform.md ├── effect_multiply.h ├── utility ├── imxrt_hw.h ├── sqrt_integer.c ├── sqrt_integer.h └── imxrt_hw.cpp ├── input_pdm.h ├── filter_fir.cpp ├── input_tdm.h ├── memcpy_audio.h ├── analyze_rms.h ├── AudioControl.h ├── effect_chorus.h ├── play_memory.h ├── output_tdm.h ├── play_sd_raw.h ├── output_pwm.h ├── control_wm8731.h ├── synth_whitenoise.h ├── input_i2s_quad.h ├── play_queue.h ├── effect_midside.h ├── analyze_peak.cpp ├── .travis.yml ├── synth_tonesweep.h ├── record_queue.h ├── effect_flange.h ├── output_dacs.h ├── play_serialflash_raw.h ├── effect_sh.cpp ├── output_spdif.h ├── input_adc.h ├── effect_combine.h ├── output_dac.h ├── effect_bitcrusher.h ├── input_i2s.h ├── spi_interrupt.h ├── synth_pwm.h ├── analyze_print.h ├── effect_fade.h ├── input_adcs.h ├── effect_granular.h ├── play_queue.cpp ├── filter_fir.h ├── output_i2s_quad.h ├── synth_pinknoise.h ├── follower.h ├── synth_karplusstrong.h ├── analyze_peak.h ├── effect_tape_delay.h ├── output_i2s.h ├── control_cs4272.h └── play_sd_wav.h /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | -------------------------------------------------------------------------------- /gui/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/favicon.ico -------------------------------------------------------------------------------- /gui/icons/db.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/db.png -------------------------------------------------------------------------------- /gui/img/grip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/img/grip.png -------------------------------------------------------------------------------- /gui/icons/feed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/feed.png -------------------------------------------------------------------------------- /gui/icons/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/file.png -------------------------------------------------------------------------------- /gui/icons/hash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/hash.png -------------------------------------------------------------------------------- /gui/icons/rpi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/rpi.png -------------------------------------------------------------------------------- /gui/icons/swap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/swap.png -------------------------------------------------------------------------------- /gui/img/biquad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/img/biquad.png -------------------------------------------------------------------------------- /gui/img/dacpin.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/img/dacpin.jpg -------------------------------------------------------------------------------- /gui/img/dahdsr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/img/dahdsr.png -------------------------------------------------------------------------------- /gui/img/delay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/img/delay.png -------------------------------------------------------------------------------- /gui/icons/alert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/alert.png -------------------------------------------------------------------------------- /gui/icons/arduino.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/arduino.png -------------------------------------------------------------------------------- /gui/icons/bridge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/bridge.png -------------------------------------------------------------------------------- /gui/icons/comment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/comment.png -------------------------------------------------------------------------------- /gui/icons/debug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/debug.png -------------------------------------------------------------------------------- /gui/icons/inject.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/inject.png -------------------------------------------------------------------------------- /gui/icons/leveldb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/leveldb.png -------------------------------------------------------------------------------- /gui/icons/light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/light.png -------------------------------------------------------------------------------- /gui/icons/mongodb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/mongodb.png -------------------------------------------------------------------------------- /gui/icons/range.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/range.png -------------------------------------------------------------------------------- /gui/icons/redis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/redis.png -------------------------------------------------------------------------------- /gui/icons/serial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/serial.png -------------------------------------------------------------------------------- /gui/icons/switch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/switch.png -------------------------------------------------------------------------------- /gui/icons/timer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/timer.png -------------------------------------------------------------------------------- /gui/icons/trigger.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/trigger.png -------------------------------------------------------------------------------- /gui/icons/twitter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/twitter.png -------------------------------------------------------------------------------- /gui/icons/watch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/watch.png -------------------------------------------------------------------------------- /gui/img/adcpins1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/img/adcpins1.jpg -------------------------------------------------------------------------------- /gui/img/adcpins2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/img/adcpins2.jpg -------------------------------------------------------------------------------- /gui/img/multiply.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/img/multiply.png -------------------------------------------------------------------------------- /gui/img/node-red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/img/node-red.png -------------------------------------------------------------------------------- /gui/img/w25q128fv.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/img/w25q128fv.jpg -------------------------------------------------------------------------------- /gui/icons/arrow-in.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/arrow-in.png -------------------------------------------------------------------------------- /gui/icons/bluetooth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/bluetooth.png -------------------------------------------------------------------------------- /gui/icons/envelope.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/envelope.png -------------------------------------------------------------------------------- /gui/icons/function.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/function.png -------------------------------------------------------------------------------- /gui/icons/template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/template.png -------------------------------------------------------------------------------- /gui/img/adccircuit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/img/adccircuit.png -------------------------------------------------------------------------------- /gui/img/fir_filter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/img/fir_filter.png -------------------------------------------------------------------------------- /gui/img/memoryboard.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/img/memoryboard.jpg -------------------------------------------------------------------------------- /gui/img/spdif_proto.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/img/spdif_proto.jpg -------------------------------------------------------------------------------- /gui/img/whitenoise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/img/whitenoise.png -------------------------------------------------------------------------------- /multiplier.md: -------------------------------------------------------------------------------- 1 | multiplier 140411 2 | Multiplies two input waveforms, from channels zero and one. -------------------------------------------------------------------------------- /gui/icons/bridge-dash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/bridge-dash.png -------------------------------------------------------------------------------- /gui/icons/node-changed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/node-changed.png -------------------------------------------------------------------------------- /gui/icons/node-error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/node-error.png -------------------------------------------------------------------------------- /gui/icons/white-globe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/icons/white-globe.png -------------------------------------------------------------------------------- /gui/img/pw_maze_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/img/pw_maze_white.png -------------------------------------------------------------------------------- /gui/img/pwmdualcircuit.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/img/pwmdualcircuit.jpg -------------------------------------------------------------------------------- /gui/img/sgtl5000closeup.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/img/sgtl5000closeup.jpg -------------------------------------------------------------------------------- /gui/img/audioshield_inputs.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/img/audioshield_inputs.jpg -------------------------------------------------------------------------------- /gui/img/audioshield_outputs.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/img/audioshield_outputs.jpg -------------------------------------------------------------------------------- /extras/wav2sketch/wav2sketch.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/extras/wav2sketch/wav2sketch.exe -------------------------------------------------------------------------------- /gui/img/audioshield_backside.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/img/audioshield_backside.jpg -------------------------------------------------------------------------------- /gui/font-awesome/fonts/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/font-awesome/fonts/FontAwesome.otf -------------------------------------------------------------------------------- /gui/bootstrap/img/glyphicons-halflings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/bootstrap/img/glyphicons-halflings.png -------------------------------------------------------------------------------- /gui/font-awesome/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/font-awesome/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /gui/font-awesome/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/font-awesome/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /gui/bootstrap/img/glyphicons-halflings-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/bootstrap/img/glyphicons-halflings-white.png -------------------------------------------------------------------------------- /gui/font-awesome/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/font-awesome/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /examples/Effects/Filter_FIR/screencap_bandpass.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/examples/Effects/Filter_FIR/screencap_bandpass.jpg -------------------------------------------------------------------------------- /examples/Effects/Filter_FIR/screencap_lowpass.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/examples/Effects/Filter_FIR/screencap_lowpass.jpg -------------------------------------------------------------------------------- /examples/SamplePlayer/AudioSampleKick.h: -------------------------------------------------------------------------------- 1 | // Audio data converted from WAV file by wav2sketch 2 | 3 | extern const unsigned int AudioSampleKick[2561]; 4 | -------------------------------------------------------------------------------- /examples/Effects/Filter_FIR/filters.h: -------------------------------------------------------------------------------- 1 | // Number of coefficients 2 | #define NUM_COEFFS 100 3 | extern short low_pass[]; 4 | extern short band_pass[]; 5 | 6 | -------------------------------------------------------------------------------- /examples/SamplePlayer/AudioSampleGong.h: -------------------------------------------------------------------------------- 1 | // Audio data converted from WAV file by wav2sketch 2 | 3 | extern const unsigned int AudioSampleGong[27633]; 4 | -------------------------------------------------------------------------------- /examples/SamplePlayer/AudioSampleHihat.h: -------------------------------------------------------------------------------- 1 | // Audio data converted from WAV file by wav2sketch 2 | 3 | extern const unsigned int AudioSampleHihat[5953]; 4 | -------------------------------------------------------------------------------- /examples/SamplePlayer/AudioSampleSnare.h: -------------------------------------------------------------------------------- 1 | // Audio data converted from WAV file by wav2sketch 2 | 3 | extern const unsigned int AudioSampleSnare[2817]; 4 | -------------------------------------------------------------------------------- /examples/SamplePlayer/AudioSampleTomtom.h: -------------------------------------------------------------------------------- 1 | // Audio data converted from WAV file by wav2sketch 2 | 3 | extern const unsigned int AudioSampleTomtom[3489]; 4 | -------------------------------------------------------------------------------- /gui/jquery/css/smoothness/images/animated-overlay.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/jquery/css/smoothness/images/animated-overlay.gif -------------------------------------------------------------------------------- /examples/Tutorial/Part_2_03_Samples/AudioSampleGong.h: -------------------------------------------------------------------------------- 1 | // Audio data converted from WAV file by wav2sketch 2 | 3 | extern const unsigned int AudioSampleGong[27633]; 4 | -------------------------------------------------------------------------------- /examples/Tutorial/Part_2_03_Samples/AudioSampleKick.h: -------------------------------------------------------------------------------- 1 | // Audio data converted from WAV file by wav2sketch 2 | 3 | extern const unsigned int AudioSampleKick[2561]; 4 | -------------------------------------------------------------------------------- /examples/SamplePlayer/AudioSampleCashregister.h: -------------------------------------------------------------------------------- 1 | // Audio data converted from WAV file by wav2sketch 2 | 3 | extern const unsigned int AudioSampleCashregister[5809]; 4 | -------------------------------------------------------------------------------- /examples/Synthesis/PlaySynthMusic/miditones/Makefile: -------------------------------------------------------------------------------- 1 | miditones: miditonesV1.6.c 2 | gcc -O2 -Wall -o miditones miditonesV1.6.c 3 | 4 | clean: 5 | rm -f miditones 6 | -------------------------------------------------------------------------------- /examples/Tutorial/Part_2_03_Samples/AudioSampleHihat.h: -------------------------------------------------------------------------------- 1 | // Audio data converted from WAV file by wav2sketch 2 | 3 | extern const unsigned int AudioSampleHihat[5953]; 4 | -------------------------------------------------------------------------------- /examples/Tutorial/Part_2_03_Samples/AudioSampleSnare.h: -------------------------------------------------------------------------------- 1 | // Audio data converted from WAV file by wav2sketch 2 | 3 | extern const unsigned int AudioSampleSnare[2817]; 4 | -------------------------------------------------------------------------------- /examples/Tutorial/Part_2_03_Samples/AudioSampleTomtom.h: -------------------------------------------------------------------------------- 1 | // Audio data converted from WAV file by wav2sketch 2 | 3 | extern const unsigned int AudioSampleTomtom[3489]; 4 | -------------------------------------------------------------------------------- /gui/jquery/css/smoothness/images/ui-icons_222222_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/jquery/css/smoothness/images/ui-icons_222222_256x240.png -------------------------------------------------------------------------------- /gui/jquery/css/smoothness/images/ui-icons_2e83ff_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/jquery/css/smoothness/images/ui-icons_2e83ff_256x240.png -------------------------------------------------------------------------------- /gui/jquery/css/smoothness/images/ui-icons_454545_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/jquery/css/smoothness/images/ui-icons_454545_256x240.png -------------------------------------------------------------------------------- /gui/jquery/css/smoothness/images/ui-icons_888888_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/jquery/css/smoothness/images/ui-icons_888888_256x240.png -------------------------------------------------------------------------------- /gui/jquery/css/smoothness/images/ui-icons_cd0a0a_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/jquery/css/smoothness/images/ui-icons_cd0a0a_256x240.png -------------------------------------------------------------------------------- /gui/jquery/css/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/jquery/css/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png -------------------------------------------------------------------------------- /examples/Tutorial/Part_2_03_Samples/AudioSampleCashregister.h: -------------------------------------------------------------------------------- 1 | // Audio data converted from WAV file by wav2sketch 2 | 3 | extern const unsigned int AudioSampleCashregister[5809]; 4 | -------------------------------------------------------------------------------- /examples/Tutorial/Part_3_02_Fourier_Transform/AudioSampleGuitar.h: -------------------------------------------------------------------------------- 1 | // Audio data converted from WAV file by wav2sketch 2 | 3 | extern const unsigned int AudioSampleGuitar[36929]; 4 | -------------------------------------------------------------------------------- /gui/jquery/css/smoothness/images/ui-bg_flat_75_ffffff_40x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/jquery/css/smoothness/images/ui-bg_flat_75_ffffff_40x100.png -------------------------------------------------------------------------------- /gui/jquery/css/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/jquery/css/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png -------------------------------------------------------------------------------- /gui/jquery/css/smoothness/images/ui-bg_glass_65_ffffff_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/jquery/css/smoothness/images/ui-bg_glass_65_ffffff_1x400.png -------------------------------------------------------------------------------- /gui/jquery/css/smoothness/images/ui-bg_glass_75_dadada_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/jquery/css/smoothness/images/ui-bg_glass_75_dadada_1x400.png -------------------------------------------------------------------------------- /gui/jquery/css/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/jquery/css/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png -------------------------------------------------------------------------------- /gui/jquery/css/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/jquery/css/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png -------------------------------------------------------------------------------- /gui/jquery/css/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BleepLabs/Audio/HEAD/gui/jquery/css/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png -------------------------------------------------------------------------------- /examples/Effects/Filter_FIR/filters.cpp: -------------------------------------------------------------------------------- 1 | #include "filters.h" 2 | short low_pass[NUM_COEFFS] = { 3 | #include "lopass_1000_44100.h" 4 | }; 5 | 6 | short band_pass[NUM_COEFFS] = { 7 | #include "bandp_1200_1700.h" 8 | }; 9 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Audio 2 | version=1.3 3 | author=Paul Stoffregen 4 | maintainer=Paul Stoffregen 5 | sentence=Teensy Audio Library - Flexible, High Quality Audio Processing 6 | paragraph=A toolkit for building streaming audio projects, featuring Polyphonic Playback, Recording, Synthesis, Analysis, Effects, Filtering, Mixing, Multiple Simultaneous Inputs & Outputs, Flexible Internal Signal Routing, Automatic Streaming 16 bits, 44.1 kHz as the Arduino Sketch Runs. 7 | category=Signal Input/Output 8 | url=http://www.pjrc.com/teensy/td_libs_Audio.html 9 | architectures=* 10 | 11 | -------------------------------------------------------------------------------- /examples/Tutorial/Part_2_04_Microphone_Check/Part_2_04_Microphone_Check.ino: -------------------------------------------------------------------------------- 1 | // Advanced Microcontroller-based Audio Workshop 2 | // 3 | // Part 2-1: Using the Microphone 4 | 5 | 6 | /////////////////////////////////// 7 | // copy the Design Tool code here 8 | /////////////////////////////////// 9 | 10 | 11 | 12 | 13 | void setup() { 14 | Serial.begin(9600); 15 | AudioMemory(8); 16 | sgtl5000_1.enable(); 17 | sgtl5000_1.volume(0.5); 18 | sgtl5000_1.inputSelect(AUDIO_INPUT_MIC); 19 | sgtl5000_1.micGain(36); 20 | delay(1000); 21 | } 22 | 23 | void loop() { 24 | // do nothing 25 | } 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Audio", 3 | "frameworks": "Arduino", 4 | "platforms": "Teensy", 5 | "keywords": "sound, audio, FFT, filter, effect", 6 | "description": "Teensy Audio Library", 7 | "url": "http://www.pjrc.com/teensy/td_libs_Audio.html", 8 | "version": "1.3", 9 | "export": { 10 | "exclude": [ 11 | "gui", 12 | "extras" 13 | ] 14 | }, 15 | "authors": 16 | { 17 | "name": "Paul Stoffregen", 18 | "maintainer": true 19 | }, 20 | "repository": 21 | { 22 | "type": "git", 23 | "url": "https://github.com/PaulStoffregen/Audio" 24 | }, 25 | "dependencies": 26 | { 27 | "name": "SerialFlash", 28 | "frameworks": "arduino" 29 | }, 30 | "examples": [ 31 | "examples/*/*.ino", 32 | "examples/*/*/*.ino" 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /filter_fir.md: -------------------------------------------------------------------------------- 1 | filter_fir 140418 2 | Filters the audio stream using FIR coefficients supplied by the user. 3 | The ARM library has two q15 functions which perform an FIR filter. One uses 4 | a 64-bit accumulator (arm_fir_q15) and the other uses a 32-bit accumulator 5 | (arm_fir_fast_q15). When instantiating a filter a boolean argument specifies 6 | which version to use. Specifying USE_FAST_FIR (defined as boolean true) uses 7 | the fast code otherwise the slower code is used. For example: 8 | AudioFilterFIR myFilterL(USE_FAST_FIR); 9 | 10 | void begin(short *cp,int n_coeffs) 11 | Starts the filter using coefficients at *cp and the number of coefficients 12 | is n_coeffs. The special value FIR_PASSTHRU can be used in place of the 13 | address of the coefficient array, in which case the function will just pass 14 | audio samples through without filtering. 15 | 16 | void stop(void) 17 | Stops the filter. 18 | 19 | -------------------------------------------------------------------------------- /matrix_mixer.h: -------------------------------------------------------------------------------- 1 | // matrix_mixer.h 2 | 3 | #ifndef matrix_mixer_h_ 4 | #define matrix_mixer_h_ 5 | 6 | #include "Arduino.h" 7 | #include "AudioStream.h" 8 | 9 | class AudioMatrixMixer : public AudioStream 10 | { 11 | 12 | public: 13 | AudioMatrixMixer(void) : AudioStream(4, inputQueueArray) { 14 | /* for (int j = 0; j < 4; j++) { 15 | for (int i = 0; i < 4; i++) { 16 | multiplier[j][i] = 65536; 17 | }*/ 18 | } 19 | virtual void update(void); 20 | 21 | void gain(unsigned int out_sel, unsigned int channel, float gain) { 22 | if (channel >= 4) return; 23 | if (out_sel >= 4) return; 24 | if (gain > 32767.0f) gain = 32767.0f; 25 | else if (gain < -32767.0f) gain = -32767.0f; 26 | multiplier[out_sel][channel] = gain * 255.0f; // TODO: proper roundoff? 27 | } 28 | private: 29 | #define mmax 4 30 | 31 | byte multiplier[mmax][mmax]; 32 | audio_block_t *inputQueueArray[mmax]; 33 | }; 34 | #endif 35 | -------------------------------------------------------------------------------- /gui/red/ui/state.js: -------------------------------------------------------------------------------- 1 | /** Modified from original Node-Red source, for audio system visualization 2 | * vim: set ts=4: 3 | * Copyright 2013 IBM Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **/ 17 | RED.state = { 18 | DEFAULT: 0, 19 | MOVING: 1, 20 | JOINING: 2, 21 | MOVING_ACTIVE: 3, 22 | ADDING: 4, 23 | EDITING: 5, 24 | EXPORT: 6, 25 | IMPORT: 7, 26 | IMPORT_DRAGGING: 8 27 | } 28 | -------------------------------------------------------------------------------- /gui/red/storage.js: -------------------------------------------------------------------------------- 1 | /* public domain 2 | * vim: set ts=4: 3 | */ 4 | 5 | RED.storage = (function() { 6 | function update() { 7 | // TOOD: use setTimeout to limit the rate of changes? 8 | if (localStorage) { 9 | var nns = RED.nodes.createCompleteNodeSet(); 10 | localStorage.setItem("audio_library_guitool", JSON.stringify(nns)); 11 | //console.log("localStorage write"); 12 | } 13 | } 14 | function load() { 15 | if (localStorage) { 16 | var data = localStorage.getItem("audio_library_guitool"); 17 | //console.log("localStorage read: " + data); 18 | if (data) RED.nodes.import(data, false); 19 | } 20 | } 21 | function clear() { 22 | // TOOD: use setTimeout to limit the rate of changes? 23 | if (localStorage) { 24 | localStorage.removeItem("audio_library_guitool"); 25 | //console.log("localStorage write"); 26 | } 27 | } 28 | return { 29 | update: update, 30 | load: load, 31 | clear: clear 32 | } 33 | })(); 34 | -------------------------------------------------------------------------------- /examples/Tutorial/Part_2_01_First_Design_Tool_Use/Part_2_01_First_Design_Tool_Use.ino: -------------------------------------------------------------------------------- 1 | // Advanced Microcontroller-based Audio Workshop 2 | // 3 | // Part 2-1: First Design Tool Use 4 | 5 | /////////////////////////////////// 6 | // copy the Design Tool code here 7 | /////////////////////////////////// 8 | 9 | 10 | 11 | void setup() { 12 | Serial.begin(9600); 13 | AudioMemory(8); 14 | sgtl5000_1.enable(); 15 | sgtl5000_1.volume(0.5); 16 | SPI.setMOSI(7); 17 | SPI.setSCK(14); 18 | if (!(SD.begin(10))) { 19 | while (1) { 20 | Serial.println("Unable to access the SD card"); 21 | delay(500); 22 | } 23 | } 24 | delay(1000); 25 | } 26 | 27 | void loop() { 28 | if (playSdWav1.isPlaying() == false) { 29 | Serial.println("Start playing"); 30 | playSdWav1.play("SDTEST3.WAV"); 31 | delay(10); // wait for library to parse WAV info 32 | } 33 | 34 | // do nothing while playing... 35 | } 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /examples/HardwareTesting/PassThroughMono/PassThroughMono.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * A simple hardware test which receives audio on the A2 analog pin 3 | * and sends it to the PWM (pin 3) output and DAC (A14 pin) output. 4 | * 5 | * This example code is in the public domain. 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | // GUItool: begin automatically generated code 15 | AudioInputAnalog adc1; //xy=161,80 16 | AudioOutputAnalog dac1; //xy=329,47 17 | AudioOutputPWM pwm1; //xy=331,125 18 | AudioConnection patchCord1(adc1, dac1); 19 | AudioConnection patchCord2(adc1, pwm1); 20 | // GUItool: end automatically generated code 21 | 22 | void setup() { 23 | // Audio connections require memory to work. For more 24 | // detailed information, see the MemoryAndCpuUsage example 25 | AudioMemory(12); 26 | } 27 | 28 | void loop() { 29 | // Do nothing here. The Audio flows automatically 30 | 31 | // When AudioInputAnalog is running, analogRead() must NOT be used. 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /examples/Tutorial/Part_2_06_Feedback_Delay/Part_2_06_Feedback_Delay.ino: -------------------------------------------------------------------------------- 1 | // Advanced Microcontroller-based Audio Workshop 2 | // 3 | // Part 2-6: Feedback (Echo) Delay 4 | 5 | 6 | 7 | /////////////////////////////////// 8 | // copy the Design Tool code here 9 | /////////////////////////////////// 10 | 11 | 12 | 13 | 14 | #include 15 | 16 | Bounce button0 = Bounce(0, 5); 17 | 18 | void setup() { 19 | Serial.begin(9600); 20 | pinMode(0, INPUT_PULLUP); 21 | AudioMemory(160); 22 | sgtl5000_1.enable(); 23 | sgtl5000_1.volume(0.55); 24 | sgtl5000_1.inputSelect(AUDIO_INPUT_MIC); 25 | sgtl5000_1.micGain(36); 26 | mixer1.gain(0, 0.5); 27 | mixer1.gain(3, 0.7); 28 | delay1.delay(0, 400); 29 | delay(1000); 30 | } 31 | 32 | void loop() { 33 | // uncomment for A3 knob to control the feedback level 34 | /* 35 | int knob = analogRead(A3); 36 | float feedback = (float)knob / 1050.0; 37 | mixer1.gain(3, feedback); 38 | */ 39 | 40 | // uncomment for pin 0 button to double the feedback (allowing unstable) 41 | /* 42 | button0.update(); 43 | if (button0.read() == LOW) { 44 | mixer1.gain(3, feedback * 2.0); 45 | } 46 | */ 47 | } 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /examples/Tutorial/Part_2_05_Simple_Delay/Part_2_05_Simple_Delay.ino: -------------------------------------------------------------------------------- 1 | // Advanced Microcontroller-based Audio Workshop 2 | // 3 | // Part 2-5: Simple Delay 4 | 5 | /////////////////////////////////// 6 | // copy the Design Tool code here 7 | /////////////////////////////////// 8 | 9 | 10 | 11 | 12 | 13 | void setup() { 14 | Serial.begin(9600); 15 | AudioMemory(160); 16 | sgtl5000_1.enable(); 17 | sgtl5000_1.volume(0.6); 18 | sgtl5000_1.inputSelect(AUDIO_INPUT_MIC); 19 | sgtl5000_1.micGain(36); 20 | mixer1.gain(0, 0.2); 21 | mixer1.gain(1, 0.2); 22 | mixer1.gain(2, 0.2); 23 | mixer1.gain(3, 0.2); 24 | mixer2.gain(0, 0.2); 25 | mixer2.gain(1, 0.2); 26 | mixer2.gain(2, 0.2); 27 | mixer2.gain(3, 0.2); 28 | mixer3.gain(0, 0.0); // default = do not listen to direct signal 29 | mixer3.gain(1, 1.0); // ch1 is output of mixer1 30 | mixer3.gain(2, 1.0); // ch2 is output of mixer2 31 | delay1.delay(0, 400); 32 | delay1.delay(1, 400); 33 | delay1.delay(2, 400); 34 | delay1.delay(3, 400); 35 | delay1.delay(4, 400); 36 | delay1.delay(5, 400); 37 | delay1.delay(6, 400); 38 | delay1.delay(7, 400); 39 | delay(1000); 40 | } 41 | 42 | void loop() { 43 | // do nothing 44 | } 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /effect_sh.h: -------------------------------------------------------------------------------- 1 | #ifndef effect_sh_h_ 2 | #define effect_sh_h_ 3 | #include "AudioStream.h" 4 | #include "utility/dspinst.h" 5 | 6 | class AudioEffectSH : public AudioStream 7 | { 8 | public: 9 | AudioEffectSH() : AudioStream(2, inputQueueArray) { } 10 | 11 | 12 | virtual void update(void); 13 | void begin(float rr_amt,short sm){ 14 | smooth(sm); 15 | amount(rr_amt); 16 | } 17 | 18 | void smooth(short sm) { 19 | smooth_en=sm; 20 | } 21 | 22 | void manual_hold(short mh) { 23 | manual_hold_en=mh; 24 | } 25 | 26 | void amount(float rr_amt) { 27 | 28 | 29 | 30 | if (rr_amt>0){ 31 | float a3t = rr_amt * rr_amt ; //pow doesn't work here? 32 | rate_reduction_amt =rr_amt* (65536.0f); 33 | //rate_reduction_amt =rr_amt* (65536.0f); 34 | 35 | } 36 | if (rr_amt<=0){ 37 | rate_reduction_amt=0; 38 | } 39 | 40 | 41 | } 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | private: 50 | audio_block_t *inputQueueArray[2]; 51 | uint32_t rate_reduction_amt; 52 | int32_t mix; 53 | int32_t mix_inv; 54 | short smooth_en ; 55 | short manual_hold_en; 56 | 57 | 58 | }; 59 | 60 | #endif -------------------------------------------------------------------------------- /examples/Effects/Filter/Filter.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | // GUItool: begin automatically generated code 8 | AudioInputI2S i2s1; //xy=99,60 9 | AudioFilterBiquad biquad1; //xy=257,60 10 | AudioOutputI2S i2s2; //xy=416,60 11 | AudioConnection patchCord1(i2s1, 0, biquad1, 0); 12 | AudioConnection patchCord2(biquad1, 0, i2s2, 0); 13 | AudioConnection patchCord3(biquad1, 0, i2s2, 1); 14 | AudioControlSGTL5000 sgtl5000_1; //xy=305,132 15 | // GUItool: end automatically generated code 16 | 17 | 18 | const int myInput = AUDIO_INPUT_LINEIN; 19 | //const int myInput = AUDIO_INPUT_MIC; 20 | 21 | void setup() { 22 | AudioMemory(12); 23 | 24 | sgtl5000_1.enable(); // Enable the audio shield 25 | sgtl5000_1.inputSelect(myInput); 26 | sgtl5000_1.volume(0.5); 27 | 28 | // Butterworth filter, 12 db/octave 29 | biquad1.setLowpass(0, 800, 0.707); 30 | 31 | // Linkwitz-Riley filter, 48 dB/octave 32 | //biquad1.setLowpass(0, 800, 0.54); 33 | //biquad1.setLowpass(1, 800, 1.3); 34 | //biquad1.setLowpass(2, 800, 0.54); 35 | //biquad1.setLowpass(3, 800, 1.3); 36 | } 37 | 38 | 39 | void loop() { 40 | } 41 | 42 | 43 | -------------------------------------------------------------------------------- /examples/Tutorial/Part_1_03_Playing_Music/Part_1_03_Playing_Music.ino: -------------------------------------------------------------------------------- 1 | // Advanced Microcontroller-based Audio Workshop 2 | // 3 | // Part 1-3: First "Hello World" program, play a music file 4 | // 5 | // WAV files for this and other Tutorials are here: 6 | // http://www.pjrc.com/teensy/td_libs_AudioDataFiles.html 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | AudioPlaySdWav playSdWav1; 15 | AudioOutputI2S i2s1; 16 | AudioConnection patchCord1(playSdWav1, 0, i2s1, 0); 17 | AudioConnection patchCord2(playSdWav1, 1, i2s1, 1); 18 | AudioControlSGTL5000 sgtl5000_1; 19 | 20 | void setup() { 21 | Serial.begin(9600); 22 | AudioMemory(8); 23 | sgtl5000_1.enable(); 24 | sgtl5000_1.volume(0.5); 25 | SPI.setMOSI(7); 26 | SPI.setSCK(14); 27 | if (!(SD.begin(10))) { 28 | while (1) { 29 | Serial.println("Unable to access the SD card"); 30 | delay(500); 31 | } 32 | } 33 | delay(1000); 34 | } 35 | 36 | void loop() { 37 | if (playSdWav1.isPlaying() == false) { 38 | Serial.println("Start playing"); 39 | playSdWav1.play("SDTEST2.WAV"); 40 | delay(10); // wait for library to parse WAV info 41 | } 42 | // do nothing while playing... 43 | } 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /gui/jquery/js/jquery.ui.touch-punch.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * jQuery UI Touch Punch 0.2.3 3 | * 4 | * Copyright 2011–2014, Dave Furfero 5 | * Dual licensed under the MIT or GPL Version 2 licenses. 6 | * 7 | * Depends: 8 | * jquery.ui.widget.js 9 | * jquery.ui.mouse.js 10 | */ 11 | !function(a){function f(a,b){if(!(a.originalEvent.touches.length>1)){a.preventDefault();var c=a.originalEvent.changedTouches[0],d=document.createEvent("MouseEvents");d.initMouseEvent(b,!0,!0,window,1,c.screenX,c.screenY,c.clientX,c.clientY,!1,!1,!1,!1,0,null),a.target.dispatchEvent(d)}}if(a.support.touch="ontouchend"in document,a.support.touch){var e,b=a.ui.mouse.prototype,c=b._mouseInit,d=b._mouseDestroy;b._touchStart=function(a){var b=this;!e&&b._mouseCapture(a.originalEvent.changedTouches[0])&&(e=!0,b._touchMoved=!1,f(a,"mouseover"),f(a,"mousemove"),f(a,"mousedown"))},b._touchMove=function(a){e&&(this._touchMoved=!0,f(a,"mousemove"))},b._touchEnd=function(a){e&&(f(a,"mouseup"),f(a,"mouseout"),this._touchMoved||f(a,"click"),e=!1)},b._mouseInit=function(){var b=this;b.element.bind({touchstart:a.proxy(b,"_touchStart"),touchmove:a.proxy(b,"_touchMove"),touchend:a.proxy(b,"_touchEnd")}),c.call(b)},b._mouseDestroy=function(){var b=this;b.element.unbind({touchstart:a.proxy(b,"_touchStart"),touchmove:a.proxy(b,"_touchMove"),touchend:a.proxy(b,"_touchEnd")}),d.call(b)}}}(jQuery); -------------------------------------------------------------------------------- /examples/Analysis/PeakMeterMono/PeakMeterMono.ino: -------------------------------------------------------------------------------- 1 | /* Mono Peak Meter 2 | 3 | Scrolling peak audio level meter in the Arduino Serial Monitor 4 | 5 | Audio input needs to connect to pin 16 (A2). The signal range is 0 to 1.2V. 6 | See the documentation in the Audio System Design Tool for the recommended 7 | circuit to connect an analog signal. 8 | 9 | This example code is in the public domain 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | // GUItool: begin automatically generated code 19 | AudioInputAnalog adc1; //xy=164,95 20 | AudioAnalyzePeak peak1; //xy=317,123 21 | AudioConnection patchCord1(adc1, peak1); 22 | // GUItool: end automatically generated code 23 | 24 | 25 | void setup() { 26 | AudioMemory(4); 27 | Serial.begin(9600); 28 | } 29 | 30 | // for best effect make your terminal/monitor a minimum of 31 chars wide and as high as you can. 31 | 32 | elapsedMillis fps; 33 | 34 | void loop() { 35 | if (fps > 24) { 36 | if (peak1.available()) { 37 | fps = 0; 38 | int monoPeak = peak1.read() * 30.0; 39 | Serial.print("|"); 40 | for (int cnt=0; cnt"); 42 | } 43 | Serial.println(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /examples/Synthesis/pulseWidth/pulseWidth.ino: -------------------------------------------------------------------------------- 1 | 2 | // demonstrate pulse with slow changes in pulse width 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | // GUItool: begin automatically generated code 11 | AudioSynthWaveform waveform1; //xy=188,240 12 | AudioEffectEnvelope envelope1; //xy=371,237 13 | AudioOutputI2S i2s1; //xy=565,241 14 | AudioConnection patchCord1(waveform1, envelope1); 15 | AudioConnection patchCord2(envelope1, 0, i2s1, 0); 16 | AudioConnection patchCord3(envelope1, 0, i2s1, 1); 17 | AudioControlSGTL5000 audioShield; //xy=586,175 18 | // GUItool: end automatically generated code 19 | 20 | 21 | void setup(void) 22 | { 23 | 24 | // Set up 25 | AudioMemory(8); 26 | audioShield.enable(); 27 | audioShield.volume(0.45); 28 | 29 | waveform1.pulseWidth(0.5); 30 | waveform1.begin(0.4, 220, WAVEFORM_PULSE); 31 | 32 | envelope1.attack(50); 33 | envelope1.decay(50); 34 | envelope1.release(250); 35 | 36 | } 37 | 38 | void loop() { 39 | 40 | float w; 41 | for (uint32_t i =1; i<20; i++) { 42 | w = i / 20.0; 43 | waveform1.pulseWidth(w); 44 | envelope1.noteOn(); 45 | delay(800); 46 | envelope1.noteOff(); 47 | delay(600); 48 | } 49 | } 50 | 51 | 52 | -------------------------------------------------------------------------------- /examples/HardwareTesting/WM8731MikroSine/WM8731MikroSine.ino: -------------------------------------------------------------------------------- 1 | // Simple sine wave test for WM8731 Audio Codec Board 2 | // 3 | // Requires the MikroElektronika Audio Codec board or similar hardware 4 | // http://www.mikroe.com/add-on-boards/audio-voice/audio-codec-proto/ 5 | // 6 | // Recommended connections: 7 | // 8 | // Mikroe Teensy 3.1 9 | // ------ ---------- 10 | // SCK 9 11 | // MISO 13 12 | // MOSI 22 13 | // ADCL 14 | // DACL 23 15 | // SDA 18 16 | // SCL 19 17 | // 3.3V +3.3V 18 | // GND GND 19 | // 20 | // This example code is in the public domain. 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | // GUItool: begin automatically generated code 29 | AudioSynthWaveform waveform1; //xy=110,75 30 | AudioOutputI2Sslave i2ss1; //xy=303,78 31 | AudioConnection patchCord1(waveform1, 0, i2ss1, 0); 32 | AudioConnection patchCord2(waveform1, 0, i2ss1, 1); 33 | AudioControlWM8731master wm8731m1; //xy=230,154 34 | // GUItool: end automatically generated code 35 | 36 | 37 | void setup() { 38 | wm8731m1.enable(); 39 | 40 | AudioMemory(15); 41 | 42 | waveform1.begin(WAVEFORM_SINE); 43 | waveform1.frequency(440); 44 | waveform1.amplitude(0.9); 45 | 46 | wm8731m1.volume(0.50); 47 | } 48 | 49 | 50 | void loop() { 51 | } 52 | -------------------------------------------------------------------------------- /examples/HardwareTesting/PassThroughStereo/PassThroughStereo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * A simple hardware test which receives audio from the audio shield 3 | * Line-In pins and send it to the Line-Out pins and headphone jack. 4 | * 5 | * This example code is in the public domain. 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | // GUItool: begin automatically generated code 15 | AudioInputI2S i2s1; //xy=200,69 16 | AudioOutputI2S i2s2; //xy=365,94 17 | AudioConnection patchCord1(i2s1, 0, i2s2, 0); 18 | AudioConnection patchCord2(i2s1, 1, i2s2, 1); 19 | AudioControlSGTL5000 sgtl5000_1; //xy=302,184 20 | // GUItool: end automatically generated code 21 | 22 | 23 | const int myInput = AUDIO_INPUT_LINEIN; 24 | //const int myInput = AUDIO_INPUT_MIC; 25 | 26 | 27 | void setup() { 28 | // Audio connections require memory to work. For more 29 | // detailed information, see the MemoryAndCpuUsage example 30 | AudioMemory(12); 31 | 32 | // Enable the audio shield, select input, and enable output 33 | sgtl5000_1.enable(); 34 | sgtl5000_1.inputSelect(myInput); 35 | sgtl5000_1.volume(0.5); 36 | } 37 | 38 | elapsedMillis volmsec=0; 39 | 40 | void loop() { 41 | // every 50 ms, adjust the volume 42 | if (volmsec > 50) { 43 | float vol = analogRead(15); 44 | vol = vol / 1023.0; 45 | //audioShield.volume(vol); // <-- uncomment if you have the optional 46 | volmsec = 0; // volume pot on your audio shield 47 | } 48 | } 49 | 50 | 51 | -------------------------------------------------------------------------------- /examples/Tutorial/Part_2_02_Mixers/Part_2_02_Mixers.ino: -------------------------------------------------------------------------------- 1 | // Advanced Microcontroller-based Audio Workshop 2 | // 3 | // Part 2-2: Mixers & Playing Multiple Sounds 4 | 5 | /////////////////////////////////// 6 | // copy the Design Tool code here 7 | /////////////////////////////////// 8 | 9 | 10 | 11 | 12 | void setup() { 13 | Serial.begin(9600); 14 | AudioMemory(8); 15 | sgtl5000_1.enable(); 16 | sgtl5000_1.volume(0.5); 17 | SPI.setMOSI(7); 18 | SPI.setSCK(14); 19 | if (!(SD.begin(10))) { 20 | while (1) { 21 | Serial.println("Unable to access the SD card"); 22 | delay(500); 23 | } 24 | } 25 | pinMode(13, OUTPUT); // LED on pin 13 26 | mixer1.gain(0, 0.5); 27 | mixer1.gain(1, 0.5); 28 | mixer2.gain(0, 0.5); 29 | mixer2.gain(1, 0.5); 30 | delay(1000); 31 | } 32 | 33 | void loop() { 34 | if (playSdWav1.isPlaying() == false) { 35 | Serial.println("Start playing 1"); 36 | playSdWav1.play("SDTEST1.WAV"); 37 | delay(10); // wait for library to parse WAV info 38 | } 39 | if (playSdWav2.isPlaying() == false) { 40 | Serial.println("Start playing 2"); 41 | playSdWav2.play("SDTEST4.WAV"); 42 | delay(10); // wait for library to parse WAV info 43 | } 44 | // uncomment this code to allow Knob A3 to pan between songs 45 | /* 46 | int knob = analogRead(A3); // knob = 0 to 1023 47 | float gain1 = (float)knob / 1023.0; 48 | float gain2 = 1.0 - gain1; 49 | mixer1.gain(0, gain1); 50 | mixer1.gain(1, gain2); 51 | mixer2.gain(0, gain1); 52 | mixer2.gain(1, gain2); 53 | */ 54 | } 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /spi_interrupt.cpp: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #include 28 | #include "spi_interrupt.h" 29 | 30 | #ifdef SPI_HAS_NOTUSINGINTERRUPT 31 | 32 | unsigned short AudioUsingSPICount = 0; 33 | 34 | #endif 35 | 36 | -------------------------------------------------------------------------------- /effect_waveshaper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Waveshaper for Teensy 3.X audio 3 | * 4 | * Copyright (c) 2017 Damien Clarke, http://damienclarke.me 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef effect_waveshaper_h_ 26 | #define effect_waveshaper_h_ 27 | 28 | #include "Arduino.h" 29 | #include "AudioStream.h" 30 | 31 | class AudioEffectWaveshaper : public AudioStream 32 | { 33 | public: 34 | AudioEffectWaveshaper(void): AudioStream(1, inputQueueArray) {} 35 | ~AudioEffectWaveshaper(); 36 | virtual void update(void); 37 | void shape(float* waveshape, int length); 38 | private: 39 | audio_block_t *inputQueueArray[1]; 40 | int16_t* waveshape; 41 | int16_t lerpshift; 42 | }; 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /synth_waveform.md: -------------------------------------------------------------------------------- 1 | synth_waveform 140404 2 | This synthesizes a waveform of the specified type with a given amplitude 3 | and frequency. There are currently four types of waveform: 4 | #define TONE_TYPE_SINE 0 5 | #define TONE_TYPE_SAWTOOTH 1 6 | #define TONE_TYPE_SQUARE 2 7 | #define TONE_TYPE_TRIANGLE 3 8 | Sine wave generation uses a lookup table and linear interpolation. 9 | The other three waveforms are generated directly without using table lookup. 10 | 11 | boolean begin(float t_amp,float t_freq,short t_type) 12 | This starts generation of a waveform of given type, amplitude and frequency 13 | Example: begin(0.8,440.0,TONE_TYPE_SINE) 14 | 15 | void set_ramp_length(int16_t r_length) 16 | When a tone starts, or ends, playing it can generate an audible "thump" which can 17 | be very distracting, especially when playing musical notes. This function specifies 18 | a "ramp" length (in number of samples) and the beginning of the generated waveform 19 | will be ramped up in volume from zero to t_amp over the course of r_length samples. 20 | When the tone is switched off, by changing its volume to zero, instead of ending 21 | abruptly it will be ramped down to zero over the next r_length samples. 22 | For example, if r_length is 44, the beginning and end of the wave will have a ramp 23 | of approximately one millisecond. 24 | 25 | void frequency(float t_freq) 26 | Changes the frequency of the wave to the specified t_freq. This is done in a phase- 27 | continuous manner which should allow generation of audio frequency shift keying and 28 | other effects requiring a changing frequency. 29 | If the frequency is set to zero sample generation is stopped. 30 | 31 | void amplitude(float n) 32 | Changes the amplitude to 'n'. If 'n' is zero the wave is turned off and any further 33 | audio output will be zero. 34 | 35 | 36 | -------------------------------------------------------------------------------- /examples/Analysis/PeakMeterStereo/PeakMeterStereo.ino: -------------------------------------------------------------------------------- 1 | /* Stereo peak meter example, assumes Audio adapter but just uses terminal so no more parts required. 2 | 3 | This example code is in the public domain 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | const int myInput = AUDIO_INPUT_LINEIN; 13 | // const int myInput = AUDIO_INPUT_MIC; 14 | 15 | AudioInputI2S audioInput; // audio shield: mic or line-in 16 | AudioAnalyzePeak peak_L; 17 | AudioAnalyzePeak peak_R; 18 | AudioOutputI2S audioOutput; // audio shield: headphones & line-out 19 | 20 | AudioConnection c1(audioInput,0,peak_L,0); 21 | AudioConnection c2(audioInput,1,peak_R,0); 22 | AudioConnection c3(audioInput,0,audioOutput,0); 23 | AudioConnection c4(audioInput,1,audioOutput,1); 24 | 25 | AudioControlSGTL5000 audioShield; 26 | 27 | 28 | void setup() { 29 | AudioMemory(6); 30 | audioShield.enable(); 31 | audioShield.inputSelect(myInput); 32 | audioShield.volume(0.5); 33 | Serial.begin(9600); 34 | } 35 | 36 | // for best effect make your terminal/monitor a minimum of 62 chars wide and as high as you can. 37 | 38 | elapsedMillis fps; 39 | uint8_t cnt=0; 40 | 41 | void loop() { 42 | if(fps > 24) { 43 | if (peak_L.available() && peak_R.available()) { 44 | fps=0; 45 | uint8_t leftPeak=peak_L.read() * 30.0; 46 | uint8_t rightPeak=peak_R.read() * 30.0; 47 | 48 | for(cnt=0;cnt<30-leftPeak;cnt++) { 49 | Serial.print(" "); 50 | } 51 | while(cnt++<30) { 52 | Serial.print("<"); 53 | } 54 | Serial.print("||"); 55 | for(cnt=0;cnt"); 57 | } 58 | while(cnt++<30) { 59 | Serial.print(" "); 60 | } 61 | Serial.println(); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /effect_multiply.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef effect_multiply_h_ 28 | #define effect_multiply_h_ 29 | #include "Arduino.h" 30 | #include "AudioStream.h" 31 | #include "utility/dspinst.h" 32 | 33 | class AudioEffectMultiply : public AudioStream 34 | { 35 | public: 36 | AudioEffectMultiply() : AudioStream(2, inputQueueArray) { } 37 | virtual void update(void); 38 | private: 39 | audio_block_t *inputQueueArray[2]; 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /examples/HardwareTesting/SGTL5000/balanceHP/balanceHP.ino: -------------------------------------------------------------------------------- 1 | /* HP balance example: Will influence only HP output. 2 | 3 | This example code is in the public domain 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | const int myInput = AUDIO_INPUT_LINEIN; 13 | // const int myInput = AUDIO_INPUT_MIC; 14 | 15 | // Create the Audio components. These should be created in the 16 | // order data flows, inputs/sources -> processing -> outputs 17 | // 18 | 19 | AudioInputI2S audioInput; // audio shield: mic or line-in 20 | AudioOutputI2S audioOutput; // audio shield: headphones & line-out 21 | 22 | // Create Audio connections between the components 23 | 24 | // Just connecting in to out 25 | AudioConnection c1(audioInput, 0, audioOutput, 0); // left connection 26 | AudioConnection c2(audioInput, 1, audioOutput, 1); // right connection 27 | 28 | // Create an object to control the audio shield. 29 | // 30 | AudioControlSGTL5000 audioShield; 31 | 32 | void setup() { 33 | // Audio connections require memory to work. For more 34 | // detailed information, see the MemoryAndCpuUsage example 35 | AudioMemory(4); 36 | // Enable the audio shield and set the output volume. 37 | audioShield.enable(); 38 | audioShield.inputSelect(myInput); 39 | audioShield.volume(0.5); 40 | } 41 | 42 | elapsedMillis chgMsec=0; 43 | 44 | float lastBal=1024; 45 | float vol1=0.75; 46 | 47 | void loop() { 48 | // every 10 ms, check for adjustment 49 | if (chgMsec > 10) { 50 | float bal1=analogRead(15); 51 | bal1=((bal1-512)/512); 52 | bal1=(int)bal1; 53 | if(lastBal!=bal1) 54 | { 55 | if(bal1<0) 56 | { 57 | audioShield.volume(vol1,vol1*(1+bal1)); 58 | } else { 59 | audioShield.volume(vol1*(1-bal1),vol1); 60 | } 61 | lastBal=bal1; 62 | } 63 | chgMsec = 0; 64 | } 65 | } 66 | 67 | -------------------------------------------------------------------------------- /utility/imxrt_hw.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2019, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | /* 27 | (c) Frank B 28 | */ 29 | 30 | #if defined(__IMXRT1062__) 31 | 32 | #ifndef imxr_hw_h_ 33 | #define imxr_hw_h_ 34 | 35 | #define IMXRT_CACHE_ENABLED 2 // 0=disabled, 1=WT, 2= WB 36 | 37 | #include 38 | #include 39 | 40 | void set_audioClock(int nfact, int32_t nmult, uint32_t ndiv, bool force = false); // sets PLL4 41 | 42 | #endif 43 | 44 | #else 45 | //No IMXRT 46 | #define IMXRT_CACHE_ENABLED 0 47 | #endif 48 | 49 | -------------------------------------------------------------------------------- /examples/HardwareTesting/ToneSweep/ToneSweep.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Demo of the audio sweep function. 3 | The user specifies the amplitude, 4 | start and end frequencies (which can sweep up or down) 5 | and the length of time of the sweep. 6 | 7 | FMI: 8 | The audio board uses the following pins. 9 | 6 - MEMCS 10 | 7 - MOSI 11 | 9 - BCLK 12 | 10 - SDCS 13 | 11 - MCLK 14 | 12 - MISO 15 | 13 - RX 16 | 14 - SCLK 17 | 15 - VOL 18 | 18 - SDA 19 | 19 - SCL 20 | 22 - TX 21 | 23 - LRCLK 22 | 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | AudioSynthToneSweep myEffect; 33 | AudioOutputI2S audioOutput; // audio shield: headphones & line-out 34 | 35 | // The tone sweep goes to left and right channels 36 | AudioConnection c1(myEffect, 0, audioOutput, 0); 37 | AudioConnection c2(myEffect, 0, audioOutput, 1); 38 | 39 | AudioControlSGTL5000 audioShield; 40 | 41 | 42 | float t_ampx = 0.8; 43 | int t_lox = 10; 44 | int t_hix = 22000; 45 | // Length of time for the sweep in seconds 46 | float t_timex = 10; 47 | // <<<<<<<<<<<<<<>>>>>>>>>>>>>>>> 48 | void setup(void) 49 | { 50 | 51 | Serial.begin(9600); 52 | while (!Serial) ; 53 | delay(3000); 54 | 55 | AudioMemory(2); 56 | 57 | audioShield.enable(); 58 | audioShield.volume(0.5); 59 | 60 | Serial.println("setup done"); 61 | 62 | if(!myEffect.play(t_ampx,t_lox,t_hix,t_timex)) { 63 | Serial.println("AudioSynthToneSweep - begin failed"); 64 | while(1); 65 | } 66 | // wait for the sweep to end 67 | while(myEffect.isPlaying()); 68 | 69 | // and now reverse the sweep 70 | if(!myEffect.play(t_ampx,t_hix,t_lox,t_timex)) { 71 | Serial.println("AudioSynthToneSweep - begin failed"); 72 | while(1); 73 | } 74 | // wait for the sweep to end 75 | while(myEffect.isPlaying()); 76 | Serial.println("Done"); 77 | } 78 | 79 | void loop(void) 80 | { 81 | } 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /examples/Tutorial/Part_3_01_Peak_Detection/Part_3_01_Peak_Detection.ino: -------------------------------------------------------------------------------- 1 | // Advanced Microcontroller-based Audio Workshop 2 | // 3 | // Part 3-1: Peak Detection 4 | 5 | 6 | /////////////////////////////////// 7 | // copy the Design Tool code here 8 | /////////////////////////////////// 9 | 10 | 11 | 12 | 13 | void setup() { 14 | Serial.begin(9600); 15 | AudioMemory(10); 16 | sgtl5000_1.enable(); 17 | sgtl5000_1.volume(0.5); 18 | SPI.setMOSI(7); 19 | SPI.setSCK(14); 20 | if (!(SD.begin(10))) { 21 | while (1) { 22 | Serial.println("Unable to access the SD card"); 23 | delay(500); 24 | } 25 | } 26 | delay(1000); 27 | } 28 | 29 | // for best effect make your terminal/monitor a minimum of 62 chars wide and as high as you can. 30 | 31 | elapsedMillis msecs; 32 | 33 | void loop() { 34 | if (playSdWav1.isPlaying() == false) { 35 | Serial.println("Start playing"); 36 | //playSdWav1.play("SDTEST1.WAV"); 37 | playSdWav1.play("SDTEST2.WAV"); 38 | //playSdWav1.play("SDTEST3.WAV"); 39 | //playSdWav1.play("SDTEST4.WAV"); 40 | delay(10); // wait for library to parse WAV info 41 | } 42 | 43 | if (msecs > 40) { 44 | if (peak1.available() && peak2.available()) { 45 | msecs = 0; 46 | float leftNumber = peak1.read(); 47 | float rightNumber = peak2.read(); 48 | int leftPeak = leftNumber * 30.0; 49 | int rightPeak = rightNumber * 30.0; 50 | int count; 51 | for (count=0; count < 30-leftPeak; count++) { 52 | Serial.print(" "); 53 | } 54 | while (count++ < 30) { 55 | Serial.print("<"); 56 | } 57 | Serial.print("||"); 58 | for (count=0; count < rightPeak; count++) { 59 | Serial.print(">"); 60 | } 61 | while (count++ < 30) { 62 | Serial.print(" "); 63 | } 64 | Serial.print(leftNumber); 65 | Serial.print(", "); 66 | Serial.print(rightNumber); 67 | Serial.println(); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /examples/HardwareTesting/SGTL5000/balanceDAC/balanceDAC.ino: -------------------------------------------------------------------------------- 1 | /* DAC balance example: Will influence both HP & LO outputs. 2 | 3 | This example code is in the public domain 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | const int myInput = AUDIO_INPUT_LINEIN; 14 | // const int myInput = AUDIO_INPUT_MIC; 15 | 16 | // Create the Audio components. These should be created in the 17 | // order data flows, inputs/sources -> processing -> outputs 18 | // 19 | 20 | AudioInputI2S audioInput; // audio shield: mic or line-in 21 | AudioOutputI2S audioOutput; // audio shield: headphones & line-out 22 | 23 | // Create Audio connections between the components 24 | // 25 | AudioConnection c1(audioInput, 0, audioOutput, 0); // left passing through 26 | AudioConnection c2(audioInput, 1, audioOutput, 1); // right passing through 27 | 28 | // Create an object to control the audio shield. 29 | // 30 | AudioControlSGTL5000 audioShield; 31 | 32 | void setup() { 33 | // Audio connections require memory to work. For more 34 | // detailed information, see the MemoryAndCpuUsage example 35 | AudioMemory(4); 36 | // Enable the audio shield and set the output volume. 37 | audioShield.enable(); 38 | audioShield.inputSelect(myInput); 39 | audioShield.volume(0.5); 40 | } 41 | 42 | elapsedMillis chgMsec=0; 43 | float lastBal=1024; 44 | 45 | void loop() { 46 | // every 10 ms, check for adjustment 47 | if (chgMsec > 10) { 48 | float bal1=analogRead(15); 49 | bal1=((bal1-512)/512); 50 | bal1=(int)bal1; 51 | if(lastBal!=bal1) 52 | { 53 | if(bal1<0) 54 | { // leaning toward left... 55 | audioShield.dacVolume(1,1+bal1); 56 | } else if(bal1>0) { // to the right 57 | audioShield.dacVolume(1-bal1,1); 58 | } else { // middle 59 | audioShield.dacVolume(1); 60 | } 61 | lastBal=bal1; 62 | } 63 | chgMsec = 0; 64 | } 65 | } 66 | 67 | -------------------------------------------------------------------------------- /gui/red/ui/notifications.js: -------------------------------------------------------------------------------- 1 | /** Modified from original Node-Red source, for audio system visualization 2 | * vim: set ts=4: 3 | * Copyright 2013 IBM Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **/ 17 | RED.notify = (function() { 18 | var currentNotifications = []; 19 | var c = 0; 20 | return function(msg,type,fixed,timeout) { 21 | if (currentNotifications.length > 4) { 22 | var ll = currentNotifications.length; 23 | for (var i = 0;ll > 4 && i 24 | #include "filter_fir.h" 25 | 26 | 27 | void AudioFilterFIR::update(void) 28 | { 29 | audio_block_t *block, *b_new; 30 | 31 | block = receiveReadOnly(); 32 | if (!block) return; 33 | 34 | // If there's no coefficient table, give up. 35 | if (coeff_p == NULL) { 36 | release(block); 37 | return; 38 | } 39 | 40 | // do passthru 41 | if (coeff_p == FIR_PASSTHRU) { 42 | // Just passthrough 43 | transmit(block); 44 | release(block); 45 | return; 46 | } 47 | 48 | // get a block for the FIR output 49 | b_new = allocate(); 50 | if (b_new) { 51 | arm_fir_fast_q15(&fir_inst, (q15_t *)block->data, 52 | (q15_t *)b_new->data, AUDIO_BLOCK_SAMPLES); 53 | transmit(b_new); // send the FIR output 54 | release(b_new); 55 | } 56 | release(block); 57 | } 58 | 59 | 60 | -------------------------------------------------------------------------------- /input_tdm.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2017, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef _input_tdm_h_ 28 | #define _input_tdm_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | #include "DMAChannel.h" 33 | 34 | class AudioInputTDM : public AudioStream 35 | { 36 | public: 37 | AudioInputTDM(void) : AudioStream(0, NULL) { begin(); } 38 | virtual void update(void); 39 | void begin(void); 40 | protected: 41 | static bool update_responsibility; 42 | static DMAChannel dma; 43 | static void isr(void); 44 | private: 45 | static audio_block_t *block_incoming[16]; 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /memcpy_audio.h: -------------------------------------------------------------------------------- 1 | /* Teensyduino Audio Memcpy 2 | * Copyright (c) 2016 Frank Bösing 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * 1. The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * 2. If the Software is incorporated into a build system that allows 16 | * selection among a list of target devices, then similar target 17 | * devices manufactured by PJRC.COM must be included in the list of 18 | * target devices and selectable in the same manner. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 24 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 25 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 26 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 | * SOFTWARE. 28 | */ 29 | 30 | #ifndef memcpy_audio_h_ 31 | #define memcpy_audio_h_ 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | void memcpy_tointerleaveLR(int16_t *dst, const int16_t *srcL, const int16_t *srcR); 37 | void memcpy_tointerleaveL(int16_t *dst, const int16_t *srcL); 38 | void memcpy_tointerleaveR(int16_t *dst, const int16_t *srcR); 39 | void memcpy_tointerleaveQuad(int16_t *dst, const int16_t *src1, const int16_t *src2, 40 | const int16_t *src3, const int16_t *src4); 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /analyze_rms.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef analyze_rms_h_ 28 | #define analyze_rms_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | 33 | class AudioAnalyzeRMS : public AudioStream 34 | { 35 | private: 36 | audio_block_t *inputQueueArray[1]; 37 | int64_t accum; 38 | uint32_t count; 39 | 40 | public: 41 | AudioAnalyzeRMS(void) : AudioStream(1, inputQueueArray) { 42 | accum = 0; 43 | count = 0; 44 | } 45 | bool available(void) { 46 | return count > 0; 47 | } 48 | float read(void); 49 | virtual void update(void); 50 | }; 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /examples/Tutorial/Part_1_04_Blink_While_Playing/Part_1_04_Blink_While_Playing.ino: -------------------------------------------------------------------------------- 1 | // Advanced Microcontroller-based Audio Workshop 2 | // 3 | // Part 1-4: Blink LED while Playing Music 4 | // 5 | // Do something while playing a music file. Admittedly 6 | // only blink Teensy's LED and print info about the 7 | // playing time in the file. The point is that Arduino 8 | // sketch code is free to do other work while the audio 9 | // library streams data from the SD card to the headphones. 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | AudioPlaySdWav playSdWav1; 18 | AudioOutputI2S audioOutput; 19 | AudioConnection patchCord1(playSdWav1, 0, audioOutput, 0); 20 | AudioConnection patchCord2(playSdWav1, 1, audioOutput, 1); 21 | AudioControlSGTL5000 sgtl5000_1; 22 | 23 | void setup() { 24 | Serial.begin(9600); 25 | AudioMemory(8); 26 | sgtl5000_1.enable(); 27 | sgtl5000_1.volume(0.45); 28 | SPI.setMOSI(7); 29 | SPI.setSCK(14); 30 | if (!(SD.begin(10))) { 31 | while (1) { 32 | Serial.println("Unable to access the SD card"); 33 | delay(500); 34 | } 35 | } 36 | pinMode(13, OUTPUT); // LED on pin 13 37 | delay(1000); 38 | } 39 | 40 | void loop() { 41 | if (playSdWav1.isPlaying() == false) { 42 | Serial.println("Start playing"); 43 | playSdWav1.play("SDTEST3.WAV"); 44 | delay(10); // wait for library to parse WAV info 45 | } 46 | 47 | // print the play time offset 48 | Serial.print("Playing, now at "); 49 | Serial.print(playSdWav1.positionMillis()); 50 | Serial.println(" ms"); 51 | 52 | // blink LED and print info while playing 53 | digitalWrite(13, HIGH); 54 | delay(250); 55 | digitalWrite(13, LOW); 56 | delay(250); 57 | 58 | // read the knob position (analog input A2) 59 | /* 60 | int knob = analogRead(A2); 61 | float vol = (float)knob / 1280.0; 62 | sgtl5000_1.volume(vol); 63 | Serial.print("volume = "); 64 | Serial.println(vol); 65 | */ 66 | } 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /examples/HardwareTesting/SGTL5000/dap_avc_agc/dap_avc_agc.ino: -------------------------------------------------------------------------------- 1 | /* DAP AVC example; AVC is SGTL5000 equiv of AGC 2 | 3 | This example code is in the public domain 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | const int myInput = AUDIO_INPUT_LINEIN; 14 | // const int myInput = AUDIO_INPUT_MIC; 15 | 16 | // Create the Audio components. These should be created in the 17 | // order data flows, inputs/sources -> processing -> outputs 18 | // 19 | 20 | AudioInputI2S audioInput; // audio shield: mic or line-in 21 | AudioOutputI2S audioOutput; // audio shield: headphones & line-out 22 | 23 | // Create Audio connections between the components 24 | // 25 | AudioConnection c1(audioInput, 0, audioOutput, 0); // left passing through 26 | AudioConnection c2(audioInput, 1, audioOutput, 1); // right passing through 27 | 28 | // Create an object to control the audio shield. 29 | // 30 | AudioControlSGTL5000 audioShield; 31 | 32 | void setup() { 33 | // Audio connections require memory to work. For more 34 | // detailed information, see the MemoryAndCpuUsage example 35 | AudioMemory(4); 36 | // Enable the audio shield and set the output volume. 37 | audioShield.enable(); 38 | audioShield.inputSelect(myInput); 39 | audioShield.volume(0.5); 40 | audioShield.audioPreProcessorEnable(); 41 | // here are some settings for AVC that have a fairly obvious effect 42 | audioShield.autoVolumeControl(2,1,0,-5,0.5,0.5); // see comments starting line #699 of control_sgtl5000.cpp in ./libraries/audio/ 43 | // AVC has its own enable/disable bit 44 | // you can use audioShield.autoVolumeEnable(0); to turn off AVC 45 | } 46 | 47 | elapsedMillis chgMsec=0; 48 | float lastVol=1024; 49 | 50 | void loop() { 51 | // every 10 ms, check for adjustment 52 | if (chgMsec > 10) { 53 | float vol1=analogRead(15)/1023.0; 54 | vol1=(int)vol1; 55 | if(lastVol!=vol1) 56 | { 57 | audioShield.volume(vol1); 58 | lastVol=vol1; 59 | } 60 | chgMsec = 0; 61 | } 62 | } 63 | 64 | -------------------------------------------------------------------------------- /AudioControl.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef AudioControl_h_ 28 | #define AudioControl_h_ 29 | 30 | #include 31 | 32 | // A base class for all Codecs, DACs and ADCs, so at least the 33 | // most basic functionality is consistent. 34 | 35 | #define AUDIO_INPUT_LINEIN 0 36 | #define AUDIO_INPUT_MIC 1 37 | 38 | class AudioControl 39 | { 40 | public: 41 | virtual bool enable(void) = 0; 42 | virtual bool disable(void) = 0; 43 | virtual bool volume(float volume) = 0; // volume 0.0 to 1.0 44 | virtual bool inputLevel(float volume) = 0; // volume 0.0 to 1.0 45 | virtual bool inputSelect(int n) = 0; 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /effect_chorus.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Pete (El Supremo) 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | #ifndef effect_chorus_h_ 24 | #define effect_chorus_h_ 25 | 26 | #include "Arduino.h" 27 | #include "AudioStream.h" 28 | 29 | /******************************************************************/ 30 | 31 | // A u d i o E f f e c t C h o r u s 32 | // Written by Pete (El Supremo) Jan 2014 33 | // 140219 - correct storage class (not static) 34 | 35 | #define CHORUS_DELAY_PASSTHRU -1 36 | 37 | class AudioEffectChorus : 38 | public AudioStream 39 | { 40 | public: 41 | AudioEffectChorus(void): 42 | AudioStream(1,inputQueueArray), num_chorus(2) 43 | { } 44 | 45 | boolean begin(short *delayline,int delay_length,int n_chorus); 46 | virtual void update(void); 47 | void voices(int n_chorus); 48 | 49 | private: 50 | audio_block_t *inputQueueArray[1]; 51 | short *l_delayline; 52 | short l_circ_idx; 53 | int num_chorus; 54 | int delay_length; 55 | }; 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /play_memory.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef play_memory_h_ 28 | #define play_memory_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | 33 | class AudioPlayMemory : public AudioStream 34 | { 35 | public: 36 | AudioPlayMemory(void) : AudioStream(0, NULL), playing(0) { } 37 | void play(const unsigned int *data); 38 | void stop(void); 39 | bool isPlaying(void) { return playing; } 40 | uint32_t positionMillis(void); 41 | uint32_t lengthMillis(void); 42 | virtual void update(void); 43 | private: 44 | const unsigned int *next; 45 | const unsigned int *beginning; 46 | uint32_t length; 47 | int16_t prior; 48 | volatile uint8_t playing; 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /output_tdm.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2017, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef output_tdm_h_ 28 | #define output_tdm_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | #include "DMAChannel.h" 33 | 34 | class AudioOutputTDM : public AudioStream 35 | { 36 | public: 37 | AudioOutputTDM(void) : AudioStream(16, inputQueueArray) { begin(); } 38 | virtual void update(void); 39 | void begin(void); 40 | friend class AudioInputTDM; 41 | protected: 42 | static void config_tdm(void); 43 | static audio_block_t *block_input[16]; 44 | static bool update_responsibility; 45 | static DMAChannel dma; 46 | static void isr(void); 47 | private: 48 | audio_block_t *inputQueueArray[16]; 49 | }; 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /play_sd_raw.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef play_sd_raw_h_ 28 | #define play_sd_raw_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | #include "SD.h" 33 | 34 | class AudioPlaySdRaw : public AudioStream 35 | { 36 | public: 37 | AudioPlaySdRaw(void) : AudioStream(0, NULL) { begin(); } 38 | void begin(void); 39 | bool play(const char *filename); 40 | void stop(void); 41 | bool isPlaying(void) { return playing; } 42 | uint32_t positionMillis(void); 43 | uint32_t lengthMillis(void); 44 | virtual void update(void); 45 | private: 46 | File rawfile; 47 | uint32_t file_size; 48 | volatile uint32_t file_offset; 49 | volatile bool playing; 50 | }; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /output_pwm.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef output_pwm_h_ 28 | #define output_pwm_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | #include "DMAChannel.h" 33 | 34 | class AudioOutputPWM : public AudioStream 35 | { 36 | public: 37 | AudioOutputPWM(void) : AudioStream(1, inputQueueArray) { begin(); } 38 | virtual void update(void); 39 | private: 40 | static audio_block_t *block_1st; 41 | static audio_block_t *block_2nd; 42 | static uint32_t block_offset; 43 | static bool update_responsibility; 44 | static uint8_t interrupt_count; 45 | audio_block_t *inputQueueArray[1]; 46 | static DMAChannel dma; 47 | static void isr(void); 48 | void begin(void); 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /examples/Effects/Delay/Delay.ino: -------------------------------------------------------------------------------- 1 | // Delay demonstration example, Teensy Audio Library 2 | // http://www.pjrc.com/teensy/td_libs_Audio.html 3 | // 4 | // Creates a chirp on the left channel, then 5 | // three delayed copies on the right channel. 6 | // 7 | // Requires the audio shield: 8 | // http://www.pjrc.com/store/teensy3_audio.html 9 | // 10 | // This example code is in the public domain. 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | // GUItool: begin automatically generated code 19 | AudioSynthWaveformSine sine1; //xy=158,74 20 | AudioEffectEnvelope envelope1; //xy=232,156 21 | AudioEffectDelay delay1; //xy=393,238 22 | AudioMixer4 mixer1; //xy=532,205 23 | AudioOutputI2S i2s1; //xy=611,61 24 | AudioConnection patchCord1(sine1, envelope1); 25 | AudioConnection patchCord2(envelope1, delay1); 26 | AudioConnection patchCord3(envelope1, 0, i2s1, 0); 27 | AudioConnection patchCord4(delay1, 0, mixer1, 0); 28 | AudioConnection patchCord5(delay1, 1, mixer1, 1); 29 | AudioConnection patchCord6(delay1, 2, mixer1, 2); 30 | AudioConnection patchCord7(delay1, 3, mixer1, 3); 31 | AudioConnection patchCord8(mixer1, 0, i2s1, 1); 32 | AudioControlSGTL5000 sgtl5000_1; //xy=195,272 33 | // GUItool: end automatically generated code 34 | 35 | void setup() { 36 | // allocate enough memory for the delay 37 | AudioMemory(120); 38 | 39 | // enable the audio shield 40 | sgtl5000_1.enable(); 41 | sgtl5000_1.volume(0.5); 42 | 43 | // configure a sine wave for the chirp 44 | // the original is turned on/off by an envelope effect 45 | // and output directly on the left channel 46 | sine1.frequency(1000); 47 | sine1.amplitude(0.5); 48 | 49 | // create 3 delay taps, which connect through a 50 | // mixer to the right channel output 51 | delay1.delay(0, 110); 52 | delay1.delay(1, 220); 53 | delay1.delay(2, 330); 54 | } 55 | 56 | void loop() { 57 | envelope1.noteOn(); 58 | delay(36); 59 | envelope1.noteOff(); 60 | delay(4000); 61 | } 62 | -------------------------------------------------------------------------------- /control_wm8731.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef control_wm8731_h_ 28 | #define control_wm8731_h_ 29 | 30 | #include "AudioControl.h" 31 | 32 | class AudioControlWM8731 : public AudioControl 33 | { 34 | public: 35 | bool enable(void); 36 | bool disable(void) { return false; } 37 | bool volume(float n) { return volumeInteger(n * 80.0 + 47.499); } 38 | bool inputLevel(float n); // range: 0.0f to 1.0f 39 | bool inputSelect(int n); 40 | protected: 41 | bool write(unsigned int reg, unsigned int val); 42 | bool volumeInteger(unsigned int n); // range: 0x2F to 0x7F 43 | }; 44 | 45 | class AudioControlWM8731master : public AudioControlWM8731 46 | { 47 | public: 48 | bool enable(void); 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /synth_whitenoise.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef synth_whitenoise_h_ 28 | #define synth_whitenoise_h_ 29 | #include "Arduino.h" 30 | #include "AudioStream.h" 31 | #include "utility/dspinst.h" 32 | 33 | class AudioSynthNoiseWhite : public AudioStream 34 | { 35 | public: 36 | AudioSynthNoiseWhite() : AudioStream(0, NULL) { 37 | level = 0; 38 | seed = 1 + instance_count++; 39 | } 40 | void amplitude(float n) { 41 | if (n < 0.0) n = 0.0; 42 | else if (n > 1.0) n = 1.0; 43 | level = (int32_t)(n * 65536.0); 44 | } 45 | virtual void update(void); 46 | private: 47 | int32_t level; // 0=off, 65536=max 48 | uint32_t seed; // must start at 1 49 | static uint16_t instance_count; 50 | }; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /input_i2s_quad.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef _input_i2s_quad_h_ 28 | #define _input_i2s_quad_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | #include "DMAChannel.h" 33 | 34 | class AudioInputI2SQuad : public AudioStream 35 | { 36 | public: 37 | AudioInputI2SQuad(void) : AudioStream(0, NULL) { begin(); } 38 | virtual void update(void); 39 | void begin(void); 40 | private: 41 | static bool update_responsibility; 42 | static DMAChannel dma; 43 | static void isr(void); 44 | static audio_block_t *block_ch1; 45 | static audio_block_t *block_ch2; 46 | static audio_block_t *block_ch3; 47 | static audio_block_t *block_ch4; 48 | static uint16_t block_offset; 49 | }; 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /play_queue.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef play_queue_h_ 28 | #define play_queue_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | 33 | class AudioPlayQueue : public AudioStream 34 | { 35 | public: 36 | AudioPlayQueue(void) : AudioStream(0, NULL), 37 | userblock(NULL), head(0), tail(0) { } 38 | void play(int16_t data); 39 | void play(const int16_t *data, uint32_t len); 40 | bool available(void); 41 | int16_t * getBuffer(void); 42 | void playBuffer(void); 43 | void stop(void); 44 | //bool isPlaying(void) { return playing; } 45 | virtual void update(void); 46 | private: 47 | audio_block_t *queue[32]; 48 | audio_block_t *userblock; 49 | volatile uint8_t head, tail; 50 | }; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /effect_midside.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2015, Hedde Bosman 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | #ifndef effect_midside_decode_h_ 24 | #define effect_midside_decode_h_ 25 | 26 | #include "Arduino.h" 27 | #include "AudioStream.h" 28 | 29 | #include "utility/dspinst.h" 30 | 31 | 32 | /** 33 | * This object performs the decoding of mid/side signals into a stereo signal. 34 | * That is, left = (mid+side), right = (mid-side) 35 | * After encoding and processing, this object decodes the mid/side components 36 | * back into enjoyable stereo audio. 37 | * Caution: processed mid/side signals may cause digital saturation (clipping). 38 | ***************************************************************/ 39 | class AudioEffectMidSide : public AudioStream 40 | { 41 | public: 42 | AudioEffectMidSide(void): AudioStream(2,inputQueueArray), encoding(true) { } 43 | void encode() { encoding = true; } 44 | void decode() { encoding = false; } 45 | virtual void update(void); 46 | private: 47 | bool encoding; 48 | audio_block_t *inputQueueArray[2]; 49 | }; 50 | 51 | #endif 52 | 53 | -------------------------------------------------------------------------------- /analyze_peak.cpp: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #include 28 | #include "analyze_peak.h" 29 | 30 | void AudioAnalyzePeak::update(void) 31 | { 32 | audio_block_t *block; 33 | const int16_t *p, *end; 34 | int32_t min, max; 35 | 36 | block = receiveReadOnly(); 37 | if (!block) { 38 | return; 39 | } 40 | p = block->data; 41 | end = p + AUDIO_BLOCK_SAMPLES; 42 | min = min_sample; 43 | max = max_sample; 44 | do { 45 | int16_t d=*p++; 46 | // TODO: can we speed this up with SSUB16 and SEL 47 | // http://www.m4-unleashed.com/parallel-comparison/ 48 | if (dmax) max=d; 50 | } while (p < end); 51 | min_sample = min; 52 | max_sample = max; 53 | new_output = true; 54 | release(block); 55 | } 56 | 57 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "2.7" 4 | 5 | # Cache PlatformIO packages using Travis CI container-based infrastructure 6 | sudo: false 7 | cache: 8 | directories: 9 | - "~/.platformio" 10 | 11 | env: 12 | - PLATFORMIO_CI_SRC=examples/MemoryAndCpuUsage 13 | - PLATFORMIO_CI_SRC=examples/Recorder 14 | - PLATFORMIO_CI_SRC=examples/SamplePlayer 15 | - PLATFORMIO_CI_SRC=examples/WavFilePlayer 16 | - PLATFORMIO_CI_SRC=examples/Analysis/DialTone_7segment 17 | - PLATFORMIO_CI_SRC=examples/Analysis/DialTone_Serial 18 | - PLATFORMIO_CI_SRC=examples/Analysis/FFT 19 | - PLATFORMIO_CI_SRC=examples/Analysis/PeakMeterMono 20 | - PLATFORMIO_CI_SRC=examples/Analysis/PeakMeterStereo 21 | - PLATFORMIO_CI_SRC=examples/Analysis/SpectrumAnalyzerBasic 22 | - PLATFORMIO_CI_SRC=examples/Effects/Bitcrusher 23 | - PLATFORMIO_CI_SRC=examples/Effects/Chorus 24 | - PLATFORMIO_CI_SRC=examples/Effects/Delay 25 | - PLATFORMIO_CI_SRC=examples/Effects/Filter 26 | - PLATFORMIO_CI_SRC=examples/Effects/Filter_FIR 27 | - PLATFORMIO_CI_SRC=examples/Effects/Flange 28 | - PLATFORMIO_CI_SRC=examples/HardwareTesting/PassThroughMono 29 | - PLATFORMIO_CI_SRC=examples/HardwareTesting/PassThroughStereo 30 | - PLATFORMIO_CI_SRC=examples/HardwareTesting/SdCardTest 31 | - PLATFORMIO_CI_SRC=examples/HardwareTesting/ToneSweep 32 | - PLATFORMIO_CI_SRC=examples/HardwareTesting/WM8731MikroSine 33 | - PLATFORMIO_CI_SRC=examples/Synthesis/PlaySynthMusic 34 | - PLATFORMIO_CI_SRC=examples/Synthesis/pulseWidth 35 | - PLATFORMIO_CI_SRC=examples/Tutorial/Part_1_02_Hardware_Test 36 | - PLATFORMIO_CI_SRC=examples/Tutorial/Part_1_03_Playing_Music 37 | - PLATFORMIO_CI_SRC=examples/Tutorial/Part_1_04_Blink_While_Playing 38 | - PLATFORMIO_CI_SRC=examples/Tutorial/Part_1_05_Do_More_While_Playing 39 | 40 | install: 41 | - pip install -U platformio 42 | 43 | # install dependent libraries 44 | # http://platformio.org/#!/lib/show/539/SerialFlash 45 | - platformio lib install 539 46 | 47 | - export PLATFORMIO_BUILD_FLAGS=-larm_cortexM4l_math 48 | 49 | # remove unused items 50 | - rm -r extras 51 | 52 | script: 53 | - platformio ci --lib=. --board=teensy31 54 | -------------------------------------------------------------------------------- /synth_tonesweep.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Pete (El Supremo) 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | #ifndef synth_tonesweep_h_ 24 | #define synth_tonesweep_h_ 25 | 26 | #include "Arduino.h" 27 | #include "AudioStream.h" 28 | 29 | // A u d i o S y n t h T o n e S w e e p 30 | // Written by Pete (El Supremo) Feb 2014 31 | 32 | class AudioSynthToneSweep : public AudioStream 33 | { 34 | public: 35 | AudioSynthToneSweep(void) : 36 | AudioStream(0,NULL), sweep_busy(0) 37 | { } 38 | 39 | boolean play(float t_amp,int t_lo,int t_hi,float t_time); 40 | virtual void update(void); 41 | unsigned char isPlaying(void); 42 | float read(void) { 43 | __disable_irq(); 44 | uint64_t freq = tone_freq; 45 | unsigned char busy = sweep_busy; 46 | __enable_irq(); 47 | if (!busy) return 0.0f; 48 | return (float)(freq >> 32); 49 | } 50 | 51 | private: 52 | short tone_amp; 53 | unsigned int tone_lo; 54 | unsigned int tone_hi; 55 | uint64_t tone_freq; 56 | uint64_t tone_phase; 57 | uint64_t tone_incr; 58 | int tone_sign; 59 | unsigned char sweep_busy; 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /examples/HardwareTesting/SGTL5000/dap_bass_enhance/dap_bass_enhance.ino: -------------------------------------------------------------------------------- 1 | /* DAP Bass enhance example SGTL5000 only 2 | 3 | This example code is in the public domain 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | const int myInput = AUDIO_INPUT_LINEIN; 14 | // const int myInput = AUDIO_INPUT_MIC; 15 | 16 | // Create the Audio components. These should be created in the 17 | // order data flows, inputs/sources -> processing -> outputs 18 | // 19 | 20 | AudioInputI2S audioInput; // audio shield: mic or line-in 21 | AudioOutputI2S audioOutput; // audio shield: headphones & line-out 22 | 23 | // Create Audio connections between the components 24 | // 25 | AudioConnection c1(audioInput, 0, audioOutput, 0); // left passing through 26 | AudioConnection c2(audioInput, 1, audioOutput, 1); // right passing through 27 | 28 | // Create an object to control the audio shield. 29 | // 30 | AudioControlSGTL5000 audioShield; 31 | 32 | void setup() { 33 | // Audio connections require memory to work. For more 34 | // detailed information, see the MemoryAndCpuUsage example 35 | AudioMemory(4); 36 | // Enable the audio shield and set the output volume. 37 | audioShield.enable(); 38 | audioShield.inputSelect(myInput); 39 | audioShield.volume(0.5); 40 | // just enable it to use default settings. 41 | audioShield.audioPostProcessorEnable(); 42 | audioShield.enhanceBassEnable(); // all we need to do for default bass enhancement settings. 43 | // audioShield.enhanceBass((float)lr_level,(float)bass_level); 44 | // audioShield.enhanceBass((float)lr_level,(float)bass_level,(uint8_t)hpf_bypass,(uint8_t)cutoff); 45 | // please see http://www.pjrc.com/teensy/SGTL5000.pdf page 50 for valid values for BYPASS_HPF and CUTOFF 46 | } 47 | 48 | elapsedMillis chgMsec=0; 49 | float lastVol=1024; 50 | 51 | void loop() { 52 | // every 10 ms, check for adjustment 53 | if (chgMsec > 10) { // more regular updates for actual changes seems better. 54 | float vol1=analogRead(15)/1023.0; 55 | vol1=(int)vol1; 56 | if(lastVol!=vol1) 57 | { 58 | audioShield.volume(vol1); 59 | lastVol=vol1; 60 | } 61 | chgMsec = 0; 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /record_queue.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef record_queue_h_ 28 | #define record_queue_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | 33 | class AudioRecordQueue : public AudioStream 34 | { 35 | public: 36 | AudioRecordQueue(void) : AudioStream(1, inputQueueArray), 37 | userblock(NULL), head(0), tail(0), enabled(0) { } 38 | void begin(void) { 39 | clear(); 40 | enabled = 1; 41 | } 42 | int available(void); 43 | void clear(void); 44 | int16_t * readBuffer(void); 45 | void freeBuffer(void); 46 | void end(void) { 47 | enabled = 0; 48 | } 49 | virtual void update(void); 50 | private: 51 | audio_block_t *inputQueueArray[1]; 52 | audio_block_t * volatile queue[53]; 53 | audio_block_t *userblock; 54 | volatile uint8_t head, tail, enabled; 55 | }; 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /utility/sqrt_integer.c: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #include "sqrt_integer.h" 28 | 29 | const uint16_t sqrt_integer_guess_table[33] = { 30 | 55109, 31 | 38968, 32 | 27555, 33 | 19484, 34 | 13778, 35 | 9742, 36 | 6889, 37 | 4871, 38 | 3445, 39 | 2436, 40 | 1723, 41 | 1218, 42 | 862, 43 | 609, 44 | 431, 45 | 305, 46 | 216, 47 | 153, 48 | 108, 49 | 77, 50 | 54, 51 | 39, 52 | 27, 53 | 20, 54 | 14, 55 | 10, 56 | 7, 57 | 5, 58 | 4, 59 | 3, 60 | 2, 61 | 1, 62 | 0 63 | }; 64 | /* 65 | #! /usr/bin/perl 66 | use POSIX; 67 | print "const uint16_t sqrt_integer_guess_table[33] = {\n"; 68 | for ($i=0; $i <= 32; $i++) { 69 | printf "%5d", ceil(sqrt((0xFFFFFFFF >> $i) * sqrt(2)/2 )); 70 | print "," if $i < 32; 71 | print "\n"; 72 | } 73 | print "};\n"; 74 | */ 75 | -------------------------------------------------------------------------------- /gui/red/ui/keyboard.js: -------------------------------------------------------------------------------- 1 | /** Modified from original Node-Red source, for audio system visualization 2 | * vim: set ts=4: 3 | * Copyright 2013 IBM Corp. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | **/ 17 | RED.keyboard = (function() { 18 | 19 | var active = true; 20 | var handlers = {}; 21 | 22 | d3.select(window).on("keydown",function() { 23 | if (!active) { return; } 24 | var handler = handlers[d3.event.keyCode]; 25 | if (handler && handler.ondown) { 26 | if (!handler.modifiers || 27 | ((!handler.modifiers.shift || d3.event.shiftKey) && 28 | (!handler.modifiers.ctrl || d3.event.ctrlKey ) && 29 | (!handler.modifiers.alt || d3.event.altKey ) )) { 30 | handler.ondown(); 31 | } 32 | } 33 | }); 34 | d3.select(window).on("keyup",function() { 35 | if (!active) { return; } 36 | var handler = handlers[d3.event.keyCode]; 37 | if (handler && handler.onup) { 38 | if (!handler.modifiers || 39 | ((!handler.modifiers.shift || d3.event.shiftKey) && 40 | (!handler.modifiers.ctrl || d3.event.ctrlKey ) && 41 | (!handler.modifiers.alt || d3.event.altKey ) )) { 42 | handler.onup(); 43 | } 44 | } 45 | }); 46 | function addHandler(key,modifiers,ondown,onup) { 47 | var mod = modifiers; 48 | var cbdown = ondown; 49 | var cbup = onup; 50 | 51 | if (typeof modifiers == "function") { 52 | mod = {}; 53 | cbdown = modifiers; 54 | cbup = ondown; 55 | } 56 | handlers[key] = {modifiers:mod, ondown:cbdown, onup:cbup}; 57 | } 58 | function removeHandler(key) { 59 | delete handlers[key]; 60 | } 61 | 62 | return { 63 | add: addHandler, 64 | remove: removeHandler, 65 | disable: function(){ active = false;}, 66 | enable: function(){ active = true; } 67 | } 68 | 69 | })(); 70 | -------------------------------------------------------------------------------- /effect_flange.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Pete (El Supremo) 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | #ifndef effect_flange_h_ 24 | #define effect_flange_h_ 25 | 26 | #include "Arduino.h" 27 | #include "AudioStream.h" 28 | 29 | /******************************************************************/ 30 | // A u d i o E f f e c t F l a n g e 31 | // Written by Pete (El Supremo) Jan 2014 32 | // 140529 - change to handle mono stream and change modify() to voices() 33 | 34 | #define FLANGE_DELAY_PASSTHRU 0 35 | 36 | class AudioEffectFlange : 37 | public AudioStream 38 | { 39 | public: 40 | AudioEffectFlange(void): 41 | AudioStream(1,inputQueueArray) { 42 | } 43 | 44 | boolean begin(short *delayline,int d_length,int delay_offset,int d_depth,float delay_rate); 45 | boolean voices(int delay_offset,int d_depth,float delay_rate); 46 | virtual void update(void); 47 | 48 | private: 49 | audio_block_t *inputQueueArray[1]; 50 | short *l_delayline; 51 | int delay_length; 52 | short l_circ_idx; 53 | int delay_depth; 54 | int delay_offset_idx; 55 | int delay_rate_incr; 56 | unsigned int l_delay_rate_index; 57 | }; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /output_dacs.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef output_dacs_h_ 28 | #define output_dacs_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | #include "DMAChannel.h" 33 | 34 | class AudioOutputAnalogStereo : public AudioStream 35 | { 36 | public: 37 | AudioOutputAnalogStereo(void) : AudioStream(2, inputQueueArray) { begin(); } 38 | virtual void update(void); 39 | void begin(void); 40 | void analogReference(int ref); 41 | private: 42 | static audio_block_t *block_left_1st; 43 | static audio_block_t *block_left_2nd; 44 | static audio_block_t *block_right_1st; 45 | static audio_block_t *block_right_2nd; 46 | static audio_block_t block_silent; 47 | static bool update_responsibility; 48 | audio_block_t *inputQueueArray[2]; 49 | static DMAChannel dma; 50 | static void isr(void); 51 | }; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /play_serialflash_raw.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * Modified to use SerialFlash instead of SD library by Wyatt Olson 4 | * 5 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 6 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 7 | * open source software by purchasing Teensy or other PJRC products. 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice, development funding notice, and this permission 17 | * notice shall be included in all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | */ 27 | 28 | #ifndef play_serial_raw_h_ 29 | #define play_serial_raw_h_ 30 | 31 | #include "Arduino.h" 32 | #include 33 | #include 34 | 35 | class AudioPlaySerialflashRaw : public AudioStream 36 | { 37 | public: 38 | AudioPlaySerialflashRaw(void) : AudioStream(0, NULL) { begin(); } 39 | void begin(void); 40 | bool play(const char *filename); 41 | void stop(void); 42 | bool isPlaying(void) { return playing; } 43 | uint32_t positionMillis(void); 44 | uint32_t lengthMillis(void); 45 | virtual void update(void); 46 | private: 47 | SerialFlashFile rawfile; 48 | uint32_t file_size; 49 | volatile uint32_t file_offset; 50 | volatile bool playing; 51 | }; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /effect_sh.cpp: -------------------------------------------------------------------------------- 1 | #include "effect_sh.h" 2 | 3 | 4 | 5 | 6 | void AudioEffectSH::update(void){ 7 | 8 | audio_block_t *blocka,*blockb; 9 | int16_t *pa,*pb,*end; 10 | static uint32_t prev_sh; 11 | static int16_t paudio_in0,paudio_in1,ccnt0,ccnt1,audio_in0,audio_out0,audio_out1,audio_out_c,mod_in; 12 | float step = 1/2^(16); 13 | static uint32_t accumulator0; 14 | static int16_t last,hey; 15 | 16 | 17 | blocka = receiveWritable(0); 18 | blockb = receiveReadOnly(1); 19 | 20 | if (!blocka) { 21 | return; 22 | } 23 | 24 | pa = (int16_t *)(blocka->data); 25 | pb = (int16_t *)(blockb->data); 26 | 27 | end = (pa + AUDIO_BLOCK_SAMPLES); 28 | 29 | while (pa < end) { 30 | paudio_in0=audio_out_c; 31 | audio_in0 = *pa; 32 | 33 | if (blockb) { 34 | mod_in= *pb++; 35 | } 36 | 37 | if (!blockb) { 38 | mod_in= -1; 39 | } 40 | 41 | 42 | //uint32_t increment0=rate_reduction_amt; 43 | //if (smooth_en==1){ 44 | 45 | accumulator0 += rate_reduction_amt; 46 | 47 | if (accumulator0 > 65535){ 48 | accumulator0 -= 65535; 49 | audio_out_c=audio_in0; 50 | } 51 | 52 | else { 53 | audio_out_c = paudio_in0; 54 | } 55 | /* 56 | } 57 | 58 | if (smooth_en==0){ 59 | ccnt0++; 60 | 61 | if (ccnt0 >= rate_reduction_amt){ 62 | ccnt0=0; 63 | audio_out_c = audio_in0; 64 | } 65 | 66 | else { 67 | audio_out_c = paudio_in0; 68 | } 69 | 70 | } 71 | 72 | 73 | if (manual_hold_en==1 || mod_in>=1){ 74 | audio_out_c = paudio_in0; 75 | } 76 | */ 77 | 78 | *pa++ = audio_out_c; 79 | 80 | /* 81 | if (millis() - prev_sh>150){ 82 | prev_sh=millis(); 83 | Serial.println(hey); 84 | 85 | Serial.println(rate_reduction_amt); 86 | Serial.println(mod_in); 87 | Serial.println(); 88 | 89 | } 90 | */ 91 | 92 | // *pa++ = t1; 93 | 94 | } 95 | 96 | transmit(blocka); 97 | release(blocka); 98 | if (blockb) 99 | { 100 | release(blockb); 101 | } 102 | 103 | 104 | 105 | } 106 | 107 | -------------------------------------------------------------------------------- /output_spdif.h: -------------------------------------------------------------------------------- 1 | /* SPDIF for Teensy 3.X 2 | * Copyright (c) 2015, Frank Bösing, f.boesing@gmx.de, 3 | * Thanks to KPC & Paul Stoffregen! 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice, development funding notice, and this permission 13 | * notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | 24 | #ifndef output_SPDIF_h_ 25 | #define output_SPDIF_h_ 26 | 27 | #include "Arduino.h" 28 | #include "AudioStream.h" 29 | #include "DMAChannel.h" 30 | 31 | class AudioOutputSPDIF : public AudioStream 32 | { 33 | public: 34 | AudioOutputSPDIF(void) : AudioStream(2, inputQueueArray) { begin(); } 35 | virtual void update(void); 36 | void begin(void); 37 | friend class AudioInputSPDIF; 38 | static void mute_PCM(const bool mute); 39 | protected: 40 | AudioOutputSPDIF(int dummy): AudioStream(2, inputQueueArray) {} 41 | static void config_SPDIF(void); 42 | static audio_block_t *block_left_1st; 43 | static audio_block_t *block_right_1st; 44 | static bool update_responsibility; 45 | static DMAChannel dma; 46 | static void isr(void); 47 | private: 48 | static uint32_t vucp; 49 | static audio_block_t *block_left_2nd; 50 | static audio_block_t *block_right_2nd; 51 | static uint16_t block_left_offset; 52 | static uint16_t block_right_offset; 53 | audio_block_t *inputQueueArray[2]; 54 | }; 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /input_adc.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef input_adc_h_ 28 | #define input_adc_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | #include "DMAChannel.h" 33 | 34 | class AudioInputAnalog : public AudioStream 35 | { 36 | public: 37 | AudioInputAnalog() : AudioStream(0, NULL) { init(A2); } 38 | AudioInputAnalog(uint8_t pin) : AudioStream(0, NULL) { init(pin); } 39 | virtual void update(void); 40 | friend void dma_ch9_isr(void); 41 | private: 42 | static audio_block_t *block_left; 43 | static uint16_t block_offset; 44 | static int32_t hpf_y1; 45 | static int32_t hpf_x1; 46 | 47 | static bool update_responsibility; 48 | static DMAChannel dma; 49 | static void isr(void); 50 | static void init(uint8_t pin); 51 | 52 | }; 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /effect_combine.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef effect_combine_h_ 28 | #define effect_combine_h_ 29 | #include "AudioStream.h" 30 | #include "utility/dspinst.h" 31 | #include "Arduino.h" 32 | 33 | class AudioEffectDigitalCombine : public AudioStream 34 | { 35 | public: 36 | AudioEffectDigitalCombine() : AudioStream(2, inputQueueArray) { } 37 | 38 | void start(int sel, short* bank){ 39 | delayline=bank; 40 | } 41 | 42 | uint16_t mode(int sel){ 43 | bitmode=sel; 44 | return bitmode; 45 | } 46 | 47 | virtual void update(void); 48 | private: 49 | short *delayline; 50 | int16_t out1; 51 | int16_t shifta, shiftb; //, b56, b78; 52 | int16_t tick1; 53 | int32_t temp1,apos,bpos,readt1,paudio_in0; 54 | uint32_t accumulator0; 55 | audio_block_t *inputQueueArray[2]; 56 | uint16_t bitmode,readhead,writehead; 57 | }; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /utility/sqrt_integer.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #include 28 | 29 | #ifdef __cplusplus 30 | extern "C" const uint16_t sqrt_integer_guess_table[]; 31 | #else 32 | extern const uint16_t sqrt_integer_guess_table[]; 33 | #endif 34 | 35 | inline uint32_t sqrt_uint32(uint32_t in) __attribute__((always_inline,unused)); 36 | inline uint32_t sqrt_uint32(uint32_t in) 37 | { 38 | uint32_t n = sqrt_integer_guess_table[__builtin_clz(in)]; 39 | n = ((in / n) + n) / 2; 40 | n = ((in / n) + n) / 2; 41 | n = ((in / n) + n) / 2; 42 | return n; 43 | } 44 | 45 | inline uint32_t sqrt_uint32_approx(uint32_t in) __attribute__((always_inline,unused)); 46 | inline uint32_t sqrt_uint32_approx(uint32_t in) 47 | { 48 | uint32_t n = sqrt_integer_guess_table[__builtin_clz(in)]; 49 | n = ((in / n) + n) / 2; 50 | n = ((in / n) + n) / 2; 51 | return n; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /output_dac.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef output_dac_h_ 28 | #define output_dac_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | #include "DMAChannel.h" 33 | 34 | class AudioOutputAnalog : public AudioStream 35 | { 36 | public: 37 | AudioOutputAnalog(void) : AudioStream(1, inputQueueArray) { begin(); } 38 | virtual void update(void); 39 | void begin(void); 40 | void analogReference(int ref); 41 | private: 42 | static audio_block_t *block_left_1st; 43 | static audio_block_t *block_left_2nd; 44 | static bool update_responsibility; 45 | audio_block_t *inputQueueArray[1]; 46 | #if defined(KINETISK) 47 | static DMAChannel dma; 48 | static void isr(void); 49 | #elif defined(KINETISL) 50 | static DMAChannel dma1; 51 | static DMAChannel dma2; 52 | static void isr1(void); 53 | static void isr2(void); 54 | #endif 55 | }; 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /examples/Effects/Filter_FIR/lopass_1000_44100.h: -------------------------------------------------------------------------------- 1 | 2 | /* .fir file parameters which generated these coefficients 3 | 100 1 2 16 32768 44100 4 | 0 1000 2000 5 | 1.0000 0.0000 6 | 1.0000 70.0000 7 | */ 8 | (short)0x0015, 9 | (short)0x0011, 10 | (short)0x0017, 11 | (short)0x001E, 12 | (short)0x0025, 13 | (short)0x002C, 14 | (short)0x0032, 15 | (short)0x0037, 16 | (short)0x003B, 17 | (short)0x003C, 18 | (short)0x003B, 19 | (short)0x0036, 20 | (short)0x002E, 21 | (short)0x0021, 22 | (short)0x000F, 23 | (short)0xFFF9, 24 | (short)0xFFDE, 25 | (short)0xFFBF, 26 | (short)0xFF9C, 27 | (short)0xFF76, 28 | (short)0xFF4F, 29 | (short)0xFF27, 30 | (short)0xFF02, 31 | (short)0xFEDF, 32 | (short)0xFEC2, 33 | (short)0xFEAC, 34 | (short)0xFEA0, 35 | (short)0xFE9F, 36 | (short)0xFEAC, 37 | (short)0xFEC8, 38 | (short)0xFEF4, 39 | (short)0xFF31, 40 | (short)0xFF7F, 41 | (short)0xFFDF, 42 | (short)0x0050, 43 | (short)0x00D0, 44 | (short)0x015E, 45 | (short)0x01F8, 46 | (short)0x029A, 47 | (short)0x0341, 48 | (short)0x03EA, 49 | (short)0x0491, 50 | (short)0x0532, 51 | (short)0x05CA, 52 | (short)0x0653, 53 | (short)0x06CC, 54 | (short)0x0731, 55 | (short)0x077F, 56 | (short)0x07B4, 57 | (short)0x07CF, 58 | (short)0x07CF, 59 | (short)0x07B4, 60 | (short)0x077F, 61 | (short)0x0731, 62 | (short)0x06CC, 63 | (short)0x0653, 64 | (short)0x05CA, 65 | (short)0x0532, 66 | (short)0x0491, 67 | (short)0x03EA, 68 | (short)0x0341, 69 | (short)0x029A, 70 | (short)0x01F8, 71 | (short)0x015E, 72 | (short)0x00D0, 73 | (short)0x0050, 74 | (short)0xFFDF, 75 | (short)0xFF7F, 76 | (short)0xFF31, 77 | (short)0xFEF4, 78 | (short)0xFEC8, 79 | (short)0xFEAC, 80 | (short)0xFE9F, 81 | (short)0xFEA0, 82 | (short)0xFEAC, 83 | (short)0xFEC2, 84 | (short)0xFEDF, 85 | (short)0xFF02, 86 | (short)0xFF27, 87 | (short)0xFF4F, 88 | (short)0xFF76, 89 | (short)0xFF9C, 90 | (short)0xFFBF, 91 | (short)0xFFDE, 92 | (short)0xFFF9, 93 | (short)0x000F, 94 | (short)0x0021, 95 | (short)0x002E, 96 | (short)0x0036, 97 | (short)0x003B, 98 | (short)0x003C, 99 | (short)0x003B, 100 | (short)0x0037, 101 | (short)0x0032, 102 | (short)0x002C, 103 | (short)0x0025, 104 | (short)0x001E, 105 | (short)0x0017, 106 | (short)0x0011, 107 | (short)0x0015, 108 | 109 | 110 | -------------------------------------------------------------------------------- /examples/Effects/Filter_FIR/bandp_1200_1700.h: -------------------------------------------------------------------------------- 1 | 2 | /* .fir file parameters which generated these coefficients 3 | 100 1 3 16 32768 44100 4 | 0 500 1200 1700 2300 5 | 0.0000 1.0000 0.0000 6 | 70.0000 1.0000 70.0000 7 | */ 8 | (short)0xFFAA, 9 | (short)0xFFC5, 10 | (short)0xFFB6, 11 | (short)0xFFA7, 12 | (short)0xFF9B, 13 | (short)0xFF94, 14 | (short)0xFF93, 15 | (short)0xFF9A, 16 | (short)0xFFAA, 17 | (short)0xFFC4, 18 | (short)0xFFE9, 19 | (short)0x0017, 20 | (short)0x004F, 21 | (short)0x008E, 22 | (short)0x00D1, 23 | (short)0x0115, 24 | (short)0x0155, 25 | (short)0x018F, 26 | (short)0x01BC, 27 | (short)0x01D9, 28 | (short)0x01E2, 29 | (short)0x01D3, 30 | (short)0x01AB, 31 | (short)0x0168, 32 | (short)0x010A, 33 | (short)0x0095, 34 | (short)0x000B, 35 | (short)0xFF72, 36 | (short)0xFED1, 37 | (short)0xFE2E, 38 | (short)0xFD92, 39 | (short)0xFD06, 40 | (short)0xFC92, 41 | (short)0xFC3D, 42 | (short)0xFC0D, 43 | (short)0xFC08, 44 | (short)0xFC30, 45 | (short)0xFC85, 46 | (short)0xFD06, 47 | (short)0xFDAF, 48 | (short)0xFE79, 49 | (short)0xFF5C, 50 | (short)0x004D, 51 | (short)0x0143, 52 | (short)0x0231, 53 | (short)0x030D, 54 | (short)0x03CB, 55 | (short)0x0463, 56 | (short)0x04CC, 57 | (short)0x0502, 58 | (short)0x0502, 59 | (short)0x04CC, 60 | (short)0x0463, 61 | (short)0x03CB, 62 | (short)0x030D, 63 | (short)0x0231, 64 | (short)0x0143, 65 | (short)0x004D, 66 | (short)0xFF5C, 67 | (short)0xFE79, 68 | (short)0xFDAF, 69 | (short)0xFD06, 70 | (short)0xFC85, 71 | (short)0xFC30, 72 | (short)0xFC08, 73 | (short)0xFC0D, 74 | (short)0xFC3D, 75 | (short)0xFC92, 76 | (short)0xFD06, 77 | (short)0xFD92, 78 | (short)0xFE2E, 79 | (short)0xFED1, 80 | (short)0xFF72, 81 | (short)0x000B, 82 | (short)0x0095, 83 | (short)0x010A, 84 | (short)0x0168, 85 | (short)0x01AB, 86 | (short)0x01D3, 87 | (short)0x01E2, 88 | (short)0x01D9, 89 | (short)0x01BC, 90 | (short)0x018F, 91 | (short)0x0155, 92 | (short)0x0115, 93 | (short)0x00D1, 94 | (short)0x008E, 95 | (short)0x004F, 96 | (short)0x0017, 97 | (short)0xFFE9, 98 | (short)0xFFC4, 99 | (short)0xFFAA, 100 | (short)0xFF9A, 101 | (short)0xFF93, 102 | (short)0xFF94, 103 | (short)0xFF9B, 104 | (short)0xFFA7, 105 | (short)0xFFB6, 106 | (short)0xFFC5, 107 | (short)0xFFAA, 108 | 109 | -------------------------------------------------------------------------------- /effect_bitcrusher.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Jonathan Payne (jon@jonnypayne.com) 3 | * Based on Effect_Fade by Paul Stoffregen 4 | 5 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 6 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 7 | * open source software by purchasing Teensy or other PJRC products. 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice, development funding notice, and this permission 17 | * notice shall be included in all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | */ 27 | 28 | #ifndef effect_bitcrusher_h_ 29 | #define effect_bitcrusher_h_ 30 | 31 | #include "Arduino.h" 32 | #include "AudioStream.h" 33 | 34 | class AudioEffectBitcrusher : public AudioStream 35 | { 36 | public: 37 | AudioEffectBitcrusher(void) 38 | : AudioStream(1, inputQueueArray) {} 39 | void bits(uint8_t b) { 40 | if (b > 16) b = 16; 41 | else if (b == 0) b = 1; 42 | crushBits = b; 43 | } 44 | void sampleRate(float hz) { 45 | int n = (AUDIO_SAMPLE_RATE_EXACT / hz) + 0.5; 46 | if (n < 1) n = 1; 47 | else if (n > 64) n = 64; 48 | sampleStep = n; 49 | } 50 | virtual void update(void); 51 | 52 | private: 53 | uint8_t crushBits; // 16 = off 54 | uint8_t sampleStep; // the number of samples to double up. This simple technique only allows a few stepped positions. 55 | audio_block_t *inputQueueArray[1]; 56 | }; 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /input_i2s.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef _input_i2s_h_ 28 | #define _input_i2s_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | #include "DMAChannel.h" 33 | 34 | class AudioInputI2S : public AudioStream 35 | { 36 | public: 37 | AudioInputI2S(void) : AudioStream(0, NULL) { begin(); } 38 | virtual void update(void); 39 | void begin(void); 40 | protected: 41 | AudioInputI2S(int dummy): AudioStream(0, NULL) {} // to be used only inside AudioInputI2Sslave !! 42 | static bool update_responsibility; 43 | static DMAChannel dma; 44 | static void isr(void); 45 | private: 46 | static audio_block_t *block_left; 47 | static audio_block_t *block_right; 48 | static uint16_t block_offset; 49 | }; 50 | 51 | 52 | class AudioInputI2Sslave : public AudioInputI2S 53 | { 54 | public: 55 | AudioInputI2Sslave(void) : AudioInputI2S(0) { begin(); } 56 | void begin(void); 57 | friend void dma_ch1_isr(void); 58 | }; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /spi_interrupt.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef audio_spi_interrupt_h_ 28 | #define audio_spi_interrupt_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | #include "SPI.h" 33 | 34 | static inline void AudioStartUsingSPI(void) __attribute__((always_inline, unused)); 35 | static inline void AudioStopUsingSPI(void) __attribute__((always_inline, unused)); 36 | 37 | #ifdef SPI_HAS_NOTUSINGINTERRUPT 38 | 39 | extern unsigned short AudioUsingSPICount; 40 | 41 | static inline void AudioStartUsingSPI(void) { 42 | SPI.usingInterrupt(IRQ_SOFTWARE); 43 | AudioUsingSPICount++; 44 | } 45 | 46 | static inline void AudioStopUsingSPI(void) { 47 | if (AudioUsingSPICount == 0 || --AudioUsingSPICount == 0) 48 | SPI.notUsingInterrupt(IRQ_SOFTWARE); 49 | } 50 | 51 | #else 52 | 53 | static inline void AudioStartUsingSPI(void) { 54 | SPI.usingInterrupt(IRQ_SOFTWARE); 55 | } 56 | 57 | static inline void AudioStopUsingSPI(void) { 58 | } 59 | 60 | #endif 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /examples/Tutorial/Part_2_03_Samples/Part_2_03_Samples.ino: -------------------------------------------------------------------------------- 1 | // Advanced Microcontroller-based Audio Workshop 2 | // 3 | // Part 2-3: Playing Samples 4 | 5 | // WAV files converted to code by wav2sketch 6 | #include "AudioSampleSnare.h" // http://www.freesound.org/people/KEVOY/sounds/82583/ 7 | #include "AudioSampleTomtom.h" // http://www.freesound.org/people/zgump/sounds/86334/ 8 | #include "AudioSampleHihat.h" // http://www.freesound.org/people/mhc/sounds/102790/ 9 | #include "AudioSampleKick.h" // http://www.freesound.org/people/DWSD/sounds/171104/ 10 | #include "AudioSampleGong.h" // http://www.freesound.org/people/juskiddink/sounds/86773/ 11 | #include "AudioSampleCashregister.h" // http://www.freesound.org/people/kiddpark/sounds/201159/ 12 | #include 13 | 14 | 15 | /////////////////////////////////// 16 | // copy the Design Tool code here 17 | /////////////////////////////////// 18 | 19 | 20 | 21 | 22 | 23 | // Bounce objects to read pushbuttons 24 | Bounce button0 = Bounce(0, 15); 25 | Bounce button1 = Bounce(1, 15); // 15 ms debounce time 26 | Bounce button2 = Bounce(2, 15); 27 | 28 | 29 | void setup() { 30 | pinMode(0, INPUT_PULLUP); 31 | pinMode(1, INPUT_PULLUP); 32 | pinMode(2, INPUT_PULLUP); 33 | AudioMemory(10); 34 | sgtl5000_1.enable(); 35 | sgtl5000_1.volume(0.5); 36 | mixer1.gain(0, 0.4); 37 | mixer1.gain(1, 0.4); 38 | mixer1.gain(2, 0.4); 39 | mixer1.gain(3, 0.4); 40 | } 41 | 42 | void loop() { 43 | // Update all the button objects 44 | button0.update(); 45 | button1.update(); 46 | button2.update(); 47 | 48 | if (button0.fallingEdge()) { 49 | playMem1.play(AudioSampleSnare); 50 | } 51 | if (button1.fallingEdge()) { 52 | playMem2.play(AudioSampleTomtom); 53 | } 54 | if (button2.fallingEdge()) { 55 | playMem3.play(AudioSampleHihat); 56 | } 57 | 58 | /* 59 | int knob = analogRead(A3); 60 | if (button0.fallingEdge()) { 61 | if (knob < 512) { 62 | playMem1.play(AudioSampleSnare); 63 | } else { 64 | playMem1.play(AudioSampleKick); 65 | } 66 | } 67 | if (button1.fallingEdge()) { 68 | if (knob < 512) { 69 | playMem2.play(AudioSampleTomtom); 70 | } else { 71 | playMem4.play(AudioSampleGong); 72 | } 73 | } 74 | if (button2.fallingEdge()) { 75 | if (knob < 512) { 76 | playMem3.play(AudioSampleHihat); 77 | } else { 78 | playMem3.play(AudioSampleCashregister); 79 | } 80 | } 81 | */ 82 | 83 | } 84 | 85 | -------------------------------------------------------------------------------- /synth_pwm.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2017, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef synth_pwm_h_ 28 | #define synth_pwm_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | #include "arm_math.h" 33 | 34 | class AudioSynthWaveformPWM : public AudioStream 35 | { 36 | public: 37 | AudioSynthWaveformPWM() : AudioStream(1, inputQueueArray), magnitude(0), elapsed(0) {} 38 | void frequency(float freq) { 39 | if (freq < 1.0) freq = 1.0; 40 | else if (freq > AUDIO_SAMPLE_RATE_EXACT/4) freq = AUDIO_SAMPLE_RATE_EXACT/4; 41 | //phase_increment = freq * (4294967296.0 / AUDIO_SAMPLE_RATE_EXACT); 42 | duration = (AUDIO_SAMPLE_RATE_EXACT * 65536.0 + freq) / (freq * 2.0); 43 | } 44 | void amplitude(float n) { 45 | if (n < 0) n = 0; 46 | else if (n > 1.0) n = 1.0; 47 | magnitude = n * 32767.0; 48 | } 49 | virtual void update(void); 50 | private: 51 | uint32_t duration; // samples per half cycle (when 50% duty) * 65536 52 | audio_block_t *inputQueueArray[1]; 53 | int32_t magnitude; 54 | uint32_t elapsed; 55 | }; 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /analyze_print.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef analyze_print_h_ 28 | #define analyze_print_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | 33 | class AudioAnalyzePrint : public AudioStream 34 | { 35 | public: 36 | AudioAnalyzePrint(void) : AudioStream(1, inputQueueArray), 37 | myname(NULL), state(0), trigger_edge(0), delay_length(0), print_length(500) {} 38 | virtual void update(void); 39 | void name(const char *str) { myname = str; } 40 | void trigger(void); 41 | void trigger(float level, int edge); 42 | void delay(uint32_t num) { delay_length = num; } 43 | void length(uint32_t num) { print_length = num; } 44 | private: 45 | const char *myname; 46 | uint8_t state; 47 | uint8_t trigger_edge; // trigger type, 0=none, 2=RISING, 3=FALLING 48 | int16_t trigger_level; 49 | uint32_t delay_length; // number of samples between trigger and printing 50 | uint32_t print_length; // number of samples to print 51 | uint32_t count; 52 | audio_block_t *inputQueueArray[1]; 53 | }; 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /effect_fade.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef effect_fade_h_ 28 | #define effect_fade_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | 33 | class AudioEffectFade : public AudioStream 34 | { 35 | public: 36 | AudioEffectFade(void) 37 | : AudioStream(1, inputQueueArray), position(0xFFFFFFFF) {} 38 | void fadeIn(uint32_t milliseconds) { 39 | uint32_t samples = (uint32_t)(milliseconds * 441u + 5u) / 10u; 40 | //Serial.printf("fadeIn, %u samples\n", samples); 41 | fadeBegin(0xFFFFFFFFu / samples, 1); 42 | } 43 | void fadeOut(uint32_t milliseconds) { 44 | uint32_t samples = (uint32_t)(milliseconds * 441u + 5u) / 10u; 45 | //Serial.printf("fadeOut, %u samples\n", samples); 46 | fadeBegin(0xFFFFFFFFu / samples, 0); 47 | } 48 | virtual void update(void); 49 | private: 50 | void fadeBegin(uint32_t newrate, uint8_t dir); 51 | uint32_t position; // 0 = off, 0xFFFFFFFF = on 52 | uint32_t rate; 53 | uint8_t direction; // 0 = fading out, 1 = fading in 54 | audio_block_t *inputQueueArray[1]; 55 | }; 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /examples/HardwareTesting/SGTL5000/CalcBiquadToneControlDAP/CalcBiquadToneControlDAP.ino: -------------------------------------------------------------------------------- 1 | /* Tone example using SGTL5000 DAP PEQ filters and calcBiquad filter calculator routine. 2 | 3 | This example code is in the public domain 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | const int myInput = AUDIO_INPUT_LINEIN; 12 | // const int myInput = AUDIO_INPUT_MIC; 13 | 14 | int updateFilter[5]; 15 | 16 | AudioInputI2S audioInput; // audio shield: mic or line-in 17 | AudioOutputI2S audioOutput; // audio shield: headphones & line-out 18 | 19 | // Create Audio connections between the components 20 | // 21 | AudioConnection c1(audioInput, 0, audioOutput, 0); // left passing through 22 | AudioConnection c2(audioInput, 1, audioOutput, 1); // right passing through 23 | 24 | // Create an object to control the audio shield. 25 | // 26 | AudioControlSGTL5000 audioShield; 27 | 28 | void setup() { 29 | // Audio connections require memory to work. For more 30 | // detailed information, see the MemoryAndCpuUsage example 31 | AudioMemory(4); 32 | // Enable the audio shield, select the input and set the output volume. 33 | audioShield.enable(); 34 | audioShield.inputSelect(myInput); 35 | audioShield.volume(0.5); 36 | audioShield.audioPostProcessorEnable(); // enable the DAP block in SGTL5000 37 | // audioShield.eqSelect(1); // using PEQ Biquad filters 38 | // audioShield.eqFilterCount(2); // enable filter 0 & filter 1 39 | calcBiquad(FILTER_PARAEQ,110,0,0.2,524288,44100,updateFilter); // automation negates the need 40 | audioShield.eqFilter(0,updateFilter); // for the three lines commented out above. 41 | calcBiquad(FILTER_PARAEQ,4400,0,0.167,524288,44100,updateFilter); 42 | audioShield.eqFilter(1,updateFilter); 43 | } 44 | 45 | elapsedMillis chgMsec=0; 46 | float tone1=0; 47 | 48 | void loop() { 49 | // every 10 ms, check for adjustment 50 | if (chgMsec > 10) { 51 | 52 | float tone2=analogRead(15); 53 | tone2=floor(((tone2-512)/512)*70)/10; 54 | if(tone2!=tone1) 55 | { 56 | // calcBiquad(FilterType,FrequencyC,dBgain,Q,QuantizationUnit,SampleRate,int*); 57 | calcBiquad(FILTER_PARAEQ,110,-tone2,0.2,524288,44100,updateFilter); 58 | audioShield.eqFilter(0,updateFilter); 59 | calcBiquad(FILTER_PARAEQ,4400,tone2,0.167,524288,44100,updateFilter); 60 | audioShield.eqFilter(1,updateFilter); 61 | tone1=tone2; 62 | } 63 | chgMsec = 0; 64 | } 65 | } 66 | 67 | -------------------------------------------------------------------------------- /input_adcs.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef input_adcs_h_ 28 | #define input_adcs_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | #include "DMAChannel.h" 33 | 34 | class AudioInputAnalogStereo : public AudioStream 35 | { 36 | public: 37 | AudioInputAnalogStereo() : AudioStream(0, NULL) { 38 | init(A2, A3); 39 | } 40 | AudioInputAnalogStereo(uint8_t pin0, uint8_t pin1) : AudioStream(0, NULL) { 41 | init(pin0, pin1); 42 | } 43 | virtual void update(void); 44 | private: 45 | static audio_block_t *block_left; 46 | static audio_block_t *block_right; 47 | static uint16_t offset_left; 48 | static uint16_t offset_right; 49 | static int32_t hpf_y1[2]; 50 | static int32_t hpf_x1[2]; 51 | 52 | static bool update_responsibility; 53 | static DMAChannel dma0; 54 | static DMAChannel dma1; 55 | static void isr0(void); 56 | static void isr1(void); 57 | static void init(uint8_t pin0, uint8_t pin1); 58 | }; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /effect_granular.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 John-Michael Reed 3 | * bleeplabs.com 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #include "AudioStream.h" 25 | 26 | class AudioEffectGranular : public AudioStream 27 | { 28 | public: 29 | AudioEffectGranular(void): AudioStream(1,inputQueueArray) { } 30 | void begin(int16_t *sample_bank_def, int16_t max_len_def); 31 | void setSpeed(float ratio) { 32 | if (ratio < 0.125) ratio = 0.125; 33 | else if (ratio > 8.0) ratio = 8.0; 34 | playpack_rate = ratio * 65536.0 + 0.499; 35 | } 36 | void beginFreeze(float grain_length) { 37 | if (grain_length <= 0.0) return; 38 | beginFreeze_int(grain_length * (AUDIO_SAMPLE_RATE_EXACT * 0.001) + 0.5); 39 | } 40 | void beginPitchShift(float grain_length) { 41 | if (grain_length <= 0.0) return; 42 | beginPitchShift_int(grain_length * (AUDIO_SAMPLE_RATE_EXACT * 0.001) + 0.5); 43 | } 44 | void stop(); 45 | virtual void update(void); 46 | private: 47 | void beginFreeze_int(int grain_samples); 48 | void beginPitchShift_int(int grain_samples); 49 | audio_block_t *inputQueueArray[1]; 50 | int16_t *sample_bank; 51 | uint32_t playpack_rate; 52 | uint32_t accumulator; 53 | int16_t max_sample_len; 54 | int16_t write_head; 55 | int16_t read_head; 56 | int16_t grain_mode; 57 | int16_t freeze_len; 58 | int16_t prev_input; 59 | int16_t glitch_len; 60 | bool allow_len_change; 61 | bool sample_loaded; 62 | bool write_en; 63 | bool sample_req; 64 | }; 65 | 66 | -------------------------------------------------------------------------------- /examples/Analysis/FFT/FFT.ino: -------------------------------------------------------------------------------- 1 | // FFT Test 2 | // 3 | // Compute a 1024 point Fast Fourier Transform (spectrum analysis) 4 | // on audio connected to the Left Line-In pin. By changing code, 5 | // a synthetic sine wave can be input instead. 6 | // 7 | // The first 40 (of 512) frequency analysis bins are printed to 8 | // the Arduino Serial Monitor. Viewing the raw data can help you 9 | // understand how the FFT works and what results to expect when 10 | // using the data to control LEDs, motors, or other fun things! 11 | // 12 | // This example code is in the public domain. 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | const int myInput = AUDIO_INPUT_LINEIN; 21 | //const int myInput = AUDIO_INPUT_MIC; 22 | 23 | // Create the Audio components. These should be created in the 24 | // order data flows, inputs/sources -> processing -> outputs 25 | // 26 | AudioInputI2S audioInput; // audio shield: mic or line-in 27 | AudioSynthWaveformSine sinewave; 28 | AudioAnalyzeFFT1024 myFFT; 29 | AudioOutputI2S audioOutput; // audio shield: headphones & line-out 30 | 31 | // Connect either the live input or synthesized sine wave 32 | AudioConnection patchCord1(audioInput, 0, myFFT, 0); 33 | //AudioConnection patchCord1(sinewave, 0, myFFT, 0); 34 | 35 | AudioControlSGTL5000 audioShield; 36 | 37 | void setup() { 38 | // Audio connections require memory to work. For more 39 | // detailed information, see the MemoryAndCpuUsage example 40 | AudioMemory(12); 41 | 42 | // Enable the audio shield and set the output volume. 43 | audioShield.enable(); 44 | audioShield.inputSelect(myInput); 45 | audioShield.volume(0.5); 46 | 47 | // Configure the window algorithm to use 48 | myFFT.windowFunction(AudioWindowHanning1024); 49 | //myFFT.windowFunction(NULL); 50 | 51 | // Create a synthetic sine wave, for testing 52 | // To use this, edit the connections above 53 | sinewave.amplitude(0.8); 54 | sinewave.frequency(1034.007); 55 | } 56 | 57 | void loop() { 58 | float n; 59 | int i; 60 | 61 | if (myFFT.available()) { 62 | // each time new FFT data is available 63 | // print it all to the Arduino Serial Monitor 64 | Serial.print("FFT: "); 65 | for (i=0; i<40; i++) { 66 | n = myFFT.read(i); 67 | if (n >= 0.01) { 68 | Serial.print(n); 69 | Serial.print(" "); 70 | } else { 71 | Serial.print(" - "); // don't print "0.00" 72 | } 73 | } 74 | Serial.println(); 75 | } 76 | } 77 | 78 | 79 | -------------------------------------------------------------------------------- /play_queue.cpp: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #include 28 | #include "play_queue.h" 29 | #include "utility/dspinst.h" 30 | 31 | bool AudioPlayQueue::available(void) 32 | { 33 | if (userblock) return true; 34 | userblock = allocate(); 35 | if (userblock) return true; 36 | return false; 37 | } 38 | 39 | int16_t * AudioPlayQueue::getBuffer(void) 40 | { 41 | if (userblock) return userblock->data; 42 | while (1) { 43 | userblock = allocate(); 44 | if (userblock) return userblock->data; 45 | yield(); 46 | } 47 | } 48 | 49 | void AudioPlayQueue::playBuffer(void) 50 | { 51 | uint32_t h; 52 | 53 | if (!userblock) return; 54 | h = head + 1; 55 | if (h >= 32) h = 0; 56 | while (tail == h) ; // wait until space in the queue 57 | queue[h] = userblock; 58 | head = h; 59 | userblock = NULL; 60 | } 61 | 62 | void AudioPlayQueue::update(void) 63 | { 64 | audio_block_t *block; 65 | uint32_t t; 66 | 67 | t = tail; 68 | if (t != head) { 69 | if (++t >= 32) t = 0; 70 | block = queue[t]; 71 | tail = t; 72 | transmit(block); 73 | release(block); 74 | } 75 | } 76 | 77 | -------------------------------------------------------------------------------- /examples/Effects/Chorus/effects_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | CHORUS and FLANGE effects 3 | Both effects use a delay line to hold previous samples. This allows 4 | the current sample to be combined in some way with a sample that 5 | occurred in the past. An obvious effect this would allow would be 6 | an echo where the current sample is combined with a sample from, 7 | say, 250 milliseconds ago. The chorus and flange effects do this 8 | as well but they combine samples from only about 50ms (or less) ago. 9 | 10 | CHORUS EFFECT 11 | This combines one or more samples up to about 50ms ago. In this 12 | library, the additional samples are evenly spread through the 13 | supplied delay line. 14 | E.G. If the number of voices is specified as 2 then the effect 15 | combines the current sample and the oldest sample (the last one in 16 | the delay line). If the number of voices is 3 then the effect 17 | combines the most recent sample, the oldest sample and the sample 18 | in the middle of the delay line. 19 | For two voices the effect can be represented as: 20 | result = (sample(0) + sample(dt))/2 21 | where sample(0) represents the current sample and sample(dt) is 22 | the sample in the delay line from dt milliseconds ago. 23 | 24 | FLANGE EFFECT 25 | This combines only one sample from the delay line but the position 26 | of that sample varies sinusoidally. 27 | In this case the effect can be represented as: 28 | result = sample(0) + sample(dt + depth*sin(2*PI*Fe)) 29 | The value of the sine function is always a number from -1 to +1 30 | and so the result of depth*(sinFe) is always a number from 31 | -depth to +depth. Thus, the delayed sample will be selected from 32 | the range (dt-depth) to (dt+depth). This selection will vary 33 | at whatever rate is specified as the frequency of the effect Fe. 34 | 35 | Try these settings: 36 | #define FLANGE_DELAY_LENGTH (2*AUDIO_BLOCK_SAMPLES) 37 | and 38 | int s_idx = 2*FLANGE_DELAY_LENGTH/4; 39 | int s_depth = FLANGE_DELAY_LENGTH/4; 40 | double s_freq = 3; 41 | The flange effect can also produce a chorus effect if a longer 42 | delay line is used with a slower rate, for example try: 43 | #define FLANGE_DELAY_LENGTH (12*AUDIO_BLOCK_SAMPLES) 44 | and 45 | int s_idx = 3*FLANGE_DELAY_LENGTH/4; 46 | int s_depth = FLANGE_DELAY_LENGTH/8; 47 | double s_freq = .0625; 48 | 49 | When trying out these effects with recorded music as input, it is 50 | best to use those where there is a solo voice which is clearly 51 | "in front" of the accompaniment. Tracks which already contain 52 | flange or chorus effects don't work well. 53 | 54 | */ 55 | -------------------------------------------------------------------------------- /examples/Effects/Flange/effects_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | CHORUS and FLANGE effects 3 | Both effects use a delay line to hold previous samples. This allows 4 | the current sample to be combined in some way with a sample that 5 | occurred in the past. An obvious effect this would allow would be 6 | an echo where the current sample is combined with a sample from, 7 | say, 250 milliseconds ago. The chorus and flange effects do this 8 | as well but they combine samples from only about 50ms (or less) ago. 9 | 10 | CHORUS EFFECT 11 | This combines one or more samples up to about 50ms ago. In this 12 | library, the additional samples are evenly spread through the 13 | supplied delay line. 14 | E.G. If the number of voices is specified as 2 then the effect 15 | combines the current sample and the oldest sample (the last one in 16 | the delay line). If the number of voices is 3 then the effect 17 | combines the most recent sample, the oldest sample and the sample 18 | in the middle of the delay line. 19 | For two voices the effect can be represented as: 20 | result = (sample(0) + sample(dt))/2 21 | where sample(0) represents the current sample and sample(dt) is 22 | the sample in the delay line from dt milliseconds ago. 23 | 24 | FLANGE EFFECT 25 | This combines only one sample from the delay line but the position 26 | of that sample varies sinusoidally. 27 | In this case the effect can be represented as: 28 | result = sample(0) + sample(dt + depth*sin(2*PI*Fe)) 29 | The value of the sine function is always a number from -1 to +1 30 | and so the result of depth*(sinFe) is always a number from 31 | -depth to +depth. Thus, the delayed sample will be selected from 32 | the range (dt-depth) to (dt+depth). This selection will vary 33 | at whatever rate is specified as the frequency of the effect Fe. 34 | 35 | Try these settings: 36 | #define FLANGE_DELAY_LENGTH (2*AUDIO_BLOCK_SAMPLES) 37 | and 38 | int s_idx = 2*FLANGE_DELAY_LENGTH/4; 39 | int s_depth = FLANGE_DELAY_LENGTH/4; 40 | double s_freq = 3; 41 | The flange effect can also produce a chorus effect if a longer 42 | delay line is used with a slower rate, for example try: 43 | #define FLANGE_DELAY_LENGTH (12*AUDIO_BLOCK_SAMPLES) 44 | and 45 | int s_idx = 3*FLANGE_DELAY_LENGTH/4; 46 | int s_depth = FLANGE_DELAY_LENGTH/8; 47 | double s_freq = .0625; 48 | 49 | When trying out these effects with recorded music as input, it is 50 | best to use those where there is a solo voice which is clearly 51 | "in front" of the accompaniment. Tracks which already contain 52 | flange or chorus effects don't work well. 53 | 54 | */ 55 | -------------------------------------------------------------------------------- /filter_fir.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Pete (El Supremo) 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | #ifndef filter_fir_h_ 24 | #define filter_fir_h_ 25 | 26 | #include "Arduino.h" 27 | #include "AudioStream.h" 28 | #include "arm_math.h" 29 | 30 | // Indicates that the code should just pass through the audio 31 | // without any filtering (as opposed to doing nothing at all) 32 | #define FIR_PASSTHRU ((const short *) 1) 33 | 34 | #define FIR_MAX_COEFFS 200 35 | 36 | class AudioFilterFIR : public AudioStream 37 | { 38 | public: 39 | AudioFilterFIR(void): AudioStream(1,inputQueueArray), coeff_p(NULL) { 40 | } 41 | void begin(const short *cp, int n_coeffs) { 42 | coeff_p = cp; 43 | // Initialize FIR instance (ARM DSP Math Library) 44 | if (coeff_p && (coeff_p != FIR_PASSTHRU) && n_coeffs <= FIR_MAX_COEFFS) { 45 | if (arm_fir_init_q15(&fir_inst, n_coeffs, (q15_t *)coeff_p, 46 | &StateQ15[0], AUDIO_BLOCK_SAMPLES) != ARM_MATH_SUCCESS) { 47 | // n_coeffs must be an even number, 4 or larger 48 | coeff_p = NULL; 49 | } 50 | } 51 | } 52 | void end(void) { 53 | coeff_p = NULL; 54 | } 55 | virtual void update(void); 56 | private: 57 | audio_block_t *inputQueueArray[1]; 58 | 59 | // pointer to current coefficients or NULL or FIR_PASSTHRU 60 | const short *coeff_p; 61 | 62 | // ARM DSP Math library filter instance 63 | arm_fir_instance_q15 fir_inst; 64 | q15_t StateQ15[AUDIO_BLOCK_SAMPLES + FIR_MAX_COEFFS]; 65 | }; 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /output_i2s_quad.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef output_i2s_quad_h_ 28 | #define output_i2s_quad_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | #include "DMAChannel.h" 33 | 34 | class AudioOutputI2SQuad : public AudioStream 35 | { 36 | public: 37 | AudioOutputI2SQuad(void) : AudioStream(4, inputQueueArray) { begin(); } 38 | virtual void update(void); 39 | void begin(void); 40 | friend class AudioInputI2SQuad; 41 | private: 42 | static void config_i2s(void); 43 | static audio_block_t *block_ch1_1st; 44 | static audio_block_t *block_ch2_1st; 45 | static audio_block_t *block_ch3_1st; 46 | static audio_block_t *block_ch4_1st; 47 | static bool update_responsibility; 48 | static DMAChannel dma; 49 | static void isr(void); 50 | static audio_block_t *block_ch1_2nd; 51 | static audio_block_t *block_ch2_2nd; 52 | static audio_block_t *block_ch3_2nd; 53 | static audio_block_t *block_ch4_2nd; 54 | static uint16_t ch1_offset; 55 | static uint16_t ch2_offset; 56 | static uint16_t ch3_offset; 57 | static uint16_t ch4_offset; 58 | audio_block_t *inputQueueArray[4]; 59 | }; 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /synth_pinknoise.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef synth_pinknoise_h_ 28 | #define synth_pinknoise_h_ 29 | #include "Arduino.h" 30 | #include "AudioStream.h" 31 | #include "utility/dspinst.h" 32 | 33 | class AudioSynthNoisePink : public AudioStream 34 | { 35 | public: 36 | AudioSynthNoisePink() : AudioStream(0, NULL) { 37 | plfsr = 0x5EED41F5 + instance_cnt++; 38 | paccu = 0; 39 | pncnt = 0; 40 | pinc = 0x0CCC; 41 | pdec = 0x0CCC; 42 | } 43 | void amplitude(float n) { 44 | if (n < 0.0) n = 0.0; 45 | else if (n > 1.0) n = 1.0; 46 | level = (int32_t)(n * 65536.0); 47 | } 48 | virtual void update(void); 49 | private: 50 | static const uint8_t pnmask[256]; 51 | static const int32_t pfira[64]; 52 | static const int32_t pfirb[64]; 53 | static int16_t instance_cnt; 54 | int32_t plfsr; // linear feedback shift register 55 | int32_t pinc; // increment for all noise sources (bits) 56 | int32_t pdec; // decrement for all noise sources 57 | int32_t paccu; // accumulator 58 | uint8_t pncnt; // overflowing counter as index to pnmask[] 59 | int32_t level; // 0=off, 65536=max 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /follower.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef analyze_follower_h_ 28 | #define analyze_follower_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | 33 | class AudioAnalyzeFollower : public AudioStream 34 | { 35 | public: 36 | AudioAnalyzeFollower(void) : AudioStream(1, inputQueueArray) 37 | { 38 | } 39 | void rate(uint32_t r1) { 40 | //fr = r1 * 4096.00; 41 | fr = r1; 42 | } 43 | void exp_set(uint16_t es){ 44 | exp_div=es; 45 | } 46 | int32_t current() { 47 | return output; 48 | } 49 | 50 | void amplitude(float amp) { 51 | amp_div=amp*256; 52 | 53 | } 54 | 55 | int32_t aveo() { 56 | return max_in; 57 | } 58 | 59 | virtual void update(void); 60 | private: 61 | #define ave_div (AUDIO_BLOCK_SAMPLES) 62 | audio_block_t *inputQueueArray[2]; 63 | int32_t min_sample; 64 | int32_t max_sample; 65 | int32_t aves[68]; 66 | short ave_cnt,rising; 67 | const short nave=32; 68 | int32_t in_ave, prev_in_ave,ave_sum; 69 | int32_t audio_in, prev_audio_in; 70 | int32_t min, max, max_in, output; 71 | int32_t fr, j; 72 | int32_t exp_div = 4092; 73 | int32_t amp_div; 74 | }; 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /synth_karplusstrong.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2016, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef synth_karplusstrong_h_ 28 | #define synth_karplusstrong_h_ 29 | #include "Arduino.h" 30 | #include "AudioStream.h" 31 | #include "utility/dspinst.h" 32 | 33 | class AudioSynthKarplusStrong : public AudioStream 34 | { 35 | public: 36 | AudioSynthKarplusStrong() : AudioStream(0, NULL) { 37 | state = 0; 38 | } 39 | void noteOn(float frequency, float velocity) { 40 | if (velocity > 1.0f) { 41 | velocity = 0.0f; 42 | } else if (velocity <= 0.0f) { 43 | noteOff(1.0f); 44 | return; 45 | } 46 | magnitude = velocity * 65535.0f; 47 | int len = (AUDIO_SAMPLE_RATE_EXACT / frequency) + 0.5f; 48 | if (len > 536) len = 536; 49 | bufferLen = len; 50 | bufferIndex = 0; 51 | state = 1; 52 | } 53 | void noteOff(float velocity) { 54 | state = 0; 55 | } 56 | virtual void update(void); 57 | private: 58 | uint8_t state; // 0=steady output, 1=begin on next update, 2=playing 59 | uint16_t bufferLen; 60 | uint16_t bufferIndex; 61 | int32_t magnitude; // current output 62 | static uint32_t seed; // must start at 1 63 | int16_t buffer[536]; // TODO: dynamically use audio memory blocks 64 | }; 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /analyze_peak.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef analyze_peakdetect_h_ 28 | #define analyze_peakdetect_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | 33 | class AudioAnalyzePeak : public AudioStream 34 | { 35 | public: 36 | AudioAnalyzePeak(void) : AudioStream(1, inputQueueArray) { 37 | min_sample = 32767; 38 | max_sample = -32768; 39 | } 40 | bool available(void) { 41 | __disable_irq(); 42 | bool flag = new_output; 43 | if (flag) new_output = false; 44 | __enable_irq(); 45 | return flag; 46 | } 47 | float read(void) { 48 | __disable_irq(); 49 | int min = min_sample; 50 | int max = max_sample; 51 | min_sample = 32767; 52 | max_sample = -32768; 53 | __enable_irq(); 54 | min = abs(min); 55 | max = abs(max); 56 | if (min > max) max = min; 57 | return (float)max / 32767.0f; 58 | } 59 | float readPeakToPeak(void) { 60 | __disable_irq(); 61 | int min = min_sample; 62 | int max = max_sample; 63 | min_sample = 32767; 64 | max_sample = -32768; 65 | __enable_irq(); 66 | return (float)(max - min) / 32767.0f; 67 | } 68 | 69 | virtual void update(void); 70 | private: 71 | audio_block_t *inputQueueArray[1]; 72 | volatile bool new_output; 73 | int16_t min_sample; 74 | int16_t max_sample; 75 | }; 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /effect_tape_delay.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | 26 | Interpolated delay time gives delay effect with a tape like response. 27 | Control of this interpolation speed and delay sample rate is now possible 28 | 29 | */ 30 | 31 | #include "AudioStream.h" 32 | #include "Arduino.h" 33 | 34 | class AudioEffectTapeDelay : 35 | public AudioStream 36 | { 37 | public: 38 | AudioEffectTapeDelay(void): 39 | AudioStream(1, inputQueueArray) { 40 | } 41 | 42 | void begin(short *delayline, uint32_t max_len, uint32_t dly_len, short redux, short lerp); 43 | uint32_t length(uint32_t dly_len); 44 | uint32_t length_no_lerp(uint32_t dly_len); 45 | 46 | void sampleRate(short redux); 47 | 48 | 49 | virtual void update(void); 50 | 51 | 52 | private: 53 | uint32_t dlyd, dlyt; 54 | 55 | audio_block_t *inputQueueArray[1]; 56 | short *l_delayline; 57 | uint32_t delay_length, desired_delay_length; 58 | int32_t inv_delay_length; 59 | uint32_t max_dly_len; 60 | uint32_t write_head; 61 | uint32_t delay_depth; 62 | uint32_t rate_redux; 63 | uint32_t delay_offset_idx; 64 | uint32_t delay_rate_incr; 65 | uint32_t read_head, feedback; 66 | short SIMPLE_SMOOTH, lerp_len; 67 | uint32_t l_delay_rate_index; 68 | 69 | short sync_out_latch; 70 | short sync_out_count; 71 | }; -------------------------------------------------------------------------------- /examples/Tutorial/Part_1_05_Do_More_While_Playing/Part_1_05_Do_More_While_Playing.ino: -------------------------------------------------------------------------------- 1 | // Advanced Microcontroller-based Audio Workshop 2 | // 3 | // Part 1-5: Respond to Pushbuttons & Volume Knob 4 | // 5 | // Do more while playing. Monitor pushbuttons and adjust 6 | // the volume. Whe the buttons are pressed, stop playing 7 | // the current file and skip to the next or previous. 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | AudioPlaySdWav playSdWav1; 17 | AudioOutputI2S i2s1; 18 | AudioConnection patchCord1(playSdWav1, 0, i2s1, 0); 19 | AudioConnection patchCord2(playSdWav1, 1, i2s1, 1); 20 | AudioControlSGTL5000 sgtl5000_1; 21 | 22 | Bounce button0 = Bounce(0, 15); 23 | Bounce button2 = Bounce(2, 15); // 15 = 15 ms debounce time 24 | 25 | void setup() { 26 | Serial.begin(9600); 27 | AudioMemory(8); 28 | sgtl5000_1.enable(); 29 | sgtl5000_1.volume(0.5); 30 | SPI.setMOSI(7); 31 | SPI.setSCK(14); 32 | if (!(SD.begin(10))) { 33 | while (1) { 34 | Serial.println("Unable to access the SD card"); 35 | delay(500); 36 | } 37 | } 38 | pinMode(13, OUTPUT); // LED on pin 13 39 | pinMode(0, INPUT_PULLUP); 40 | pinMode(2, INPUT_PULLUP); 41 | delay(1000); 42 | } 43 | 44 | int filenumber = 0; // while file to play 45 | 46 | const char * filelist[4] = { 47 | "SDTEST1.WAV", "SDTEST2.WAV", "SDTEST3.WAV", "SDTEST4.WAV" 48 | }; 49 | 50 | elapsedMillis blinkTime; 51 | 52 | void loop() { 53 | 54 | if (playSdWav1.isPlaying() == false) { 55 | const char *filename = filelist[filenumber]; 56 | filenumber = filenumber + 1; 57 | if (filenumber >= 4) filenumber = 0; 58 | Serial.print("Start playing "); 59 | Serial.println(filename); 60 | playSdWav1.play(filename); 61 | delay(10); // wait for library to parse WAV info 62 | } 63 | 64 | // blink the LED without delays 65 | if (blinkTime < 250) { 66 | digitalWrite(13, LOW); 67 | } else if (blinkTime < 500) { 68 | digitalWrite(13, HIGH); 69 | } else { 70 | blinkTime = 0; // start blink cycle over again 71 | } 72 | 73 | // read pushbuttons 74 | button0.update(); 75 | if (button0.fallingEdge()) { 76 | playSdWav1.stop(); 77 | } 78 | button2.update(); 79 | if (button2.fallingEdge()) { 80 | playSdWav1.stop(); 81 | filenumber = filenumber - 2; 82 | if (filenumber < 0) filenumber = filenumber + 4; 83 | } 84 | 85 | // read the knob position (analog input A2) 86 | int knob = analogRead(A2); 87 | float vol = (float)knob / 1280.0; 88 | sgtl5000_1.volume(vol); 89 | //Serial.print("volume = "); 90 | //Serial.println(vol); 91 | } 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /utility/imxrt_hw.cpp: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2019, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | /* 27 | (c) Frank B 28 | */ 29 | 30 | #if defined(__IMXRT1052__) || defined(__IMXRT1062__) 31 | #include "imxrt_hw.h" 32 | 33 | FLASHMEM 34 | void set_audioClock(int nfact, int32_t nmult, uint32_t ndiv, bool force) // sets PLL4 35 | { 36 | if (!force && (CCM_ANALOG_PLL_AUDIO & CCM_ANALOG_PLL_AUDIO_ENABLE)) return; 37 | 38 | CCM_ANALOG_PLL_AUDIO = CCM_ANALOG_PLL_AUDIO_BYPASS | CCM_ANALOG_PLL_AUDIO_ENABLE 39 | | CCM_ANALOG_PLL_AUDIO_POST_DIV_SELECT(2) // 2: 1/4; 1: 1/2; 0: 1/1 40 | | CCM_ANALOG_PLL_AUDIO_DIV_SELECT(nfact); 41 | 42 | CCM_ANALOG_PLL_AUDIO_NUM = nmult & CCM_ANALOG_PLL_AUDIO_NUM_MASK; 43 | CCM_ANALOG_PLL_AUDIO_DENOM = ndiv & CCM_ANALOG_PLL_AUDIO_DENOM_MASK; 44 | 45 | CCM_ANALOG_PLL_AUDIO &= ~CCM_ANALOG_PLL_AUDIO_POWERDOWN;//Switch on PLL 46 | while (!(CCM_ANALOG_PLL_AUDIO & CCM_ANALOG_PLL_AUDIO_LOCK)) {}; //Wait for pll-lock 47 | 48 | const int div_post_pll = 1; // other values: 2,4 49 | CCM_ANALOG_MISC2 &= ~(CCM_ANALOG_MISC2_DIV_MSB | CCM_ANALOG_MISC2_DIV_LSB); 50 | if(div_post_pll>1) CCM_ANALOG_MISC2 |= CCM_ANALOG_MISC2_DIV_LSB; 51 | if(div_post_pll>3) CCM_ANALOG_MISC2 |= CCM_ANALOG_MISC2_DIV_MSB; 52 | 53 | CCM_ANALOG_PLL_AUDIO &= ~CCM_ANALOG_PLL_AUDIO_BYPASS;//Disable Bypass 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /output_i2s.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef output_i2s_h_ 28 | #define output_i2s_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | #include "DMAChannel.h" 33 | 34 | class AudioOutputI2S : public AudioStream 35 | { 36 | public: 37 | AudioOutputI2S(void) : AudioStream(2, inputQueueArray) { begin(); } 38 | virtual void update(void); 39 | void begin(void); 40 | friend class AudioInputI2S; 41 | protected: 42 | AudioOutputI2S(int dummy): AudioStream(2, inputQueueArray) {} // to be used only inside AudioOutputI2Sslave !! 43 | static void config_i2s(void); 44 | static audio_block_t *block_left_1st; 45 | static audio_block_t *block_right_1st; 46 | static bool update_responsibility; 47 | static DMAChannel dma; 48 | static void isr(void); 49 | private: 50 | static audio_block_t *block_left_2nd; 51 | static audio_block_t *block_right_2nd; 52 | static uint16_t block_left_offset; 53 | static uint16_t block_right_offset; 54 | audio_block_t *inputQueueArray[2]; 55 | }; 56 | 57 | 58 | class AudioOutputI2Sslave : public AudioOutputI2S 59 | { 60 | public: 61 | AudioOutputI2Sslave(void) : AudioOutputI2S(0) { begin(); } ; 62 | void begin(void); 63 | friend class AudioInputI2Sslave; 64 | friend void dma_ch0_isr(void); 65 | protected: 66 | static void config_i2s(void); 67 | }; 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /examples/Tutorial/Part_3_03_TFT_Display/Part_3_03_TFT_Display.ino: -------------------------------------------------------------------------------- 1 | // Advanced Microcontroller-based Audio Workshop 2 | // 3 | // Part 3-3: TFT Display 4 | 5 | #include 6 | #include // from ILI9341_t3 7 | 8 | 9 | /////////////////////////////////// 10 | // copy the Design Tool code here 11 | /////////////////////////////////// 12 | 13 | 14 | 15 | 16 | 17 | #define TFT_DC 20 18 | #define TFT_CS 21 19 | #define TFT_RST 255 // 255 = unused, connect to 3.3V 20 | #define TFT_MOSI 7 21 | #define TFT_SCLK 14 22 | #define TFT_MISO 12 23 | ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_MISO); 24 | 25 | 26 | void setup() { 27 | Serial.begin(9600); 28 | delay(500); 29 | tft.begin(); 30 | tft.fillScreen(ILI9341_BLACK); 31 | tft.setTextColor(ILI9341_YELLOW); 32 | tft.setFont(Arial_24); 33 | //tft.setTextSize(3); 34 | tft.setCursor(40, 8); 35 | tft.println("Peak Meter"); 36 | 37 | AudioMemory(10); 38 | sgtl5000_1.enable(); 39 | sgtl5000_1.volume(0.5); 40 | SPI.setMOSI(7); 41 | SPI.setSCK(14); 42 | if (!(SD.begin(10))) { 43 | while (1) { 44 | Serial.println("Unable to access the SD card"); 45 | delay(500); 46 | } 47 | } 48 | delay(1000); 49 | } 50 | 51 | elapsedMillis msecs; 52 | 53 | void loop() { 54 | if (playSdWav1.isPlaying() == false) { 55 | Serial.println("Start playing"); 56 | //playSdWav1.play("SDTEST1.WAV"); 57 | //playSdWav1.play("SDTEST2.WAV"); 58 | playSdWav1.play("SDTEST3.WAV"); 59 | //playSdWav1.play("SDTEST4.WAV"); 60 | delay(10); // wait for library to parse WAV info 61 | } 62 | 63 | if (msecs > 15) { 64 | if (peak1.available() && peak2.available()) { 65 | msecs = 0; 66 | float leftNumber = peak1.read(); 67 | float rightNumber = peak2.read(); 68 | Serial.print(leftNumber); 69 | Serial.print(", "); 70 | Serial.print(rightNumber); 71 | Serial.println(); 72 | 73 | // draw the verticle bars 74 | int height = leftNumber * 240; 75 | tft.fillRect(60, 280 - height, 40, height, ILI9341_GREEN); 76 | tft.fillRect(60, 280 - 240, 40, 240 - height, ILI9341_BLACK); 77 | height = rightNumber * 240; 78 | tft.fillRect(140, 280 - height, 40, height, ILI9341_GREEN); 79 | tft.fillRect(140, 280 - 240, 40, 240 - height, ILI9341_BLACK); 80 | // a smarter approach would redraw only the changed portion... 81 | 82 | // draw numbers underneath each bar 83 | tft.setFont(Arial_14); 84 | tft.fillRect(60, 284, 40, 16, ILI9341_BLACK); 85 | tft.setCursor(60, 284); 86 | tft.print(leftNumber); 87 | tft.fillRect(140, 284, 40, 16, ILI9341_BLACK); 88 | tft.setCursor(140, 284); 89 | tft.print(rightNumber); 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /control_cs4272.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * https://hackaday.io/project/5912-teensy-super-audio-board 5 | * https://github.com/whollender/Audio/tree/SuperAudioBoard 6 | * 7 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 8 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 9 | * open source software by purchasing Teensy or other PJRC products. 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the "Software"), to deal 13 | * in the Software without restriction, including without limitation the rights 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | * copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice, development funding notice, and this permission 19 | * notice shall be included in all copies or substantial portions of the Software. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | * THE SOFTWARE. 28 | */ 29 | 30 | #ifndef control_cs4272_h_ 31 | #define control_cs4272_h_ 32 | 33 | #include "AudioControl.h" 34 | 35 | class AudioControlCS4272 : public AudioControl 36 | { 37 | public: 38 | bool enable(void); 39 | bool disable(void) { return false; } 40 | bool volume(float n) { return volumeInteger(n * 127 + 0.499); } 41 | bool inputLevel(float n) { return false; } 42 | bool inputSelect(int n) { return false; } 43 | 44 | bool volume(float left, float right); 45 | bool dacVolume(float n) { return volumeInteger(n * 127 + 0.499); } 46 | bool dacVolume(float left, float right); 47 | 48 | bool muteOutput(void); 49 | bool unmuteOutput(void); 50 | 51 | bool muteInput(void); 52 | bool unmuteInput(void); 53 | 54 | bool enableDither(void); 55 | bool disableDither(void); 56 | 57 | protected: 58 | bool write(unsigned int reg, unsigned int val); 59 | bool volumeInteger(unsigned int n); // range: 0x0 to 0x7F 60 | 61 | uint8_t regLocal[8]; 62 | 63 | void initLocalRegs(void); 64 | }; 65 | 66 | // For sample rate ratio select (only single speed tested) 67 | #define CS4272_RATIO_SINGLE 0 68 | #define CS4272_RATIO_DOUBLE 2 69 | #define CS4272_RATIO_QUAD 3 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /play_sd_wav.h: -------------------------------------------------------------------------------- 1 | /* Audio Library for Teensy 3.X 2 | * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com 3 | * 4 | * Development of this audio library was funded by PJRC.COM, LLC by sales of 5 | * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop 6 | * open source software by purchasing Teensy or other PJRC products. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice, development funding notice, and this permission 16 | * notice shall be included in all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef play_sd_wav_h_ 28 | #define play_sd_wav_h_ 29 | 30 | #include "Arduino.h" 31 | #include "AudioStream.h" 32 | #include "SD.h" 33 | 34 | class AudioPlaySdWav : public AudioStream 35 | { 36 | public: 37 | AudioPlaySdWav(void) : AudioStream(0, NULL) { begin(); } 38 | void begin(void); 39 | bool play(const char *filename); 40 | void stop(void); 41 | bool isPlaying(void); 42 | uint32_t positionMillis(void); 43 | uint32_t lengthMillis(void); 44 | virtual void update(void); 45 | private: 46 | File wavfile; 47 | bool consume(uint32_t size); 48 | bool parse_format(void); 49 | uint32_t header[10]; // temporary storage of wav header data 50 | uint32_t data_length; // number of bytes remaining in current section 51 | uint32_t total_length; // number of audio data bytes in file 52 | uint32_t bytes2millis; 53 | audio_block_t *block_left; 54 | audio_block_t *block_right; 55 | uint16_t block_offset; // how much data is in block_left & block_right 56 | uint8_t buffer[512]; // buffer one block of data 57 | uint16_t buffer_offset; // where we're at consuming "buffer" 58 | uint16_t buffer_length; // how much data is in "buffer" (512 until last read) 59 | uint8_t header_offset; // number of bytes in header[] 60 | uint8_t state; 61 | uint8_t state_play; 62 | uint8_t leftover_bytes; 63 | }; 64 | 65 | #endif 66 | --------------------------------------------------------------------------------