diff --git a/examples/ESP32/ESP32_AudioTest/ESP32_AudioTest.ino b/examples/Platforms/ESP32/ESP32_AudioTest/ESP32_AudioTest.ino similarity index 100% rename from examples/ESP32/ESP32_AudioTest/ESP32_AudioTest.ino rename to examples/Platforms/ESP32/ESP32_AudioTest/ESP32_AudioTest.ino diff --git a/examples/ESP32/ESP32_AudioTest/mySine.h b/examples/Platforms/ESP32/ESP32_AudioTest/mySine.h similarity index 100% rename from examples/ESP32/ESP32_AudioTest/mySine.h rename to examples/Platforms/ESP32/ESP32_AudioTest/mySine.h diff --git a/examples/ESP32/ESP32_AudioTest/myWAV.h b/examples/Platforms/ESP32/ESP32_AudioTest/myWAV.h similarity index 100% rename from examples/ESP32/ESP32_AudioTest/myWAV.h rename to examples/Platforms/ESP32/ESP32_AudioTest/myWAV.h diff --git a/examples/ESP32/ESP32_AudioTest/volume.h b/examples/Platforms/ESP32/ESP32_AudioTest/volume.h similarity index 100% rename from examples/ESP32/ESP32_AudioTest/volume.h rename to examples/Platforms/ESP32/ESP32_AudioTest/volume.h diff --git a/examples/Platforms/NRF52/NRF52_PDM_I2STest/NRF52_PDM_I2STest.ino b/examples/Platforms/NRF52/NRF52_PDM_I2STest/NRF52_PDM_I2STest.ino new file mode 100644 index 0000000..7ce5a3d --- /dev/null +++ b/examples/Platforms/NRF52/NRF52_PDM_I2STest/NRF52_PDM_I2STest.ino @@ -0,0 +1,39 @@ +#include + +AutoAnalog aaAudio; + +#if defined(USE_TINYUSB) + // Needed for Serial.print on non-MBED enabled or adafruit-based nRF52 cores + #include "Adafruit_TinyUSB.h" +#endif + +/*********************************************************/ +/* Tested with MAX98357A I2S breakout +/* BCLK connected to Arduino D1 (p0.03) +/* LRCK connected to Arduino D3 (p0.29) +/* DIN connected to Arduino D5 (p0.05) +/* SD connected to Arduino D6 (p1.11) +/*********************************************************/ + +void setup() { + + + Serial.begin(115200); + aaAudio.begin(1, 1, 1); //Setup aaAudio using DAC & I2S + aaAudio.adcBitsPerSample = 16; // 16-bit samples input from PDM + aaAudio.dacBitsPerSample = 16; // 16-bit samples output to I2S + aaAudio.setSampleRate(32000); // 32kHz + + pinMode(6, OUTPUT); //Connected to SD pin of MAX98357A + digitalWrite(6,HIGH); + +} + +void loop() { + + aaAudio.getADC(6400); // Get data from PDM microphone + + memcpy(aaAudio.dacBuffer16, aaAudio.adcBuffer16, 12800); // Copy data into output buffer from input buffer + + aaAudio.feedDAC(0,6400); // Feed the data to I2S output +} diff --git a/examples/NRF52_PDM_PWMTest/NRF52_PDM_PWMTest.ino b/examples/Platforms/NRF52/NRF52_PDM_PWMTest/NRF52_PDM_PWMTest.ino similarity index 100% rename from examples/NRF52_PDM_PWMTest/NRF52_PDM_PWMTest.ino rename to examples/Platforms/NRF52/NRF52_PDM_PWMTest/NRF52_PDM_PWMTest.ino diff --git a/examples/Platforms/NRF52/NRF52_SD_Playback_I2S/NRF52_SD_Playback_I2S.ino b/examples/Platforms/NRF52/NRF52_SD_Playback_I2S/NRF52_SD_Playback_I2S.ino new file mode 100644 index 0000000..3989d46 --- /dev/null +++ b/examples/Platforms/NRF52/NRF52_SD_Playback_I2S/NRF52_SD_Playback_I2S.ino @@ -0,0 +1,94 @@ +/* + AutoAnalogAudio streaming via DAC & ADC by TMRh20 + Copyright (C) 2016 TMRh20 - tmrh20@gmail.com, github.com/TMRh20 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + Auto Analog Audio (Automatic DAC, ADC & Timer) library + + Auto Analog Audio Library Information: + http://github.com/TMRh20 + http://tmrh20.blogspot.com + +*/ + +#include +#include +#include + +AutoAnalog aaAudio; + +/*********************************************************/ +/* Tested with MAX98357A I2S breakout +/* BCLK connected to Arduino D1 (p0.03) +/* LRCK connected to Arduino D3 (p0.29) +/* DIN connected to Arduino D5 (p0.05) +/* SD connected to Arduino D6 (p1.11) +/*********************************************************/ + +void setup() { + + Serial.begin(115200); + + Serial.print("Init SD card..."); + if (!SD.begin(10000000, 2)) { + Serial.println("init failed!"); + return; + } + Serial.println("init ok"); + Serial.println("Analog Audio Begin"); + aaAudio.begin(0, 1, 1); //Setup aaAudio using DAC and I2S + + //Setup for audio: Use 8 or 16-bit, mono or stereo. Valid sample rates are 16000, 24000, 32000, 44000 + aaAudio.dacBitsPerSample = 8; // 8-bit + aaAudio.setSampleRate(24000, 0); // 24khz, mono + + pinMode(6,OUTPUT); //Connected to SD pin of MAX98357A + digitalWrite(6,HIGH); + + playAudio("brick/brick24.wav"); // 24kHz @ 16-bits is about the maximum when reading from SD card +} + +void loop() { + + loadBuffer(); + +} + +/*********************************************************/ +/* A simple function to handle playing audio files +/*********************************************************/ + +File myFile; + +void playAudio(char *audioFile) { + + if (myFile) { + myFile.close(); + } + //Open the designated file + myFile = SD.open(audioFile); + //Skip past the WAV header + myFile.seek(44); +} + +void loadBuffer() { + + if( myFile.available() ){ + myFile.read(aaAudio.dacBuffer, 6400); // Change this to dacBuffer16 for 16-bit samples + aaAudio.feedDAC(0, 6400); // change this to 3200 for 16-bit samples + }else{ + myFile.seek(44); + } +}